Commit 2cdeb7cf authored by Pedro Gonnet's avatar Pedro Gonnet
Browse files

don't trust existing sorts as we force re-sorts, added some checks for sorted flags consistency.

parent 4975c9c5
......@@ -289,6 +289,15 @@ void runner_do_sort_ascending(struct entry *sort, int N) {
}
}
void runner_check_sorts(struct cell *c, int flags) {
if (flags & ~c->sorted)
error("Inconsistent sort flags (downward)!");
if (c->split)
for (int k = 0; k < 8; k++)
if (c->progeny[k] != NULL)
runner_check_sorts(c->progeny[k], c->sorted);
}
/**
* @brief Sort the particles in the given cell along all cardinal directions.
*
......@@ -312,18 +321,30 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int clock) {
/* Check that the particles have been moved to the current time */
if (!cell_is_drifted(c, r->e)) error("Sorting un-drifted cell");
#ifdef SWIFT_DEBUG_CHECKS
/* Make sure the sort flags are consistent (downward). */
runner_check_sorts(c, c->sorted);
/* Make sure the sort flags are consistent (upard). */
for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent) {
if (finger->sorted & ~c->sorted)
error("Inconsistent sort flags (upward).");
}
#endif
/* Clean-up the flags, i.e. filter out what's already been sorted, but
only if the sorts are recent. */
if (c->ti_sort == r->e->ti_current) {
/* Ignore dimensions that have been sorted. */
flags &= ~c->sorted;
/* Ignore dimensions that have been sorted in this timestep. */
// flags &= ~c->sorted;
} else {
/* Clean old (stale) sorts. */
flags |= c->sorted;
c->sorted = 0;
}
if (flags == 0) return;
/* start by allocating the entry arrays. */
if (c->sort == NULL || c->sortsize < count) {
if (c->sort != NULL) free(c->sort);
......@@ -336,7 +357,7 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int clock) {
/* Does this cell have any progeny? */
if (c->split) {
/* Fill in the gaps within the progeny. */
float dx_max_sort = 0.0f;
for (int k = 0; k < 8; k++) {
......@@ -474,6 +495,15 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int clock) {
if (finger[k].i >= count) error("Sorting failed, indices borked.");
}
}
/* Make sure the sort flags are consistent (downward). */
runner_check_sorts(c, flags);
/* Make sure the sort flags are consistent (upward). */
for (struct cell *finger = c->parent; finger != NULL; finger = finger->parent) {
if (finger->sorted & ~c->sorted)
error("Inconsistent sort flags.");
}
#endif
if (clock) TIMER_TOC(timer_dosort);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment