From 15d6e47ccaf0f77aadf5bec0bccd8424051920e9 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Sat, 4 May 2019 17:31:05 +0100
Subject: [PATCH] Pass the star formation flag to the star unskipping routines.

---
 src/cell.c             | 18 +++++++++++-------
 src/cell.h             |  5 +++--
 src/engine_marktasks.c |  6 +++---
 src/runner.c           | 11 +++++++----
 4 files changed, 24 insertions(+), 16 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 7bff8c163a..17059d0b42 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -2694,7 +2694,8 @@ void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
  * @param s The task #scheduler.
  */
 void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
-                                       struct scheduler *s) {
+                                       struct scheduler *s,
+				       const int with_star_formation) {
   const struct engine *e = s->space->e;
 
   /* Store the current dx_max and h_max values. */
@@ -2722,11 +2723,12 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
       /* Loop over all progenies and pairs of progenies */
       for (int j = 0; j < 8; j++) {
         if (ci->progeny[j] != NULL) {
-          cell_activate_subcell_stars_tasks(ci->progeny[j], NULL, s);
+          cell_activate_subcell_stars_tasks(ci->progeny[j], NULL, 
+					    s, with_star_formation);
           for (int k = j + 1; k < 8; k++)
             if (ci->progeny[k] != NULL)
               cell_activate_subcell_stars_tasks(ci->progeny[j], ci->progeny[k],
-                                                s);
+                                                s, with_star_formation);
         }
       }
     } else {
@@ -2754,7 +2756,7 @@ void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
         const int pjd = csp->pairs[k].pjd;
         if (ci->progeny[pid] != NULL && cj->progeny[pjd] != NULL)
           cell_activate_subcell_stars_tasks(ci->progeny[pid], cj->progeny[pjd],
-                                            s);
+                                            s, with_star_formation);
       }
     }
 
@@ -3453,7 +3455,9 @@ 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) {
+int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s, 
+			    const int with_star_formation) {
+
   struct engine *e = s->space->e;
   const int nodeID = e->nodeID;
   int rebuild = 0;
@@ -3529,11 +3533,11 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) {
       }
 
       else if (t->type == task_type_sub_self) {
-        cell_activate_subcell_stars_tasks(ci, NULL, s);
+        cell_activate_subcell_stars_tasks(ci, NULL, s, with_star_formation);
       }
 
       else if (t->type == task_type_sub_pair) {
-        cell_activate_subcell_stars_tasks(ci, cj, s);
+        cell_activate_subcell_stars_tasks(ci, cj, s, with_star_formation);
       }
     }
 
diff --git a/src/cell.h b/src/cell.h
index 1cc6b81e35..2b685bd23e 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -844,7 +844,8 @@ void cell_check_spart_drift_point(struct cell *c, void *data);
 void cell_check_multipole_drift_point(struct cell *c, void *data);
 void cell_reset_task_counters(struct cell *c);
 int cell_unskip_hydro_tasks(struct cell *c, struct scheduler *s);
-int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s);
+int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s,
+			    const int with_star_formation);
 int cell_unskip_black_holes_tasks(struct cell *c, struct scheduler *s);
 int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s);
 void cell_drift_part(struct cell *c, const struct engine *e, int force);
@@ -860,7 +861,7 @@ void cell_activate_subcell_hydro_tasks(struct cell *ci, struct cell *cj,
 void cell_activate_subcell_grav_tasks(struct cell *ci, struct cell *cj,
                                       struct scheduler *s);
 void cell_activate_subcell_stars_tasks(struct cell *ci, struct cell *cj,
-                                       struct scheduler *s);
+                                       struct scheduler *s, const int with_star_formation);
 void cell_activate_subcell_black_holes_tasks(struct cell *ci, struct cell *cj,
                                              struct scheduler *s);
 void cell_activate_subcell_external_grav_tasks(struct cell *ci,
diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c
index e38e2efc41..d7b2bdd534 100644
--- a/src/engine_marktasks.c
+++ b/src/engine_marktasks.c
@@ -70,8 +70,8 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
   struct engine *e = (struct engine *)((size_t *)extra_data)[0];
   const int nodeID = e->nodeID;
   const int with_limiter = e->policy & engine_policy_limiter;
-#ifdef WITH_MPI
   const int with_star_formation = e->policy & engine_policy_star_formation;
+#ifdef WITH_MPI
   const int with_feedback = e->policy & engine_policy_feedback;
 #endif
 
@@ -152,7 +152,7 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
                t_subtype == task_subtype_stars_density) {
         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, with_star_formation);
         }
       }
 
@@ -342,7 +342,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 &&
                  t_subtype == task_subtype_stars_density) {
-          cell_activate_subcell_stars_tasks(ci, cj, s);
+          cell_activate_subcell_stars_tasks(ci, cj, s, with_star_formation);
         }
       }
 
diff --git a/src/runner.c b/src/runner.c
index 8420153689..dc6b52c08c 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -2345,7 +2345,8 @@ static void runner_do_unskip_hydro(struct cell *c, struct engine *e) {
  * @param c The cell.
  * @param e The engine.
  */
-static void runner_do_unskip_stars(struct cell *c, struct engine *e) {
+static void runner_do_unskip_stars(struct cell *c, struct engine *e,
+				   const int with_star_formation) {
 
   /* Ignore empty cells. */
   if (c->stars.count == 0) return;
@@ -2358,13 +2359,13 @@ static void runner_do_unskip_stars(struct cell *c, struct engine *e) {
     for (int k = 0; k < 8; k++) {
       if (c->progeny[k] != NULL) {
         struct cell *cp = c->progeny[k];
-        runner_do_unskip_stars(cp, e);
+        runner_do_unskip_stars(cp, e, with_star_formation);
       }
     }
   }
 
   /* Unskip any active tasks. */
-  const int forcerebuild = cell_unskip_stars_tasks(c, &e->sched);
+  const int forcerebuild = cell_unskip_stars_tasks(c, &e->sched, with_star_formation);
   if (forcerebuild) atomic_inc(&e->forcerebuild);
 }
 
@@ -2436,6 +2437,7 @@ void runner_do_unskip_mapper(void *map_data, int num_elements,
                              void *extra_data) {
 
   struct engine *e = (struct engine *)extra_data;
+  const int with_star_formation = e->policy & engine_policy_star_formation;
   const int nodeID = e->nodeID;
   struct space *s = e->s;
   int *local_cells = (int *)map_data;
@@ -2453,7 +2455,8 @@ void runner_do_unskip_mapper(void *map_data, int num_elements,
         runner_do_unskip_gravity(c, e);
 
       /* Stars tasks */
-      if (e->policy & engine_policy_stars) runner_do_unskip_stars(c, e);
+      if (e->policy & engine_policy_stars) 
+	runner_do_unskip_stars(c, e, with_star_formation);
 
       /* Black hole tasks */
       if (e->policy & engine_policy_black_holes)
-- 
GitLab