From 200c0d609782207c9033e77c227dde8639190c53 Mon Sep 17 00:00:00 2001
From: James Willis <james.s.willis@durham.ac.uk>
Date: Tue, 7 Nov 2017 13:47:07 +0000
Subject: [PATCH] Make sure that the correct indices are set in max_index
 arrays.

---
 src/runner_doiact_vec.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/runner_doiact_vec.c b/src/runner_doiact_vec.c
index 2781f6ea27..4dc3a8dcf6 100644
--- a/src/runner_doiact_vec.c
+++ b/src/runner_doiact_vec.c
@@ -322,7 +322,12 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
       max_index_i[ci->count - 1] = 0;
     }
   }
-  else first_pi = ci->count - 1; 
+  else {
+    /* Make sure that foreign cells are only read into the cache if the local cell requires it. 
+     * Also ensure that it does not require any particles from cj. */
+    first_pi = ci->count - 1; 
+    max_index_i[ci->count - 1] = 0;
+  }
 
   if(cj_local) {
     /* Find the rightmost active particle in cell j that interacts with any
@@ -370,7 +375,12 @@ __attribute__((always_inline)) INLINE static void populate_max_index_no_cache(
       max_index_j[0] = ci->count - 1;
     }
   }
-  else last_pj = 0;
+  else {
+    /* Make sure that foreign cells are only read into the cache if the local cell requires it. 
+     * Also ensure that it does not require any particles from ci. */
+    last_pj = 0;
+    max_index_j[0] = ci->count - 1;
+  }
 
   *init_pi = first_pi;
   *init_pj = last_pj;
-- 
GitLab