Commit a06eedec authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Clean up the memory allocated in the proxies when exiting a calculation.

parent 5613efe0
......@@ -37,6 +37,7 @@
/* MPI headers. */
#ifdef WITH_MPI
#include <mpi.h>
#endif
......@@ -1113,8 +1114,7 @@ void engine_allocate_foreign_particles(struct engine *e) {
/* Allocate space for the foreign particles we will receive */
if (count_parts_in > s->size_parts_foreign) {
if (s->parts_foreign != NULL)
swift_free("sparts_foreign", s->parts_foreign);
if (s->parts_foreign != NULL) swift_free("parts_foreign", s->parts_foreign);
s->size_parts_foreign = engine_foreign_alloc_margin * count_parts_in;
if (swift_memalign("parts_foreign", (void **)&s->parts_foreign, part_align,
sizeof(struct part) * s->size_parts_foreign) != 0)
......@@ -4687,6 +4687,13 @@ void engine_clean(struct engine *e, const int fof) {
scheduler_clean(&e->sched);
space_clean(e->s);
threadpool_clean(&e->threadpool);
#if defined(WITH_MPI)
for (int i = 0; i < e->nr_proxies; ++i) {
proxy_clean(&e->proxies[i]);
}
free(e->proxy_ind);
free(e->proxies);
#endif
/* Close files */
if (!fof && e->nodeID == 0) {
......
......@@ -983,6 +983,29 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
p->nr_bparts_out = 0;
}
/**
* @brief Free the memory allocated by a #proxy
*/
void proxy_clean(struct proxy *p) {
free(p->cells_in);
free(p->cells_out);
free(p->cells_in_type);
free(p->cells_out_type);
swift_free("pcells_in", p->pcells_in);
swift_free("pcells_out", p->pcells_out);
swift_free("parts_out", p->parts_out);
swift_free("xparts_out", p->xparts_out);
swift_free("gparts_out", p->gparts_out);
swift_free("sparts_out", p->sparts_out);
swift_free("bparts_out", p->bparts_out);
swift_free("parts_in", p->parts_in);
swift_free("xparts_in", p->xparts_in);
swift_free("gparts_in", p->gparts_in);
swift_free("sparts_in", p->sparts_in);
swift_free("bparts_in", p->bparts_in);
}
/**
* @brief Registers the MPI types for the proxy cells.
*/
......
......@@ -98,6 +98,7 @@ struct proxy {
/* Function prototypes. */
void proxy_init(struct proxy *p, int mynodeID, int nodeID);
void proxy_clean(struct proxy *p);
void proxy_parts_load(struct proxy *p, const struct part *parts,
const struct xpart *xparts, int N);
void proxy_gparts_load(struct proxy *p, const struct gpart *gparts, int N);
......
......@@ -5462,6 +5462,12 @@ void space_clean(struct space *s) {
swift_free("gparts", s->gparts);
swift_free("sparts", s->sparts);
swift_free("bparts", s->bparts);
#ifdef WITH_MPI
swift_free("parts_foreign", s->parts_foreign);
swift_free("sparts_foreign", s->sparts_foreign);
swift_free("gparts_foreign", s->gparts_foreign);
swift_free("bparts_foreign", s->bparts_foreign);
#endif
}
/**
......
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