Merge branch 'master' of bitbucket.org:glavaux/cosmotool

This commit is contained in:
Guilhem Lavaux 2021-06-02 08:52:14 +02:00
commit 84ad61a717
10 changed files with 265 additions and 186 deletions

View File

@ -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 "1${EXTRA_VERSION}")
SET(CPACK_PACKAGE_VERSION_PATCH "2${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

View File

@ -1 +1,4 @@
export CC=$(basename ${CC})
export CXX=$(basename ${CXX})
$PYTHON setup.py install

View File

@ -1,6 +1,7 @@
python:
- 3.7
- 3.8
- 3.9
numpy:
- 1.11

View File

@ -1,16 +1,16 @@
package:
name: cosmotool
version: "1.0.0a7"
version: "1.2.2"
source:
git_rev: 7fce73e
git_rev: 03033b6
git_url: https://bitbucket.org/glavaux/cosmotool
requirements:
build:
- numpy >=1.11
- gcc_linux-64
- gxx_linux-64
- {{ compiler('c') }}
- {{ compiler('cxx') }}
- python
- setuptools
- cython
@ -21,6 +21,16 @@ requirements:
- gsl
- h5py
host:
- python
- numexpr
- cython
- healpy
- cffi
- pyfftw
- gsl
- h5py
run:
- numpy
- python

12
external/patch-omptl vendored
View File

@ -92,3 +92,15 @@ diff -ur omptl.orig/omptl_numeric_par.h omptl/omptl_numeric_par.h
namespace omptl
{
diff -ur omptl.orig/omptl_algorithm_par.h omptl/omptl_algorithm_par.h
--- omptl.orig/omptl_algorithm_par.h 2021-05-09 14:26:47.227632829 +0300
+++ omptl/omptl_algorithm_par.h 2021-05-09 14:27:02.815744567 +0300
@@ -1700,7 +1700,7 @@
std::vector<char> pivot_used(pivots.size(), false); // can't be bool due to parallel write
- const unsigned max_depth = std::floor(std::tr1::log2(P));
+ const unsigned max_depth = unsigned(std::floor(std::tr1::log2(P)));
assert(1u << max_depth <= P);
for (unsigned i = 0; i < max_depth; ++i)
{

View File

@ -223,7 +223,7 @@ class BuildCMakeExt(build_ext):
CosmoTool_extension = CMakeExtension(name="cosmotool")
setup(name='cosmotool',
version='1.2.1',
version='1.2.2',
packages=["cosmotool"],
package_dir={'cosmotool': 'python/cosmotool'},
install_requires=['numpy','cffi','numexpr','pyfftw','h5py'],

View File

@ -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);

View File

@ -39,91 +39,112 @@ knowledge of the CeCILL license and that you accept its terms.
#include <fftw3.h>
#include <complex>
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<typename T> class FFTW_Calls {};
template <typename T>
class FFTW_Calls {};
#define FFTW_CALLS_BASE(rtype, prefix) \
template <> \
class FFTW_Calls<rtype> { \
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<real_type> *out) { \
prefix##_execute_dft_r2c(p, in, (complex_type *)out); \
} \
static void \
execute_c2r(plan_type p, std::complex<real_type> *in, real_type *out) { \
prefix##_execute_dft_c2r(p, (complex_type *)in, out); \
} \
static void execute_c2c( \
plan_type p, std::complex<real_type> *in, \
std::complex<real_type> *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 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); } \
}
#define FFTW_CALLS_BASE(rtype, prefix) \
template<> \
class FFTW_Calls<rtype> { \
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<real_type> *out) { prefix ## _execute_dft_r2c(p, in, (complex_type*)out); } \
static void execute_c2r(plan_type p, std::complex<real_type> *in, real_type *out) { prefix ## _execute_dft_c2r(p, (complex_type*) in, out); } \
static void execute_c2c(plan_type p, std::complex<real_type> *in, std::complex<real_type> *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

View File

@ -5,110 +5,140 @@
#include <mpi.h>
#include <fftw3-mpi.h>
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<typename T> class FFTW_MPI_Calls {};
template <typename T>
class FFTW_MPI_Calls {};
#define FFTW_MPI_CALLS_BASE(rtype, prefix) \
template <> \
class FFTW_MPI_Calls<rtype> { \
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 <size_t Nd> \
static ptrdiff_t local_size( \
std::array<ptrdiff_t, Nd> 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<real_type> *in, \
std::complex<real_type> *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<real_type> *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<real_type> *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_c2r_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 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); } \
}
#define FFTW_MPI_CALLS_BASE(rtype, prefix) \
template<> \
class FFTW_MPI_Calls<rtype> { \
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<size_t Nd> \
static ptrdiff_t local_size(std::array<ptrdiff_t,Nd> 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<real_type> *in, std::complex<real_type> *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<real_type> *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<real_type> *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

View File

@ -144,8 +144,8 @@ namespace CosmoTool {
bool useBases = false)
{
std::vector<hsize_t> memdims(data.shape(), data.shape() + data.num_dimensions());
H5::DataSpace dataspace(dimensions.size(), dimensions.data());
H5::DataSpace memspace(memdims.size(), memdims.data());
H5::DataSpace dataspace(int(dimensions.size()), dimensions.data());
H5::DataSpace memspace(int(memdims.size()), memdims.data());
if (useBases) {
std::vector<hsize_t> offsets(data.index_bases(), data.index_bases() + data.num_dimensions());
@ -398,7 +398,7 @@ namespace CosmoTool {
hdf5_weak_check_array(data, dimensions);
std::vector<hsize_t> memdims(data.shape(), data.shape() + data.num_dimensions());
H5::DataSpace memspace(memdims.size(), memdims.data());
H5::DataSpace memspace(int(memdims.size()), memdims.data());
std::vector<hsize_t> offsets(data.index_bases(), data.index_bases() + data.num_dimensions());
dataspace.selectHyperslab(H5S_SELECT_SET, memdims.data(), offsets.data());