From 94745b29ed9d8652b4f554d27fed1ecc6795750b Mon Sep 17 00:00:00 2001
From: Cristian C Lalescu <Cristian.Lalescu@ds.mpg.de>
Date: Fri, 5 Mar 2021 10:31:39 +0100
Subject: [PATCH] reduces p2p buffer usage

---
 cpp/field.cpp                       | 12 ++++++------
 cpp/particles/p2p/p2p_distr_mpi.hpp |  3 +++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/cpp/field.cpp b/cpp/field.cpp
index 92f5afb1..f64cdfcf 100644
--- a/cpp/field.cpp
+++ b/cpp/field.cpp
@@ -110,9 +110,9 @@ field<rnumber, be, fc>::field(
                     this->data,
                     this->comm,
                     this->fftw_plan_rigor | FFTW_MPI_TRANSPOSED_IN);
-            plan_information = fftw_interface<rnumber>::sprint(this->c2r_plan);
-            DEBUG_MSG("field::field c2r plan representation is\n\%s\n", plan_information);
-            free(plan_information);
+            //plan_information = fftw_interface<rnumber>::sprint(this->c2r_plan);
+            //DEBUG_MSG("field::field c2r plan representation is\n\%s\n", plan_information);
+            //free(plan_information);
             this->r2c_plan = fftw_interface<rnumber>::mpi_plan_many_dft_r2c(
                     3, nfftw, ncomp(fc),
                     FFTW_MPI_DEFAULT_BLOCK, FFTW_MPI_DEFAULT_BLOCK,
@@ -120,9 +120,9 @@ field<rnumber, be, fc>::field(
                     (typename fftw_interface<rnumber>::complex*)this->data,
                     this->comm,
                     this->fftw_plan_rigor | FFTW_MPI_TRANSPOSED_OUT);
-            plan_information = fftw_interface<rnumber>::sprint(this->r2c_plan);
-            DEBUG_MSG("field::field r2c plan representation is\n\%s\n", plan_information);
-            free(plan_information);
+            //plan_information = fftw_interface<rnumber>::sprint(this->r2c_plan);
+            //DEBUG_MSG("field::field r2c plan representation is\n\%s\n", plan_information);
+            //free(plan_information);
             break;
     }
     // use Fourier representation for setting field to 0,
diff --git a/cpp/particles/p2p/p2p_distr_mpi.hpp b/cpp/particles/p2p/p2p_distr_mpi.hpp
index 6639fb70..e1d596e0 100644
--- a/cpp/particles/p2p/p2p_distr_mpi.hpp
+++ b/cpp/particles/p2p/p2p_distr_mpi.hpp
@@ -128,6 +128,9 @@ protected:
                 data[destData*sizeElement + idxVal]
                         = dataBuffer[srcData*sizeElement + idxVal];
             }
+
+        // Clean up memory
+        buffer->resize(0);
         }
 
         buffer->resize(0);
-- 
GitLab