From 5f098ac22e2e4ce93a825f05891987d86c257034 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Sun, 31 Mar 2019 15:20:38 +0200
Subject: [PATCH] Correctly activate the feedback task over the network.

---
 src/cell.c             | 17 ++++++++++++++---
 src/engine_marktasks.c | 22 ++++++++++++++++++----
 2 files changed, 32 insertions(+), 7 deletions(-)

diff --git a/src/cell.c b/src/cell.c
index f8722eccc5..95e323307a 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -3574,12 +3574,23 @@ int cell_unskip_stars_tasks(struct cell *c, struct scheduler *s) {
     const int cj_nodeID = nodeID;
 #endif
 
-    if ((ci_active && cj_nodeID == nodeID) ||
-        (cj_active && ci_nodeID == nodeID)) {
+    /* We only want to activate the task if the cell is active and is
+       going to update some gas on the *local* node */
+    if ((ci_nodeID == nodeID && cj_nodeID == nodeID) &&
+        (ci_active || cj_active)) {
+
+      scheduler_activate(s, t);
+
+    } else if ((ci_nodeID == nodeID && cj_nodeID != nodeID) && (cj_active)) {
+
       scheduler_activate(s, t);
 
-      /* Nothing more to do here, all drifts and sorts activated above */
+    } else if ((ci_nodeID != nodeID && cj_nodeID == nodeID) && (ci_active)) {
+
+      scheduler_activate(s, t);
     }
+
+    /* Nothing more to do here, all drifts and sorts activated above */
   }
 
   /* Unskip all the other task types. */
diff --git a/src/engine_marktasks.c b/src/engine_marktasks.c
index 9b34b3ea95..277c956031 100644
--- a/src/engine_marktasks.c
+++ b/src/engine_marktasks.c
@@ -309,11 +309,25 @@ void engine_marktasks_mapper(void *map_data, int num_elements,
       }
 
       /* Stars feedback */
-      else if ((t_subtype == task_subtype_stars_feedback) &&
-               ((ci_active_stars && ci_nodeID == nodeID) ||
-                (cj_active_stars && cj_nodeID == nodeID))) {
+      else if (t_subtype == task_subtype_stars_feedback) {
 
-        scheduler_activate(s, t);
+        /* We only want to activate the task if the cell is active and is
+           going to update some gas on the *local* node */
+        if ((ci_nodeID == nodeID && cj_nodeID == nodeID) &&
+            (ci_active_stars || cj_active_stars)) {
+
+          scheduler_activate(s, t);
+
+        } else if ((ci_nodeID == nodeID && cj_nodeID != nodeID) &&
+                   (cj_active_stars)) {
+
+          scheduler_activate(s, t);
+
+        } else if ((ci_nodeID != nodeID && cj_nodeID == nodeID) &&
+                   (ci_active_stars)) {
+
+          scheduler_activate(s, t);
+        }
       }
 
       /* Gravity */
-- 
GitLab