Commit 857df4fe authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Add finer control of the stars' time-steps.

parent 3f28bc56
...@@ -390,6 +390,29 @@ __attribute__((always_inline)) INLINE static int cell_is_starting_gravity( ...@@ -390,6 +390,29 @@ __attribute__((always_inline)) INLINE static int cell_is_starting_gravity(
return (c->grav.ti_beg_max == e->ti_current); 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 ? * @brief Is this particle starting its time-step now ?
* *
......
...@@ -387,6 +387,7 @@ int cell_pack(struct cell *restrict c, struct pcell *restrict pc, ...@@ -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_min = c->grav.ti_end_min;
pc->grav.ti_end_max = c->grav.ti_end_max; pc->grav.ti_end_max = c->grav.ti_end_max;
pc->stars.ti_end_min = c->stars.ti_end_min; 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->hydro.ti_old_part = c->hydro.ti_old_part;
pc->grav.ti_old_part = c->grav.ti_old_part; pc->grav.ti_old_part = c->grav.ti_old_part;
pc->grav.ti_old_multipole = c->grav.ti_old_multipole; 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, ...@@ -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_min = pc->grav.ti_end_min;
c->grav.ti_end_max = pc->grav.ti_end_max; c->grav.ti_end_max = pc->grav.ti_end_max;
c->stars.ti_end_min = pc->stars.ti_end_min; 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->hydro.ti_old_part = pc->hydro.ti_old_part;
c->grav.ti_old_part = pc->grav.ti_old_part; c->grav.ti_old_part = pc->grav.ti_old_part;
c->grav.ti_old_multipole = pc->grav.ti_old_multipole; c->grav.ti_old_multipole = pc->grav.ti_old_multipole;
...@@ -623,6 +625,7 @@ int cell_pack_end_step(struct cell *restrict c, ...@@ -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_min = c->grav.ti_end_min;
pcells[0].grav.ti_end_max = c->grav.ti_end_max; 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_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].hydro.dx_max_part = c->hydro.dx_max_part;
pcells[0].stars.dx_max_part = c->stars.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, ...@@ -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_min = pcells[0].grav.ti_end_min;
c->grav.ti_end_max = pcells[0].grav.ti_end_max; 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_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->hydro.dx_max_part = pcells[0].hydro.dx_max_part;
c->stars.dx_max_part = pcells[0].stars.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) { ...@@ -3400,6 +3404,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) {
* @return 1 If the space needs rebuilding. 0 otherwise. * @return 1 If the space needs rebuilding. 0 otherwise.
*/ */
int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) { int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) {
struct engine *e = s->space->e; struct engine *e = s->space->e;
const int nodeID = e->nodeID; const int nodeID = e->nodeID;
int rebuild = 0; int rebuild = 0;
...@@ -3559,6 +3564,7 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) { ...@@ -3559,6 +3564,7 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) {
/* Unskip all the other task types. */ /* Unskip all the other task types. */
if (c->nodeID == nodeID && cell_is_active_stars(c, e)) { 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.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_in != NULL) scheduler_activate(s, c->stars.stars_in);
if (c->stars.stars_out != NULL) scheduler_activate(s, c->stars.stars_out); if (c->stars.stars_out != NULL) scheduler_activate(s, c->stars.stars_out);
......
...@@ -150,6 +150,9 @@ struct pcell { ...@@ -150,6 +150,9 @@ struct pcell {
/*! Minimal integer end-of-timestep in this cell for stars tasks */ /*! Minimal integer end-of-timestep in this cell for stars tasks */
integertime_t ti_end_min; 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 */ /*! Integer time of the last drift of the #spart in this cell */
integertime_t ti_old_part; integertime_t ti_old_part;
...@@ -201,12 +204,15 @@ struct pcell_step { ...@@ -201,12 +204,15 @@ struct pcell_step {
/*! Stars variables */ /*! Stars variables */
struct { struct {
/*! Maximal distance any #part has travelled since last rebuild */
float dx_max_part;
/*! Minimal integer end-of-timestep in this cell (stars) */ /*! Minimal integer end-of-timestep in this cell (stars) */
integertime_t ti_end_min; 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; } stars;
}; };
...@@ -542,6 +548,13 @@ struct cell { ...@@ -542,6 +548,13 @@ struct cell {
/*! Maximum end of (integer) time step in this cell for gravity tasks. */ /*! Maximum end of (integer) time step in this cell for gravity tasks. */
integertime_t ti_end_min; 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. */ /*! Number of #spart updated in this cell. */
int updated; int updated;
......
...@@ -384,7 +384,7 @@ void engine_addtasks_recv_hydro(struct engine *e, struct cell *c, ...@@ -384,7 +384,7 @@ void engine_addtasks_recv_hydro(struct engine *e, struct cell *c,
/* Add dependencies. */ /* Add dependencies. */
if (c->hydro.sorts != NULL) scheduler_addunlock(s, t_xv, c->hydro.sorts); 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) { for (struct link *l = c->hydro.density; l != NULL; l = l->next) {
scheduler_addunlock(s, t_xv, l->t); 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, ...@@ -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) { void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) {
struct scheduler *s = &e->sched; 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_feedback = (e->policy & engine_policy_feedback);
const int with_cooling = (e->policy & engine_policy_cooling); const int with_cooling = (e->policy & engine_policy_cooling);
const int with_star_formation = (e->policy & engine_policy_star_formation); 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) { ...@@ -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); s, task_type_extra_ghost, task_subtype_none, 0, 0, c, NULL);
#endif #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 */ /* Subgrid tasks: cooling */
if (with_cooling) { if (with_cooling) {
...@@ -897,8 +907,6 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) { ...@@ -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, scheduler_addtask(s, task_type_stars_out, task_subtype_none, 0,
/* implicit = */ 1, c, NULL); /* 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, c->stars.ghost = scheduler_addtask(s, task_type_stars_ghost,
task_subtype_none, 0, 0, c, NULL); task_subtype_none, 0, 0, c, NULL);
......
...@@ -1816,7 +1816,7 @@ void runner_do_kick1(struct runner *r, struct cell *c, int timer) { ...@@ -1816,7 +1816,7 @@ void runner_do_kick1(struct runner *r, struct cell *c, int timer) {
TIMER_TIC; TIMER_TIC;
/* Anything to do here? */ /* 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? */ /* Recurse? */
if (c->split) { if (c->split) {
...@@ -1998,7 +1998,7 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) { ...@@ -1998,7 +1998,7 @@ void runner_do_kick2(struct runner *r, struct cell *c, int timer) {
TIMER_TIC; TIMER_TIC;
/* Anything to do here? */ /* 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? */ /* Recurse? */
if (c->split) { if (c->split) {
...@@ -2205,7 +2205,8 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ...@@ -2205,7 +2205,8 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) {
ti_hydro_beg_max = 0; ti_hydro_beg_max = 0;
integertime_t ti_gravity_end_min = max_nr_timesteps, ti_gravity_end_max = 0, integertime_t ti_gravity_end_min = max_nr_timesteps, ti_gravity_end_max = 0,
ti_gravity_beg_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? */ /* No children? */
if (!c->split) { if (!c->split) {
...@@ -2383,13 +2384,13 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ...@@ -2383,13 +2384,13 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) {
s_updated++; s_updated++;
g_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_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 ? */ /* What is the next starting point for this cell ? */
ti_stars_beg_max = max(ti_current, ti_stars_beg_max);
ti_gravity_beg_max = max(ti_current, ti_gravity_beg_max); ti_gravity_beg_max = max(ti_current, ti_gravity_beg_max);
/* star particle is inactive but not inhibited */ /* star particle is inactive but not inhibited */
...@@ -2401,23 +2402,23 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ...@@ -2401,23 +2402,23 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) {
const integertime_t ti_end = const integertime_t ti_end =
get_integer_time_end(ti_current, sp->time_bin); get_integer_time_end(ti_current, sp->time_bin);
/* What is the next sync-point ? */ 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_min = min(ti_end, ti_gravity_end_min);
ti_gravity_end_max = max(ti_end, ti_gravity_end_max); ti_gravity_end_max = max(ti_end, ti_gravity_end_max);
ti_stars_end_min = min(ti_end, ti_stars_end_min);
const integertime_t ti_beg = 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 ? */ /* What is the next starting point for this cell ? */
ti_stars_beg_max = max(ti_beg, ti_stars_beg_max);
ti_gravity_beg_max = max(ti_beg, ti_gravity_beg_max); ti_gravity_beg_max = max(ti_beg, ti_gravity_beg_max);
} }
} }
} else { } else {
/* Loop over the progeny. */ /* Loop over the progeny. */
for (int k = 0; k < 8; k++) for (int k = 0; k < 8; k++) {
if (c->progeny[k] != NULL) { if (c->progeny[k] != NULL) {
struct cell *restrict cp = c->progeny[k]; struct cell *restrict cp = c->progeny[k];
...@@ -2438,6 +2439,9 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ...@@ -2438,6 +2439,9 @@ 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_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_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_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);
}
} }
} }
...@@ -2455,6 +2459,8 @@ void runner_do_timestep(struct runner *r, struct cell *c, int timer) { ...@@ -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_end_max = ti_gravity_end_max;
c->grav.ti_beg_max = ti_gravity_beg_max; c->grav.ti_beg_max = ti_gravity_beg_max;
c->stars.ti_end_min = ti_stars_end_min; 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 #ifdef SWIFT_DEBUG_CHECKS
if (c->hydro.ti_end_min == e->ti_current && if (c->hydro.ti_end_min == e->ti_current &&
......
...@@ -253,6 +253,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements, ...@@ -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_min = -1;
c->grav.ti_end_max = -1; c->grav.ti_end_max = -1;
c->stars.ti_end_min = -1; c->stars.ti_end_min = -1;
c->stars.ti_end_max = -1;
#ifdef SWIFT_DEBUG_CHECKS #ifdef SWIFT_DEBUG_CHECKS
c->cellID = 0; c->cellID = 0;
#endif #endif
...@@ -2599,7 +2600,8 @@ void space_split_recursive(struct space *s, struct cell *c, ...@@ -2599,7 +2600,8 @@ void space_split_recursive(struct space *s, struct cell *c,
ti_hydro_beg_max = 0; ti_hydro_beg_max = 0;
integertime_t ti_gravity_end_min = max_nr_timesteps, ti_gravity_end_max = 0, integertime_t ti_gravity_end_min = max_nr_timesteps, ti_gravity_end_max = 0,
ti_gravity_beg_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 part *parts = c->hydro.parts;
struct gpart *gparts = c->grav.parts; struct gpart *gparts = c->grav.parts;
struct spart *sparts = c->stars.parts; struct spart *sparts = c->stars.parts;
...@@ -2771,6 +2773,8 @@ void space_split_recursive(struct space *s, struct cell *c, ...@@ -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_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_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_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 */ /* Increase the depth */
if (cp->maxdepth > maxdepth) maxdepth = cp->maxdepth; if (cp->maxdepth > maxdepth) maxdepth = cp->maxdepth;
...@@ -2999,6 +3003,8 @@ void space_split_recursive(struct space *s, struct cell *c, ...@@ -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_end_max = ti_gravity_end_max;
c->grav.ti_beg_max = ti_gravity_beg_max; c->grav.ti_beg_max = ti_gravity_beg_max;
c->stars.ti_end_min = ti_stars_end_min; 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->stars.h_max = stars_h_max;
c->maxdepth = maxdepth; c->maxdepth = maxdepth;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment