Skip to content
Snippets Groups Projects
Commit a7ef7b4c authored by James Willis's avatar James Willis
Browse files

Free memory as soon as it is used. Break after finding a local cell is in...

Free memory as soon as it is used. Break after finding a local cell is in range of a foreign cell when populating the interface_cell array.
parent 47c3e8e4
No related branches found
No related tags found
1 merge request!543Fof
...@@ -897,26 +897,29 @@ void fof_search_foreign_cells(struct space *s) { ...@@ -897,26 +897,29 @@ void fof_search_foreign_cells(struct space *s) {
for(int j=0; j<e->proxies[i].nr_cells_out; j++) { for(int j=0; j<e->proxies[i].nr_cells_out; j++) {
/* Skip non-gravity cells. */
if(e->proxies[i].cells_out_type[j] != proxy_cell_type_gravity) continue;
struct cell *restrict local_cell = e->proxies[i].cells_out[j]; struct cell *restrict local_cell = e->proxies[i].cells_out[j];
int found = 0;
/* Skip empty cells. */ /* Skip empty cells. */
if(local_cell->gcount == 0) continue; if(local_cell->gcount == 0) continue;
for(int k=0; k<e->proxies[i].nr_cells_in; k++) { for(int k=0; k<e->proxies[i].nr_cells_in; k++) {
/* Skip non-gravity cells. */
if(e->proxies[i].cells_in_type[k] != proxy_cell_type_gravity) continue;
struct cell *restrict foreign_cell = e->proxies[i].cells_in[k]; struct cell *restrict foreign_cell = e->proxies[i].cells_in[k];
/* Skip empty cells. */ /* Skip empty cells. */
if(foreign_cell->gcount == 0) continue; if(foreign_cell->gcount == 0) continue;
/* Check if local cell has already been added to the local list of cells. */ /* Check if local cell has already been added to the local list of cells. */
if(!found) { const double r2 = cell_min_dist(local_cell, foreign_cell, dim);
const double r2 = cell_min_dist(local_cell, foreign_cell, dim); if(r2 < search_r2) {
if(r2 < search_r2) { interface_cells[interface_cell_count++] = local_cell;
interface_cells[interface_cell_count++] = local_cell; break;
found = 1;
}
} }
} }
} }
...@@ -992,6 +995,9 @@ void fof_search_foreign_cells(struct space *s) { ...@@ -992,6 +995,9 @@ void fof_search_foreign_cells(struct space *s) {
} }
} }
} }
/* Clean up memory. */
free(interface_cells);
message("Rank %d found %zu links between local and foreign groups.", engine_rank, part_link_count); message("Rank %d found %zu links between local and foreign groups.", engine_rank, part_link_count);
...@@ -1033,6 +1039,9 @@ void fof_search_foreign_cells(struct space *s) { ...@@ -1033,6 +1039,9 @@ void fof_search_foreign_cells(struct space *s) {
} }
} }
/* Clean up memory. */
free(part_links);
message("Rank %d found %d unique group links.", engine_rank, group_link_count); message("Rank %d found %d unique group links.", engine_rank, group_link_count);
...@@ -1067,6 +1076,10 @@ void fof_search_foreign_cells(struct space *s) { ...@@ -1067,6 +1076,10 @@ void fof_search_foreign_cells(struct space *s) {
/* Gather the global link list on all ranks. */ /* Gather the global link list on all ranks. */
MPI_Allgatherv(group_links, group_link_count, fof_mpi_type, global_group_links, group_link_counts, displ, fof_mpi_type, MPI_COMM_WORLD); MPI_Allgatherv(group_links, group_link_count, fof_mpi_type, global_group_links, group_link_counts, displ, fof_mpi_type, MPI_COMM_WORLD);
/* Clean up memory. */
free(displ);
free(group_links);
/* Transform the group IDs to a local list going from 0-group_count so a union-find can be performed. */ /* Transform the group IDs to a local list going from 0-group_count so a union-find can be performed. */
int *global_group_index = NULL, *global_group_id = NULL, *global_group_size = NULL; int *global_group_index = NULL, *global_group_id = NULL, *global_group_size = NULL;
...@@ -1259,11 +1272,7 @@ void fof_search_foreign_cells(struct space *s) { ...@@ -1259,11 +1272,7 @@ void fof_search_foreign_cells(struct space *s) {
} }
/* Clean up memory. */ /* Clean up memory. */
free(part_links);
free(interface_cells);
free(group_links);
free(global_group_links); free(global_group_links);
free(displ);
free(global_group_index); free(global_group_index);
free(global_group_size); free(global_group_size);
free(global_group_mass); free(global_group_mass);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment