From 97f98762c044cecf2119ef6ea25fee62f18c6d5d Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 13:24:18 +0100 Subject: [PATCH 01/32] Allow the code to run again with periodic gravity --- examples/main.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/main.c b/examples/main.c index 773accc46..a468cddc8 100644 --- a/examples/main.c +++ b/examples/main.c @@ -720,11 +720,6 @@ int main(int argc, char *argv[]) { fflush(stdout); } -#ifdef WITH_MPI - if (periodic && with_self_gravity) - error("Periodic self-gravity over MPI temporarily disabled."); -#endif - #if defined(WITH_MPI) && defined(HAVE_VELOCIRAPTOR) if (with_structure_finding) error("VEOCIraptor not yet enabled over MPI."); #endif -- GitLab From b9403b81a41591f33bd4ecec577ca87298418c8f Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 13:24:40 +0100 Subject: [PATCH 02/32] Reduce the gravity mesh over MPI before performing the FFT. --- src/mesh_gravity.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/mesh_gravity.c b/src/mesh_gravity.c index 2359b8a9c..68c6d0727 100644 --- a/src/mesh_gravity.c +++ b/src/mesh_gravity.c @@ -314,7 +314,7 @@ void pm_mesh_compute_potential(struct pm_mesh* mesh, const struct space* s, fftw_plan inverse_plan = fftw_plan_dft_c2r_3d( N, N, N, frho, rho, FFTW_ESTIMATE | FFTW_DESTROY_INPUT); - const ticks tic = getticks(); + ticks tic = getticks(); /* Zero everything */ bzero(rho, N * N * N * sizeof(double)); @@ -324,9 +324,22 @@ void pm_mesh_compute_potential(struct pm_mesh* mesh, const struct space* s, gpart_to_mesh_CIC(&s->gparts[i], rho, N, cell_fac, dim); if (verbose) - message("gpart assignment took %.3f %s.", + message("Gpart assignment took %.3f %s.", clocks_from_ticks(getticks() - tic), clocks_getunit()); +#ifdef WITH_MPI + + MPI_Barrier(MPI_COMM_WORLD); + tic = getticks(); + + /* Merge everybody's share of the density mesh */ + MPI_Allreduce(MPI_IN_PLACE, rho, N * N * N, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + + if (verbose) + message("Mesh comunication took %.3f %s.", + clocks_from_ticks(getticks() - tic), clocks_getunit()); +#endif + /* message("\n\n\n DENSITY"); */ /* print_array(rho, N); */ -- GitLab From 463d1302d8cfac8a82c23c024907255cebdb0a18 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 13:50:33 +0100 Subject: [PATCH 03/32] Make the proxy construction similar to the self-gravity task construction. --- src/engine.c | 52 ++++++++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 30 deletions(-) diff --git a/src/engine.c b/src/engine.c index 8ba089295..704df2721 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5274,14 +5274,11 @@ void engine_makeproxies(struct engine *e) { const int nodeID = e->nodeID; const struct space *s = e->s; const int *cdim = s->cdim; - const int periodic = s->periodic; /* Get some info about the physics */ - const double *dim = s->dim; - const struct gravity_props *props = e->gravity_properties; - const double theta_crit2 = props->theta_crit2; const int with_hydro = (e->policy & engine_policy_hydro); const int with_gravity = (e->policy & engine_policy_self_gravity); + const double theta_crit = e->gravity_properties->theta_crit; /* Handle on the cells and proxies */ struct cell *cells = s->cells_top; @@ -5300,13 +5297,27 @@ void engine_makeproxies(struct engine *e) { /* Compute how many cells away we need to walk */ int delta = 1; /*hydro case */ if (with_gravity) { - const double distance = 2.5 * cells[0].width[0] / props->theta_crit; + const double distance = 2.5 * cells[0].width[0] / theta_crit; delta = (int)(distance / cells[0].width[0]) + 1; } + int delta_m = delta; + int delta_p = delta; + + /* Special case where every cell is in range of every other one */ + if (delta >= cdim[0] / 2) { + if (cdim[0] % 2 == 0) { + delta_m = cdim[0] / 2; + delta_p = cdim[0] / 2 - 1; + } else { + delta_m = cdim[0] / 2; + delta_p = cdim[0] / 2; + } + } /* Let's be verbose about this choice */ if (e->verbose) - message("Looking for proxies up to %d top-level cells away", delta); + message("Looking for proxies up to %d top-level cells away (delta_m=%d delta_m=%d)", + delta, delta_m, delta_p); /* Loop over each cell in the space. */ int ind[3]; @@ -5331,19 +5342,19 @@ void engine_makeproxies(struct engine *e) { } /* Loop over all its neighbours (periodic). */ - for (int i = -delta; i <= delta; i++) { + for (int i = -delta_m; i <= delta_p; i++) { int ii = ind[0] + i; if (ii >= cdim[0]) ii -= cdim[0]; else if (ii < 0) ii += cdim[0]; - for (int j = -delta; j <= delta; j++) { + for (int j = -delta_m; j <= delta_p; j++) { int jj = ind[1] + j; if (jj >= cdim[1]) jj -= cdim[1]; else if (jj < 0) jj += cdim[1]; - for (int k = -delta; k <= delta; k++) { + for (int k = -delta_m; k <= delta_p; k++) { int kk = ind[2] + k; if (kk >= cdim[2]) kk -= cdim[2]; @@ -5366,7 +5377,7 @@ void engine_makeproxies(struct engine *e) { int proxy_type = 0; - /* In the hydro case, only care about neighbours */ + /* In the hydro case, only care about direct neighbours */ if (with_hydro) { /* This is super-ugly but checks for direct neighbours */ @@ -5386,27 +5397,8 @@ void engine_makeproxies(struct engine *e) { /* In the gravity case, check distances using the MAC. */ if (with_gravity) { - /* Get cj's multipole */ - const struct gravity_tensors *multi_j = cells[cjd].multipole; - const double CoM_j[3] = {multi_j->CoM[0], multi_j->CoM[1], - multi_j->CoM[2]}; - const double r_max_j = multi_j->r_max; - - /* Let's compute the current distance between the cell pair*/ - double dx = CoM_i[0] - CoM_j[0]; - double dy = CoM_i[1] - CoM_j[1]; - double dz = CoM_i[2] - CoM_j[2]; - - /* Apply BC */ - if (periodic) { - dx = nearest(dx, dim[0]); - dy = nearest(dy, dim[1]); - dz = nearest(dz, dim[2]); - } - const double r2 = dx * dx + dy * dy + dz * dz; - /* Are we too close for M2L? */ - if (!gravity_M2L_accept(r_max_i, r_max_j, theta_crit2, r2)) + if (!cell_can_use_pair_mm(&cells[cid], &cells[cjd], e, s)) proxy_type |= (int)proxy_cell_type_gravity; } -- GitLab From 7ae67880ce02355fef75b8b84ad181a379ea01e3 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 14:36:37 +0100 Subject: [PATCH 04/32] Allow the task splitting routine to split gravity tasks and replace them by M-M tasks when gravity is on. --- src/scheduler.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/scheduler.c b/src/scheduler.c index 497488465..b8a02c8c4 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -804,11 +804,8 @@ static void scheduler_splittask_hydro(struct task *t, struct scheduler *s) { */ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { -/* Temporarily prevent MPI here */ -#ifndef WITH_MPI const struct space *sp = s->space; struct engine *e = sp->e; -#endif /* Iterate on this task until we're done with it. */ int redo = 1; @@ -838,9 +835,6 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { break; } -/* Temporarily prevent MPI here */ -#ifndef WITH_MPI - /* Should we split this task? */ if (cell_can_split_self_gravity_task(ci)) { @@ -879,7 +873,6 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { } /* Self-gravity only */ } /* Make tasks explicitly */ } /* Cell is split */ -#endif /* WITH_MPI */ } /* Self interaction */ /* Pair interaction? */ @@ -895,9 +888,6 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { break; } -/* Temporarily prevent MPI here */ -#ifndef WITH_MPI - /* Should we replace it with an M-M task? */ if (cell_can_use_pair_mm(ci, cj, e, sp)) { @@ -954,7 +944,6 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { } } /* Split the pair */ } -#endif /* WITH_MPI */ } /* pair interaction? */ } /* iterate over the current task. */ } -- GitLab From c921391155467f12b584854d38249ee943d049e2 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 16:36:01 +0100 Subject: [PATCH 05/32] Initialise the redshift correctly when cosmology is off. --- src/cosmology.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cosmology.c b/src/cosmology.c index a39efc605..0ee76dd79 100644 --- a/src/cosmology.c +++ b/src/cosmology.c @@ -497,6 +497,7 @@ void cosmology_init_no_cosmo(struct cosmology *c) { c->H = 0.; c->a = 1.; + c->z = 0.; c->a_inv = 1.; c->a2_inv = 1.; c->a3_inv = 1.; -- GitLab From 575077b3051844c6442d16137919a9f4637e3d39 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 17:14:23 +0100 Subject: [PATCH 06/32] When activating an M-M task over MPI, also activate the corresponding drifts. --- src/cell.c | 40 ++++++++++++++++++++++++++++++++-------- src/engine.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 58 insertions(+), 14 deletions(-) diff --git a/src/cell.c b/src/cell.c index 85f8531c2..375c8ebd8 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2240,10 +2240,15 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { struct task *t = l->t; struct cell *ci = t->ci; struct cell *cj = t->cj; - const int ci_nodeID = ci->nodeID; - const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; const int ci_active = cell_is_active_gravity(ci, e); const int cj_active = (cj != NULL) ? cell_is_active_gravity(cj, e) : 0; +#ifdef WITH_MPI + const int ci_nodeID = ci->nodeID; + const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; +#else + const int ci_nodeID = nodeID; + const int cj_nodeID = nodeID; +#endif /* Only activate tasks that involve a local active cell. */ if ((ci_active && ci_nodeID == nodeID) || @@ -2270,9 +2275,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { if (ci_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ - if (cj_active) { - scheduler_activate(s, ci->recv_grav); - } + if (cj_active) scheduler_activate(s, ci->recv_grav); /* If the foreign cell is active, we want its ti_end values. */ if (ci_active) scheduler_activate(s, ci->recv_ti); @@ -2294,9 +2297,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } else if (cj_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ - if (ci_active) { - scheduler_activate(s, cj->recv_grav); - } + if (ci_active) scheduler_activate(s, cj->recv_grav); /* If the foreign cell is active, we want its ti_end values. */ if (cj_active) scheduler_activate(s, cj->recv_ti); @@ -2317,6 +2318,29 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } #endif } + + if (t->type == task_type_grav_mm) { + +#ifdef WITH_MPI + /* Activate the send/recv tasks. */ + if (ci_nodeID != nodeID) { + + /* If the foreign cell is active, we want its ti_end values. */ + if (ci_active) scheduler_activate(s, ci->recv_ti); + + /* If the local cell is active, send its ti_end values. */ + if (cj_active) scheduler_activate_send(s, cj->send_ti, ci_nodeID); + + } else if (cj_nodeID != nodeID) { + + /* If the foreign cell is active, we want its ti_end values. */ + if (cj_active) scheduler_activate(s, cj->recv_ti); + + /* If the local cell is active, send its ti_end values. */ + if (ci_active) scheduler_activate_send(s, ci->send_ti, cj_nodeID); + } +#endif + } } /* Unskip all the other task types. */ diff --git a/src/engine.c b/src/engine.c index 704df2721..ae778cf17 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3540,10 +3540,12 @@ void engine_marktasks_mapper(void *map_data, int num_elements, cell_activate_subcell_grav_tasks(t->ci, t->cj, s); } +#ifdef SWIFT_DEBUG_CHECKS else if (t->type == task_type_sub_pair && t->subtype == task_subtype_grav) { error("Invalid task sub-type encountered"); } +#endif } /* Only interested in density tasks as of here. */ @@ -3648,9 +3650,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements, if (ci->nodeID != engine_rank) { /* If the local cell is active, receive data from the foreign cell. */ - if (cj_active_gravity) { - scheduler_activate(s, ci->recv_grav); - } + if (cj_active_gravity) scheduler_activate(s, ci->recv_grav); /* If the foreign cell is active, we want its ti_end values. */ if (ci_active_gravity) scheduler_activate(s, ci->recv_ti); @@ -3674,9 +3674,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements, } else if (cj->nodeID != engine_rank) { /* If the local cell is active, receive data from the foreign cell. */ - if (ci_active_gravity) { - scheduler_activate(s, cj->recv_grav); - } + if (ci_active_gravity) scheduler_activate(s, cj->recv_grav); /* If the foreign cell is active, we want its ti_end values. */ if (cj_active_gravity) scheduler_activate(s, cj->recv_ti); @@ -3743,6 +3741,28 @@ void engine_marktasks_mapper(void *map_data, int num_elements, if ((ci_active_gravity && ci_nodeID == engine_rank) || (cj_active_gravity && cj_nodeID == engine_rank)) scheduler_activate(s, t); + +#ifdef WITH_MPI + /* Activate the send/recv tasks. */ + if (ci->nodeID != engine_rank) { + + /* If the foreign cell is active, we want its ti_end values. */ + if (ci_active_gravity) scheduler_activate(s, ci->recv_ti); + + /* If the local cell is active, send its ti_end values. */ + if (cj_active_gravity) + scheduler_activate_send(s, cj->send_ti, ci->nodeID); + + } else if (cj->nodeID != engine_rank) { + + /* If the foreign cell is active, we want its ti_end values. */ + if (cj_active_gravity) scheduler_activate(s, cj->recv_ti); + + /* If the local cell is active, send its ti_end values. */ + if (ci_active_gravity) + scheduler_activate_send(s, ci->send_ti, cj->nodeID); + } +#endif } /* Time-step? */ -- GitLab From 1749bef1f93702d5838444b4b26ff7d5c825da4d Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 8 Aug 2018 18:01:48 +0100 Subject: [PATCH 07/32] Removed too-stringent test in the receiving gpart task. --- src/runner.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/runner.c b/src/runner.c index 7771e247a..dcc740500 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1898,11 +1898,6 @@ void runner_do_recv_gpart(struct runner *r, struct cell *c, int timer) { if (gparts[k].time_bin == time_bin_inhibited) continue; time_bin_min = min(time_bin_min, gparts[k].time_bin); time_bin_max = max(time_bin_max, gparts[k].time_bin); - -#ifdef SWIFT_DEBUG_CHECKS - if (gparts[k].ti_drift != ti_current) - error("Received un-drifted g-particle !"); -#endif } /* Convert into a time */ -- GitLab From 42842d3048feaa234ef47414cecbcfb9c243fe1c Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 9 Aug 2018 15:49:54 +0200 Subject: [PATCH 08/32] Removed unused variables preventing compilation. --- src/engine.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/engine.c b/src/engine.c index ae778cf17..5e9726fa8 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5348,19 +5348,6 @@ void engine_makeproxies(struct engine *e) { /* Get the cell ID. */ const int cid = cell_getid(cdim, ind[0], ind[1], ind[2]); - double CoM_i[3] = {0., 0., 0.}; - double r_max_i = 0.; - - if (with_gravity) { - - /* Get ci's multipole */ - const struct gravity_tensors *multi_i = cells[cid].multipole; - CoM_i[0] = multi_i->CoM[0]; - CoM_i[1] = multi_i->CoM[1]; - CoM_i[2] = multi_i->CoM[2]; - r_max_i = multi_i->r_max; - } - /* Loop over all its neighbours (periodic). */ for (int i = -delta_m; i <= delta_p; i++) { int ii = ind[0] + i; -- GitLab From 9a80921eefaecd60f45e021d0d78a9f67cdd4257 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 9 Aug 2018 16:32:55 +0200 Subject: [PATCH 09/32] Code formatting --- src/engine.c | 26 ++++++++++++++------------ src/mesh_gravity.c | 3 ++- src/scheduler.c | 4 ++-- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/engine.c b/src/engine.c index 5e9726fa8..f3ad83eb0 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3746,21 +3746,21 @@ void engine_marktasks_mapper(void *map_data, int num_elements, /* Activate the send/recv tasks. */ if (ci->nodeID != engine_rank) { - /* If the foreign cell is active, we want its ti_end values. */ - if (ci_active_gravity) scheduler_activate(s, ci->recv_ti); + /* If the foreign cell is active, we want its ti_end values. */ + if (ci_active_gravity) scheduler_activate(s, ci->recv_ti); - /* If the local cell is active, send its ti_end values. */ - if (cj_active_gravity) - scheduler_activate_send(s, cj->send_ti, ci->nodeID); + /* If the local cell is active, send its ti_end values. */ + if (cj_active_gravity) + scheduler_activate_send(s, cj->send_ti, ci->nodeID); } else if (cj->nodeID != engine_rank) { - /* If the foreign cell is active, we want its ti_end values. */ - if (cj_active_gravity) scheduler_activate(s, cj->recv_ti); + /* If the foreign cell is active, we want its ti_end values. */ + if (cj_active_gravity) scheduler_activate(s, cj->recv_ti); - /* If the local cell is active, send its ti_end values. */ - if (ci_active_gravity) - scheduler_activate_send(s, ci->send_ti, cj->nodeID); + /* If the local cell is active, send its ti_end values. */ + if (ci_active_gravity) + scheduler_activate_send(s, ci->send_ti, cj->nodeID); } #endif } @@ -5336,8 +5336,10 @@ void engine_makeproxies(struct engine *e) { /* Let's be verbose about this choice */ if (e->verbose) - message("Looking for proxies up to %d top-level cells away (delta_m=%d delta_m=%d)", - delta, delta_m, delta_p); + message( + "Looking for proxies up to %d top-level cells away (delta_m=%d " + "delta_m=%d)", + delta, delta_m, delta_p); /* Loop over each cell in the space. */ int ind[3]; diff --git a/src/mesh_gravity.c b/src/mesh_gravity.c index 68c6d0727..d49b850f9 100644 --- a/src/mesh_gravity.c +++ b/src/mesh_gravity.c @@ -333,7 +333,8 @@ void pm_mesh_compute_potential(struct pm_mesh* mesh, const struct space* s, tic = getticks(); /* Merge everybody's share of the density mesh */ - MPI_Allreduce(MPI_IN_PLACE, rho, N * N * N, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); + MPI_Allreduce(MPI_IN_PLACE, rho, N * N * N, MPI_DOUBLE, MPI_SUM, + MPI_COMM_WORLD); if (verbose) message("Mesh comunication took %.3f %s.", diff --git a/src/scheduler.c b/src/scheduler.c index b8a02c8c4..3b52cb570 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -944,8 +944,8 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { } } /* Split the pair */ } - } /* pair interaction? */ - } /* iterate over the current task. */ + } /* pair interaction? */ + } /* iterate over the current task. */ } /** -- GitLab From de03f318049fb9cdd2893fc697b2b49f4ebdbf8c Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Thu, 9 Aug 2018 16:33:26 +0200 Subject: [PATCH 10/32] Also optimize out the cell nodeID lookup in the hydro unskipping --- src/cell.c | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/cell.c b/src/cell.c index 375c8ebd8..d36cbbb50 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2072,15 +2072,22 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { struct cell *cj = t->cj; const int ci_active = cell_is_active_hydro(ci, e); const int cj_active = (cj != NULL) ? cell_is_active_hydro(cj, e) : 0; +#ifdef WITH_MPI + const int ci_nodeID = ci->nodeID; + const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; +#else + const int ci_nodeID = nodeID; + const int cj_nodeID = nodeID; +#endif /* Only activate tasks that involve a local active cell. */ - if ((ci_active && ci->nodeID == nodeID) || - (cj_active && cj->nodeID == nodeID)) { + if ((ci_active && ci_nodeID == nodeID) || + (cj_active && cj_nodeID == nodeID)) { scheduler_activate(s, t); /* Activate hydro drift */ if (t->type == task_type_self) { - if (ci->nodeID == nodeID) cell_activate_drift_part(ci, s); + if (ci_nodeID == nodeID) cell_activate_drift_part(ci, s); } /* Set the correct sorting flags and activate hydro drifts */ @@ -2092,8 +2099,8 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { cj->dx_max_sort_old = cj->dx_max_sort; /* Activate the drift tasks. */ - if (ci->nodeID == nodeID) cell_activate_drift_part(ci, s); - if (cj->nodeID == nodeID) cell_activate_drift_part(cj, s); + if (ci_nodeID == nodeID) cell_activate_drift_part(ci, s); + if (cj_nodeID == nodeID) cell_activate_drift_part(cj, s); /* Check the sorts and activate them if needed. */ cell_activate_sorts(ci, t->flags, s); @@ -2114,7 +2121,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { #ifdef WITH_MPI /* Activate the send/recv tasks. */ - if (ci->nodeID != nodeID) { + if (ci_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ if (cj_active) { @@ -2134,7 +2141,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { /* Is the foreign cell active and will need stuff from us? */ if (ci_active) { - scheduler_activate_send(s, cj->send_xv, ci->nodeID); + scheduler_activate_send(s, cj->send_xv, ci_nodeID); /* Drift the cell which will be sent; note that not all sent particles will be drifted, only those that are needed. */ @@ -2142,18 +2149,18 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { /* If the local cell is also active, more stuff will be needed. */ if (cj_active) { - scheduler_activate_send(s, cj->send_rho, ci->nodeID); + scheduler_activate_send(s, cj->send_rho, ci_nodeID); #ifdef EXTRA_HYDRO_LOOP - scheduler_activate_send(s, cj->send_gradient, ci->nodeID); + scheduler_activate_send(s, cj->send_gradient, ci_nodeID); #endif } } /* If the local cell is active, send its ti_end values. */ - if (cj_active) scheduler_activate_send(s, cj->send_ti, ci->nodeID); + if (cj_active) scheduler_activate_send(s, cj->send_ti, ci_nodeID); - } else if (cj->nodeID != nodeID) { + } else if (cj_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ if (ci_active) { @@ -2173,7 +2180,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { /* Is the foreign cell active and will need stuff from us? */ if (cj_active) { - scheduler_activate_send(s, ci->send_xv, cj->nodeID); + scheduler_activate_send(s, ci->send_xv, cj_nodeID); /* Drift the cell which will be sent; note that not all sent particles will be drifted, only those that are needed. */ @@ -2182,16 +2189,16 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { /* If the local cell is also active, more stuff will be needed. */ if (ci_active) { - scheduler_activate_send(s, ci->send_rho, cj->nodeID); + scheduler_activate_send(s, ci->send_rho, cj_nodeID); #ifdef EXTRA_HYDRO_LOOP - scheduler_activate_send(s, ci->send_gradient, cj->nodeID); + scheduler_activate_send(s, ci->send_gradient, cj_nodeID); #endif } } /* If the local cell is active, send its ti_end values. */ - if (ci_active) scheduler_activate_send(s, ci->send_ti, cj->nodeID); + if (ci_active) scheduler_activate_send(s, ci->send_ti, cj_nodeID); } #endif } -- GitLab From 23689046bd6ab54744880c79ccb874da748ec5ea Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 10 Aug 2018 14:06:05 +0200 Subject: [PATCH 11/32] Added specific counters for communication tasks. --- examples/main.c | 14 ++++++-------- src/engine.c | 24 ++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/examples/main.c b/examples/main.c index a468cddc8..eaeb597a1 100644 --- a/examples/main.c +++ b/examples/main.c @@ -755,8 +755,7 @@ int main(int argc, char *argv[]) { if (myrank == 0) message( "Read %lld gas particles, %lld star particles and %lld gparts from " - "the " - "ICs.", + "the ICs.", N_total[0], N_total[2], N_total[1]); /* Verify that the fields to dump actually exist */ @@ -891,11 +890,10 @@ int main(int argc, char *argv[]) { "particles (%lld gravity particles)", N_total[0], N_total[2], N_total[1] > 0 ? N_DM : 0, N_total[1]); message( - "from t=%.3e until t=%.3e with %d threads and %d queues " - "(dt_min=%.3e, " - "dt_max=%.3e)...", - e.time_begin, e.time_end, e.nr_threads, e.sched.nr_queues, e.dt_min, - e.dt_max); + "from t=%.3e until t=%.3e with %d ranks, %d threads / rank and %d " + "task queues / rank (dt_min=%.3e, dt_max=%.3e)...", + e.time_begin, e.time_end, nr_nodes, e.nr_threads, e.sched.nr_queues, + e.dt_min, e.dt_max); fflush(stdout); } } @@ -935,7 +933,7 @@ int main(int argc, char *argv[]) { engine_init_particles(&e, flag_entropy_ICs, clean_smoothing_length_values); /* Write the state of the system before starting time integration. */ - engine_dump_snapshot(&e); + // engine_dump_snapshot(&e); engine_print_stats(&e); #ifdef HAVE_VELOCIRAPTOR diff --git a/src/engine.c b/src/engine.c index f3ad83eb0..41a8348d0 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3818,14 +3818,29 @@ void engine_print_task_counts(struct engine *e) { const int nr_tasks = sched->nr_tasks; const struct task *const tasks = sched->tasks; + int count_send_gpart = 0; + int count_recv_gpart = 0; + int count_send_tiend = 0; + int count_recv_tiend = 0; + /* Count and print the number of each task type. */ int counts[task_type_count + 1]; for (int k = 0; k <= task_type_count; k++) counts[k] = 0; for (int k = 0; k < nr_tasks; k++) { if (tasks[k].skip) counts[task_type_count] += 1; - else + else { counts[(int)tasks[k].type] += 1; + + if(tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_gpart) + ++count_send_gpart; + if(tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_tend) + ++count_send_tiend; + if(tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_gpart) + ++count_recv_gpart; + if(tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_tend) + ++count_recv_tiend; + } } message("Total = %d (per cell = %d)", nr_tasks, (int)ceil((double)nr_tasks / e->s->tot_cells)); @@ -3840,6 +3855,11 @@ void engine_print_task_counts(struct engine *e) { printf(" %s=%i", taskID_names[k], counts[k]); printf(" skipped=%i ]\n", counts[task_type_count]); fflush(stdout); + message("send_gpart = %d", count_send_gpart); + message("send_tiend = %d", count_send_tiend); + message("recv_gpart = %d", count_recv_gpart); + message("recv_tiend = %d", count_recv_tiend); + message("nr_parts = %zu.", e->s->nr_parts); message("nr_gparts = %zu.", e->s->nr_gparts); message("nr_sparts = %zu.", e->s->nr_sparts); @@ -4807,7 +4827,7 @@ void engine_step(struct engine *e) { engine_prepare(e); /* Print the number of active tasks ? */ - if (e->verbose) engine_print_task_counts(e); + if (e->step == 389) engine_print_task_counts(e); /* Dump local cells and active particle counts. */ /* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */ -- GitLab From 618b275d9c07ab24aeeb4eba520b22165957070e Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 10 Aug 2018 14:36:08 +0200 Subject: [PATCH 12/32] When running without cosmology, set w to -1. --- src/cosmology.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cosmology.c b/src/cosmology.c index 0ee76dd79..0c81cb00a 100644 --- a/src/cosmology.c +++ b/src/cosmology.c @@ -488,7 +488,7 @@ void cosmology_init_no_cosmo(struct cosmology *c) { c->w_0 = 0.; c->w_a = 0.; c->h = 1.; - c->w = 0.; + c->w = -1.; c->a_begin = 1.; c->a_end = 1.; -- GitLab From 1972befe7756fade63d815328b96926cb565cdcd Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 10 Aug 2018 14:51:25 +0200 Subject: [PATCH 13/32] Do not accumulate the minimal time in do_recv_spart(). --- src/runner.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/runner.c b/src/runner.c index dcc740500..f6f769d2f 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1972,11 +1972,6 @@ void runner_do_recv_spart(struct runner *r, struct cell *c, int timer) { if (sparts[k].time_bin == time_bin_inhibited) continue; time_bin_min = min(time_bin_min, sparts[k].time_bin); time_bin_max = max(time_bin_max, sparts[k].time_bin); - -#ifdef SWIFT_DEBUG_CHECKS - if (sparts[k].ti_drift != ti_current) - error("Received un-drifted s-particle !"); -#endif } /* Convert into a time */ @@ -2006,8 +2001,8 @@ void runner_do_recv_spart(struct runner *r, struct cell *c, int timer) { #endif /* ... and store. */ - c->ti_gravity_end_min = ti_gravity_end_min; - c->ti_gravity_end_max = ti_gravity_end_max; + //c->ti_gravity_end_min = ti_gravity_end_min; + //c->ti_gravity_end_max = ti_gravity_end_max; c->ti_old_gpart = ti_current; if (timer) TIMER_TOC(timer_dorecv_spart); -- GitLab From 636243659f4fe2dc127c7c718989a93fa2ab03f9 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 10 Aug 2018 14:53:10 +0200 Subject: [PATCH 14/32] Receiving gparts should not unlock mm. These are un-related. --- src/engine.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/engine.c b/src/engine.c index 41a8348d0..265571b46 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1582,7 +1582,8 @@ void engine_addtasks_recv_gravity(struct engine *e, struct cell *c, c->recv_grav = t_grav; for (struct link *l = c->grav; l != NULL; l = l->next) - scheduler_addunlock(s, t_grav, l->t); + if (l->t->type != task_type_grav_mm) + scheduler_addunlock(s, t_grav, l->t); /* Recurse? */ if (c->split) @@ -4827,7 +4828,7 @@ void engine_step(struct engine *e) { engine_prepare(e); /* Print the number of active tasks ? */ - if (e->step == 389) engine_print_task_counts(e); + if (e->step == 43) engine_print_task_counts(e); /* Dump local cells and active particle counts. */ /* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */ -- GitLab From c1c29386ad0296ff601a1c8240fd73ffe66a096a Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 12 Aug 2018 20:41:34 +0200 Subject: [PATCH 15/32] Separeated the M-M tasks from the other gravity tasks in the cells' linked-lists. --- examples/main.c | 2 +- src/cell.c | 41 ++++++++++++++++++++++------------------- src/cell.h | 3 +++ src/engine.c | 27 +++++++++++++++------------ src/runner.c | 4 ++-- src/scheduler.c | 4 ++-- src/space.c | 1 + 7 files changed, 46 insertions(+), 36 deletions(-) diff --git a/examples/main.c b/examples/main.c index eaeb597a1..7a45dc1d9 100644 --- a/examples/main.c +++ b/examples/main.c @@ -893,7 +893,7 @@ int main(int argc, char *argv[]) { "from t=%.3e until t=%.3e with %d ranks, %d threads / rank and %d " "task queues / rank (dt_min=%.3e, dt_max=%.3e)...", e.time_begin, e.time_end, nr_nodes, e.nr_threads, e.sched.nr_queues, - e.dt_min, e.dt_max); + e.dt_min, e.dt_max); fflush(stdout); } } diff --git a/src/cell.c b/src/cell.c index d36cbbb50..e8038db1d 100644 --- a/src/cell.c +++ b/src/cell.c @@ -1095,6 +1095,7 @@ void cell_clean_links(struct cell *c, void *data) { c->gradient = NULL; c->force = NULL; c->grav = NULL; + c->grav_mm = NULL; } /** @@ -2271,7 +2272,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } else if (t->type == task_type_pair) { cell_activate_subcell_grav_tasks(ci, cj, s); } else if (t->type == task_type_grav_mm) { - cell_activate_grav_mm_task(ci, cj, s); + error("Incorrectyl linked M-M task!"); } } @@ -2325,28 +2326,29 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } #endif } + } - if (t->type == task_type_grav_mm) { + for (struct link *l = c->grav_mm; l != NULL; l = l->next) { + struct task *t = l->t; + struct cell *ci = t->ci; + struct cell *cj = t->cj; + const int ci_active = cell_is_active_gravity(ci, e); + const int cj_active = (cj != NULL) ? cell_is_active_gravity(cj, e) : 0; #ifdef WITH_MPI - /* Activate the send/recv tasks. */ - if (ci_nodeID != nodeID) { - - /* If the foreign cell is active, we want its ti_end values. */ - if (ci_active) scheduler_activate(s, ci->recv_ti); - - /* If the local cell is active, send its ti_end values. */ - if (cj_active) scheduler_activate_send(s, cj->send_ti, ci_nodeID); - - } else if (cj_nodeID != nodeID) { + const int ci_nodeID = ci->nodeID; + const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; +#else + const int ci_nodeID = nodeID; + const int cj_nodeID = nodeID; +#endif - /* If the foreign cell is active, we want its ti_end values. */ - if (cj_active) scheduler_activate(s, cj->recv_ti); + if (t->type != task_type_grav_mm) error("Incorrectly linked gravity task!"); - /* If the local cell is active, send its ti_end values. */ - if (ci_active) scheduler_activate_send(s, ci->send_ti, cj_nodeID); - } -#endif + /* Only activate tasks that involve a local active cell. */ + if ((ci_active && ci_nodeID == nodeID) || + (cj_active && cj_nodeID == nodeID)) { + cell_activate_grav_mm_task(ci, cj, s); } } @@ -2420,7 +2422,8 @@ void cell_set_super_hydro(struct cell *c, struct cell *super_hydro) { void cell_set_super_gravity(struct cell *c, struct cell *super_gravity) { /* Are we in a cell with some kind of self/pair task ? */ - if (super_gravity == NULL && c->grav != NULL) super_gravity = c; + if (super_gravity == NULL && (c->grav != NULL || c->grav_mm != NULL)) + super_gravity = c; /* Set the super-cell */ c->super_gravity = super_gravity; diff --git a/src/cell.h b/src/cell.h index 31d525b02..534f9d704 100644 --- a/src/cell.h +++ b/src/cell.h @@ -216,6 +216,9 @@ struct cell { /*! Linked list of the tasks computing this cell's gravity forces. */ struct link *grav; + /*! Linked list of the tasks computing this cell's gravity M-M forces. */ + struct link *grav_mm; + /*! The task computing this cell's sorts. */ struct task *sorts; diff --git a/src/engine.c b/src/engine.c index 265571b46..04694b2c9 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1582,8 +1582,7 @@ void engine_addtasks_recv_gravity(struct engine *e, struct cell *c, c->recv_grav = t_grav; for (struct link *l = c->grav; l != NULL; l = l->next) - if (l->t->type != task_type_grav_mm) - scheduler_addunlock(s, t_grav, l->t); + scheduler_addunlock(s, t_grav, l->t); /* Recurse? */ if (c->split) @@ -3823,7 +3822,7 @@ void engine_print_task_counts(struct engine *e) { int count_recv_gpart = 0; int count_send_tiend = 0; int count_recv_tiend = 0; - + /* Count and print the number of each task type. */ int counts[task_type_count + 1]; for (int k = 0; k <= task_type_count; k++) counts[k] = 0; @@ -3833,14 +3832,18 @@ void engine_print_task_counts(struct engine *e) { else { counts[(int)tasks[k].type] += 1; - if(tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_gpart) - ++count_send_gpart; - if(tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_tend) - ++count_send_tiend; - if(tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_gpart) - ++count_recv_gpart; - if(tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_tend) - ++count_recv_tiend; + if (tasks[k].type == task_type_send && + tasks[k].subtype == task_subtype_gpart) + ++count_send_gpart; + if (tasks[k].type == task_type_send && + tasks[k].subtype == task_subtype_tend) + ++count_send_tiend; + if (tasks[k].type == task_type_recv && + tasks[k].subtype == task_subtype_gpart) + ++count_recv_gpart; + if (tasks[k].type == task_type_recv && + tasks[k].subtype == task_subtype_tend) + ++count_recv_tiend; } } message("Total = %d (per cell = %d)", nr_tasks, @@ -3860,7 +3863,7 @@ void engine_print_task_counts(struct engine *e) { message("send_tiend = %d", count_send_tiend); message("recv_gpart = %d", count_recv_gpart); message("recv_tiend = %d", count_recv_tiend); - + message("nr_parts = %zu.", e->s->nr_parts); message("nr_gparts = %zu.", e->s->nr_gparts); message("nr_sparts = %zu.", e->s->nr_sparts); diff --git a/src/runner.c b/src/runner.c index f6f769d2f..187e60131 100644 --- a/src/runner.c +++ b/src/runner.c @@ -2001,8 +2001,8 @@ void runner_do_recv_spart(struct runner *r, struct cell *c, int timer) { #endif /* ... and store. */ - //c->ti_gravity_end_min = ti_gravity_end_min; - //c->ti_gravity_end_max = ti_gravity_end_max; + // c->ti_gravity_end_min = ti_gravity_end_min; + // c->ti_gravity_end_max = ti_gravity_end_max; c->ti_old_gpart = ti_current; if (timer) TIMER_TOC(timer_dorecv_spart); diff --git a/src/scheduler.c b/src/scheduler.c index 3b52cb570..8204351c2 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -897,8 +897,8 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { /* Since this task will not be split, we can already link it */ atomic_inc(&ci->nr_tasks); atomic_inc(&cj->nr_tasks); - engine_addlink(e, &ci->grav, t); - engine_addlink(e, &cj->grav, t); + engine_addlink(e, &ci->grav_mm, t); + engine_addlink(e, &cj->grav_mm, t); break; } diff --git a/src/space.c b/src/space.c index 6f98e788e..caf779553 100644 --- a/src/space.c +++ b/src/space.c @@ -168,6 +168,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->gradient = NULL; c->force = NULL; c->grav = NULL; + c->grav_mm = NULL; c->dx_max_part = 0.0f; c->dx_max_sort = 0.0f; c->sorted = 0; -- GitLab From f5a50abe0087f27d8d3002cb376cf6ec9cd2922a Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 12 Aug 2018 22:45:10 +0100 Subject: [PATCH 16/32] Do not activate communication tasks when unlocking an M-M one. --- src/cell.c | 2 ++ src/engine.c | 22 ---------------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/src/cell.c b/src/cell.c index e8038db1d..eba2ee675 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2348,6 +2348,8 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { /* Only activate tasks that involve a local active cell. */ if ((ci_active && ci_nodeID == nodeID) || (cj_active && cj_nodeID == nodeID)) { + + scheduler_activate(s, t); cell_activate_grav_mm_task(ci, cj, s); } } diff --git a/src/engine.c b/src/engine.c index 04694b2c9..6a840379f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -3741,28 +3741,6 @@ void engine_marktasks_mapper(void *map_data, int num_elements, if ((ci_active_gravity && ci_nodeID == engine_rank) || (cj_active_gravity && cj_nodeID == engine_rank)) scheduler_activate(s, t); - -#ifdef WITH_MPI - /* Activate the send/recv tasks. */ - if (ci->nodeID != engine_rank) { - - /* If the foreign cell is active, we want its ti_end values. */ - if (ci_active_gravity) scheduler_activate(s, ci->recv_ti); - - /* If the local cell is active, send its ti_end values. */ - if (cj_active_gravity) - scheduler_activate_send(s, cj->send_ti, ci->nodeID); - - } else if (cj->nodeID != engine_rank) { - - /* If the foreign cell is active, we want its ti_end values. */ - if (cj_active_gravity) scheduler_activate(s, cj->recv_ti); - - /* If the local cell is active, send its ti_end values. */ - if (ci_active_gravity) - scheduler_activate_send(s, ci->send_ti, cj->nodeID); - } -#endif } /* Time-step? */ -- GitLab From 073d67f289ddf0ccfb0ef064e70d9017187fdd5d Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" Date: Wed, 15 Aug 2018 12:12:13 +0100 Subject: [PATCH 17/32] Look for grav_mm tasks that will also need send_ti updates --- src/engine.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/engine.c b/src/engine.c index 04694b2c9..8529cb01f 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1458,6 +1458,11 @@ void engine_addtasks_send_timestep(struct engine *e, struct cell *ci, if (l->t->ci->nodeID == nodeID || (l->t->cj != NULL && l->t->cj->nodeID == nodeID)) break; + if (l == NULL) + for (l = ci->grav_mm; l != NULL; l = l->next) + if (l->t->ci->nodeID == nodeID || + (l->t->cj != NULL && l->t->cj->nodeID == nodeID)) + break; /* Check whether instead any of the hydro tasks are for the target node. */ if (l == NULL) -- GitLab From 1cef67c93fc680f304fb783caab04b09e57ec61d Mon Sep 17 00:00:00 2001 From: "Peter W. Draper" Date: Wed, 15 Aug 2018 12:57:27 +0100 Subject: [PATCH 18/32] Revert "Look for grav_mm tasks that will also need send_ti updates" Not the effect we're after. This reverts commit 073d67f289ddf0ccfb0ef064e70d9017187fdd5d. --- src/engine.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/engine.c b/src/engine.c index 8529cb01f..04694b2c9 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1458,11 +1458,6 @@ void engine_addtasks_send_timestep(struct engine *e, struct cell *ci, if (l->t->ci->nodeID == nodeID || (l->t->cj != NULL && l->t->cj->nodeID == nodeID)) break; - if (l == NULL) - for (l = ci->grav_mm; l != NULL; l = l->next) - if (l->t->ci->nodeID == nodeID || - (l->t->cj != NULL && l->t->cj->nodeID == nodeID)) - break; /* Check whether instead any of the hydro tasks are for the target node. */ if (l == NULL) -- GitLab From 82e9ddbc93dbe3285776a77392a4d4a997a19abc Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Wed, 15 Aug 2018 14:03:57 +0100 Subject: [PATCH 19/32] Do not link the M-M tasks in with the other gravity pair tasks. --- src/active.h | 2 +- src/cell.c | 2 +- src/cell.h | 3 +++ src/engine.c | 2 +- src/scheduler.c | 4 ++-- src/space.c | 1 + 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/active.h b/src/active.h index 3fe52a86b..d53c2fcce 100644 --- a/src/active.h +++ b/src/active.h @@ -129,7 +129,7 @@ __attribute__((always_inline)) INLINE static int cell_is_active_gravity( const struct cell *c, const struct engine *e) { #ifdef SWIFT_DEBUG_CHECKS - if (c->ti_gravity_end_min < e->ti_current) + if (c->ti_gravity_end_min < e->ti_current && c->nr_tasks > 0) error( "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and " "e->ti_current=%lld (t=%e, a=%e)", diff --git a/src/cell.c b/src/cell.c index eba2ee675..8ca6771a4 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2381,7 +2381,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { void cell_set_super(struct cell *c, struct cell *super) { /* Are we in a cell with some kind of self/pair task ? */ - if (super == NULL && c->nr_tasks > 0) super = c; + if (super == NULL && (c->nr_tasks > 0 || c->nr_mm_tasks > 0)) super = c; /* Set the super-cell */ c->super = super; diff --git a/src/cell.h b/src/cell.h index 534f9d704..ed017d2d1 100644 --- a/src/cell.h +++ b/src/cell.h @@ -428,6 +428,9 @@ struct cell { /*! Number of tasks that are associated with this cell. */ short int nr_tasks; + /*! Number of M-M tasks that are associated with this cell. */ + short int nr_mm_tasks; + /*! The depth of this cell in the tree. */ char depth; diff --git a/src/engine.c b/src/engine.c index 6a840379f..93c033d0c 100644 --- a/src/engine.c +++ b/src/engine.c @@ -4757,7 +4757,7 @@ void engine_step(struct engine *e) { e->min_active_bin = get_min_active_bin(e->ti_current, e->ti_old); e->step += 1; e->step_props = engine_step_prop_none; - + /* When restarting, move everyone to the current time. */ if (e->restarting) engine_drift_all(e); diff --git a/src/scheduler.c b/src/scheduler.c index 8204351c2..16e627f27 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -895,8 +895,8 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { t->subtype = task_subtype_none; /* Since this task will not be split, we can already link it */ - atomic_inc(&ci->nr_tasks); - atomic_inc(&cj->nr_tasks); + atomic_inc(&ci->nr_mm_tasks); + atomic_inc(&cj->nr_mm_tasks); engine_addlink(e, &ci->grav_mm, t); engine_addlink(e, &cj->grav_mm, t); break; diff --git a/src/space.c b/src/space.c index caf779553..81efe9984 100644 --- a/src/space.c +++ b/src/space.c @@ -164,6 +164,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, multipole_rec_end); c->sorts = NULL; c->nr_tasks = 0; + c->nr_mm_tasks = 0; c->density = NULL; c->gradient = NULL; c->force = NULL; -- GitLab From 24f8a41138a8453e54486b982ae601ef129abacb Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 24 Aug 2018 13:45:34 +0100 Subject: [PATCH 20/32] Make sure to reset all the timings when recycling a cell --- src/space.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/space.c b/src/space.c index 81efe9984..91661071f 100644 --- a/src/space.c +++ b/src/space.c @@ -204,6 +204,10 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->do_sub_sort = 0; c->do_grav_sub_drift = 0; c->do_sub_drift = 0; + c->ti_hydro_end_min = -1; + c->ti_hydro_end_max = -1; + c->ti_gravity_end_min = -1; + c->ti_gravity_end_max = -1; if (s->gravity) bzero(c->multipole, sizeof(struct gravity_tensors)); for (int i = 0; i < 13; i++) if (c->sort[i] != NULL) { -- GitLab From 0b6fc758e6ffd73523d7d240202f4bad5d0c3a75 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 24 Aug 2018 13:47:53 +0100 Subject: [PATCH 21/32] Added a lot of debugging calls to track assymetries between nodes. --- src/active.h | 16 ++++- src/cell.c | 142 +++++++++++++++++++++++++++++++++++---- src/cell.h | 6 ++ src/engine.c | 39 ++++++++--- src/runner_doiact_grav.h | 6 +- src/scheduler.c | 2 +- 6 files changed, 184 insertions(+), 27 deletions(-) diff --git a/src/active.h b/src/active.h index d53c2fcce..fedb668c8 100644 --- a/src/active.h +++ b/src/active.h @@ -129,7 +129,7 @@ __attribute__((always_inline)) INLINE static int cell_is_active_gravity( const struct cell *c, const struct engine *e) { #ifdef SWIFT_DEBUG_CHECKS - if (c->ti_gravity_end_min < e->ti_current && c->nr_tasks > 0) + if (c->ti_gravity_end_min < e->ti_current) error( "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and " "e->ti_current=%lld (t=%e, a=%e)", @@ -140,6 +140,20 @@ __attribute__((always_inline)) INLINE static int cell_is_active_gravity( return (c->ti_gravity_end_min == e->ti_current); } +/** + * @brief Does a cell contain any g-particle finishing their time-step now ? + * + * @param c The #cell. + * @param e The #engine containing information about the current time. + * @return 1 if the #cell contains at least an active particle, 0 otherwise. + */ +__attribute__((always_inline)) INLINE static int cell_is_active_gravity_mm( + const struct cell *c, const struct engine *e) { + + return (c->ti_gravity_end_min == e->ti_current); +} + + /** * @brief Are *all* g-particles in a cell finishing their time-step now ? * diff --git a/src/cell.c b/src/cell.c index 1ceb0556a..4d7cf05b9 100644 --- a/src/cell.c +++ b/src/cell.c @@ -67,6 +67,10 @@ /* Global variables. */ int cell_next_tag = 0; +integertime_t ti_current_global; + +extern FILE* file_dump; + /** * @brief Get the size of the cell subtree. * @@ -180,9 +184,12 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc) { pc->ti_hydro_end_max = c->ti_hydro_end_max; pc->ti_gravity_end_min = c->ti_gravity_end_min; pc->ti_gravity_end_max = c->ti_gravity_end_max; - pc->ti_old_part = c->ti_old_part; - pc->ti_old_gpart = c->ti_old_gpart; - pc->ti_old_multipole = c->ti_old_multipole; + //pc->ti_old_part = c->ti_old_part; + // pc->ti_old_gpart = c->ti_old_gpart; + //pc->ti_old_multipole = c->ti_old_multipole; + + pc->multipole = *(c->multipole); + pc->count = c->count; pc->gcount = c->gcount; pc->scount = c->scount; @@ -230,9 +237,16 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, c->ti_hydro_end_max = pc->ti_hydro_end_max; c->ti_gravity_end_min = pc->ti_gravity_end_min; c->ti_gravity_end_max = pc->ti_gravity_end_max; - c->ti_old_part = pc->ti_old_part; - c->ti_old_gpart = pc->ti_old_gpart; - c->ti_old_multipole = pc->ti_old_multipole; + //c->ti_old_part = pc->ti_old_part; + //c->ti_old_gpart = pc->ti_old_gpart; + //c->ti_old_multipole = pc->ti_old_multipole; + + c->ti_old_part = ti_current_global; + c->ti_old_gpart = ti_current_global; + c->ti_old_multipole = ti_current_global; + + *(c->multipole) = pc->multipole; + c->count = pc->count; c->gcount = pc->gcount; c->scount = pc->scount; @@ -339,6 +353,11 @@ int cell_unpack_end_step(struct cell *restrict c, c->ti_gravity_end_max = pcells[0].ti_gravity_end_max; c->dx_max_part = pcells[0].dx_max_part; + if(c->ti_last_update == ti_current_global && c->ti_last_update > 0) + error("Overwriting data"); + + c->ti_last_update = ti_current_global; + /* Fill in the progeny, depth-first recursion. */ int count = 1; for (int k = 0; k < 8; k++) @@ -1878,7 +1897,7 @@ void cell_activate_grav_mm_task(struct cell *ci, struct cell *cj, const struct engine *e = s->space->e; /* Anything to do here? */ - if (!cell_is_active_gravity(ci, e) && !cell_is_active_gravity(cj, e)) + if (!cell_is_active_gravity_mm(ci, e) && !cell_is_active_gravity_mm(cj, e)) error("Inactive MM task being activated"); /* Atomically drift the multipole in ci */ @@ -2273,7 +2292,9 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } else if (t->type == task_type_pair) { cell_activate_subcell_grav_tasks(ci, cj, s); } else if (t->type == task_type_grav_mm) { - error("Incorrectyl linked M-M task!"); +#ifdef SWIFT_DEBUG_CHECKS + error("Incorrectly linked M-M task!"); +#endif } } @@ -2284,8 +2305,18 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { if (ci_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ - if (cj_active) scheduler_activate(s, ci->recv_grav); + if (cj_active) {scheduler_activate(s, ci->recv_grav); + + fprintf(file_dump, "node %d activating cell %d to be received. ", + cj->nodeID, ci->cellID); + if(ci->parent == NULL) + fprintf(file_dump, "top\n"); + else + fprintf(file_dump, " \n"); + fflush(file_dump); + + } /* If the foreign cell is active, we want its ti_end values. */ if (ci_active) scheduler_activate(s, ci->recv_ti); @@ -2294,6 +2325,15 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { scheduler_activate_send(s, cj->send_grav, ci_nodeID); + fprintf(file_dump, "node %d activating cell %d to send to node %d ", + cj->nodeID, cj->cellID, ci->nodeID); + if(cj->parent == NULL) + fprintf(file_dump, "top\n"); + else + fprintf(file_dump, " \n"); + + fflush(file_dump); + /* Drift the cell which will be sent at the level at which it is sent, i.e. drift the cell specified in the send task (l->t) itself. */ @@ -2306,7 +2346,18 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } else if (cj_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ - if (ci_active) scheduler_activate(s, cj->recv_grav); + if (ci_active) {scheduler_activate(s, cj->recv_grav); + + fprintf(file_dump, "node %d activating cell %d to be received. ", + ci->nodeID, cj->cellID); + if(cj->parent == NULL) + fprintf(file_dump, "top\n"); + else + fprintf(file_dump, " \n"); + + + fflush(file_dump); + } /* If the foreign cell is active, we want its ti_end values. */ if (cj_active) scheduler_activate(s, cj->recv_ti); @@ -2316,6 +2367,15 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { scheduler_activate_send(s, ci->send_grav, cj_nodeID); + fprintf(file_dump, "node %d activating cell %d to sent to node %d", + ci->nodeID, ci->cellID, cj->nodeID); + if(ci->parent == NULL) + fprintf(file_dump, " top\n"); + else + fprintf(file_dump, " \n"); + + fflush(file_dump); + /* Drift the cell which will be sent at the level at which it is sent, i.e. drift the cell specified in the send task (l->t) itself. */ @@ -2334,8 +2394,8 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { struct task *t = l->t; struct cell *ci = t->ci; struct cell *cj = t->cj; - const int ci_active = cell_is_active_gravity(ci, e); - const int cj_active = (cj != NULL) ? cell_is_active_gravity(cj, e) : 0; + const int ci_active = cell_is_active_gravity_mm(ci, e); + const int cj_active = (cj != NULL) ? cell_is_active_gravity_mm(cj, e) : 0; #ifdef WITH_MPI const int ci_nodeID = ci->nodeID; const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; @@ -2344,7 +2404,9 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { const int cj_nodeID = nodeID; #endif +#ifdef SWIFT_DEBUG_CHECKS if (t->type != task_type_grav_mm) error("Incorrectly linked gravity task!"); +#endif /* Only activate tasks that involve a local active cell. */ if ((ci_active && ci_nodeID == nodeID) || @@ -2356,7 +2418,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } /* Unskip all the other task types. */ - if (c->nodeID == nodeID && cell_is_active_gravity(c, e)) { + if (c->nodeID == nodeID && cell_is_active_gravity_mm(c, e)) { if (c->init_grav != NULL) scheduler_activate(s, c->init_grav); if (c->init_grav_out != NULL) scheduler_activate(s, c->init_grav_out); @@ -2898,3 +2960,57 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, return gravity_M2L_accept(multi_i->r_max, multi_j->r_max, theta_crit2, r2); } + + +/** + * @brief Can we use the MM interactions fo a given pair of cells? + * + * @param ci The first #cell. + * @param cj The second #cell. + * @param e The #engine. + * @param s The #space. + */ +int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, + const struct engine *e, const struct space *s) { + + const double theta_crit2 = e->gravity_properties->theta_crit2; + const int periodic = s->periodic; + const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]}; + + /* Recover the multipole information */ + const struct gravity_tensors *const multi_i = ci->multipole; + const struct gravity_tensors *const multi_j = cj->multipole; + +#ifdef SWIFT_DEBUG_CHECKS + + if(multi_i->CoM[0] < ci->loc[0] || multi_i->CoM[0] > ci->loc[0] + ci->width[0]) + error("Invalid multipole position ci"); + if(multi_i->CoM[1] < ci->loc[1] || multi_i->CoM[1] > ci->loc[1] + ci->width[1]) + error("Invalid multipole position ci"); + if(multi_i->CoM[2] < ci->loc[2] || multi_i->CoM[2] > ci->loc[2] + ci->width[2]) + error("Invalid multipole position ci"); + + if(multi_j->CoM[0] < cj->loc[0] || multi_j->CoM[0] > cj->loc[0] + cj->width[0]) + error("Invalid multipole position cj"); + if(multi_j->CoM[1] < cj->loc[1] || multi_j->CoM[1] > cj->loc[1] + cj->width[1]) + error("Invalid multipole position cj"); + if(multi_j->CoM[2] < cj->loc[2] || multi_j->CoM[2] > cj->loc[2] + cj->width[2]) + error("Invalid multipole position cj"); + +#endif + + /* Get the distance between the CoMs */ + double dx = multi_i->CoM[0] - multi_j->CoM[0]; + double dy = multi_i->CoM[1] - multi_j->CoM[1]; + double dz = multi_i->CoM[2] - multi_j->CoM[2]; + + /* Apply BC */ + if (periodic) { + dx = nearest(dx, dim[0]); + dy = nearest(dy, dim[1]); + dz = nearest(dz, dim[2]); + } + const double r2 = dx * dx + dy * dy + dz * dz; + + return gravity_M2L_accept(multi_i->r_max, multi_j->r_max, theta_crit2, r2); +} diff --git a/src/cell.h b/src/cell.h index ed017d2d1..fc18ed510 100644 --- a/src/cell.h +++ b/src/cell.h @@ -122,6 +122,8 @@ struct pcell { /*! Relative indices of the cell's progeny. */ int progeny[8]; + struct gravity_tensors multipole; + #ifdef SWIFT_DEBUG_CHECKS /* Cell ID (for debugging) */ int cellID; @@ -157,6 +159,8 @@ struct pcell_step { */ struct cell { + integertime_t ti_last_update; + /*! The cell location on the grid. */ double loc[3]; @@ -529,6 +533,8 @@ void cell_set_super_mapper(void *map_data, int num_elements, void *extra_data); int cell_has_tasks(struct cell *c); int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const struct engine *e, const struct space *s); +int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, + const struct engine *e, const struct space *s); /* Inlined functions (for speed). */ diff --git a/src/engine.c b/src/engine.c index 78705411d..f35e4d80b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -92,6 +92,8 @@ /* Particle cache size. */ #define CACHE_SIZE 512 +FILE* file_dump; + const char *engine_policy_names[] = {"none", "rand", "steal", @@ -114,6 +116,8 @@ const char *engine_policy_names[] = {"none", /** The rank of the engine as a global variable (for messages). */ int engine_rank; +extern integertime_t ti_current_global; + /** * @brief Data collected from the cells at the end of a time-step */ @@ -2496,7 +2500,7 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, if (periodic && min_radius > max_distance) continue; /* Are the cells too close for a MM interaction ? */ - if (!cell_can_use_pair_mm(ci, cj, e, s)) { + if (!cell_can_use_pair_mm_rebuild(ci, cj, e, s)) { /* Ok, we need to add a direct pair calculation */ scheduler_addtask(sched, task_type_pair, task_subtype_grav, 0, 0, @@ -3739,8 +3743,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements, const struct cell *cj = t->cj; const int ci_nodeID = ci->nodeID; const int cj_nodeID = cj->nodeID; - const int ci_active_gravity = cell_is_active_gravity(ci, e); - const int cj_active_gravity = cell_is_active_gravity(cj, e); + const int ci_active_gravity = cell_is_active_gravity_mm(ci, e); + const int cj_active_gravity = cell_is_active_gravity_mm(cj, e); if ((ci_active_gravity && ci_nodeID == engine_rank) || (cj_active_gravity && cj_nodeID == engine_rank)) @@ -4003,12 +4007,12 @@ void engine_rebuild(struct engine *e, int clean_smoothing_length_values) { /* If in parallel, exchange the cell structure, top-level and neighbouring * multipoles. */ #ifdef WITH_MPI - engine_exchange_cells(e); - if (e->policy & engine_policy_self_gravity) engine_exchange_top_multipoles(e); - if (e->policy & engine_policy_self_gravity) - engine_exchange_proxy_multipoles(e); + engine_exchange_cells(e); + + //if (e->policy & engine_policy_self_gravity) + // engine_exchange_proxy_multipoles(e); #endif /* Re-build the tasks. */ @@ -4761,7 +4765,11 @@ void engine_step(struct engine *e) { e->min_active_bin = get_min_active_bin(e->ti_current, e->ti_old); e->step += 1; e->step_props = engine_step_prop_none; + + ti_current_global = e->ti_current; + fprintf(file_dump, "#################### Step %d #####################\n\n\n", e->step); + /* When restarting, move everyone to the current time. */ if (e->restarting) engine_drift_all(e); @@ -5344,7 +5352,7 @@ void engine_makeproxies(struct engine *e) { if (e->verbose) message( "Looking for proxies up to %d top-level cells away (delta_m=%d " - "delta_m=%d)", + "delta_p=%d)", delta, delta_m, delta_p); /* Loop over each cell in the space. */ @@ -5413,7 +5421,16 @@ void engine_makeproxies(struct engine *e) { if (with_gravity) { /* Are we too close for M2L? */ - if (!cell_can_use_pair_mm(&cells[cid], &cells[cjd], e, s)) + //if (!cell_can_use_pair_mm_rebuild(&cells[cid], &cells[cjd], e, s)) + /* if (((abs(ind[0] - ii) <= 5 || */ + /* abs(ind[0] - ii - cdim[0]) <= 5 || */ + /* abs(ind[0] - ii + cdim[0]) <= 5) && */ + /* (abs(ind[1] - jj) <= 5 || */ + /* abs(ind[1] - jj - cdim[1]) <= 5 || */ + /* abs(ind[1] - jj + cdim[1]) <= 5) && */ + /* (abs(ind[2] - kk) <= 5 || */ + /* abs(ind[2] - kk - cdim[2]) <= 5 || */ + /* abs(ind[2] - kk + cdim[2]) <= 5))) */ proxy_type |= (int)proxy_cell_type_gravity; } @@ -5893,6 +5910,10 @@ void engine_config(int restart, struct engine *e, struct swift_params *params, e->timeFirstSTFOutput = 0; engine_rank = nodeID; + char buffer[32]; + sprintf(buffer, "dump_%d.txt", engine_rank); + file_dump = fopen(buffer, "w"); + /* Initialise VELOCIraptor. */ if (e->policy & engine_policy_structure_finding) { parser_get_param_string(params, "StructureFinding:basename", diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h index 812a6e385..69213095a 100644 --- a/src/runner_doiact_grav.h +++ b/src/runner_doiact_grav.h @@ -1144,7 +1144,7 @@ static INLINE void runner_dopair_grav_mm(struct runner *r, TIMER_TIC; /* Anything to do here? */ - if (!cell_is_active_gravity(ci, e) || ci->nodeID != engine_rank) return; + if (!cell_is_active_gravity_mm(ci, e) || ci->nodeID != engine_rank) return; /* Short-cut to the multipole */ const struct multipole *multi_j = &cj->multipole->m_pole; @@ -1485,8 +1485,8 @@ static INLINE void runner_dopair_grav_mm_symmetric(struct runner *r, error("Running M-M task with two inactive cells."); #endif - if (cell_is_active_gravity(ci, e)) runner_dopair_grav_mm(r, ci, cj); - if (cell_is_active_gravity(cj, e)) runner_dopair_grav_mm(r, cj, ci); + if (cell_is_active_gravity_mm(ci, e)) runner_dopair_grav_mm(r, ci, cj); + if (cell_is_active_gravity_mm(cj, e)) runner_dopair_grav_mm(r, cj, ci); } /** diff --git a/src/scheduler.c b/src/scheduler.c index 16e627f27..78bbdcfb0 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -889,7 +889,7 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { } /* Should we replace it with an M-M task? */ - if (cell_can_use_pair_mm(ci, cj, e, sp)) { + if (cell_can_use_pair_mm_rebuild(ci, cj, e, sp)) { t->type = task_type_grav_mm; t->subtype = task_subtype_none; -- GitLab From 602a11647dac8251077d291ee7333de014bce271 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Fri, 24 Aug 2018 18:19:32 +0100 Subject: [PATCH 22/32] Record also the communications that have been activated between nodes. --- src/engine.c | 61 ++++++++++++++++++++++++++++++++++++---------------- src/space.c | 3 +++ 2 files changed, 46 insertions(+), 18 deletions(-) diff --git a/src/engine.c b/src/engine.c index f35e4d80b..ffe61d2b3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -93,6 +93,7 @@ #define CACHE_SIZE 512 FILE* file_dump; +FILE* file_tasks; const char *engine_policy_names[] = {"none", "rand", @@ -1389,6 +1390,9 @@ void engine_addtasks_send_hydro(struct engine *e, struct cell *ci, #endif } +int count_send[4]; +int count_recv[4]; + /** * @brief Add send tasks for the gravity pairs to a hierarchy of cells. * @@ -1420,6 +1424,8 @@ void engine_addtasks_send_gravity(struct engine *e, struct cell *ci, t_grav = scheduler_addtask(s, task_type_send, task_subtype_gpart, 6 * ci->tag + 4, 0, ci, cj); + count_send[nodeID]++; + /* The sends should unlock the down pass. */ scheduler_addunlock(s, t_grav, ci->super_gravity->grav_down); @@ -1582,6 +1588,10 @@ void engine_addtasks_recv_gravity(struct engine *e, struct cell *c, /* Create the tasks. */ t_grav = scheduler_addtask(s, task_type_recv, task_subtype_gpart, 6 * c->tag + 4, 0, c, NULL); + + if(c->nodeID < 0 || c->nodeID > 3) + error("Invalid nodeID"); + count_recv[c->nodeID]++; } c->recv_grav = t_grav; @@ -2210,8 +2220,8 @@ void engine_exchange_proxy_multipoles(struct engine *e) { const ticks tic = getticks(); /* Start by counting the number of cells to send and receive */ - int count_send = 0; - int count_recv = 0; + int count_send_cells = 0; + int count_recv_cells = 0; int count_send_requests = 0; int count_recv_requests = 0; @@ -2227,21 +2237,21 @@ void engine_exchange_proxy_multipoles(struct engine *e) { /* And the actual number of things we are going to ship */ for (int k = 0; k < p->nr_cells_in; k++) - count_recv += p->cells_in[k]->pcell_size; + count_recv_cells += p->cells_in[k]->pcell_size; for (int k = 0; k < p->nr_cells_out; k++) - count_send += p->cells_out[k]->pcell_size; + count_send_cells += p->cells_out[k]->pcell_size; } /* Allocate the buffers for the packed data */ struct gravity_tensors *buffer_send = NULL; if (posix_memalign((void **)&buffer_send, SWIFT_CACHE_ALIGNMENT, - count_send * sizeof(struct gravity_tensors)) != 0) + count_send_cells * sizeof(struct gravity_tensors)) != 0) error("Unable to allocate memory for multipole transactions"); struct gravity_tensors *buffer_recv = NULL; if (posix_memalign((void **)&buffer_recv, SWIFT_CACHE_ALIGNMENT, - count_recv * sizeof(struct gravity_tensors)) != 0) + count_recv_cells * sizeof(struct gravity_tensors)) != 0) error("Unable to allocate memory for multipole transactions"); /* Also allocate the MPI requests */ @@ -3321,6 +3331,11 @@ void engine_maketasks(struct engine *e) { message("Linking gravity tasks took %.3f %s.", clocks_from_ticks(getticks() - tic2), clocks_getunit()); + for(int k=0; k<4 ; ++k){ + count_send[k] = 0; + count_recv[k] = 0; + } + #ifdef WITH_MPI /* Add the communication tasks if MPI is being used. */ @@ -3373,6 +3388,12 @@ void engine_maketasks(struct engine *e) { } #endif + for(int k=0; k<4 ; ++k){ + fprintf(file_tasks, "Send to %d: %d\n", k, count_send[k]); + fprintf(file_tasks, "recv from %d: %d\n", k, count_recv[k]); + } + fflush(file_tasks); + tic2 = getticks(); /* Set the unlocks per task. */ @@ -3804,10 +3825,10 @@ void engine_print_task_counts(struct engine *e) { const int nr_tasks = sched->nr_tasks; const struct task *const tasks = sched->tasks; - int count_send_gpart = 0; - int count_recv_gpart = 0; - int count_send_tiend = 0; - int count_recv_tiend = 0; + int count_send_gpart[4] = {0}; + int count_recv_gpart[4] = {0}; + int count_send_tiend[4] = {0}; + int count_recv_tiend[4] = {0}; /* Count and print the number of each task type. */ int counts[task_type_count + 1]; @@ -3820,16 +3841,16 @@ void engine_print_task_counts(struct engine *e) { if (tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_gpart) - ++count_send_gpart; + ++count_send_gpart[tasks[k].cj->nodeID]; if (tasks[k].type == task_type_send && tasks[k].subtype == task_subtype_tend) - ++count_send_tiend; + ++count_send_tiend[tasks[k].cj->nodeID]; if (tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_gpart) - ++count_recv_gpart; + ++count_recv_gpart[tasks[k].ci->nodeID]; if (tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_tend) - ++count_recv_tiend; + ++count_recv_tiend[tasks[k].ci->nodeID]; } } message("Total = %d (per cell = %d)", nr_tasks, @@ -3845,10 +3866,10 @@ void engine_print_task_counts(struct engine *e) { printf(" %s=%i", taskID_names[k], counts[k]); printf(" skipped=%i ]\n", counts[task_type_count]); fflush(stdout); - message("send_gpart = %d", count_send_gpart); - message("send_tiend = %d", count_send_tiend); - message("recv_gpart = %d", count_recv_gpart); - message("recv_tiend = %d", count_recv_tiend); + message("send_gpart = %3d %3d %3d %3d", count_send_gpart[0], count_send_gpart[1], count_send_gpart[2], count_send_gpart[3]); + message("recv_gpart = %3d %3d %3d %3d", count_recv_gpart[0], count_recv_gpart[1], count_recv_gpart[2], count_recv_gpart[3]); + message("send_tiend = %3d %3d %3d %3d", count_send_tiend[0], count_send_tiend[1], count_send_tiend[2], count_send_tiend[3]); + message("recv_tiend = %3d %3d %3d %3d", count_recv_tiend[0], count_recv_tiend[1], count_recv_tiend[2], count_recv_tiend[3]); message("nr_parts = %zu.", e->s->nr_parts); message("nr_gparts = %zu.", e->s->nr_gparts); @@ -4769,6 +4790,7 @@ void engine_step(struct engine *e) { ti_current_global = e->ti_current; fprintf(file_dump, "#################### Step %d #####################\n\n\n", e->step); + fprintf(file_tasks, "#################### Step %d #####################\n\n\n", e->step); /* When restarting, move everyone to the current time. */ if (e->restarting) engine_drift_all(e); @@ -5914,6 +5936,9 @@ void engine_config(int restart, struct engine *e, struct swift_params *params, sprintf(buffer, "dump_%d.txt", engine_rank); file_dump = fopen(buffer, "w"); + sprintf(buffer, "tasks_%d.txt", engine_rank); + file_tasks = fopen(buffer, "w"); + /* Initialise VELOCIraptor. */ if (e->policy & engine_policy_structure_finding) { parser_get_param_string(params, "StructureFinding:basename", diff --git a/src/space.c b/src/space.c index 91661071f..3c0fc9b00 100644 --- a/src/space.c +++ b/src/space.c @@ -428,6 +428,7 @@ void space_regrid(struct space *s, int verbose) { c->ti_old_part = ti_current; c->ti_old_gpart = ti_current; c->ti_old_multipole = ti_current; + c->cellID = -(last_cell_id++); if (s->gravity) c->multipole = &s->multipoles_top[cid]; } @@ -2748,6 +2749,8 @@ void space_init(struct space *s, struct swift_params *params, #endif } + last_cell_id = 1; + /* Are we replicating the space ? */ if (replicate < 1) error("Value of 'InitialConditions:replicate' (%d) is too small", -- GitLab From 20f107e92e4c95c5618e59d82d28c0dc07544a43 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sat, 25 Aug 2018 12:37:47 +0100 Subject: [PATCH 23/32] Assign cellID to the top-level cells. Track the send and recvs on step 43. --- src/engine.c | 39 +++++++++++++++++++++++++++++++++++++++ src/space.c | 22 ++++++++++++++++++---- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/src/engine.c b/src/engine.c index ffe61d2b3..a3d4a781b 100644 --- a/src/engine.c +++ b/src/engine.c @@ -94,6 +94,8 @@ FILE* file_dump; FILE* file_tasks; +FILE* file_send; +FILE* file_recv; const char *engine_policy_names[] = {"none", "rand", @@ -3851,6 +3853,35 @@ void engine_print_task_counts(struct engine *e) { if (tasks[k].type == task_type_recv && tasks[k].subtype == task_subtype_tend) ++count_recv_tiend[tasks[k].ci->nodeID]; + + + if (tasks[k].type == task_type_send && + tasks[k].subtype == task_subtype_gpart) { + + int from = engine_rank; + int to = tasks[k].cj->nodeID; + + if((from == 3 && to == 0)) { + fprintf(file_send, "Sending cell ci=%d cj=%d to rank 3 (depth= %d %d)\n", + tasks[k].ci->cellID, tasks[k].cj->cellID, tasks[k].ci->depth, tasks[k].cj->depth); + fflush(file_send); + } + } + + if (tasks[k].type == task_type_recv && + tasks[k].subtype == task_subtype_gpart) { + + int to = engine_rank; + int from = tasks[k].ci->nodeID; + + if(to == 0 && from == 3) { + fprintf(file_recv, "Receiving cell ci=%d from rank 3 (depth= %d)\n", + tasks[k].ci->cellID, tasks[k].ci->depth); + fflush(file_recv); + + } + } + } } message("Total = %d (per cell = %d)", nr_tasks, @@ -4791,6 +4822,8 @@ void engine_step(struct engine *e) { fprintf(file_dump, "#################### Step %d #####################\n\n\n", e->step); fprintf(file_tasks, "#################### Step %d #####################\n\n\n", e->step); + fprintf(file_send, "#################### Step %d #####################\n\n\n", e->step); + fprintf(file_recv, "#################### Step %d #####################\n\n\n", e->step); /* When restarting, move everyone to the current time. */ if (e->restarting) engine_drift_all(e); @@ -5939,6 +5972,12 @@ void engine_config(int restart, struct engine *e, struct swift_params *params, sprintf(buffer, "tasks_%d.txt", engine_rank); file_tasks = fopen(buffer, "w"); + sprintf(buffer, "send_%d.txt", engine_rank); + file_send = fopen(buffer, "w"); + + sprintf(buffer, "recv_%d.txt", engine_rank); + file_recv = fopen(buffer, "w"); + /* Initialise VELOCIraptor. */ if (e->policy & engine_policy_structure_finding) { parser_get_param_string(params, "StructureFinding:basename", diff --git a/src/space.c b/src/space.c index 3c0fc9b00..7e85f5cdc 100644 --- a/src/space.c +++ b/src/space.c @@ -208,6 +208,9 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->ti_hydro_end_max = -1; c->ti_gravity_end_min = -1; c->ti_gravity_end_max = -1; +#ifdef SWIFT_DEBUG_CHECKS + c->cellID = 0; +#endif if (s->gravity) bzero(c->multipole, sizeof(struct gravity_tensors)); for (int i = 0; i < 13; i++) if (c->sort[i] != NULL) { @@ -338,7 +341,7 @@ void space_regrid(struct space *s, int verbose) { /* Are we about to allocate new top level cells without a regrid? * Can happen when restarting the application. */ - int no_regrid = (s->cells_top == NULL && oldnodeIDs == NULL); + const int no_regrid = (s->cells_top == NULL && oldnodeIDs == NULL); #endif /* Do we need to re-build the upper-level cells? */ @@ -428,8 +431,12 @@ void space_regrid(struct space *s, int verbose) { c->ti_old_part = ti_current; c->ti_old_gpart = ti_current; c->ti_old_multipole = ti_current; - c->cellID = -(last_cell_id++); if (s->gravity) c->multipole = &s->multipoles_top[cid]; + //#ifdef SWIFT_DEBUG_CHECKS + c->cellID = -last_cell_id; + last_cell_id++; + message("cid=%lld cellID=%d", cid, c->cellID); + //#endif } /* Be verbose about the change. */ @@ -921,6 +928,11 @@ void space_rebuild(struct space *s, int verbose) { c->ti_old_part = ti_current; c->ti_old_gpart = ti_current; c->ti_old_multipole = ti_current; + + c->cellID = -last_cell_id; + last_cell_id++; + message("cid=%d cellID=%d", k, c->cellID); + if (c->nodeID == engine_rank) { c->parts = finger; c->xparts = xfinger; @@ -2749,8 +2761,6 @@ void space_init(struct space *s, struct swift_params *params, #endif } - last_cell_id = 1; - /* Are we replicating the space ? */ if (replicate < 1) error("Value of 'InitialConditions:replicate' (%d) is too small", @@ -2904,6 +2914,10 @@ void space_init(struct space *s, struct swift_params *params, /* Init the space lock. */ if (lock_init(&s->lock) != 0) error("Failed to create space spin-lock."); +#ifdef SWIFT_DEBUG_CHECKS + last_cell_id = 1; +#endif + /* Build the cells recursively. */ if (!dry_run) space_regrid(s, verbose); } -- GitLab From 76587e71da70ed97b8120b64fd1bf304a3150e0a Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sat, 25 Aug 2018 20:59:25 +0100 Subject: [PATCH 24/32] Traced the bug back to the splitting condition in scheduler_splittask not being symmetric because of rounding --- src/engine.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ src/scheduler.c | 36 ++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/src/engine.c b/src/engine.c index a3d4a781b..2be2d5ec3 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2514,6 +2514,12 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, /* Are the cells too close for a MM interaction ? */ if (!cell_can_use_pair_mm_rebuild(ci, cj, e, s)) { + if(ci->cellID == -111895 || cj->cellID == -111895) { + + message("Constructing grav task! t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", + ci->cellID, cj->cellID, ci->nodeID, cj->nodeID); + } + /* Ok, we need to add a direct pair calculation */ scheduler_addtask(sched, task_type_pair, task_subtype_grav, 0, 0, ci, cj); @@ -2700,6 +2706,14 @@ void engine_count_and_link_tasks_mapper(void *map_data, int num_elements, engine_addlink(e, &ci->density, t); engine_addlink(e, &cj->density, t); } else if (t_subtype == task_subtype_grav) { + + if((ci->cellID == -91806 && cj->cellID == -111895) || + (cj->cellID == -91806 && ci->cellID == -111895)) { + + message("Task linked to ci and cj"); + + } + engine_addlink(e, &ci->grav, t); engine_addlink(e, &cj->grav, t); } @@ -3268,6 +3282,25 @@ void engine_maketasks(struct engine *e) { tic2 = getticks(); + for(int i = 0; isched.nr_tasks; ++i) { + + struct task *t = &e->sched.tasks[i]; + + if(t->type == task_type_pair && t->subtype == task_subtype_grav) { + + struct cell *ci = t->ci; + struct cell *cj = t->cj; + + if((ci->cellID == -91806 && cj->cellID == -111895) || + (cj->cellID == -91806 && ci->cellID == -111895)) { + + message("Found the task!"); + } + + } + + } + /* Split the tasks. */ scheduler_splittasks(sched); @@ -4878,6 +4911,39 @@ void engine_step(struct engine *e) { /* Print the number of active tasks ? */ if (e->step == 43) engine_print_task_counts(e); + if (e->step == 43) { + + for(int i = 0; i < e->s->nr_cells; ++i) { + + const struct cell *c = &e->s->cells_top[i]; + + if(c->cellID == -111895) { + + message("c->loc= [%f %f %f]", c->loc[0], c->loc[1], c->loc[2]); + message("c->depth= %d", c->depth); + message("c->nodeID= %d", c->nodeID); + message("c->gcount= %d c->count= %d c->scount= %d", c->gcount, c->count, c->scount); + message("c->ti_hydro_end_min= %lld c->ti_gravity_end_min= %lld", c->ti_hydro_end_min, c->ti_gravity_end_min); +#ifdef WITH_MPI + message("c->recv_grav= %p", c->recv_grav); + if(c->recv_grav) + message("c->recv_grav->skip= %d c->recv_grav->wait= %d", c->recv_grav->skip, c->recv_grav->wait); + + if(c->send_grav) + for(struct link *l = c->send_grav; l!=NULL; l = l->next) + message("Send task: t->cj->nodeID=%d t->skip=%d", l->t->cj->nodeID, l->t->skip); + + if(c->grav) + for(struct link *l = c->grav; l!=NULL; l = l->next) + if(l->t->type == task_type_pair) + message("grav task t->wait=%d t->skip=%d t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", + l->t->wait, l->t->skip, l->t->ci->cellID, l->t->cj->cellID, l->t->ci->nodeID, l->t->cj->nodeID); +#endif + + } + } + } + /* Dump local cells and active particle counts. */ /* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */ diff --git a/src/scheduler.c b/src/scheduler.c index 78bbdcfb0..314589d0e 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -888,12 +888,28 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { break; } + if((ci->cellID == -91806 && cj->cellID == -111895) || + (cj->cellID == -91806 && ci->cellID == -111895)) { + + message("Found the task! ci->cellID=%d cj->cellID=%d ci->nodeID=%d cj->nodeID=%d ci->gcount=%d cj->gcount=%d ci->split=%d cj->split=%d ci->depth=%d cj->depth=%d", + ci->cellID, cj->cellID, ci->nodeID, cj->nodeID, ci->gcount, cj->gcount, + ci->split, cj->split, ci->depth, cj->depth); + } + + /* Should we replace it with an M-M task? */ if (cell_can_use_pair_mm_rebuild(ci, cj, e, sp)) { t->type = task_type_grav_mm; t->subtype = task_subtype_none; + if((ci->cellID == -91806 && cj->cellID == -111895) || + (cj->cellID == -91806 && ci->cellID == -111895)) { + + message("Replaced by M-M task!"); + + } + /* Since this task will not be split, we can already link it */ atomic_inc(&ci->nr_mm_tasks); atomic_inc(&cj->nr_mm_tasks); @@ -906,9 +922,20 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { if (cell_can_split_pair_gravity_task(ci) && cell_can_split_pair_gravity_task(cj)) { + const long long gcount_i = ci->gcount; + const long long gcount_j = cj->gcount; + /* Replace by a single sub-task? */ if (scheduler_dosub && /* Use division to avoid integer overflow. */ - ci->gcount < space_subsize_pair_grav / cj->gcount) { + gcount_i * gcount_j < ((long long) space_subsize_pair_grav)) { + + if((ci->cellID == -91806 && cj->cellID == -111895) || + (cj->cellID == -91806 && ci->cellID == -111895)) { + + message("Do nothing!"); + + } + /* Otherwise, split it. */ } else { @@ -916,6 +943,13 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { /* Take a step back (we're going to recycle the current task)... */ redo = 1; + if((ci->cellID == -91806 && cj->cellID == -111895) || + (cj->cellID == -91806 && ci->cellID == -111895)) { + + message("Split into smaller tasks!"); + + } + /* Find the first non-empty childrens of the cells */ int first_ci_child = 0, first_cj_child = 0; while (ci->progeny[first_ci_child] == NULL) first_ci_child++; -- GitLab From 7a66956896168beaca9eb9bbcdb7959990e7ce89 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sat, 25 Aug 2018 21:44:22 +0100 Subject: [PATCH 25/32] Removed some of the debugging checks --- src/cell.c | 59 +++++++++++++--------------- src/engine.c | 102 ++++++++++++++++++++++++------------------------ src/scheduler.c | 36 ++++++++--------- src/space.c | 10 ++--- 4 files changed, 102 insertions(+), 105 deletions(-) diff --git a/src/cell.c b/src/cell.c index 4d7cf05b9..eff14a551 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2307,14 +2307,14 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { /* If the local cell is active, receive data from the foreign cell. */ if (cj_active) {scheduler_activate(s, ci->recv_grav); - fprintf(file_dump, "node %d activating cell %d to be received. ", - cj->nodeID, ci->cellID); - if(ci->parent == NULL) - fprintf(file_dump, "top\n"); - else - fprintf(file_dump, " \n"); + /* fprintf(file_dump, "node %d activating cell %d to be received. ", */ + /* cj->nodeID, ci->cellID); */ + /* if(ci->parent == NULL) */ + /* fprintf(file_dump, "top\n"); */ + /* else */ + /* fprintf(file_dump, " \n"); */ - fflush(file_dump); + /* fflush(file_dump); */ } /* If the foreign cell is active, we want its ti_end values. */ @@ -2325,14 +2325,14 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { scheduler_activate_send(s, cj->send_grav, ci_nodeID); - fprintf(file_dump, "node %d activating cell %d to send to node %d ", - cj->nodeID, cj->cellID, ci->nodeID); - if(cj->parent == NULL) - fprintf(file_dump, "top\n"); - else - fprintf(file_dump, " \n"); + /* fprintf(file_dump, "node %d activating cell %d to send to node %d ", */ + /* cj->nodeID, cj->cellID, ci->nodeID); */ + /* if(cj->parent == NULL) */ + /* fprintf(file_dump, "top\n"); */ + /* else */ + /* fprintf(file_dump, " \n"); */ - fflush(file_dump); + /* fflush(file_dump); */ /* Drift the cell which will be sent at the level at which it is sent, i.e. drift the cell specified in the send task (l->t) @@ -2348,15 +2348,13 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { /* If the local cell is active, receive data from the foreign cell. */ if (ci_active) {scheduler_activate(s, cj->recv_grav); - fprintf(file_dump, "node %d activating cell %d to be received. ", - ci->nodeID, cj->cellID); - if(cj->parent == NULL) - fprintf(file_dump, "top\n"); - else - fprintf(file_dump, " \n"); - - - fflush(file_dump); + /* fprintf(file_dump, "node %d activating cell %d to be received. ", */ + /* ci->nodeID, cj->cellID); */ + /* if(cj->parent == NULL) */ + /* fprintf(file_dump, "top\n"); */ + /* else */ + /* fprintf(file_dump, " \n"); */ + /* fflush(file_dump); */ } /* If the foreign cell is active, we want its ti_end values. */ @@ -2367,14 +2365,13 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { scheduler_activate_send(s, ci->send_grav, cj_nodeID); - fprintf(file_dump, "node %d activating cell %d to sent to node %d", - ci->nodeID, ci->cellID, cj->nodeID); - if(ci->parent == NULL) - fprintf(file_dump, " top\n"); - else - fprintf(file_dump, " \n"); - - fflush(file_dump); + /* fprintf(file_dump, "node %d activating cell %d to sent to node %d", */ + /* ci->nodeID, ci->cellID, cj->nodeID); */ + /* if(ci->parent == NULL) */ + /* fprintf(file_dump, " top\n"); */ + /* else */ + /* fprintf(file_dump, " \n"); */ + /* fflush(file_dump); */ /* Drift the cell which will be sent at the level at which it is sent, i.e. drift the cell specified in the send task (l->t) diff --git a/src/engine.c b/src/engine.c index 2be2d5ec3..20918d43d 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2514,11 +2514,11 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, /* Are the cells too close for a MM interaction ? */ if (!cell_can_use_pair_mm_rebuild(ci, cj, e, s)) { - if(ci->cellID == -111895 || cj->cellID == -111895) { + /* if(ci->cellID == -111895 || cj->cellID == -111895) { */ - message("Constructing grav task! t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", - ci->cellID, cj->cellID, ci->nodeID, cj->nodeID); - } + /* message("Constructing grav task! t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", */ + /* ci->cellID, cj->cellID, ci->nodeID, cj->nodeID); */ + /* } */ /* Ok, we need to add a direct pair calculation */ scheduler_addtask(sched, task_type_pair, task_subtype_grav, 0, 0, @@ -2707,12 +2707,12 @@ void engine_count_and_link_tasks_mapper(void *map_data, int num_elements, engine_addlink(e, &cj->density, t); } else if (t_subtype == task_subtype_grav) { - if((ci->cellID == -91806 && cj->cellID == -111895) || - (cj->cellID == -91806 && ci->cellID == -111895)) { + /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ + /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - message("Task linked to ci and cj"); + /* message("Task linked to ci and cj"); */ - } + /* } */ engine_addlink(e, &ci->grav, t); engine_addlink(e, &cj->grav, t); @@ -3282,24 +3282,24 @@ void engine_maketasks(struct engine *e) { tic2 = getticks(); - for(int i = 0; isched.nr_tasks; ++i) { + /* for(int i = 0; isched.nr_tasks; ++i) { */ - struct task *t = &e->sched.tasks[i]; + /* struct task *t = &e->sched.tasks[i]; */ - if(t->type == task_type_pair && t->subtype == task_subtype_grav) { + /* if(t->type == task_type_pair && t->subtype == task_subtype_grav) { */ - struct cell *ci = t->ci; - struct cell *cj = t->cj; + /* struct cell *ci = t->ci; */ + /* struct cell *cj = t->cj; */ - if((ci->cellID == -91806 && cj->cellID == -111895) || - (cj->cellID == -91806 && ci->cellID == -111895)) { + /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ + /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - message("Found the task!"); - } + /* message("Found the task!"); */ + /* } */ - } + /* } */ - } + /* } */ /* Split the tasks. */ scheduler_splittasks(sched); @@ -3895,8 +3895,8 @@ void engine_print_task_counts(struct engine *e) { int to = tasks[k].cj->nodeID; if((from == 3 && to == 0)) { - fprintf(file_send, "Sending cell ci=%d cj=%d to rank 3 (depth= %d %d)\n", - tasks[k].ci->cellID, tasks[k].cj->cellID, tasks[k].ci->depth, tasks[k].cj->depth); + /* fprintf(file_send, "Sending cell ci=%d cj=%d to rank 3 (depth= %d %d)\n", */ + /* tasks[k].ci->cellID, tasks[k].cj->cellID, tasks[k].ci->depth, tasks[k].cj->depth); */ fflush(file_send); } } @@ -3908,8 +3908,8 @@ void engine_print_task_counts(struct engine *e) { int from = tasks[k].ci->nodeID; if(to == 0 && from == 3) { - fprintf(file_recv, "Receiving cell ci=%d from rank 3 (depth= %d)\n", - tasks[k].ci->cellID, tasks[k].ci->depth); + /* fprintf(file_recv, "Receiving cell ci=%d from rank 3 (depth= %d)\n", */ + /* tasks[k].ci->cellID, tasks[k].ci->depth); */ fflush(file_recv); } @@ -4909,40 +4909,40 @@ void engine_step(struct engine *e) { engine_prepare(e); /* Print the number of active tasks ? */ - if (e->step == 43) engine_print_task_counts(e); + //if (e->step == 43) engine_print_task_counts(e); - if (e->step == 43) { +/* if (e->step == 43) { */ - for(int i = 0; i < e->s->nr_cells; ++i) { +/* for(int i = 0; i < e->s->nr_cells; ++i) { */ - const struct cell *c = &e->s->cells_top[i]; +/* const struct cell *c = &e->s->cells_top[i]; */ - if(c->cellID == -111895) { +/* if(c->cellID == -111895) { */ - message("c->loc= [%f %f %f]", c->loc[0], c->loc[1], c->loc[2]); - message("c->depth= %d", c->depth); - message("c->nodeID= %d", c->nodeID); - message("c->gcount= %d c->count= %d c->scount= %d", c->gcount, c->count, c->scount); - message("c->ti_hydro_end_min= %lld c->ti_gravity_end_min= %lld", c->ti_hydro_end_min, c->ti_gravity_end_min); -#ifdef WITH_MPI - message("c->recv_grav= %p", c->recv_grav); - if(c->recv_grav) - message("c->recv_grav->skip= %d c->recv_grav->wait= %d", c->recv_grav->skip, c->recv_grav->wait); - - if(c->send_grav) - for(struct link *l = c->send_grav; l!=NULL; l = l->next) - message("Send task: t->cj->nodeID=%d t->skip=%d", l->t->cj->nodeID, l->t->skip); - - if(c->grav) - for(struct link *l = c->grav; l!=NULL; l = l->next) - if(l->t->type == task_type_pair) - message("grav task t->wait=%d t->skip=%d t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", - l->t->wait, l->t->skip, l->t->ci->cellID, l->t->cj->cellID, l->t->ci->nodeID, l->t->cj->nodeID); -#endif +/* message("c->loc= [%f %f %f]", c->loc[0], c->loc[1], c->loc[2]); */ +/* message("c->depth= %d", c->depth); */ +/* message("c->nodeID= %d", c->nodeID); */ +/* message("c->gcount= %d c->count= %d c->scount= %d", c->gcount, c->count, c->scount); */ +/* message("c->ti_hydro_end_min= %lld c->ti_gravity_end_min= %lld", c->ti_hydro_end_min, c->ti_gravity_end_min); */ +/* #ifdef WITH_MPI */ +/* message("c->recv_grav= %p", c->recv_grav); */ +/* if(c->recv_grav) */ +/* message("c->recv_grav->skip= %d c->recv_grav->wait= %d", c->recv_grav->skip, c->recv_grav->wait); */ - } - } - } +/* if(c->send_grav) */ +/* for(struct link *l = c->send_grav; l!=NULL; l = l->next) */ +/* message("Send task: t->cj->nodeID=%d t->skip=%d", l->t->cj->nodeID, l->t->skip); */ + +/* if(c->grav) */ +/* for(struct link *l = c->grav; l!=NULL; l = l->next) */ +/* if(l->t->type == task_type_pair) */ +/* message("grav task t->wait=%d t->skip=%d t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", */ +/* l->t->wait, l->t->skip, l->t->ci->cellID, l->t->cj->cellID, l->t->ci->nodeID, l->t->cj->nodeID); */ +/* #endif */ + +/* } */ +/* } */ +/* } */ /* Dump local cells and active particle counts. */ /* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */ diff --git a/src/scheduler.c b/src/scheduler.c index 314589d0e..c6b9b5547 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -888,13 +888,13 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { break; } - if((ci->cellID == -91806 && cj->cellID == -111895) || - (cj->cellID == -91806 && ci->cellID == -111895)) { + /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ + /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - message("Found the task! ci->cellID=%d cj->cellID=%d ci->nodeID=%d cj->nodeID=%d ci->gcount=%d cj->gcount=%d ci->split=%d cj->split=%d ci->depth=%d cj->depth=%d", - ci->cellID, cj->cellID, ci->nodeID, cj->nodeID, ci->gcount, cj->gcount, - ci->split, cj->split, ci->depth, cj->depth); - } + /* message("Found the task! ci->cellID=%d cj->cellID=%d ci->nodeID=%d cj->nodeID=%d ci->gcount=%d cj->gcount=%d ci->split=%d cj->split=%d ci->depth=%d cj->depth=%d", */ + /* ci->cellID, cj->cellID, ci->nodeID, cj->nodeID, ci->gcount, cj->gcount, */ + /* ci->split, cj->split, ci->depth, cj->depth); */ + /* } */ /* Should we replace it with an M-M task? */ @@ -903,12 +903,12 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { t->type = task_type_grav_mm; t->subtype = task_subtype_none; - if((ci->cellID == -91806 && cj->cellID == -111895) || - (cj->cellID == -91806 && ci->cellID == -111895)) { + /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ + /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - message("Replaced by M-M task!"); + /* message("Replaced by M-M task!"); */ - } + /* } */ /* Since this task will not be split, we can already link it */ atomic_inc(&ci->nr_mm_tasks); @@ -929,12 +929,12 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { if (scheduler_dosub && /* Use division to avoid integer overflow. */ gcount_i * gcount_j < ((long long) space_subsize_pair_grav)) { - if((ci->cellID == -91806 && cj->cellID == -111895) || - (cj->cellID == -91806 && ci->cellID == -111895)) { + /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ + /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - message("Do nothing!"); + /* message("Do nothing!"); */ - } + /* } */ /* Otherwise, split it. */ @@ -943,12 +943,12 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { /* Take a step back (we're going to recycle the current task)... */ redo = 1; - if((ci->cellID == -91806 && cj->cellID == -111895) || - (cj->cellID == -91806 && ci->cellID == -111895)) { + /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ + /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - message("Split into smaller tasks!"); + /* message("Split into smaller tasks!"); */ - } + /* } */ /* Find the first non-empty childrens of the cells */ int first_ci_child = 0, first_cj_child = 0; diff --git a/src/space.c b/src/space.c index 7e85f5cdc..74fa307ea 100644 --- a/src/space.c +++ b/src/space.c @@ -432,11 +432,10 @@ void space_regrid(struct space *s, int verbose) { c->ti_old_gpart = ti_current; c->ti_old_multipole = ti_current; if (s->gravity) c->multipole = &s->multipoles_top[cid]; - //#ifdef SWIFT_DEBUG_CHECKS +#ifdef SWIFT_DEBUG_CHECKS c->cellID = -last_cell_id; last_cell_id++; - message("cid=%lld cellID=%d", cid, c->cellID); - //#endif +#endif } /* Be verbose about the change. */ @@ -928,10 +927,11 @@ void space_rebuild(struct space *s, int verbose) { c->ti_old_part = ti_current; c->ti_old_gpart = ti_current; c->ti_old_multipole = ti_current; - + +#ifdef SWIFT_DEBUG_CHECKS c->cellID = -last_cell_id; last_cell_id++; - message("cid=%d cellID=%d", k, c->cellID); +#endif if (c->nodeID == engine_rank) { c->parts = finger; -- GitLab From 0ec04f1f0d2fb1dbec82994770ecb2a40e1fc727 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sat, 25 Aug 2018 23:35:33 +0200 Subject: [PATCH 26/32] Removed debugging code. --- examples/main.c | 2 +- src/active.h | 3 +- src/cell.c | 93 ++++++----------------- src/cell.h | 6 +- src/engine.c | 193 +++--------------------------------------------- src/scheduler.c | 37 +--------- src/space.c | 6 +- 7 files changed, 40 insertions(+), 300 deletions(-) diff --git a/examples/main.c b/examples/main.c index 7a45dc1d9..891715616 100644 --- a/examples/main.c +++ b/examples/main.c @@ -933,7 +933,7 @@ int main(int argc, char *argv[]) { engine_init_particles(&e, flag_entropy_ICs, clean_smoothing_length_values); /* Write the state of the system before starting time integration. */ - // engine_dump_snapshot(&e); + engine_dump_snapshot(&e); engine_print_stats(&e); #ifdef HAVE_VELOCIRAPTOR diff --git a/src/active.h b/src/active.h index fedb668c8..949babf1b 100644 --- a/src/active.h +++ b/src/active.h @@ -141,7 +141,7 @@ __attribute__((always_inline)) INLINE static int cell_is_active_gravity( } /** - * @brief Does a cell contain any g-particle finishing their time-step now ? + * @brief Does a cell contain any multipole requiring calculation ? * * @param c The #cell. * @param e The #engine containing information about the current time. @@ -153,7 +153,6 @@ __attribute__((always_inline)) INLINE static int cell_is_active_gravity_mm( return (c->ti_gravity_end_min == e->ti_current); } - /** * @brief Are *all* g-particles in a cell finishing their time-step now ? * diff --git a/src/cell.c b/src/cell.c index eff14a551..81fe668da 100644 --- a/src/cell.c +++ b/src/cell.c @@ -67,10 +67,6 @@ /* Global variables. */ int cell_next_tag = 0; -integertime_t ti_current_global; - -extern FILE* file_dump; - /** * @brief Get the size of the cell subtree. * @@ -184,12 +180,9 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc) { pc->ti_hydro_end_max = c->ti_hydro_end_max; pc->ti_gravity_end_min = c->ti_gravity_end_min; pc->ti_gravity_end_max = c->ti_gravity_end_max; - //pc->ti_old_part = c->ti_old_part; - // pc->ti_old_gpart = c->ti_old_gpart; - //pc->ti_old_multipole = c->ti_old_multipole; - - pc->multipole = *(c->multipole); - + pc->ti_old_part = c->ti_old_part; + pc->ti_old_gpart = c->ti_old_gpart; + pc->ti_old_multipole = c->ti_old_multipole; pc->count = c->count; pc->gcount = c->gcount; pc->scount = c->scount; @@ -237,16 +230,9 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, c->ti_hydro_end_max = pc->ti_hydro_end_max; c->ti_gravity_end_min = pc->ti_gravity_end_min; c->ti_gravity_end_max = pc->ti_gravity_end_max; - //c->ti_old_part = pc->ti_old_part; - //c->ti_old_gpart = pc->ti_old_gpart; - //c->ti_old_multipole = pc->ti_old_multipole; - - c->ti_old_part = ti_current_global; - c->ti_old_gpart = ti_current_global; - c->ti_old_multipole = ti_current_global; - - *(c->multipole) = pc->multipole; - + c->ti_old_part = pc->ti_old_part; + c->ti_old_gpart = pc->ti_old_gpart; + c->ti_old_multipole = pc->ti_old_multipole; c->count = pc->count; c->gcount = pc->gcount; c->scount = pc->scount; @@ -353,11 +339,6 @@ int cell_unpack_end_step(struct cell *restrict c, c->ti_gravity_end_max = pcells[0].ti_gravity_end_max; c->dx_max_part = pcells[0].dx_max_part; - if(c->ti_last_update == ti_current_global && c->ti_last_update > 0) - error("Overwriting data"); - - c->ti_last_update = ti_current_global; - /* Fill in the progeny, depth-first recursion. */ int count = 1; for (int k = 0; k < 8; k++) @@ -2305,18 +2286,8 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { if (ci_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ - if (cj_active) {scheduler_activate(s, ci->recv_grav); + if (cj_active) scheduler_activate(s, ci->recv_grav); - /* fprintf(file_dump, "node %d activating cell %d to be received. ", */ - /* cj->nodeID, ci->cellID); */ - /* if(ci->parent == NULL) */ - /* fprintf(file_dump, "top\n"); */ - /* else */ - /* fprintf(file_dump, " \n"); */ - - /* fflush(file_dump); */ - - } /* If the foreign cell is active, we want its ti_end values. */ if (ci_active) scheduler_activate(s, ci->recv_ti); @@ -2325,15 +2296,6 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { scheduler_activate_send(s, cj->send_grav, ci_nodeID); - /* fprintf(file_dump, "node %d activating cell %d to send to node %d ", */ - /* cj->nodeID, cj->cellID, ci->nodeID); */ - /* if(cj->parent == NULL) */ - /* fprintf(file_dump, "top\n"); */ - /* else */ - /* fprintf(file_dump, " \n"); */ - - /* fflush(file_dump); */ - /* Drift the cell which will be sent at the level at which it is sent, i.e. drift the cell specified in the send task (l->t) itself. */ @@ -2346,16 +2308,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { } else if (cj_nodeID != nodeID) { /* If the local cell is active, receive data from the foreign cell. */ - if (ci_active) {scheduler_activate(s, cj->recv_grav); - - /* fprintf(file_dump, "node %d activating cell %d to be received. ", */ - /* ci->nodeID, cj->cellID); */ - /* if(cj->parent == NULL) */ - /* fprintf(file_dump, "top\n"); */ - /* else */ - /* fprintf(file_dump, " \n"); */ - /* fflush(file_dump); */ - } + if (ci_active) scheduler_activate(s, cj->recv_grav); /* If the foreign cell is active, we want its ti_end values. */ if (cj_active) scheduler_activate(s, cj->recv_ti); @@ -2365,14 +2318,6 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { scheduler_activate_send(s, ci->send_grav, cj_nodeID); - /* fprintf(file_dump, "node %d activating cell %d to sent to node %d", */ - /* ci->nodeID, ci->cellID, cj->nodeID); */ - /* if(ci->parent == NULL) */ - /* fprintf(file_dump, " top\n"); */ - /* else */ - /* fprintf(file_dump, " \n"); */ - /* fflush(file_dump); */ - /* Drift the cell which will be sent at the level at which it is sent, i.e. drift the cell specified in the send task (l->t) itself. */ @@ -2958,7 +2903,6 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, return gravity_M2L_accept(multi_i->r_max, multi_j->r_max, theta_crit2, r2); } - /** * @brief Can we use the MM interactions fo a given pair of cells? * @@ -2968,7 +2912,8 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, * @param s The #space. */ int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, - const struct engine *e, const struct space *s) { + const struct engine *e, + const struct space *s) { const double theta_crit2 = e->gravity_properties->theta_crit2; const int periodic = s->periodic; @@ -2980,18 +2925,24 @@ int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, #ifdef SWIFT_DEBUG_CHECKS - if(multi_i->CoM[0] < ci->loc[0] || multi_i->CoM[0] > ci->loc[0] + ci->width[0]) + if (multi_i->CoM[0] < ci->loc[0] || + multi_i->CoM[0] > ci->loc[0] + ci->width[0]) error("Invalid multipole position ci"); - if(multi_i->CoM[1] < ci->loc[1] || multi_i->CoM[1] > ci->loc[1] + ci->width[1]) + if (multi_i->CoM[1] < ci->loc[1] || + multi_i->CoM[1] > ci->loc[1] + ci->width[1]) error("Invalid multipole position ci"); - if(multi_i->CoM[2] < ci->loc[2] || multi_i->CoM[2] > ci->loc[2] + ci->width[2]) + if (multi_i->CoM[2] < ci->loc[2] || + multi_i->CoM[2] > ci->loc[2] + ci->width[2]) error("Invalid multipole position ci"); - if(multi_j->CoM[0] < cj->loc[0] || multi_j->CoM[0] > cj->loc[0] + cj->width[0]) + if (multi_j->CoM[0] < cj->loc[0] || + multi_j->CoM[0] > cj->loc[0] + cj->width[0]) error("Invalid multipole position cj"); - if(multi_j->CoM[1] < cj->loc[1] || multi_j->CoM[1] > cj->loc[1] + cj->width[1]) + if (multi_j->CoM[1] < cj->loc[1] || + multi_j->CoM[1] > cj->loc[1] + cj->width[1]) error("Invalid multipole position cj"); - if(multi_j->CoM[2] < cj->loc[2] || multi_j->CoM[2] > cj->loc[2] + cj->width[2]) + if (multi_j->CoM[2] < cj->loc[2] || + multi_j->CoM[2] > cj->loc[2] + cj->width[2]) error("Invalid multipole position cj"); #endif diff --git a/src/cell.h b/src/cell.h index fc18ed510..6a7662b46 100644 --- a/src/cell.h +++ b/src/cell.h @@ -122,8 +122,6 @@ struct pcell { /*! Relative indices of the cell's progeny. */ int progeny[8]; - struct gravity_tensors multipole; - #ifdef SWIFT_DEBUG_CHECKS /* Cell ID (for debugging) */ int cellID; @@ -159,8 +157,6 @@ struct pcell_step { */ struct cell { - integertime_t ti_last_update; - /*! The cell location on the grid. */ double loc[3]; @@ -534,7 +530,7 @@ int cell_has_tasks(struct cell *c); int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, const struct engine *e, const struct space *s); int cell_can_use_pair_mm_rebuild(const struct cell *ci, const struct cell *cj, - const struct engine *e, const struct space *s); + const struct engine *e, const struct space *s); /* Inlined functions (for speed). */ diff --git a/src/engine.c b/src/engine.c index 20918d43d..d34da676e 100644 --- a/src/engine.c +++ b/src/engine.c @@ -92,11 +92,6 @@ /* Particle cache size. */ #define CACHE_SIZE 512 -FILE* file_dump; -FILE* file_tasks; -FILE* file_send; -FILE* file_recv; - const char *engine_policy_names[] = {"none", "rand", "steal", @@ -119,8 +114,6 @@ const char *engine_policy_names[] = {"none", /** The rank of the engine as a global variable (for messages). */ int engine_rank; -extern integertime_t ti_current_global; - /** * @brief Data collected from the cells at the end of a time-step */ @@ -1392,9 +1385,6 @@ void engine_addtasks_send_hydro(struct engine *e, struct cell *ci, #endif } -int count_send[4]; -int count_recv[4]; - /** * @brief Add send tasks for the gravity pairs to a hierarchy of cells. * @@ -1426,8 +1416,6 @@ void engine_addtasks_send_gravity(struct engine *e, struct cell *ci, t_grav = scheduler_addtask(s, task_type_send, task_subtype_gpart, 6 * ci->tag + 4, 0, ci, cj); - count_send[nodeID]++; - /* The sends should unlock the down pass. */ scheduler_addunlock(s, t_grav, ci->super_gravity->grav_down); @@ -1590,10 +1578,6 @@ void engine_addtasks_recv_gravity(struct engine *e, struct cell *c, /* Create the tasks. */ t_grav = scheduler_addtask(s, task_type_recv, task_subtype_gpart, 6 * c->tag + 4, 0, c, NULL); - - if(c->nodeID < 0 || c->nodeID > 3) - error("Invalid nodeID"); - count_recv[c->nodeID]++; } c->recv_grav = t_grav; @@ -2514,12 +2498,6 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, /* Are the cells too close for a MM interaction ? */ if (!cell_can_use_pair_mm_rebuild(ci, cj, e, s)) { - /* if(ci->cellID == -111895 || cj->cellID == -111895) { */ - - /* message("Constructing grav task! t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", */ - /* ci->cellID, cj->cellID, ci->nodeID, cj->nodeID); */ - /* } */ - /* Ok, we need to add a direct pair calculation */ scheduler_addtask(sched, task_type_pair, task_subtype_grav, 0, 0, ci, cj); @@ -2706,14 +2684,6 @@ void engine_count_and_link_tasks_mapper(void *map_data, int num_elements, engine_addlink(e, &ci->density, t); engine_addlink(e, &cj->density, t); } else if (t_subtype == task_subtype_grav) { - - /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ - /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - - /* message("Task linked to ci and cj"); */ - - /* } */ - engine_addlink(e, &ci->grav, t); engine_addlink(e, &cj->grav, t); } @@ -2776,8 +2746,7 @@ void engine_link_gravity_tasks(struct engine *e) { /* Get a pointer to the task. */ struct task *t = &sched->tasks[k]; - if(t->type == task_type_none) - continue; + if (t->type == task_type_none) continue; /* Get the cells we act on */ struct cell *ci = t->ci; @@ -3282,25 +3251,6 @@ void engine_maketasks(struct engine *e) { tic2 = getticks(); - /* for(int i = 0; isched.nr_tasks; ++i) { */ - - /* struct task *t = &e->sched.tasks[i]; */ - - /* if(t->type == task_type_pair && t->subtype == task_subtype_grav) { */ - - /* struct cell *ci = t->ci; */ - /* struct cell *cj = t->cj; */ - - /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ - /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - - /* message("Found the task!"); */ - /* } */ - - /* } */ - - /* } */ - /* Split the tasks. */ scheduler_splittasks(sched); @@ -3366,11 +3316,6 @@ void engine_maketasks(struct engine *e) { message("Linking gravity tasks took %.3f %s.", clocks_from_ticks(getticks() - tic2), clocks_getunit()); - for(int k=0; k<4 ; ++k){ - count_send[k] = 0; - count_recv[k] = 0; - } - #ifdef WITH_MPI /* Add the communication tasks if MPI is being used. */ @@ -3423,12 +3368,6 @@ void engine_maketasks(struct engine *e) { } #endif - for(int k=0; k<4 ; ++k){ - fprintf(file_tasks, "Send to %d: %d\n", k, count_send[k]); - fprintf(file_tasks, "recv from %d: %d\n", k, count_recv[k]); - } - fflush(file_tasks); - tic2 = getticks(); /* Set the unlocks per task. */ @@ -3860,62 +3799,14 @@ void engine_print_task_counts(struct engine *e) { const int nr_tasks = sched->nr_tasks; const struct task *const tasks = sched->tasks; - int count_send_gpart[4] = {0}; - int count_recv_gpart[4] = {0}; - int count_send_tiend[4] = {0}; - int count_recv_tiend[4] = {0}; - /* Count and print the number of each task type. */ int counts[task_type_count + 1]; for (int k = 0; k <= task_type_count; k++) counts[k] = 0; for (int k = 0; k < nr_tasks; k++) { if (tasks[k].skip) counts[task_type_count] += 1; - else { + else counts[(int)tasks[k].type] += 1; - - if (tasks[k].type == task_type_send && - tasks[k].subtype == task_subtype_gpart) - ++count_send_gpart[tasks[k].cj->nodeID]; - if (tasks[k].type == task_type_send && - tasks[k].subtype == task_subtype_tend) - ++count_send_tiend[tasks[k].cj->nodeID]; - if (tasks[k].type == task_type_recv && - tasks[k].subtype == task_subtype_gpart) - ++count_recv_gpart[tasks[k].ci->nodeID]; - if (tasks[k].type == task_type_recv && - tasks[k].subtype == task_subtype_tend) - ++count_recv_tiend[tasks[k].ci->nodeID]; - - - if (tasks[k].type == task_type_send && - tasks[k].subtype == task_subtype_gpart) { - - int from = engine_rank; - int to = tasks[k].cj->nodeID; - - if((from == 3 && to == 0)) { - /* fprintf(file_send, "Sending cell ci=%d cj=%d to rank 3 (depth= %d %d)\n", */ - /* tasks[k].ci->cellID, tasks[k].cj->cellID, tasks[k].ci->depth, tasks[k].cj->depth); */ - fflush(file_send); - } - } - - if (tasks[k].type == task_type_recv && - tasks[k].subtype == task_subtype_gpart) { - - int to = engine_rank; - int from = tasks[k].ci->nodeID; - - if(to == 0 && from == 3) { - /* fprintf(file_recv, "Receiving cell ci=%d from rank 3 (depth= %d)\n", */ - /* tasks[k].ci->cellID, tasks[k].ci->depth); */ - fflush(file_recv); - - } - } - - } } message("Total = %d (per cell = %d)", nr_tasks, (int)ceil((double)nr_tasks / e->s->tot_cells)); @@ -3930,11 +3821,6 @@ void engine_print_task_counts(struct engine *e) { printf(" %s=%i", taskID_names[k], counts[k]); printf(" skipped=%i ]\n", counts[task_type_count]); fflush(stdout); - message("send_gpart = %3d %3d %3d %3d", count_send_gpart[0], count_send_gpart[1], count_send_gpart[2], count_send_gpart[3]); - message("recv_gpart = %3d %3d %3d %3d", count_recv_gpart[0], count_recv_gpart[1], count_recv_gpart[2], count_recv_gpart[3]); - message("send_tiend = %3d %3d %3d %3d", count_send_tiend[0], count_send_tiend[1], count_send_tiend[2], count_send_tiend[3]); - message("recv_tiend = %3d %3d %3d %3d", count_recv_tiend[0], count_recv_tiend[1], count_recv_tiend[2], count_recv_tiend[3]); - message("nr_parts = %zu.", e->s->nr_parts); message("nr_gparts = %zu.", e->s->nr_gparts); message("nr_sparts = %zu.", e->s->nr_sparts); @@ -4092,12 +3978,12 @@ void engine_rebuild(struct engine *e, int clean_smoothing_length_values) { /* If in parallel, exchange the cell structure, top-level and neighbouring * multipoles. */ #ifdef WITH_MPI - if (e->policy & engine_policy_self_gravity) engine_exchange_top_multipoles(e); - engine_exchange_cells(e); - //if (e->policy & engine_policy_self_gravity) - // engine_exchange_proxy_multipoles(e); + if (e->policy & engine_policy_self_gravity) engine_exchange_top_multipoles(e); + + if (e->policy & engine_policy_self_gravity) + engine_exchange_proxy_multipoles(e); #endif /* Re-build the tasks. */ @@ -4851,13 +4737,6 @@ void engine_step(struct engine *e) { e->step += 1; e->step_props = engine_step_prop_none; - ti_current_global = e->ti_current; - - fprintf(file_dump, "#################### Step %d #####################\n\n\n", e->step); - fprintf(file_tasks, "#################### Step %d #####################\n\n\n", e->step); - fprintf(file_send, "#################### Step %d #####################\n\n\n", e->step); - fprintf(file_recv, "#################### Step %d #####################\n\n\n", e->step); - /* When restarting, move everyone to the current time. */ if (e->restarting) engine_drift_all(e); @@ -4909,40 +4788,7 @@ void engine_step(struct engine *e) { engine_prepare(e); /* Print the number of active tasks ? */ - //if (e->step == 43) engine_print_task_counts(e); - -/* if (e->step == 43) { */ - -/* for(int i = 0; i < e->s->nr_cells; ++i) { */ - -/* const struct cell *c = &e->s->cells_top[i]; */ - -/* if(c->cellID == -111895) { */ - -/* message("c->loc= [%f %f %f]", c->loc[0], c->loc[1], c->loc[2]); */ -/* message("c->depth= %d", c->depth); */ -/* message("c->nodeID= %d", c->nodeID); */ -/* message("c->gcount= %d c->count= %d c->scount= %d", c->gcount, c->count, c->scount); */ -/* message("c->ti_hydro_end_min= %lld c->ti_gravity_end_min= %lld", c->ti_hydro_end_min, c->ti_gravity_end_min); */ -/* #ifdef WITH_MPI */ -/* message("c->recv_grav= %p", c->recv_grav); */ -/* if(c->recv_grav) */ -/* message("c->recv_grav->skip= %d c->recv_grav->wait= %d", c->recv_grav->skip, c->recv_grav->wait); */ - -/* if(c->send_grav) */ -/* for(struct link *l = c->send_grav; l!=NULL; l = l->next) */ -/* message("Send task: t->cj->nodeID=%d t->skip=%d", l->t->cj->nodeID, l->t->skip); */ - -/* if(c->grav) */ -/* for(struct link *l = c->grav; l!=NULL; l = l->next) */ -/* if(l->t->type == task_type_pair) */ -/* message("grav task t->wait=%d t->skip=%d t->ci->cellID= %d t->cj->cellID= %d t->ci->nodeID= %d t->cj->nodeID= %d", */ -/* l->t->wait, l->t->skip, l->t->ci->cellID, l->t->cj->cellID, l->t->ci->nodeID, l->t->cj->nodeID); */ -/* #endif */ - -/* } */ -/* } */ -/* } */ + if (e->verbose) engine_print_task_counts(e); /* Dump local cells and active particle counts. */ /* dumpCells("cells", 0, 0, 0, 0, e->s, e->nodeID, e->step); */ @@ -5542,16 +5388,8 @@ void engine_makeproxies(struct engine *e) { if (with_gravity) { /* Are we too close for M2L? */ - //if (!cell_can_use_pair_mm_rebuild(&cells[cid], &cells[cjd], e, s)) - /* if (((abs(ind[0] - ii) <= 5 || */ - /* abs(ind[0] - ii - cdim[0]) <= 5 || */ - /* abs(ind[0] - ii + cdim[0]) <= 5) && */ - /* (abs(ind[1] - jj) <= 5 || */ - /* abs(ind[1] - jj - cdim[1]) <= 5 || */ - /* abs(ind[1] - jj + cdim[1]) <= 5) && */ - /* (abs(ind[2] - kk) <= 5 || */ - /* abs(ind[2] - kk - cdim[2]) <= 5 || */ - /* abs(ind[2] - kk + cdim[2]) <= 5))) */ + if (!cell_can_use_pair_mm_rebuild(&cells[cid], &cells[cjd], e, + s)) proxy_type |= (int)proxy_cell_type_gravity; } @@ -6031,19 +5869,6 @@ void engine_config(int restart, struct engine *e, struct swift_params *params, e->timeFirstSTFOutput = 0; engine_rank = nodeID; - char buffer[32]; - sprintf(buffer, "dump_%d.txt", engine_rank); - file_dump = fopen(buffer, "w"); - - sprintf(buffer, "tasks_%d.txt", engine_rank); - file_tasks = fopen(buffer, "w"); - - sprintf(buffer, "send_%d.txt", engine_rank); - file_send = fopen(buffer, "w"); - - sprintf(buffer, "recv_%d.txt", engine_rank); - file_recv = fopen(buffer, "w"); - /* Initialise VELOCIraptor. */ if (e->policy & engine_policy_structure_finding) { parser_get_param_string(params, "StructureFinding:basename", diff --git a/src/scheduler.c b/src/scheduler.c index c6b9b5547..a641df326 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -888,28 +888,12 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { break; } - /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ - /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - - /* message("Found the task! ci->cellID=%d cj->cellID=%d ci->nodeID=%d cj->nodeID=%d ci->gcount=%d cj->gcount=%d ci->split=%d cj->split=%d ci->depth=%d cj->depth=%d", */ - /* ci->cellID, cj->cellID, ci->nodeID, cj->nodeID, ci->gcount, cj->gcount, */ - /* ci->split, cj->split, ci->depth, cj->depth); */ - /* } */ - - /* Should we replace it with an M-M task? */ if (cell_can_use_pair_mm_rebuild(ci, cj, e, sp)) { t->type = task_type_grav_mm; t->subtype = task_subtype_none; - /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ - /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - - /* message("Replaced by M-M task!"); */ - - /* } */ - /* Since this task will not be split, we can already link it */ atomic_inc(&ci->nr_mm_tasks); atomic_inc(&cj->nr_mm_tasks); @@ -922,20 +906,12 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { if (cell_can_split_pair_gravity_task(ci) && cell_can_split_pair_gravity_task(cj)) { - const long long gcount_i = ci->gcount; - const long long gcount_j = cj->gcount; + const long long gcount_i = ci->gcount; + const long long gcount_j = cj->gcount; /* Replace by a single sub-task? */ if (scheduler_dosub && /* Use division to avoid integer overflow. */ - gcount_i * gcount_j < ((long long) space_subsize_pair_grav)) { - - /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ - /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - - /* message("Do nothing!"); */ - - /* } */ - + gcount_i * gcount_j < ((long long)space_subsize_pair_grav)) { /* Otherwise, split it. */ } else { @@ -943,13 +919,6 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { /* Take a step back (we're going to recycle the current task)... */ redo = 1; - /* if((ci->cellID == -91806 && cj->cellID == -111895) || */ - /* (cj->cellID == -91806 && ci->cellID == -111895)) { */ - - /* message("Split into smaller tasks!"); */ - - /* } */ - /* Find the first non-empty childrens of the cells */ int first_ci_child = 0, first_cj_child = 0; while (ci->progeny[first_ci_child] == NULL) first_ci_child++; diff --git a/src/space.c b/src/space.c index 74fa307ea..f9f8411b9 100644 --- a/src/space.c +++ b/src/space.c @@ -433,8 +433,8 @@ void space_regrid(struct space *s, int verbose) { c->ti_old_multipole = ti_current; if (s->gravity) c->multipole = &s->multipoles_top[cid]; #ifdef SWIFT_DEBUG_CHECKS - c->cellID = -last_cell_id; - last_cell_id++; + c->cellID = -last_cell_id; + last_cell_id++; #endif } @@ -928,7 +928,7 @@ void space_rebuild(struct space *s, int verbose) { c->ti_old_gpart = ti_current; c->ti_old_multipole = ti_current; -#ifdef SWIFT_DEBUG_CHECKS +#ifdef SWIFT_DEBUG_CHECKS c->cellID = -last_cell_id; last_cell_id++; #endif -- GitLab From bd6ae8b6e5c29d7f14f833cd7ed5715b151f1dc6 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 26 Aug 2018 11:37:08 +0100 Subject: [PATCH 27/32] Prevent the use of the multipole reconstruction mode over MPI. --- examples/main.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/main.c b/examples/main.c index c0faa6ef8..3712f2bac 100644 --- a/examples/main.c +++ b/examples/main.c @@ -486,6 +486,17 @@ int main(int argc, char *argv[]) { MPI_Bcast(params, sizeof(struct swift_params), MPI_BYTE, 0, MPI_COMM_WORLD); #endif + /* Temporary early aborts for modes not supported over MPI. */ +#ifdef WITH_MPI + if(with_mpole_reconstruction && nr_nodes > 1) + error("Cannot reconstruct m-poles every step over MPI (yet)."); +#endif + +#if defined(WITH_MPI) && defined(HAVE_VELOCIRAPTOR) + if (with_structure_finding && nr_nodes > 1) + error("VEOCIraptor not yet enabled over MPI."); +#endif + /* Check that we can write the snapshots by testing if the output * directory exists and is searchable and writable. */ char basename[PARSER_MAX_LINE_SIZE]; @@ -729,10 +740,6 @@ int main(int argc, char *argv[]) { fflush(stdout); } -#if defined(WITH_MPI) && defined(HAVE_VELOCIRAPTOR) - if (with_structure_finding) error("VEOCIraptor not yet enabled over MPI."); -#endif - #ifdef SWIFT_DEBUG_CHECKS /* Check once and for all that we don't have unwanted links */ if (!with_stars && !dry_run) { -- GitLab From 5dd4aef0f34adfd7ac17b0656f708ac8587552c7 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 26 Aug 2018 11:49:20 +0100 Subject: [PATCH 28/32] Exchange the multipoles at the same time as the cells when running with gravity. --- src/cell.c | 17 +++-- src/cell.h | 13 ++-- src/engine.c | 24 ++++--- src/proxy.c | 196 ++++++++++++++++++++++++++------------------------- src/proxy.h | 4 +- 5 files changed, 136 insertions(+), 118 deletions(-) diff --git a/src/cell.c b/src/cell.c index 78b9fdd2a..2919839d5 100644 --- a/src/cell.c +++ b/src/cell.c @@ -167,14 +167,19 @@ int cell_link_sparts(struct cell *c, struct spart *sparts) { * @param c The #cell. * @param pc Pointer to an array of packed cells in which the * cells will be packed. + * @param with_gravity Are we running with gravity and hence need + * to exchange multipoles? * * @return The number of packed cells. */ -int cell_pack(struct cell *restrict c, struct pcell *restrict pc) { +int cell_pack(struct cell *restrict c, struct pcell *restrict pc, + const int with_gravity) { #ifdef WITH_MPI /* Start by packing the data of the current cell. */ + if(with_gravity) + pc->multipole = *(c->multipole); pc->h_max = c->h_max; pc->ti_hydro_end_min = c->ti_hydro_end_min; pc->ti_hydro_end_max = c->ti_hydro_end_max; @@ -196,7 +201,7 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc) { for (int k = 0; k < 8; k++) if (c->progeny[k] != NULL) { pc->progeny[k] = count; - count += cell_pack(c->progeny[k], &pc[count]); + count += cell_pack(c->progeny[k], &pc[count], with_gravity); } else { pc->progeny[k] = -1; } @@ -251,15 +256,19 @@ int cell_pack_tags(const struct cell *c, int *tags) { * @param pc An array of packed #pcell. * @param c The #cell in which to unpack the #pcell. * @param s The #space in which the cells are created. + * @param with_gravity Are we running with gravity and hence need + * to exchange multipoles? * * @return The number of cells created. */ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, - struct space *restrict s) { + struct space *restrict s, const int with_gravity) { #ifdef WITH_MPI /* Unpack the current pcell. */ + if(with_gravity) + *(c->multipole) = pc->multipole; c->h_max = pc->h_max; c->ti_hydro_end_min = pc->ti_hydro_end_min; c->ti_hydro_end_max = pc->ti_hydro_end_max; @@ -304,7 +313,7 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, temp->parent = c; c->progeny[k] = temp; c->split = 1; - count += cell_unpack(&pc[pc->progeny[k]], temp, s); + count += cell_unpack(&pc[pc->progeny[k]], temp, s, with_gravity); } /* Return the total number of unpacked cells. */ diff --git a/src/cell.h b/src/cell.h index 356e03773..c209f8d99 100644 --- a/src/cell.h +++ b/src/cell.h @@ -77,6 +77,12 @@ struct link { */ struct pcell { + /*! This cell's gravity-related tensors */ + struct gravity_tensors multipole; + + /*! Relative indices of the cell's progeny. */ + int progeny[8]; + /*! Maximal smoothing length. */ double h_max; @@ -116,9 +122,6 @@ struct pcell { /*! Number of #spart in this cell. */ int scount; - /*! Relative indices of the cell's progeny. */ - int progeny[8]; - #ifdef SWIFT_DEBUG_CHECKS /* Cell ID (for debugging) */ int cellID; @@ -485,8 +488,8 @@ int cell_mlocktree(struct cell *c); void cell_munlocktree(struct cell *c); int cell_slocktree(struct cell *c); void cell_sunlocktree(struct cell *c); -int cell_pack(struct cell *c, struct pcell *pc); -int cell_unpack(struct pcell *pc, struct cell *c, struct space *s); +int cell_pack(struct cell *c, struct pcell *pc, const int with_gravity); +int cell_unpack(struct pcell *pc, struct cell *c, struct space *s, const int with_gravity); int cell_pack_tags(const struct cell *c, int *tags); int cell_unpack_tags(const int *tags, struct cell *c); int cell_pack_end_step(struct cell *c, struct pcell_step *pcell); diff --git a/src/engine.c b/src/engine.c index ab8c4dd69..605983978 100644 --- a/src/engine.c +++ b/src/engine.c @@ -1670,10 +1670,11 @@ void engine_exchange_cells(struct engine *e) { struct space *s = e->s; const int nr_proxies = e->nr_proxies; + const int with_gravity = e->policy & engine_policy_self_gravity; const ticks tic = getticks(); /* Exchange the cell structure with neighbouring ranks. */ - proxy_cells_exchange(e->proxies, e->nr_proxies, e->s); + proxy_cells_exchange(e->proxies, e->nr_proxies, e->s, with_gravity); /* Count the number of particles we need to import and re-allocate the buffer if needed. */ @@ -3948,18 +3949,14 @@ void engine_rebuild(struct engine *e, int clean_smoothing_length_values) { /* If in parallel, exchange the cell structure, top-level and neighbouring * multipoles. */ #ifdef WITH_MPI - engine_exchange_cells(e); - if (e->policy & engine_policy_self_gravity) engine_exchange_top_multipoles(e); + + engine_exchange_cells(e); #endif /* Re-build the tasks. */ engine_maketasks(e); -#ifdef WITH_MPI - if (e->policy & engine_policy_self_gravity) engine_exchange_proxy_multipoles(e); -#endif - /* Make the list of top-level cells that have tasks */ space_list_cells_with_tasks(e->s); @@ -5400,8 +5397,17 @@ void engine_makeproxies(struct engine *e) { if (with_gravity) { /* Are we too close for M2L? */ - if (!cell_can_use_pair_mm_rebuild(&cells[cid], &cells[cjd], e, - s)) + /* if (!cell_can_use_pair_mm_rebuild(&cells[cid], &cells[cjd], e, */ + /* s)) */ + if (((abs(ind[0] - ii) <= 5 || + abs(ind[0] - ii - cdim[0]) <= 5 || + abs(ind[0] - ii + cdim[0]) <= 5) && + (abs(ind[1] - jj) <= 5 || + abs(ind[1] - jj - cdim[1]) <= 5 || + abs(ind[1] - jj + cdim[1]) <= 5) && + (abs(ind[2] - kk) <= 5 || + abs(ind[2] - kk - cdim[2]) <= 5 || + abs(ind[2] - kk + cdim[2]) <= 5))) proxy_type |= (int)proxy_cell_type_gravity; } diff --git a/src/proxy.c b/src/proxy.c index 615629137..a5d30848a 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -159,103 +159,6 @@ void proxy_tags_exchange(struct proxy *proxies, int num_proxies, #endif } -/** - * @brief Exchange the cell structures with all proxies. - * - * @param proxies The list of #proxy that will send/recv cells. - * @param num_proxies The number of proxies. - * @param s The space into which the particles will be unpacked. - */ -void proxy_cells_exchange(struct proxy *proxies, int num_proxies, - struct space *s) { - -#ifdef WITH_MPI - - MPI_Request *reqs; - if ((reqs = (MPI_Request *)malloc(sizeof(MPI_Request) * 2 * num_proxies)) == - NULL) - error("Failed to allocate request buffers."); - MPI_Request *reqs_in = reqs; - MPI_Request *reqs_out = &reqs[num_proxies]; - - /* Run through the cells and get the size of the ones that will be sent off. - */ - int count_out = 0; - int offset[s->nr_cells]; - for (int k = 0; k < s->nr_cells; k++) { - offset[k] = count_out; - if (s->cells_top[k].sendto) - count_out += - (s->cells_top[k].pcell_size = cell_getsize(&s->cells_top[k])); - } - - /* Allocate the pcells. */ - struct pcell *pcells = NULL; - if (posix_memalign((void **)&pcells, SWIFT_CACHE_ALIGNMENT, - sizeof(struct pcell) * count_out) != 0) - error("Failed to allocate pcell buffer."); - - /* Pack the cells. */ - for (int k = 0; k < s->nr_cells; k++) - if (s->cells_top[k].sendto) { - cell_pack(&s->cells_top[k], &pcells[offset[k]]); - s->cells_top[k].pcell = &pcells[offset[k]]; - } - - /* Launch the first part of the exchange. */ - for (int k = 0; k < num_proxies; k++) { - proxy_cells_exchange_first(&proxies[k]); - reqs_in[k] = proxies[k].req_cells_count_in; - reqs_out[k] = proxies[k].req_cells_count_out; - } - - /* Wait for each count to come in and start the recv. */ - for (int k = 0; k < num_proxies; k++) { - int pid = MPI_UNDEFINED; - MPI_Status status; - if (MPI_Waitany(num_proxies, reqs_in, &pid, &status) != MPI_SUCCESS || - pid == MPI_UNDEFINED) - error("MPI_Waitany failed."); - // message( "request from proxy %i has arrived." , pid ); - proxy_cells_exchange_second(&proxies[pid]); - } - - /* 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."); - - /* Set the requests for the cells. */ - for (int k = 0; k < num_proxies; k++) { - reqs_in[k] = proxies[k].req_cells_in; - reqs_out[k] = proxies[k].req_cells_out; - } - - /* Wait for each pcell array to come in from the proxies. */ - for (int k = 0; k < num_proxies; k++) { - int pid = MPI_UNDEFINED; - MPI_Status status; - if (MPI_Waitany(num_proxies, reqs_in, &pid, &status) != MPI_SUCCESS || - pid == MPI_UNDEFINED) - error("MPI_Waitany failed."); - // message( "cell data from proxy %i has arrived." , pid ); - for (int count = 0, j = 0; j < proxies[pid].nr_cells_in; j++) - count += cell_unpack(&proxies[pid].pcells_in[count], - proxies[pid].cells_in[j], s); - } - - /* 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."); - - /* Clean up. */ - free(reqs); - free(pcells); - -#else - error("SWIFT was not compiled with MPI support."); -#endif -} - /** * @brief Exchange cells with a remote node, first part. * @@ -350,6 +253,105 @@ void proxy_cells_exchange_second(struct proxy *p) { #endif } +/** + * @brief Exchange the cell structures with all proxies. + * + * @param proxies The list of #proxy that will send/recv cells. + * @param num_proxies The number of proxies. + * @param s The space into which the particles will be unpacked. + * @param with_gravity Are we running with gravity and hence need + * to exchange multipoles? + */ +void proxy_cells_exchange(struct proxy *proxies, int num_proxies, + struct space *s, const int with_gravity) { + +#ifdef WITH_MPI + + MPI_Request *reqs; + if ((reqs = (MPI_Request *)malloc(sizeof(MPI_Request) * 2 * num_proxies)) == + NULL) + error("Failed to allocate request buffers."); + MPI_Request *reqs_in = reqs; + MPI_Request *reqs_out = &reqs[num_proxies]; + + /* Run through the cells and get the size of the ones that will be sent off. + */ + int count_out = 0; + int offset[s->nr_cells]; + for (int k = 0; k < s->nr_cells; k++) { + offset[k] = count_out; + if (s->cells_top[k].sendto) + count_out += + (s->cells_top[k].pcell_size = cell_getsize(&s->cells_top[k])); + } + + /* Allocate the pcells. */ + struct pcell *pcells = NULL; + if (posix_memalign((void **)&pcells, SWIFT_CACHE_ALIGNMENT, + sizeof(struct pcell) * count_out) != 0) + error("Failed to allocate pcell buffer."); + + /* Pack the cells. */ + for (int k = 0; k < s->nr_cells; k++) + if (s->cells_top[k].sendto) { + cell_pack(&s->cells_top[k], &pcells[offset[k]], with_gravity); + s->cells_top[k].pcell = &pcells[offset[k]]; + } + + /* Launch the first part of the exchange. */ + for (int k = 0; k < num_proxies; k++) { + proxy_cells_exchange_first(&proxies[k]); + reqs_in[k] = proxies[k].req_cells_count_in; + reqs_out[k] = proxies[k].req_cells_count_out; + } + + /* Wait for each count to come in and start the recv. */ + for (int k = 0; k < num_proxies; k++) { + int pid = MPI_UNDEFINED; + MPI_Status status; + if (MPI_Waitany(num_proxies, reqs_in, &pid, &status) != MPI_SUCCESS || + pid == MPI_UNDEFINED) + error("MPI_Waitany failed."); + // message( "request from proxy %i has arrived." , pid ); + proxy_cells_exchange_second(&proxies[pid]); + } + + /* 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."); + + /* Set the requests for the cells. */ + for (int k = 0; k < num_proxies; k++) { + reqs_in[k] = proxies[k].req_cells_in; + reqs_out[k] = proxies[k].req_cells_out; + } + + /* Wait for each pcell array to come in from the proxies. */ + for (int k = 0; k < num_proxies; k++) { + int pid = MPI_UNDEFINED; + MPI_Status status; + if (MPI_Waitany(num_proxies, reqs_in, &pid, &status) != MPI_SUCCESS || + pid == MPI_UNDEFINED) + error("MPI_Waitany failed."); + // message( "cell data from proxy %i has arrived." , pid ); + for (int count = 0, j = 0; j < proxies[pid].nr_cells_in; j++) + count += cell_unpack(&proxies[pid].pcells_in[count], + proxies[pid].cells_in[j], s, with_gravity); + } + + /* 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."); + + /* Clean up. */ + free(reqs); + free(pcells); + +#else + error("SWIFT was not compiled with MPI support."); +#endif +} + /** * @brief Add a cell to the given proxy's input list. * diff --git a/src/proxy.h b/src/proxy.h index 63f51846d..fbc3f1a16 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -102,9 +102,7 @@ void proxy_parts_exchange_second(struct proxy *p); void proxy_addcell_in(struct proxy *p, struct cell *c, int type); void proxy_addcell_out(struct proxy *p, struct cell *c, int type); void proxy_cells_exchange(struct proxy *proxies, int num_proxies, - struct space *s); -void proxy_cells_exchange_first(struct proxy *p); -void proxy_cells_exchange_second(struct proxy *p); + struct space *s, int with_gravity); void proxy_tags_exchange(struct proxy *proxies, int num_proxies, struct space *s); -- GitLab From d986be96bf0a2c9bea1cc3e1cd7be23114ee2cc0 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 26 Aug 2018 13:25:54 +0100 Subject: [PATCH 29/32] Numerically motivated maximal distance for the gravity proxies and better calculation of the upper-bound. --- examples/EAGLE_12/eagle_12.yml | 3 -- src/engine.c | 84 ++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 23 deletions(-) diff --git a/examples/EAGLE_12/eagle_12.yml b/examples/EAGLE_12/eagle_12.yml index 8ebe29fb0..77d3f358b 100644 --- a/examples/EAGLE_12/eagle_12.yml +++ b/examples/EAGLE_12/eagle_12.yml @@ -22,9 +22,6 @@ TimeIntegration: dt_min: 1e-10 # The minimal time-step size of the simulation (in internal units). dt_max: 1e-3 # The maximal time-step size of the simulation (in internal units). -Scheduler: - max_top_level_cells: 8 - # Parameters governing the snapshots Snapshots: basename: eagle # Common part of the name of output files diff --git a/src/engine.c b/src/engine.c index 605983978..13e5c4748 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5283,16 +5283,28 @@ void engine_makeproxies(struct engine *e) { #ifdef WITH_MPI const int nodeID = e->nodeID; const struct space *s = e->s; - const int *cdim = s->cdim; + + /* Handle on the cells and proxies */ + struct cell *cells = s->cells_top; + struct proxy *proxies = e->proxies; + + /* Some info about the domain */ + const int cdim[3] = {s->cdim[0], s->cdim[1], s->cdim[2]}; + const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]}; + const int periodic = s->periodic; + const double cell_width[3] = {cells[0].width[0], cells[0].width[1], cells[0].width[2]}; /* Get some info about the physics */ const int with_hydro = (e->policy & engine_policy_hydro); const int with_gravity = (e->policy & engine_policy_self_gravity); - const double theta_crit = e->gravity_properties->theta_crit; + const double theta_crit_inv = e->gravity_properties->theta_crit_inv; + const double theta_crit2 = e->gravity_properties->theta_crit2; - /* Handle on the cells and proxies */ - struct cell *cells = s->cells_top; - struct proxy *proxies = e->proxies; + /* Maximal distance between CoMs and any particle in the cell */ + const double r_max2 = cell_width[0] * cell_width[0] + + cell_width[1] * cell_width[1] + + cell_width[2] * cell_width[2]; + const double r_max = sqrt(r_max2); /* Let's time this */ const ticks tic = getticks(); @@ -5306,10 +5318,14 @@ void engine_makeproxies(struct engine *e) { /* Compute how many cells away we need to walk */ int delta = 1; /*hydro case */ + + /* Gravity needs to take the opening angle into account */ if (with_gravity) { - const double distance = 2.5 * cells[0].width[0] / theta_crit; - delta = (int)(distance / cells[0].width[0]) + 1; + const double distance = 2. * r_max * theta_crit_inv; + delta = (int)(distance / cells[0].dmin) + 1; } + + /* Turn this into upper and lower bounds for loops */ int delta_m = delta; int delta_p = delta; @@ -5340,6 +5356,11 @@ void engine_makeproxies(struct engine *e) { /* Get the cell ID. */ const int cid = cell_getid(cdim, ind[0], ind[1], ind[2]); + /* and it's location */ + const double loc_i[3] = {cells[cid].loc[0], + cells[cid].loc[1], + cells[cid].loc[2]}; + /* Loop over all its neighbours (periodic). */ for (int i = -delta_m; i <= delta_p; i++) { int ii = ind[0] + i; @@ -5379,6 +5400,9 @@ void engine_makeproxies(struct engine *e) { /* In the hydro case, only care about direct neighbours */ if (with_hydro) { + //MATTHIEU: to do: Write a better expression for the + // non-periodic case. + /* This is super-ugly but checks for direct neighbours */ /* with periodic BC */ if (((abs(ind[0] - ii) <= 1 || @@ -5396,19 +5420,39 @@ void engine_makeproxies(struct engine *e) { /* In the gravity case, check distances using the MAC. */ if (with_gravity) { - /* Are we too close for M2L? */ - /* if (!cell_can_use_pair_mm_rebuild(&cells[cid], &cells[cjd], e, */ - /* s)) */ - if (((abs(ind[0] - ii) <= 5 || - abs(ind[0] - ii - cdim[0]) <= 5 || - abs(ind[0] - ii + cdim[0]) <= 5) && - (abs(ind[1] - jj) <= 5 || - abs(ind[1] - jj - cdim[1]) <= 5 || - abs(ind[1] - jj + cdim[1]) <= 5) && - (abs(ind[2] - kk) <= 5 || - abs(ind[2] - kk - cdim[2]) <= 5 || - abs(ind[2] - kk + cdim[2]) <= 5))) - proxy_type |= (int)proxy_cell_type_gravity; + /* We don't have multipoles yet (or there CoMs) so we will have to + cook up something based on cell locations only. We hence need + an upper limit on the distance that the CoMs in those cells + could have. We then can decide whether we are too close + for an M2L interaction and hence require a proxy as this pair + of cells cannot rely on just an M2L calculation. */ + + const double loc_j[3] = {cells[cjd].loc[0], + cells[cjd].loc[1], + cells[cjd].loc[2]}; + + /* Start with the distance between the cell centres. */ + double dx = loc_i[0] - loc_j[0]; + double dy = loc_i[1] - loc_j[1]; + double dz = loc_i[2] - loc_j[2]; + + /* Apply BC */ + if (periodic) { + dx = nearest(dx, dim[0]); + dy = nearest(dy, dim[0]); + dz = nearest(dz, dim[0]); + } + + /* Add to it for the case where the future CoMs are in the corners */ + dx += cell_width[0]; + dy += cell_width[1]; + dz += cell_width[2]; + + /* This is a crazy upper-bound but the best we can do */ + const double r2 = dx * dx + dy * dy + dz * dz; + + if (!gravity_M2L_accept(r_max, r_max, theta_crit2, r2)) + proxy_type |= (int)proxy_cell_type_gravity; } /* Abort if not in range at all */ -- GitLab From 7fac9be5aa7aa38079aa4e297f906215488d3dab Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 26 Aug 2018 13:45:16 +0100 Subject: [PATCH 30/32] Only copy the multipole information that is required and not the full gravity information. --- src/cell.c | 36 ++++++++++++++++++++++++++++++++---- src/cell.h | 14 +++++++++++++- src/multipole.h | 6 +++--- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/cell.c b/src/cell.c index 2919839d5..7a50e8000 100644 --- a/src/cell.c +++ b/src/cell.c @@ -178,8 +178,6 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, #ifdef WITH_MPI /* Start by packing the data of the current cell. */ - if(with_gravity) - pc->multipole = *(c->multipole); pc->h_max = c->h_max; pc->ti_hydro_end_min = c->ti_hydro_end_min; pc->ti_hydro_end_max = c->ti_hydro_end_max; @@ -192,6 +190,22 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, pc->gcount = c->gcount; pc->scount = c->scount; + /* Copy the Multipole related information */ + if(with_gravity) { + const struct gravity_tensors *mp = c->multipole; + + pc->m_pole = mp->m_pole; + pc->CoM[0] = mp->CoM[0]; + pc->CoM[1] = mp->CoM[1]; + pc->CoM[2] = mp->CoM[2]; + pc->CoM_rebuild[0] = mp->CoM_rebuild[0]; + pc->CoM_rebuild[1] = mp->CoM_rebuild[1]; + pc->CoM_rebuild[2] = mp->CoM_rebuild[2]; + pc->r_max = mp->r_max; + pc->r_max_rebuild = mp->r_max_rebuild; + } + + #ifdef SWIFT_DEBUG_CHECKS pc->cellID = c->cellID; #endif @@ -267,8 +281,6 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, #ifdef WITH_MPI /* Unpack the current pcell. */ - if(with_gravity) - *(c->multipole) = pc->multipole; c->h_max = pc->h_max; c->ti_hydro_end_min = pc->ti_hydro_end_min; c->ti_hydro_end_max = pc->ti_hydro_end_max; @@ -284,6 +296,22 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, c->cellID = pc->cellID; #endif + /* Copy the Multipole related information */ + if(with_gravity) { + + struct gravity_tensors *mp = c->multipole; + + mp->m_pole = pc->m_pole; + mp->CoM[0] = pc->CoM[0]; + mp->CoM[1] = pc->CoM[1]; + mp->CoM[2] = pc->CoM[2]; + mp->CoM_rebuild[0] = pc->CoM_rebuild[0]; + mp->CoM_rebuild[1] = pc->CoM_rebuild[1]; + mp->CoM_rebuild[2] = pc->CoM_rebuild[2]; + mp->r_max = pc->r_max; + mp->r_max_rebuild = pc->r_max_rebuild; + } + /* Number of new cells created. */ int count = 1; diff --git a/src/cell.h b/src/cell.h index c209f8d99..8e53bb185 100644 --- a/src/cell.h +++ b/src/cell.h @@ -78,7 +78,19 @@ struct link { struct pcell { /*! This cell's gravity-related tensors */ - struct gravity_tensors multipole; + struct multipole m_pole; + + /*! Centre of mass. */ + double CoM[3]; + + /*! Centre of mass at rebuild time. */ + double CoM_rebuild[3]; + + /*! Upper limit of the CoM<->gpart distance. */ + double r_max; + + /*! Upper limit of the CoM<->gpart distance at last rebuild. */ + double r_max_rebuild; /*! Relative indices of the cell's progeny. */ int progeny[8]; diff --git a/src/multipole.h b/src/multipole.h index c05aa3689..2ada835e3 100644 --- a/src/multipole.h +++ b/src/multipole.h @@ -186,12 +186,12 @@ struct gravity_tensors { /*! The actual content */ struct { - /*! Multipole mass */ - struct multipole m_pole; - /*! Field tensor for the potential */ struct grav_tensor pot; + /*! Multipole mass */ + struct multipole m_pole; + /*! Centre of mass of the matter dsitribution */ double CoM[3]; -- GitLab From 0b000f61cf1930729a755856e1ff008014c5d0b2 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 26 Aug 2018 14:46:03 +0200 Subject: [PATCH 31/32] Code formatting --- examples/main.c | 8 ++--- src/cell.c | 9 +++--- src/cell.h | 5 ++-- src/engine.c | 80 ++++++++++++++++++++++++------------------------- src/proxy.c | 4 +-- 5 files changed, 53 insertions(+), 53 deletions(-) diff --git a/examples/main.c b/examples/main.c index 3712f2bac..38847543b 100644 --- a/examples/main.c +++ b/examples/main.c @@ -488,13 +488,13 @@ int main(int argc, char *argv[]) { /* Temporary early aborts for modes not supported over MPI. */ #ifdef WITH_MPI - if(with_mpole_reconstruction && nr_nodes > 1) - error("Cannot reconstruct m-poles every step over MPI (yet)."); + if (with_mpole_reconstruction && nr_nodes > 1) + error("Cannot reconstruct m-poles every step over MPI (yet)."); #endif #if defined(WITH_MPI) && defined(HAVE_VELOCIRAPTOR) - if (with_structure_finding && nr_nodes > 1) - error("VEOCIraptor not yet enabled over MPI."); + if (with_structure_finding && nr_nodes > 1) + error("VEOCIraptor not yet enabled over MPI."); #endif /* Check that we can write the snapshots by testing if the output diff --git a/src/cell.c b/src/cell.c index 7a50e8000..6ad7e4d97 100644 --- a/src/cell.c +++ b/src/cell.c @@ -173,7 +173,7 @@ int cell_link_sparts(struct cell *c, struct spart *sparts) { * @return The number of packed cells. */ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, - const int with_gravity) { + const int with_gravity) { #ifdef WITH_MPI @@ -191,7 +191,7 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, pc->scount = c->scount; /* Copy the Multipole related information */ - if(with_gravity) { + if (with_gravity) { const struct gravity_tensors *mp = c->multipole; pc->m_pole = mp->m_pole; @@ -205,7 +205,6 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, pc->r_max_rebuild = mp->r_max_rebuild; } - #ifdef SWIFT_DEBUG_CHECKS pc->cellID = c->cellID; #endif @@ -297,7 +296,7 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, #endif /* Copy the Multipole related information */ - if(with_gravity) { + if (with_gravity) { struct gravity_tensors *mp = c->multipole; @@ -311,7 +310,7 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, mp->r_max = pc->r_max; mp->r_max_rebuild = pc->r_max_rebuild; } - + /* Number of new cells created. */ int count = 1; diff --git a/src/cell.h b/src/cell.h index 8e53bb185..747b79f05 100644 --- a/src/cell.h +++ b/src/cell.h @@ -79,7 +79,7 @@ struct pcell { /*! This cell's gravity-related tensors */ struct multipole m_pole; - + /*! Centre of mass. */ double CoM[3]; @@ -501,7 +501,8 @@ void cell_munlocktree(struct cell *c); int cell_slocktree(struct cell *c); void cell_sunlocktree(struct cell *c); int cell_pack(struct cell *c, struct pcell *pc, const int with_gravity); -int cell_unpack(struct pcell *pc, struct cell *c, struct space *s, const int with_gravity); +int cell_unpack(struct pcell *pc, struct cell *c, struct space *s, + const int with_gravity); int cell_pack_tags(const struct cell *c, int *tags); int cell_unpack_tags(const int *tags, struct cell *c); int cell_pack_end_step(struct cell *c, struct pcell_step *pcell); diff --git a/src/engine.c b/src/engine.c index 13e5c4748..3525172f1 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5292,7 +5292,8 @@ void engine_makeproxies(struct engine *e) { const int cdim[3] = {s->cdim[0], s->cdim[1], s->cdim[2]}; const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]}; const int periodic = s->periodic; - const double cell_width[3] = {cells[0].width[0], cells[0].width[1], cells[0].width[2]}; + const double cell_width[3] = {cells[0].width[0], cells[0].width[1], + cells[0].width[2]}; /* Get some info about the physics */ const int with_hydro = (e->policy & engine_policy_hydro); @@ -5356,10 +5357,9 @@ void engine_makeproxies(struct engine *e) { /* Get the cell ID. */ const int cid = cell_getid(cdim, ind[0], ind[1], ind[2]); - /* and it's location */ - const double loc_i[3] = {cells[cid].loc[0], - cells[cid].loc[1], - cells[cid].loc[2]}; + /* and it's location */ + const double loc_i[3] = {cells[cid].loc[0], cells[cid].loc[1], + cells[cid].loc[2]}; /* Loop over all its neighbours (periodic). */ for (int i = -delta_m; i <= delta_p; i++) { @@ -5400,8 +5400,8 @@ void engine_makeproxies(struct engine *e) { /* In the hydro case, only care about direct neighbours */ if (with_hydro) { - //MATTHIEU: to do: Write a better expression for the - // non-periodic case. + // MATTHIEU: to do: Write a better expression for the + // non-periodic case. /* This is super-ugly but checks for direct neighbours */ /* with periodic BC */ @@ -5420,39 +5420,39 @@ void engine_makeproxies(struct engine *e) { /* In the gravity case, check distances using the MAC. */ if (with_gravity) { - /* We don't have multipoles yet (or there CoMs) so we will have to - cook up something based on cell locations only. We hence need - an upper limit on the distance that the CoMs in those cells - could have. We then can decide whether we are too close - for an M2L interaction and hence require a proxy as this pair - of cells cannot rely on just an M2L calculation. */ - - const double loc_j[3] = {cells[cjd].loc[0], - cells[cjd].loc[1], - cells[cjd].loc[2]}; - - /* Start with the distance between the cell centres. */ - double dx = loc_i[0] - loc_j[0]; - double dy = loc_i[1] - loc_j[1]; - double dz = loc_i[2] - loc_j[2]; - - /* Apply BC */ - if (periodic) { - dx = nearest(dx, dim[0]); - dy = nearest(dy, dim[0]); - dz = nearest(dz, dim[0]); - } - - /* Add to it for the case where the future CoMs are in the corners */ - dx += cell_width[0]; - dy += cell_width[1]; - dz += cell_width[2]; - - /* This is a crazy upper-bound but the best we can do */ - const double r2 = dx * dx + dy * dy + dz * dz; - - if (!gravity_M2L_accept(r_max, r_max, theta_crit2, r2)) - proxy_type |= (int)proxy_cell_type_gravity; + /* We don't have multipoles yet (or there CoMs) so we will have + to cook up something based on cell locations only. We hence + need an upper limit on the distance that the CoMs in those + cells could have. We then can decide whether we are too close + for an M2L interaction and hence require a proxy as this pair + of cells cannot rely on just an M2L calculation. */ + + const double loc_j[3] = {cells[cjd].loc[0], cells[cjd].loc[1], + cells[cjd].loc[2]}; + + /* Start with the distance between the cell centres. */ + double dx = loc_i[0] - loc_j[0]; + double dy = loc_i[1] - loc_j[1]; + double dz = loc_i[2] - loc_j[2]; + + /* Apply BC */ + if (periodic) { + dx = nearest(dx, dim[0]); + dy = nearest(dy, dim[0]); + dz = nearest(dz, dim[0]); + } + + /* Add to it for the case where the future CoMs are in the + * corners */ + dx += cell_width[0]; + dy += cell_width[1]; + dz += cell_width[2]; + + /* This is a crazy upper-bound but the best we can do */ + const double r2 = dx * dx + dy * dy + dz * dz; + + if (!gravity_M2L_accept(r_max, r_max, theta_crit2, r2)) + proxy_type |= (int)proxy_cell_type_gravity; } /* Abort if not in range at all */ diff --git a/src/proxy.c b/src/proxy.c index a5d30848a..55d1f7d08 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -126,8 +126,8 @@ void proxy_tags_exchange(struct proxy *proxies, int num_proxies, const int cid = proxies[k].cells_out[j] - s->cells_top; cids_out[send_rid] = cid; int err = MPI_Isend( - &tags_out[offset_out[cid]], proxies[k].cells_out[j]->pcell_size, MPI_INT, - proxies[k].nodeID, cid, MPI_COMM_WORLD, &reqs_out[send_rid]); + &tags_out[offset_out[cid]], proxies[k].cells_out[j]->pcell_size, + MPI_INT, proxies[k].nodeID, cid, MPI_COMM_WORLD, &reqs_out[send_rid]); if (err != MPI_SUCCESS) mpi_error(err, "Failed to isend tags."); send_rid += 1; } -- GitLab From e6255f26cd8d19c5ba7d67c67fe439e3c4d592a0 Mon Sep 17 00:00:00 2001 From: Matthieu Schaller Date: Sun, 26 Aug 2018 18:30:06 +0200 Subject: [PATCH 32/32] Skip gravity proxies that are beuond the range where the truncated tree forces are 0. --- src/engine.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/engine.c b/src/engine.c index 3525172f1..5502dafe5 100644 --- a/src/engine.c +++ b/src/engine.c @@ -5300,6 +5300,7 @@ void engine_makeproxies(struct engine *e) { const int with_gravity = (e->policy & engine_policy_self_gravity); const double theta_crit_inv = e->gravity_properties->theta_crit_inv; const double theta_crit2 = e->gravity_properties->theta_crit2; + const double max_distance = e->mesh->r_cut_max; /* Maximal distance between CoMs and any particle in the cell */ const double r_max2 = cell_width[0] * cell_width[0] + @@ -5451,8 +5452,22 @@ void engine_makeproxies(struct engine *e) { /* This is a crazy upper-bound but the best we can do */ const double r2 = dx * dx + dy * dy + dz * dz; - if (!gravity_M2L_accept(r_max, r_max, theta_crit2, r2)) - proxy_type |= (int)proxy_cell_type_gravity; + /* Minimal distance between any pair of particles */ + const double min_radius = sqrt(r2) - 2. * r_max; + + /* 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_radius < max_distance) && + (!gravity_M2L_accept(r_max, r_max, theta_crit2, r2))) + proxy_type |= (int)proxy_cell_type_gravity; + + } else { + + if (!gravity_M2L_accept(r_max, r_max, theta_crit2, r2)) + proxy_type |= (int)proxy_cell_type_gravity; + } } /* Abort if not in range at all */ -- GitLab