From 399b5a1a7fe84a364c23b75264fbf6a4bf4aa5ad Mon Sep 17 00:00:00 2001
From: Matthieu Schaller <schaller@strw.leidenuniv.nl>
Date: Sat, 15 Sep 2018 16:55:09 +0200
Subject: [PATCH] Only attempt to allocate the gravity mesh on restart if we
 are running with periodic BCs.

---
 src/mesh_gravity.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/mesh_gravity.c b/src/mesh_gravity.c
index 182e4fdd9c..3b3f495e78 100644
--- a/src/mesh_gravity.c
+++ b/src/mesh_gravity.c
@@ -686,15 +686,18 @@ void pm_mesh_struct_restore(struct pm_mesh* mesh, FILE* stream) {
 
   restart_read_blocks((void*)mesh, sizeof(struct pm_mesh), 1, stream, NULL,
                       "gravity props");
-#ifdef HAVE_FFTW
-  const int N = mesh->N;
 
-  /* Allocate the memory for the combined density and potential array */
-  mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N);
-  if (mesh->potential == NULL)
-    error("Error allocating memory for the long-range gravity mesh.");
+  if (mesh->periodic) {
+
+#ifdef HAVE_FFTW
+    const int N = mesh->N;
 
+    /* Allocate the memory for the combined density and potential array */
+    mesh->potential = (double*)fftw_malloc(sizeof(double) * N * N * N);
+    if (mesh->potential == NULL)
+      error("Error allocating memory for the long-range gravity mesh.");
 #else
-  error("No FFTW library found. Cannot compute periodic long-range forces.");
+    error("No FFTW library found. Cannot compute periodic long-range forces.");
 #endif
+  }
 }
-- 
GitLab