From 82e9ddbc93dbe3285776a77392a4d4a997a19abc Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Wed, 15 Aug 2018 14:03:57 +0100
Subject: [PATCH] Do not link the M-M tasks in with the other gravity pair
 tasks.

---
 src/active.h    | 2 +-
 src/cell.c      | 2 +-
 src/cell.h      | 3 +++
 src/engine.c    | 2 +-
 src/scheduler.c | 4 ++--
 src/space.c     | 1 +
 6 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/active.h b/src/active.h
index 3fe52a86b3..d53c2fcce7 100644
--- a/src/active.h
+++ b/src/active.h
@@ -129,7 +129,7 @@ __attribute__((always_inline)) INLINE static int cell_is_active_gravity(
     const struct cell *c, const struct engine *e) {
 
 #ifdef SWIFT_DEBUG_CHECKS
-  if (c->ti_gravity_end_min < e->ti_current)
+  if (c->ti_gravity_end_min < e->ti_current && c->nr_tasks > 0)
     error(
         "cell in an impossible time-zone! c->ti_end_min=%lld (t=%e) and "
         "e->ti_current=%lld (t=%e, a=%e)",
diff --git a/src/cell.c b/src/cell.c
index eba2ee675b..8ca6771a43 100644
--- a/src/cell.c
+++ b/src/cell.c
@@ -2381,7 +2381,7 @@ int cell_unskip_gravity_tasks(struct cell *c, struct scheduler *s) {
 void cell_set_super(struct cell *c, struct cell *super) {
 
   /* Are we in a cell with some kind of self/pair task ? */
-  if (super == NULL && c->nr_tasks > 0) super = c;
+  if (super == NULL && (c->nr_tasks > 0 || c->nr_mm_tasks > 0)) super = c;
 
   /* Set the super-cell */
   c->super = super;
diff --git a/src/cell.h b/src/cell.h
index 534f9d704d..ed017d2d11 100644
--- a/src/cell.h
+++ b/src/cell.h
@@ -428,6 +428,9 @@ struct cell {
   /*! Number of tasks that are associated with this cell. */
   short int nr_tasks;
 
+  /*! Number of M-M tasks that are associated with this cell. */
+  short int nr_mm_tasks;
+
   /*! The depth of this cell in the tree. */
   char depth;
 
diff --git a/src/engine.c b/src/engine.c
index 6a840379fc..93c033d0c3 100644
--- a/src/engine.c
+++ b/src/engine.c
@@ -4757,7 +4757,7 @@ void engine_step(struct engine *e) {
   e->min_active_bin = get_min_active_bin(e->ti_current, e->ti_old);
   e->step += 1;
   e->step_props = engine_step_prop_none;
-
+  
   /* When restarting, move everyone to the current time. */
   if (e->restarting) engine_drift_all(e);
 
diff --git a/src/scheduler.c b/src/scheduler.c
index 8204351c2b..16e627f27a 100644
--- a/src/scheduler.c
+++ b/src/scheduler.c
@@ -895,8 +895,8 @@ static void scheduler_splittask_gravity(struct task *t, struct scheduler *s) {
         t->subtype = task_subtype_none;
 
         /* Since this task will not be split, we can already link it */
-        atomic_inc(&ci->nr_tasks);
-        atomic_inc(&cj->nr_tasks);
+        atomic_inc(&ci->nr_mm_tasks);
+        atomic_inc(&cj->nr_mm_tasks);
         engine_addlink(e, &ci->grav_mm, t);
         engine_addlink(e, &cj->grav_mm, t);
         break;
diff --git a/src/space.c b/src/space.c
index caf7795536..81efe99847 100644
--- a/src/space.c
+++ b/src/space.c
@@ -164,6 +164,7 @@ void space_rebuild_recycle_mapper(void *map_data, int num_elements,
                          multipole_rec_end);
     c->sorts = NULL;
     c->nr_tasks = 0;
+    c->nr_mm_tasks = 0;
     c->density = NULL;
     c->gradient = NULL;
     c->force = NULL;
-- 
GitLab