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

Find the root of pi in the outer loop and update it on the fly in the inner...

Find the root of pi in the outer loop and update it on the fly in the inner loop. Saves having to call fof_find at every iteration of the inner loop.
parent 4e7b4d49
No related branches found
No related tags found
1 merge request!543Fof
...@@ -258,6 +258,9 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid, ...@@ -258,6 +258,9 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid,
const double piz = pi->x[2]; const double piz = pi->x[2];
const size_t offset_i = pi->offset; const size_t offset_i = pi->offset;
/* Find the root of pi. */
int root_i = fof_find(offset_i, pid);
for (size_t j = i + 1; j < count; j++) { for (size_t j = i + 1; j < count; j++) {
struct gpart *pj = &gparts[j]; struct gpart *pj = &gparts[j];
...@@ -278,8 +281,7 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid, ...@@ -278,8 +281,7 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid,
r2 += dx[k] * dx[k]; r2 += dx[k] * dx[k];
} }
/* Find the roots of pi and pj. */ /* Find the root of pj. */
const int root_i = fof_find(offset_i, pid);
const int root_j = fof_find(offset_j, pid); const int root_j = fof_find(offset_j, pid);
/* Skip particles in the same group. */ /* Skip particles in the same group. */
...@@ -288,8 +290,13 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid, ...@@ -288,8 +290,13 @@ void fof_search_cell(struct space *s, struct cell *c, int *pid,
/* Hit or miss? */ /* Hit or miss? */
if (r2 < l_x2) { if (r2 < l_x2) {
if (root_j < root_i) /* If the root ID of pj is lower than pi's root ID set pi's root to point to pj's.
* Otherwise set pj's to root to point to pi's.*/
if (root_j < root_i) {
pid[root_i] = root_j; pid[root_i] = root_j;
/* Update root_i on the fly. */
root_i = root_j;
}
else else
pid[root_j] = root_i; pid[root_j] = root_i;
...@@ -336,13 +343,15 @@ void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj, ...@@ -336,13 +343,15 @@ void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj,
const double piz = pi->x[2] - shift[2]; const double piz = pi->x[2] - shift[2];
const size_t offset_i = pi->offset; const size_t offset_i = pi->offset;
/* Find the root of pi. */
int root_i = fof_find(offset_i, pid);
for (size_t j = 0; j < count_j; j++) { for (size_t j = 0; j < count_j; j++) {
struct gpart *pj = &gparts_j[j]; struct gpart *pj = &gparts_j[j];
const size_t offset_j = pj->offset; const size_t offset_j = pj->offset;
/* Find the roots of pi and pj. */ /* Find the root of pj. */
const int root_i = fof_find(offset_i, pid);
const int root_j = fof_find(offset_j, pid); const int root_j = fof_find(offset_j, pid);
/* Skip particles in the same group. */ /* Skip particles in the same group. */
...@@ -364,8 +373,13 @@ void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj, ...@@ -364,8 +373,13 @@ void fof_search_pair_cells(struct space *s, struct cell *ci, struct cell *cj,
/* Hit or miss? */ /* Hit or miss? */
if (r2 < l_x2) { if (r2 < l_x2) {
if (root_j < root_i) /* If the root ID of pj is lower than pi's root ID set pi's root to point to pj's.
* Otherwise set pj's to root to point to pi's.*/
if (root_j < root_i) {
pid[root_i] = root_j; pid[root_i] = root_j;
/* Update root_i on the fly. */
root_i = root_j;
}
else else
pid[root_j] = root_i; pid[root_j] = root_i;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment