diff --git a/src/cell.h b/src/cell.h index 7fda5fb40c69e1bc83a367265a0fbe9afb9ff266..a64cc3fe423700e122e852c1fe982adc8046a2bf 100644 --- a/src/cell.h +++ b/src/cell.h @@ -671,67 +671,62 @@ int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, const struct engine *e, const struct space *s); /** - * @brief Compute the sqaure of the minimal distance between any two points in two cells of the same size + * @brief Compute the sqaure of the minimal distance between any two points in + * two cells of the same size * * @param ci The first #cell. * @param cj The second #cell. * @param periodic Are we using periodic BCs? * @param dim The dimensions of the simulation volume */ -__attribute__((always_inline)) INLINE static double -cell_min_dist2_same_size(const struct cell *restrict ci, const struct cell *restrict cj, const int periodic, - const double dim[3]) { +__attribute__((always_inline)) INLINE static double cell_min_dist2_same_size( + const struct cell *restrict ci, const struct cell *restrict cj, + const int periodic, const double dim[3]) { #ifdef SWIFT_DEBUG_CHECKS - if (ci->width[0] != cj->width[0]) - error("Cells of different size!"); - if (ci->width[1] != cj->width[1]) - error("Cells of different size!"); - if (ci->width[2] != cj->width[2]) - error("Cells of different size!"); + if (ci->width[0] != cj->width[0]) error("Cells of different size!"); + if (ci->width[1] != cj->width[1]) error("Cells of different size!"); + if (ci->width[2] != cj->width[2]) error("Cells of different size!"); #endif - const double cix_min = ci->loc[0]; - const double ciy_min = ci->loc[1]; - const double ciz_min = ci->loc[2]; - const double cjx_min = cj->loc[0]; - const double cjy_min = cj->loc[1]; - const double cjz_min = cj->loc[2]; - - const double cix_max = ci->loc[0] + ci->width[0]; - const double ciy_max = ci->loc[1] + ci->width[1]; - const double ciz_max = ci->loc[2] + ci->width[2]; - const double cjx_max = cj->loc[0] + cj->width[0]; - const double cjy_max = cj->loc[1] + cj->width[1]; + const double cix_min = ci->loc[0]; + const double ciy_min = ci->loc[1]; + const double ciz_min = ci->loc[2]; + const double cjx_min = cj->loc[0]; + const double cjy_min = cj->loc[1]; + const double cjz_min = cj->loc[2]; + + const double cix_max = ci->loc[0] + ci->width[0]; + const double ciy_max = ci->loc[1] + ci->width[1]; + const double ciz_max = ci->loc[2] + ci->width[2]; + const double cjx_max = cj->loc[0] + cj->width[0]; + const double cjy_max = cj->loc[1] + cj->width[1]; const double cjz_max = cj->loc[2] + cj->width[2]; if (periodic) { const double dx = min4(fabs(nearest(cix_min - cjx_min, dim[0])), - fabs(nearest(cix_min - cjx_max, dim[0])), - fabs(nearest(cix_max - cjx_min, dim[0])), - fabs(nearest(cix_max - cjx_max, dim[0]))); - + fabs(nearest(cix_min - cjx_max, dim[0])), + fabs(nearest(cix_max - cjx_min, dim[0])), + fabs(nearest(cix_max - cjx_max, dim[0]))); + const double dy = min4(fabs(nearest(ciy_min - cjy_min, dim[1])), - fabs(nearest(ciy_min - cjy_max, dim[1])), - fabs(nearest(ciy_max - cjy_min, dim[1])), - fabs(nearest(ciy_max - cjy_max, dim[1]))); - + fabs(nearest(ciy_min - cjy_max, dim[1])), + fabs(nearest(ciy_max - cjy_min, dim[1])), + fabs(nearest(ciy_max - cjy_max, dim[1]))); + const double dz = min4(fabs(nearest(ciz_min - cjz_min, dim[2])), - fabs(nearest(ciz_min - cjz_max, dim[2])), - fabs(nearest(ciz_max - cjz_min, dim[2])), - fabs(nearest(ciz_max - cjz_max, dim[2]))); - + fabs(nearest(ciz_min - cjz_max, dim[2])), + fabs(nearest(ciz_max - cjz_min, dim[2])), + fabs(nearest(ciz_max - cjz_max, dim[2]))); + return dx * dx + dy * dy + dz * dz; } else { - const double dx = min(fabs(cix_max - cjx_min), - fabs(cix_min - cjx_max)); - const double dy = min(fabs(ciy_max - cjy_min), - fabs(ciy_min - cjy_max)); - const double dz = min(fabs(ciz_max - cjz_min), - fabs(ciz_min - cjz_max)); + const double dx = min(fabs(cix_max - cjx_min), fabs(cix_min - cjx_max)); + const double dy = min(fabs(ciy_max - cjy_min), fabs(ciy_min - cjy_max)); + const double dz = min(fabs(ciz_max - cjz_min), fabs(ciz_min - cjz_max)); return dx * dx + dy * dy + dz * dz; } diff --git a/src/engine.c b/src/engine.c index 7f6b0ffd40ad69a0a805874e4082fa5bd7dfe74d..31ee8f761bc56c17b1f7b853027f97e77341c665 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3619,16 +3619,16 @@ void engine_makeproxies(struct engine *e) { /* Distance between centre of the cell and corners */ const double r_diag2 = cell_width[0] * cell_width[0] + - cell_width[1] * cell_width[1] + - cell_width[2] * cell_width[2]; + cell_width[1] * cell_width[1] + + cell_width[2] * cell_width[2]; const double r_diag = 0.5 * sqrt(r_diag2); /* Maximal distance from a shifted CoM to centre of cell */ const double delta_CoM = engine_max_proxy_centre_frac * r_diag; - + /* Maximal distance from shifted CoM to any corner */ const double r_max = r_diag + 2. * delta_CoM; - + /* Prepare the proxies and the proxy index. */ if (e->proxy_ind == NULL) if ((e->proxy_ind = (int *)malloc(sizeof(int) * e->nr_nodes)) == NULL) @@ -3660,7 +3660,7 @@ void engine_makeproxies(struct engine *e) { } } - for(int i = 0; i < e->s->nr_cells; ++i) { + for (int i = 0; i < e->s->nr_cells; ++i) { cells[i].num_hydro_proxies = 0; cells[i].num_grav_proxies = 0; } @@ -3677,30 +3677,30 @@ void engine_makeproxies(struct engine *e) { for (int i = 0; i < cdim[0]; i++) { for (int j = 0; j < cdim[1]; j++) { for (int k = 0; k < cdim[2]; k++) { - + /* Get the cell ID. */ const int cid = cell_getid(cdim, i, j, k); - + /* Loop over all its neighbours neighbours in range. */ for (int ii = -delta_m; ii <= delta_p; ii++) { int iii = i + ii; - if (!periodic && (iii < 0 || iii >= cdim[0])) continue; - iii = (iii + cdim[0]) % cdim[0]; + if (!periodic && (iii < 0 || iii >= cdim[0])) continue; + iii = (iii + cdim[0]) % cdim[0]; for (int jj = -delta_m; jj <= delta_p; jj++) { - int jjj = j + jj; - if (!periodic && (jjj < 0 || jjj >= cdim[1])) continue; - jjj = (jjj + cdim[1]) % cdim[1]; + int jjj = j + jj; + if (!periodic && (jjj < 0 || jjj >= cdim[1])) continue; + jjj = (jjj + cdim[1]) % cdim[1]; for (int kk = -delta_m; kk <= delta_p; kk++) { - int kkk = k + kk; - if (!periodic && (kkk < 0 || kkk >= cdim[2])) continue; - kkk = (kkk + cdim[2]) % cdim[2]; - + int kkk = k + kk; + if (!periodic && (kkk < 0 || kkk >= cdim[2])) continue; + kkk = (kkk + cdim[2]) % cdim[2]; + /* Get the cell ID. */ const int cjd = cell_getid(cdim, iii, jjj, kkk); - + /* Early abort (same cell) */ if (cid >= cjd) continue; - + /* Early abort (both same node) */ if (cells[cid].nodeID == nodeID && cells[cjd].nodeID == nodeID) continue; @@ -3708,7 +3708,7 @@ void engine_makeproxies(struct engine *e) { /* Early abort (both foreign node) */ if (cells[cid].nodeID != nodeID && cells[cjd].nodeID != nodeID) continue; - + int proxy_type = 0; /* In the hydro case, only care about direct neighbours */ @@ -3719,14 +3719,11 @@ void engine_makeproxies(struct engine *e) { /* This is super-ugly but checks for direct neighbours */ /* with periodic BC */ - if (((abs(i - iii) <= 1 || - abs(i- iii - cdim[0]) <= 1 || + if (((abs(i - iii) <= 1 || abs(i - iii - cdim[0]) <= 1 || abs(i - iii + cdim[0]) <= 1) && - (abs(j - jjj) <= 1 || - abs(j - jjj - cdim[1]) <= 1 || + (abs(j - jjj) <= 1 || abs(j - jjj - cdim[1]) <= 1 || abs(j - jjj + cdim[1]) <= 1) && - (abs(k - kkk) <= 1 || - abs(k - kkk - cdim[2]) <= 1 || + (abs(k - kkk) <= 1 || abs(k - kkk - cdim[2]) <= 1 || abs(k - kkk + cdim[2]) <= 1))) proxy_type |= (int)proxy_cell_type_hydro; } @@ -3741,24 +3738,28 @@ void engine_makeproxies(struct engine *e) { for an M2L interaction and hence require a proxy as this pair of cells cannot rely on just an M2L calculation. */ - /* Minimal distance between any two points in the cells */ - const double min_dist_centres2 = cell_min_dist2_same_size(&cells[cid], &cells[cjd], periodic, dim); + /* Minimal distance between any two points in the cells */ + const double min_dist_centres2 = cell_min_dist2_same_size( + &cells[cid], &cells[cjd], periodic, dim); - /* Let's now assume the CoMs will shift a bit */ - const double min_dist_CoM = sqrt(min_dist_centres2) - 2. * delta_CoM; - const double min_dist_CoM2 = min_dist_CoM * min_dist_CoM; + /* Let's now assume the CoMs will shift a bit */ + const double min_dist_CoM = + sqrt(min_dist_centres2) - 2. * delta_CoM; + const double min_dist_CoM2 = min_dist_CoM * min_dist_CoM; /* Are we beyond the distance where the truncated forces are 0 * but not too far such that M2L can be used? */ if (periodic) { if ((min_dist_CoM2 < max_mesh_dist2) && - (!gravity_M2L_accept(r_max, r_max, theta_crit2, min_dist_CoM2))) + (!gravity_M2L_accept(r_max, r_max, theta_crit2, + min_dist_CoM2))) proxy_type |= (int)proxy_cell_type_gravity; } else { - if (!gravity_M2L_accept(r_max, r_max, theta_crit2, min_dist_CoM2)) + if (!gravity_M2L_accept(r_max, r_max, theta_crit2, + min_dist_CoM2)) proxy_type |= (int)proxy_cell_type_gravity; } } @@ -3784,19 +3785,21 @@ void engine_makeproxies(struct engine *e) { proxy_id = e->nr_proxies; e->nr_proxies += 1; - /* Check the maximal proxy limit */ - if(proxy_id > 8 * sizeof(long long)) - error("Created more than %zd proxies. cell.mpi.sendto will overflow.", - 8 * sizeof(long long)); + /* Check the maximal proxy limit */ + if (proxy_id > 8 * sizeof(long long)) + error( + "Created more than %zd proxies. cell.mpi.sendto will " + "overflow.", + 8 * sizeof(long long)); } /* Add the cell to the proxy */ proxy_addcell_in(&proxies[proxy_id], &cells[cjd], proxy_type); proxy_addcell_out(&proxies[proxy_id], &cells[cid], proxy_type); - if(proxy_type & (int)proxy_cell_type_gravity) + if (proxy_type & (int)proxy_cell_type_gravity) cells[cid].num_grav_proxies++; - if(proxy_type & (int)proxy_cell_type_hydro) + if (proxy_type & (int)proxy_cell_type_hydro) cells[cid].num_hydro_proxies++; /* Store info about where to send the cell */ @@ -3820,20 +3823,22 @@ void engine_makeproxies(struct engine *e) { e->proxy_ind[cells[cid].nodeID] = e->nr_proxies; proxy_id = e->nr_proxies; e->nr_proxies += 1; - - /* Check the maximal proxy limit */ - if(proxy_id > 8 * sizeof(long long)) - error("Created more than %zd proxies. cell.mpi.sendto will overflow.", - 8 * sizeof(long long)); + + /* Check the maximal proxy limit */ + if (proxy_id > 8 * sizeof(long long)) + error( + "Created more than %zd proxies. cell.mpi.sendto will " + "overflow.", + 8 * sizeof(long long)); } /* Add the cell to the proxy */ proxy_addcell_in(&proxies[proxy_id], &cells[cid], proxy_type); proxy_addcell_out(&proxies[proxy_id], &cells[cjd], proxy_type); - if(proxy_type & (int)proxy_cell_type_gravity) + if (proxy_type & (int)proxy_cell_type_gravity) cells[cjd].num_grav_proxies++; - if(proxy_type & (int)proxy_cell_type_hydro) + if (proxy_type & (int)proxy_cell_type_hydro) cells[cjd].num_hydro_proxies++; /* Store info about where to send the cell */ diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c index 33ed4fa654ca78b9e1cb7577589e969b3147eeec..c2c07c9462c7e4784258bd1b4ce658476b295d6f 100644 --- a/src/engine_maketasks.c +++ b/src/engine_maketasks.c @@ -757,7 +757,7 @@ void engine_make_hierarchical_tasks_stars(struct engine *e, struct cell *c) { void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, void *extra_data) { - struct engine *e = (struct engine *) extra_data; + struct engine *e = (struct engine *)extra_data; struct space *s = e->s; struct scheduler *sched = &e->sched; const int nodeID = e->nodeID; @@ -806,7 +806,7 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, /* If the cell is local build a self-interaction */ if (ci->nodeID == nodeID) scheduler_addtask(sched, task_type_self, task_subtype_grav, 0, 0, ci, - NULL); + NULL); /* Loop over every other cell within (Manhattan) range delta */ for (int ii = -delta_m; ii <= delta_p; ii++) { @@ -828,20 +828,21 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, /* Avoid duplicates, empty cells and completely foreign pairs */ if (cid >= cjd || cj->grav.count == 0 || - (ci->nodeID != nodeID && cj->nodeID != nodeID)) + (ci->nodeID != nodeID && cj->nodeID != nodeID)) continue; /* Recover the multipole information */ - const struct gravity_tensors *multi_i = ci->grav.multipole; + const struct gravity_tensors *multi_i = ci->grav.multipole; const struct gravity_tensors *multi_j = cj->grav.multipole; - if(multi_i == NULL && ci->nodeID != nodeID) - error("Multipole of ci was not exchanged properly via the proxies"); - if(multi_j == NULL && cj->nodeID != nodeID) - error("Multipole of cj was not exchanged properly via the proxies"); + if (multi_i == NULL && ci->nodeID != nodeID) + error("Multipole of ci was not exchanged properly via the proxies"); + if (multi_j == NULL && cj->nodeID != nodeID) + error("Multipole of cj was not exchanged properly via the proxies"); /* Minimal distance between any pair of particles */ - const double min_radius2 = cell_min_dist2_same_size(ci, cj, periodic, dim); + const double min_radius2 = + cell_min_dist2_same_size(ci, cj, periodic, dim); /* Are we beyond the distance where the truncated forces are 0 ?*/ if (periodic && min_radius2 > max_distance2) continue; @@ -854,55 +855,57 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, ci, cj); #ifdef WITH_MPI - - /* Let's cross-check that we had a proxy for that cell */ - if (ci->nodeID == nodeID && cj->nodeID != engine_rank) { - - /* Find the proxy for this node */ - const int proxy_id = e->proxy_ind[cj->nodeID]; - if (proxy_id < 0) - error("No proxy exists for that foreign node %d!", cj->nodeID); - - const struct proxy *p = &e->proxies[proxy_id]; - - /* Check whether the cell exists in the proxy */ - int n = 0, err = 1; - for (; n < p->nr_cells_in; n++) - if(p->cells_in[n] == cj) { - err = 0; - break; - } - if(err) - error("Cell %d not found in the proxy but trying to construct grav task!", - cjd); - } - else if(cj->nodeID == nodeID && ci->nodeID != engine_rank) { - - /* Find the proxy for this node */ - const int proxy_id = e->proxy_ind[ci->nodeID]; - if (proxy_id < 0) - error("No proxy exists for that foreign node %d!", ci->nodeID); - - const struct proxy *p = &e->proxies[proxy_id]; - - /* Check whether the cell exists in the proxy */ - int n = 0, err = 1; - for (; n < p->nr_cells_in; n++) - if(p->cells_in[n] == ci) { - err = 0; - break; - } - if(err) - error("Cell %d not found in the proxy but trying to construct grav task!", - cid); - } -#endif + /* Let's cross-check that we had a proxy for that cell */ + if (ci->nodeID == nodeID && cj->nodeID != engine_rank) { + + /* Find the proxy for this node */ + const int proxy_id = e->proxy_ind[cj->nodeID]; + if (proxy_id < 0) + error("No proxy exists for that foreign node %d!", cj->nodeID); + + const struct proxy *p = &e->proxies[proxy_id]; + + /* Check whether the cell exists in the proxy */ + int n = 0, err = 1; + for (; n < p->nr_cells_in; n++) + if (p->cells_in[n] == cj) { + err = 0; + break; + } + if (err) + error( + "Cell %d not found in the proxy but trying to construct " + "grav task!", + cjd); + } else if (cj->nodeID == nodeID && ci->nodeID != engine_rank) { + + /* Find the proxy for this node */ + const int proxy_id = e->proxy_ind[ci->nodeID]; + if (proxy_id < 0) + error("No proxy exists for that foreign node %d!", ci->nodeID); + + const struct proxy *p = &e->proxies[proxy_id]; + + /* Check whether the cell exists in the proxy */ + int n = 0, err = 1; + for (; n < p->nr_cells_in; n++) + if (p->cells_in[n] == ci) { + err = 0; + break; + } + if (err) + error( + "Cell %d not found in the proxy but trying to construct " + "grav task!", + cid); + } +#endif - if(ci->nodeID == nodeID && cj->nodeID != engine_rank) - atomic_inc(&ci->num_foreign_pair_grav); - if(cj->nodeID == nodeID && ci->nodeID != engine_rank) - atomic_inc(&cj->num_foreign_pair_grav); + if (ci->nodeID == nodeID && cj->nodeID != engine_rank) + atomic_inc(&ci->num_foreign_pair_grav); + if (cj->nodeID == nodeID && ci->nodeID != engine_rank) + atomic_inc(&cj->num_foreign_pair_grav); } } } @@ -945,7 +948,7 @@ void engine_make_self_gravity_tasks(struct engine *e) { struct space *s = e->s; - for(int i = 0; i<s->nr_cells; ++i) { + for (int i = 0; i < s->nr_cells; ++i) { s->cells_top[i].num_foreign_pair_grav = 0; } @@ -1818,52 +1821,53 @@ void engine_make_hydroloop_tasks_mapper(void *map_data, int num_elements, const int sid = sortlistID[(kk + 1) + 3 * ((jj + 1) + 3 * (ii + 1))]; scheduler_addtask(sched, task_type_pair, task_subtype_density, sid, 0, ci, cj); - + #ifdef WITH_MPI - - /* Let's cross-check that we had a proxy for that cell */ - if (ci->nodeID == nodeID && cj->nodeID != engine_rank) { - - /* Find the proxy for this node */ - const int proxy_id = e->proxy_ind[cj->nodeID]; - if (proxy_id < 0) - error("No proxy exists for that foreign node %d!", cj->nodeID); - - const struct proxy *p = &e->proxies[proxy_id]; - - /* Check whether the cell exists in the proxy */ - int n = 0; - for (n = 0; n < p->nr_cells_in; n++) - if(p->cells_in[n] == cj) - break; - if(n == p->nr_cells_in) - error("Cell %d not found in the proxy but trying to construct hydro task!", - cjd); - } - else if(cj->nodeID == nodeID && ci->nodeID != engine_rank) { - - /* Find the proxy for this node */ - const int proxy_id = e->proxy_ind[ci->nodeID]; - if (proxy_id < 0) - error("No proxy exists for that foreign node %d!", ci->nodeID); - - const struct proxy *p = &e->proxies[proxy_id]; - - /* Check whether the cell exists in the proxy */ - int n = 0; - for (n = 0; n < p->nr_cells_in; n++) - if(p->cells_in[n] == ci) - break; - if(n == p->nr_cells_in) - error("Cell %d not found in the proxy but trying to construct hydro task!", - cid); - } + + /* Let's cross-check that we had a proxy for that cell */ + if (ci->nodeID == nodeID && cj->nodeID != engine_rank) { + + /* Find the proxy for this node */ + const int proxy_id = e->proxy_ind[cj->nodeID]; + if (proxy_id < 0) + error("No proxy exists for that foreign node %d!", cj->nodeID); + + const struct proxy *p = &e->proxies[proxy_id]; + + /* Check whether the cell exists in the proxy */ + int n = 0; + for (n = 0; n < p->nr_cells_in; n++) + if (p->cells_in[n] == cj) break; + if (n == p->nr_cells_in) + error( + "Cell %d not found in the proxy but trying to construct " + "hydro task!", + cjd); + } else if (cj->nodeID == nodeID && ci->nodeID != engine_rank) { + + /* Find the proxy for this node */ + const int proxy_id = e->proxy_ind[ci->nodeID]; + if (proxy_id < 0) + error("No proxy exists for that foreign node %d!", ci->nodeID); + + const struct proxy *p = &e->proxies[proxy_id]; + + /* Check whether the cell exists in the proxy */ + int n = 0; + for (n = 0; n < p->nr_cells_in; n++) + if (p->cells_in[n] == ci) break; + if (n == p->nr_cells_in) + error( + "Cell %d not found in the proxy but trying to construct " + "hydro task!", + cid); + } #endif - if(ci->nodeID == nodeID && cj->nodeID != engine_rank) - atomic_inc(&ci->num_foreign_pair_hydro); - if(cj->nodeID == nodeID && ci->nodeID != engine_rank) - atomic_inc(&cj->num_foreign_pair_hydro); + if (ci->nodeID == nodeID && cj->nodeID != engine_rank) + atomic_inc(&ci->num_foreign_pair_hydro); + if (cj->nodeID == nodeID && ci->nodeID != engine_rank) + atomic_inc(&cj->num_foreign_pair_hydro); } } } @@ -1888,7 +1892,7 @@ void engine_maketasks(struct engine *e) { ticks tic2 = getticks(); - for(int i = 0; i<s->nr_cells; ++i) { + for (int i = 0; i < s->nr_cells; ++i) { s->cells_top[i].num_foreign_pair_hydro = 0; } @@ -2039,11 +2043,15 @@ void engine_maketasks(struct engine *e) { message("Linking stars tasks took %.3f %s (including reweight).", clocks_from_ticks(getticks() - tic2), clocks_getunit()); - if(e->nodeID == 0) - for(int i = 0; i < e->s->nr_cells; ++i) { - message("cid= %d num_grav_proxy= %d num_hydro_proxy= %d num_foreign_grav= %d num_foreign_hydro= %d", - i, e->s->cells_top[i].num_grav_proxies, e->s->cells_top[i].num_hydro_proxies, - e->s->cells_top[i].num_foreign_pair_grav, e->s->cells_top[i].num_foreign_pair_hydro); + if (e->nodeID == 0) + for (int i = 0; i < e->s->nr_cells; ++i) { + message( + "cid= %d num_grav_proxy= %d num_hydro_proxy= %d num_foreign_grav= %d " + "num_foreign_hydro= %d", + i, e->s->cells_top[i].num_grav_proxies, + e->s->cells_top[i].num_hydro_proxies, + e->s->cells_top[i].num_foreign_pair_grav, + e->s->cells_top[i].num_foreign_pair_hydro); } #ifdef WITH_MPI @@ -2158,12 +2166,14 @@ void engine_maketasks(struct engine *e) { message("took %.3f %s (including reweight).", clocks_from_ticks(getticks() - tic), clocks_getunit()); - if(e->nodeID == 0) - for(int i = 0; i < e->s->nr_cells; ++i) { - message("cid= %d num_grav_proxy= %d num_hydro_proxy= %d num_foreign_grav= %d num_foreign_hydro= %d", - i, e->s->cells_top[i].num_grav_proxies, e->s->cells_top[i].num_hydro_proxies, - e->s->cells_top[i].num_foreign_pair_grav, e->s->cells_top[i].num_foreign_pair_hydro); + if (e->nodeID == 0) + for (int i = 0; i < e->s->nr_cells; ++i) { + message( + "cid= %d num_grav_proxy= %d num_hydro_proxy= %d num_foreign_grav= %d " + "num_foreign_hydro= %d", + i, e->s->cells_top[i].num_grav_proxies, + e->s->cells_top[i].num_hydro_proxies, + e->s->cells_top[i].num_foreign_pair_grav, + e->s->cells_top[i].num_foreign_pair_hydro); } - - } diff --git a/src/minmax.h b/src/minmax.h index 8964b4a477d2b103869bdaff3f256476d9a44b87..e4d7c8788ea1e43d1c296a212193049a94347949 100644 --- a/src/minmax.h +++ b/src/minmax.h @@ -76,15 +76,15 @@ * * This macro evaluates its arguments exactly once. */ -#define min4(x, y, z, w) \ - ({ \ - const __typeof__(x) _x = (x); \ - const __typeof__(y) _y = (y); \ - const __typeof__(z) _z = (z); \ - const __typeof__(w) _w = (w); \ +#define min4(x, y, z, w) \ + ({ \ + const __typeof__(x) _x = (x); \ + const __typeof__(y) _y = (y); \ + const __typeof__(z) _z = (z); \ + const __typeof__(w) _w = (w); \ const __typeof__(x) _temp1 = min(_x, _y); \ const __typeof__(x) _temp2 = min(_z, _w); \ - min(_temp1, _temp2);\ + min(_temp1, _temp2); \ }) /** @@ -92,15 +92,15 @@ * * This macro evaluates its arguments exactly once. */ -#define max4(x, y, z, w) \ - ({ \ - const __typeof__(x) _x = (x); \ - const __typeof__(y) _y = (y); \ - const __typeof__(z) _z = (z); \ - const __typeof__(w) _w = (w); \ +#define max4(x, y, z, w) \ + ({ \ + const __typeof__(x) _x = (x); \ + const __typeof__(y) _y = (y); \ + const __typeof__(z) _z = (z); \ + const __typeof__(w) _w = (w); \ const __typeof__(x) _temp1 = max(_x, _y); \ const __typeof__(x) _temp2 = max(_z, _w); \ - max(_temp1, _temp2);\ + max(_temp1, _temp2); \ }) #endif /* SWIFT_MINMAX_H */ diff --git a/src/proxy.c b/src/proxy.c index 6f16691bd418d4e497df128f5a6a8ac723221ce0..f279eaaee6120588e65a5429b50ac04bcf54bad2 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -350,20 +350,19 @@ void proxy_cells_wait_and_unpack_mapper(void *unused_map_data, int num_elements, } } -void proxy_cells_unpack_mapper(void* map_data, int num_elements, - void* extra_data) { +void proxy_cells_unpack_mapper(void *map_data, int num_elements, + void *extra_data) { - struct space *s = (struct space*) extra_data; - struct proxy *proxies = (struct proxy*) map_data; + struct space *s = (struct space *)extra_data; + struct proxy *proxies = (struct proxy *)map_data; - for(int k = 0; k < num_elements; ++k) { + for (int k = 0; k < num_elements; ++k) { int count = 0; for (int j = 0; j < proxies[k].nr_cells_in; j++) { - count += cell_unpack(&proxies[k].pcells_in[count], - proxies[k].cells_in[j], s, s->gravity); + count += cell_unpack(&proxies[k].pcells_in[count], proxies[k].cells_in[j], + s, s->gravity); } - } } @@ -464,32 +463,31 @@ void proxy_cells_exchange(struct proxy *proxies, int num_proxies, message("MPI_Waitall on recvs took %.3f %s.", clocks_from_ticks(getticks() - tic2), clocks_getunit()); - int* counters = malloc(s->e->nr_nodes * sizeof(int)); + int *counters = malloc(s->e->nr_nodes * sizeof(int)); bzero(counters, s->e->nr_nodes * sizeof(int)); tic2 = getticks(); message("num proxies: %d", num_proxies); - threadpool_map(&s->e->threadpool, proxy_cells_unpack_mapper, - proxies, num_proxies, sizeof(struct proxy), 0, s); + threadpool_map(&s->e->threadpool, proxy_cells_unpack_mapper, proxies, + num_proxies, sizeof(struct proxy), 0, s); if (s->e->verbose) message("Un-packing cells took %.3f %s.", clocks_from_ticks(getticks() - tic2), clocks_getunit()); - for(int i = 0; i < num_proxies; ++i) { + for (int i = 0; i < num_proxies; ++i) { counters[i] += proxies[i].nr_cells_in; } - - for(int i = 0; i < s->e->nr_nodes; ++i) { - if( i == s->e->nodeID) { + for (int i = 0; i < s->e->nr_nodes; ++i) { + if (i == s->e->nodeID) { printf("Rank %d: |", i); int total = 0; - for(int j = 0; j < s->e->nr_nodes; ++j) { - total += counters[j]; - printf(" %d", counters[j]); + for (int j = 0; j < s->e->nr_nodes; ++j) { + total += counters[j]; + printf(" %d", counters[j]); } printf("| %d |\n", total); } @@ -498,7 +496,6 @@ void proxy_cells_exchange(struct proxy *proxies, int num_proxies, } free(counters); - /* Wait for all the sends to have finished too. */ if (MPI_Waitall(num_proxies, reqs_out, MPI_STATUSES_IGNORE) != MPI_SUCCESS) error("MPI_Waitall on sends failed."); diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h index afe77eb92cee1ab74dfd40dcbb2f23a05883c0a9..2ed2495154195d09af2825eab4c277150b73ec01 100644 --- a/src/runner_doiact_grav.h +++ b/src/runner_doiact_grav.h @@ -1781,7 +1781,7 @@ static INLINE void runner_do_grav_long_range(struct runner *r, struct cell *ci, double dx_r = CoM_rebuild_top[0] - multi_j->CoM_rebuild[0]; double dy_r = CoM_rebuild_top[1] - multi_j->CoM_rebuild[1]; double dz_r = CoM_rebuild_top[2] - multi_j->CoM_rebuild[2]; - + /* Apply BC */ if (periodic) { dx_r = nearest(dx_r, dim[0]); @@ -1789,7 +1789,7 @@ static INLINE void runner_do_grav_long_range(struct runner *r, struct cell *ci, dz_r = nearest(dz_r, dim[2]); } const double r2_rebuild = dx_r * dx_r + dy_r * dy_r + dz_r * dz_r; - + /* Are we in charge of this cell pair? */ if (gravity_M2L_accept(multi_top->r_max_rebuild, multi_j->r_max_rebuild, theta_crit2, r2_rebuild)) {