diff --git a/src/cell.c b/src/cell.c index 0c24d1adecfd7f43087eac7d1db8cff6d91e5c12..3d12780513f1cae3cdf693fe7dda6a19d618608e 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2486,11 +2486,12 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj, else { /* Should we even bother? */ - if (!cell_is_active_stars(ci, e) && !cell_is_active_stars(cj, e)) return; + const int should_do_ci = ci->stars.count != 0 && cj->hydro.count != 0 && + cell_is_active_stars(ci, e); + const int should_do_cj = cj->stars.count != 0 && ci->hydro.count != 0 && + cell_is_active_stars(cj, e); - int should_do = ci->stars.count != 0 && cj->hydro.count != 0; - should_do |= cj->stars.count != 0 && ci->hydro.count != 0; - if (!should_do) return; + if (!should_do_ci && !should_do_cj) return; /* Get the orientation of the pair. */ double shift[3]; @@ -2776,8 +2777,12 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj, /* Otherwise, activate the sorts and drifts. */ else { + const int do_ci = ci->stars.count != 0 && cj->hydro.count != 0 && + cell_is_active_stars(ci, e); + const int do_cj = cj->stars.count != 0 && ci->hydro.count != 0 && + cell_is_active_stars(cj, e); - if (cell_is_active_stars(ci, e)) { + if (do_ci) { /* We are going to interact this pair, so store some values. */ atomic_or(&cj->hydro.requires_sorts, 1 << sid); atomic_or(&ci->stars.requires_sorts, 1 << sid); @@ -2794,7 +2799,7 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj, cell_activate_stars_sorts(ci, sid, s); } - if (cell_is_active_stars(cj, e)) { + if (do_cj) { /* We are going to interact this pair, so store some values. */ atomic_or(&cj->stars.requires_sorts, 1 << sid); atomic_or(&ci->hydro.requires_sorts, 1 << sid); @@ -3354,23 +3359,20 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) { const int ci_nodeID = ci->nodeID; const int cj_nodeID = (cj != NULL) ? cj->nodeID : -1; - /* Only activate tasks that involve a local active cell. */ - if ((ci_active && ci->nodeID == nodeID) || - (cj_active && cj->nodeID == nodeID)) { - scheduler_activate(s, t); + if (t->type == task_type_self && + ci_active && ci->nodeID == nodeID) { - /* Activate drifts */ - if (t->type == task_type_self) { - if (ci->nodeID == nodeID) { - cell_activate_drift_part(ci, s); - cell_activate_drift_spart(ci, s); - } - } + cell_activate_drift_part(ci, s); + cell_activate_drift_spart(ci, s); } /* Activate cells that contains either a density or a feedback task */ if ((ci_active || cj_active) && (ci_nodeID == nodeID || cj_nodeID == nodeID)) { + + /* Only activate tasks that involve a local active cell. */ + scheduler_activate(s, t); + /* Set the correct sorting flags and activate hydro drifts */ if (t->type == task_type_pair) { /* Do ci */ diff --git a/src/cell.h b/src/cell.h index 49ee0c2a00a512de1b3038faae8ffeaae175368d..dd328c7e17840effe1456d5b2e022d18ed02dc95 100644 --- a/src/cell.h +++ b/src/cell.h @@ -874,7 +874,9 @@ cell_can_recurse_in_pair_stars_task(const struct cell *c) { /* smaller than the sub-cell sizes ? */ /* Note: We use the _old values as these might have been updated by a drift */ return c->split && ((kernel_gamma * c->stars.h_max_old + - c->stars.dx_max_part_old) < 0.5f * c->dmin); + c->stars.dx_max_part_old) < 0.5f * c->dmin) && + ((kernel_gamma * c->hydro.h_max_old + + c->hydro.dx_max_part_old) < 0.5f * c->dmin); } /** @@ -887,7 +889,8 @@ __attribute__((always_inline)) INLINE static int cell_can_recurse_in_self_stars_task(const struct cell *c) { /* Is the cell split and not smaller than the smoothing length? */ - return c->split && (kernel_gamma * c->stars.h_max_old < 0.5f * c->dmin); + return c->split && (kernel_gamma * c->stars.h_max_old < 0.5f * c->dmin) && + (kernel_gamma * c->hydro.h_max_old < 0.5f * c->dmin); } /** diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c index c90f28b10b8832f4e36fec8804c7b6bc1dcd71f3..dd80070f55abc03cd1de087ad51629ac4d05a32b 100644 --- a/src/engine_marktasks.c +++ b/src/engine_marktasks.c @@ -252,7 +252,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements, t_subtype == task_subtype_stars_feedback) { if (cell_is_active_stars(ci, e)) { scheduler_activate(s, t); - cell_activate_subcell_stars_tasks(ci, NULL, s); + cell_activate_subcell_stars_tasks(ci, NULL, s); } } @@ -344,26 +344,22 @@ void engine_marktasks_mapper(void *map_data, int num_elements, /* Stars density and feedback */ const int stars_density = - t_subtype == task_subtype_stars_density && - ((ci_active_stars && ci->nodeID == engine_rank) || - (cj_active_stars && cj->nodeID == engine_rank)); + t_subtype == task_subtype_stars_density; + const int stars_feedback = - t_subtype == task_subtype_stars_feedback && - ((ci_active_stars && cj->nodeID == engine_rank) || - (cj_active_stars && ci->nodeID == engine_rank)); + t_subtype == task_subtype_stars_feedback; - if (stars_density || stars_feedback) { + const int active = ci_active_stars || cj_active_stars; - scheduler_activate(s, t); + if ((stars_density || stars_feedback) && active) { - const int should_do = - t_subtype == task_subtype_stars_density || cj->nodeID != ci->nodeID; + scheduler_activate(s, t); /* Set the correct sorting flags */ if (t_type == task_type_pair) { /* Do ci */ - if (ci_active_stars && should_do) { + if (ci_active_stars) { /* Store some values. */ atomic_or(&cj->hydro.requires_sorts, 1 << t->flags); atomic_or(&ci->stars.requires_sorts, 1 << t->flags); @@ -383,7 +379,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements, } /* Do cj */ - if (cj_active_stars && should_do) { + if (cj_active_stars) { /* Store some values. */ atomic_or(&ci->hydro.requires_sorts, 1 << t->flags); atomic_or(&cj->stars.requires_sorts, 1 << t->flags); @@ -403,7 +399,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements, } /* Store current values of dx_max and h_max. */ - else if (t_type == task_type_sub_pair && should_do) { + else if (t_type == task_type_sub_pair) { cell_activate_subcell_stars_tasks(t->ci, t->cj, s); } } diff --git a/src/runner.c b/src/runner.c index 22d35d31c4318874fe6a47438d6025cd578a1c73..011c5bccc2dd645baee0a58350306395c2817089 100644 --- a/src/runner.c +++ b/src/runner.c @@ -965,10 +965,11 @@ void runner_do_stars_sort(struct runner *r, struct cell *c, int flags, for (int k = 0; k < 8; k++) { if (c->progeny[k] != NULL && c->progeny[k]->stars.count > 0) { /* Only propagate cleanup if the progeny is stale. */ + const int cleanup_prog = cleanup && + (c->progeny[k]->stars.dx_max_sort_old > + space_maxreldx * c->progeny[k]->dmin); runner_do_stars_sort(r, c->progeny[k], flags, - cleanup && (c->progeny[k]->stars.dx_max_sort_old > - space_maxreldx * c->progeny[k]->dmin), - 0); + cleanup_prog, 0); dx_max_sort = max(dx_max_sort, c->progeny[k]->stars.dx_max_sort); dx_max_sort_old = max(dx_max_sort_old, c->progeny[k]->stars.dx_max_sort_old); @@ -2704,7 +2705,7 @@ void runner_do_end_force(struct runner *r, struct cell *c, int timer) { if (spart_is_active(sp, e)) { /* Finish the force loop */ - stars_end_feedback(sp); + stars_end_force(sp); } } } @@ -2955,6 +2956,7 @@ void runner_do_recv_spart(struct runner *r, struct cell *c, int clear_sorts, /* ... and store. */ // c->grav.ti_end_min = ti_gravity_end_min; // c->grav.ti_end_max = ti_gravity_end_max; + c->hydro.ti_old_part = ti_current; c->grav.ti_old_part = ti_current; c->stars.h_max = h_max; @@ -3121,9 +3123,8 @@ void *runner_main(void *data) { case task_type_stars_sort_local: case task_type_stars_sort_foreign: /* Cleanup only if any of the indices went stale. */ - runner_do_stars_sort( - r, ci, t->flags, - ci->stars.dx_max_sort_old > space_maxreldx * ci->dmin, 1); + runner_do_stars_sort(r, ci, t->flags, + ci->stars.dx_max_sort_old > space_maxreldx * ci->dmin, 1); /* Reset the sort flags as our work here is done. */ t->flags = 0; break; diff --git a/src/runner_doiact_stars.h b/src/runner_doiact_stars.h index 917799d008eb6f2ab57dc9efd7f0317d35c6dcb7..df67f2b098f38dc6cedcc4d2e041590c1f1e1d18 100644 --- a/src/runner_doiact_stars.h +++ b/src/runner_doiact_stars.h @@ -990,7 +990,14 @@ void DOSUB_SUBSET_STARS(struct runner *r, struct cell *ci, struct spart *sparts, else if (cell_is_active_stars(ci, e) || cell_is_active_stars(cj, e)) { /* Do any of the cells need to be drifted first? */ - if (!cell_are_part_drifted(cj, e)) error("Cell should be drifted!"); + if (cell_is_active_stars(ci, e)) { + if (!cell_are_spart_drifted(ci, e)) error("Cell should be drifted!"); + if (!cell_are_part_drifted(cj, e)) error("Cell should be drifted!"); + } + if (cell_is_active_stars(cj, e)) { + if (!cell_are_part_drifted(ci, e)) error("Cell should be drifted!"); + if (!cell_are_spart_drifted(cj, e)) error("Cell should be drifted! %i %i %lli %lli %lli", cj->cellID, cj->nodeID, e->ti_current, cj->grav.ti_old_part, cj->super->grav.ti_old_part); + } DOPAIR1_SUBSET_BRANCH_STARS(r, ci, sparts, ind, scount, cj); } @@ -1142,11 +1149,11 @@ void DOSUB_PAIR1_STARS(struct runner *r, struct cell *ci, struct cell *cj, const struct engine *e = r->e; /* Should we even bother? */ - int should_do = ci->stars.count != 0 && cj->hydro.count != 0 && + const int should_do_ci = ci->stars.count != 0 && cj->hydro.count != 0 && cell_is_active_stars(ci, e); - should_do |= cj->stars.count != 0 && ci->hydro.count != 0 && + const int should_do_cj = cj->stars.count != 0 && ci->hydro.count != 0 && cell_is_active_stars(cj, e); - if (!should_do) return; + if (!should_do_ci && !should_do_cj) return; /* Get the type of pair if not specified explicitly. */ double shift[3]; @@ -1420,7 +1427,6 @@ void DOSUB_PAIR1_STARS(struct runner *r, struct cell *ci, struct cell *cj, * @param gettimer Do we have a timer ? */ void DOSUB_SELF1_STARS(struct runner *r, struct cell *ci, int gettimer) { - /* Should we even bother? */ if (ci->hydro.count == 0 || ci->stars.count == 0 || !cell_is_active_stars(ci, r->e))