Commit 625354cb authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

rolled back the changes to space_split_mapper as the old version was faster,...

rolled back the changes to space_split_mapper as the old version was faster, but kept the part-gpart relinking changes.
parent 6be81db4
......@@ -754,12 +754,13 @@ void cell_sunlocktree(struct cell *c) {
}
/**
* @brief Sort the part buffers into eight bins along the given pivots.
*
* Assumes the #cell has all its progeny and sets the parts and counts
* in each sub-cell.
* @brief Sort the parts into eight bins along the given pivots.
*
* @param c The #cell array to be sorted.
* @param parts_offset Offset of the cell parts array relative to the
* space's parts array, i.e. c->parts - s->parts.
* @param sparts_offset Offset of the cell sparts array relative to the
* space's sparts array, i.e. c->sparts - s->sparts.
* @param buff A buffer with at least max(c->count, c->gcount) entries,
* used for sorting indices.
* @param sbuff A buffer with at least max(c->scount, c->gcount) entries,
......@@ -767,16 +768,40 @@ void cell_sunlocktree(struct cell *c) {
* @param gbuff A buffer with at least max(c->count, c->gcount) entries,
* used for sorting indices for the gparts.
*/
void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
struct cell_buff *buff, struct cell_buff *sbuff,
struct cell_buff *gbuff) {
const int count = c->count, gcount = c->gcount, scount = c->scount;
struct part *parts = c->parts;
struct xpart *xparts = c->xparts;
struct gpart *gparts = c->gparts;
struct spart *sparts = c->sparts;
const double pivot[3] = {c->loc[0] + c->width[0] / 2,
c->loc[1] + c->width[1] / 2,
c->loc[2] + c->width[2] / 2};
int bucket_count[8] = {0, 0, 0, 0, 0, 0, 0, 0};
int bucket_offset[9];
#ifdef SWIFT_DEBUG_CHECKS
/* Check that the buffs are OK. */
for (int k = 0; k < count; k++) {
if (buff[k].x[0] != parts[k].x[0] || buff[k].x[1] != parts[k].x[1] ||
buff[k].x[2] != parts[k].x[2])
error("Inconsistent buff contents.");
}
for (int k = 0; k < gcount; k++) {
if (gbuff[k].x[0] != gparts[k].x[0] || gbuff[k].x[1] != gparts[k].x[1] ||
gbuff[k].x[2] != gparts[k].x[2])
error("Inconsistent gbuff contents.");
}
for (int k = 0; k < scount; k++) {
if (sbuff[k].x[0] != sparts[k].x[0] || sbuff[k].x[1] != sparts[k].x[1] ||
sbuff[k].x[2] != sparts[k].x[2])
error("Inconsistent sbuff contents.");
}
#endif /* SWIFT_DEBUG_CHECKS */
/* Fill the buffer with the indices. */
for (int k = 0; k < count; k++) {
const int bid = (buff[k].x[0] >= pivot[0]) * 4 +
......@@ -798,6 +823,8 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
k < bucket_offset[bucket + 1]; k++) {
int bid = buff[k].ind;
if (bid != bucket) {
struct part part = parts[k];
struct xpart xpart = xparts[k];
struct cell_buff temp_buff = buff[k];
while (bid != bucket) {
int j = bucket_offset[bid] + bucket_count[bid]++;
......@@ -805,10 +832,18 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
j++;
bucket_count[bid]++;
}
memswap(&parts[j], &part, sizeof(struct part));
memswap(&xparts[j], &xpart, sizeof(struct xpart));
memswap(&buff[j], &temp_buff, sizeof(struct cell_buff));
if (parts[j].gpart)
parts[j].gpart->id_or_neg_offset = -(j + parts_offset);
bid = temp_buff.ind;
}
parts[k] = part;
xparts[k] = xpart;
buff[k] = temp_buff;
if (parts[k].gpart)
parts[k].gpart->id_or_neg_offset = -(k + parts_offset);
}
bucket_count[bid]++;
}
......@@ -825,6 +860,9 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
/* Check that the buffs are OK. */
for (int k = 1; k < count; k++) {
if (buff[k].ind < buff[k - 1].ind) error("Buff not sorted.");
if (buff[k].x[0] != parts[k].x[0] || buff[k].x[1] != parts[k].x[1] ||
buff[k].x[2] != parts[k].x[2])
error("Inconsistent buff contents (k=%i).", k);
}
/* Verify that _all_ the parts have been assigned to a cell. */
......@@ -839,36 +877,44 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
/* Verify a few sub-cells. */
for (int k = 0; k < c->progeny[0]->count; k++)
if (buff[k].x[0] >= pivot[0] || buff[k].x[1] >= pivot[1] ||
buff[k].x[2] >= pivot[2])
if (c->progeny[0]->parts[k].x[0] >= pivot[0] ||
c->progeny[0]->parts[k].x[1] >= pivot[1] ||
c->progeny[0]->parts[k].x[2] >= pivot[2])
error("Sorting failed (progeny=0).");
for (int k = bucket_offset[1]; k < bucket_offset[2]; k++)
if (buff[k].x[0] >= pivot[0] || buff[k].x[1] >= pivot[1] ||
buff[k].x[2] < pivot[2])
for (int k = 0; k < c->progeny[1]->count; k++)
if (c->progeny[1]->parts[k].x[0] >= pivot[0] ||
c->progeny[1]->parts[k].x[1] >= pivot[1] ||
c->progeny[1]->parts[k].x[2] < pivot[2])
error("Sorting failed (progeny=1).");
for (int k = bucket_offset[2]; k < bucket_offset[3]; k++)
if (buff[k].x[0] >= pivot[0] || buff[k].x[1] < pivot[1] ||
buff[k].x[2] >= pivot[2])
for (int k = 0; k < c->progeny[2]->count; k++)
if (c->progeny[2]->parts[k].x[0] >= pivot[0] ||
c->progeny[2]->parts[k].x[1] < pivot[1] ||
c->progeny[2]->parts[k].x[2] >= pivot[2])
error("Sorting failed (progeny=2).");
for (int k = bucket_offset[3]; k < bucket_offset[4]; k++)
if (buff[k].x[0] >= pivot[0] || buff[k].x[1] < pivot[1] ||
buff[k].x[2] < pivot[2])
for (int k = 0; k < c->progeny[3]->count; k++)
if (c->progeny[3]->parts[k].x[0] >= pivot[0] ||
c->progeny[3]->parts[k].x[1] < pivot[1] ||
c->progeny[3]->parts[k].x[2] < pivot[2])
error("Sorting failed (progeny=3).");
for (int k = bucket_offset[4]; k < bucket_offset[5]; k++)
if (buff[k].x[0] < pivot[0] || buff[k].x[1] >= pivot[1] ||
buff[k].x[2] >= pivot[2])
for (int k = 0; k < c->progeny[4]->count; k++)
if (c->progeny[4]->parts[k].x[0] < pivot[0] ||
c->progeny[4]->parts[k].x[1] >= pivot[1] ||
c->progeny[4]->parts[k].x[2] >= pivot[2])
error("Sorting failed (progeny=4).");
for (int k = bucket_offset[5]; k < bucket_offset[6]; k++)
if (buff[k].x[0] < pivot[0] || buff[k].x[1] >= pivot[1] ||
buff[k].x[2] < pivot[2])
for (int k = 0; k < c->progeny[5]->count; k++)
if (c->progeny[5]->parts[k].x[0] < pivot[0] ||
c->progeny[5]->parts[k].x[1] >= pivot[1] ||
c->progeny[5]->parts[k].x[2] < pivot[2])
error("Sorting failed (progeny=5).");
for (int k = bucket_offset[6]; k < bucket_offset[7]; k++)
if (buff[k].x[0] < pivot[0] || buff[k].x[1] < pivot[1] ||
buff[k].x[2] >= pivot[2])
for (int k = 0; k < c->progeny[6]->count; k++)
if (c->progeny[6]->parts[k].x[0] < pivot[0] ||
c->progeny[6]->parts[k].x[1] < pivot[1] ||
c->progeny[6]->parts[k].x[2] >= pivot[2])
error("Sorting failed (progeny=6).");
for (int k = bucket_offset[7]; k < c->count; k++)
if (buff[k].x[0] < pivot[0] || buff[k].x[1] < pivot[1] ||
buff[k].x[2] < pivot[2])
for (int k = 0; k < c->progeny[7]->count; k++)
if (c->progeny[7]->parts[k].x[0] < pivot[0] ||
c->progeny[7]->parts[k].x[1] < pivot[1] ||
c->progeny[7]->parts[k].x[2] < pivot[2])
error("Sorting failed (progeny=7).");
#endif
......@@ -896,6 +942,7 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
k < bucket_offset[bucket + 1]; k++) {
int bid = sbuff[k].ind;
if (bid != bucket) {
struct spart spart = sparts[k];
struct cell_buff temp_buff = sbuff[k];
while (bid != bucket) {
int j = bucket_offset[bid] + bucket_count[bid]++;
......@@ -903,10 +950,16 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
j++;
bucket_count[bid]++;
}
memswap(&sparts[j], &spart, sizeof(struct spart));
memswap(&sbuff[j], &temp_buff, sizeof(struct cell_buff));
if (sparts[j].gpart)
sparts[j].gpart->id_or_neg_offset = -(j + sparts_offset);
bid = temp_buff.ind;
}
sparts[k] = spart;
sbuff[k] = temp_buff;
if (sparts[k].gpart)
sparts[k].gpart->id_or_neg_offset = -(k + sparts_offset);
}
bucket_count[bid]++;
}
......@@ -942,6 +995,7 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
k < bucket_offset[bucket + 1]; k++) {
int bid = gbuff[k].ind;
if (bid != bucket) {
struct gpart gpart = gparts[k];
struct cell_buff temp_buff = gbuff[k];
while (bid != bucket) {
int j = bucket_offset[bid] + bucket_count[bid]++;
......@@ -949,10 +1003,25 @@ void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
j++;
bucket_count[bid]++;
}
memswap(&gparts[j], &gpart, sizeof(struct gpart));
memswap(&gbuff[j], &temp_buff, sizeof(struct cell_buff));
if (gparts[j].type == swift_type_gas) {
parts[-gparts[j].id_or_neg_offset - parts_offset].gpart =
&gparts[j];
} else if (gparts[j].type == swift_type_star) {
sparts[-gparts[j].id_or_neg_offset - sparts_offset].gpart =
&gparts[j];
}
bid = temp_buff.ind;
}
gparts[k] = gpart;
gbuff[k] = temp_buff;
if (gparts[k].type == swift_type_gas) {
parts[-gparts[k].id_or_neg_offset - parts_offset].gpart = &gparts[k];
} else if (gparts[k].type == swift_type_star) {
sparts[-gparts[k].id_or_neg_offset - sparts_offset].gpart =
&gparts[k];
}
}
bucket_count[bid]++;
}
......@@ -1017,23 +1086,6 @@ void cell_sanitize(struct cell *c, int treated) {
c->h_max = h_max;
}
/**
* @brief Converts hydro quantities to a valid state after the initial density
* calculation
*
* @param c Cell to act upon
* @param data Unused parameter
*/
void cell_convert_hydro(struct cell *c, void *data) {
struct part *p = c->parts;
struct xpart *xp = c->xparts;
for (int i = 0; i < c->count; ++i) {
hydro_convert_quantities(&p[i], &xp[i]);
}
}
/**
* @brief Cleans the links in a given cell.
*
......
......@@ -54,10 +54,9 @@ struct scheduler;
/* Global variables. */
extern int cell_next_tag;
/* Struct to temporarily buffer the particle locationsm, offset, and bin id. */
/* Struct to temporarily buffer the particle locations and bin id. */
struct cell_buff {
double x[3];
int offset;
int ind;
} SWIFT_STRUCT_ALIGN;
......@@ -471,7 +470,8 @@ struct cell {
((int)(k) + (cdim)[2] * ((int)(j) + (cdim)[1] * (int)(i)))
/* Function prototypes. */
void cell_split(struct cell *c, struct cell_buff *buff, struct cell_buff *sbuff,
void cell_split(struct cell *c, ptrdiff_t parts_offset, ptrdiff_t sparts_offset,
struct cell_buff *buff, struct cell_buff *sbuff,
struct cell_buff *gbuff);
void cell_sanitize(struct cell *c, int treated);
int cell_locktree(struct cell *c);
......@@ -492,7 +492,6 @@ int cell_getsize(struct cell *c);
int cell_link_parts(struct cell *c, struct part *parts);
int cell_link_gparts(struct cell *c, struct gpart *gparts);
int cell_link_sparts(struct cell *c, struct spart *sparts);
void cell_convert_hydro(struct cell *c, void *data);
void cell_clean_links(struct cell *c, void *data);
void cell_make_multipoles(struct cell *c, integertime_t ti_current);
void cell_check_multipole(struct cell *c, void *data);
......
......@@ -1435,7 +1435,8 @@ void scheduler_enqueue(struct scheduler *s, struct task *t) {
switch (t->type) {
case task_type_self:
case task_type_sub_self:
if (t->subtype == task_subtype_grav || t->subtype == task_subtype_external_grav)
if (t->subtype == task_subtype_grav ||
t->subtype == task_subtype_external_grav)
qid = t->ci->super_gravity->owner;
else
qid = t->ci->super_hydro->owner;
......
......@@ -1701,7 +1701,7 @@ void space_map_cells_pre(struct space *s, int full,
*/
void space_split_recursive(struct space *s, struct cell *c,
struct cell_buff *buff, struct cell_buff *sbuff,
struct cell_buff *gbuff, int *cell_id) {
struct cell_buff *gbuff) {
const int count = c->count;
const int gcount = c->gcount;
......@@ -1719,6 +1719,41 @@ void space_split_recursive(struct space *s, struct cell *c,
struct xpart *xparts = c->xparts;
struct engine *e = s->e;
/* If the buff is NULL, allocate it, and remember to free it. */
const int allocate_buffer = (buff == NULL && gbuff == NULL && sbuff == NULL);
if (allocate_buffer) {
if (count > 0) {
if (posix_memalign((void **)&buff, SWIFT_STRUCT_ALIGNMENT,
sizeof(struct cell_buff) * count) != 0)
error("Failed to allocate temporary indices.");
for (int k = 0; k < count; k++) {
buff[k].x[0] = parts[k].x[0];
buff[k].x[1] = parts[k].x[1];
buff[k].x[2] = parts[k].x[2];
}
}
if (gcount > 0) {
if (posix_memalign((void **)&gbuff, SWIFT_STRUCT_ALIGNMENT,
sizeof(struct cell_buff) * gcount) != 0)
error("Failed to allocate temporary indices.");
for (int k = 0; k < gcount; k++) {
gbuff[k].x[0] = gparts[k].x[0];
gbuff[k].x[1] = gparts[k].x[1];
gbuff[k].x[2] = gparts[k].x[2];
}
}
if (scount > 0) {
if (posix_memalign((void **)&sbuff, SWIFT_STRUCT_ALIGNMENT,
sizeof(struct cell_buff) * scount) != 0)
error("Failed to allocate temporary indices.");
for (int k = 0; k < scount; k++) {
sbuff[k].x[0] = sparts[k].x[0];
sbuff[k].x[1] = sparts[k].x[1];
sbuff[k].x[2] = sparts[k].x[2];
}
}
}
/* Check the depth. */
while (depth > (maxdepth = s->maxdepth)) {
atomic_cas(&s->maxdepth, maxdepth, depth);
......@@ -1774,12 +1809,12 @@ void space_split_recursive(struct space *s, struct cell *c,
}
/* Split the cell data. */
cell_split(c, buff, sbuff, gbuff);
cell_split(c, c->parts - s->parts, c->sparts - s->sparts, buff, sbuff,
gbuff);
/* Remove any progeny with zero parts. */
struct cell_buff *progeny_buff = buff;
struct cell_buff *progeny_gbuff = gbuff;
struct cell_buff *progeny_sbuff = sbuff;
struct cell_buff *progeny_buff = buff, *progeny_gbuff = gbuff,
*progeny_sbuff = sbuff;
for (int k = 0; k < 8; k++) {
if (c->progeny[k]->count == 0 && c->progeny[k]->gcount == 0 &&
c->progeny[k]->scount == 0) {
......@@ -1787,10 +1822,10 @@ void space_split_recursive(struct space *s, struct cell *c,
c->progeny[k] = NULL;
} else {
space_split_recursive(s, c->progeny[k], progeny_buff, progeny_sbuff,
progeny_gbuff, cell_id);
if (progeny_buff) progeny_buff += c->progeny[k]->count;
if (progeny_gbuff) progeny_gbuff += c->progeny[k]->gcount;
if (progeny_sbuff) progeny_sbuff += c->progeny[k]->scount;
progeny_gbuff);
progeny_buff += c->progeny[k]->count;
progeny_gbuff += c->progeny[k]->gcount;
progeny_sbuff += c->progeny[k]->scount;
h_max = max(h_max, c->progeny[k]->h_max);
ti_hydro_end_min =
min(ti_hydro_end_min, c->progeny[k]->ti_hydro_end_min);
......@@ -1883,58 +1918,43 @@ void space_split_recursive(struct space *s, struct cell *c,
timebin_t hydro_time_bin_min = num_time_bins, hydro_time_bin_max = 0;
timebin_t gravity_time_bin_min = num_time_bins, gravity_time_bin_max = 0;
/* Get a pointer to the root cell (we probably want to make this a parameter
* later). */
struct cell *root = c;
while (root->parent != NULL) root = root->parent;
/* Get a unique sequence number of this leaf cell. */
const int current_cell_id = (*cell_id)++;
/* Put the parts and xparts in the right order. */
const int parts_offset = c->parts - root->parts;
/* parts: Get dt_min/dt_max and h_max. */
for (int k = 0; k < count; k++) {
#ifdef SWIFT_DEBUG_CHECKS
if (parts[k].time_bin == time_bin_inhibited)
error("Inhibited particle present in space_split()");
#endif
hydro_time_bin_min = min(hydro_time_bin_min, parts[k].time_bin);
hydro_time_bin_max = max(hydro_time_bin_max, parts[k].time_bin);
h_max = max(h_max, parts[k].h);
}
/* parts: Reset x_diff */
for (int k = 0; k < count; k++) {
/* Set the cell_id in the buffer. */
buff[k].ind = current_cell_id;
/* parts: Get dt_min/dt_max and h_max. */
struct part *p = &parts[buff[k].offset - parts_offset];
hydro_time_bin_min = min(hydro_time_bin_min, p->time_bin);
hydro_time_bin_max = max(hydro_time_bin_max, p->time_bin);
h_max = max(h_max, p->h);
/* xparts: Reset x_diff */
xparts[k].x_diff[0] = 0.f;
xparts[k].x_diff[1] = 0.f;
xparts[k].x_diff[2] = 0.f;
}
/* Put the sparts in the right order. */
const int sparts_offset = c->sparts - root->sparts;
for (int k = 0; k < scount; k++) {
/* Set the cell_id in the buffer. */
sbuff[k].ind = current_cell_id;
/* sparts: Get dt_min/dt_max */
struct spart *sp = &sparts[sbuff[k].offset - sparts_offset];
gravity_time_bin_min = min(gravity_time_bin_min, sp->time_bin);
gravity_time_bin_max = max(gravity_time_bin_max, sp->time_bin);
}
/* Put the gparts in the right order. */
const int gparts_offset = c->gparts - root->gparts;
/* gparts: Get dt_min/dt_max, reset x_diff. */
for (int k = 0; k < gcount; k++) {
/* Set the cell_id in the buffer. */
gbuff[k].ind = current_cell_id;
/* gparts: Get dt_min/dt_max, reset x_diff. */
struct gpart *gp = &gparts[gbuff[k].offset - gparts_offset];
gravity_time_bin_min = min(gravity_time_bin_min, gp->time_bin);
gravity_time_bin_max = max(gravity_time_bin_max, gp->time_bin);
#ifdef SWIFT_DEBUG_CHECKS
if (gparts[k].time_bin == time_bin_inhibited)
error("Inhibited g-particle present in space_split()");
#endif
gravity_time_bin_min = min(gravity_time_bin_min, gparts[k].time_bin);
gravity_time_bin_max = max(gravity_time_bin_max, gparts[k].time_bin);
gparts[k].x_diff[0] = 0.f;
gparts[k].x_diff[1] = 0.f;
gparts[k].x_diff[2] = 0.f;
}
/* sparts: Get dt_min/dt_max */
for (int k = 0; k < scount; k++) {
#ifdef SWIFT_DEBUG_CHECKS
if (sparts[k].time_bin == time_bin_inhibited)
error("Inhibited s-particle present in space_split()");
#endif
gravity_time_bin_min = min(gravity_time_bin_min, sparts[k].time_bin);
gravity_time_bin_max = max(gravity_time_bin_max, sparts[k].time_bin);
}
/* Convert into integer times */
ti_hydro_end_min = get_integer_time_end(e->ti_current, hydro_time_bin_min);
......@@ -2000,106 +2020,13 @@ void space_split_recursive(struct space *s, struct cell *c,
((c->gparts - s->gparts) % s->nr_gparts) * s->nr_queues / s->nr_gparts;
else
c->owner = 0; /* Ok, there is really nothing on this rank... */
}
void space_split_cell(struct space *s, struct cell *c) {
struct part *parts = c->parts;
struct gpart *gparts = c->gparts;
struct spart *sparts = c->sparts;
const int count = c->count;
const int gcount = c->gcount;
const int scount = c->scount;
struct cell_buff *buff = NULL;
struct cell_buff *gbuff = NULL;
struct cell_buff *sbuff = NULL;
/* Allocate and fill the particle position buffers. */
if (count > 0) {
if (posix_memalign((void **)&buff, SWIFT_STRUCT_ALIGNMENT,
sizeof(struct cell_buff) * count) != 0)
error("Failed to allocate temporary indices.");
for (int k = 0; k < count; k++) {
buff[k].x[0] = parts[k].x[0];
buff[k].x[1] = parts[k].x[1];
buff[k].x[2] = parts[k].x[2];
buff[k].offset = k;
}
}
if (gcount > 0) {
if (posix_memalign((void **)&gbuff, SWIFT_STRUCT_ALIGNMENT,
sizeof(struct cell_buff) * gcount) != 0)
error("Failed to allocate temporary indices.");
for (int k = 0; k < gcount; k++) {
gbuff[k].x[0] = gparts[k].x[0];
gbuff[k].x[1] = gparts[k].x[1];
gbuff[k].x[2] = gparts[k].x[2];
gbuff[k].offset = k;
}
}
if (scount > 0) {
if (posix_memalign((void **)&sbuff, SWIFT_STRUCT_ALIGNMENT,
sizeof(struct cell_buff) * scount) != 0)
error("Failed to allocate temporary indices.");
for (int k = 0; k < scount; k++) {
sbuff[k].x[0] = sparts[k].x[0];
sbuff[k].x[1] = sparts[k].x[1];
sbuff[k].x[2] = sparts[k].x[2];
sbuff[k].offset = k;
}
}
/* Call the recursive cell splitting function. */
int num_leaf_cells = 0;
space_split_recursive(s, c, buff, sbuff, gbuff, &num_leaf_cells);
/* Collect the particle leaf cell indices. */
int max_count = (count > gcount) ? count : gcount;
if (max_count < scount) max_count = scount;
int *leaf_cell_ind = (int *)malloc(sizeof(int) * max_count);
int *leaf_cell_count = (int *)calloc(sizeof(int), num_leaf_cells);
if (!leaf_cell_ind || !leaf_cell_count)
error("Error allocating temporary leaf cell index and count.");
for (int k = 0; k < count; k++) {
leaf_cell_ind[buff[k].offset] = buff[k].ind;
leaf_cell_count[buff[k].ind]++;
}
/* Re-shuffle the parts into the correct leaf cells and clean up. */
space_parts_sort(c->parts, c->xparts, leaf_cell_ind, leaf_cell_count,
num_leaf_cells, c->parts - s->parts);
/* Re-populate the leaf_cell indices and counts for sparts. */
bzero(leaf_cell_count, sizeof(int) * num_leaf_cells);
for (int k = 0; k < scount; k++) {
leaf_cell_ind[sbuff[k].offset] = sbuff[k].ind;
leaf_cell_count[sbuff[k].ind]++;
}
/* Re-shuffle the sparts into the correct leaf cells and clean up. */
space_sparts_sort(c->sparts, leaf_cell_ind, leaf_cell_count, num_leaf_cells,
c->sparts - s->sparts);
/* Re-populate the leaf_cell indices and counts for sparts. */
bzero(leaf_cell_count, sizeof(int) * num_leaf_cells);
for (int k = 0; k < scount; k++) {
leaf_cell_ind[gbuff[k].offset] = gbuff[k].ind;
leaf_cell_count[gbuff[k].ind]++;
}
/* Re-shuffle the gparts into the correct leaf cells and clean up. */
space_gparts_sort(c->gparts, s->parts, s->sparts, leaf_cell_ind,
leaf_cell_count, num_leaf_cells);
/* Clean up the leaf cell sorting data. */
free(leaf_cell_ind);
free(leaf_cell_count);
/* Clean up. */
if (buff != NULL) free(buff);
if (gbuff != NULL) free(gbuff);
if (sbuff != NULL) free(sbuff);
if (allocate_buffer) {
if (buff != NULL) free(buff);
if (gbuff != NULL) free(gbuff);
if (sbuff != NULL) free(sbuff);
}
}
/**
......@@ -2118,7 +2045,7 @@ void space_split_mapper(void *map_data, int num_cells, void *extra_data) {
for (int ind = 0; ind < num_cells; ind++) {
struct cell *c = &cells_top[ind];
space_split_cell(s, c);
space_split_recursive(s, c, NULL, NULL, NULL);
}
#ifdef SWIFT_DEBUG_CHECKS
......@@ -2239,7 +2166,7 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) {
if (posix_memalign((void **)&s->cells_sub, cell_align,
space_cellallocchunk * sizeof(struct cell)) != 0)
error("Failed to allocate more cells.");
/* Clear the newly-allocated cells. */
bzero(s->cells_sub, sizeof(struct cell) * space_cellallocchunk);
......@@ -2293,11 +2220,12 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) {
/**
* @brief Free sort arrays in any cells in the cell buffer.
*
*
* @param s The #space.
*/
void space_free_buff_sort_indices(struct space *s) {
for (struct cell *finger = s->cells_sub; finger != NULL; finger = finger->next) {
for (struct cell *finger = s->cells_sub; finger != NULL;