diff --git a/src/active.h b/src/active.h index dabb798855cbebf594a6cb180d2b98084450cbca..89955ae430aa0a685cdc513b5c11ac44f6b093e8 100644 --- a/src/active.h +++ b/src/active.h @@ -390,6 +390,29 @@ __attribute__((always_inline)) INLINE static int cell_is_starting_gravity( return (c->grav.ti_beg_max == e->ti_current); } +/** + * @brief Does a cell contain any s-particle starting 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_starting_stars( + const struct cell *c, const struct engine *e) { + +#ifdef SWIFT_DEBUG_CHECKS + if (c->stars.ti_beg_max > e->ti_current) + error( + "cell in an impossible time-zone! c->ti_beg_max=%lld (t=%e) and " + "e->ti_current=%lld (t=%e, a=%e)", + c->stars.ti_beg_max, c->stars.ti_beg_max * e->time_base, e->ti_current, + e->ti_current * e->time_base, e->cosmology->a); +#endif + + return (c->stars.ti_beg_max == e->ti_current); +} + + /** * @brief Is this particle starting its time-step now ? * diff --git a/src/cell.c b/src/cell.c index b16168347c2cf653df44bfe20b4ecc272758fd89..8f63a3c51492cd3b0f65a5d55f79fe54aa4e293b 100644 --- a/src/cell.c +++ b/src/cell.c @@ -387,6 +387,7 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, pc->grav.ti_end_min = c->grav.ti_end_min; pc->grav.ti_end_max = c->grav.ti_end_max; pc->stars.ti_end_min = c->stars.ti_end_min; + pc->stars.ti_end_max = c->stars.ti_end_max; pc->hydro.ti_old_part = c->hydro.ti_old_part; pc->grav.ti_old_part = c->grav.ti_old_part; pc->grav.ti_old_multipole = c->grav.ti_old_multipole; @@ -493,6 +494,7 @@ int cell_unpack(struct pcell *restrict pc, struct cell *restrict c, c->grav.ti_end_min = pc->grav.ti_end_min; c->grav.ti_end_max = pc->grav.ti_end_max; c->stars.ti_end_min = pc->stars.ti_end_min; + c->stars.ti_end_max = pc->stars.ti_end_max; c->hydro.ti_old_part = pc->hydro.ti_old_part; c->grav.ti_old_part = pc->grav.ti_old_part; c->grav.ti_old_multipole = pc->grav.ti_old_multipole; @@ -623,6 +625,7 @@ int cell_pack_end_step(struct cell *restrict c, pcells[0].grav.ti_end_min = c->grav.ti_end_min; pcells[0].grav.ti_end_max = c->grav.ti_end_max; pcells[0].stars.ti_end_min = c->stars.ti_end_min; + pcells[0].stars.ti_end_max = c->stars.ti_end_max; pcells[0].hydro.dx_max_part = c->hydro.dx_max_part; pcells[0].stars.dx_max_part = c->stars.dx_max_part; @@ -661,6 +664,7 @@ int cell_unpack_end_step(struct cell *restrict c, c->grav.ti_end_min = pcells[0].grav.ti_end_min; c->grav.ti_end_max = pcells[0].grav.ti_end_max; c->stars.ti_end_min = pcells[0].stars.ti_end_min; + c->stars.ti_end_max = pcells[0].stars.ti_end_max; c->hydro.dx_max_part = pcells[0].hydro.dx_max_part; c->stars.dx_max_part = pcells[0].stars.dx_max_part; @@ -3400,6 +3404,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) { * @return 1 If the space needs rebuilding. 0 otherwise. */ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) { + struct engine *e = s->space->e; const int nodeID = e->nodeID; int rebuild = 0; @@ -3559,6 +3564,7 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) { /* Unskip all the other task types. */ if (c->nodeID == nodeID && cell_is_active_stars(c, e)) { + if (c->stars.drift != NULL) scheduler_activate(s, c->stars.drift); if (c->stars.ghost != NULL) scheduler_activate(s, c->stars.ghost); if (c->stars.stars_in != NULL) scheduler_activate(s, c->stars.stars_in); if (c->stars.stars_out != NULL) scheduler_activate(s, c->stars.stars_out); diff --git a/src/cell.h b/src/cell.h index 48ed1e91bb98faf1492b5625d1723e6275896735..529993a7433385656a0964867ddae1bf1f0a6e7c 100644 --- a/src/cell.h +++ b/src/cell.h @@ -150,6 +150,9 @@ struct pcell { /*! Minimal integer end-of-timestep in this cell for stars tasks */ integertime_t ti_end_min; + /*! Maximal integer end-of-timestep in this cell for stars tasks */ + integertime_t ti_end_max; + /*! Integer time of the last drift of the #spart in this cell */ integertime_t ti_old_part; @@ -201,12 +204,15 @@ struct pcell_step { /*! Stars variables */ struct { - /*! Maximal distance any #part has travelled since last rebuild */ - float dx_max_part; - /*! Minimal integer end-of-timestep in this cell (stars) */ integertime_t ti_end_min; + /*! Maximal integer end-of-timestep in this cell (stars) */ + integertime_t ti_end_max; + + /*! Maximal distance any #part has travelled since last rebuild */ + float dx_max_part; + } stars; }; @@ -542,6 +548,13 @@ struct cell { /*! Maximum end of (integer) time step in this cell for gravity tasks. */ integertime_t ti_end_min; + /*! Maximum end of (integer) time step in this cell for star tasks. */ + integertime_t ti_end_max; + + /*! Maximum beginning of (integer) time step in this cell for star tasks. + */ + integertime_t ti_beg_max; + /*! Number of #spart updated in this cell. */ int updated; diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c index bb41bb9a56936ebf79641e9615530df4d0cc3c13..d88bd304d0f99c13a040ce926215244555161b03 100644 --- a/src/engine_maketasks.c +++ b/src/engine_maketasks.c @@ -384,7 +384,7 @@ void engine_addtasks_recv_hydro(struct engine *e, struct cell *c, /* Add dependencies. */ if (c->hydro.sorts != NULL) scheduler_addunlock(s, t_xv, c->hydro.sorts); - if (c->stars.sorts != NULL) scheduler_addunlock(s, t_rho, c->stars.sorts); + if (c->stars.sorts != NULL) scheduler_addunlock(s, t_xv, c->stars.sorts); for (struct link *l = c->hydro.density; l != NULL; l = l->next) { scheduler_addunlock(s, t_xv, l->t); @@ -821,6 +821,7 @@ void engine_add_ghosts(struct engine *e, struct cell *c, struct task *ghost_in, void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) { struct scheduler *s = &e->sched; + const int with_stars = (e->policy & engine_policy_stars); const int with_feedback = (e->policy & engine_policy_feedback); const int with_cooling = (e->policy & engine_policy_cooling); const int with_star_formation = (e->policy & engine_policy_star_formation); @@ -863,6 +864,15 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) { s, task_type_extra_ghost, task_subtype_none, 0, 0, c, NULL); #endif + /* Stars */ + if (with_stars) { + c->stars.drift = scheduler_addtask(s, task_type_drift_spart, + task_subtype_none, 0, 0, c, NULL); + if(!with_feedback) { + scheduler_addunlock(s, c->stars.drift, c->super->kick2); + } + } + /* Subgrid tasks: cooling */ if (with_cooling) { @@ -897,8 +907,6 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) { scheduler_addtask(s, task_type_stars_out, task_subtype_none, 0, /* implicit = */ 1, c, NULL); - c->stars.drift = scheduler_addtask(s, task_type_drift_spart, - task_subtype_none, 0, 0, c, NULL); c->stars.ghost = scheduler_addtask(s, task_type_stars_ghost, task_subtype_none, 0, 0, c, NULL); diff --git a/src/runner.c b/src/runner.c index 7d5e8da71a46714026d52ab9b7bb361d63e95942..5f018f661650529f1d549fcd2f1f315f11f88b89 100644 --- a/src/runner.c +++ b/src/runner.c @@ -1816,7 +1816,7 @@ void runner_do_kick1(struct runner *r, struct cell *c, int timer) { TIMER_TIC; /* Anything to do here? */ - if (!cell_is_starting_hydro(c, e) && !cell_is_starting_gravity(c, e)) return; + if (!cell_is_starting_hydro(c, e) && !cell_is_starting_gravity(c, e) && !cell_is_starting_stars(c, e)) return; /* Recurse? */ if (c->split) { @@ -1998,7 +1998,7 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) { TIMER_TIC; /* Anything to do here? */ - if (!cell_is_active_hydro(c, e) && !cell_is_active_gravity(c, e)) return; + if (!cell_is_active_hydro(c, e) && !cell_is_active_gravity(c, e) && !cell_is_active_stars(c, e)) return; /* Recurse? */ if (c->split) { @@ -2205,7 +2205,8 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ti_hydro_beg_max = 0; integertime_t ti_gravity_end_min = max_nr_timesteps, ti_gravity_end_max = 0, ti_gravity_beg_max = 0; - integertime_t ti_stars_end_min = max_nr_timesteps; + integertime_t ti_stars_end_min = max_nr_timesteps, ti_stars_end_max = 0, + ti_stars_beg_max = 0; /* No children? */ if (!c->split) { @@ -2383,15 +2384,15 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { s_updated++; g_updated++; - /* What is the next sync-point ? */ - ti_gravity_end_min = min(ti_current + ti_new_step, ti_gravity_end_min); - ti_gravity_end_max = max(ti_current + ti_new_step, ti_gravity_end_max); - ti_stars_end_min = min(ti_current + ti_new_step, ti_stars_end_min); + ti_stars_end_max = max(ti_current + ti_new_step, ti_stars_end_max); + ti_gravity_end_min = min(ti_end, ti_gravity_end_min); + ti_gravity_end_max = max(ti_end, ti_gravity_end_max); /* What is the next starting point for this cell ? */ - ti_gravity_beg_max = max(ti_current, ti_gravity_beg_max); - + ti_stars_beg_max = max(ti_current, ti_stars_beg_max); + ti_gravity_beg_max = max(ti_current, ti_gravity_beg_max); + /* star particle is inactive but not inhibited */ } else { @@ -2401,26 +2402,26 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { const integertime_t ti_end = get_integer_time_end(ti_current, sp->time_bin); - /* What is the next sync-point ? */ - ti_gravity_end_min = min(ti_end, ti_gravity_end_min); - ti_gravity_end_max = max(ti_end, ti_gravity_end_max); - ti_stars_end_min = min(ti_end, ti_stars_end_min); + ti_stars_end_max = max(ti_end, ti_stars_end_max); + ti_gravity_end_min = min(ti_end, ti_gravity_end_min); + ti_gravity_end_max = max(ti_end, ti_gravity_end_max); const integertime_t ti_beg = - get_integer_time_begin(ti_current + 1, sp->time_bin); - + get_integer_time_begin(ti_current + 1, sp->time_bin); + /* What is the next starting point for this cell ? */ - ti_gravity_beg_max = max(ti_beg, ti_gravity_beg_max); + ti_stars_beg_max = max(ti_beg, ti_stars_beg_max); + ti_gravity_beg_max = max(ti_beg, ti_gravity_beg_max); } } } else { /* Loop over the progeny. */ - for (int k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { if (c->progeny[k] != NULL) { struct cell *restrict cp = c->progeny[k]; - + /* Recurse */ runner_do_timestep(r, cp, 0); @@ -2438,7 +2439,10 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ti_gravity_end_max = max(cp->grav.ti_end_max, ti_gravity_end_max); ti_gravity_beg_max = max(cp->grav.ti_beg_max, ti_gravity_beg_max); ti_stars_end_min = min(cp->stars.ti_end_min, ti_stars_end_min); + ti_stars_end_max = max(cp->grav.ti_end_max, ti_stars_end_max); + ti_stars_beg_max = max(cp->grav.ti_beg_max, ti_stars_beg_max); } + } } /* Store the values. */ @@ -2455,6 +2459,8 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { c->grav.ti_end_max = ti_gravity_end_max; c->grav.ti_beg_max = ti_gravity_beg_max; c->stars.ti_end_min = ti_stars_end_min; + c->stars.ti_end_max = ti_stars_end_max; + c->stars.ti_beg_max = ti_stars_beg_max; #ifdef SWIFT_DEBUG_CHECKS if (c->hydro.ti_end_min == e->ti_current && diff --git a/src/space.c b/src/space.c index 7b575f9223058c5b8f7d55eaf5edd2e86d5bab87..08480866395436f272c9956b8a36421f7a97fc01 100644 --- a/src/space.c +++ b/src/space.c @@ -253,6 +253,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, c->grav.ti_end_min = -1; c->grav.ti_end_max = -1; c->stars.ti_end_min = -1; + c->stars.ti_end_max = -1; #ifdef SWIFT_DEBUG_CHECKS c->cellID = 0; #endif @@ -2599,7 +2600,8 @@ void space_split_recursive(struct space *s, struct cell *c, ti_hydro_beg_max = 0; integertime_t ti_gravity_end_min = max_nr_timesteps, ti_gravity_end_max = 0, ti_gravity_beg_max = 0; - integertime_t ti_stars_end_min = max_nr_timesteps; + integertime_t ti_stars_end_min = max_nr_timesteps, ti_stars_end_max = 0, + ti_stars_beg_max = 0; struct part *parts = c->hydro.parts; struct gpart *gparts = c->grav.parts; struct spart *sparts = c->stars.parts; @@ -2771,6 +2773,8 @@ void space_split_recursive(struct space *s, struct cell *c, ti_gravity_end_max = max(ti_gravity_end_max, cp->grav.ti_end_max); ti_gravity_beg_max = max(ti_gravity_beg_max, cp->grav.ti_beg_max); ti_stars_end_min = min(ti_stars_end_min, cp->stars.ti_end_min); + ti_stars_end_max = min(ti_stars_end_max, cp->stars.ti_end_max); + ti_stars_beg_max = min(ti_stars_beg_max, cp->stars.ti_beg_max); /* Increase the depth */ if (cp->maxdepth > maxdepth) maxdepth = cp->maxdepth; @@ -2999,6 +3003,8 @@ void space_split_recursive(struct space *s, struct cell *c, c->grav.ti_end_max = ti_gravity_end_max; c->grav.ti_beg_max = ti_gravity_beg_max; c->stars.ti_end_min = ti_stars_end_min; + c->stars.ti_end_max = ti_stars_end_max; + c->stars.ti_beg_max = ti_stars_beg_max; c->stars.h_max = stars_h_max; c->maxdepth = maxdepth;