Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SWIFT
SWIFTsim
Commits
b23474cd
Commit
b23474cd
authored
Aug 12, 2015
by
Pedro Gonnet
Browse files
re-name some variables for clarity.
Former-commit-id: 87384a946150dc2b684bd2cdb0eab7612f4233a6
parent
a689d22a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/space.c
View file @
b23474cd
...
...
@@ -308,7 +308,7 @@ void space_rebuild ( struct space *s , double cell_max ) {
struct
part
*
restrict
finger
,
*
restrict
p
,
*
parts
=
s
->
parts
;
struct
xpart
*
xfinger
,
*
xparts
=
s
->
xparts
;
struct
gpart
*
gp
,
*
gparts
=
s
->
gparts
,
*
gfinger
;
int
*
i
n
d
;
int
*
cell_
id
;
double
ih
[
3
],
dim
[
3
];
// ticks tic;
...
...
@@ -321,8 +321,8 @@ void space_rebuild ( struct space *s , double cell_max ) {
/* Run through the particles and get their cell index. */
// tic = getticks();
const
int
i
n
d_size
=
s
->
size
_parts
;
if
(
(
i
n
d
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
i
n
d_size
)
)
==
NULL
)
const
int
cell_
id_size
=
s
->
nr
_parts
;
if
(
(
cell_
id
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
cell_
id_size
)
)
==
NULL
)
error
(
"Failed to allocate temporary particle indices."
);
ih
[
0
]
=
s
->
ih
[
0
];
ih
[
1
]
=
s
->
ih
[
1
];
ih
[
2
]
=
s
->
ih
[
2
];
dim
[
0
]
=
s
->
dim
[
0
];
dim
[
1
]
=
s
->
dim
[
1
];
dim
[
2
]
=
s
->
dim
[
2
];
...
...
@@ -334,10 +334,10 @@ void space_rebuild ( struct space *s , double cell_max ) {
p
->
x
[
j
]
+=
dim
[
j
];
else
if
(
p
->
x
[
j
]
>=
dim
[
j
]
)
p
->
x
[
j
]
-=
dim
[
j
];
i
n
d
[
k
]
=
cell_getid
(
cdim
,
p
->
x
[
0
]
*
ih
[
0
]
,
p
->
x
[
1
]
*
ih
[
1
]
,
p
->
x
[
2
]
*
ih
[
2
]
);
if
(
i
n
d
[
k
]
<
0
||
i
n
d
[
k
]
>=
s
->
nr_cells
)
error
(
"Bad cell id %i."
,
i
n
d
[
k
]);
atomic_inc
(
&
cells
[
i
n
d
[
k
]
].
count
);
cell_
id
[
k
]
=
cell_getid
(
cdim
,
p
->
x
[
0
]
*
ih
[
0
]
,
p
->
x
[
1
]
*
ih
[
1
]
,
p
->
x
[
2
]
*
ih
[
2
]
);
if
(
cell_
id
[
k
]
<
0
||
cell_
id
[
k
]
>=
s
->
nr_cells
)
error
(
"Bad cell id %i."
,
cell_
id
[
k
]);
atomic_inc
(
&
cells
[
cell_
id
[
k
]
].
count
);
}
// message( "getting particle indices took %.3f ms." , (double)(getticks() - tic) / CPU_TPS * 1000 );
...
...
@@ -347,8 +347,8 @@ void space_rebuild ( struct space *s , double cell_max ) {
int
nodeID
=
s
->
e
->
nodeID
;
int
nr_local_parts
=
s
->
nr_parts
;
for
(
k
=
0
;
k
<
nr_local_parts
;
k
++
)
if
(
cells
[
i
n
d
[
k
]
].
nodeID
!=
nodeID
)
{
cells
[
i
n
d
[
k
]
].
count
-=
1
;
if
(
cells
[
cell_
id
[
k
]
].
nodeID
!=
nodeID
)
{
cells
[
cell_
id
[
k
]
].
count
-=
1
;
nr_local_parts
-=
1
;
struct
part
tp
=
parts
[
k
];
parts
[
k
]
=
parts
[
nr_local_parts
];
...
...
@@ -356,40 +356,41 @@ void space_rebuild ( struct space *s , double cell_max ) {
struct
xpart
txp
=
xparts
[
k
];
xparts
[
k
]
=
xparts
[
nr_local_parts
];
xparts
[
nr_local_parts
]
=
txp
;
int
t
=
i
n
d
[
k
];
i
n
d
[
k
]
=
i
n
d
[
nr_local_parts
];
i
n
d
[
nr_local_parts
]
=
t
;
int
t
=
cell_
id
[
k
];
cell_
id
[
k
]
=
cell_
id
[
nr_local_parts
];
cell_
id
[
nr_local_parts
]
=
t
;
}
/* Exchange the strays, note that this potentially re-allocates
the parts arrays. */
s
->
nr_parts
=
nr_local_parts
+
engine_exchange_strays
(
s
->
e
,
nr_local_parts
,
&
i
n
d
[
nr_local_parts
]
,
s
->
nr_parts
-
nr_local_parts
);
s
->
nr_parts
=
nr_local_parts
+
engine_exchange_strays
(
s
->
e
,
nr_local_parts
,
&
cell_
id
[
nr_local_parts
]
,
s
->
nr_parts
-
nr_local_parts
);
parts
=
s
->
parts
;
xparts
=
s
->
xparts
;
/* Re-allocate the index array if needed.. */
if
(
s
->
nr_parts
>
i
n
d_size
)
{
int
*
i
n
d_new
;
if
(
(
i
n
d_new
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
s
->
nr_parts
)
)
==
NULL
)
if
(
s
->
nr_parts
>
cell_
id_size
)
{
int
*
cell_
id_new
;
if
(
(
cell_
id_new
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
s
->
nr_parts
)
)
==
NULL
)
error
(
"Failed to allocate temporary particle indices."
);
memcpy
(
i
n
d_new
,
i
n
d
,
sizeof
(
int
)
*
nr_local_parts
);
free
(
ind
);
ind
=
in
d_new
;
memcpy
(
cell_
id_new
,
cell_
id
,
sizeof
(
int
)
*
nr_local_parts
);
free
(
cell_id
);
cell_id
=
cell_i
d_new
;
}
/* Assign each particle to its cell. */
for
(
k
=
nr_local_parts
;
k
<
s
->
nr_parts
;
k
++
)
{
p
=
&
parts
[
k
];
ind
[
k
]
=
cell_getid
(
cdim
,
p
->
x
[
0
]
*
ih
[
0
]
,
p
->
x
[
1
]
*
ih
[
1
]
,
p
->
x
[
2
]
*
ih
[
2
]
);
cells
[
ind
[
k
]
].
count
+=
1
;
if
(
cells
[
ind
[
k
]
].
nodeID
!=
nodeID
)
error
(
"Received part that does not belong to me (nodeID=%i)."
,
cells
[
ind
[
k
]
].
nodeID
);
cell_id
[
k
]
=
cell_getid
(
cdim
,
p
->
x
[
0
]
*
ih
[
0
]
,
p
->
x
[
1
]
*
ih
[
1
]
,
p
->
x
[
2
]
*
ih
[
2
]
);
cells
[
cell_id
[
k
]
].
count
+=
1
;
if
(
cells
[
cell_id
[
k
]
].
nodeID
!=
nodeID
)
error
(
"Received part that does not belong to me (nodeID=%i, x=[%e,%e,%e])."
,
cells
[
cell_id
[
k
]
].
nodeID
,
p
->
x
[
0
],
p
->
x
[
1
],
p
->
x
[
2
]
);
}
#endif
/* Sort the parts according to their cells. */
// tic = getticks();
parts_sort
(
parts
,
xparts
,
i
n
d
,
s
->
nr_parts
,
0
,
s
->
nr_cells
-
1
);
parts_sort
(
parts
,
xparts
,
cell_
id
,
s
->
nr_parts
,
0
,
s
->
nr_cells
-
1
);
// message( "parts_sort took %.3f ms." , (double)(getticks() - tic) / CPU_TPS * 1000 );
/* Re-link the gparts. */
...
...
@@ -399,21 +400,21 @@ void space_rebuild ( struct space *s , double cell_max ) {
/* Verify sort. */
/* for ( k = 1 ; k < nr_parts ; k++ ) {
if ( i
n
d[k-1] > i
n
d[k] ) {
if (
cell_
id[k-1] >
cell_
id[k] ) {
error( "Sort failed!" );
}
else if ( i
n
d[k] != cell_getid( cdim , parts[k].x[0]*ih[0] , parts[k].x[1]*ih[1] , parts[k].x[2]*ih[2] ) )
else if (
cell_
id[k] != cell_getid( cdim , parts[k].x[0]*ih[0] , parts[k].x[1]*ih[1] , parts[k].x[2]*ih[2] ) )
error( "Incorrect indices!" );
} */
/* We no longer need the indices as of here. */
free
(
i
n
d
);
free
(
cell_
id
);
/* Run through the gravity particles and get their cell index. */
// tic = getticks();
if
(
(
i
n
d
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
s
->
size_gparts
)
)
==
NULL
)
if
(
(
cell_
id
=
(
int
*
)
malloc
(
sizeof
(
int
)
*
s
->
size_gparts
)
)
==
NULL
)
error
(
"Failed to allocate temporary particle indices."
);
for
(
k
=
0
;
k
<
nr_gparts
;
k
++
)
{
gp
=
&
gparts
[
k
];
...
...
@@ -422,8 +423,8 @@ void space_rebuild ( struct space *s , double cell_max ) {
gp
->
x
[
j
]
+=
dim
[
j
];
else
if
(
gp
->
x
[
j
]
>=
dim
[
j
]
)
gp
->
x
[
j
]
-=
dim
[
j
];
i
n
d
[
k
]
=
cell_getid
(
cdim
,
gp
->
x
[
0
]
*
ih
[
0
]
,
gp
->
x
[
1
]
*
ih
[
1
]
,
gp
->
x
[
2
]
*
ih
[
2
]
);
atomic_inc
(
&
cells
[
i
n
d
[
k
]
].
gcount
);
cell_
id
[
k
]
=
cell_getid
(
cdim
,
gp
->
x
[
0
]
*
ih
[
0
]
,
gp
->
x
[
1
]
*
ih
[
1
]
,
gp
->
x
[
2
]
*
ih
[
2
]
);
atomic_inc
(
&
cells
[
cell_
id
[
k
]
].
gcount
);
}
// message( "getting particle indices took %.3f ms." , (double)(getticks() - tic) / CPU_TPS * 1000 );
...
...
@@ -431,7 +432,7 @@ void space_rebuild ( struct space *s , double cell_max ) {
/* Sort the parts according to their cells. */
// tic = getticks();
gparts_sort
(
gparts
,
i
n
d
,
nr_gparts
,
0
,
s
->
nr_cells
-
1
);
gparts_sort
(
gparts
,
cell_
id
,
nr_gparts
,
0
,
s
->
nr_cells
-
1
);
// message( "gparts_sort took %.3f ms." , (double)(getticks() - tic) / CPU_TPS * 1000 );
/* Re-link the parts. */
...
...
@@ -440,7 +441,7 @@ void space_rebuild ( struct space *s , double cell_max ) {
gparts
[
k
].
part
->
gpart
=
&
gparts
[
k
];
/* We no longer need the indices as of here. */
free
(
i
n
d
);
free
(
cell_
id
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment