diff --git a/src/cell.c b/src/cell.c index 76a90016abc68a97136dc153eb9592591b09a464..276109ace602de29e36368bd4fb3b8900096640f 100644 --- a/src/cell.c +++ b/src/cell.c @@ -1406,14 +1406,16 @@ void cell_activate_drift_part(struct cell *c, struct scheduler *s) { /* Set the do_sub_drifts all the way up and activate the super drift if this has not yet been done. */ if (c == c->super_hydro) { - if(c->drift_part == NULL) error("Trying to activate un-existing c->drift_part"); + if (c->drift_part == NULL) + error("Trying to activate un-existing c->drift_part"); scheduler_activate(s, c->drift_part); } else { for (struct cell *parent = c->parent; parent != NULL && !parent->do_sub_drift; parent = parent->parent) { parent->do_sub_drift = 1; if (parent == c->super_hydro) { - if(parent->drift_part == NULL) error("Trying to activate un-existing parent->drift_part"); + if (parent->drift_part == NULL) + error("Trying to activate un-existing parent->drift_part"); scheduler_activate(s, parent->drift_part); break; } @@ -1435,12 +1437,13 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) { /* Set the do_grav_sub_drifts all the way up and activate the super drift if this has not yet been done. */ if (c == c->super_gravity) { - + /* Lock the cell and actuivate things */ - if(lock_lock(&c->lock) != 0) error("Error trying to lock cell"); - if(c->drift_gpart == NULL) error("Trying to activate un-existing c->drift_gpart"); - if(c->drift_gpart != NULL) scheduler_activate(s, c->drift_gpart); - if(lock_unlock(&c->lock) != 0) error("Error trying to unlock cell"); + if (lock_lock(&c->lock) != 0) error("Error trying to lock cell"); + if (c->drift_gpart == NULL) + error("Trying to activate un-existing c->drift_gpart"); + if (c->drift_gpart != NULL) scheduler_activate(s, c->drift_gpart); + if (lock_unlock(&c->lock) != 0) error("Error trying to unlock cell"); } else { for (struct cell *parent = c->parent; parent != NULL && !parent->do_grav_sub_drift; @@ -1448,11 +1451,15 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) { parent->do_grav_sub_drift = 1; if (parent == c->super_gravity) { - /* Lock the cell and actuivate things */ - if(lock_lock(&parent->lock) != 0) error("Error trying to lock parent cell"); - if(parent->drift_gpart == NULL) error("Trying to activate un-existing parent->drift_gpart"); - if(parent->drift_gpart != NULL)scheduler_activate(s, parent->drift_gpart); - if(lock_unlock(&parent->lock) != 0) error("Error trying to unlock parent cell"); + /* Lock the cell and actuivate things */ + if (lock_lock(&parent->lock) != 0) + error("Error trying to lock parent cell"); + if (parent->drift_gpart == NULL) + error("Trying to activate un-existing parent->drift_gpart"); + if (parent->drift_gpart != NULL) + scheduler_activate(s, parent->drift_gpart); + if (lock_unlock(&parent->lock) != 0) + error("Error trying to unlock parent cell"); break; } } @@ -1465,7 +1472,7 @@ void cell_activate_drift_gpart(struct cell *c, struct scheduler *s) { void cell_activate_sorts_up(struct cell *c, struct scheduler *s) { if (c == c->super_hydro) { - if(c->sorts == NULL) error("Trying to activate un-existing c->sorts"); + if (c->sorts == NULL) error("Trying to activate un-existing c->sorts"); scheduler_activate(s, c->sorts); if (c->nodeID == engine_rank) cell_activate_drift_part(c, s); } else { @@ -1474,7 +1481,8 @@ void cell_activate_sorts_up(struct cell *c, struct scheduler *s) { parent != NULL && !parent->do_sub_sort; parent = parent->parent) { parent->do_sub_sort = 1; if (parent == c->super_hydro) { - if(parent->sorts == NULL) error("Trying to activate un-existing parents->sorts"); + if (parent->sorts == NULL) + error("Trying to activate un-existing parents->sorts"); scheduler_activate(s, parent->sorts); if (parent->nodeID == engine_rank) cell_activate_drift_part(parent, s); break; diff --git a/src/cell.h b/src/cell.h index 18f6ee9d052c0b780e0c4028e8dd2cd3665d60fb..2fcd3e20ee3d18c1b6f012f9cd4f61f364348b9f 100644 --- a/src/cell.h +++ b/src/cell.h @@ -538,8 +538,8 @@ int cell_can_use_pair_mm(const struct cell *ci, const struct cell *cj, * * @param c The #cell. */ -__attribute__((always_inline)) INLINE static int cell_can_recurse_in_pair_hydro_task( - const struct cell *c) { +__attribute__((always_inline)) INLINE static int +cell_can_recurse_in_pair_hydro_task(const struct cell *c) { /* Is the cell split ? */ /* If so, is the cut-off radius plus the max distance the parts have moved */ @@ -555,8 +555,8 @@ __attribute__((always_inline)) INLINE static int cell_can_recurse_in_pair_hydro_ * * @param c The #cell. */ -__attribute__((always_inline)) INLINE static int cell_can_recurse_in_self_hydro_task( - const struct cell *c) { +__attribute__((always_inline)) INLINE static int +cell_can_recurse_in_self_hydro_task(const struct cell *c) { /* Is the cell split and not smaller than the smoothing length? */ return c->split && (kernel_gamma * c->h_max_old < 0.5f * c->dmin); @@ -596,15 +596,14 @@ __attribute__((always_inline)) INLINE static int cell_can_split_self_hydro_task( return c->split && (space_stretch * kernel_gamma * c->h_max < 0.5f * c->dmin); } - /** * @brief Can a pair gravity task associated with a cell be split into smaller * sub-tasks. * * @param c The #cell. */ -__attribute__((always_inline)) INLINE static int cell_can_split_pair_gravity_task( - const struct cell *c) { +__attribute__((always_inline)) INLINE static int +cell_can_split_pair_gravity_task(const struct cell *c) { /* Is the cell split ? */ return c->split && c->depth < space_subdepth_grav; @@ -616,8 +615,8 @@ __attribute__((always_inline)) INLINE static int cell_can_split_pair_gravity_tas * * @param c The #cell. */ -__attribute__((always_inline)) INLINE static int cell_can_split_self_gravity_task( - const struct cell *c) { +__attribute__((always_inline)) INLINE static int +cell_can_split_self_gravity_task(const struct cell *c) { /* Is the cell split ? */ return c->split && c->depth < space_subdepth_grav; diff --git a/src/engine.c b/src/engine.c index ed880973fd224f3fbc5a4669bb5b6cbaa883a461..62d9da4e05c16fb04c1693920bd3175572e9f8f5 100644 --- a/src/engine.c +++ b/src/engine.c @@ -2404,9 +2404,9 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, const double CoM_i[3] = {multi_i->CoM[0], multi_i->CoM[1], multi_i->CoM[2]}; #ifdef SWIFT_DEBUG_CHECKS - if(cell_getid(cdim, i, j, k) != cid) - error("Incorrect calculation of indices (i,j,k)=(%d,%d,%d) cid=%d", - i, j, k, cid); + if (cell_getid(cdim, i, j, k) != cid) + error("Incorrect calculation of indices (i,j,k)=(%d,%d,%d) cid=%d", i, j, + k, cid); if (multi_i->r_max != multi_i->r_max_rebuild) error( @@ -2417,29 +2417,37 @@ void engine_make_self_gravity_tasks_mapper(void *map_data, int num_elements, /* Loop over every other cell within (Manhattan) range delta */ for (int x = -delta; x <= delta; x++) { int ii = i + x; - if (ii >= cdim[0]) ii -= cdim[0]; - else if (ii < 0) ii += cdim[0]; + if (ii >= cdim[0]) + ii -= cdim[0]; + else if (ii < 0) + ii += cdim[0]; for (int y = -delta; y <= delta; y++) { - int jj = j + y; - if (jj >= cdim[1]) jj -= cdim[1]; - else if (jj < 0) jj += cdim[1]; - for (int z = -delta; z <= delta; z++) { - int kk = k + z; - if (kk >= cdim[2]) kk -= cdim[2]; - else if (kk < 0) kk += cdim[2]; + int jj = j + y; + if (jj >= cdim[1]) + jj -= cdim[1]; + else if (jj < 0) + jj += cdim[1]; + for (int z = -delta; z <= delta; z++) { + int kk = k + z; + if (kk >= cdim[2]) + kk -= cdim[2]; + else if (kk < 0) + kk += cdim[2]; /* Get the cell */ const int cjd = cell_getid(cdim, ii, jj, kk); struct cell *cj = &cells[cjd]; #ifdef SWIFT_DEBUG_CHECKS - const int iii = cjd / (cdim[1] * cdim[2]); - const int jjj = (cjd / cdim[2]) % cdim[1]; - const int kkk = cjd % cdim[2]; - - if(ii != iii || jj != jjj || kk != kkk) - error("Incorrect calculation of indices (iii,jjj,kkk)=(%d,%d,%d) cjd=%d", - iii, jjj, kkk, cjd); + const int iii = cjd / (cdim[1] * cdim[2]); + const int jjj = (cjd / cdim[2]) % cdim[1]; + const int kkk = cjd % cdim[2]; + + if (ii != iii || jj != jjj || kk != kkk) + error( + "Incorrect calculation of indices (iii,jjj,kkk)=(%d,%d,%d) " + "cjd=%d", + iii, jjj, kkk, cjd); #endif /* Avoid duplicates of local pairs*/ @@ -2730,7 +2738,7 @@ void engine_link_gravity_tasks(struct engine *e) { const enum task_types t_type = t->type; const enum task_subtypes t_subtype = t->subtype; - /* Node ID (if running with MPI) */ +/* Node ID (if running with MPI) */ #ifdef WITH_MPI const int ci_nodeID = ci->nodeID; const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; @@ -3244,8 +3252,8 @@ void engine_maketasks(struct engine *e) { Each force task depends on the cell ghosts and unlocks the kick task of its super-cell. */ if (e->policy & engine_policy_hydro) - threadpool_map(&e->threadpool, engine_make_extra_hydroloop_tasks_mapper, - sched->tasks, sched->nr_tasks, sizeof(struct task), 0, e); + threadpool_map(&e->threadpool, engine_make_extra_hydroloop_tasks_mapper, + sched->tasks, sched->nr_tasks, sizeof(struct task), 0, e); /* Add the dependencies for the gravity stuff */ if (e->policy & (engine_policy_self_gravity | engine_policy_external_gravity)) @@ -3958,7 +3966,8 @@ void engine_prepare(struct engine *e) { if (!e->forcerepart) engine_unskip(e); #ifdef WITH_MPI - MPI_Allreduce(MPI_IN_PLACE, &e->forcerebuild, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); + MPI_Allreduce(MPI_IN_PLACE, &e->forcerebuild, 1, MPI_INT, MPI_MAX, + MPI_COMM_WORLD); #endif /* Do we need repartitioning ? */ diff --git a/src/runner_doiact.h b/src/runner_doiact.h index 80f661502d93a70c06e940b074ef56292b5e29fd..79c7760b86a7e8cc92bc7aef5d0bab093464033c 100644 --- a/src/runner_doiact.h +++ b/src/runner_doiact.h @@ -2086,7 +2086,8 @@ void DOSUB_PAIR1(struct runner *r, struct cell *ci, struct cell *cj, int sid, sid = space_getsid(s, &ci, &cj, shift); /* Recurse? */ - if (cell_can_recurse_in_pair_hydro_task(ci) && cell_can_recurse_in_pair_hydro_task(cj)) { + if (cell_can_recurse_in_pair_hydro_task(ci) && + cell_can_recurse_in_pair_hydro_task(cj)) { /* Different types of flags. */ switch (sid) { @@ -2376,7 +2377,8 @@ void DOSUB_PAIR2(struct runner *r, struct cell *ci, struct cell *cj, int sid, sid = space_getsid(s, &ci, &cj, shift); /* Recurse? */ - if (cell_can_recurse_in_pair_hydro_task(ci) && cell_can_recurse_in_pair_hydro_task(cj)) { + if (cell_can_recurse_in_pair_hydro_task(ci) && + cell_can_recurse_in_pair_hydro_task(cj)) { /* Different types of flags. */ switch (sid) { diff --git a/src/scheduler.c b/src/scheduler.c index 90f20d776361ea27d79083500f14f1ff536b894a..4974884651b02db57d851493a4fc8fe343483a05 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -419,7 +419,8 @@ static void scheduler_splittask_hydro(struct task *t, struct scheduler *s) { const int sid = space_getsid(s->space, &ci, &cj, shift); /* Should this task be split-up? */ - if (cell_can_split_pair_hydro_task(ci) && cell_can_split_pair_hydro_task(cj)) { + if (cell_can_split_pair_hydro_task(ci) && + cell_can_split_pair_hydro_task(cj)) { /* Replace by a single sub-task? */ if (scheduler_dosub && /* Use division to avoid integer overflow. */ @@ -903,16 +904,17 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) { t->type = task_type_grav_mm; 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); - engine_addlink(e, &ci->grav, t); - engine_addlink(e, &cj->grav, t); + /* 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); break; } /* Should this task be split-up? */ - if (cell_can_split_pair_gravity_task(ci) && cell_can_split_pair_gravity_task(cj)) { + if (cell_can_split_pair_gravity_task(ci) && + cell_can_split_pair_gravity_task(cj)) { /* Replace by a single sub-task? */ if (scheduler_dosub && /* Use division to avoid integer overflow. */