From 12abbde01ac99fba731872f5206fdffe1a39f4d8 Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Sun, 2 Sep 2018 18:07:42 +0100
Subject: [PATCH] Only loop over local top level cells when performing the
 local FOF.

---
 src/fof.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/fof.c b/src/fof.c
index 9707d3c32a..580de4ab33 100644
--- a/src/fof.c
+++ b/src/fof.c
@@ -723,12 +723,12 @@ void fof_search_tree_mapper(void *map_data, int num_elements,
   struct space *s = (struct space *)extra_data;
   int *local_cells = (int *)map_data;
 
-  const size_t nr_cells = s->nr_cells;
+  const size_t nr_local_cells = s->nr_local_cells;
   const double dim[3] = {s->dim[0], s->dim[1], s->dim[2]};
   const double search_r2 = s->l_x2;
  
-  /* Make a list of cell offsets into the top-level cell array. */
-  int *const offset = s->cell_index + (ptrdiff_t)(&s->cells_top[local_cells[0]] - s->cells_top);
+  /* Make a list of cell offsets into the local top-level cell array. */
+  int *const offset = s->cell_index + (ptrdiff_t)(local_cells - s->local_cells_top);
 
   /* Loop over cells and find which cells are in range of each other to perform
    * the FOF search. */
@@ -748,9 +748,9 @@ void fof_search_tree_mapper(void *map_data, int num_elements,
 
       /* Loop over all top-level cells skipping over the cells already searched.
       */
-      for (size_t cjd = offset[ind] + 1; cjd < nr_cells; cjd++) {
+      for (size_t cjd = offset[ind] + 1; cjd < nr_local_cells; cjd++) {
 
-        struct cell *restrict cj = &s->cells_top[cjd];
+        struct cell *restrict cj = &s->cells_top[s->local_cells_top[cjd]];
 
         /* Only perform FOF search on local cells. */
         if(cj->nodeID == engine_rank) {
-- 
GitLab