From 66c79889640bdea5ba53f11b522728a968756f44 Mon Sep 17 00:00:00 2001
From: Cristian C Lalescu <Cristian.Lalescu@mpcdf.mpg.de>
Date: Thu, 3 Dec 2020 13:27:17 +0100
Subject: [PATCH] adds fftw plan printout message

---
 cpp/base.hpp               |  4 ++--
 cpp/fftw_interface.hpp     | 20 ++++++++++++++++++++
 cpp/field.cpp              |  7 +++++++
 cpp/field.hpp              | 30 ++++++++++++++++++++++++++++++
 cpp/vorticity_equation.cpp |  4 ++++
 5 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/cpp/base.hpp b/cpp/base.hpp
index 4604426c..4bbaa486 100644
--- a/cpp/base.hpp
+++ b/cpp/base.hpp
@@ -145,7 +145,7 @@ inline void DEBUG_MSG(const char * format, ...)
     va_start(argptr, format);
     sprintf(
             debug_message_buffer,
-            "cpu%.4d ",
+            "MPIrank%.4d ",
             myrank);
     vsnprintf(
             debug_message_buffer + 8,
@@ -162,7 +162,7 @@ inline void DEBUG_MSG_WAIT(MPI_Comm communicator, const char * format, ...)
     va_start(argptr, format);
     sprintf(
             debug_message_buffer,
-            "cpu%.4d ",
+            "MPIrank%.4d ",
             myrank);
     vsnprintf(
             debug_message_buffer + 8,
diff --git a/cpp/fftw_interface.hpp b/cpp/fftw_interface.hpp
index fd88ed4a..8528aba3 100644
--- a/cpp/fftw_interface.hpp
+++ b/cpp/fftw_interface.hpp
@@ -94,8 +94,18 @@ public:
     };
 
     using many_plan = many_plan_container;
+
+    static char* sprint(const many_plan mp)
+    {
+        return fftwf_sprint_plan(mp.plan_to_use);
+    }
 #else
     using many_plan = fftwf_plan;
+
+    static char* sprint(many_plan mp)
+    {
+        return fftwf_sprint_plan(mp);
+    }
 #endif
 
     static complex* alloc_complex(const size_t in_size){
@@ -451,8 +461,18 @@ public:
     };
 
     using many_plan = many_plan_container;
+
+    static char* sprint(const many_plan mp)
+    {
+        return fftw_sprint_plan(mp.plan_to_use);
+    }
 #else
     using many_plan = fftw_plan;
+
+    static char* sprint(const many_plan mp)
+    {
+        return fftw_sprint_plan(mp);
+    }
 #endif
 
     static complex* alloc_complex(const size_t in_size){
diff --git a/cpp/field.cpp b/cpp/field.cpp
index 1b3cb6e3..875bc4b3 100644
--- a/cpp/field.cpp
+++ b/cpp/field.cpp
@@ -103,6 +103,7 @@ field<rnumber, be, fc>::field(
             this->data = fftw_interface<rnumber>::alloc_real(
                     this->rmemlayout->local_size);
             memset(this->data, 0, sizeof(rnumber)*this->rmemlayout->local_size);
+            char *plan_information = NULL;
             this->c2r_plan = fftw_interface<rnumber>::mpi_plan_many_dft_c2r(
                     3, nfftw, ncomp(fc),
                     FFTW_MPI_DEFAULT_BLOCK, FFTW_MPI_DEFAULT_BLOCK,
@@ -110,6 +111,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);
             this->r2c_plan = fftw_interface<rnumber>::mpi_plan_many_dft_r2c(
                     3, nfftw, ncomp(fc),
                     FFTW_MPI_DEFAULT_BLOCK, FFTW_MPI_DEFAULT_BLOCK,
@@ -117,6 +121,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);
             break;
     }
 }
diff --git a/cpp/field.hpp b/cpp/field.hpp
index 15b298be..427d091e 100644
--- a/cpp/field.hpp
+++ b/cpp/field.hpp
@@ -334,6 +334,36 @@ class field
                               in_global_y - this->rlayout->starts[1],
                               in_global_z - this->rlayout->starts[0]);
         }
+
+        int print_plan(const std::string preamble)
+        {
+            char *c2r_plan_information = fftw_interface<rnumber>::sprint(this->c2r_plan);
+            char *r2c_plan_information = fftw_interface<rnumber>::sprint(this->r2c_plan);
+            if (this->myrank == 0)
+            {
+                std::cout << preamble <<
+                             std::endl <<
+                             "----c2r plan is:\n" <<
+                             c2r_plan_information <<
+                             std::endl <<
+                             "----r2c plan is:\n" <<
+                             r2c_plan_information <<
+                             std::endl;
+            }
+            std::string err_message = (
+                    std::string("MPI rank ") +
+                    preamble +
+                    std::to_string(this->myrank) +
+                    std::string("\n----c2r plan is:\n") +
+                    std::string(c2r_plan_information) +
+                    std::string("\n----r2c plan is:\n") +
+                    std::string(r2c_plan_information) +
+                    std::string("\n"));
+            std::cerr << err_message;
+            free(c2r_plan_information);
+            free(r2c_plan_information);
+            return EXIT_SUCCESS;
+        }
 };
 
 /** \brief Compute gradient of a field
diff --git a/cpp/vorticity_equation.cpp b/cpp/vorticity_equation.cpp
index 5372660e..e6c500b9 100644
--- a/cpp/vorticity_equation.cpp
+++ b/cpp/vorticity_equation.cpp
@@ -143,6 +143,10 @@ vorticity_equation<rnumber, be>::vorticity_equation(
             nx, ny, nz, MPI_COMM_WORLD, FFTW_PLAN_RIGOR);
     this->u = this->cvelocity;
 
+    /* print fftw plan information for relevant fields */
+    this->rvorticity->print_plan("rvorticity");
+    this->cvelocity->print_plan("cvelocity");
+
     /* initialize kspace */
     this->kk = new kspace<be, SMOOTH>(
             this->cvorticity->clayout, DKX, DKY, DKZ);
-- 
GitLab