From 4debd3c46939741cec6e66410b504d8c975fa31d Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Tue, 8 Nov 2016 12:09:39 +0000
Subject: [PATCH] Only sort particles in top-level cells if you have particles

---
 src/space.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/space.c b/src/space.c
index 645dda1844..f88e2450da 100644
--- a/src/space.c
+++ b/src/space.c
@@ -600,7 +600,7 @@ void space_rebuild(struct space *s, int verbose) {
 #endif /* WITH_MPI */
 
   /* Sort the parts according to their cells. */
-  space_parts_sort(s, ind, nr_parts, 0, s->nr_cells - 1, verbose);
+  if(nr_parts > 0) space_parts_sort(s, ind, nr_parts, 0, s->nr_cells - 1, verbose);
 
   /* Re-link the gparts. */
   if (nr_parts > 0 && nr_gparts > 0) part_relink_gparts(s->parts, nr_parts, 0);
@@ -660,7 +660,7 @@ void space_rebuild(struct space *s, int verbose) {
 #endif
 
   /* Sort the gparts according to their cells. */
-  space_gparts_sort(s, gind, nr_gparts, 0, s->nr_cells - 1, verbose);
+  if(nr_gparts > 0) space_gparts_sort(s, gind, nr_gparts, 0, s->nr_cells - 1, verbose);
 
   /* Re-link the parts. */
   if (nr_parts > 0 && nr_gparts > 0)
-- 
GitLab