diff --git a/CMakeLists.txt b/CMakeLists.txt index b61f220..02a93d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,18 @@ ENDIF(BUILD_PYTHON) MESSAGE(STATUS "Using the target ${CosmoTool_local} to build python module") +find_package(ZLIB) +find_library(ZLIB_LIBRARY z) +find_library(DL_LIBRARY dl) +find_library(RT_LIBRARY rt) +if (RT_LIBRARY) + SET(RT_DEP rt) + message(STATUS "RT found, linking against it") +else() + SET(RT_DEP) +endif() +find_library(MATH_LIBRARY m) + include(${CMAKE_SOURCE_DIR}/external/external_build.cmake) IF(YORICK_SUPPORT) @@ -55,9 +67,6 @@ IF(YORICK_SUPPORT) ENDIF(YORICK_SUPPORT) find_program(CYTHON NAMES cython3 cython) -find_library(ZLIB_LIBRARY z) -find_library(DL_LIBRARY dl) -find_library(MATH_LIBRARY m) set(NETCDF_FIND_REQUIRED ${YORICK_SUPPORT}) set(GSL_FIND_REQUIRED TRUE) @@ -71,10 +80,10 @@ 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 "3") -SET(CPACK_PACKAGE_VERSION_PATCH "1${EXTRA_VERSION}") +SET(CPACK_PACKAGE_VERSION_PATCH "4${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 +SET(CPACK_SOURCE_IGNORE_FILES "/CVS/;/\\\\.git/;/\\\\.svn/;\\\\.swp$;\\\\.#;/#;.*~;cscope.*;/CMakeFiles/;.*\\\\.cmake;Makefile") add_subdirectory(src) diff --git a/MANIFEST.in b/MANIFEST.in index 5c4f363..105a2d6 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,4 +1,5 @@ include .gitignore +include pyproject.toml include CMakeLists.txt include FindNumPy.cmake include FindPyLibs.cmake @@ -16,14 +17,17 @@ include doc/source/cpplibrary.rst include doc/source/index.rst include doc/source/intro.rst include doc/source/pythonmodule.rst +include external/config.guess +include external/config.sub include external/external_build.cmake -include external/libsharp-6077806.tar.gz +include external/libsharp-8d51946.tar.gz include external/omptl-20120422.tar.bz2 include external/patch-omptl include python/CMakeLists.txt include python/_cosmo_bispectrum.cpp include python/_cosmo_cic.pyx include python/_cosmo_power.pyx +include python/_cosmomath.pyx include python/_cosmotool.pyx include python/_fast_interp.pyx include python/_project.pyx @@ -93,6 +97,7 @@ include sample/testkd3.cpp include setup.py include src/CMakeLists.txt include src/algo.hpp +include src/numpy_adaptors.hpp include src/bqueue.hpp include src/bqueue.tcc include src/bsp_simple.hpp diff --git a/builder/build-wheels.sh b/builder/build-wheels.sh index 60a8bfc..8f529dd 100755 --- a/builder/build-wheels.sh +++ b/builder/build-wheels.sh @@ -16,7 +16,7 @@ ln -fs /usr/bin/cmake3 /usr/bin/cmake test -d /io/wheelhouse || mkdir /io/wheelhouse test -d /io/wheelhouse/fix || mkdir /io/wheelhouse/fix -ALL_PYTHON="cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310" +ALL_PYTHON="cp39-cp39 cp310-cp310" # Compile wheels for pkg in $ALL_PYTHON; do @@ -24,11 +24,11 @@ for pkg in $ALL_PYTHON; do # "${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/ + "${PYBIN}/pip" wheel -vvv /io/ -w /io/wheelhouse/ done # Bundle external shared libraries into the wheels -for whl in /io/wheelhouse/cosmotool*.whl; do +for whl in /io/wheelhouse/cosmotool*linux*.whl; do auditwheel repair "$whl" --plat $PLAT -w /io/wheelhouse/fix done diff --git a/builder/start.sh b/builder/start.sh index 9fbc185..31f95f0 100755 --- a/builder/start.sh +++ b/builder/start.sh @@ -9,4 +9,4 @@ if ! [ -e ${d}/setup.py ] ; then exit 1 fi -podman run -ti --rm -e PLAT=manylinux2010_x86_64 -v ${d}:/io:Z quay.io/pypa/manylinux2010_x86_64 /io/builder/build-wheels.sh +podman run -ti --rm -e PLAT=manylinux2014_x86_64 -v ${d}:/io:Z quay.io/pypa/manylinux2014_x86_64 /io/builder/build-wheels.sh diff --git a/external/external_build.cmake b/external/external_build.cmake index c0e73eb..54a9a27 100644 --- a/external/external_build.cmake +++ b/external/external_build.cmake @@ -2,6 +2,7 @@ include(FindOpenMP) OPTION(ENABLE_OPENMP "Set to Yes if Healpix and/or you need openMP" OFF) +SET(SOURCE_PREFIX ${CMAKE_SOURCE_DIR}) SET(FFTW_URL "http://www.fftw.org/fftw-3.3.3.tar.gz" CACHE STRING "URL to download FFTW from") SET(EIGEN_URL "https://gitlab.com/libeigen/eigen/-/archive/3.3.7/eigen-3.3.7.tar.bz2" CACHE STRING "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") @@ -12,6 +13,8 @@ SET(BOOST_URL "https://boostorg.jfrog.io/artifactory/main/release/1.82.0/source/ SET(GSL_URL "https://ftpmirror.gnu.org/gsl/gsl-2.7.tar.gz" CACHE STRING "URL to download GSL from ") mark_as_advanced(FFTW_URL EIGEN_URL HDF5_URL NETCDF_URL BOOST_URL GSL_URL) +file(MAKE_DIRECTORY ${SOURCE_PREFIX}/downloads) + SET(all_deps) MACRO(CHECK_CHANGE_STATE VAR) @@ -36,12 +39,13 @@ CHECK_CHANGE_STATE(INTERNAL_DLIB DLIB_INCLUDE_DIR DLIB_LIBRARIES) IF(ENABLE_OPENMP) IF (NOT OPENMP_FOUND) - MESSAGE(ERROR "No known compiler option for enabling OpenMP") + MESSAGE(NOTICE "No known compiler option for enabling OpenMP") + ELSE() + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}") ENDIF(NOT OPENMP_FOUND) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_C_FLAGS}") ENDIF(ENABLE_OPENMP) @@ -55,21 +59,25 @@ if (ENABLE_SHARP) SET(DEP_BUILD ${BUILD_PREFIX}/sharp-prefix/src/sharp/auto) IF(NOT ENABLE_OPENMP) SET(SHARP_OPENMP --disable-openmp) + ELSE() + SET(SHARP_OPENMP) ENDIF() SET(CUTILS_LIBRARY ${DEP_BUILD}/lib/libc_utils.a) SET(FFTPACK_LIBRARY ${DEP_BUILD}/lib/libfftpack.a) SET(SHARP_LIBRARY ${DEP_BUILD}/lib/libsharp.a) SET(SHARP_LIBRARIES ${SHARP_LIBRARY} ${FFTPACK_LIBRARY} ${CUTILS_LIBRARY}) SET(SHARP_INCLUDE_PATH ${DEP_BUILD}/include) + message(STATUS "Flags: ${CMAKE_C_FLAGS}") ExternalProject_Add(sharp - URL ${CMAKE_SOURCE_DIR}/external/libsharp-6077806.tar.gz + URL ${CMAKE_SOURCE_DIR}/external/libsharp-8d51946.tar.gz PREFIX ${BUILD_PREFIX}/sharp-prefix + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads BUILD_IN_SOURCE 1 CONFIGURE_COMMAND cp -f ${CMAKE_SOURCE_DIR}/external/config.guess . && cp -f ${CMAKE_SOURCE_DIR}/external/config.sub . && autoconf && - ./configure "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" --prefix=${DEP_BUILD} ${SHARP_OPENMP} + ./configure "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" "CFLAGS=${CMAKE_C_FLAGS}" "LDFLAGS=${CMAKE_EXE_LINKER_FLAGS}" --prefix=${DEP_BUILD} ${SHARP_OPENMP} INSTALL_COMMAND echo "No install" BUILD_BYPRODUCTS ${SHARP_LIBRARIES} ) @@ -87,22 +95,17 @@ if (INTERNAL_HDF5) PREFIX ${BUILD_PREFIX}/hdf5-prefix URL ${HDF5_URL} URL_HASH MD5=30172c75e436d7f2180e274071a4ca97 - 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 - -DHDF5_ENABLE_Z_LIB_SUPPORT=ON + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads + CONFIGURE_COMMAND + ${HDF5_SOURCE_DIR}/configure "CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}" "CFLAGS=${CMAKE_C_FLAGS}" "LDFLAGS=${CMAKE_EXE_LINKER_FLAGS}" --prefix=${HDF5_BIN_DIR} --disable-shared --enable-cxx --enable-hl --enable-tools --with-pic + INSTALL_COMMAND make install ) SET(cosmotool_DEPS ${cosmotool_DEPS} hdf5) SET(hdf5_built hdf5) SET(ENV{HDF5_ROOT} ${HDF5_BIN_DIR}) SET(HDF5_ROOTDIR ${HDF5_BIN_DIR}) SET(CONFIGURE_LDFLAGS "${CONFIGURE_LDFLAGS} -L${HDF5_BIN_DIR}/lib") - SET(CONFIGURE_LIBS "${CONFIGURE_LIBS} -ldl") + SET(CONFIGURE_LIBS "${CONFIGURE_LIBS} -ldl ${RT_LIBRARY}") set(HDF5_C_STATIC_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5.a) set(HDF5_HL_STATIC_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5_hl.a) set(HDF5_LIBRARIES ${HDF5_BIN_DIR}/lib/libhdf5.a CACHE STRING "HDF5 lib" FORCE) @@ -172,37 +175,45 @@ if (INTERNAL_NETCDF) string(REPLACE ";" "|" CMAKE_PREFIX_PATH_ALT_SEP "${CMAKE_PREFIX_PATH}") ExternalProject_Add(netcdf DEPENDS ${hdf5_built} + URL_HASH MD5=f48ee01534365006934f0c63d4055ea0 PREFIX ${BUILD_PREFIX}/netcdf-prefix + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads URL ${NETCDF_URL} - LIST_SEPARATOR | - CMAKE_ARGS + LIST_SEPARATOR | + CMAKE_ARGS -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH_ALT_SEP} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DNC_EXTRA_DEPS=${RT_DEP} -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DENABLE_NETCDF4=ON -DENABLE_BYTERANGE=FALSE - -DCMAKE_POSITION_INDEPENDENT_CODE=ON - -DENABLE_DAP=OFF + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DENABLE_DAP=OFF -DCMAKE_INSTALL_PREFIX=${NETCDF_BIN_DIR} -DHDF5_C_LIBRARY=${HDF5_C_STATIC_LIBRARY} -DHDF5_HL_LIBRARY=${HDF5_HL_STATIC_LIBRARY} -DHDF5_INCLUDE_DIR=${HDF5_INCLUDE_DIRS} - -DCMAKE_INSTALL_LIBDIR=lib + -DCMAKE_INSTALL_LIBDIR=lib ) 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 + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads URL ${NETCDFCXX_URL} CMAKE_ARGS + -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH_ALT_SEP} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DBUILD_SHARED_LIBS=OFF - -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + -DHDF5_C_LIBRARY=${HDF5_C_STATIC_LIBRARY} + -DHDF5_HL_LIBRARY=${HDF5_HL_STATIC_LIBRARY} + -DHDF5_INCLUDE_DIR=${HDF5_INCLUDE_DIRS} -DBUILD_TESTING=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=${NETCDF_BIN_DIR} @@ -240,6 +251,7 @@ if (INTERNAL_BOOST) ExternalProject_Add(boost URL ${BOOST_URL} PREFIX ${BUILD_PREFIX}/boost-prefix + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads URL_HASH MD5=f7050f554a65f6a42ece221eaeec1660 CONFIGURE_COMMAND ${BOOST_SOURCE_DIR}/bootstrap.sh --prefix=${CMAKE_BINARY_DIR}/ext_build/boost @@ -283,6 +295,7 @@ IF(INTERNAL_GSL) ExternalProject_Add(gsl URL ${GSL_URL} PREFIX ${BUILD_PREFIX}/gsl-prefix + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads CONFIGURE_COMMAND ${GSL_SOURCE_DIR}/configure --prefix=${EXT_INSTALL} --disable-shared --with-pic @@ -335,6 +348,7 @@ IF(INTERNAL_FFTW) ExternalProject_Add(fftw URL ${FFTW_URL} PREFIX ${BUILD_PREFIX}/fftw-prefix + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads CONFIGURE_COMMAND ${FFTW_SOURCE}/configure --prefix=${EXT_INSTALL} @@ -364,10 +378,12 @@ IF (INTERNAL_EIGEN) ExternalProject_Add(eigen URL ${EIGEN_URL} URL_HASH MD5=b9e98a200d2455f06db9c661c5610496 + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads PREFIX ${BUILD_PREFIX}/eigen-prefix CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXT_INSTALL} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} + -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ) SET(EIGEN3_INCLUDEDIR ${EXT_INSTALL}/include/eigen3) @@ -396,6 +412,7 @@ SET(cosmotool_DEPS ${cosmotool_DEPS} omptl) SET(OMPTL_BUILD_DIR ${BUILD_PREFIX}/omptl-prefix/src/omptl) ExternalProject_Add(omptl PREFIX ${BUILD_PREFIX}/omptl-prefix + DOWNLOAD_DIR ${SOURCE_PREFIX}/downloads URL ${CMAKE_SOURCE_DIR}/external/omptl-20120422.tar.bz2 CONFIGURE_COMMAND echo "No configure" BUILD_COMMAND echo "No build" diff --git a/external/libsharp-8d51946.tar.gz b/external/libsharp-8d51946.tar.gz new file mode 100644 index 0000000..7ca7602 Binary files /dev/null and b/external/libsharp-8d51946.tar.gz differ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..7a031e7 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,8 @@ +[build-system] +requires = ["setuptools","wheel","cython"] +build-backend = "setuptools.build_meta" + + +[tool.towncrier] +directory = "changes" + diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 7eda7ac..1b3fe10 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -2,7 +2,7 @@ set(CMAKE_SHARED_MODULE_PREFIX) set(PYTHON_INCLUDES ${NUMPY_INCLUDE_DIRS} ${PYTHON_INCLUDE_PATH} ${CMAKE_SOURCE_DIR}/python) -include_directories(${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src) +include_directories(${CMAKE_SOURCE_DIR}/python ${CMAKE_SOURCE_DIR}/src ${CMAKE_BINARY_DIR}/src) IF(CYTHON) add_custom_command( @@ -69,13 +69,10 @@ target_link_libraries(_fast_interp PRIVATE ${CosmoTool_local} ) SET(ct_TARGETS _cosmotool _project _cosmo_power _cosmo_cic _fast_interp _cosmomath) if (Boost_FOUND) - message(STATUS "Building bispectrum support (path = ${Boost_INCLUDE_DIRS})") + message(STATUS "Building bispectrum support") include_directories(${Boost_INCLUDE_DIRS}) add_library(_cosmo_bispectrum MODULE _cosmo_bispectrum.cpp) target_link_libraries(_cosmo_bispectrum ${MATH_LIBRARY}) - if(ENABLE_OPENMP) - set_target_properties(_cosmo_bispectrum PROPERTIES COMPILE_FLAGS "${OpenMP_CXX_FLAGS}" LINK_FLAGS "${OpenMP_CXX_FLAGS}") - endif() if (Boost_DEP) add_dependencies(_cosmo_bispectrum ${Boost_DEP}) endif() diff --git a/python/_cosmomath.pyx b/python/_cosmomath.pyx index e5ab880..fc4b3b6 100644 --- a/python/_cosmomath.pyx +++ b/python/_cosmomath.pyx @@ -12,7 +12,7 @@ cdef extern from "numpy/npy_common.h": ctypedef npy_intp cdef extern from "special_math.hpp" namespace "CosmoTool": - T log_modified_bessel_first_kind[T](T v, T z) nogil except + + T log_modified_bessel_first_kind[T](T v, T z) except + nogil cdef extern from "numpy_adaptors.hpp" namespace "CosmoTool": void parallel_ufunc_dd_d[T,IT](char **args, IT* dimensions, IT* steps, void *func) diff --git a/python/_cosmotool.pyx b/python/_cosmotool.pyx index b2494bd..7f2bc76 100644 --- a/python/_cosmotool.pyx +++ b/python/_cosmotool.pyx @@ -39,7 +39,7 @@ cdef extern from "loadSimu.hpp" namespace "CosmoTool": cdef extern from "loadGadget.hpp" namespace "CosmoTool": - SimuData *loadGadgetMulti(const char *fname, int id, int flags, int gformat) nogil except + + SimuData *loadGadgetMulti(const char *fname, int id, int flags, int gformat) except + nogil void cxx_writeGadget "CosmoTool::writeGadget" (const char * s, SimuData *data) except + cdef extern from "safe_gadget.hpp": @@ -313,6 +313,13 @@ tries to get an array from the object.""" references to the object are gone. """ pass + +cdef extern from "numpy/arrayobject.h": + # a little bit awkward: the reference to obj will be stolen + # using PyObject* to signal that Cython cannot handle it automatically + int PyArray_SetBaseObject(np.ndarray arr, PyObject *obj) except -1 # -1 means there was an error + + cdef object wrap_array(void *p, np.uint64_t s, int typ): cdef np.ndarray ndarray cdef ArrayWrapper wrapper @@ -320,7 +327,8 @@ cdef object wrap_array(void *p, np.uint64_t s, int typ): wrapper = ArrayWrapper() wrapper.set_data(s, typ, p) ndarray = np.array(wrapper, copy=False) - ndarray.base = wrapper + #ndarray.base = wrapper + PyArray_SetBaseObject(ndarray, wrapper) Py_INCREF(wrapper) return ndarray diff --git a/python/_project.pyx b/python/_project.pyx index bd64667..726ed0c 100644 --- a/python/_project.pyx +++ b/python/_project.pyx @@ -727,7 +727,7 @@ cdef DTYPE_t C_line_of_sight_projection(DTYPE_t[:,:,:] density, cdef int iu0[3] cdef int i cdef int N = density.shape[0] - cdef int half_N = density.shape[0]/2 + cdef int half_N = density.shape[0]//2 cdef int completed cdef DTYPE_t I0, d, dist2, delta, s, max_distance2 cdef int jumper[1] diff --git a/requirements.txt b/requirements.txt index 8342e0f..922eaeb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,4 @@ numpy<1.22 cffi numexpr -pyfftw -cython +cython<3 diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 03709a7..6d019a7 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -1,4 +1,8 @@ SET(tolink ${CosmoTool_local} ${CosmoTool_LIBS} ${GSL_LIBRARIES} ${DL_LIBRARY}) +if (RT_LIBRARY) + SET(tolink ${tolink} ${RT_LIBRARY}) +endif() + include_directories(${CMAKE_SOURCE_DIR}/src) include_directories(${FFTW3_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIRS} ${GSL_INCLUDE_PATH}) if(YORICK_SUPPORT) diff --git a/sample/simple3DFilter.cpp b/sample/simple3DFilter.cpp index e075b06..2dbde42 100644 --- a/sample/simple3DFilter.cpp +++ b/sample/simple3DFilter.cpp @@ -84,6 +84,7 @@ int main(int argc, char **argv) { char *fname1, *outFile; double rLimit, boxsize, rLimit2, cx, cy, cz; int Nres; + int periodic; MiniArgDesc args[] = {{"INPUT DATA1", &fname1, MINIARG_STRING}, {"RADIUS LIMIT", &rLimit, MINIARG_DOUBLE}, @@ -93,6 +94,7 @@ int main(int argc, char **argv) { {"CY", &cy, MINIARG_DOUBLE}, {"CZ", &cz, MINIARG_DOUBLE}, {"OUTPUT FILE", &outFile, MINIARG_STRING}, + {"PERIODIC", &periodic, MINIARG_INT}, {0, 0, MINIARG_NULL}}; if (!parseMiniArgs(argc, argv, args)) @@ -148,6 +150,7 @@ int main(int argc, char **argv) { cout << "Building trees..." << endl; MyTree tree1(allCells_1, N1_points); + tree1.setPeriodic(periodic != 0, boxsize); cout << "Creating smoothing filter..." << endl; diff --git a/setup.py b/setup.py index f9b7042..0b98cce 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import stat import os import sys import shutil +from sysconfig import get_config_var from distutils.command.install_data import install_data import pathlib from setuptools import find_packages, setup, Extension @@ -76,9 +77,9 @@ class InstallCMakeLibs(install_lib): # # your files are moved to the appropriate location when the installation # # is run # -# libs = [os.path.join(bin_dir, _lib) for _lib in -# os.listdir(bin_dir) if -# os.path.isfile(os.path.join(bin_dir, _lib)) and +# libs = [os.path.join(bin_dir, _lib) for _lib in +# os.listdir(bin_dir) if +# os.path.isfile(os.path.join(bin_dir, _lib)) and # os.path.splitext(_lib)[1] in [".dll", ".so"] # and not (_lib.startswith("python") or _lib.startswith(PACKAGE_NAME))] # @@ -87,16 +88,16 @@ class InstallCMakeLibs(install_lib): # shutil.move(lib, os.path.join(self.build_dir, # os.path.basename(lib))) # -# # Mark the libs for installation, adding them to -# # distribution.data_files seems to ensure that setuptools' record +# # Mark the libs for installation, adding them to +# # distribution.data_files seems to ensure that setuptools' record # # writer appends them to installed-files.txt in the package's egg-info # # -# # Also tried adding the libraries to the distribution.libraries list, -# # but that never seemed to add them to the installed-files.txt in the -# # egg-info, and the online recommendation seems to be adding libraries -# # into eager_resources in the call to setup(), which I think puts them -# # in data_files anyways. -# # +# # Also tried adding the libraries to the distribution.libraries list, +# # but that never seemed to add them to the installed-files.txt in the +# # egg-info, and the online recommendation seems to be adding libraries +# # into eager_resources in the call to setup(), which I think puts them +# # in data_files anyways. +# # # # What is the best way? # # # These are the additional installation files that should be @@ -104,7 +105,7 @@ class InstallCMakeLibs(install_lib): # # step; depending on the files that are generated from your cmake # # build chain, you may need to modify the below code # -# self.distribution.data_files = [os.path.join(self.install_dir, +# self.distribution.data_files = [os.path.join(self.install_dir, # os.path.basename(lib)) # for lib in libs] # print(self.distribution.data_files) @@ -167,17 +168,24 @@ 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 + c_compiler=os.environ.get('CC', get_config_var("CC")) + cxx_compiler=os.environ.get('CXX', get_config_var("CXX")) + compilers=[] fill_up_settings=[ - ("CMAKE_C_COMPILER", "CC"), - ("CMAKE_CXX_COMPILER", "CXX"), - ("CMAKE_C_FLAGS", "CFLAGS"), - ("CMAKE_EXE_LINKER_FLAGS_INIT", "LDFLAGS"), - ("CMAKE_SHARED_LINKER_FLAGS_INIT", "LDFLAGS"), - ("CMAKE_MODULE_LINKER_FLAGS_INIT", "LDFLAGS")] - for cmake_flag, os_flag in fill_up_settings: - if os_flag in os.environ: - compilers.append(f"-D{cmake_flag}={os.environ[os_flag]}") + ("CMAKE_C_COMPILER", "CC", get_config_var("CC")), + ("CMAKE_CXX_COMPILER", "CXX", get_config_var("CXX")), + ("CMAKE_C_FLAGS", "CFLAGS", None), + ("CMAKE_CXX_FLAGS", "CXXFLAGS", None), + ("CMAKE_EXE_LINKER_FLAGS_INIT", "LDFLAGS", None), + ("CMAKE_SHARED_LINKER_FLAGS_INIT", "LDFLAGS", None), + ("CMAKE_MODULE_LINKER_FLAGS_INIT", "LDFLAGS", None)] + for cmake_flag, os_flag, default_flag in fill_up_settings: + if os_flag in os.environ or default_flag is not None: + c = os.environ.get(os_flag, default_flag) + if not c is None: + compilers.append(f"-D{cmake_flag}={c}") + print(compilers) self.spawn(['cmake', '-H'+SOURCE_DIR, '-B'+self.build_temp, '-DENABLE_OPENMP=ON','-DINTERNAL_BOOST=ON','-DINTERNAL_EIGEN=ON', @@ -213,7 +221,7 @@ class BuildCMakeExt(build_ext): if _pyd_top[0].startswith(PACKAGE_NAME): if os.path.splitext(_pyd)[1] in [".pyd", ".so"] or _pyd_top[-1] == 'config.py': pyd_path.append((_pyd_top,_pyd)) - + for top,p in pyd_path: _,n = os.path.split(p) @@ -229,10 +237,10 @@ class BuildCMakeExt(build_ext): CosmoTool_extension = CMakeExtension(name="cosmotool") setup(name='cosmotool', - version='1.3.2', + version='1.3.6', packages=["cosmotool"], package_dir={'cosmotool': 'python/cosmotool'}, - install_requires=['numpy','cffi','numexpr','pyfftw','h5py'], + install_requires=['cython','numpy','cffi','numexpr','h5py'], setup_requires=['cython','cffi','numpy','numexpr'], ext_modules=[CosmoTool_extension], description='A small cosmotool box of useful functions', diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c075396..944aa80 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 @@ -39,7 +39,7 @@ if (HDF5_FOUND) loadFlash.cpp ) add_dependencies(CosmoHDF5 ${cosmotool_DEPS}) - set_property(TARGET CosmoHDF5 PROPERTY POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}) + set_property(TARGET CosmoHDF5 PROPERTY POSITION_INDEPENDENT_CODE ON) target_include_directories(CosmoHDF5 BEFORE PRIVATE ${HDF5_INCLUDE_DIR}) else(HDF5_FOUND) add_library(CosmoHDF5 OBJECT diff --git a/src/hdf5_array.hpp b/src/hdf5_array.hpp index db75a33..55dc87b 100644 --- a/src/hdf5_array.hpp +++ b/src/hdf5_array.hpp @@ -426,7 +426,7 @@ namespace CosmoTool { #define CTOOL_HDF5_INSERT_ELEMENT(r, STRUCT, element) \ { \ ::CosmoTool::get_hdf5_data_type t; \ - long position = HOFFSET(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \ + long position = offsetof(STRUCT, BOOST_PP_TUPLE_ELEM(2, 1, element)); \ const char *field_name = BOOST_PP_STRINGIZE(BOOST_PP_TUPLE_ELEM(2, 1, element)); \ type.insertMember(field_name, position, t.type()); \ } diff --git a/src/interpolate.cpp b/src/interpolate.cpp index 3de19f5..b996f7a 100644 --- a/src/interpolate.cpp +++ b/src/interpolate.cpp @@ -157,6 +157,7 @@ const Interpolate& Interpolate::operator=(const Interpolate& a) gsl_spline_init(spline, a.spline->x, a.spline->y, a.spline->size); logx = a.logx; logy = a.logy; + return *this; } double Interpolate::getMaxX() const diff --git a/src/sphSmooth.hpp b/src/sphSmooth.hpp index fdada71..f9c468b 100644 --- a/src/sphSmooth.hpp +++ b/src/sphSmooth.hpp @@ -72,7 +72,9 @@ namespace CosmoTool { void fetchNeighbours(const typename SPHTree::coords &c, SPHState *state = 0); - void fetchNeighbours(const typename SPHTree::coords &c, uint32_t newNsph); + void fetchNeighbours( + const typename SPHTree::coords &c, uint32_t newNsph, + SPHState *state = 0); void fetchNeighboursOnVolume( const typename SPHTree::coords &c, ComputePrecision radius); const typename SPHTree::coords &getCurrentCenter() const { diff --git a/src/sphSmooth.tcc b/src/sphSmooth.tcc index c163feb..6643dd3 100644 --- a/src/sphSmooth.tcc +++ b/src/sphSmooth.tcc @@ -35,32 +35,38 @@ namespace CosmoTool { template void SPHSmooth::fetchNeighbours( - const typename SPHTree::coords &c, uint32_t newNngb) { + const typename SPHTree::coords &c, uint32_t newNngb, SPHState *state) { ComputePrecision d2, max_dist = 0; uint32_t requested = newNngb; - if (requested > maxNgb) { - maxNgb = requested; - internal.ngb = boost::shared_ptr(new P_SPHCell[maxNgb]); - internal.distances = - boost::shared_ptr(new CoordType[maxNgb]); + if (state != 0) { + state->distances = boost::shared_ptr(new CoordType[newNngb]); + state->ngb = boost::shared_ptr(new SPHCell *[newNngb]); + } else { + state = &internal; + if (requested > maxNgb) { + maxNgb = requested; + internal.ngb = boost::shared_ptr(new P_SPHCell[maxNgb]); + internal.distances = + boost::shared_ptr(new CoordType[maxNgb]); + } } - memcpy(internal.currentCenter, c, sizeof(c)); + memcpy(state->currentCenter, c, sizeof(c)); tree->getNearestNeighbours( - c, requested, (SPHCell **)internal.ngb.get(), - (CoordType *)internal.distances.get()); + c, requested, (SPHCell **)state->ngb.get(), + (CoordType *)state->distances.get()); - internal.currentNgb = 0; - for (uint32_t i = 0; i < requested && (internal.ngb)[i] != 0; - i++, internal.currentNgb++) { - internal.distances[i] = sqrt(internal.distances[i]); - d2 = internal.distances[i]; + state->currentNgb = 0; + for (uint32_t i = 0; i < requested && (state->ngb)[i] != 0; + i++, state->currentNgb++) { + state->distances[i] = sqrt(state->distances[i]); + d2 = state->distances[i]; if (d2 > max_dist) max_dist = d2; } - internal.smoothRadius = max_dist / 2; + state->smoothRadius = max_dist / 2; } template @@ -206,7 +212,7 @@ namespace CosmoTool { ComputePrecision d = state->distances[i]; SPHCell &cell = *(state->ngb[i]); double kernel_value = getKernel(d / state->smoothRadius) / r3; -#pragma omp atomic +#pragma omp atomic update cell.val.weight += kernel_value; } } @@ -241,5 +247,4 @@ namespace CosmoTool { const SPHSmooth &s2) { return (s1.getSmoothingLen() < s2.getSmoothingLen()); } - }; // namespace CosmoTool