diff --git a/CMakeLists.txt b/CMakeLists.txt index 1094098..ecf5f9f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,20 +5,22 @@ project(CosmoToolbox) include(GetGitRevisionDescription) include(ExternalProject) -include(FindOpenMP) +include(FindPkgConfig) +include(FindPackageHandleStandardArgs) include(FindPythonInterp) set(NumPy_FIND_REQUIRED TRUE) include(${CMAKE_SOURCE_DIR}/FindPyLibs.cmake) include(${CMAKE_SOURCE_DIR}/FindNumPy.cmake) - get_git_head_revision(HEAD GIT_VER) option(BUILD_SHARED_LIBS "Build shared libraries." OFF) option(BUILD_STATIC_LIBS "Build static libraries." ON) -option(ENABLE_OPENMP "Enable OpenMP support." OFF) -option(ENABLE_SHARP "Enable SPHT support." ON) +option(ENABLE_SHARP "Enable SHARP support." ON) +option(INTERNAL_HDF5 "Build internal version of HDF5" OFF) +option(INTERNAL_NETCDF "Build internal version of NETCDF" OFF) +option(INTERNAL_BOOST "Build internal version of BOOST" OFF) IF(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) SET(CosmoTool_local CosmoTool_static) @@ -26,10 +28,7 @@ ELSE(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) SET(CosmoTool_local CosmoTool) ENDIF(BUILD_SHARED_LIBS AND BUILD_STATIC_LIBS) -find_path(NETCDF_INCLUDE_PATH NAMES netcdf.h) -find_path(NETCDFCPP_INCLUDE_PATH NAMES netcdfcpp.h netcdf) -find_path(GSL_INCLUDE_PATH NAMES gsl/gsl_blas.h) -find_library(NETCDFCPP_LIBRARY NAMES netcdf_c++ netcdf_c++4) +include(${CMAKE_SOURCE_DIR}/external/external_build.cmake) IF(EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf AND ${NETCDFCPP_LIBRARY} MATCHES "netcdf_c\\+\\+4") SET(FOUND_NETCDF4 1) @@ -39,52 +38,20 @@ ELSE(EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf AND ${NETCDFCPP_LIBRARY} MATCHES "n FILE(WRITE ${CMAKE_BINARY_DIR}/src/ctool_netcdf_ver.hpp "#undef NETCDFCPP4") ENDIF(EXISTS ${NETCDFCPP_INCLUDE_PATH}/netcdf AND ${NETCDFCPP_LIBRARY} MATCHES "netcdf_c\\+\\+4") -find_library(NETCDF_LIBRARY netcdf) -find_library(GSL_LIBRARY gsl) -find_library(GSLCBLAS_LIBRARY gslcblas) - find_program(CYTHON cython) -find_package(Boost 1.53) - -include(${CMAKE_SOURCE_DIR}/external/external_build.cmake) - set(HDF5_FIND_COMPONENTS HL CXX) if(HDF5_ROOTDIR) SET(ENV{HDF5_ROOT} ${HDF5_ROOTDIR}) endif(HDF5_ROOTDIR) include(FindHDF5) -include(FindPkgConfig) -pkg_check_modules(FFTW3 fftw3>=3.3) -pkg_check_modules(FFTW3F fftw3f>=3.3) -pkg_check_modules(EIGEN3 eigen3) - - -find_library(FFTW3F_LIBRARY_FULL fftw3f PATHS ${FFTW3F_LIBDIR} NO_DEFAULT_PATH) -find_library(FFTW3_LIBRARY_FULL fftw3 PATHS ${FFTW3_LIBDIR} NO_DEFAULT_PATH) - -include(FindPackageHandleStandardArgs) set(NETCDF_FIND_REQUIRED TRUE) set(GSL_FIND_REQUIRED TRUE) FIND_PACKAGE_HANDLE_STANDARD_ARGS(NetCDF DEFAULT_MSG NETCDF_LIBRARY NETCDFCPP_LIBRARY NETCDF_INCLUDE_PATH) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSL DEFAULT_MSG GSL_LIBRARY GSLCBLAS_LIBRARY GSL_INCLUDE_PATH) -IF(ENABLE_OPENMP) - - IF (NOT OPENMP_FOUND) - MESSAGE(ERROR "No known compiler option for enabling OpenMP") - 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) - - - -set(GSL_LIBRARIES ${GSL_LIBRARY} ${GSLCBLAS_LIBRARY}) # CPACK Configuration SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A toolbox for impatient cosmologists") diff --git a/external/external_build.cmake b/external/external_build.cmake index 93f02a5..edbf6ae 100644 --- a/external/external_build.cmake +++ b/external/external_build.cmake @@ -1,3 +1,30 @@ +include(FindOpenMP) + +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.1.4.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 "http://www.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8.9/src/hdf5-1.8.9.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.49.0/boost_1_49_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) + + +IF(ENABLE_OPENMP) + IF (NOT OPENMP_FOUND) + MESSAGE(ERROR "No known compiler option for enabling OpenMP") + 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) + + +SET(BUILD_PREFIX ${CMAKE_BINARY_DIR}/external_build) +SET(EXT_INSTALL ${CMAKE_BINARY_DIR}/ext_install) if (ENABLE_SHARP) SET(SHARP_SOURCE ${CMAKE_SOURCE_DIR}/external/sharp) @@ -17,6 +44,202 @@ if (ENABLE_SHARP) endif (ENABLE_SHARP) +############### +# Build HDF5 +############### + +if (INTERNAL_HDF5) + SET(HDF5_SOURCE_DIR ${BUILD_PREFIX}/hdf5-prefix/src/hdf5) + SET(HDF5_BIN_DIR ${EXT_INSTALL}) + 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 + ) + SET(cosmotool_DEPS ${cosmotool_DEPS} hdf5) + SET(hdf5_built hdf5) + set(HDF5_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5.a CACHE STRING "HDF5 lib" FORCE) + set(HDF5_CPP_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5_cpp.a CACHE STRING "HDF5 C++ lib" FORCE) + set(HDF5HL_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5_hl.a CACHE STRING "HDF5-HL lib" FORCE) + set(HDF5HL_CPP_LIBRARY ${HDF5_BIN_DIR}/lib/libhdf5_hl_cpp.a CACHE STRING "HDF5-HL C++ lib" FORCE) + SET(HDF5_INCLUDE_PATH ${HDF5_BIN_DIR}/include CACHE STRING "HDF5 include path" FORCE) + SET(ENV{HDF5_ROOT} ${HDF5_BIN_DIR}) + SET(HDF5_ROOTDIR ${HDF5_BIN_DIR}) + SET(CONFIGURE_LDFLAGS "${CONFIGURE_LDFLAGS} -L${HDF5_BIN_DIR}/lib") +else(INTERNAL_HDF5) + find_path(HDF5_INCLUDE_PATH hdf5.h) + find_library(HDF5_LIBRARY hdf5) + find_library(HDF5_CPP_LIBRARY hdf5_cpp) + find_library(HDF5HL_CPP_LIBRARY hdf5_hl_cpp) + find_library(HDF5HL_LIBRARY hdf5_hl) +endif (INTERNAL_HDF5) +SET(CONFIGURE_CPP_FLAGS "${CONFIGURE_CPP_FLAGS} -I${HDF5_INCLUDE_PATH}") +mark_as_advanced(HDF5_INCLUDE_PATH HDF5_LIBRARY HDF5_CPP_LIBRARY HDF5HL_LIBRARY HDF5HL_CPP_LIBRARY) + +############### +# Build NetCDF +############### + + +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_LDFLAGS "${CONFIGURE_LDFLAGS} -L${NETCDF_BIN_DIR}/lib") + SET(EXTRA_NC_FLAGS CPPFLAGS=${CONFIGURE_CPP_FLAGS} LDFLAGS=${CONFIGURE_LDFLAGS}) + ExternalProject_Add(netcdf + DEPENDS ${hdf5_built} + PREFIX ${BUILD_PREFIX}/netcdf-prefix + URL ${NETCDF_URL} + CONFIGURE_COMMAND ${NETCDF_SOURCE_DIR}/configure + --prefix=${NETCDF_BIN_DIR} --libdir=${NETCDF_BIN_DIR}/lib + --enable-netcdf-4 --with-pic --disable-shared --disable-dap + --disable-cdmremote --disable-rpc + --disable-examples ${EXTRA_NC_FLAGS} CC=${CMAKE_C_COMPILER} + CXX=${CMAKE_CXX_COMPILER} + BUILD_IN_SOURCE 1 + INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + ) + 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(NETCDF_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf.a CACHE STRING "NetCDF lib" FORCE) + SET(NETCDFCPP_LIBRARY ${NETCDF_BIN_DIR}/lib/libnetcdf_c++.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) + +ELSE(INTERNAL_NETCDF) + find_path(NETCDF_INCLUDE_PATH NAMES netcdf.h) + find_path(NETCDFCPP_INCLUDE_PATH NAMES netcdfcpp.h netcdf) + find_library(NETCDF_LIBRARY netcdf) + find_library(NETCDFCPP_LIBRARY NAMES netcdf_c++ netcdf_c++4) + + SET(CONFIGURE_CPP_FLAGS ${CONFIGURE_CPP_FLAGS} + -I${NETCDF_INCLUDE_PATH} -I${NETCDFCPP_INCLUDE_PATH}) +endif (INTERNAL_NETCDF) +mark_as_advanced(NETCDF_LIBRARY NETCDFCPP_LIBRARY NETCDF_INCLUDE_PATH NETCDFCPP_INCLUDE_PATH) + +################## +# Build BOOST +################## + +if (INTERNAL_BOOST) + SET(BOOST_SOURCE_DIR ${BUILD_PREFIX}/boost-prefix/src/boost) + ExternalProject_Add(boost + URL ${BOOST_URL} + PREFIX ${BUILD_PREFIX}/boost-prefix + CONFIGURE_COMMAND + ${BOOST_SOURCE_DIR}/bootstrap.sh --prefix=${CMAKE_BINARY_DIR}/ext_build/boost + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${BOOST_SOURCE_DIR}/b2 --with-exception + INSTALL_COMMAND echo "No install" + ) + set(Boost_INCLUDE_DIRS ${BOOST_SOURCE_DIR} CACHE STRING "Boost path" FORCE) + set(Boost_LIBRARIES ${BOOST_SOURCE_DIR}/stage/lib/libboost_python.a CACHE STRING "Boost libraries" FORCE) + +ELSE (INTERNAL_BOOST) + find_package(Boost 1.53) +endif (INTERNAL_BOOST) +mark_as_advanced(Boost_INCLUDE_DIRS Boost_LIBRARIES) + +################## +# Build GSL +################## + +IF(INTERNAL_GSL) + SET(GSL_SOURCE_DIR ${BUILD_PREFIX}/gsl-prefix/src/gsl) + ExternalProject_Add(gsl + URL ${GSL_URL} + PREFIX ${BUILD_PREFIX}/gsl-prefix + CONFIGURE_COMMAND ${GSL_SOURCE_DIR}/configure + --prefix=${EXT_INSTALL} --disable-shared + --with-pic + CPPFLAGS=${CONFIGURE_CPP_FLAGS} CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} + BUILD_IN_SOURCE 1 + BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} + INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + ) + SET(GSL_INTERNAL_LIBS ${EXT_INSTALL}/lib) + SET(GSL_LIBRARY ${GSL_INTERNAL_LIBS}/libgsl.a CACHE STRING "GSL internal path" FORCE) + SET(GSLCBLAS_LIBRARY ${GSL_INTERNAL_LIBS}/libgslcblas.a CACHE STRING "GSL internal path" FORCE) + set(GSL_INCLUDE_PATH ${CMAKE_BINARY_DIR}/ext_build/gsl/include CACHE STRING "GSL internal path" FORCE) + SET(cosmotool_DEPS ${cosmotool_DEPS} gsl) +ELSE(INTERNAL_GSL) + find_path(GSL_INCLUDE_PATH NAMES gsl/gsl_blas.h) + find_library(GSL_LIBRARY gsl) + find_library(GSLCBLAS_LIBRARY gslcblas) + + set(GSL_LIBRARIES ${GSL_LIBRARY} ${GSLCBLAS_LIBRARY}) + +ENDIF(INTERNAL_GSL) +mark_as_advanced(GSL_LIBRARY GSLCBLAS_LIBRARY GSL_INCLUDE_PATH) + + +############# +# Build FFTW +############# + +IF(INTERNAL_FFTW) + SET(EXTRA_FFTW_CONF) + IF(HAVE_SSE) + SET(EXTRA_FFTW_CONF ${EXTRA_FFTW_CONF} --enable-sse) + ENDIF(HAVE_SSE) + IF(HAVE_SSE2) + SET(EXTRA_FFTW_CONF ${EXTRA_FFTW_CONF} --enable-sse2) + ENDIF(HAVE_SSE2) + IF(HAVE_AVX) + SET(EXTRA_FFTW_CONF ${EXTRA_FFTW_CONF} --enable-avx) + ENDIF(HAVE_AVX) + + SET(cosmotool_DEPS ${cosmotool_DEPS} fftw) + SET(FFTW_SOURCE ${BUILD_PREFIX}/fftw-prefix/src/fftw) + ExternalProject_Add(fftw + URL ${FFTW_URL} + PREFIX ${BUILD_PREFIX}/fftw-prefix + CONFIGURE_COMMAND + ${FFTW_SOURCE}/configure + --prefix=${EXT_INSTALL} + ${EXTRA_FFTW_CONF} --disable-shared --enable-threads + BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} + INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install + ) + SET(FFTW3_LIBRARY_DIRS ${EXT_INSTALL}/lib) + SET(FFTW3_INCLUDE_PATH ${EXT_INSTALL}/include) + SET(FFTW3_THREADS ${EXT_INSTALL}/lib/libfftw3_threads.a) + SET(FFTW3_LIBRARIES ${EXT_INSTALL}/lib/libfftw3.a) + +ELSE (INTERNAL_FFTW) + pkg_check_modules(FFTW3 fftw3>=3.3) + pkg_check_modules(FFTW3F fftw3f>=3.3) + + find_library(FFTW3F_LIBRARY_FULL fftw3f PATHS ${FFTW3F_LIBDIR} NO_DEFAULT_PATH) + find_library(FFTW3_LIBRARY_FULL fftw3 PATHS ${FFTW3_LIBDIR} NO_DEFAULT_PATH) + +ENDIF(INTERNAL_FFTW) + + +############## +# Build Eigen +############## +IF (INTERNAL_EIGEN) + ExternalProject_Add(eigen + URL ${EIGEN_URL} + PREFIX ${BUILD_PREFIX}/eigen-prefix + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXT_INSTALL} + ) + SET(EIGEN_INCLUDE_PATH ${EXT_INSTALL}/include/eigen3) + +ELSE (INTERNAL_EIGEN) + pkg_check_modules(EIGEN3 eigen3) +ENDIF(INTERNAL_EIGEN) + + SET(OMPTL_BUILD_DIR ${CMAKE_BINARY_DIR}/omptl-prefix/src/omptl) ExternalProject_Add(omptl diff --git a/python_sample/icgen/borgicgen.py b/python_sample/icgen/borgicgen.py index fcfee2c..53c4c60 100644 --- a/python_sample/icgen/borgicgen.py +++ b/python_sample/icgen/borgicgen.py @@ -4,10 +4,10 @@ import cosmolopy as cpy from cosmogrowth import * import borgadaptor as ba -def gen_posgrid(N, L): +def gen_posgrid(N, L, delta=1, dtype=np.float32): """ Generate an ordered lagrangian grid""" - ix = (np.arange(N)*L/N).astype(np.float32) + ix = (np.arange(N)*L/N*delta).astype(dtype) x = ix[:,None,None].repeat(N, axis=1).repeat(N, axis=2) y = ix[None,:,None].repeat(N, axis=0).repeat(N, axis=2)