From b35e512601b9f90cbc00182541617faba3898303 Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <matthieu.schaller@durham.ac.uk>
Date: Fri, 1 Sep 2017 12:57:38 +0100
Subject: [PATCH] Prevent floating point excetion involving the padded gravity
 caches

---
 src/gravity_cache.h      |  8 ++++----
 src/runner_doiact_grav.h | 12 ++++++------
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/gravity_cache.h b/src/gravity_cache.h
index 14b672233a..b9fde71dd8 100644
--- a/src/gravity_cache.h
+++ b/src/gravity_cache.h
@@ -131,7 +131,7 @@ static INLINE void gravity_cache_init(struct gravity_cache *c, int count) {
  */
 __attribute__((always_inline)) INLINE void gravity_cache_populate(
     struct gravity_cache *c, const struct gpart *restrict gparts, int gcount,
-    int gcount_padded, const double shift[3]) {
+    int gcount_padded, const double shift[3], const struct cell *cell) {
 
   /* Make the compiler understand we are in happy vectorization land */
   float *restrict x = c->x;
@@ -161,9 +161,9 @@ __attribute__((always_inline)) INLINE void gravity_cache_populate(
 
   /* Pad the caches */
   for (int i = gcount; i < gcount_padded; ++i) {
-    x[i] = 0.f;
-    y[i] = 0.f;
-    z[i] = 0.f;
+    x[i] = -3.f * cell->width[0];
+    y[i] = -3.f * cell->width[0];
+    z[i] = -3.f * cell->width[0];
     epsilon[i] = 0.f;
     m[i] = 0.f;
   }
diff --git a/src/runner_doiact_grav.h b/src/runner_doiact_grav.h
index 01ea6a0732..69f821f0a9 100644
--- a/src/runner_doiact_grav.h
+++ b/src/runner_doiact_grav.h
@@ -194,9 +194,9 @@ void runner_dopair_grav_pp_full(struct runner *r, struct cell *ci,
 
   /* Fill the caches */
   gravity_cache_populate(ci_cache, gparts_i, gcount_i, gcount_padded_i,
-                         loc_mean);
+                         loc_mean, ci);
   gravity_cache_populate(cj_cache, gparts_j, gcount_j, gcount_padded_j,
-                         loc_mean);
+                         loc_mean, cj);
 
   /* Ok... Here we go ! */
 
@@ -542,9 +542,9 @@ void runner_dopair_grav_pp_truncated(struct runner *r, struct cell *ci,
 
   /* Fill the caches */
   gravity_cache_populate(ci_cache, gparts_i, gcount_i, gcount_padded_i,
-                         loc_mean);
+                         loc_mean, ci);
   gravity_cache_populate(cj_cache, gparts_j, gcount_j, gcount_padded_j,
-                         loc_mean);
+                         loc_mean, cj);
 
   /* Ok... Here we go ! */
 
@@ -941,7 +941,7 @@ void runner_doself_grav_pp_full(struct runner *r, struct cell *c) {
   /* Computed the padded counts */
   const int gcount_padded = gcount - (gcount % VEC_SIZE) + VEC_SIZE;
 
-  gravity_cache_populate(ci_cache, gparts, gcount, gcount_padded, loc);
+  gravity_cache_populate(ci_cache, gparts, gcount, gcount_padded, loc, c);
 
   /* Ok... Here we go ! */
 
@@ -1155,7 +1155,7 @@ void runner_doself_grav_pp_truncated(struct runner *r, struct cell *c) {
   /* Computed the padded counts */
   const int gcount_padded = gcount - (gcount % VEC_SIZE) + VEC_SIZE;
 
-  gravity_cache_populate(ci_cache, gparts, gcount, gcount_padded, loc);
+  gravity_cache_populate(ci_cache, gparts, gcount, gcount_padded, loc, c);
 
   /* Ok... Here we go ! */
 
-- 
GitLab