From ee303a50f64fa1016ebd776099e209bc1a6112af Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" <p.w.draper@durham.ac.uk> Date: Wed, 27 Mar 2019 12:12:51 +0000 Subject: [PATCH] Free space used by foreign particles before attempting a repartition, this frees space for the particle type copy we need --- src/engine.c | 6 +++++- src/space.c | 28 ++++++++++++++++++++++++++++ src/space.h | 2 ++ 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/engine.c b/src/engine.c index 52a2e13c0f..05b1e937b7 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1007,7 +1007,8 @@ void engine_repartition(struct engine *e) { /* Partitioning requires copies of the particles, so we need to reduce the * memory in use to the minimum, we can free the sorting indices and the - * tasks as these will be regenerated at the next rebuild. */ + * tasks as these will be regenerated at the next rebuild. Also the foreign + * particle arrays can go as these will be regenerated in proxy exchange. */ /* Sorting indices. */ if (e->s->cells_top != NULL) space_free_cells(e->s); @@ -1015,6 +1016,9 @@ void engine_repartition(struct engine *e) { /* Task arrays. */ scheduler_free_tasks(&e->sched); + /* Foreign parts. */ + space_free_foreign_parts(e->s); + /* Now comes the tricky part: Exchange particles between all nodes. This is done in two steps, first allreducing a matrix of how many particles go from where to where, then re-allocating diff --git a/src/space.c b/src/space.c index 9161e578d0..120f95c80e 100644 --- a/src/space.c +++ b/src/space.c @@ -294,6 +294,8 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, /** * @brief Free up any allocated cells. + * + * @param s The #space. */ void space_free_cells(struct space *s) { @@ -308,6 +310,32 @@ void space_free_cells(struct space *s) { clocks_getunit()); } +/** + * @brief Free any memory in use for foreign particles. + * + * @param s The #space. + */ +void space_free_foreign_parts(struct space *s) { + +#ifdef WITH_MPI + if (s->parts_foreign != NULL) { + free(s->parts_foreign); + s->size_parts_foreign = 0; + s->parts_foreign = NULL; + } + if (s->gparts_foreign != NULL) { + free(s->gparts_foreign); + s->size_gparts_foreign = 0; + s->gparts_foreign = NULL; + } + if (s->sparts_foreign != NULL) { + free(s->sparts_foreign); + s->size_sparts_foreign = 0; + s->sparts_foreign = NULL; + } +#endif +} + /** * @brief Re-build the top-level cell grid. * diff --git a/src/space.h b/src/space.h index 924c3efaf8..272ee41c35 100644 --- a/src/space.h +++ b/src/space.h @@ -329,6 +329,8 @@ void space_reset_task_counters(struct space *s); void space_clean(struct space *s); void space_free_cells(struct space *s); +void space_free_foreign_parts(struct space *s); + void space_struct_dump(struct space *s, FILE *stream); void space_struct_restore(struct space *s, FILE *stream); void space_write_cell_hierarchy(const struct space *s); -- GitLab