From 06275b03c06f3615d6442ef9243a41ffecbcae19 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 17 Jul 2019 15:46:39 -0400 Subject: [PATCH] refactor FFT handling in CMake module for KSPACE. This also improves the FFT info output in the PPPM styles --- cmake/CMakeLists.txt | 7 ++++++- cmake/Modules/Packages/KSPACE.cmake | 28 ++++++++++++++++------------ src/KOKKOS/pppm_kokkos.cpp | 10 ++-------- src/KSPACE/pppm.cpp | 10 ++-------- src/KSPACE/pppm.h | 11 +++++++++++ src/KSPACE/pppm_disp.cpp | 10 ++-------- src/KSPACE/pppm_disp.h | 10 ++++++++++ 7 files changed, 49 insertions(+), 37 deletions(-) diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index bde36aa896..4b528f280e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -673,5 +673,10 @@ if(PKG_KOKKOS) message(STATUS "Kokkos Arch: ${KOKKOS_ARCH}") endif() if(PKG_KSPACE) - message(STATUS "Using ${FFT} as FFT") + message(STATUS "Using ${FFT} as primary FFT library") + if(FFT_SINGLE) + message(STATUS "Using single precision FFTs") + else() + message(STATUS "Using double precision FFTs") + endif() endif() diff --git a/cmake/Modules/Packages/KSPACE.cmake b/cmake/Modules/Packages/KSPACE.cmake index 6938a93a36..63c42baf2d 100644 --- a/cmake/Modules/Packages/KSPACE.cmake +++ b/cmake/Modules/Packages/KSPACE.cmake @@ -1,5 +1,5 @@ if(PKG_KSPACE) - option(FFT_SINGLE "Use single precision FFT instead of double" OFF) + option(FFT_SINGLE "Use single precision FFTs instead of double precision FFTs" OFF) set(FFTW "FFTW3") if(FFT_SINGLE) set(FFTW "FFTW3F") @@ -7,26 +7,30 @@ if(PKG_KSPACE) endif() find_package(${FFTW} QUIET) if(${FFTW}_FOUND) - set(FFT "${FFTW}" CACHE STRING "FFT library for KSPACE package") + set(FFT "FFTW3" CACHE STRING "FFT library for KSPACE package") else() set(FFT "KISS" CACHE STRING "FFT library for KSPACE package") endif() - set(FFT_VALUES KISS ${FFTW} MKL) + set(FFT_VALUES KISS FFTW3 MKL) set_property(CACHE FFT PROPERTY STRINGS ${FFT_VALUES}) validate_option(FFT FFT_VALUES) string(TOUPPER ${FFT} FFT) - if(NOT FFT STREQUAL "KISS") - find_package(${FFT} REQUIRED) - if(NOT FFT STREQUAL "FFTW3F") - add_definitions(-DFFT_FFTW) - else() - add_definitions(-DFFT_${FFT}) - endif() - include_directories(${${FFT}_INCLUDE_DIRS}) - list(APPEND LAMMPS_LINK_LIBS ${${FFT}_LIBRARIES}) + + if(FFT STREQUAL "FFTW3") + find_package(${FFTW} REQUIRED) + add_definitions(-DFFT_FFTW3) + include_directories(${${FFTW}_INCLUDE_DIRS}) + list(APPEND LAMMPS_LINK_LIBS ${${FFTW}_LIBRARIES}) + elseif(FFT STREQUAL "MKL") + find_package(MKL REQUIRED) + add_definitions(-DFFT_MKL) + include_directories(${MKL_INCLUDE_DIRS}) + list(APPEND LAMMPS_LINK_LIBS ${MKL_LIBRARIES}) else() + # last option is KISSFFT add_definitions(-DFFT_KISS) endif() + set(FFT_PACK "array" CACHE STRING "Optimization for FFT") set(FFT_PACK_VALUES array pointer memcpy) set_property(CACHE FFT_PACK PROPERTY STRINGS ${FFT_PACK_VALUES}) diff --git a/src/KOKKOS/pppm_kokkos.cpp b/src/KOKKOS/pppm_kokkos.cpp index 7c01adc510..c9c0d6d1d4 100644 --- a/src/KOKKOS/pppm_kokkos.cpp +++ b/src/KOKKOS/pppm_kokkos.cpp @@ -306,12 +306,6 @@ void PPPMKokkos::init() if (me == 0) { -#ifdef FFT_SINGLE - const char fft_prec[] = "single"; -#else - const char fft_prec[] = "double"; -#endif - if (screen) { fprintf(screen," G vector (1/distance) = %g\n",g_ewald); fprintf(screen," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); @@ -320,7 +314,7 @@ void PPPMKokkos::init() estimated_accuracy); fprintf(screen," estimated relative force accuracy = %g\n", estimated_accuracy/two_charge_force); - fprintf(screen," using %s precision FFTs\n",fft_prec); + fprintf(screen," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); fprintf(screen," 3d grid and FFT values/proc = %d %d\n", ngrid_max,nfft_both_max); } @@ -332,7 +326,7 @@ void PPPMKokkos::init() estimated_accuracy); fprintf(logfile," estimated relative force accuracy = %g\n", estimated_accuracy/two_charge_force); - fprintf(logfile," using %s precision FFTs\n",fft_prec); + fprintf(logfile," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", ngrid_max,nfft_both_max); } diff --git a/src/KSPACE/pppm.cpp b/src/KSPACE/pppm.cpp index 53c18804a5..1abb19e947 100644 --- a/src/KSPACE/pppm.cpp +++ b/src/KSPACE/pppm.cpp @@ -350,12 +350,6 @@ void PPPM::init() if (me == 0) { -#ifdef FFT_SINGLE - const char fft_prec[] = "single"; -#else - const char fft_prec[] = "double"; -#endif - if (screen) { fprintf(screen," G vector (1/distance) = %g\n",g_ewald); fprintf(screen," grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); @@ -364,7 +358,7 @@ void PPPM::init() estimated_accuracy); fprintf(screen," estimated relative force accuracy = %g\n", estimated_accuracy/two_charge_force); - fprintf(screen," using %s precision FFTs\n",fft_prec); + fprintf(screen," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); fprintf(screen," 3d grid and FFT values/proc = %d %d\n", ngrid_max,nfft_both_max); } @@ -376,7 +370,7 @@ void PPPM::init() estimated_accuracy); fprintf(logfile," estimated relative force accuracy = %g\n", estimated_accuracy/two_charge_force); - fprintf(logfile," using %s precision FFTs\n",fft_prec); + fprintf(logfile," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", ngrid_max,nfft_both_max); } diff --git a/src/KSPACE/pppm.h b/src/KSPACE/pppm.h index 1ce1a0d666..6426b9c22d 100644 --- a/src/KSPACE/pppm.h +++ b/src/KSPACE/pppm.h @@ -23,11 +23,22 @@ KSpaceStyle(pppm,PPPM) #include "lmptype.h" #include +#if defined(FFT_FFTW3) +#define LMP_FFT_LIB "FFTW3" +#elif defined(FFT_MKL) +#define LMP_FFT_LIB "MKL FFT" +#else +#define LMP_FFT_LIB "KISS FFT" +#endif + #ifdef FFT_SINGLE typedef float FFT_SCALAR; +#define LMP_FFT_PREC "single" #define MPI_FFT_SCALAR MPI_FLOAT #else + typedef double FFT_SCALAR; +#define LMP_FFT_PREC "double" #define MPI_FFT_SCALAR MPI_DOUBLE #endif diff --git a/src/KSPACE/pppm_disp.cpp b/src/KSPACE/pppm_disp.cpp index 45dce0895b..ba0e85bbba 100644 --- a/src/KSPACE/pppm_disp.cpp +++ b/src/KSPACE/pppm_disp.cpp @@ -474,12 +474,6 @@ void PPPMDisp::init() MPI_Allreduce(&nfft_both,&nfft_both_max,1,MPI_INT,MPI_MAX,world); if (me == 0) { - #ifdef FFT_SINGLE - const char fft_prec[] = "single"; - #else - const char fft_prec[] = "double"; - #endif - if (screen) { fprintf(screen," Coulomb G vector (1/distance)= %g\n",g_ewald); fprintf(screen," Coulomb grid = %d %d %d\n",nx_pppm,ny_pppm,nz_pppm); @@ -488,7 +482,7 @@ void PPPMDisp::init() acc); fprintf(screen," Coulomb estimated relative force accuracy = %g\n", acc/two_charge_force); - fprintf(screen," using %s precision FFTs\n",fft_prec); + fprintf(screen," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); fprintf(screen," 3d grid and FFT values/proc = %d %d\n", ngrid_max, nfft_both_max); } @@ -501,7 +495,7 @@ void PPPMDisp::init() acc); fprintf(logfile," Coulomb estimated relative force accuracy = %g\n", acc/two_charge_force); - fprintf(logfile," using %s precision FFTs\n",fft_prec); + fprintf(logfile," using " LMP_FFT_PREC " precision " LMP_FFT_LIB "\n"); fprintf(logfile," 3d grid and FFT values/proc = %d %d\n", ngrid_max, nfft_both_max); } diff --git a/src/KSPACE/pppm_disp.h b/src/KSPACE/pppm_disp.h index ccbeb60f3c..8674669274 100644 --- a/src/KSPACE/pppm_disp.h +++ b/src/KSPACE/pppm_disp.h @@ -23,11 +23,21 @@ KSpaceStyle(pppm/disp,PPPMDisp) #include "lmptype.h" #include +#if defined(FFT_FFTW3) +#define LMP_FFT_LIB "FFTW3" +#elif defined(FFT_MKL) +#define LMP_FFT_LIB "MKL FFT" +#else +#define LMP_FFT_LIB "KISS FFT" +#endif + #ifdef FFT_SINGLE typedef float FFT_SCALAR; +#define LMP_FFT_PREC "single" #define MPI_FFT_SCALAR MPI_FLOAT #else typedef double FFT_SCALAR; +#define LMP_FFT_PREC "double" #define MPI_FFT_SCALAR MPI_DOUBLE #endif