Commit 027223b6 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Merge branch 'star_formation_sort_task' into 'master'

Split the star formation task into two parts

See merge request !844
parents 8dcd4ac0 c0d792d8
......@@ -3408,6 +3408,7 @@ int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s) {
if (c->top->hydro.star_formation != NULL) {
scheduler_activate(s, c->top->hydro.star_formation);
scheduler_activate(s, c->top->hydro.stars_resort);
cell_activate_drift_spart(c, s);
}
}
......@@ -3561,13 +3562,6 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) {
if (c->grav.long_range != NULL) scheduler_activate(s, c->grav.long_range);
if (c->grav.end_force != NULL) scheduler_activate(s, c->grav.end_force);
if (c->logger != NULL) scheduler_activate(s, c->logger);
/* Subgrid tasks */
if ((e->policy & engine_policy_cooling) && c->hydro.cooling != NULL)
scheduler_activate(s, c->hydro.cooling);
if ((e->policy & engine_policy_star_formation) &&
c->hydro.star_formation != NULL)
scheduler_activate(s, c->hydro.star_formation);
}
return rebuild;
......
......@@ -288,7 +288,8 @@ enum cell_flags {
cell_flag_do_stars_drift = (1UL << 9),
cell_flag_do_stars_sub_drift = (1UL << 10),
cell_flag_do_bh_drift = (1UL << 11),
cell_flag_do_bh_sub_drift = (1UL << 12)
cell_flag_do_bh_sub_drift = (1UL << 12),
cell_flag_do_stars_resort = (1UL << 13)
};
/**
......@@ -377,6 +378,9 @@ struct cell {
/*! Task for star formation */
struct task *star_formation;
/*! Task for sorting the stars again after a SF event */
struct task *stars_resort;
/*! Max smoothing length in this cell. */
double h_max;
......
......@@ -774,6 +774,9 @@ void engine_make_hierarchical_tasks_common(struct engine *e, struct cell *c) {
if (with_star_formation && c->hydro.count > 0) {
c->hydro.star_formation = scheduler_addtask(
s, task_type_star_formation, task_subtype_none, 0, 0, c, NULL);
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);
}
}
......@@ -1074,8 +1077,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, c->top->hydro.star_formation,
c->stars.stars_in);
scheduler_addunlock(s, c->top->hydro.stars_resort, c->stars.stars_in);
}
}
......
......@@ -919,7 +919,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
}
/* Subgrid tasks: star formation */
else if (t_type == task_type_star_formation) {
else if (t_type == task_type_star_formation ||
t_type == task_type_stars_resort) {
if (cell_is_active_hydro(t->ci, e)) {
scheduler_activate(s, t);
cell_activate_super_spart_drifts(t->ci, s);
......
......@@ -1211,14 +1211,41 @@ void runner_do_star_formation(struct runner *r, struct cell *c, int timer) {
* re-compute them. */
if (with_feedback && (c == c->top) &&
(current_stars_count != c->stars.count)) {
cell_set_flag(c, cell_flag_do_stars_resort);
cell_clear_stars_sort_flags(c, /*clear_unused_flags=*/0);
runner_do_all_stars_sort(r, c);
}
if (timer) TIMER_TOC(timer_do_star_formation);
}
/**
* @brief Sorts again all the stars in a given cell hierarchy.
*
* This is intended to be used after the star formation task has been run
* to get the cells back into a state where self/pair star tasks can be run.
*
* @param r The thread #runner.
* @param c The top-level cell to run on.
* @param timer Are we timing this?
*/
void runner_do_stars_resort(struct runner *r, struct cell *c, const int timer) {
#ifdef SWIFT_DEBUG_CHECKS
if (c->nodeID != r->e->nodeID) error("Task must be run locally!");
if (c->depth != 0) error("Task must be run at the top-level");
#endif
TIMER_TIC;
/* Did we demand a recalculation of the stars'sorts? */
if (cell_get_flag(c, cell_flag_do_stars_resort)) {
runner_do_all_stars_sort(r, c);
cell_clear_flag(c, cell_flag_do_stars_resort);
}
if (timer) TIMER_TOC(timer_do_stars_resort);
}
/**
* @brief Sort the entries in ascending order using QuickSort.
*
......@@ -4602,6 +4629,9 @@ void *runner_main(void *data) {
case task_type_star_formation:
runner_do_star_formation(r, t->ci, 1);
break;
case task_type_stars_resort:
runner_do_stars_resort(r, t->ci, 1);
break;
case task_type_fof_self:
runner_do_fof_self(r, t->ci, 1);
break;
......
......@@ -228,6 +228,8 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements,
c->hydro.ghost_in = NULL;
c->hydro.ghost_out = NULL;
c->hydro.ghost = NULL;
c->hydro.star_formation = NULL;
c->hydro.stars_resort = NULL;
c->stars.ghost = NULL;
c->stars.density = NULL;
c->stars.feedback = NULL;
......
......@@ -89,6 +89,7 @@ const char *taskID_names[task_type_count] = {"none",
"stars_ghost",
"stars_ghost_out",
"stars_sort",
"stars_resort",
"bh_in",
"bh_out",
"bh_density_ghost",
......@@ -172,6 +173,7 @@ __attribute__((always_inline)) INLINE static enum task_actions task_acts_on(
case task_type_drift_spart:
case task_type_stars_ghost:
case task_type_stars_sort:
case task_type_stars_resort:
return task_action_spart;
break;
......@@ -431,6 +433,7 @@ void task_unlock(struct task *t) {
break;
case task_type_stars_sort:
case task_type_stars_resort:
cell_sunlocktree(ci);
break;
......@@ -565,6 +568,7 @@ int task_lock(struct task *t) {
break;
case task_type_stars_sort:
case task_type_stars_resort:
if (ci->stars.hold) return 0;
if (cell_slocktree(ci) != 0) return 0;
break;
......
......@@ -84,6 +84,7 @@ enum task_types {
task_type_stars_ghost,
task_type_stars_ghost_out, /* Implicit */
task_type_stars_sort,
task_type_stars_resort,
task_type_bh_in, /* Implicit */
task_type_bh_out, /* Implicit */
task_type_bh_density_ghost,
......
......@@ -107,6 +107,7 @@ enum {
timer_step,
timer_logger,
timer_do_stars_sort,
timer_do_stars_resort,
timer_fof_self,
timer_fof_pair,
timer_count,
......
......@@ -104,6 +104,7 @@ TASKTYPES = [
"stars_ghost",
"stars_ghost_out",
"stars_sort",
"stars_resort",
"bh_in",
"bh_out",
"bh_ghost",
......
......@@ -189,6 +189,7 @@ TASKTYPES = [
"stars_ghost",
"stars_ghost_out",
"stars_sort",
"stars_resort",
"bh_in",
"bh_out",
"bh_ghost",
......
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