Commit ce2c2715 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'free_proxy_mem' into 'master'

Free unnecessary proxy memory

See merge request !1026
parents e67aeacc 2ed54732
......@@ -487,12 +487,13 @@ void engine_exchange_cells(struct engine *e) {
* gparts, i.e. the received particles have correct linkeage.
*/
void engine_exchange_strays(struct engine *e, const size_t offset_parts,
const int *ind_part, size_t *Npart,
const size_t offset_gparts, const int *ind_gpart,
size_t *Ngpart, const size_t offset_sparts,
const int *ind_spart, size_t *Nspart,
const size_t offset_bparts, const int *ind_bpart,
size_t *Nbpart) {
const int *restrict ind_part, size_t *Npart,
const size_t offset_gparts,
const int *restrict ind_gpart, size_t *Ngpart,
const size_t offset_sparts,
const int *restrict ind_spart, size_t *Nspart,
const size_t offset_bparts,
const int *restrict ind_bpart, size_t *Nbpart) {
#ifdef WITH_MPI
struct space *s = e->s;
......@@ -983,6 +984,11 @@ void engine_exchange_strays(struct engine *e, const size_t offset_parts,
MPI_SUCCESS)
error("MPI_Waitall on sends failed.");
/* Free the proxy memory */
for (int k = 0; k < e->nr_proxies; k++) {
proxy_free_particle_buffers(&e->proxies[k]);
}
if (e->verbose)
message("took %.3f %s.", clocks_from_ticks(getticks() - tic),
clocks_getunit());
......
......@@ -3418,6 +3418,12 @@ void engine_maketasks(struct engine *e) {
e->nr_links, e->size_links, (float)e->nr_links / (float)e->size_links,
e->size_links * sizeof(struct link) / (1024 * 1024));
/* Report the values that could have been used */
if (e->verbose)
message("Actual usage: tasks/cell: %f links/task: %f",
(float)e->sched.nr_tasks / s->tot_cells,
(float)e->nr_links / e->sched.nr_tasks);
tic2 = getticks();
/* Set the unlocks per task. */
......
......@@ -486,6 +486,12 @@ void proxy_cells_exchange(struct proxy *proxies, int num_proxies,
free(reqs);
swift_free("pcells", pcells);
swift_free("proxy_cell_offset", offset);
for (int k = 0; k < num_proxies; k++) {
swift_free("pcells_in", proxies[k].pcells_in);
swift_free("pcells_out", proxies[k].pcells_out);
proxies[k].pcells_in = NULL;
proxies[k].pcells_out = NULL;
}
#else
error("SWIFT was not compiled with MPI support.");
......@@ -518,18 +524,19 @@ void proxy_addcell_in(struct proxy *p, struct cell *c, int type) {
p->size_cells_in *= proxy_buffgrow;
struct cell **temp_cell;
if ((temp_cell = (struct cell **)malloc(sizeof(struct cell *) *
p->size_cells_in)) == NULL)
if ((temp_cell = (struct cell **)swift_malloc(
"cells_in", sizeof(struct cell *) * p->size_cells_in)) == NULL)
error("Failed to allocate incoming cell list.");
memcpy(temp_cell, p->cells_in, sizeof(struct cell *) * p->nr_cells_in);
free(p->cells_in);
swift_free("cells_in", p->cells_in);
p->cells_in = temp_cell;
int *temp_type;
if ((temp_type = (int *)malloc(sizeof(int) * p->size_cells_in)) == NULL)
if ((temp_type = (int *)swift_malloc(
"cells_in_type", sizeof(int) * p->size_cells_in)) == NULL)
error("Failed to allocate incoming cell type list.");
memcpy(temp_type, p->cells_in_type, sizeof(int) * p->nr_cells_in);
free(p->cells_in_type);
swift_free("cells_in_type", p->cells_in_type);
p->cells_in_type = temp_type;
}
......@@ -564,18 +571,19 @@ void proxy_addcell_out(struct proxy *p, struct cell *c, int type) {
p->size_cells_out *= proxy_buffgrow;
struct cell **temp_cell;
if ((temp_cell = (struct cell **)malloc(sizeof(struct cell *) *
p->size_cells_out)) == NULL)
if ((temp_cell = (struct cell **)swift_malloc(
"cells_out", sizeof(struct cell *) * p->size_cells_out)) == NULL)
error("Failed to allocate outgoing cell list.");
memcpy(temp_cell, p->cells_out, sizeof(struct cell *) * p->nr_cells_out);
free(p->cells_out);
swift_free("cells_out", p->cells_out);
p->cells_out = temp_cell;
int *temp_type;
if ((temp_type = (int *)malloc(sizeof(int) * p->size_cells_out)) == NULL)
if ((temp_type = (int *)swift_malloc(
"cells_out_type", sizeof(int) * p->size_cells_out)) == NULL)
error("Failed to allocate outgoing cell type list.");
memcpy(temp_type, p->cells_out_type, sizeof(int) * p->nr_cells_out);
free(p->cells_out_type);
swift_free("cells_out_type", p->cells_out_type);
p->cells_out_type = temp_type;
}
......@@ -881,6 +889,81 @@ void proxy_bparts_load(struct proxy *p, const struct bpart *bparts, int N) {
p->nr_bparts_out += N;
}
/**
* @brief Frees the memory allocated for the particle proxies and sets their
* size back to the initial state.
*
* @param p The #proxy.
*/
void proxy_free_particle_buffers(struct proxy *p) {
if (p->size_parts_out > proxy_buffinit) {
swift_free("parts_out", p->parts_out);
p->size_parts_out = proxy_buffinit;
if ((p->parts_out = (struct part *)swift_malloc(
"parts_out", sizeof(struct part) * p->size_parts_out)) == NULL)
error("Failed to allocate parts_out buffers.");
if ((p->xparts_out = (struct xpart *)swift_malloc(
"xparts_out", sizeof(struct xpart) * p->size_parts_out)) == NULL)
error("Failed to allocate xparts_out buffers.");
}
if (p->size_parts_in > proxy_buffinit) {
swift_free("parts_in", p->parts_in);
p->size_parts_in = proxy_buffinit;
if ((p->parts_in = (struct part *)swift_malloc(
"parts_in", sizeof(struct part) * p->size_parts_in)) == NULL)
error("Failed to allocate parts_in buffers.");
if ((p->xparts_in = (struct xpart *)swift_malloc(
"xparts_in", sizeof(struct xpart) * p->size_parts_in)) == NULL)
error("Failed to allocate xparts_in buffers.");
}
if (p->size_gparts_out > proxy_buffinit) {
swift_free("gparts_out", p->gparts_out);
p->size_gparts_out = proxy_buffinit;
if ((p->gparts_out = (struct gpart *)swift_malloc(
"gparts_out", sizeof(struct gpart) * p->size_gparts_out)) == NULL)
error("Failed to allocate gparts_out buffers.");
}
if (p->size_gparts_in > proxy_buffinit) {
swift_free("gparts_in", p->gparts_in);
p->size_gparts_in = proxy_buffinit;
if ((p->gparts_in = (struct gpart *)swift_malloc(
"gparts_in", sizeof(struct gpart) * p->size_gparts_in)) == NULL)
error("Failed to allocate gparts_in buffers.");
}
if (p->size_sparts_out > proxy_buffinit) {
swift_free("sparts_out", p->sparts_out);
p->size_sparts_out = proxy_buffinit;
if ((p->sparts_out = (struct spart *)swift_malloc(
"sparts_out", sizeof(struct spart) * p->size_sparts_out)) == NULL)
error("Failed to allocate sparts_out buffers.");
}
if (p->size_sparts_in > proxy_buffinit) {
swift_free("sparts_in", p->sparts_in);
p->size_sparts_in = proxy_buffinit;
if ((p->sparts_in = (struct spart *)swift_malloc(
"sparts_in", sizeof(struct spart) * p->size_sparts_in)) == NULL)
error("Failed to allocate sparts_in buffers.");
}
if (p->size_bparts_out > proxy_buffinit) {
swift_free("bparts_out", p->bparts_out);
p->size_bparts_out = proxy_buffinit;
if ((p->bparts_out = (struct bpart *)swift_malloc(
"bparts_out", sizeof(struct bpart) * p->size_bparts_out)) == NULL)
error("Failed to allocate bparts_out buffers.");
}
if (p->size_bparts_in > proxy_buffinit) {
swift_free("bparts_in", p->bparts_in);
p->size_bparts_in = proxy_buffinit;
if ((p->bparts_in = (struct bpart *)swift_malloc(
"bparts_in", sizeof(struct bpart) * p->size_bparts_in)) == NULL)
error("Failed to allocate bparts_in buffers.");
}
}
/**
* @brief Initialize the given proxy.
*
......@@ -897,21 +980,21 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
/* Allocate the cell send and receive buffers, if needed. */
if (p->cells_in == NULL) {
p->size_cells_in = proxy_buffinit;
if ((p->cells_in =
(struct cell **)malloc(sizeof(void *) * p->size_cells_in)) == NULL)
if ((p->cells_in = (struct cell **)swift_malloc(
"cells_in", sizeof(void *) * p->size_cells_in)) == NULL)
error("Failed to allocate cells_in buffer.");
if ((p->cells_in_type = (int *)malloc(sizeof(int) * p->size_cells_in)) ==
NULL)
if ((p->cells_in_type = (int *)swift_malloc(
"cells_in_type", sizeof(int) * p->size_cells_in)) == NULL)
error("Failed to allocate cells_in_type buffer.");
}
p->nr_cells_in = 0;
if (p->cells_out == NULL) {
p->size_cells_out = proxy_buffinit;
if ((p->cells_out = (struct cell **)malloc(sizeof(void *) *
p->size_cells_out)) == NULL)
if ((p->cells_out = (struct cell **)swift_malloc(
"cells_out", sizeof(void *) * p->size_cells_out)) == NULL)
error("Failed to allocate cells_out buffer.");
if ((p->cells_out_type = (int *)malloc(sizeof(int) * p->size_cells_out)) ==
NULL)
if ((p->cells_out_type = (int *)swift_malloc(
"cells_out_type", sizeof(int) * p->size_cells_out)) == NULL)
error("Failed to allocate cells_out_type buffer.");
}
p->nr_cells_out = 0;
......@@ -990,10 +1073,10 @@ void proxy_init(struct proxy *p, int mynodeID, int nodeID) {
*/
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("cells_in", p->cells_in);
swift_free("cells_out", p->cells_out);
swift_free("cells_in_type", p->cells_in_type);
swift_free("cells_out_type", 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);
......
......@@ -104,6 +104,7 @@ void proxy_parts_load(struct proxy *p, const struct part *parts,
void proxy_gparts_load(struct proxy *p, const struct gpart *gparts, int N);
void proxy_sparts_load(struct proxy *p, const struct spart *sparts, int N);
void proxy_bparts_load(struct proxy *p, const struct bpart *bparts, int N);
void proxy_free_particle_buffers(struct proxy *p);
void proxy_parts_exchange_first(struct proxy *p);
void proxy_parts_exchange_second(struct proxy *p);
void proxy_addcell_in(struct proxy *p, struct cell *c, int type);
......
......@@ -1321,6 +1321,8 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) {
"counter.");
#endif
const ticks tic2 = getticks();
/* Move non-local parts and inhibited parts to the end of the list. */
if ((with_dithering || !repartitioned) &&
(s->e->nr_nodes > 1 || count_inhibited_parts > 0)) {
......@@ -1520,6 +1522,10 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) {
}
}
if (verbose)
message("Moving non-local particles took %.3f %s.",
clocks_from_ticks(getticks() - tic2), clocks_getunit());
#ifdef SWIFT_DEBUG_CHECKS
/* Check that all gparts are in the correct place. */
size_t check_count_inhibited_gpart = 0;
......@@ -1900,7 +1906,7 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) {
#endif
/* Hook the cells up to the parts. Make list of local and non-empty cells */
ticks tic2 = getticks();
const ticks tic3 = getticks();
struct part *finger = s->parts;
struct xpart *xfinger = s->xparts;
struct gpart *gfinger = s->gparts;
......@@ -1966,7 +1972,7 @@ void space_rebuild(struct space *s, int repartitioned, int verbose) {
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());
clocks_from_ticks(getticks() - tic3), clocks_getunit());
}
/* Re-order the extra particles such that they are at the end of their cell's
......
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