diff --git a/src/engine.c b/src/engine.c index 1d8a945cdcf58771b8e3df754dd9583adf1996f0..1248783bf18e125fdc66b6729c953f647fa61c54 100644 --- a/src/engine.c +++ b/src/engine.c @@ -4499,9 +4499,6 @@ void engine_rebuild(struct engine *e, int repartitioned, /* Re-build the space. */ space_rebuild(e->s, repartitioned, e->verbose); - /* Construct the list of purely local cells */ - space_list_local_cells(e->s); - /* Update the global counters of particles */ long long num_particles[3] = {e->s->nr_parts, e->s->nr_gparts, e->s->nr_sparts}; @@ -4557,9 +4554,6 @@ void engine_rebuild(struct engine *e, int repartitioned, } #endif - /* Make a short list of cells with any gpart. */ - space_list_cells_with_particles(e->s); - /* Re-build the tasks. */ engine_maketasks(e); diff --git a/src/space.c b/src/space.c index 5cfae82f859ba075d29e070ec7dd46cad48a70b4..e0e4d3810f22bf77e899e9c9c62e2a8f9964ea12 100644 --- a/src/space.c +++ b/src/space.c @@ -1069,12 +1069,14 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) { nr_sparts, verbose); #endif - /* Hook the cells up to the parts. */ + /* Hook the cells up to the parts. Make list of local and non-empty cells */ ticks tic2 = getticks(); struct part *finger = s->parts; struct xpart *xfinger = s->xparts; struct gpart *gfinger = s->gparts; struct spart *sfinger = s->sparts; + s->nr_cells_with_particles = 0; + s->nr_local_cells = 0; for (int k = 0; k < s->nr_cells; k++) { struct cell *restrict c = &cells_top[k]; c->hydro.ti_old_part = ti_current; @@ -1095,11 +1097,28 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) { xfinger = &xfinger[c->hydro.count]; gfinger = &gfinger[c->grav.count]; sfinger = &sfinger[c->stars.count]; + + /* Add this cell to the list of local cells */ + s->local_cells_top[s->nr_local_cells] = k; + s->nr_local_cells++; + } + + if ((cells_top[k].hydro.count > 0) || (cells_top[k].grav.count > 0) || + (cells_top[k].stars.count > 0)) { + + /* Add this cell to the list of non-empty cells */ + s->cells_with_particles_top[s->nr_cells_with_particles] = k; + s->nr_cells_with_particles++; } } - if (verbose) + if (verbose) { + message("Have %d top-level cells with particles (total=%d)", + s->nr_cells_with_particles, s->nr_cells); + message("Have %d local top-level cells (total=%d)", s->nr_local_cells, + s->nr_cells); message("hooking up cells took %.3f %s.", clocks_from_ticks(getticks() - tic2), clocks_getunit()); + } /* At this point, we have the upper-level cells, old or new. Now make sure that the parts in each cell are ok. */ @@ -2567,37 +2586,6 @@ void space_free_buff_sort_indices(struct space *s) { } } -/** - * @brief Construct the list of top-level cells that have any particle - * - * This assumes the list has been pre-allocated at a regrid. - * - * @param s The #space. - */ -void space_list_cells_with_particles(struct space *s) { - - const ticks tic = getticks(); - - s->nr_cells_with_particles = 0; - - if (!s->gravity) return; - - for (int i = 0; i < s->nr_cells; ++i) - if ((s->cells_top[i].hydro.count > 0) || (s->cells_top[i].grav.count > 0) || - (s->cells_top[i].stars.count > 0)) { - s->cells_with_particles_top[s->nr_cells_with_particles] = i; - s->nr_cells_with_particles++; - } - - if (s->e->verbose) - message("Have %d top-level cells with particles (total=%d)", - s->nr_cells_with_particles, s->nr_cells); - - if (s->e->verbose) - message("took %.3f %s.", clocks_from_ticks(getticks() - tic), - clocks_getunit()); -} - /** * @brief Construct the list of top-level cells that have any tasks in * their hierarchy on this MPI rank. @@ -2626,34 +2614,6 @@ void space_list_cells_with_tasks(struct space *s) { clocks_getunit()); } -/** - * @brief Construct the list of local top-level cells. - * - * This assumes the list has been pre-allocated at a regrid. - * - * @param s The #space. - */ -void space_list_local_cells(struct space *s) { - - const ticks tic = getticks(); - - s->nr_local_cells = 0; - - for (int i = 0; i < s->nr_cells; ++i) - if (s->cells_top[i].nodeID == engine_rank) { - s->local_cells_top[s->nr_local_cells] = i; - s->nr_local_cells++; - } - - if (s->e->verbose) - message("Have %d local top-level cells (total=%d)", s->nr_local_cells, - s->nr_cells); - - if (s->e->verbose) - message("took %.3f %s.", clocks_from_ticks(getticks() - tic), - clocks_getunit()); -} - 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 af11363fd3ab5dba60aae9f36927d0cbe0a14d3d..cc8f62659e7b7306d77808d4d2a435066f37c29e 100644 --- a/src/space.h +++ b/src/space.h @@ -256,9 +256,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_local_cells(struct space *s); void space_list_cells_with_tasks(struct space *s); -void space_list_cells_with_particles(struct space *s); void space_parts_get_cell_index(struct space *s, int *ind, int *cell_counts, int *count_inibibited_parts, int verbose); void space_gparts_get_cell_index(struct space *s, int *gind, int *cell_counts,