diff --git a/CMakeLists.txt b/CMakeLists.txt index 69dd2ec..63a0146 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,305 +1,312 @@ #################################################### # # # SpecMiCP : CMakeLists.txt # # # #################################################### project(specmicp) cmake_minimum_required(VERSION 3.2) # CMake Options # ============= # For an explanation of the options see the INSTALL file option( SPECMICP_USE_OPENMP "Use OpenMP for parallelisation" ON ) option( SPECMICP_NO_DEBUG "Disable SpecMiCP assert" OFF ) option( SPECMICP_BUILD_STATIC "Build static libraries" OFF ) option( SPECMICP_BUILD_EXAMPLE "Build the examples" ON ) option( SPECMICP_BENCHMARK "Build benchmark" OFF ) option( SPECMICP_TEST "Enable testing" ON ) option( SPECMICP_BINARIES_USE_STATIC "Executables use static libraries" OFF ) # PGO sequence option( SPECMICP_PROFILE_GENERATE "Generate profile for PGO optimization" OFF ) option( SPECMICP_PROFILE_USE "Use profile for PGO optimization" OFF ) # LTO optimization option( SPECMICP_LD_GOLD "Use GNU gold linker" ON ) option( SPECMICP_LTO "Use link time optimization" OFF ) option( SPECMICP_FAT_LTO "Use link time optimization with fat objects" ON ) +OPTION( SPECMICP_CXX_STANDARD_14 "Use c++14" OFF) + # the following is only a debug options for developpers # This options turns on the finite difference jacobian in specmicp system option( SPECMICP_DEBUG_EQUATION_FD_JACOBIAN "Use a finite difference jacobian" OFF ) # global variables # ================ set(SPECMICP_VERSION 0.0.4) # External Package # ================ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # OpenMP #------- # not required but recommended in release mode if(SPECMICP_USE_OPENMP) find_package(OpenMP) if (OPENMP_FOUND) set(SPECMICP_HAVE_OPENMP ON) endif(OPENMP_FOUND) endif() # Eigen # ----- find_package(Eigen3 REQUIRED) # This module comes from the Eigen3 Package include_directories(${EIGEN3_INCLUDE_DIR}) message(STATUS "Eigen3 version ${EIGEN3_VERSION}") # check eigen version # this check is necessary to avoid problem in the transition 3.2->3.3 if(${EIGEN3_VERSION} VERSION_LESS 3.2.90) set(HAVE_EIGEN_VERSION_LT_3_3 ON) add_definitions(-DHAVE_EIGEN_VERSION_LT_3_3) endif() find_package(Eigen3Unsupported) if(EIGEN3_UNSUPPORTED_FOUND) add_definitions(-DEIGEN3_UNSUPPORTED_FOUND) include_directories(${EIGEN3_UNSUPPORTED_INCLUDE_DIR}) endif(EIGEN3_UNSUPPORTED_FOUND) # Yaml-cpp # -------- # YAML-cpp library is required and used by all modules for configuration # and data storage # YAML-CPP does not provide a CMake find module. # Instead, we use pkgconfig include(FindPkgConfig) pkg_check_modules(YAML REQUIRED yaml-cpp>=0.5) include_directories(${YAML_INCLUDE_DIRS}) link_directories(${YAML_LIBRARY_DIRS}) # HDF5 # ---- # HDF5 is required and used by all modules for output # # Only the C serial API is used find_package(HDF5 REQUIRED COMPONENTS C) include_directories(${HDF5_C_INCLUDE_DIR}) # libc functions required # ----------------------- # note : most of this functions are required by specmicp_common/filesystem.cpp # just a friendly warning if(NOT UNIX) message(WARNING "Not tested on non linux platform ! Probably won't work") endif() include(CheckIncludeFile) include(CheckFunctionExists) # just a quick macro to check if a required include exist macro(check_required_include name var) CHECK_INCLUDE_FILE( ${name} ${var} ) if (NOT ${var}) message(SEND_ERROR "Missing required include ${name}") endif() endmacro(check_required_include) check_required_include( "string.h" HAVE_STRING_H ) check_required_include( "dirent.h" HAVE_DIRENT_H ) check_required_include( "unistd.h" HAVE_UNISTD_H ) check_required_include( "sys/stat.h" HAVE_SYS_STAT_H ) check_required_include( "limits.h" HAVE_LIMITS_H ) check_required_include( "stdlib.h" HAVE_STDLIB_H ) # These includes are optional CHECK_INCLUDE_FILE( "sys/time.h" HAVE_TIME_H ) CHECK_INCLUDE_FILE( "sys/resource.h" HAVE_RESOURCE_H ) if (${HAVE_TIME_H} AND ${HAVE_RESOURCE_H}) CHECK_FUNCTION_EXISTS("getrusage" SPECMICP_HAVE_GETRUSAGE) endif() CHECK_FUNCTION_EXISTS( "secure_getenv" SPECMICP_HAVE_SECURE_GETENV ) # Build Mode # ========== # sanitizer # --------- # to check memory, undefined behavior and all... include(ASanitizer) include(UBSanitizer) # compilation flags # ============================================================================ # require C++11 standard by default +# use C++14 if possible # note : these cmake features require CMake >= 3.2 -set(CMAKE_CXX_STANDARD 11) +if (SPECMICP_CXX_STANDARD_14) + set( CMAKE_CXX_STANDARD 14 ) +else () + set( CMAKE_CXX_STANDARD 11 ) +endif(SPECMICP_CXX_STANDARD_14) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Some more flags # Check corresponding cmake files for more detail # Gold Linker # ------------ include(gold_linker) # PGO optimization # ---------------- include(pg_optimization) # Symbols visibility # ------------------ include(visibility_flag) # Link time optimization # ---------------------- include(lto) # set the flags # ------------- if (OPENMP_FOUND) SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() # let's be pedantic in DEBUG mode, it's always fun SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic") # always best to check what we do... message(STATUS "C++ flags : ${CMAKE_CXX_FLAGS}") # Directories ######################################################################### # use gnu coding standards include(GNUInstallDirs) # the libraries install dir set( LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_FULL_LIBDIR} CACHE PATH "Installation directory for libraries" ) # the static libraries install dir set( STATIC_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_FULL_LIBDIR} CACHE PATH "Installation directory for static libraries" ) # Binaries # -------- set( BIN_INSTALL_DIR ${CMAKE_INSTALL_FULL_BINDIR} CACHE PATH "Installation directory for the programs" ) # include #-------- set( INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR} CACHE PATH "Installation directory for the headers" ) # share #------ set( SHARE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/specmicp/" CACHE PATH "Installation directory for the miscalleneous files..." ) mark_as_advanced( LIBRARY_INSTALL_DIR STATIC_LIBRARY_INSTALL_DIR BIN_INSTALL_DIR INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR ) # CPP API : SpecMiCP / ReactMiCP ######################################################################### # the main source directory - the c++ api set(SPECMICP_CPP_API ${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories( ${SPECMICP_CPP_API} ) add_subdirectory( ${SPECMICP_CPP_API} ) # the necessary libraries to link to set( SPECMICP_LIBS # just speciation solver specmicp specmicp_database specmicp_common ${YAML_LIBRARIES} ) set( REACTMICP_LIBS # reactive transport solver reactmicp dfpm ${SPECMICP_LIBS} ) # static versions set( SPECMICP_STATIC_LIBS specmicp_static specmicp_database_static specmicp_common_static ${YAML_LIBRARIES} ) set( REACTMICP_STATIC_LIBS reactmicp_static dfpm_static ${SPECMICP_STATIC_LIBS} ) # Databases ######################################################################### add_subdirectory( data ) # Documentation ######################################################################### # "common" documentation # ----------------------- set( DOCS_LIST ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/COPYING ) add_custom_target(docs SOURCES ${DOCS_LIST}) install(FILES ${DOCS_LIST} DESTINATION ${SHARE_INSTALL_DIR} ) # scripts # -------- add_subdirectory( scripts ) # Doxygen documentation # --------------------- add_subdirectory( doc ) # Tests ######################################################################### if( SPECMICP_TEST ) enable_testing(true) endif() add_subdirectory( tests ) # Examples ######################################################################### add_subdirectory( examples ) # Benchmark ######################################################################## if (SPECMICP_BENCHMARK) add_subdirectory( benchmark ) endif() # Docker ######################################################################## add_subdirectory( docker ) diff --git a/INSTALL b/INSTALL index 7cb3c17..4f24c7d 100644 --- a/INSTALL +++ b/INSTALL @@ -1,124 +1,131 @@ Building SpecMiCP ----------------- SpecMiCP uses CMake[1] as build system, to build it, in the specmicp directory, run : cmake . make To customize build, see the cmake documentation[2] and the following informations : Requirements : ============== - C++11 compiler ( tested with - gcc 4,9.2, and 5.3.0 - clang 3.6.0. 3.7.0) - not tested with Visual Studio, probably won't work out of the box - Eigen [4] (>=3.2) - yaml-cpp [8] (>= 0.5) (version <= 0.5.1 requires boost) Older version required boost, but the dependancy has been removed. Requirements for the documentation : ------------------------------------ - Doxygen[5] -The tests require Catch[6] but it is downloaded automatically by Cmake in the project directory if needed. +The tests require Catch[6] but it is downloaded automatically by Cmake in the +project directory if needed. Configuration Options : ======================= These options are used by CMake to configure the project - SPECMICP_NO_DEBUG - bool (default OFF) - if true, remove assert used in specmicp - SPECMICP_USE_OPENMP : - bool (default ON) - use OpenMP to parallelize code - SPECMICP_BUILD_STATIC - bool (default OFF) - - if ON, also build static libraries + - if ON, also build static libraries. Note the static libraries are also + compiled with -fPIC so they can be used in python modules. - SPECMICP_BINARIES_USE_STATIC - bool (default OFF) - if ON, executables use the static libraries - SPECMICP_BUILD_EXAMPLE - bool (default ON) - if ON, build the examples - SPECMICP_BUILD_BENCHMARK - bool (default OFF) - if ON, build the micro-benchmark, use Google benchmark library [9] - SPECMICP_BUILD_TEST - bool (default ON) - if ON, build the test (run with ctest) + - SPECMICP_CXX_STANDARD_14 + - bool (default OFF) + - If ON, compiles SpecMiCP using c++14 + - SPECMICP_LTO - bool (default OFF) - if ON, use link-time optimization if available - SPECMICP_LD_GOLD - bool (default ON) - if ON, use the Gold linker [7] if available - SPECMICP_PROFILE_GENERATE - bool (default OFF) - if ON, generate the profiles for profile guided optimization - SPECMICP_PROFILE_USE - bool (default OFF) - if ON, use the profiles to better optimimize the programs The libs must have been compiled with -DSPECMICP_PROFILE_GENERATE=ON before, and trained. See scripts/pgo_sequence.sh - SPECMICP_DEBUG_EQUATION_FD_JACOBIAN - bool (default OFF) - - use a finite difference jacobian in specmicp (dev option for debug only) + - Use a finite difference jacobian in specmicp. Thi sis a dev option only + as it is quite slower. Examples of configuration : mkdir build; cd build cmake .. -DSPECMICP_USE_OPENMP=ON -DCMAKE_BUILD_TYPE=Release Other example : to install specmicp in '/opt/local' mkdir build cd build cmake .. -DSPECMICP_BUILD_EXAMPLE=ON -DSPECMICP_USE_LTO=ON -DSPECMICP_USE_OPENMP=ON -DCMAKE_INSTALL_PREFIX=/opt/local -DCMAKE_BUILD_TYPE=release make && make doc_html make install For a custom version of eigen 3: -DEIGEN3_INCLUDE_DIR=[eigen3 directory] # This is not needed anymore, just for old version # For a custom version of boost : # -DBoost_NO_BOOST_CMAKE=true -DBOOSTROOT=[boost directory] Tests ===== The tests can be executed with through the ctest command ctest [--output-on-failure] ctest is part of the cmake framework. The commands `make check` and `make test` will also work. [1]: http://www.cmake.org/ [2]: http://www.cmake.org/cmake/help/v3.0/ [3]: http://www.boost.org/ [4]: http://eigen.tuxfamily.org/ [5]: http://www.stack.nl/~dimitri/doxygen/ [6]: https://github.com/philsquared/Catch [7]: https://en.wikipedia.org/wiki/Gold_%28linker%29 [8]: https://github.com/jbeder/yaml-cpp [9]: https://github.com/google/benchmark diff --git a/src/specmicp_common/compat.hpp b/src/specmicp_common/compat.hpp index 3c415b0..0ae26e9 100644 --- a/src/specmicp_common/compat.hpp +++ b/src/specmicp_common/compat.hpp @@ -1,63 +1,59 @@ /* ============================================================================= Copyright (c) 2014 - 2016 F. Georget Princeton University All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * ============================================================================= */ #ifndef SPECMICP_UTILS_COMPAT_HPP #define SPECMICP_UTILS_COMPAT_HPP #include //! \file compat.hpp //! \brief Compatibility/portability between C++ version namespace specmicp { //! \brief Build a unique_ptr //! if using c++14 use the version in the standard library #if (__cplusplus == 201103L) template std::unique_ptr inline make_unique(Ts&&... params) { return std::unique_ptr(new T(std::forward(params)...)); } #elif (__cplusplus >= 201402L) -template -std::unique_ptr inline make_unique(Ts&&... params) -{ - return std::make_unique(std::forward(params)...); -} +using std::make_unique; #endif } //end namespace specmicp #endif // SPECMICP_UTILS_COMPAT_HPP