diff --git a/src/lammps.cpp b/src/lammps.cpp index 0e3ec7d062..809f0299da 100644 --- a/src/lammps.cpp +++ b/src/lammps.cpp @@ -19,6 +19,9 @@ #include #include #include +#ifdef FFT_FFTW3 +#include +#endif #include "style_angle.h" // IWYU pragma: keep #include "style_atom.h" // IWYU pragma: keep #include "style_bond.h" // IWYU pragma: keep @@ -1315,3 +1318,15 @@ void LAMMPS::print_config(FILE *fp) } fputs("\n\n",fp); } + +void LAMMPS::cleanup() { +#ifdef FFT_FFTW3 + // tell fftw3 to delete its global memory pool + // and thus avoid bogus valgrind memory leak reports +#ifdef FFT_SINGLE + fftwf_cleanup(); +#else + fftw_cleanup(); +#endif +#endif +} diff --git a/src/lammps.h b/src/lammps.h index dc2916f214..8029ffab3e 100644 --- a/src/lammps.h +++ b/src/lammps.h @@ -79,6 +79,7 @@ class LAMMPS { void post_create(); void init(); void destroy(); + void cleanup(); void print_config(FILE *); // print compile time settings private: diff --git a/src/main.cpp b/src/main.cpp index 85e25aa2e4..d89ba11668 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,10 +19,6 @@ #include #endif -#ifdef FFT_FFTW3 -#include -#endif - #if defined(LAMMPS_EXCEPTIONS) #include "exceptions.h" #endif @@ -63,18 +59,9 @@ int main(int argc, char **argv) #else LAMMPS *lammps = new LAMMPS(argc,argv,MPI_COMM_WORLD); lammps->input->file(); + lammps->cleanup(); delete lammps; #endif MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); - -#ifdef FFT_FFTW3 - // tell fftw3 to delete its global memory pool - // and thus avoid bogus valgrind memory leak reports -#ifdef FFT_SINGLE - fftwf_cleanup(); -#else - fftw_cleanup(); -#endif -#endif }