From 7e436bb0e729106368b8fe58423f0fa649773835 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Fri, 13 Nov 2020 13:32:06 +0100 Subject: [PATCH 1/8] Add missing declaration --- src/fortran.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fortran.cpp b/src/fortran.cpp index 376d62d..d831dc5 100644 --- a/src/fortran.cpp +++ b/src/fortran.cpp @@ -139,6 +139,8 @@ void UnformattedRead::beginCheckpoint(bool bufferRecord) void UnformattedRead::endCheckpoint(bool autodrop) { + bool always_fail = false; + if (recordBuffer != 0) { delete[] recordBuffer; recordBuffer = 0; From cb9e97e2c1d634d90b13758bdd03369df7d19505 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sun, 24 Jan 2021 09:31:01 +0100 Subject: [PATCH 2/8] Fixes --- python/_cosmotool.pyx | 2 +- src/fortran.cpp | 6 ++++-- src/loadGadget.cpp | 10 +++++----- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/python/_cosmotool.pyx b/python/_cosmotool.pyx index ed9195e..3bfc88c 100644 --- a/python/_cosmotool.pyx +++ b/python/_cosmotool.pyx @@ -410,7 +410,7 @@ def loadGadget(str filename, int snapshot_id, int gadgetFormat = 1, bool loadPos with nogil: data = loadGadgetMulti(filename_bs, snapshot_id, flags, gadgetFormat) if data == 0: - return None + raise RuntimeError("File could not be read") return PySimulationAdaptor(wrap_simudata(data, flags)) diff --git a/src/fortran.cpp b/src/fortran.cpp index 376d62d..967b19a 100644 --- a/src/fortran.cpp +++ b/src/fortran.cpp @@ -139,14 +139,16 @@ void UnformattedRead::beginCheckpoint(bool bufferRecord) void UnformattedRead::endCheckpoint(bool autodrop) { + bool always_fail = false; + if (recordBuffer != 0) { delete[] recordBuffer; recordBuffer = 0; } if (cSize == Check_32bits) { - if (checkPointAccum >= 1<<32UL) { + if (checkPointAccum >= 1UL<<32UL) { always_fail = true; - checkPointAccum %= (1<<32UL); + checkPointAccum %= (1UL<<32UL); } } diff --git a/src/loadGadget.cpp b/src/loadGadget.cpp index 0a5a0f0..3969ec2 100644 --- a/src/loadGadget.cpp +++ b/src/loadGadget.cpp @@ -221,7 +221,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, cerr << "Invalid format while reading header" << endl; delete data; delete f; - return 0; + throw; } @@ -275,7 +275,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, cerr << "Invalid format while reading positions" << endl; delete f; delete data; - return 0; + throw; } } else { @@ -292,7 +292,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, { delete f; delete data; - return 0; + throw; } } @@ -317,7 +317,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, cerr << "Invalid format while reading velocities" << endl; delete f; delete data; - return 0; + throw; } // THE VELOCITIES ARE IN PHYSICAL COORDINATES @@ -367,7 +367,7 @@ SimuData *CosmoTool::loadGadgetMulti(const char *fname, int id, cerr << "Invalid unformatted access while reading ID" << endl; delete f; delete data; - return 0; + throw; } } else { f->skip(2*4); From 793c649a8dfe3735f9ff0e1452c6607d7ac0ddc6 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Sun, 24 Jan 2021 09:40:58 +0100 Subject: [PATCH 3/8] Fixes for compiler detection in setup.py --- CMakeLists.txt | 4 ++-- setup.py | 11 ++++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c64358..e7bc520 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,8 +70,8 @@ SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A toolbox for impatient cosmologists") SET(CPACK_PACKAGE_VENDOR "Guilhem Lavaux") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE_CeCILL_V2") SET(CPACK_PACKAGE_VERSION_MAJOR "1") -SET(CPACK_PACKAGE_VERSION_MINOR "1") -SET(CPACK_PACKAGE_VERSION_PATCH "2${EXTRA_VERSION}") +SET(CPACK_PACKAGE_VERSION_MINOR "2") +SET(CPACK_PACKAGE_VERSION_PATCH "0${EXTRA_VERSION}") SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CosmoToolbox-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") SET(CPACK_STRIP_FILES "lib/libCosmoTool.so") SET(CPACK_SOURCE_IGNORE_FILES diff --git a/setup.py b/setup.py index 6975776..95542a8 100644 --- a/setup.py +++ b/setup.py @@ -167,15 +167,20 @@ class BuildCMakeExt(build_ext): # Change your cmake arguments below as necessary # Below is just an example set of arguments for building Blender as a Python module + compilers=[] + if "CC" in os.environ: + compilers.append('-DCMAKE_C_COMPILER=' + os.environ["CC"]) + if "CXX" in os.environ: + compilers.append("-DCMAKE_CXX_COMPILER=" + os.environ["CXX"]) + self.spawn(['cmake', '-H'+SOURCE_DIR, '-B'+self.build_temp, - '-DCMAKE_C_COMPILER=' + os.environ["CC"], "-DCMAKE_CXX_COMPILER=" + os.environ["CXX"], '-DENABLE_OPENMP=ON','-DINTERNAL_BOOST=ON','-DINTERNAL_EIGEN=ON', '-DINTERNAL_HDF5=ON','-DINTERNAL_NETCDF=ON', '-DBUILD_PYTHON=ON', '-DINSTALL_PYTHON_LOCAL=OFF', '-DCOSMOTOOL_PYTHON_PACKAGING=ON', f"-DCYTHON={cython_code}", f"-DPYTHON_SITE_PACKAGES={build_dir.absolute()}/private_install", - f"-DPYTHON_EXECUTABLE={sys.executable}"]) + f"-DPYTHON_EXECUTABLE={sys.executable}"] + compilers) self.announce("Building binaries", level=3) @@ -218,7 +223,7 @@ class BuildCMakeExt(build_ext): CosmoTool_extension = CMakeExtension(name="cosmotool") setup(name='cosmotool', - version='1.1.2', + version='1.2.0', packages=["cosmotool"], package_dir={'cosmotool': 'python/cosmotool'}, install_requires=['numpy','cffi','numexpr','pyfftw','h5py'], From 041cfc0630c84cf02ea16e0e7a5f4c96c77378ff Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Mon, 25 Jan 2021 09:50:48 +0100 Subject: [PATCH 4/8] Symbols protection --- builder/build-wheels.sh | 13 +++++++------ python/CMakeLists.txt | 4 ++++ python/cosmotool.version | 7 +++++++ 3 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 python/cosmotool.version diff --git a/builder/build-wheels.sh b/builder/build-wheels.sh index 90f87a9..ac343fe 100755 --- a/builder/build-wheels.sh +++ b/builder/build-wheels.sh @@ -8,7 +8,7 @@ export CC CXX # Install a system package required by our library #yum install -y atlas-devel -yum install -y cmake3 gsl-devel zlib-devel +yum install -y cmake3 gsl-devel zlib-devel fftw3-devel ln -fs /usr/bin/cmake3 /usr/bin/cmake @@ -19,17 +19,18 @@ ALL_PYTHON="cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39" for pkg in $ALL_PYTHON; do PYBIN=/opt/python/${pkg}/bin # "${PYBIN}/pip" install -r /io/dev-requirements.txt + "${PYBIN}/pip" install setuptools wheel Cython "${PYBIN}/pip" install -r /io/requirements.txt "${PYBIN}/pip" wheel -vvv /io/ -w wheelhouse/ done # Bundle external shared libraries into the wheels -for whl in wheelhouse/*.whl; do +for whl in wheelhouse/cosmotool*.whl; do auditwheel repair "$whl" --plat $PLAT -w /io/wheelhouse/ done # Install packages and test -for pkg in $ALL_PYTHON; do - PYBIN=/opt/python/${pkg}/bin - "${PYBIN}/pip" install cosmotool --no-index -f /io/wheelhouse -done +#for pkg in $ALL_PYTHON; do +# PYBIN=/opt/python/${pkg}/bin +# "${PYBIN}/pip" install cosmotool --no-index -f /io/wheelhouse +#done diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index e2ea884..db4bc17 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -54,6 +54,10 @@ SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Bsymbolic-functions if(APPLE) set(CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup") endif() +IF(NOT APPLE) + set(CMAKE_MODULE_LINKER_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/cosmotool.version") +ENDIF() + target_link_libraries(_cosmotool PRIVATE ${CosmoTool_local} ${GSL_LIBRARIES}) target_link_libraries(_cosmo_power PRIVATE ${CosmoTool_local} ${GSL_LIBRARIES}) diff --git a/python/cosmotool.version b/python/cosmotool.version new file mode 100644 index 0000000..fb25144 --- /dev/null +++ b/python/cosmotool.version @@ -0,0 +1,7 @@ +CODEABI_1.0 { + global: + PyInit_*; + _init; + _fini; + local: *; +}; From 52f870e0c196b6050e2c92bf1f50d562df5379aa Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Mon, 25 Jan 2021 09:51:18 +0100 Subject: [PATCH 5/8] Bump version --- CMakeLists.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7bc520..6225de6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ SET(CPACK_PACKAGE_VENDOR "Guilhem Lavaux") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENCE_CeCILL_V2") SET(CPACK_PACKAGE_VERSION_MAJOR "1") SET(CPACK_PACKAGE_VERSION_MINOR "2") -SET(CPACK_PACKAGE_VERSION_PATCH "0${EXTRA_VERSION}") +SET(CPACK_PACKAGE_VERSION_PATCH "1${EXTRA_VERSION}") SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CosmoToolbox-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}") SET(CPACK_STRIP_FILES "lib/libCosmoTool.so") SET(CPACK_SOURCE_IGNORE_FILES diff --git a/setup.py b/setup.py index 95542a8..2a5e548 100644 --- a/setup.py +++ b/setup.py @@ -223,7 +223,7 @@ class BuildCMakeExt(build_ext): CosmoTool_extension = CMakeExtension(name="cosmotool") setup(name='cosmotool', - version='1.2.0', + version='1.2.1', packages=["cosmotool"], package_dir={'cosmotool': 'python/cosmotool'}, install_requires=['numpy','cffi','numexpr','pyfftw','h5py'], From e6950440a32293f0191903356fb00f5a5d0de53e Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Mon, 8 Feb 2021 18:36:56 +0100 Subject: [PATCH 6/8] Remove generation of dump of power spectrum --- src/cosmopower.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cosmopower.cpp b/src/cosmopower.cpp index 3278876..5e58c2c 100644 --- a/src/cosmopower.cpp +++ b/src/cosmopower.cpp @@ -342,12 +342,14 @@ void CosmoPower::normalize(double k_min, double k_max) normPower = 1; +#if 0 ofstream ff("PP_k.txt"); for (int i = 0; i < 100; i++) { double k = pow(10.0, 8.0*i/100.-4); ff << k << " " << power(k) << endl; } +#endif // gsl_integration_qagiu(&f, 0, 0, TOLERANCE, NUM_ITERATION, w, &normVal, &abserr); gsl_integration_qag(&f, x_min, x_max, 0, TOLERANCE, NUM_ITERATION, GSL_INTEG_GAUSS61, w, &normVal, &abserr); From 3e013139f2c710f2e6c89644db5d65dfca1f9fea Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 22 Apr 2021 08:27:18 +0200 Subject: [PATCH 7/8] Reformat and add 1d support --- src/fourier/fft/fftw_calls.hpp | 176 ++++++++++++----------- src/fourier/fft/fftw_calls_mpi.hpp | 219 ++++++++++++++++------------- 2 files changed, 218 insertions(+), 177 deletions(-) diff --git a/src/fourier/fft/fftw_calls.hpp b/src/fourier/fft/fftw_calls.hpp index a5ef225..5ffefcc 100644 --- a/src/fourier/fft/fftw_calls.hpp +++ b/src/fourier/fft/fftw_calls.hpp @@ -39,91 +39,107 @@ knowledge of the CeCILL license and that you accept its terms. #include #include -namespace CosmoTool -{ +namespace CosmoTool { -static inline void init_fftw_wisdom() -{ - fftw_import_system_wisdom(); - fftw_import_wisdom_from_filename("fft_wisdom"); -} + static inline void init_fftw_wisdom() { + fftw_import_system_wisdom(); + fftw_import_wisdom_from_filename("fft_wisdom"); + } -static inline void save_fftw_wisdom() -{ - fftw_export_wisdom_to_filename("fft_wisdom"); -} + static inline void save_fftw_wisdom() { + fftw_export_wisdom_to_filename("fft_wisdom"); + } -template class FFTW_Calls {}; + template + class FFTW_Calls {}; +#define FFTW_CALLS_BASE(rtype, prefix) \ + template <> \ + class FFTW_Calls { \ + public: \ + typedef rtype real_type; \ + typedef prefix##_complex complex_type; \ + typedef prefix##_plan plan_type; \ + \ + static complex_type *alloc_complex(size_t N) { \ + return prefix##_alloc_complex(N); \ + } \ + static real_type *alloc_real(size_t N) { return prefix##_alloc_real(N); } \ + static void free(void *p) { fftw_free(p); } \ + \ + static void execute(plan_type p) { prefix##_execute(p); } \ + static void execute_r2c(plan_type p, real_type *in, complex_type *out) { \ + prefix##_execute_dft_r2c(p, in, out); \ + } \ + static void execute_c2r(plan_type p, complex_type *in, real_type *out) { \ + prefix##_execute_dft_c2r(p, in, out); \ + } \ + static void \ + execute_r2c(plan_type p, real_type *in, std::complex *out) { \ + prefix##_execute_dft_r2c(p, in, (complex_type *)out); \ + } \ + static void \ + execute_c2r(plan_type p, std::complex *in, real_type *out) { \ + prefix##_execute_dft_c2r(p, (complex_type *)in, out); \ + } \ + static void execute_c2c( \ + plan_type p, std::complex *in, \ + std::complex *out) { \ + prefix##_execute_dft(p, (complex_type *)in, (complex_type *)out); \ + } \ + static plan_type plan_dft_r2c_1d( \ + int Nx, real_type *in, complex_type *out, unsigned flags) { \ + return prefix##_plan_dft_r2c_1d(Nx, in, out, flags); \ + } \ + static plan_type plan_dft_c2r_1d( \ + int Nx, complex_type *in, real_type *out, unsigned flags) { \ + return prefix##_plan_dft_c2r_1d(Nx, in, out, flags); \ + } \ + static plan_type plan_dft_r2c_2d( \ + int Nx, int Ny, real_type *in, complex_type *out, unsigned flags) { \ + return prefix##_plan_dft_r2c_2d(Nx, Ny, in, out, flags); \ + } \ + static plan_type plan_dft_c2r_2d( \ + int Nx, int Ny, complex_type *in, real_type *out, unsigned flags) { \ + return prefix##_plan_dft_c2r_2d(Nx, Ny, in, out, flags); \ + } \ + static plan_type plan_dft_r2c_3d( \ + int Nx, int Ny, int Nz, real_type *in, complex_type *out, \ + unsigned flags) { \ + return prefix##_plan_dft_r2c_3d(Nx, Ny, Nz, in, out, flags); \ + } \ + static plan_type plan_dft_c2r_3d( \ + int Nx, int Ny, int Nz, complex_type *in, real_type *out, \ + unsigned flags) { \ + return prefix##_plan_dft_c2r_3d(Nx, Ny, Nz, in, out, flags); \ + } \ + \ + static plan_type plan_dft_r2c( \ + int rank, const int *n, real_type *in, complex_type *out, \ + unsigned flags) { \ + return prefix##_plan_dft_r2c(rank, n, in, out, flags); \ + } \ + static plan_type plan_dft_c2r( \ + int rank, const int *n, complex_type *in, real_type *out, \ + unsigned flags) { \ + return prefix##_plan_dft_c2r(rank, n, in, out, flags); \ + } \ + static plan_type plan_dft_3d( \ + int Nx, int Ny, int Nz, complex_type *in, complex_type *out, int sign, \ + unsigned flags) { \ + return prefix##_plan_dft_3d(Nx, Ny, Nz, in, out, sign, flags); \ + } \ + static plan_type plan_dft_2d( \ + int Nx, int Ny, complex_type *in, complex_type *out, int sign, \ + unsigned flags) { \ + return prefix##_plan_dft_2d(Nx, Ny, in, out, sign, flags); \ + } \ + static void destroy_plan(plan_type plan) { prefix##_destroy_plan(plan); } \ + } -#define FFTW_CALLS_BASE(rtype, prefix) \ - template<> \ -class FFTW_Calls { \ -public: \ - typedef rtype real_type; \ - typedef prefix ## _complex complex_type; \ - typedef prefix ## _plan plan_type; \ - \ - static complex_type *alloc_complex(size_t N) { return prefix ## _alloc_complex(N); } \ - static real_type *alloc_real(size_t N) { return prefix ## _alloc_real(N); } \ - static void free(void *p) { fftw_free(p); } \ -\ - static void execute(plan_type p) { prefix ## _execute(p); } \ - static void execute_r2c(plan_type p, real_type *in, complex_type *out) { prefix ## _execute_dft_r2c(p, in, out); } \ - static void execute_c2r(plan_type p, complex_type *in, real_type *out) { prefix ## _execute_dft_c2r(p, in, out); } \ - static void execute_r2c(plan_type p, real_type *in, std::complex *out) { prefix ## _execute_dft_r2c(p, in, (complex_type*)out); } \ - static void execute_c2r(plan_type p, std::complex *in, real_type *out) { prefix ## _execute_dft_c2r(p, (complex_type*) in, out); } \ - static void execute_c2c(plan_type p, std::complex *in, std::complex *out) { prefix ## _execute_dft(p, (complex_type *)in, (complex_type*)out); } \ - static plan_type plan_dft_r2c_2d(int Nx, int Ny, \ - real_type *in, complex_type *out, \ - unsigned flags) \ - { \ - return prefix ## _plan_dft_r2c_2d(Nx, Ny, in, out, \ - flags); \ - } \ - static plan_type plan_dft_c2r_2d(int Nx, int Ny, \ - complex_type *in, real_type *out, \ - unsigned flags) \ - { \ - return prefix ## _plan_dft_c2r_2d(Nx, Ny, in, out, \ - flags); \ - } \ - static plan_type plan_dft_r2c_3d(int Nx, int Ny, int Nz, \ - real_type *in, complex_type *out, \ - unsigned flags) \ - { \ - return prefix ## _plan_dft_r2c_3d(Nx, Ny, Nz, in, out, flags); \ - } \ - static plan_type plan_dft_c2r_3d(int Nx, int Ny, int Nz, \ - complex_type *in, real_type *out, \ - unsigned flags) \ - { \ - return prefix ## _plan_dft_c2r_3d(Nx, Ny, Nz, in, out, flags); \ - } \ -\ - static plan_type plan_dft_r2c(int rank, const int *n, real_type *in, \ - complex_type *out, unsigned flags) \ - { \ - return prefix ## _plan_dft_r2c(rank, n, in, out, flags); \ - } \ - static plan_type plan_dft_c2r(int rank, const int *n, complex_type *in, \ - real_type *out, unsigned flags) \ - { \ - return prefix ## _plan_dft_c2r(rank, n, in, out, flags); \ - } \ - static plan_type plan_dft_3d(int Nx, int Ny, int Nz, complex_type *in, complex_type *out, int sign, unsigned flags) { \ - return prefix ## _plan_dft_3d(Nx, Ny, Nz, in, out, sign, flags); \ - } \ - static plan_type plan_dft_2d(int Nx, int Ny, complex_type *in, complex_type *out, int sign, unsigned flags) { \ - return prefix ## _plan_dft_2d(Nx, Ny, in, out, sign, flags); \ - } \ - static void destroy_plan(plan_type plan) { prefix ## _destroy_plan(plan); } \ -} - - -FFTW_CALLS_BASE(double, fftw); -FFTW_CALLS_BASE(float, fftwf); + FFTW_CALLS_BASE(double, fftw); + FFTW_CALLS_BASE(float, fftwf); #undef FFTW_CALLS_BASE -}; +}; // namespace CosmoTool #endif diff --git a/src/fourier/fft/fftw_calls_mpi.hpp b/src/fourier/fft/fftw_calls_mpi.hpp index b592220..160a604 100644 --- a/src/fourier/fft/fftw_calls_mpi.hpp +++ b/src/fourier/fft/fftw_calls_mpi.hpp @@ -5,110 +5,135 @@ #include #include -namespace CosmoTool -{ +namespace CosmoTool { -static inline void init_fftw_mpi() -{ - fftw_mpi_init(); -} + static inline void init_fftw_mpi() { fftw_mpi_init(); } -static inline void done_fftw_mpi() -{ - fftw_mpi_cleanup(); -} + static inline void done_fftw_mpi() { fftw_mpi_cleanup(); } -template class FFTW_MPI_Calls {}; + template + class FFTW_MPI_Calls {}; +#define FFTW_MPI_CALLS_BASE(rtype, prefix) \ + template <> \ + class FFTW_MPI_Calls { \ + public: \ + typedef rtype real_type; \ + typedef prefix##_complex complex_type; \ + typedef prefix##_plan plan_type; \ + \ + static complex_type *alloc_complex(size_t N) { \ + return prefix##_alloc_complex(N); \ + } \ + static real_type *alloc_real(size_t N) { return prefix##_alloc_real(N); } \ + static void free(void *p) { fftw_free(p); } \ + \ + template \ + static ptrdiff_t local_size( \ + std::array const &N, MPI_Comm comm, \ + ptrdiff_t *local_n0, ptrdiff_t *local_0_start) { \ + return prefix##_mpi_local_size( \ + Nd, N.data(), comm, local_n0, local_0_start); \ + } \ + static ptrdiff_t local_size_2d( \ + ptrdiff_t N0, ptrdiff_t N1, MPI_Comm comm, ptrdiff_t *local_n0, \ + ptrdiff_t *local_0_start) { \ + return prefix##_mpi_local_size_2d( \ + N0, N1, comm, local_n0, local_0_start); \ + } \ + \ + static ptrdiff_t local_size_3d( \ + ptrdiff_t N0, ptrdiff_t N1, ptrdiff_t N2, MPI_Comm comm, \ + ptrdiff_t *local_n0, ptrdiff_t *local_0_start) { \ + return prefix##_mpi_local_size_3d( \ + N0, N1, N2, comm, local_n0, local_0_start); \ + } \ + \ + static void execute(plan_type p) { prefix##_execute(p); } \ + static void \ + execute_c2c(plan_type p, complex_type *in, complex_type *out) { \ + prefix##_mpi_execute_dft(p, in, out); \ + } \ + static void execute_c2c( \ + plan_type p, std::complex *in, \ + std::complex *out) { \ + prefix##_mpi_execute_dft(p, (complex_type *)in, (complex_type *)out); \ + } \ + static void execute_r2c(plan_type p, real_type *in, complex_type *out) { \ + prefix##_mpi_execute_dft_r2c(p, in, out); \ + } \ + static void \ + execute_c2r(plan_type p, std::complex *in, real_type *out) { \ + prefix##_mpi_execute_dft_c2r(p, (complex_type *)in, out); \ + } \ + static void execute_c2r(plan_type p, complex_type *in, real_type *out) { \ + prefix##_mpi_execute_dft_c2r(p, in, out); \ + } \ + static void \ + execute_r2c(plan_type p, real_type *in, std::complex *out) { \ + prefix##_mpi_execute_dft_r2c(p, in, (complex_type *)out); \ + } \ + \ + static plan_type plan_dft_r2c_1d( \ + int n, real_type *in, complex_type *out, MPI_Comm, unsigned flags) { \ + return prefix##_plan_dft_r2c_1d(n, in, out, flags); \ + } \ + \ + static plan_type plan_dft_r2c_2d( \ + int Nx, int Ny, real_type *in, complex_type *out, MPI_Comm comm, \ + unsigned flags) { \ + return prefix##_mpi_plan_dft_r2c_2d(Nx, Ny, in, out, comm, flags); \ + } \ + \ + static plan_type plan_dft_r2c_1d( \ + int n, complex_type *in, real_type *out, MPI_Comm, unsigned flags) { \ + return prefix##_plan_dft_c2r_1d(n, in, out, flags); \ + } \ + static plan_type plan_dft_c2r_2d( \ + int Nx, int Ny, complex_type *in, real_type *out, MPI_Comm comm, \ + unsigned flags) { \ + return prefix##_mpi_plan_dft_c2r_2d(Nx, Ny, in, out, comm, flags); \ + } \ + \ + static plan_type plan_dft_r2c_3d( \ + int Nx, int Ny, int Nz, real_type *in, complex_type *out, \ + MPI_Comm comm, unsigned flags) { \ + return prefix##_mpi_plan_dft_r2c_3d(Nx, Ny, Nz, in, out, comm, flags); \ + } \ + static plan_type plan_dft_c2r_3d( \ + int Nx, int Ny, int Nz, complex_type *in, real_type *out, \ + MPI_Comm comm, unsigned flags) { \ + return prefix##_mpi_plan_dft_c2r_3d(Nx, Ny, Nz, in, out, comm, flags); \ + } \ + \ + static plan_type plan_dft_r2c( \ + int rank, const ptrdiff_t *n, real_type *in, complex_type *out, \ + MPI_Comm comm, unsigned flags) { \ + return prefix##_mpi_plan_dft_r2c(rank, n, in, out, comm, flags); \ + } \ + static plan_type plan_dft_c2r( \ + int rank, const ptrdiff_t *n, complex_type *in, real_type *out, \ + MPI_Comm comm, unsigned flags) { \ + return prefix##_mpi_plan_dft_c2r(rank, n, in, out, comm, flags); \ + } \ + static plan_type plan_dft_3d( \ + int Nx, int Ny, int Nz, complex_type *in, complex_type *out, \ + MPI_Comm comm, int sign, unsigned flags) { \ + return prefix##_mpi_plan_dft_3d(Nx, Ny, Nz, in, out, comm, sign, flags); \ + } \ + static plan_type plan_dft_2d( \ + int Nx, int Ny, complex_type *in, complex_type *out, MPI_Comm comm, \ + int sign, unsigned flags) { \ + return prefix##_mpi_plan_dft_2d(Nx, Ny, in, out, comm, sign, flags); \ + } \ + static void destroy_plan(plan_type plan) { prefix##_destroy_plan(plan); } \ + } -#define FFTW_MPI_CALLS_BASE(rtype, prefix) \ - template<> \ -class FFTW_MPI_Calls { \ -public: \ - typedef rtype real_type; \ - typedef prefix ## _complex complex_type; \ - typedef prefix ## _plan plan_type; \ - \ - static complex_type *alloc_complex(size_t N) { return prefix ## _alloc_complex(N); } \ - static real_type *alloc_real(size_t N) { return prefix ## _alloc_real(N); } \ - static void free(void *p) { fftw_free(p); } \ -\ - template \ - static ptrdiff_t local_size(std::array const& N, MPI_Comm comm, \ - ptrdiff_t *local_n0, ptrdiff_t *local_0_start) { \ - return prefix ## _mpi_local_size(Nd, N.data(), comm, local_n0, local_0_start); \ - } \ - static ptrdiff_t local_size_2d(ptrdiff_t N0, ptrdiff_t N1, MPI_Comm comm, \ - ptrdiff_t *local_n0, ptrdiff_t *local_0_start) { \ - return prefix ## _mpi_local_size_2d(N0, N1, comm, local_n0, local_0_start); \ - } \ -\ - static ptrdiff_t local_size_3d(ptrdiff_t N0, ptrdiff_t N1, ptrdiff_t N2, MPI_Comm comm, \ - ptrdiff_t *local_n0, ptrdiff_t *local_0_start) { \ - return prefix ## _mpi_local_size_3d(N0, N1, N2, comm, local_n0, local_0_start); \ - } \ -\ - static void execute(plan_type p) { prefix ## _execute(p); } \ - static void execute_c2c(plan_type p, complex_type *in, complex_type *out) { prefix ## _mpi_execute_dft(p, in, out); } \ - static void execute_c2c(plan_type p, std::complex *in, std::complex *out) { prefix ## _mpi_execute_dft(p, (complex_type*)in, (complex_type*)out); } \ - static void execute_r2c(plan_type p, real_type *in, complex_type *out) { prefix ## _mpi_execute_dft_r2c(p, in, out); } \ - static void execute_c2r(plan_type p, std::complex *in, real_type *out) { prefix ## _mpi_execute_dft_c2r(p, (complex_type*)in, out); } \ - static void execute_c2r(plan_type p, complex_type *in, real_type *out) { prefix ## _mpi_execute_dft_c2r(p, in, out); } \ - static void execute_r2c(plan_type p, real_type *in, std::complex *out) { prefix ## _mpi_execute_dft_r2c(p, in, (complex_type*)out); } \ -\ - static plan_type plan_dft_r2c_2d(int Nx, int Ny, \ - real_type *in, complex_type *out, \ - MPI_Comm comm, unsigned flags) \ - { \ - return prefix ## _mpi_plan_dft_r2c_2d(Nx, Ny, in, out, \ - comm, flags); \ - } \ - static plan_type plan_dft_c2r_2d(int Nx, int Ny, \ - complex_type *in, real_type *out, \ - MPI_Comm comm, unsigned flags) \ - { \ - return prefix ## _mpi_plan_dft_c2r_2d(Nx, Ny, in, out, \ - comm, flags); \ - } \ - static plan_type plan_dft_r2c_3d(int Nx, int Ny, int Nz, \ - real_type *in, complex_type *out, \ - MPI_Comm comm, unsigned flags) \ - { \ - return prefix ## _mpi_plan_dft_r2c_3d(Nx, Ny, Nz, in, out, comm, flags); \ - } \ - static plan_type plan_dft_c2r_3d(int Nx, int Ny, int Nz, \ - complex_type *in, real_type *out, \ - MPI_Comm comm, \ - unsigned flags) \ - { \ - return prefix ## _mpi_plan_dft_c2r_3d(Nx, Ny, Nz, in, out, comm, flags); \ - } \ -\ - static plan_type plan_dft_r2c(int rank, const ptrdiff_t *n, real_type *in, \ - complex_type *out, MPI_Comm comm, unsigned flags) \ - { \ - return prefix ## _mpi_plan_dft_r2c(rank, n, in, out, comm, flags); \ - } \ - static plan_type plan_dft_c2r(int rank, const ptrdiff_t *n, complex_type *in, \ - real_type *out, MPI_Comm comm, unsigned flags) \ - { \ - return prefix ## _mpi_plan_dft_c2r(rank, n, in, out, comm, flags); \ - } \ - static plan_type plan_dft_3d(int Nx, int Ny, int Nz, complex_type *in, complex_type *out, MPI_Comm comm, int sign, unsigned flags) { \ - return prefix ## _mpi_plan_dft_3d(Nx, Ny, Nz, in, out, comm, sign, flags); \ - } \ - static plan_type plan_dft_2d(int Nx, int Ny, complex_type *in, complex_type *out, MPI_Comm comm, int sign, unsigned flags) { \ - return prefix ## _mpi_plan_dft_2d(Nx, Ny, in, out, comm, sign, flags); \ - } \ - static void destroy_plan(plan_type plan) { prefix ## _destroy_plan(plan); } \ -} - - -FFTW_MPI_CALLS_BASE(double, fftw); -FFTW_MPI_CALLS_BASE(float, fftwf); + FFTW_MPI_CALLS_BASE(double, fftw); + FFTW_MPI_CALLS_BASE(float, fftwf); #undef FFTW_MPI_CALLS_BASE -}; +}; // namespace CosmoTool #endif From 8068ebe3ae87537deb47c00746a645136f049c62 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Thu, 22 Apr 2021 08:42:24 +0200 Subject: [PATCH 8/8] Fix 1d support --- src/fourier/fft/fftw_calls.hpp | 5 +++++ src/fourier/fft/fftw_calls_mpi.hpp | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/fourier/fft/fftw_calls.hpp b/src/fourier/fft/fftw_calls.hpp index 5ffefcc..67a714a 100644 --- a/src/fourier/fft/fftw_calls.hpp +++ b/src/fourier/fft/fftw_calls.hpp @@ -134,6 +134,11 @@ namespace CosmoTool { unsigned flags) { \ return prefix##_plan_dft_2d(Nx, Ny, in, out, sign, flags); \ } \ + static plan_type plan_dft_1d( \ + int Nx, complex_type *in, complex_type *out, int sign, \ + unsigned flags) { \ + return prefix##_plan_dft_1d(Nx, in, out, sign, flags); \ + } \ static void destroy_plan(plan_type plan) { prefix##_destroy_plan(plan); } \ } diff --git a/src/fourier/fft/fftw_calls_mpi.hpp b/src/fourier/fft/fftw_calls_mpi.hpp index 160a604..aa31233 100644 --- a/src/fourier/fft/fftw_calls_mpi.hpp +++ b/src/fourier/fft/fftw_calls_mpi.hpp @@ -85,7 +85,7 @@ namespace CosmoTool { return prefix##_mpi_plan_dft_r2c_2d(Nx, Ny, in, out, comm, flags); \ } \ \ - static plan_type plan_dft_r2c_1d( \ + static plan_type plan_dft_c2r_1d( \ int n, complex_type *in, real_type *out, MPI_Comm, unsigned flags) { \ return prefix##_plan_dft_c2r_1d(n, in, out, flags); \ } \ @@ -126,6 +126,11 @@ namespace CosmoTool { int sign, unsigned flags) { \ return prefix##_mpi_plan_dft_2d(Nx, Ny, in, out, comm, sign, flags); \ } \ + static plan_type plan_dft_1d( \ + int Nx, complex_type *in, complex_type *out, MPI_Comm comm, int sign, \ + unsigned flags) { \ + return prefix##_plan_dft_1d(Nx, in, out, sign, flags); \ + } \ static void destroy_plan(plan_type plan) { prefix##_destroy_plan(plan); } \ }