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

Calculate the number of groups after the union-find in one pass over the pid array.

parent 00ea9c0a
No related branches found
No related tags found
1 merge request!543Fof
...@@ -86,7 +86,7 @@ __attribute__((always_inline)) INLINE static double cell_min_dist( ...@@ -86,7 +86,7 @@ __attribute__((always_inline)) INLINE static double cell_min_dist(
/* Recurse on a pair of cells and perform a FOF search between cells that are within /* Recurse on a pair of cells and perform a FOF search between cells that are within
* range. */ * range. */
static void rec_fof_search_pair(struct cell *ci, struct cell *cj, struct space *s, static void rec_fof_search_pair(struct cell *ci, struct cell *cj, struct space *s,
int *pid, int *num_groups, const double *dim, int *pid, const double *dim,
const double search_r2) { const double search_r2) {
/* Find the shortest distance between cells, remembering to account for /* Find the shortest distance between cells, remembering to account for
...@@ -102,14 +102,14 @@ static void rec_fof_search_pair(struct cell *ci, struct cell *cj, struct space * ...@@ -102,14 +102,14 @@ static void rec_fof_search_pair(struct cell *ci, struct cell *cj, struct space *
for (int l = 0; l < 8; l++) for (int l = 0; l < 8; l++)
if (cj->progeny[l] != NULL) if (cj->progeny[l] != NULL)
rec_fof_search_pair(ci->progeny[k], cj->progeny[l], s, pid, num_groups, dim, search_r2); rec_fof_search_pair(ci->progeny[k], cj->progeny[l], s, pid, dim, search_r2);
} }
} }
} }
/* Perform FOF search between pairs of cells that are within the linking /* Perform FOF search between pairs of cells that are within the linking
* length and not the same cell. */ * length and not the same cell. */
else if (ci != cj) else if (ci != cj)
fof_search_pair_cells(s, ci, cj, pid, num_groups); fof_search_pair_cells(s, ci, cj, pid);
else if (ci == cj) error("Pair FOF called on same cell!!!"); else if (ci == cj) error("Pair FOF called on same cell!!!");
} }
...@@ -117,7 +117,7 @@ static void rec_fof_search_pair(struct cell *ci, struct cell *cj, struct space * ...@@ -117,7 +117,7 @@ static void rec_fof_search_pair(struct cell *ci, struct cell *cj, struct space *
/* Recurse on a cell and perform a FOF search between cells that are within /* Recurse on a cell and perform a FOF search between cells that are within
* range. */ * range. */
static void rec_fof_search_self(struct cell *ci, struct space *s, static void rec_fof_search_self(struct cell *ci, struct space *s,
int *pid, int *num_groups, const double *dim, int *pid, const double *dim,
const double search_r2) { const double search_r2) {
/* Recurse? */ /* Recurse? */
...@@ -127,17 +127,17 @@ static void rec_fof_search_self(struct cell *ci, struct space *s, ...@@ -127,17 +127,17 @@ static void rec_fof_search_self(struct cell *ci, struct space *s,
for (int k = 0; k < 8; k++) { for (int k = 0; k < 8; k++) {
if (ci->progeny[k] != NULL) { if (ci->progeny[k] != NULL) {
rec_fof_search_self(ci->progeny[k], s, pid, num_groups, dim, search_r2); rec_fof_search_self(ci->progeny[k], s, pid, dim, search_r2);
for (int l = k+1; l < 8; l++) for (int l = k+1; l < 8; l++)
if (ci->progeny[l] != NULL) if (ci->progeny[l] != NULL)
rec_fof_search_pair(ci->progeny[k], ci->progeny[l], s, pid, num_groups, dim, search_r2); rec_fof_search_pair(ci->progeny[k], ci->progeny[l], s, pid, dim, search_r2);
} }
} }
} }
/* Otherwise, compute self-interaction. */ /* Otherwise, compute self-interaction. */
else else
fof_search_cell(s, ci, pid, num_groups); fof_search_cell(s, ci, pid);
} }
/* Perform naive N^2 FOF search on gravity particles using the Union-Find /* Perform naive N^2 FOF search on gravity particles using the Union-Find
...@@ -150,7 +150,7 @@ void fof_search_serial(struct space *s) { ...@@ -150,7 +150,7 @@ void fof_search_serial(struct space *s) {
const double l_x2 = s->l_x2; const double l_x2 = s->l_x2;
int *pid; int *pid;
int *group_sizes; int *group_sizes;
int num_groups = nr_gparts; int num_groups = 0;
message("Searching %ld gravity particles for links with l_x2: %lf", nr_gparts, message("Searching %ld gravity particles for links with l_x2: %lf", nr_gparts,
l_x2); l_x2);
...@@ -216,13 +216,15 @@ void fof_search_serial(struct space *s) { ...@@ -216,13 +216,15 @@ void fof_search_serial(struct space *s) {
else else
pid[root_j] = root_i; pid[root_j] = root_i;
num_groups--;
} }
} }
} }
/* Calculate the total number of particles in each group. */ /* Calculate the total number of particles in each group and total number of groups. */
for (size_t i = 0; i < nr_gparts; i++) group_sizes[fof_find(i, pid)]++; for (size_t i = 0; i < nr_gparts; i++) {
group_sizes[fof_find(i, pid)]++;
if(pid[i] == i) num_groups++;
}
fof_dump_group_data("fof_output_serial.dat", nr_gparts, pid, group_sizes); fof_dump_group_data("fof_output_serial.dat", nr_gparts, pid, group_sizes);
...@@ -248,8 +250,7 @@ void fof_search_serial(struct space *s) { ...@@ -248,8 +250,7 @@ void fof_search_serial(struct space *s) {
} }
/* Perform a FOF search on a single cell using the Union-Find algorithm.*/ /* Perform a FOF search on a single cell using the Union-Find algorithm.*/
void fof_search_cell(struct space *s, struct cell *c, int *pid, void fof_search_cell(struct space *s, struct cell *c, int *pid) {
int *num_groups) {
const size_t count = c->gcount; const size_t count = c->gcount;
struct gpart *gparts = c->gparts; struct gpart *gparts = c->gparts;
...@@ -307,7 +308,6 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid, ...@@ -307,7 +308,6 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid,
else else
pid[root_j] = root_i; pid[root_j] = root_i;
(*num_groups)--;
} }
} }
} }
...@@ -315,7 +315,7 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid, ...@@ -315,7 +315,7 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid,
/* Perform a FOF search on a pair of cells using the Union-Find algorithm.*/ /* Perform a FOF search on a pair of cells using the Union-Find algorithm.*/
void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj, void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj,
int *pid, int *num_groups) { int *pid) {
const size_t count_i = ci->gcount; const size_t count_i = ci->gcount;
const size_t count_j = cj->gcount; const size_t count_j = cj->gcount;
...@@ -390,7 +390,6 @@ void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj, ...@@ -390,7 +390,6 @@ void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj,
else else
pid[root_j] = root_i; pid[root_j] = root_i;
(*num_groups)--;
} }
} }
} }
...@@ -403,7 +402,7 @@ void fof_search_tree_serial(struct space *s) { ...@@ -403,7 +402,7 @@ void fof_search_tree_serial(struct space *s) {
const size_t nr_gparts = s->nr_gparts; const size_t nr_gparts = s->nr_gparts;
const size_t nr_cells = s->nr_cells; const size_t nr_cells = s->nr_cells;
int *pid, *group_sizes; int *pid, *group_sizes;
int num_groups = nr_gparts; int num_groups = 0;
struct gpart *gparts = s->gparts; struct gpart *gparts = s->gparts;
const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]}; const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]};
const double search_r2 = s->l_x2; const double search_r2 = s->l_x2;
...@@ -436,7 +435,7 @@ void fof_search_tree_serial(struct space *s) { ...@@ -436,7 +435,7 @@ void fof_search_tree_serial(struct space *s) {
if(ci->gcount == 0) continue; if(ci->gcount == 0) continue;
/* Perform FOF search on local particles within the cell. */ /* Perform FOF search on local particles within the cell. */
rec_fof_search_self(ci, s, pid, &num_groups, dim, search_r2); rec_fof_search_self(ci, s, pid, dim, search_r2);
/* Loop over all top-level cells skipping over the cells already searched. /* Loop over all top-level cells skipping over the cells already searched.
*/ */
...@@ -447,12 +446,15 @@ void fof_search_tree_serial(struct space *s) { ...@@ -447,12 +446,15 @@ void fof_search_tree_serial(struct space *s) {
/* Skip empty cells. */ /* Skip empty cells. */
if(cj->gcount == 0) continue; if(cj->gcount == 0) continue;
rec_fof_search_pair(ci, cj, s, pid, &num_groups, dim, search_r2); rec_fof_search_pair(ci, cj, s, pid, dim, search_r2);
} }
} }
/* Calculate the total number of particles in each group. */ /* Calculate the total number of particles in each group and total number of groups. */
for (size_t i = 0; i < nr_gparts; i++) group_sizes[fof_find(i, pid)]++; for (size_t i = 0; i < nr_gparts; i++) {
group_sizes[fof_find(i, pid)]++;
if(pid[i] == i) num_groups++;
}
fof_dump_group_data("fof_output_tree_serial.dat", nr_gparts, pid, fof_dump_group_data("fof_output_tree_serial.dat", nr_gparts, pid,
group_sizes); group_sizes);
......
...@@ -29,10 +29,9 @@ ...@@ -29,10 +29,9 @@
/* Function prototypes. */ /* Function prototypes. */
void fof_search_serial(struct space *s); void fof_search_serial(struct space *s);
void fof_search_cell(struct space *s, struct cell *c, int *pid, void fof_search_cell(struct space *s, struct cell *c, int *pid);
int *num_groups);
void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj, void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj,
int *pid, int *num_groups); int *pid);
void fof_search_tree_serial(struct space *s); void fof_search_tree_serial(struct space *s);
void fof_dump_group_data(char *out_file, const size_t nr_gparts, int *pid, void fof_dump_group_data(char *out_file, const size_t nr_gparts, int *pid,
int *num_in_groups); int *num_in_groups);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment