From 07cfe4137fe9a568753f109b3f60441e2420ccd4 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Tue, 11 Jul 2017 15:36:19 +0200 Subject: [PATCH 1/6] Generic fix and path update --- external/external_build.cmake | 2 +- python/CMakeLists.txt | 4 ++++ python/_cosmotool.pyx | 6 +++++- python/_project.pyx | 3 --- python/cosmotool/fftw.py | 15 ++++++++++++--- python/cosmotool/simu.py | 5 +++++ 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/external/external_build.cmake b/external/external_build.cmake index 225b0d4..0dbb313 100644 --- a/external/external_build.cmake +++ b/external/external_build.cmake @@ -5,7 +5,7 @@ OPTION(ENABLE_OPENMP "Set to Yes if Healpix and/or you need openMP" OFF) SET(FFTW_URL "http://www.fftw.org/fftw-3.3.3.tar.gz" CACHE URL "URL to download FFTW from") SET(EIGEN_URL "http://bitbucket.org/eigen/eigen/get/3.2.10.tar.gz" CACHE URL "URL to download Eigen from") SET(GENGETOPT_URL "ftp://ftp.gnu.org/gnu/gengetopt/gengetopt-2.22.5.tar.gz" CACHE STRING "URL to download gengetopt from") -SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/current18/src/hdf5-1.8.18.tar.bz2" CACHE STRING "URL to download HDF5 from") +SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.18/src/hdf5-1.8.18.tar.gz" CACHE STRING "URL to download HDF5 from") SET(NETCDF_URL "http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.1.3.tar.gz" CACHE STRING "URL to download NetCDF from") SET(BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.gz/download" CACHE STRING "URL to download Boost from") SET(GSL_URL "ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz" CACHE STRING "URL to download GSL from ") diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 63c5312..bb2f745 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -74,6 +74,9 @@ if (NOT PYTHON_SITE_PACKAGES) mark_as_advanced(USER_PYTHON_SITE_PACKAGES SYSTEM_PYTHON_SITE_PACKAGES) endif (NOT PYTHON_SITE_PACKAGES) +message(STATUS "System python site: ${SYSTEM_PYTHON_SITE_PACKAGES}") +message(STATUS "User python site: ${USER_PYTHON_SITE_PACKAGES}") + OPTION(INSTALL_PYTHON_LOCAL OFF) IF (NOT INSTALL_PYTHON_LOCAL) @@ -81,6 +84,7 @@ IF (NOT INSTALL_PYTHON_LOCAL) ELSE (NOT INSTALL_PYTHON_LOCAL) SET(PYTHON_SITE_PACKAGES ${USER_PYTHON_SITE_PACKAGES}) ENDIF(NOT INSTALL_PYTHON_LOCAL) +cmessage(STATUS "Python install location: ${PYTHON_SITE_PACKAGES}") if (WIN32 AND NOT CYGWIN) diff --git a/python/_cosmotool.pyx b/python/_cosmotool.pyx index 4f6758d..628e4e9 100644 --- a/python/_cosmotool.pyx +++ b/python/_cosmotool.pyx @@ -388,6 +388,7 @@ def loadGadget(str filename, int snapshot_id, int gadgetFormat = 1, bool loadPos cdef int flags cdef SimuData *data cdef Simulation simu + cdef const char *filename_bs flags = 0 if loadPosition: @@ -401,7 +402,10 @@ def loadGadget(str filename, int snapshot_id, int gadgetFormat = 1, bool loadPos if loadMass: flags |= NEED_MASS - data = loadGadgetMulti(filename, snapshot_id, flags, gadgetFormat) + filename_b = bytes(filename, 'utf-8') + filename_bs = filename_b + with nogil: + data = loadGadgetMulti(filename_bs, snapshot_id, flags, gadgetFormat) if data == 0: return None diff --git a/python/_project.pyx b/python/_project.pyx index 253b369..ed07057 100644 --- a/python/_project.pyx +++ b/python/_project.pyx @@ -404,9 +404,6 @@ cdef void INTERNAL_project_cic_no_mass(npx.ndarray[DTYPE_t, ndim=3] g, if b[j] < 0 or b[j]+1 >= Ngrid: do_not_put = True - print("b = %g %g %g" % (b[0], b[1], b[2])) - print("a = %g %g %g" % (a[0], a[1], a[2])) - if not do_not_put: g[b[0],b[1],b[2]] += c[0]*c[1]*c[2] g[b[0]+1,b[1],b[2]] += a[0]*c[1]*c[2] diff --git a/python/cosmotool/fftw.py b/python/cosmotool/fftw.py index da0c094..ec0cb6a 100644 --- a/python/cosmotool/fftw.py +++ b/python/cosmotool/fftw.py @@ -4,14 +4,23 @@ import numpy as np import numexpr as ne class CubeFT(object): - def __init__(self, L, N, max_cpu=-1): + def __init__(self, L, N, max_cpu=-1, width=32): + if width==32: + fourier_type='complex64' + real_type='float32' + elif width==64: + fourier_type='complex128' + real_type='float64' + else: + raise ValueError("Invalid bitwidth (must be 32 or 64)") + self.N = N self.align = pyfftw.simd_alignment self.L = float(L) self.max_cpu = multiprocessing.cpu_count() if max_cpu < 0 else max_cpu - self._dhat = pyfftw.n_byte_align_empty((self.N,self.N,self.N/2+1), self.align, dtype='complex64') - self._density = pyfftw.n_byte_align_empty((self.N,self.N,self.N), self.align, dtype='float32') + self._dhat = pyfftw.n_byte_align_empty((self.N,self.N,self.N/2+1), self.align, dtype=fourier_type) + self._density = pyfftw.n_byte_align_empty((self.N,self.N,self.N), self.align, dtype=real_type) self._irfft = pyfftw.FFTW(self._dhat, self._density, axes=(0,1,2), direction='FFTW_BACKWARD', threads=self.max_cpu)#, normalize_idft=False) self._rfft = pyfftw.FFTW(self._density, self._dhat, axes=(0,1,2), threads=self.max_cpu) #, normalize_idft=False) diff --git a/python/cosmotool/simu.py b/python/cosmotool/simu.py index 3dd4cf6..2389926 100644 --- a/python/cosmotool/simu.py +++ b/python/cosmotool/simu.py @@ -14,6 +14,7 @@ class SimulationBare(PySimulationBase): self.positions = [q.copy() for q in s.getPositions()] if s.getPositions() is not None else None self.velocities = [q.copy() for q in s.getVelocities()] if s.getVelocities() is not None else None self.identifiers = s.getIdentifiers().copy() if s.getIdentifiers() is not None else None + self.types = s.getTypes().copy() if s.getTypes() is not None else None self.boxsize = s.getBoxsize() self.time = s.getTime() self.Hubble = s.getHubble() @@ -53,11 +54,15 @@ class SimulationBare(PySimulationBase): self.positions = _safe_merge(self.positions, other.getPositions()) self.velocities = _safe_merge(self.velocities, other.getVelocities()) self.identifiers = _safe_merge0(self.identifiers, other.getIdentifiers()) + self.types = _safe_merge0(self.types, other.getTypes()) try: self.masses = _safe_merge0(self.masses, other.getMasses()) except Exception as e: warnings.warn("Unexpected exception: " + repr(e)); self.masses = None + + def getTypes(self): + return self.types def getPositions(self): return self.positions From c4f50298774c3e08f5473f557e4a1efa8ae1e348 Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 19 Jul 2017 18:46:05 +0300 Subject: [PATCH 2/6] Fix to remove C++11 warnings --- src/fortran.cpp | 21 --------------- src/fortran.hpp | 63 +++++++++++++++------------------------------ src/interpolate.cpp | 5 ---- src/interpolate.hpp | 15 ++++------- 4 files changed, 26 insertions(+), 78 deletions(-) diff --git a/src/fortran.cpp b/src/fortran.cpp index c41a720..1170a9a 100644 --- a/src/fortran.cpp +++ b/src/fortran.cpp @@ -43,7 +43,6 @@ using namespace std; using namespace CosmoTool; UnformattedRead::UnformattedRead(const string& fname) - throw(NoSuchFileException) { f = new ifstream(fname.c_str()); if (!*f) @@ -55,7 +54,6 @@ UnformattedRead::UnformattedRead(const string& fname) } UnformattedRead::UnformattedRead(const char *fname) - throw(NoSuchFileException) { f = new ifstream(fname); if (!*f) @@ -100,7 +98,6 @@ void UnformattedRead::setCheckpointSize(CheckpointSize cs) } void UnformattedRead::skip(int64_t off) - throw (InvalidUnformattedAccess) { if (checkPointAccum == 0 && checkPointRef == 0) { @@ -119,7 +116,6 @@ void UnformattedRead::skip(int64_t off) } void UnformattedRead::beginCheckpoint(bool bufferRecord) - throw (InvalidUnformattedAccess,EndOfFileException) { if (checkPointAccum != 0) throw InvalidUnformattedAccess(); @@ -140,7 +136,6 @@ void UnformattedRead::beginCheckpoint(bool bufferRecord) } void UnformattedRead::endCheckpoint(bool autodrop) - throw (InvalidUnformattedAccess) { if (recordBuffer != 0) { delete[] recordBuffer; @@ -169,7 +164,6 @@ void UnformattedRead::endCheckpoint(bool autodrop) } void UnformattedRead::readOrderedBuffer(void *buffer, int size) - throw (InvalidUnformattedAccess) { if ((checkPointAccum+(uint64_t)size) > checkPointRef) throw InvalidUnformattedAccess(); @@ -190,7 +184,6 @@ void UnformattedRead::readOrderedBuffer(void *buffer, int size) } double UnformattedRead::readReal64() - throw (InvalidUnformattedAccess) { union { @@ -204,7 +197,6 @@ double UnformattedRead::readReal64() } float UnformattedRead::readReal32() - throw (InvalidUnformattedAccess) { union { @@ -218,7 +210,6 @@ float UnformattedRead::readReal32() } uint32_t UnformattedRead::readUint32() - throw (InvalidUnformattedAccess) { union { @@ -232,7 +223,6 @@ uint32_t UnformattedRead::readUint32() } int32_t UnformattedRead::readInt32() - throw (InvalidUnformattedAccess) { union { @@ -246,7 +236,6 @@ int32_t UnformattedRead::readInt32() } int64_t UnformattedRead::readInt64() - throw (InvalidUnformattedAccess) { union { @@ -262,7 +251,6 @@ int64_t UnformattedRead::readInt64() //// UnformattedWrite UnformattedWrite::UnformattedWrite(const string& fname) - throw(NoSuchFileException) { f = new ofstream(fname.c_str()); if (!*f) @@ -274,7 +262,6 @@ UnformattedWrite::UnformattedWrite(const string& fname) } UnformattedWrite::UnformattedWrite(const char *fname) - throw(NoSuchFileException) { f = new ofstream(fname); if (!*f) @@ -304,7 +291,6 @@ void UnformattedWrite::setCheckpointSize(CheckpointSize cs) } void UnformattedWrite::beginCheckpoint() - throw (InvalidUnformattedAccess,FilesystemFullException) { if (checkPointAccum != 0) throw InvalidUnformattedAccess(); @@ -322,7 +308,6 @@ void UnformattedWrite::beginCheckpoint() } void UnformattedWrite::endCheckpoint() - throw (InvalidUnformattedAccess,FilesystemFullException) { if (checkPointAccum == 0) throw InvalidUnformattedAccess(); @@ -354,7 +339,6 @@ void UnformattedWrite::endCheckpoint() } void UnformattedWrite::writeOrderedBuffer(void *buffer, int size) - throw (FilesystemFullException) { f->write((char *)buffer, size); @@ -371,7 +355,6 @@ void UnformattedWrite::writeOrderedBuffer(void *buffer, int size) } void UnformattedWrite::writeReal64(double d) - throw (FilesystemFullException) { union { @@ -385,7 +368,6 @@ void UnformattedWrite::writeReal64(double d) } void UnformattedWrite::writeReal32(float f) - throw (FilesystemFullException) { union { @@ -399,7 +381,6 @@ void UnformattedWrite::writeReal32(float f) } void UnformattedWrite::writeInt32(int32_t i) - throw (FilesystemFullException) { union { @@ -412,7 +393,6 @@ void UnformattedWrite::writeInt32(int32_t i) } void UnformattedWrite::writeInt64(int64_t i) - throw (FilesystemFullException) { union { @@ -425,7 +405,6 @@ void UnformattedWrite::writeInt64(int64_t i) } void UnformattedWrite::writeInt8(int8_t i) - throw (FilesystemFullException) { union { char b; int8_t i; } a; diff --git a/src/fortran.hpp b/src/fortran.hpp index 49d8e67..471e87f 100644 --- a/src/fortran.hpp +++ b/src/fortran.hpp @@ -67,10 +67,8 @@ namespace CosmoTool { public: - UnformattedRead(const std::string& fname) - throw (NoSuchFileException); - UnformattedRead(const char *fname) - throw (NoSuchFileException); + UnformattedRead(const std::string& fname); + UnformattedRead(const char *fname); ~UnformattedRead(); // Todo implement primitive description @@ -79,30 +77,21 @@ namespace CosmoTool uint64_t getBlockSize() const { return checkPointRef; } - void beginCheckpoint(bool bufferRecord = false) - throw (InvalidUnformattedAccess,EndOfFileException); - void endCheckpoint(bool autodrop = false) - throw (InvalidUnformattedAccess); + void beginCheckpoint(bool bufferRecord = false); + void endCheckpoint(bool autodrop = false); - double readReal64() - throw (InvalidUnformattedAccess); - float readReal32() - throw (InvalidUnformattedAccess); - uint32_t readUint32() - throw (InvalidUnformattedAccess); - int32_t readInt32() - throw (InvalidUnformattedAccess); - int64_t readInt64() - throw (InvalidUnformattedAccess); + double readReal64(); + float readReal32(); + uint32_t readUint32(); + int32_t readInt32(); + int64_t readInt64(); - void skip(int64_t off) - throw (InvalidUnformattedAccess); + void skip(int64_t off); int64_t position() const; void seek(int64_t pos); - void readOrderedBuffer(void *buffer, int size) - throw (InvalidUnformattedAccess); + void readOrderedBuffer(void *buffer, int size); protected: bool swapOrdering; CheckpointSize cSize; @@ -117,34 +106,24 @@ namespace CosmoTool { public: - UnformattedWrite(const std::string& fname) - throw (NoSuchFileException); - UnformattedWrite(const char *fname) - throw (NoSuchFileException); + UnformattedWrite(const std::string& fname); + UnformattedWrite(const char *fname); ~UnformattedWrite(); // Todo implement primitive description void setOrdering(Ordering o); void setCheckpointSize(CheckpointSize cs); - void beginCheckpoint() - throw (FilesystemFullException,InvalidUnformattedAccess); - void endCheckpoint() - throw (FilesystemFullException,InvalidUnformattedAccess); + void beginCheckpoint(); + void endCheckpoint(); - void writeReal64(double d) - throw (FilesystemFullException); - void writeReal32(float f) - throw (FilesystemFullException); - void writeInt32(int32_t i) - throw (FilesystemFullException); - void writeInt64(int64_t i) - throw (FilesystemFullException); - void writeInt8(int8_t c) - throw (FilesystemFullException); + void writeReal64(double d); + void writeReal32(float f); + void writeInt32(int32_t i); + void writeInt64(int64_t i); + void writeInt8(int8_t c); - void writeOrderedBuffer(void *buffer, int size) - throw(FilesystemFullException); + void writeOrderedBuffer(void *buffer, int size); protected: bool swapOrdering; CheckpointSize cSize; diff --git a/src/interpolate.cpp b/src/interpolate.cpp index 7ce0efd..3de19f5 100644 --- a/src/interpolate.cpp +++ b/src/interpolate.cpp @@ -66,7 +66,6 @@ Interpolate::~Interpolate() } double Interpolate::compute(double x) - throw (InvalidRangeException) { double y; @@ -85,7 +84,6 @@ double Interpolate::compute(double x) } double Interpolate::compute(double x) const - throw (InvalidRangeException) { double y; @@ -107,7 +105,6 @@ double Interpolate::compute(double x) const double Interpolate::derivative(double x) - throw (InvalidRangeException) { double y, dy, x0 = x; @@ -199,7 +196,6 @@ Interpolate CosmoTool::buildFromVector(const InterpolatePairs& v) } Interpolate CosmoTool::buildInterpolateFromFile(const char *fname) - throw (NoSuchFileException) { vector allData; ifstream f(fname); @@ -239,7 +235,6 @@ Interpolate CosmoTool::buildInterpolateFromFile(const char *fname) Interpolate CosmoTool::buildInterpolateFromColumns(const char *fname, uint32_t col1, uint32_t col2, bool logx, bool logy) - throw (NoSuchFileException,InvalidRangeException) { vector allData; ifstream f(fname); diff --git a/src/interpolate.hpp b/src/interpolate.hpp index 53acd46..e2f14f9 100644 --- a/src/interpolate.hpp +++ b/src/interpolate.hpp @@ -54,12 +54,9 @@ namespace CosmoTool bool logx = false, bool logy = false); ~Interpolate(); - double compute(double x) - throw (InvalidRangeException); - double compute(double x) const - throw (InvalidRangeException); - double derivative(double x) - throw (InvalidRangeException); + double compute(double x); + double compute(double x) const; + double derivative(double x); const Interpolate& operator=(const Interpolate& a); @@ -77,10 +74,8 @@ namespace CosmoTool typedef std::vector< std::pair > InterpolatePairs; - Interpolate buildInterpolateFromFile(const char *fname) - throw (NoSuchFileException); - Interpolate buildInterpolateFromColumns(const char *fname, uint32_t col1, uint32_t col2, bool logx = false, bool logy = false) - throw (NoSuchFileException,InvalidRangeException); + Interpolate buildInterpolateFromFile(const char *fname); + Interpolate buildInterpolateFromColumns(const char *fname, uint32_t col1, uint32_t col2, bool logx = false, bool logy = false); Interpolate buildFromVector(const InterpolatePairs& v); From 8cbec6637cddd2de5f06560262a7f31aeb9be76c Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 9 Aug 2017 17:31:06 +0300 Subject: [PATCH 3/6] Make configuration file compatible with Python3 and newer hdf5 --- CMakeLists.txt | 3 +-- FindPyLibs.cmake | 4 +++- external/external_build.cmake | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f6d3669..e1d4318 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,5 @@ cmake_minimum_required(VERSION 3.6) set(CMAKE_CXX_STANDARD 11) -cmake_policy(SET CMP0012 OLD) list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}") project(CosmoToolbox) @@ -54,7 +53,7 @@ IF(YORICK_SUPPORT) ENDIF((EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf AND ${NETCDFCPP_LIBRARY} MATCHES "netcdf_c\\+\\+4") OR (INTERNAL_NETCDF)) ENDIF(YORICK_SUPPORT) -find_program(CYTHON cython) +find_program(CYTHON cython3 cython) find_library(ZLIB z) find_library(DL_LIBRARY dl) find_library(MATH_LIBRARY m) diff --git a/FindPyLibs.cmake b/FindPyLibs.cmake index 2ef426a..f8d5bae 100644 --- a/FindPyLibs.cmake +++ b/FindPyLibs.cmake @@ -1,10 +1,12 @@ execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import distutils.sysconfig as cs; import os; v=cs.get_config_vars(); print(os.path.join(v['LIBDIR'],v['LDLIBRARY']));" + "import distutils.sysconfig as cs; import os; import sys; v=cs.get_config_vars(); print(os.path.join(v['LIBDIR'],v['LDLIBRARY'])); sys.exit(0)" RESULT_VARIABLE _PYLIB_SEARCH_SUCCESS OUTPUT_VARIABLE _PYLIB_VALUES_OUTPUT ERROR_VARIABLE _PYLIB_ERROR_VALUE OUTPUT_STRIP_TRAILING_WHITESPACE) +message(${_PYLIB_SEARCH_SUCCESS}) + execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import distutils.sysconfig as cs; import os; v=cs.get_config_vars(); print(v['INCLUDEPY']);" RESULT_VARIABLE _PYINC_SEARCH_SUCCESS diff --git a/external/external_build.cmake b/external/external_build.cmake index 0dbb313..33e9304 100644 --- a/external/external_build.cmake +++ b/external/external_build.cmake @@ -112,7 +112,12 @@ else (INTERNAL_HDF5) cmessage(STATUS "HDF5 lib: ${HDF5_LIBRARIES}") cmessage(STATUS "HDF5 includes: ${HDF5_INCLUDE_DIRS}") cmessage(STATUS "HDF5 C lib: ${HDF5_C_LIBRARY}") - get_filename_component(HDF5_BIN_DIR ${HDF5_C_LIBRARY} DIRECTORY) + cmessage(STATUS "HDF5 BIN: ${HDF5_BIN_DIR}") + foreach(hdf5lib IN LISTS HDF5_LIBRARIES) + if (${hdf5lib} MATCHES "(hdf5)|(HDF5)") + get_filename_component(HDF5_BIN_DIR ${hdf5lib} DIRECTORY) + endif() + endforeach() cmessage(STATUS "HDF5 libpath: ${HDF5_BIN_DIR}") else() cmessage(STATUS "Found HDF5 cmake config.") From 170e7b7020b610ded747f3b2d66a2f438616887e Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 9 Aug 2017 17:24:54 +0200 Subject: [PATCH 4/6] Fix compilation process. Fix compile error on new compiler --- external/external_build.cmake | 51 +++++++++++++++++++++++++---------- sample/simple3DFilter.cpp | 4 +-- sample/testSmooth.cpp | 4 +-- src/CMakeLists.txt | 28 +++++++++---------- 4 files changed, 55 insertions(+), 32 deletions(-) diff --git a/external/external_build.cmake b/external/external_build.cmake index 33e9304..ace4c8f 100644 --- a/external/external_build.cmake +++ b/external/external_build.cmake @@ -6,7 +6,8 @@ SET(FFTW_URL "http://www.fftw.org/fftw-3.3.3.tar.gz" CACHE URL "URL to download SET(EIGEN_URL "http://bitbucket.org/eigen/eigen/get/3.2.10.tar.gz" CACHE URL "URL to download Eigen from") SET(GENGETOPT_URL "ftp://ftp.gnu.org/gnu/gengetopt/gengetopt-2.22.5.tar.gz" CACHE STRING "URL to download gengetopt from") SET(HDF5_URL "https://support.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8/hdf5-1.8.18/src/hdf5-1.8.18.tar.gz" CACHE STRING "URL to download HDF5 from") -SET(NETCDF_URL "http://www.unidata.ucar.edu/downloads/netcdf/ftp/netcdf-4.1.3.tar.gz" CACHE STRING "URL to download NetCDF from") +SET(NETCDF_URL "ftp://ftp.unidata.ucar.edu/pub/netcdf/netcdf-4.4.1.1.tar.gz" CACHE STRING "URL to download NetCDF from") +SET(NETCDFCXX_URL "https://github.com/Unidata/netcdf-cxx4/archive/v4.3.0.tar.gz" CACHE STRING "URL to download NetCDF-C++ from") SET(BOOST_URL "http://sourceforge.net/projects/boost/files/boost/1.61.0/boost_1_61_0.tar.gz/download" CACHE STRING "URL to download Boost from") SET(GSL_URL "ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz" CACHE STRING "URL to download GSL from ") mark_as_advanced(FFTW_URL EIGEN_URL HDF5_URL NETCDF_URL BOOST_URL GSL_URL) @@ -77,13 +78,14 @@ if (INTERNAL_HDF5) ExternalProject_Add(hdf5 PREFIX ${BUILD_PREFIX}/hdf5-prefix URL ${HDF5_URL} - CONFIGURE_COMMAND ${HDF5_SOURCE_DIR}/configure - --disable-shared --enable-cxx --with-pic - --prefix=${HDF5_BIN_DIR} --libdir=${HDF5_BIN_DIR}/lib - CPPFLAGS=${CONFIGURE_CPP_FLAGS} CC=${CMAKE_C_COMPILER} - CXX=${CMAKE_CXX_COMPILER} - BUILD_IN_SOURCE 1 - INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + CMAKE_ARGS + -DCMAKE_INSTALL_PREFIX=${EXT_INSTALL} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DHDF5_BUILD_CPP_LIB=ON + -DHDF5_BUILD_TOOLS=ON + -DHDF5_BUILD_HL_LIB=ON + -DBUILD_SHARED_LIBS=OFF ) SET(cosmotool_DEPS ${cosmotool_DEPS} hdf5) SET(hdf5_built hdf5) @@ -142,7 +144,7 @@ endforeach(include_dir) if (INTERNAL_NETCDF) SET(NETCDF_SOURCE_DIR ${BUILD_PREFIX}/netcdf-prefix/src/netcdf) SET(NETCDF_BIN_DIR ${EXT_INSTALL}) -# SET(CONFIGURE_CPP_FLAGS "${CONFIGURE_CPP_FLAGS} -I${NETCDF_BIN_DIR}/include") + SET(CONFIGURE_CPP_FLAGS "${CONFIGURE_CPP_FLAGS} -I${NETCDF_BIN_DIR}/include") SET(CONFIGURE_LDFLAGS "${CONFIGURE_LDFLAGS} -L${NETCDF_BIN_DIR}/lib") SET(EXTRA_NC_FLAGS CPPFLAGS=${CONFIGURE_CPP_FLAGS} LIBS=${CONFIGURE_LIBS} LDFLAGS=${CONFIGURE_LDFLAGS}) SET(NETCDF_CONFIG_COMMAND ${NETCDF_SOURCE_DIR}/configure @@ -155,15 +157,36 @@ if (INTERNAL_NETCDF) DEPENDS ${hdf5_built} PREFIX ${BUILD_PREFIX}/netcdf-prefix URL ${NETCDF_URL} - CONFIGURE_COMMAND ${NETCDF_CONFIG_COMMAND} - BUILD_IN_SOURCE 1 - INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + CMAKE_ARGS + -DCMAKE_PREFIX_PATH=${EXT_INSTALL} + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DBUILD_SHARED_LIBS=OFF + -DBUILD_TESTING=OFF + -DCMAKE_BUILD_TYPE=Release + -DENABLE_NETCDF4=ON + -DENABLE_DAP=OFF + -DCMAKE_INSTALL_PREFIX=${NETCDF_BIN_DIR} + ) + + SET(NETCDFCXX_SOURCE_DIR ${BUILD_PREFIX}/netcdf-c++-prefix/src/netcdf-c++) + ExternalProject_Add(netcdf-c++ + DEPENDS ${hdf5_built} netcdf + PREFIX ${BUILD_PREFIX}/netcdf-c++-prefix + URL ${NETCDFCXX_URL} + CMAKE_ARGS + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DBUILD_SHARED_LIBS=OFF + -DBUILD_TESTING=OFF + -DCMAKE_BUILD_TYPE=Release + -DCMAKE_INSTALL_PREFIX=${NETCDF_BIN_DIR} ) # SET(CONFIGURE_CPP_LDFLAGS "${CONFIGURE_LDFLAGS}") # SET(EXTRA_NC_FLAGS CPPFLAGS=${CONFIGURE_CPP_FLAGS} LDFLAGS=${CONFIGURE_CPP_LDFLAGS}) - SET(cosmotool_DEPS ${cosmotool_DEPS} netcdf) + SET(cosmotool_DEPS ${cosmotool_DEPS} netcdf netcdf-c++) SET(NETCDF_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf.a CACHE STRING "NetCDF lib" FORCE) - SET(NETCDFCPP_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf_c++4.a CACHE STRING "NetCDF-C++ lib" FORCE) + SET(NETCDFCPP_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf-cxx4.a CACHE STRING "NetCDF-C++ lib" FORCE) SET(NETCDF_INCLUDE_PATH ${NETCDF_BIN_DIR}/include CACHE STRING "NetCDF include" FORCE) SET(NETCDFCPP_INCLUDE_PATH ${NETCDF_INCLUDE_PATH} CACHE STRING "NetCDF C++ include path" FORCE) diff --git a/sample/simple3DFilter.cpp b/sample/simple3DFilter.cpp index 114ea09..0b8d7da 100644 --- a/sample/simple3DFilter.cpp +++ b/sample/simple3DFilter.cpp @@ -62,7 +62,7 @@ void computeInterpolatedField(MyTree *tree1, double boxsize, int Nres, double cx { double px = (rx)*boxsize/Nres-cx; - MyTree::coords c = { px, py, pz }; + MyTree::coords c = { float(px), float(py), float(pz) }; double r2 = c[0]*c[0]+c[1]*c[1]+c[2]*c[2]; if (r2 > rLimit2) @@ -179,7 +179,7 @@ int main(int argc, char **argv) { double px = (rx)*boxsize/Nres-cx; - MyTree::coords c = { px, py, pz }; + MyTree::coords c = { float(px), float(py), float(pz) }; double r2 = c[0]*c[0]+c[1]*c[1]+c[2]*c[2]; if (r2 > rLimit2) diff --git a/sample/testSmooth.cpp b/sample/testSmooth.cpp index 14cd779..fcf4f87 100644 --- a/sample/testSmooth.cpp +++ b/sample/testSmooth.cpp @@ -75,7 +75,7 @@ int main() cout << "iy=" << iy << endl; for (uint32_t ix = 0; ix < NX; ix++) { - MyTree::coords c = { 1.0*ix/NX, 1.0*iy/NX }; + MyTree::coords c = { 1.0f*ix/NX, 1.0f*iy/NX }; smooth.fetchNeighbours(c); smooth.addGridSite(c); } @@ -92,7 +92,7 @@ int main() cout << "iy=" << iy << endl; for (uint32_t ix = 0; ix < NX; ix++) { - MyTree::coords c = { 1.0*ix/NX, 1.0*iy/NX }; + MyTree::coords c = { 1.0f*ix/NX, 1.0f*iy/NX }; smooth.fetchNeighbours(c, &state); out.put(smooth.computeSmoothedValue(c, unit_fun, &state)); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ca862c0..8b0c90e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,18 +1,18 @@ -SET(CosmoTool_SRCS - fortran.cpp - interpolate.cpp - load_data.cpp - loadRamses.cpp - powerSpectrum.cpp - miniargs.cpp - growthFactor.cpp - cosmopower.cpp - cic.cpp -) + SET(CosmoTool_SRCS + fortran.cpp + interpolate.cpp + load_data.cpp + loadRamses.cpp + powerSpectrum.cpp + miniargs.cpp + growthFactor.cpp + cosmopower.cpp + cic.cpp + ) -IF (Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) + IF (Boost_FOUND) + include_directories(${Boost_INCLUDE_DIRS}) SET(CosmoTool_SRCS ${CosmoTool_SRCS} loadGadget.cpp @@ -78,7 +78,7 @@ endif(YORICK_SUPPORT) if (HDF5_FOUND) set(CosmoTool_LIBS ${CosmoTool_LIBS} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES} ${HDF5_CXX_LIBRARIES} ${ZLIB}) - include_directories(${HDF5_INCLUDE_DIRS}) + include_directories(${HDF5_INCLUDE_DIR}) message(STATUS "CosmoTool_LIBS: ${CosmoTool_LIBS}") endif (HDF5_FOUND) From bf0874bbd36a9c9232ea0b89df4e47ebed0e9bdd Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 9 Aug 2017 17:42:02 +0200 Subject: [PATCH 5/6] Fixes to compile on OSX --- python/CMakeLists.txt | 6 +++++- python/_cosmo_bispectrum.cpp | 10 ++++++++++ python/_cosmotool.pyx | 9 ++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index bb2f745..f5c963d 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -1,5 +1,6 @@ set(CMAKE_SHARED_MODULE_PREFIX) + include_directories(${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src ${CMAKE_SOURCE_DIR}/python) IF(CYTHON) @@ -39,7 +40,10 @@ add_library(_project MODULE ${CMAKE_CURRENT_BINARY_DIR}/_project.cpp) -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Bsymbolic-functions") +SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Bsymbolic-functions") +if(APPLE) + set(CMAKE_MODULE_LINKER_FLAGS "-undefined dynamic_lookup") +endif() target_link_libraries(_cosmotool ${CosmoTool_local} ${PYTHON_LIBRARIES} ${GSL_LIBRARIES}) target_link_libraries(_cosmo_power ${CosmoTool_local} ${PYTHON_LIBRARIES} ${GSL_LIBRARIES}) diff --git a/python/_cosmo_bispectrum.cpp b/python/_cosmo_bispectrum.cpp index 94e6491..db6a6e0 100644 --- a/python/_cosmo_bispectrum.cpp +++ b/python/_cosmo_bispectrum.cpp @@ -1,4 +1,6 @@ +#ifdef _OPENMP #include +#endif #include #include #include @@ -171,7 +173,11 @@ void CosmoTool_compute_bispectrum( { // First remap to multi_array for easy access size_t kNz = Nz/2+1; +#ifdef _OPENMP int Ntasks = omp_get_max_threads(); +#else + int Ntasks = 1; +#endif boost::multi_array_ref, 3> a_delta(reinterpret_cast*>(delta_hat), boost::extents[Nx][Ny][kNz]); boost::multi_array_ref a_Nt(Ntriangles, boost::extents[Nk][Nk][Nk]); boost::multi_array_ref, 3> a_B(reinterpret_cast*>(B), boost::extents[Nk][Nk][Nk]); @@ -190,6 +196,7 @@ void CosmoTool_compute_bispectrum( delta_mirror[n1.i1][n1.i2][n1.i3] = std::conj(delta_mirror[n2.i1][n2.i2][n2.i3]); } +#ifdef _OPENMP // First loop over m1 #pragma omp parallel { @@ -236,6 +243,9 @@ void CosmoTool_compute_bispectrum( a_B_p[q] += b_B_p[q]; } } +#else +#warning Serial version not implemented +#endif } diff --git a/python/_cosmotool.pyx b/python/_cosmotool.pyx index 628e4e9..5ef1c1a 100644 --- a/python/_cosmotool.pyx +++ b/python/_cosmotool.pyx @@ -9,6 +9,9 @@ cimport cython np.import_array() +cdef extern from "sys/types.h": + ctypedef np.int64_t int64_t + cdef extern from "loadSimu.hpp" namespace "CosmoTool": cdef cppclass SimuData: @@ -20,7 +23,7 @@ cdef extern from "loadSimu.hpp" namespace "CosmoTool": np.float_t Omega_Lambda np.int64_t TotalNumPart np.int64_t NumPart - np.int64_t *Id + int64_t *Id float *Pos[3] float *Vel[3] int *type @@ -323,7 +326,7 @@ cdef object wrap_array(void *p, np.uint64_t s, int typ): cdef object wrap_float_array(float *p, np.uint64_t s): return wrap_array(p, s, np.NPY_FLOAT32) -cdef object wrap_int64_array(np.int64_t* p, np.uint64_t s): +cdef object wrap_int64_array(int64_t* p, np.uint64_t s): return wrap_array(p, s, np.NPY_INT64) cdef object wrap_int_array(int* p, np.uint64_t s): @@ -501,7 +504,7 @@ def writeGadget(str filename, object simulation): simdata.Vel[j] = vel.data ids = simulation.getIdentifiers() - simdata.Id = ids.data + simdata.Id = ids.data simdata.BoxSize = simulation.getBoxsize() simdata.time = simulation.getTime() simdata.Hubble = simulation.getHubble() From e80cf11f92d2bc026dd6215f6e597b2cddfbb67b Mon Sep 17 00:00:00 2001 From: Guilhem Lavaux Date: Wed, 9 Aug 2017 19:31:13 +0200 Subject: [PATCH 6/6] Compilation fixes --- python/_project.pyx | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/python/_project.pyx b/python/_project.pyx index ed07057..1f8f234 100644 --- a/python/_project.pyx +++ b/python/_project.pyx @@ -389,7 +389,8 @@ cdef void INTERNAL_project_cic_no_mass(npx.ndarray[DTYPE_t, ndim=3] g, npx.ndarray[DTYPE_t, ndim=2] x, int Ngrid, double Lbox, double shifter): cdef double delta_Box = Ngrid/Lbox cdef int i - cdef double a[3], c[3] + cdef double a[3] + cdef double c[3] cdef int b[3] cdef int do_not_put @@ -421,8 +422,10 @@ cdef void INTERNAL_project_cic_no_mass_periodic(npx.ndarray[DTYPE_t, ndim=3] g, npx.ndarray[DTYPE_t, ndim=2] x, int Ngrid, double Lbox, double shifter): cdef double delta_Box = Ngrid/Lbox cdef int i - cdef double a[3], c[3] - cdef int b[3], b1[3] + cdef double a[3] + cdef double c[3] + cdef int b[3] + cdef int b1[3] cdef int do_not_put cdef DTYPE_t[:,:] ax cdef DTYPE_t[:,:,:] ag @@ -462,7 +465,8 @@ cdef void INTERNAL_project_cic_with_mass(npx.ndarray[DTYPE_t, ndim=3] g, int Ngrid, double Lbox, double shifter): cdef double delta_Box = Ngrid/Lbox cdef int i - cdef double a[3], c[3] + cdef double a[3] + cdef double c[3] cdef DTYPE_t m0 cdef int b[3] @@ -499,8 +503,10 @@ cdef void INTERNAL_project_cic_with_mass_periodic(npx.ndarray[DTYPE_t, ndim=3] g cdef double half_Box = 0.5*Lbox, m0 cdef double delta_Box = Ngrid/Lbox cdef int i - cdef double a[3], c[3] - cdef int b[3], b1[3] + cdef double a[3] + cdef double c[3] + cdef int b[3] + cdef int b1[3] for i in range(x.shape[0]): @@ -547,18 +553,18 @@ def project_cic(npx.ndarray[DTYPE_t, ndim=2] x not None, npx.ndarray[DTYPE_t, nd if x.shape[1] != 3: raise ValueError("Invalid shape for x array") - if mass != None and mass.shape[0] != x.shape[0]: + if mass is not None and mass.shape[0] != x.shape[0]: raise ValueError("Mass array and coordinate array must have the same number of elements") g = np.zeros((Ngrid,Ngrid,Ngrid),dtype=DTYPE) if not periodic: - if mass == None: + if mass is None: INTERNAL_project_cic_no_mass(g, x, Ngrid, Lbox, shifter) else: INTERNAL_project_cic_with_mass(g, x, mass, Ngrid, Lbox, shifter) else: - if mass == None: + if mass is None: INTERNAL_project_cic_no_mass_periodic(g, x, Ngrid, Lbox, shifter) else: INTERNAL_project_cic_with_mass_periodic(g, x, mass, Ngrid, Lbox, shifter) @@ -626,7 +632,8 @@ cdef DTYPE_t cube_integral(DTYPE_t u[3], DTYPE_t u0[3], int r[1], DTYPE_t alpha_ @cython.cdivision(True) cdef DTYPE_t cube_integral_trilin(DTYPE_t u[3], DTYPE_t u0[3], int r[1], DTYPE_t vertex_value[8], DTYPE_t alpha_max) nogil: cdef DTYPE_t I, tmp_a - cdef DTYPE_t v[3], term[4] + cdef DTYPE_t v[3] + cdef DTYPE_t term[4] cdef int i, j, q j = 0 @@ -668,7 +675,8 @@ cdef DTYPE_t integrator1(DTYPE_t[:,:,:] density, DTYPE_t u[3], DTYPE_t u0[3], int u_delta[3], int iu0[3], int jumper[1], DTYPE_t alpha_max) nogil: cdef DTYPE_t vertex_value[8] cdef DTYPE_t d - cdef int a[3][2], i + cdef int a[3][2] + cdef int i for i in xrange(3): a[i][0] = iu0[i] @@ -694,7 +702,10 @@ cdef DTYPE_t C_line_of_sight_projection(DTYPE_t[:,:,:] density, DTYPE_t min_distance, DTYPE_t max_distance, DTYPE_t[:] shifter, int integrator_id) nogil except? 0: - cdef DTYPE_t u[3], ifu0[3], u0[3], utot[3] + cdef DTYPE_t u[3] + cdef DTYPE_t ifu0[3] + cdef DTYPE_t u0[3] + cdef DTYPE_t utot[3] cdef int u_delta[3] cdef int iu0[3] cdef int i