From ca250f50e1361ed1d5c9987653cc2fe33ea2c025 Mon Sep 17 00:00:00 2001
From: Pedro Gonnet <gonnet@google.com>
Date: Thu, 6 Jul 2017 22:33:09 +0200
Subject: [PATCH] don't re-sort existing dimensions if no cleanup required.

---
 src/runner.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/runner.c b/src/runner.c
index 5b09b89898..aa22170b84 100644
--- a/src/runner.c
+++ b/src/runner.c
@@ -335,6 +335,11 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int cleanup,
 
   /* We need to do the local sorts plus whatever was requested further up. */
   flags |= c->do_sort;
+  if (cleanup) {
+    c->sorted = 0;
+  } else {
+    flags &= ~c->sorted;
+  }
   if (flags == 0 && !c->do_sub_sort) return;
 
   /* Check that the particles have been moved to the current time */
@@ -466,7 +471,8 @@ void runner_do_sort(struct runner *r, struct cell *c, int flags, int cleanup,
           xparts[k].x_diff_sort[2] = 0.0f;
         }
       }
-      c->dx_max_sort_old = c->dx_max_sort = 0.f;
+      c->dx_max_sort_old = 0.f;
+      c->dx_max_sort = 0.f;
     }
 
     /* Fill the sort array. */
-- 
GitLab