diff --git a/src/cell.c b/src/cell.c index 006ae37d0cd3b243146adf5d95781c7585ad65bc..e0470fc68befa8aa91986b1db8934ff07903ecc0 100644 --- a/src/cell.c +++ b/src/cell.c @@ -2397,6 +2397,34 @@ void cell_clear_limiter_flags(struct cell *c, void *data) { cell_flag_do_hydro_limiter | cell_flag_do_hydro_sub_limiter); } +void cell_activate_star_formation_tasks(struct cell *c, struct scheduler *s) { + + if (c->depth != 0) error("Function should be called at the top-level only"); + + /* Have we already unskipped that task? */ + if (c->hydro.star_formation->skip == 0) return; + + /* Activate the star formation task */ + scheduler_activate(s, c->hydro.star_formation); + scheduler_activate(s, c->hydro.stars_resort); + + /* Shallow tree case -> the resort task is at this level */ + if (c->hydro.super == c) { + scheduler_activate(s, c->hydro.stars_resort); + } + + /* Deep tree case -> the resort is in the progenies */ + else { + + for (int k = 0; k < 8; ++k) { + if (c->progeny[k] != NULL) { + message("hello"); + scheduler_activate(s, c->progeny[k]->hydro.stars_resort); + } + } + } +} + /** * @brief Recurse down in a cell hierarchy until the hydro.super level is * reached and activate the spart drift at that level. @@ -3430,12 +3458,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) { if (c->logger != NULL) scheduler_activate(s, c->logger); if (c->top->hydro.star_formation != NULL) { - scheduler_activate(s, c->top->hydro.star_formation); - } - - if (c->hydro.super != NULL && c->hydro.super->hydro.stars_resort != NULL) { - scheduler_activate(s, c->hydro.super->hydro.stars_resort); - cell_activate_drift_spart(c, s); + cell_activate_star_formation_tasks(c->top, s); } } diff --git a/src/cell.h b/src/cell.h index 9c9e2e64f85305e37fe912e0436e5dbde333f6d8..666063f1cb2a6f63d1d582c2c9e05033b38e03d1 100644 --- a/src/cell.h +++ b/src/cell.h @@ -874,6 +874,7 @@ void cell_drift_multipole(struct cell *c, const struct engine *e); void cell_drift_all_multipoles(struct cell *c, const struct engine *e); void cell_check_timesteps(struct cell *c); void cell_store_pre_drift_values(struct cell *c); +void cell_activate_star_formation_tasks(struct cell *c, struct scheduler *s); void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj, struct scheduler *s); void cell_activate_subcell_grav_tasks(struct cell *ci, struct cell *cj, diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c index d376bb43a647b105fd8a55125e6a98a69867ca56..af3e3b75c93568d915a255f95b7ab67f4351c412 100644 --- a/src/engine_maketasks.c +++ b/src/engine_maketasks.c @@ -988,15 +988,22 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c, const int with_black_holes = (e->policy & engine_policy_black_holes); /* Are we at the top-level but this is also the super-level? */ - if (c->top == c && c->hydro.super == c && c->nodeID == e->nodeID) { + if (c->top == c && c->nodeID == e->nodeID) { /* Record this is the level where we re-sort */ star_resort_cell = c; if (with_star_formation && c->hydro.count > 0) { - c->hydro.stars_resort = scheduler_addtask( - s, task_type_stars_resort, task_subtype_none, 0, 0, c, NULL); - scheduler_addunlock(s, c->hydro.star_formation, c->hydro.stars_resort); + + if (c->hydro.super == c) { + + c->hydro.stars_resort = scheduler_addtask( + s, task_type_stars_resort, task_subtype_none, 0, 0, c, NULL); + scheduler_addunlock(s, c->hydro.star_formation, c->hydro.stars_resort); + } else { + c->hydro.stars_resort = scheduler_addtask( + s, task_type_stars_resort, task_subtype_none, 0, 1, c, NULL); + } } } @@ -1011,6 +1018,7 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c, scheduler_addunlock(s, c->top->hydro.star_formation, c->hydro.stars_resort); + scheduler_addunlock(s, c->hydro.stars_resort, c->top->hydro.stars_resort); } } @@ -1103,8 +1111,7 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c, scheduler_addunlock(s, c->stars.stars_out, c->super->timestep); if (with_star_formation && c->hydro.count > 0) { - scheduler_addunlock(s, star_resort_cell->hydro.stars_resort, - c->stars.stars_in); + scheduler_addunlock(s, c->top->hydro.stars_resort, c->stars.stars_in); } } diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c index dcf1be29a677ce69d9fa471f7f734583ee6842eb..7f4e2d4c4b4ae4865eb2c2320d021be534cc57c3 100644 --- a/src/engine_marktasks.c +++ b/src/engine_marktasks.c @@ -939,10 +939,9 @@ void engine_marktasks_mapper(void *map_data, int num_elements, } /* Subgrid tasks: star formation */ - else if (t_type == task_type_star_formation || - t_type == task_type_stars_resort) { + else if (t_type == task_type_star_formation) { if (cell_is_active_hydro(t->ci, e)) { - scheduler_activate(s, t); + cell_activate_star_formation_tasks(t->ci, s); cell_activate_super_spart_drifts(t->ci, s); } }