Skip to content
GitLab
Menu
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
57e5b97f
Commit
57e5b97f
authored
Aug 26, 2016
by
Matthieu Schaller
Browse files
space->cells becomes space->cells_top
parent
cb38bd49
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/debug.c
View file @
57e5b97f
...
...
@@ -154,8 +154,9 @@ int checkSpacehmax(struct space *s) {
/* Loop over local cells. */
float
cell_h_max
=
0
.
0
f
;
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
if
(
s
->
cells
[
k
].
nodeID
==
s
->
e
->
nodeID
&&
s
->
cells
[
k
].
h_max
>
cell_h_max
)
{
cell_h_max
=
s
->
cells
[
k
].
h_max
;
if
(
s
->
cells_new
[
k
].
nodeID
==
s
->
e
->
nodeID
&&
s
->
cells_new
[
k
].
h_max
>
cell_h_max
)
{
cell_h_max
=
s
->
cells_new
[
k
].
h_max
;
}
}
...
...
@@ -172,9 +173,9 @@ int checkSpacehmax(struct space *s) {
/* There is a problem. Hunt it down. */
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
if
(
s
->
cells
[
k
].
nodeID
==
s
->
e
->
nodeID
)
{
if
(
s
->
cells
[
k
].
h_max
>
part_h_max
)
{
message
(
"cell %d is inconsistent (%f > %f)"
,
k
,
s
->
cells
[
k
].
h_max
,
if
(
s
->
cells
_new
[
k
].
nodeID
==
s
->
e
->
nodeID
)
{
if
(
s
->
cells
_new
[
k
].
h_max
>
part_h_max
)
{
message
(
"cell %d is inconsistent (%f > %f)"
,
k
,
s
->
cells
_new
[
k
].
h_max
,
part_h_max
);
}
}
...
...
src/engine.c
View file @
57e5b97f
...
...
@@ -256,7 +256,7 @@ void engine_redistribute(struct engine *e) {
const
int
nr_nodes
=
e
->
nr_nodes
;
const
int
nodeID
=
e
->
nodeID
;
struct
space
*
s
=
e
->
s
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
const
int
nr_cells
=
s
->
nr_cells
;
const
int
*
cdim
=
s
->
cdim
;
const
double
iwidth
[
3
]
=
{
s
->
iwidth
[
0
],
s
->
iwidth
[
1
],
s
->
iwidth
[
2
]};
...
...
@@ -535,12 +535,12 @@ void engine_redistribute(struct engine *e) {
#ifdef SWIFT_DEBUG_CHECKS
/* Verify that all parts are in the right place. */
for
(
in
t
k
=
0
;
k
<
nr_parts
;
k
++
)
{
int
cid
=
cell_getid
(
cdim
,
parts_new
[
k
].
x
[
0
]
*
iwidth
[
0
],
parts_new
[
k
].
x
[
1
]
*
iwidth
[
1
],
parts_new
[
k
].
x
[
2
]
*
iwidth
[
2
]);
for
(
size_
t
k
=
0
;
k
<
nr_parts
;
k
++
)
{
const
int
cid
=
cell_getid
(
cdim
,
parts_new
[
k
].
x
[
0
]
*
iwidth
[
0
],
parts_new
[
k
].
x
[
1
]
*
iwidth
[
1
],
parts_new
[
k
].
x
[
2
]
*
iwidth
[
2
]);
if
(
cells
[
cid
].
nodeID
!=
nodeID
)
error
(
"Received particle (%
i
) that does not belong here (nodeID=%i)."
,
k
,
error
(
"Received particle (%
zu
) that does not belong here (nodeID=%i)."
,
k
,
cells
[
cid
].
nodeID
);
}
...
...
@@ -561,7 +561,7 @@ void engine_redistribute(struct engine *e) {
for
(
size_t
k
=
0
;
k
<
nr_parts
;
++
k
)
{
if
(
parts_new
[
k
].
gpart
!=
NULL
&&
parts_new
[
k
].
gpart
->
id_or_neg_offset
!=
-
k
)
{
parts_new
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
{
error
(
"Linking problem !"
);
}
}
...
...
@@ -852,7 +852,7 @@ void engine_exchange_cells(struct engine *e) {
#ifdef WITH_MPI
struct
space
*
s
=
e
->
s
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
const
int
nr_cells
=
s
->
nr_cells
;
const
int
nr_proxies
=
e
->
nr_proxies
;
int
offset
[
nr_cells
];
...
...
@@ -1012,7 +1012,7 @@ void engine_exchange_strays(struct engine *e, size_t offset_parts,
/* Put the parts and gparts into the corresponding proxies. */
for
(
size_t
k
=
0
;
k
<
*
Npart
;
k
++
)
{
/* Get the target node and proxy ID. */
const
int
node_id
=
e
->
s
->
cells
[
ind_part
[
k
]].
nodeID
;
const
int
node_id
=
e
->
s
->
cells
_top
[
ind_part
[
k
]].
nodeID
;
if
(
node_id
<
0
||
node_id
>=
e
->
nr_nodes
)
error
(
"Bad node ID %i."
,
node_id
);
const
int
pid
=
e
->
proxy_ind
[
node_id
];
...
...
@@ -1036,7 +1036,7 @@ void engine_exchange_strays(struct engine *e, size_t offset_parts,
&
s
->
xparts
[
offset_parts
+
k
],
1
);
}
for
(
size_t
k
=
0
;
k
<
*
Ngpart
;
k
++
)
{
const
int
node_id
=
e
->
s
->
cells
[
ind_gpart
[
k
]].
nodeID
;
const
int
node_id
=
e
->
s
->
cells
_top
[
ind_gpart
[
k
]].
nodeID
;
if
(
node_id
<
0
||
node_id
>=
e
->
nr_nodes
)
error
(
"Bad node ID %i."
,
node_id
);
const
int
pid
=
e
->
proxy_ind
[
node_id
];
...
...
@@ -1241,7 +1241,7 @@ void engine_make_gravity_tasks(struct engine *e) {
struct
space
*
s
=
e
->
s
;
struct
scheduler
*
sched
=
&
e
->
sched
;
const
int
nodeID
=
e
->
nodeID
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
const
int
nr_cells
=
s
->
nr_cells
;
for
(
int
cid
=
0
;
cid
<
nr_cells
;
++
cid
)
{
...
...
@@ -1296,7 +1296,7 @@ void engine_make_hydroloop_tasks(struct engine *e) {
struct
scheduler
*
sched
=
&
e
->
sched
;
const
int
nodeID
=
e
->
nodeID
;
const
int
*
cdim
=
s
->
cdim
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
/* Run through the highest level of cells and add pairs. */
for
(
int
i
=
0
;
i
<
cdim
[
0
];
i
++
)
{
...
...
@@ -1802,7 +1802,7 @@ void engine_make_gravityrecursive_tasks(struct engine *e) {
struct
scheduler
*
sched
=
&
e
->
sched
;
const
int
nodeID
=
e
->
nodeID
;
const
int
nr_cells
=
s
->
nr_cells
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
for
(
int
k
=
0
;
k
<
nr_cells
;
k
++
)
{
...
...
@@ -1835,7 +1835,7 @@ void engine_maketasks(struct engine *e) {
struct
space
*
s
=
e
->
s
;
struct
scheduler
*
sched
=
&
e
->
sched
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
const
int
nr_cells
=
s
->
nr_cells
;
const
ticks
tic
=
getticks
();
...
...
@@ -2278,7 +2278,7 @@ void engine_prepare(struct engine *e) {
/* First drift all particles to the current time */
e
->
drift_all
=
1
;
threadpool_map
(
&
e
->
threadpool
,
runner_do_drift_mapper
,
e
->
s
->
cells
,
threadpool_map
(
&
e
->
threadpool
,
runner_do_drift_mapper
,
e
->
s
->
cells
_top
,
e
->
s
->
nr_cells
,
sizeof
(
struct
cell
),
1
,
e
);
/* Restore the default drifting policy */
...
...
@@ -2396,8 +2396,8 @@ void engine_collect_timestep(struct engine *e) {
/* Collect the cell data. */
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
if
(
s
->
cells
[
k
].
nodeID
==
e
->
nodeID
)
{
struct
cell
*
c
=
&
s
->
cells
[
k
];
if
(
s
->
cells
_top
[
k
].
nodeID
==
e
->
nodeID
)
{
struct
cell
*
c
=
&
s
->
cells
_top
[
k
];
/* Make the top-cells recurse */
engine_collect_kick
(
c
);
...
...
@@ -2450,8 +2450,8 @@ void engine_print_stats(struct engine *e) {
/* Collect the cell data. */
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
if
(
s
->
cells
[
k
].
nodeID
==
e
->
nodeID
)
{
struct
cell
*
c
=
&
s
->
cells
[
k
];
if
(
s
->
cells
_top
[
k
].
nodeID
==
e
->
nodeID
)
{
struct
cell
*
c
=
&
s
->
cells
_top
[
k
];
mass
+=
c
->
mass
;
e_kin
+=
c
->
e_kin
;
e_int
+=
c
->
e_int
;
...
...
@@ -2666,7 +2666,7 @@ void engine_step(struct engine *e) {
/* Drift everybody to the snapshot position */
e
->
drift_all
=
1
;
threadpool_map
(
&
e
->
threadpool
,
runner_do_drift_mapper
,
e
->
s
->
cells
,
threadpool_map
(
&
e
->
threadpool
,
runner_do_drift_mapper
,
e
->
s
->
cells
_top
,
e
->
s
->
nr_cells
,
sizeof
(
struct
cell
),
1
,
e
);
/* Restore the default drifting policy */
...
...
@@ -2706,7 +2706,7 @@ void engine_step(struct engine *e) {
}
/* Drift only the necessary particles */
threadpool_map
(
&
e
->
threadpool
,
runner_do_drift_mapper
,
e
->
s
->
cells
,
threadpool_map
(
&
e
->
threadpool
,
runner_do_drift_mapper
,
e
->
s
->
cells
_top
,
e
->
s
->
nr_cells
,
sizeof
(
struct
cell
),
1
,
e
);
/* Re-distribute the particles amongst the nodes? */
...
...
@@ -2805,7 +2805,7 @@ void engine_makeproxies(struct engine *e) {
#ifdef WITH_MPI
const
int
*
cdim
=
e
->
s
->
cdim
;
const
struct
space
*
s
=
e
->
s
;
struct
cell
*
cells
=
s
->
cells
;
struct
cell
*
cells
=
s
->
cells
_top
;
struct
proxy
*
proxies
=
e
->
proxies
;
ticks
tic
=
getticks
();
...
...
@@ -2972,7 +2972,8 @@ void engine_split(struct engine *e, struct partition *initial_partition) {
}
for
(
size_t
k
=
0
;
k
<
s
->
nr_parts
;
++
k
)
{
if
(
s
->
parts
[
k
].
gpart
!=
NULL
&&
s
->
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
k
)
if
(
s
->
parts
[
k
].
gpart
!=
NULL
&&
s
->
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
error
(
"Linking problem !"
);
}
...
...
src/partition.c
View file @
57e5b97f
...
...
@@ -143,7 +143,7 @@ static void split_vector(struct space *s, int nregions, int *samplecells) {
select
=
l
;
}
}
s
->
cells
[
n
++
].
nodeID
=
select
;
s
->
cells
_top
[
n
++
].
nodeID
=
select
;
}
}
}
...
...
@@ -795,7 +795,7 @@ void partition_initial_partition(struct partition *initial_partition,
/* Run through the cells and set their nodeID. */
// message("s->dim = [%e,%e,%e]", s->dim[0], s->dim[1], s->dim[2]);
for
(
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
c
=
&
s
->
cells
[
k
];
c
=
&
s
->
cells
_new
[
k
];
for
(
j
=
0
;
j
<
3
;
j
++
)
ind
[
j
]
=
c
->
loc
[
j
]
/
s
->
dim
[
j
]
*
initial_partition
->
grid
[
j
];
c
->
nodeID
=
ind
[
0
]
+
...
...
@@ -1037,10 +1037,10 @@ static int check_complete(struct space *s, int verbose, int nregions) {
int
failed
=
0
;
for
(
int
i
=
0
;
i
<
nregions
;
i
++
)
present
[
i
]
=
0
;
for
(
int
i
=
0
;
i
<
s
->
nr_cells
;
i
++
)
{
if
(
s
->
cells
[
i
].
nodeID
<=
nregions
)
present
[
s
->
cells
[
i
].
nodeID
]
++
;
if
(
s
->
cells
_top
[
i
].
nodeID
<=
nregions
)
present
[
s
->
cells
_top
[
i
].
nodeID
]
++
;
else
message
(
"Bad nodeID: %d"
,
s
->
cells
[
i
].
nodeID
);
message
(
"Bad nodeID: %d"
,
s
->
cells
_top
[
i
].
nodeID
);
}
for
(
int
i
=
0
;
i
<
nregions
;
i
++
)
{
if
(
!
present
[
i
])
{
...
...
@@ -1085,13 +1085,13 @@ int partition_space_to_space(double *oldh, double *oldcdim, int *oldnodeIDs,
for
(
int
k
=
0
;
k
<
s
->
cdim
[
2
];
k
++
)
{
/* Scale indices to old cell space. */
int
ii
=
rint
(
i
*
s
->
iwidth
[
0
]
*
oldh
[
0
]);
int
jj
=
rint
(
j
*
s
->
iwidth
[
1
]
*
oldh
[
1
]);
int
kk
=
rint
(
k
*
s
->
iwidth
[
2
]
*
oldh
[
2
]);
const
int
ii
=
rint
(
i
*
s
->
iwidth
[
0
]
*
oldh
[
0
]);
const
int
jj
=
rint
(
j
*
s
->
iwidth
[
1
]
*
oldh
[
1
]);
const
int
kk
=
rint
(
k
*
s
->
iwidth
[
2
]
*
oldh
[
2
]);
int
cid
=
cell_getid
(
s
->
cdim
,
i
,
j
,
k
);
int
oldcid
=
cell_getid
(
oldcdim
,
ii
,
jj
,
kk
);
s
->
cells
[
cid
].
nodeID
=
oldnodeIDs
[
oldcid
];
const
int
cid
=
cell_getid
(
s
->
cdim
,
i
,
j
,
k
);
const
int
oldcid
=
cell_getid
(
oldcdim
,
ii
,
jj
,
kk
);
s
->
cells
_top
[
cid
].
nodeID
=
oldnodeIDs
[
oldcid
];
if
(
oldnodeIDs
[
oldcid
]
>
nr_nodes
)
nr_nodes
=
oldnodeIDs
[
oldcid
];
}
...
...
src/runner_doiact_grav.h
View file @
57e5b97f
...
...
@@ -488,7 +488,7 @@ static void runner_do_grav_mm(struct runner *r, struct cell *ci, int timer) {
/* Recover the list of top-level cells */
const
struct
engine
*
e
=
r
->
e
;
struct
cell
*
cells
=
e
->
s
->
cells
;
struct
cell
*
cells
=
e
->
s
->
cells
_top
;
const
int
nr_cells
=
e
->
s
->
nr_cells
;
const
int
ti_current
=
e
->
ti_current
;
const
double
max_d
=
...
...
src/space.c
View file @
57e5b97f
...
...
@@ -170,10 +170,11 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
// tic = getticks();
float
h_max
=
s
->
cell_min
/
kernel_gamma
/
space_stretch
;
if
(
nr_parts
>
0
)
{
if
(
s
->
cells
!=
NULL
)
{
if
(
s
->
cells
_top
!=
NULL
)
{
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
if
(
s
->
cells
[
k
].
nodeID
==
engine_rank
&&
s
->
cells
[
k
].
h_max
>
h_max
)
{
h_max
=
s
->
cells
[
k
].
h_max
;
if
(
s
->
cells_top
[
k
].
nodeID
==
engine_rank
&&
s
->
cells_top
[
k
].
h_max
>
h_max
)
{
h_max
=
s
->
cells_top
[
k
].
h_max
;
}
}
}
else
{
...
...
@@ -239,7 +240,7 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
for
(
int
j
=
0
;
j
<
s
->
cdim
[
1
];
j
++
)
{
for
(
int
k
=
0
;
k
<
s
->
cdim
[
2
];
k
++
)
{
cid
=
cell_getid
(
oldcdim
,
i
,
j
,
k
);
oldnodeIDs
[
cid
]
=
s
->
cells
[
cid
].
nodeID
;
oldnodeIDs
[
cid
]
=
s
->
cells
_top
[
cid
].
nodeID
;
}
}
}
...
...
@@ -249,16 +250,16 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
/* Do we need to re-build the upper-level cells? */
// tic = getticks();
if
(
s
->
cells
==
NULL
||
cdim
[
0
]
<
s
->
cdim
[
0
]
||
cdim
[
1
]
<
s
->
cdim
[
1
]
||
if
(
s
->
cells
_top
==
NULL
||
cdim
[
0
]
<
s
->
cdim
[
0
]
||
cdim
[
1
]
<
s
->
cdim
[
1
]
||
cdim
[
2
]
<
s
->
cdim
[
2
])
{
/* Free the old cells, if they were allocated. */
if
(
s
->
cells
!=
NULL
)
{
if
(
s
->
cells
_top
!=
NULL
)
{
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
space_rebuild_recycle
(
s
,
&
s
->
cells
[
k
]);
if
(
s
->
cells
[
k
].
sort
!=
NULL
)
free
(
s
->
cells
[
k
].
sort
);
space_rebuild_recycle
(
s
,
&
s
->
cells
_top
[
k
]);
if
(
s
->
cells
_top
[
k
].
sort
!=
NULL
)
free
(
s
->
cells
_top
[
k
].
sort
);
}
free
(
s
->
cells
);
free
(
s
->
cells
_top
);
s
->
maxdepth
=
0
;
}
...
...
@@ -272,18 +273,19 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
/* Allocate the highest level of cells. */
s
->
tot_cells
=
s
->
nr_cells
=
cdim
[
0
]
*
cdim
[
1
]
*
cdim
[
2
];
if
(
posix_memalign
((
void
*
)
&
s
->
cells
,
cell_align
,
if
(
posix_memalign
((
void
*
)
&
s
->
cells
_top
,
cell_align
,
s
->
nr_cells
*
sizeof
(
struct
cell
))
!=
0
)
error
(
"Failed to allocate cells."
);
bzero
(
s
->
cells
,
s
->
nr_cells
*
sizeof
(
struct
cell
));
bzero
(
s
->
cells
_top
,
s
->
nr_cells
*
sizeof
(
struct
cell
));
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
if
(
lock_init
(
&
s
->
cells
[
k
].
lock
)
!=
0
)
error
(
"Failed to init spinlock."
);
if
(
lock_init
(
&
s
->
cells_top
[
k
].
lock
)
!=
0
)
error
(
"Failed to init spinlock."
);
/* Set the cell location and sizes. */
for
(
int
i
=
0
;
i
<
cdim
[
0
];
i
++
)
for
(
int
j
=
0
;
j
<
cdim
[
1
];
j
++
)
for
(
int
k
=
0
;
k
<
cdim
[
2
];
k
++
)
{
c
=
&
s
->
cells
[
cell_getid
(
cdim
,
i
,
j
,
k
)];
c
=
&
s
->
cells
_top
[
cell_getid
(
cdim
,
i
,
j
,
k
)];
c
->
loc
[
0
]
=
i
*
s
->
width
[
0
];
c
->
loc
[
1
]
=
j
*
s
->
width
[
1
];
c
->
loc
[
2
]
=
k
*
s
->
width
[
2
];
...
...
@@ -348,24 +350,24 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
/* Free the old cells, if they were allocated. */
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
space_rebuild_recycle
(
s
,
&
s
->
cells
[
k
]);
s
->
cells
[
k
].
sorts
=
NULL
;
s
->
cells
[
k
].
nr_tasks
=
0
;
s
->
cells
[
k
].
nr_density
=
0
;
s
->
cells
[
k
].
nr_gradient
=
0
;
s
->
cells
[
k
].
nr_force
=
0
;
s
->
cells
[
k
].
density
=
NULL
;
s
->
cells
[
k
].
gradient
=
NULL
;
s
->
cells
[
k
].
force
=
NULL
;
s
->
cells
[
k
].
dx_max
=
0
.
0
f
;
s
->
cells
[
k
].
sorted
=
0
;
s
->
cells
[
k
].
count
=
0
;
s
->
cells
[
k
].
gcount
=
0
;
s
->
cells
[
k
].
init
=
NULL
;
s
->
cells
[
k
].
extra_ghost
=
NULL
;
s
->
cells
[
k
].
ghost
=
NULL
;
s
->
cells
[
k
].
kick
=
NULL
;
s
->
cells
[
k
].
super
=
&
s
->
cells
[
k
];
space_rebuild_recycle
(
s
,
&
s
->
cells
_top
[
k
]);
s
->
cells
_top
[
k
].
sorts
=
NULL
;
s
->
cells
_top
[
k
].
nr_tasks
=
0
;
s
->
cells
_top
[
k
].
nr_density
=
0
;
s
->
cells
_top
[
k
].
nr_gradient
=
0
;
s
->
cells
_top
[
k
].
nr_force
=
0
;
s
->
cells
_top
[
k
].
density
=
NULL
;
s
->
cells
_top
[
k
].
gradient
=
NULL
;
s
->
cells
_top
[
k
].
force
=
NULL
;
s
->
cells
_top
[
k
].
dx_max
=
0
.
0
f
;
s
->
cells
_top
[
k
].
sorted
=
0
;
s
->
cells
_top
[
k
].
count
=
0
;
s
->
cells
_top
[
k
].
gcount
=
0
;
s
->
cells
_top
[
k
].
init
=
NULL
;
s
->
cells
_top
[
k
].
extra_ghost
=
NULL
;
s
->
cells
_top
[
k
].
ghost
=
NULL
;
s
->
cells
_top
[
k
].
kick
=
NULL
;
s
->
cells
_top
[
k
].
super
=
&
s
->
cells
_top
[
k
];
}
s
->
maxdepth
=
0
;
}
...
...
@@ -396,7 +398,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
size_t
nr_parts
=
s
->
nr_parts
;
size_t
nr_gparts
=
s
->
nr_gparts
;
struct
cell
*
restrict
cells
=
s
->
cells
;
struct
cell
*
restrict
cells
_top
=
s
->
cells
_top
;
const
int
ti_current
=
(
s
->
e
!=
NULL
)
?
s
->
e
->
ti_current
:
0
;
const
double
ih
[
3
]
=
{
s
->
iwidth
[
0
],
s
->
iwidth
[
1
],
s
->
iwidth
[
2
]};
...
...
@@ -418,7 +420,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
p
->
x
[
j
]
-=
dim
[
j
];
ind
[
k
]
=
cell_getid
(
cdim
,
p
->
x
[
0
]
*
ih
[
0
],
p
->
x
[
1
]
*
ih
[
1
],
p
->
x
[
2
]
*
ih
[
2
]);
cells
[
ind
[
k
]].
count
++
;
cells
_top
[
ind
[
k
]].
count
++
;
}
// message( "getting particle indices took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit()):
...
...
@@ -438,7 +440,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
gp
->
x
[
j
]
-=
dim
[
j
];
gind
[
k
]
=
cell_getid
(
cdim
,
gp
->
x
[
0
]
*
ih
[
0
],
gp
->
x
[
1
]
*
ih
[
1
],
gp
->
x
[
2
]
*
ih
[
2
]);
cells
[
gind
[
k
]].
gcount
++
;
cells
_top
[
gind
[
k
]].
gcount
++
;
}
// message( "getting particle indices took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit());
...
...
@@ -448,8 +450,8 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
/* Move non-local parts to the end of the list. */
const
int
local_nodeID
=
s
->
e
->
nodeID
;
for
(
size_t
k
=
0
;
k
<
nr_parts
;)
{
if
(
cells
[
ind
[
k
]].
nodeID
!=
local_nodeID
)
{
cells
[
ind
[
k
]].
count
-=
1
;
if
(
cells
_top
[
ind
[
k
]].
nodeID
!=
local_nodeID
)
{
cells
_top
[
ind
[
k
]].
count
-=
1
;
nr_parts
-=
1
;
const
struct
part
tp
=
s
->
parts
[
k
];
s
->
parts
[
k
]
=
s
->
parts
[
nr_parts
];
...
...
@@ -475,12 +477,12 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all parts are in the correct places. */
for
(
size_t
k
=
0
;
k
<
nr_parts
;
k
++
)
{
if
(
cells
[
ind
[
k
]].
nodeID
!=
local_nodeID
)
{
if
(
cells
_top
[
ind
[
k
]].
nodeID
!=
local_nodeID
)
{
error
(
"Failed to move all non-local parts to send list"
);
}
}
for
(
size_t
k
=
nr_parts
;
k
<
s
->
nr_parts
;
k
++
)
{
if
(
cells
[
ind
[
k
]].
nodeID
==
local_nodeID
)
{
if
(
cells
_top
[
ind
[
k
]].
nodeID
==
local_nodeID
)
{
error
(
"Failed to remove local parts from send list"
);
}
}
...
...
@@ -488,8 +490,8 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
/* Move non-local gparts to the end of the list. */
for
(
size_t
k
=
0
;
k
<
nr_gparts
;)
{
if
(
cells
[
gind
[
k
]].
nodeID
!=
local_nodeID
)
{
cells
[
gind
[
k
]].
gcount
-=
1
;
if
(
cells
_top
[
gind
[
k
]].
nodeID
!=
local_nodeID
)
{
cells
_top
[
gind
[
k
]].
gcount
-=
1
;
nr_gparts
-=
1
;
const
struct
gpart
tp
=
s
->
gparts
[
k
];
s
->
gparts
[
k
]
=
s
->
gparts
[
nr_gparts
];
...
...
@@ -513,12 +515,12 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all gparts are in the correct place (untested). */
for
(
size_t
k
=
0
;
k
<
nr_gparts
;
k
++
)
{
if
(
cells
[
gind
[
k
]].
nodeID
!=
local_nodeID
)
{
if
(
cells
_top
[
gind
[
k
]].
nodeID
!=
local_nodeID
)
{
error
(
"Failed to move all non-local gparts to send list"
);
}
}
for
(
size_t
k
=
nr_gparts
;
k
<
s
->
nr_gparts
;
k
++
)
{
if
(
cells
[
gind
[
k
]].
nodeID
==
local_nodeID
)
{
if
(
cells
_top
[
gind
[
k
]].
nodeID
==
local_nodeID
)
{
error
(
"Failed to remove local gparts from send list"
);
}
}
...
...
@@ -550,11 +552,11 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
const
struct
part
*
const
p
=
&
s
->
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
;
cells
_top
[
ind
[
k
]].
count
+=
1
;
#ifdef SWIFT_DEBUG_CHECKS
if
(
cells
[
ind
[
k
]].
nodeID
!=
local_nodeID
)
if
(
cells
_top
[
ind
[
k
]].
nodeID
!=
local_nodeID
)
error
(
"Received part that does not belong to me (nodeID=%i)."
,
cells
[
ind
[
k
]].
nodeID
);
cells
_top
[
ind
[
k
]].
nodeID
);
#endif
}
nr_parts
=
s
->
nr_parts
;
...
...
@@ -600,10 +602,13 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
const
struct
gpart
*
const
p
=
&
s
->
gparts
[
k
];
gind
[
k
]
=
cell_getid
(
cdim
,
p
->
x
[
0
]
*
ih
[
0
],
p
->
x
[
1
]
*
ih
[
1
],
p
->
x
[
2
]
*
ih
[
2
]);
cells
[
gind
[
k
]].
gcount
+=
1
;
/* if ( cells[ ind[k] ].nodeID != nodeID )
error( "Received part that does not belong to me (nodeID=%i)." , cells[
ind[k] ].nodeID ); */
cells_top
[
gind
[
k
]].
gcount
+=
1
;
#ifdef SWIFT_DEBUG_CHECKS
if
(
cells_top
[
ind
[
k
]].
nodeID
!=
s
->
e
->
nodeID
)
error
(
"Received part that does not belong to me (nodeID=%i)."
,
cells_top
[
ind
[
k
]].
nodeID
);
#endif
}
nr_gparts
=
s
->
nr_gparts
;
...
...
@@ -636,7 +641,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
for
(
size_t
k
=
0
;
k
<
nr_parts
;
++
k
)
{
if
(
s
->
parts
[
k
].
gpart
!=
NULL
&&
s
->
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
k
)
{
s
->
parts
[
k
].
gpart
->
id_or_neg_offset
!=
-
(
ptrdiff_t
)
k
)
{
error
(
"Linking problem !"
);
}
}
...
...
@@ -648,7 +653,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
struct
xpart
*
xfinger
=
s
->
xparts
;
struct
gpart
*
gfinger
=
s
->
gparts
;
for
(
int
k
=
0
;
k
<
s
->
nr_cells
;
k
++
)
{
struct
cell
*
restrict
c
=
&
cells
[
k
];
struct
cell
*
restrict
c
=
&
cells
_top
[
k
];
c
->
ti_old
=
ti_current
;
c
->
parts
=
finger
;
c
->
xparts
=
xfinger
;
...
...
@@ -662,7 +667,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
/* At this point, we have the upper-level cells, old or new. Now make
sure that the parts in each cell are ok. */
space_split
(
s
,
cells
,
verbose
);
space_split
(
s
,
cells
_top
,
verbose
);
if
(
verbose
)
message
(
"took %.3f %s."
,
clocks_from_ticks
(
getticks
()
-
tic
),
...
...
@@ -734,9 +739,9 @@ void space_parts_sort(struct space *s, int *ind, size_t N, int min, int max,
#ifdef SWIFT_DEBUG_CHECKS
/* Verify space_sort_struct. */
for
(
in
t
i
=
1
;
i
<
N
;
i
++
)
for
(
size_
t
i
=
1
;
i
<
N
;
i
++
)
if
(
ind
[
i
-
1
]
>
ind
[
i
])
error
(
"Sorting failed (ind[%
i
]=%i,ind[%
i
]=%i), min=%i, max=%i."
,
i
-
1
,
error
(
"Sorting failed (ind[%
zu
]=%i,ind[%
zu
]=%i), min=%i, max=%i."
,
i
-
1
,
ind
[
i
-
1
],
i
,
ind
[
i
],
min
,
max
);
message
(
"Sorting succeeded."
);
#endif
...
...
@@ -919,9 +924,9 @@ void space_gparts_sort(struct space *s, int *ind, size_t N, int min, int max,
#ifdef SWIFT_DEBUG_CHECKS
/* Verify space_sort_struct. */
for
(
in
t
i
=
1
;
i
<
N
;
i
++
)
for
(
size_
t
i
=
1
;
i
<
N
;
i
++
)
if
(
ind
[
i
-
1
]
>
ind
[
i
])
error
(
"Sorting failed (ind[%
i
]=%i,ind[%
i
]=%i), min=%i, max=%i."
,
i
-
1
,
error
(
"Sorting failed (ind[%
zu
]=%i,ind[%
zu
]=%i), min=%i, max=%i."
,
i
-
1
,
ind
[
i
-
1
],
i
,
ind
[
i
],
min
,
max
);
message
(
"Sorting succeeded."
);
#endif
...
...
@@ -1109,7 +1114,7 @@ void space_map_parts(struct space *s,
/* Call the recursive function on all higher-level cells. */
for
(
cid
=
0
;
cid
<
s
->
nr_cells
;
cid
++
)
rec_map_parts
(
&
s
->
cells
[
cid
],
fun
,
data
);
rec_map_parts
(
&
s
->
cells
_top
[
cid
],
fun
,
data
);
}
/**
...
...
@@ -1150,7 +1155,7 @@ void space_map_parts_xparts(struct space *s,
/* Call the recursive function on all higher-level cells. */
for
(
cid
=
0
;
cid
<
s
->
nr_cells
;
cid
++
)
rec_map_parts_xparts
(
&
s
->
cells
[
cid
],
fun
);
rec_map_parts_xparts
(
&
s
->
cells
_top
[
cid
],
fun
);
}
/**
...
...
@@ -1194,7 +1199,7 @@ void space_map_cells_post(struct space *s, int full,
/* Call the recursive function on all higher-level cells. */
for
(
cid
=
0
;
cid
<
s
->
nr_cells
;
cid
++
)
rec_map_cells_post
(
&
s
->
cells
[
cid
],
full
,
fun
,
data
);
rec_map_cells_post
(
&
s
->
cells
_top
[
cid
],
full
,
fun
,
data
);
}
static
void
rec_map_cells_pre
(
struct
cell
*
c
,
int
full
,
...
...
@@ -1228,7 +1233,7 @@ void space_map_cells_pre(struct space *s, int full,
/* Call the recursive function on all higher-level cells. */
for
(
cid
=
0
;
cid
<
s
->
nr_cells
;
cid
++
)
rec_map_cells_pre
(
&
s
->
cells
[
cid
],
full
,
fun
,
data
);
rec_map_cells_pre
(
&
s
->
cells
_top
[
cid
],
full
,
fun
,
data
);
}
/**
...
...
@@ -1240,12 +1245,12 @@ void space_split_mapper(void *map_data, int num_elements, void *extra_data) {
/* Unpack the inputs. */
struct
space
*
s
=
(
struct
space
*
)
extra_data
;
struct
cell
*
cells
=
(
struct
cell
*
)
map_data
;
struct
cell
*
cells
_top
=
(
struct
cell
*
)
map_data
;
struct
engine
*
e
=
s
->
e
;
for
(
int
ind
=
0
;
ind
<
num_elements
;
ind
++
)
{
struct
cell
*
c
=
&
cells
[
ind
];
struct
cell
*
c
=
&
cells
_top
[
ind
];
const
int
count
=
c
->
count
;
const
int
gcount
=
c
->
gcount
;
...
...
@@ -1530,7 +1535,6 @@ void space_init(struct space *s, const struct swift_params *params,
s
->
gparts
=
gparts
;
s
->
cell_min
=
parser_get_param_double
(
params
,
"SPH:max_smoothing_length"
);
s
->
nr_queues
=
1
;
/* Temporary value until engine construction */
s
->
size_parts_foreign
=
0
;
/* Get the constants for the scheduler */
space_maxsize
=
parser_get_opt_param_int
(
params
,
"Scheduler:cell_max_size"
,
...
...
@@ -1647,8 +1651,8 @@ void space_link_cleanup(struct space *s) {
*/
void
space_clean
(
struct
space
*
s
)
{
for
(
int
i
=
0
;
i
<
s
->
nr_cells
;
++
i
)
cell_clean
(
&
s
->
cells
[
i
]);
free
(
s
->
cells
);
for
(
int
i
=
0
;
i
<
s
->
nr_cells
;
++
i
)
cell_clean
(
&
s
->
cells
_top
[
i
]);
free
(
s
->
cells
_top
);
free
(
s
->
parts
);
free
(
s
->
xparts
);
free
(
s
->
gparts
);
...
...
src/space.h
View file @
57e5b97f
...
...
@@ -37,7 +37,6 @@
#include "space.h"
/* Some constants. */
#define space_maxdepth 10
#define space_cellallocchunk 1000
#define space_splitsize_default 400
#define space_maxsize_default 8000000
...
...
@@ -62,59 +61,69 @@ struct entry {
/* The space in which the cells reside. */
struct
space
{
/* Spatial extent. */
/*
!
Spatial extent. */
double
dim
[
3
];
/*
Cell width
s. */
double
width
[
3
]
,
iwidth
[
3
]
;
/*
! Width of the top-level cell
s. */
double
width
[
3
];
/* The minimum cell width. */
/* Inverse of the top-level cell width */