From 696d43bfa9af8b3fb2a1a759654f4514a032e11a Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Mon, 25 Feb 2019 23:02:02 +0100
Subject: [PATCH] Early abort in the DOSELF1 for stars if there are no stars in
 the cell.

---
 src/cell.c                |  7 +------
 src/engine_maketasks.c    | 10 +++++++---
 src/runner.c              |  1 +
 src/runner_doiact_stars.h |  3 +++
 4 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index 00c106efcf..480bad5681 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -2120,13 +2120,9 @@ void cell_activate_stars_sorts(struct cell *c, int sid, struct scheduler *s) {
     }
   }
 
-  // message("c->stars.sorted=%d", c->stars.sorted);
-
   /* Has this cell been sorted at all for the given sid? */
   if (!(c->stars.sorted & (1 << sid)) || c->nodeID != engine_rank) {
 
-    // message("bbb");
-
     atomic_or(&c->stars.do_sort, (1 << sid));
     cell_activate_stars_sorts_up(c, s);
   }
@@ -3410,8 +3406,7 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) {
   const int nodeID = e->nodeID;
   int rebuild = 0;
 
-  if (!with_feedback && c->stars.drift != NULL && cell_is_active_stars(c, e) &&
-      c->nodeID == nodeID) {
+  if (!with_feedback && c->stars.drift != NULL && cell_is_active_stars(c, e)) {
     cell_activate_drift_spart(c, s);
   }
 
diff --git a/src/engine_maketasks.c b/src/engine_maketasks.c
index 233ebdd48d..b97244e426 100644
--- a/src/engine_maketasks.c
+++ b/src/engine_maketasks.c
@@ -848,7 +848,10 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) {
       if (with_stars) {
         c->stars.drift = scheduler_addtask(s, task_type_drift_spart,
                                            task_subtype_none, 0, 0, c, NULL);
-        scheduler_addunlock(s, c->stars.drift, c->super->kick2);
+
+        if (!with_feedback) {
+          scheduler_addunlock(s, c->stars.drift, c->super->kick2);
+        }
       }
 
       /* Subgrid tasks: cooling */
@@ -891,8 +894,9 @@ void engine_make_hierarchical_tasks_hydro(struct engine *e, struct cell *c) {
         scheduler_addunlock(s, c->super->kick2, c->stars.stars_in);
         scheduler_addunlock(s, c->stars.stars_out, c->super->timestep);
 
-        if (with_star_formation)
+        if (with_star_formation) {
           scheduler_addunlock(s, c->hydro.star_formation, c->stars.stars_in);
+        }
       }
     }
   } else { /* We are above the super-cell so need to go deeper */
@@ -2286,7 +2290,7 @@ void engine_maketasks(struct engine *e) {
 
   /* Free the old list of cell-task links. */
   if (e->links != NULL) free(e->links);
-  e->size_links = e->sched.nr_tasks * e->links_per_tasks * 2;
+  e->size_links = e->sched.nr_tasks * e->links_per_tasks;
 
   /* Make sure that we have space for more links than last time. */
   if (e->size_links < e->nr_links * engine_rebuild_link_alloc_margin)
diff --git a/src/runner.c b/src/runner.c
index ab92147c55..cfe3398684 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -1817,6 +1817,7 @@ void runner_do_unskip_mapper(void *map_data, int num_elements,
     }
   }
 }
+
 /**
  * @brief Drift all part in a cell.
  *
diff --git a/src/runner_doiact_stars.h b/src/runner_doiact_stars.h
index 98113db916..f208f14ac9 100644
--- a/src/runner_doiact_stars.h
+++ b/src/runner_doiact_stars.h
@@ -1013,6 +1013,9 @@ void DOSELF1_BRANCH_STARS(struct runner *r, struct cell *c) {
 
   const struct engine *restrict e = r->e;
 
+  /* Anything to do here? */
+  if (c->stars.count == 0) return;
+
   /* Anything to do here? */
   if (!cell_is_active_stars(c, e)) return;
 
-- 
GitLab