From fe9d5b80fbd3a18a8882757bb6901211a63119f4 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Mon, 18 Dec 2017 12:46:59 +0100
Subject: [PATCH] Restore correct dependencies between force loop and kick task
 when the extra hydro loop is activated.

---
 src/engine.c             | 24 ++++++++++++++++--------
 tests/testInteractions.c |  2 +-
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/src/engine.c b/src/engine.c
index f21c7cfc8a..fe04187cef 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -2656,7 +2656,6 @@ static inline void engine_make_hydro_loops_dependencies(
 
   /* density loop --> ghost --> gradient loop --> extra_ghost */
   /* extra_ghost --> force loop  */
-  scheduler_addunlock(sched, c->super_hydro->sorts, density);
   scheduler_addunlock(sched, density, c->super_hydro->ghost_in);
   scheduler_addunlock(sched, c->super_hydro->ghost_out, gradient);
   scheduler_addunlock(sched, gradient, c->super_hydro->extra_ghost);
@@ -2731,7 +2730,7 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
       /* Now, build all the dependencies for the hydro */
       engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
                                            with_cooling);
-
+      scheduler_addunlock(sched, t3, t->ci->super->kick2);
 #else
 
       /* Start by constructing the task for the second hydro loop */
@@ -2778,10 +2777,14 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
       if (t->ci->nodeID == nodeID) {
         engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
                                              with_cooling);
+        scheduler_addunlock(sched, t3, t->ci->super->kick2);
       }
-      if (t->cj->nodeID == nodeID && t->ci->super_hydro != t->cj->super_hydro) {
-        engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->cj,
-                                             with_cooling);
+      if (t->cj->nodeID == nodeID) {
+        if (t->ci->super_hydro != t->cj->super_hydro)
+          engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->cj,
+                                               with_cooling);
+        if (t->ci->super != t->cj->super)
+          scheduler_addunlock(sched, t3, t->cj->super->kick2);
       }
 
 #else
@@ -2839,6 +2842,7 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
       if (t->ci->nodeID == nodeID) {
         engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
                                              with_cooling);
+        scheduler_addunlock(sched, t3, t->ci->super->kick2);
       }
 
 #else
@@ -2895,10 +2899,14 @@ void engine_make_extra_hydroloop_tasks_mapper(void *map_data, int num_elements,
       if (t->ci->nodeID == nodeID) {
         engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->ci,
                                              with_cooling);
+        scheduler_addunlock(sched, t3, t->ci->super->kick2);
       }
-      if (t->cj->nodeID == nodeID && t->ci->super_hydro != t->cj->super_hydro) {
-        engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->cj,
-                                             with_cooling);
+      if (t->cj->nodeID == nodeID) {
+        if (t->ci->super_hydro != t->cj->super_hydro)
+          engine_make_hydro_loops_dependencies(sched, t, t2, t3, t->cj,
+                                               with_cooling);
+        if (t->ci->super != t->cj->super)
+          scheduler_addunlock(sched, t3, t->cj->super->kick2);
       }
 
 #else
diff --git a/tests/testInteractions.c b/tests/testInteractions.c
index 71d5728f67..76ee507881 100644
--- a/tests/testInteractions.c
+++ b/tests/testInteractions.c
@@ -673,7 +673,7 @@ int main(int argc, char *argv[]) {
         break;
       case 's':
         sscanf(optarg, "%lf", &spacing);
-	break;
+        break;
       case 'n':
         sscanf(optarg, "%zu", &count);
         break;
-- 
GitLab