Commit 6010f1da authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Added an (expensive) debugging check to verify that all cells have been...

Added an (expensive) debugging check to verify that all cells have been drifted to the current point in time before a rebuild or a repartition.
parent 4258cba1
...@@ -285,6 +285,11 @@ int main(int argc, char *argv[]) { ...@@ -285,6 +285,11 @@ int main(int argc, char *argv[]) {
message("Running on: %s", hostname()); message("Running on: %s", hostname());
#endif #endif
/* Do we have debugging checks ? */
#ifdef SWIFT_DEBUG_CHECKS
message("WARNING: Debugging checks activated. Code will be slower !");
#endif
/* Do we choke on FP-exceptions ? */ /* Do we choke on FP-exceptions ? */
if (with_fp_exceptions) { if (with_fp_exceptions) {
feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW); feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
......
...@@ -763,6 +763,23 @@ void cell_clean_links(struct cell *c, void *data) { ...@@ -763,6 +763,23 @@ void cell_clean_links(struct cell *c, void *data) {
c->grav = NULL; c->grav = NULL;
} }
/**
* @brief Checks that a cell is at the current point in time
*
* Calls error() if the cell is not at the current time.
*
* @param c Cell to act upon
* @param data The current time on the integer time-line
*/
void cell_check_drift_point(struct cell *c, void *data) {
const int ti_current = *(int *)data;
if (c->ti_old != ti_current)
error("Cell in an incorrect time-zone! c->ti_old=%d ti_current=%d",
c->ti_old, ti_current);
}
/** /**
* @brief Checks whether the cells are direct neighbours ot not. Both cells have * @brief Checks whether the cells are direct neighbours ot not. Both cells have
* to be of the same size * to be of the same size
......
...@@ -291,6 +291,7 @@ int cell_are_neighbours(const struct cell *restrict ci, ...@@ -291,6 +291,7 @@ int cell_are_neighbours(const struct cell *restrict ci,
const struct cell *restrict cj); const struct cell *restrict cj);
void cell_check_multipole(struct cell *c, void *data); void cell_check_multipole(struct cell *c, void *data);
void cell_clean(struct cell *c); void cell_clean(struct cell *c);
void cell_check_drift_point(struct cell *c, void *data);
int cell_is_drift_needed(struct cell *c, const struct engine *e); int cell_is_drift_needed(struct cell *c, const struct engine *e);
int cell_unskip_tasks(struct cell *c, struct scheduler *s); int cell_unskip_tasks(struct cell *c, struct scheduler *s);
void cell_set_super(struct cell *c, struct cell *super); void cell_set_super(struct cell *c, struct cell *super);
......
...@@ -557,6 +557,11 @@ void engine_repartition(struct engine *e) { ...@@ -557,6 +557,11 @@ void engine_repartition(struct engine *e) {
ticks tic = getticks(); ticks tic = getticks();
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all cells have been drifted to the current time */
space_check_drift_point(e->s, e->ti_current);
#endif
/* Clear the repartition flag. */ /* Clear the repartition flag. */
enum repartition_type reparttype = e->forcerepart; enum repartition_type reparttype = e->forcerepart;
e->forcerepart = REPART_NONE; e->forcerepart = REPART_NONE;
...@@ -2234,6 +2239,11 @@ void engine_prepare(struct engine *e, int nodrift) { ...@@ -2234,6 +2239,11 @@ void engine_prepare(struct engine *e, int nodrift) {
e->drift_all = (e->policy & engine_policy_drift_all); e->drift_all = (e->policy & engine_policy_drift_all);
} }
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all cells have been drifted to the current time */
space_check_drift_point(e->s, e->ti_current);
#endif
engine_rebuild(e); engine_rebuild(e);
} }
......
...@@ -318,6 +318,8 @@ void space_regrid(struct space *s, int verbose) { ...@@ -318,6 +318,8 @@ void space_regrid(struct space *s, int verbose) {
s->nr_cells * sizeof(struct cell)) != 0) s->nr_cells * sizeof(struct cell)) != 0)
error("Failed to allocate cells."); error("Failed to allocate cells.");
bzero(s->cells_top, s->nr_cells * sizeof(struct cell)); bzero(s->cells_top, s->nr_cells * sizeof(struct cell));
/* Set the cells' locks */
for (int k = 0; k < s->nr_cells; k++) for (int k = 0; k < s->nr_cells; k++)
if (lock_init(&s->cells_top[k].lock) != 0) if (lock_init(&s->cells_top[k].lock) != 0)
error("Failed to init spinlock."); error("Failed to init spinlock.");
...@@ -1874,6 +1876,8 @@ void space_init(struct space *s, const struct swift_params *params, ...@@ -1874,6 +1876,8 @@ void space_init(struct space *s, const struct swift_params *params,
* @brief Cleans-up all the cell links in the space * @brief Cleans-up all the cell links in the space
* *
* Expensive funtion. Should only be used for debugging purposes. * Expensive funtion. Should only be used for debugging purposes.
*
* @param s The #space to clean.
*/ */
void space_link_cleanup(struct space *s) { void space_link_cleanup(struct space *s) {
...@@ -1881,6 +1885,20 @@ void space_link_cleanup(struct space *s) { ...@@ -1881,6 +1885,20 @@ void space_link_cleanup(struct space *s) {
space_map_cells_pre(s, 1, cell_clean_links, NULL); space_map_cells_pre(s, 1, cell_clean_links, NULL);
} }
/**
* @brief Checks that all cells have been drifted to the current point in time
*
* Expensive function. Should only be used for debugging purposes.
*
* @param s The #space to check.
* @param ti_current The (integer) time.
*/
void space_check_drift_point(struct space *s, int ti_current) {
/* Recursively check all cells */
space_map_cells_pre(s, 1, cell_check_drift_point, &ti_current);
}
/** /**
* @brief Frees up the memory allocated for this #space * @brief Frees up the memory allocated for this #space
*/ */
......
...@@ -183,6 +183,7 @@ void space_do_gparts_sort(); ...@@ -183,6 +183,7 @@ void space_do_gparts_sort();
void space_init_parts(struct space *s); void space_init_parts(struct space *s);
void space_init_gparts(struct space *s); void space_init_gparts(struct space *s);
void space_link_cleanup(struct space *s); void space_link_cleanup(struct space *s);
void space_check_drift_point(struct space *s, int ti_current);
void space_clean(struct space *s); void space_clean(struct space *s);
#endif /* SWIFT_SPACE_H */ #endif /* SWIFT_SPACE_H */
Markdown is supported
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