diff --git a/src/cell.c b/src/cell.c index 006df3e9cf1bc1b82b40350cb302d16cbe2b8213..70e0b54b680f79be213c8e3f5126ac7459a18446 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2071,6 +2071,24 @@ void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data) { } } +int cell_has_tasks(struct cell *c) { + +#ifdef WITH_MPI + if (c->timestep != NULL || c->recv_ti != NULL) return 1; +#else + if (c->timestep != NULL) return 1; +#endif /* WITH_MPI */ + + if (c->split) { + int count = 0; + for (int k = 0; k < 8; ++k) + if (c->progeny[k] != NULL) count += cell_has_tasks(c->progeny[k]); + return count; + } else { + return 0; + } +} + /** * @brief Recursively drifts the #part in a cell hierarchy. * diff --git a/src/cell.h b/src/cell.h index efc90e90040a46b4b5b631dec190762056bed151..8b62e4362011617f52c7d8efcde409200098adcd 100644 --- a/src/cell.h +++ b/src/cell.h @@ -462,6 +462,7 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s); void cell_activate_sorts(struct cell *c, int sid, struct scheduler *s); void cell_clear_drift_flags(struct cell *c, void *data); void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data); +int cell_has_tasks(struct cell *c); /* Inlined functions (for speed). */ diff --git a/src/engine.c b/src/engine.c index f28739dc8997eb4472b60f1cd97c3c0645a00404..c65757e4ea924c7c989941cf9845b85ee9e77923 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3070,6 +3070,9 @@ void engine_rebuild(struct engine *e, int clean_h_values) { /* Re-build the tasks. */ engine_maketasks(e); + /* Make the list of top-level cells that have tasks */ + space_list_cells_with_tasks(e->s); + #ifdef SWIFT_DEBUG_CHECKS /* Check that all cells have been drifted to the current time. * That can include cells that have not diff --git a/src/space.c b/src/space.c index c914b6c2e662857dec71f6bad3623f573d103133..502a691259f3ba36c989bfa97304d6778899cb7e 100644 --- a/src/space.c +++ b/src/space.c @@ -503,16 +503,6 @@ void space_regrid(struct space *s, int verbose) { } #endif /* WITH_MPI */ - /* Let's rebuild the list of local top-level cells */ - s->nr_local_cells = 0; - for (int i = 0; i < s->nr_cells; ++i) - if (s->cells_top[i].nodeID == s->nodeID) { - s->local_cells_top[s->nr_local_cells] = i; - ++s->nr_local_cells; - } - if (verbose) - message("Have %d local cells (total=%d)", s->nr_local_cells, s->nr_cells); - // message( "rebuilding upper-level cells took %.3f %s." , // clocks_from_ticks(double)(getticks() - tic), clocks_getunit()); @@ -2483,6 +2473,19 @@ void space_getcells(struct space *s, int nr_cells, struct cell **cells) { } } +void space_list_cells_with_tasks(struct space *s) { + + /* Let's rebuild the list of local top-level cells */ + s->nr_local_cells = 0; + for (int i = 0; i < s->nr_cells; ++i) + if (cell_has_tasks(&s->cells_top[i])) { + s->local_cells_top[s->nr_local_cells] = i; + ++s->nr_local_cells; + } + if (s->e->verbose) + message("Have %d local cells (total=%d)", s->nr_local_cells, s->nr_cells); +} + void space_synchronize_particle_positions_mapper(void *map_data, int nr_gparts, void *extra_data) { /* Unpack the data */ diff --git a/src/space.h b/src/space.h index 0b1e8248b5296f0be3214ad4bd7c02faf9b73a53..8307858d6ec4e997465d65cc70b97c66e01cd18a 100644 --- a/src/space.h +++ b/src/space.h @@ -213,6 +213,7 @@ void space_recycle_list(struct space *s, struct cell *cell_list_begin, void space_split(struct space *s, struct cell *cells, int nr_cells, int verbose); void space_split_mapper(void *map_data, int num_elements, void *extra_data); +void space_list_cells_with_tasks(struct space *s); void space_parts_get_cell_index(struct space *s, int *ind, struct cell *cells, int verbose); void space_gparts_get_cell_index(struct space *s, int *gind, struct cell *cells,