diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index 3189ece..af377b3 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -1,59 +1,65 @@ # ==================== # # # # Micro-Benchmarking # # # # ==================== # # use google benchmark framework : https://github.com/google/benchmark find_package(Benchmark REQUIRED) include_directories(${BENCHMARK_INCLUDE_DIR}) # Logging # ------- add_executable(bm_logging bm_logging.cpp) -target_link_libraries(bm_logging specmicp_common_static ${BENCHMARK_LIBRARIES}) +target_link_libraries(bm_logging specmicp_common_static) +target_link_libraries(bm_logging ${BENCHMARK_LIBRARIES}) # Common # ------ add_executable(bm_common bm_common.cpp) -target_link_libraries(bm_common specmicp_common_static ${BENCHMARK_LIBRARIES}) +target_link_libraries(bm_common specmicp_common_static) +target_link_libraries(bm_common ${BENCHMARK_LIBRARIES}) # Maths # ------ add_executable(bm_maths bm_maths.cpp) -target_link_libraries(bm_maths specmicp_common_static ${BENCHMARK_LIBRARIES}) +target_link_libraries(bm_maths specmicp_common_static) +target_link_libraries(bm_maths ${BENCHMARK_LIBRARIES}) # Mesh # ---- add_executable(bm_mesh bm_mesh.cpp) -target_link_libraries(bm_mesh specmicp_common_static dfpm_static ${BENCHMARK_LIBRARIES}) +target_link_libraries(bm_mesh specmicp_common_static dfpm_static) +target_link_libraries(bm_mesh ${BENCHMARK_LIBRARIES}) # database # -------- set(TEST_CEMDATA_PATH \"../data/cemdata.yaml\") set_source_files_properties(bm_database.cpp PROPERTIES COMPILE_DEFINITIONS "TEST_CEMDATA_PATH=${TEST_CEMDATA_PATH}" ) add_executable(bm_database bm_database.cpp) -target_link_libraries(bm_database specmicp_database_static specmicp_common_static ${BENCHMARK_LIBRARIES}) +target_link_libraries(bm_database specmicp_database_static specmicp_common_static) +target_link_libraries(bm_database ${BENCHMARK_LIBRARIES}) # adimensional system # -------------------- set_source_files_properties(bm_adim_system.cpp PROPERTIES COMPILE_DEFINITIONS "TEST_CEMDATA_PATH=${TEST_CEMDATA_PATH}" ) add_executable(bm_adim_system bm_adim_system.cpp) target_link_libraries(bm_adim_system specmicp_static specmicp_database_static specmicp_common_static - ${BENCHMARK_LIBRARIES} +) +target_link_libraries(bm_adim_system ${BENCHMARK_LIBRARIES} ) diff --git a/benchmark/bm_adim_system.cpp b/benchmark/bm_adim_system.cpp index b0e4a7b..c90d039 100644 --- a/benchmark/bm_adim_system.cpp +++ b/benchmark/bm_adim_system.cpp @@ -1,491 +1,491 @@ #include #include "specmicp/adimensional/adimensional_system.hpp" #include "specmicp_database/database.hpp" #include "specmicp_common/physics/laws.hpp" #include "specmicp_common/micpsolver/micpsolver.hpp" #include "specmicp/adimensional/adimensional_system_solver.hpp" #include "specmicp/adimensional/adimensional_system_solution.hpp" #include using namespace specmicp; static specmicp::RawDatabasePtr get_simple_database() { specmicp::database::Database thedatabase(TEST_CEMDATA_PATH); std::map swapping ({ {"H[+]","HO[-]"}, }); thedatabase.swap_components(swapping); std::vector to_keep = {"HO[-]", "Ca[2+]"}; thedatabase.keep_only_components(to_keep); thedatabase.remove_half_cell_reactions(std::vector({"H2O", "HO[-]"})); return thedatabase.get_database(); } static AdimensionalSystemConstraints get_simple_constraints(RawDatabasePtr raw_data) { Vector total_concentration = Vector::Zero(raw_data->nb_component()); total_concentration(raw_data->get_id_component("H2O")) = 55.5; total_concentration(raw_data->get_id_component("HO[-]")) = 2e-3; total_concentration(raw_data->get_id_component("Ca[2+]")) = 1e-3; return AdimensionalSystemConstraints(total_concentration); } static void bm_simple_init(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); while(state.KeepRunning()) { AdimensionalSystem system(raw_data, constraints); } } BENCHMARK(bm_simple_init); static void bm_simple_secondary_variables(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { system.set_secondary_variables(x); } } static void bm_ideq_w(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); while(state.KeepRunning()) { index_t id = system.ideq_w(); benchmark::DoNotOptimize(id); } } //BENCHMARK(bm_ideq_w); static void bm_ideq_comp(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); while(state.KeepRunning()) { index_t id = system.ideq_paq(2); benchmark::DoNotOptimize(id); } } //BENCHMARK(bm_ideq_comp); BENCHMARK(bm_simple_secondary_variables); static void bm_simple_secondary_concentration(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { system.set_secondary_concentration(x); } } BENCHMARK(bm_simple_secondary_concentration); static void bm_simple_log_gamma(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_concentration(x); while(state.KeepRunning()) { system.compute_log_gamma(x); } } BENCHMARK(bm_simple_log_gamma); static void bm_debye_huckel(benchmark::State& state) { scalar_t sqrtI = 0.1; scalar_t zi = 2; scalar_t ao = 3.0; while(state.KeepRunning()) { scalar_t a = laws::debye_huckel(sqrtI, zi, ao); benchmark::DoNotOptimize(a); } } BENCHMARK(bm_debye_huckel); static void bm_extended_debye_huckel(benchmark::State& state) { - scalar_t I = 0.01; + scalar_t ionic_strength = 0.01; scalar_t sqrtI = 0.1; scalar_t zi = 2; scalar_t ao = 3.0; scalar_t bdot = 0.1; while(state.KeepRunning()) { - scalar_t a = laws::extended_debye_huckel(I, sqrtI, zi, ao, bdot); + scalar_t a = laws::extended_debye_huckel(ionic_strength, sqrtI, zi, ao, bdot); benchmark::DoNotOptimize(a); } } BENCHMARK(bm_extended_debye_huckel); static void bm_simple_residual_water(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { system.residual_water_conservation(x); } } BENCHMARK(bm_simple_residual_water); static void bm_simple_residual_ca(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { system.residual_component(x, 2); } } BENCHMARK(bm_simple_residual_ca); static void bm_residuals(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { Vector residuals(system.total_variables()); system.get_residuals(x, residuals); } } BENCHMARK(bm_residuals); static void bm_analytical_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { index_t neq = system.total_variables(); Matrix jacobian(neq, neq); system.analytical_jacobian(x, jacobian); } } BENCHMARK(bm_analytical_jacobian); static void bm_finite_difference_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystem system(raw_data, constraints); Vector x(4); x << 0.1, -3, -3, 0.0; system.set_secondary_variables(x); while(state.KeepRunning()) { index_t neq = system.total_variables(); Matrix jacobian(neq, neq); system.finite_difference_jacobian(x, jacobian); } } BENCHMARK(bm_finite_difference_jacobian); static void bm_adim_solver_init(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); while(state.KeepRunning()) { micpsolver::MiCPSolver solver(system); } } BENCHMARK(bm_adim_solver_init); static void bm_adim_solver_residuals(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { Vector residuals(solver.get_neq()); solver.base::compute_residuals(x, residuals); } } BENCHMARK(bm_adim_solver_residuals); static void bm_adim_reformulate_residuals(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { Vector residuals(solver.get_neq()); solver.base::compute_residuals(x, residuals); Vector residuals_reformulated(solver.get_neq()); solver.reformulate_residuals(x, residuals, residuals_reformulated); } } BENCHMARK(bm_adim_reformulate_residuals); static void bm_adim_reformulate_residuals_inplace(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { Vector residuals(solver.get_neq()); solver.base::compute_residuals(x, residuals); solver.reformulate_residuals_inplace(x, residuals); } } BENCHMARK(bm_adim_reformulate_residuals_inplace); static void bm_adim_solver_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { solver.compute_jacobian(x); } } BENCHMARK(bm_adim_solver_jacobian); static void bm_adim_solver_reformulate_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { solver.compute_jacobian(x); solver.reformulate_jacobian(x); } } BENCHMARK(bm_adim_solver_reformulate_jacobian); static void bm_adim_solver_setup_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; while(state.KeepRunning()) { solver.setup_jacobian(x); } } BENCHMARK(bm_adim_solver_setup_jacobian); static void bm_adim_solver_scaling_jacobian(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; index_t neq = solver.get_neq(); Vector residuals(neq); solver.base::compute_residuals(x, residuals); solver.reformulate_residuals_inplace(x, residuals); Matrix jacobian(neq,neq); jacobian.setZero(); system->get_jacobian(x, jacobian); solver.reformulate_jacobian_cck(x, residuals, jacobian); while(state.KeepRunning()) { Vector rscaler(neq), cscaler(neq); solver.scaling_jacobian(jacobian, residuals, rscaler, cscaler); } } BENCHMARK(bm_adim_solver_scaling_jacobian); static void bm_adim_solver_search_direction(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; solver.setup_residuals(x); solver.setup_jacobian(x); Vector update(solver.get_neq()); while(state.KeepRunning()) { solver.search_direction_calculation_no_scaling(update); } } BENCHMARK(bm_adim_solver_search_direction); static void bm_adim_solver_search_direction_scaling(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); auto system = std::make_shared(raw_data, constraints); micpsolver::MiCPSolver solver(system); Vector x(4); x << 0.1, -3, -3, 0.0; solver.setup_residuals(x); solver.setup_jacobian(x); Vector update(solver.get_neq()); while(state.KeepRunning()) { solver.search_direction_calculation(update); } } BENCHMARK(bm_adim_solver_search_direction_scaling); static void bm_adim_system_solver_init(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); while(state.KeepRunning()) { AdimensionalSystemSolver solver(raw_data, constraints); } } BENCHMARK(bm_adim_system_solver_init); static void bm_adim_system_solver_initialize_variables(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); Vector x; while(state.KeepRunning()) { solver.initialize_variables(x, 0.5, -4); } } BENCHMARK(bm_adim_system_solver_initialize_variables); static void bm_adim_system_solver_solve(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); while(state.KeepRunning()) { Vector x; solver.initialize_variables(x, 0.5, -4); solver.solve(x, false); benchmark::DoNotOptimize(x); } } BENCHMARK(bm_adim_system_solver_solve); static void bm_adim_system_solver_get_solution(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); Vector x; solver.solve(x, true); while(state.KeepRunning()) { auto sol = solver.get_raw_solution(x); benchmark::DoNotOptimize(sol); } } BENCHMARK(bm_adim_system_solver_get_solution); static void bm_adim_system_solver_unsafe_get_solution(benchmark::State& state) { RawDatabasePtr raw_data = get_simple_database(); AdimensionalSystemConstraints constraints = get_simple_constraints(raw_data); AdimensionalSystemSolver solver(raw_data, constraints); Vector x; solver.solve(x, true); while(state.KeepRunning()) { auto sol = solver.unsafe_get_raw_solution(x); benchmark::DoNotOptimize(sol); } } BENCHMARK(bm_adim_system_solver_unsafe_get_solution); BENCHMARK_MAIN() diff --git a/cmake/SpecMiCPDepends.cmake b/cmake/SpecMiCPDepends.cmake index 6366c0d..1faf91c 100644 --- a/cmake/SpecMiCPDepends.cmake +++ b/cmake/SpecMiCPDepends.cmake @@ -1,55 +1,63 @@ # Eigen # ----- find_package(Eigen3 REQUIRED) # This module comes from the Eigen3 Package message(STATUS "Eigen3 version ${EIGEN3_VERSION}") # optional find_package(Eigen3Unsupported) add_library(Eigen::eigen INTERFACE IMPORTED) set_property(TARGET Eigen::eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${EIGEN3_INCLUDE_DIR}) +if(SPECMICP_USE_BLAS) + if(NOT DEFINED EIGEN3_EXTRA_LINKFLAGS) + message(SEND_ERROR "Set EIGEN3_EXTRA_LINKFLAGS to provide the lapacke libraries") + endif() + set_property(TARGET Eigen::eigen PROPERTY + INTERFACE_LINK_LIBRARIES ${EIGEN3_EXTRA_LINKFLAGS}) + +endif(SPECMICP_USE_BLAS) # HDF5 # ---- # HDF5 is required and used by all modules for output # # Only the C serial API is used find_package(HDF5 REQUIRED COMPONENTS C) add_library(HDF5::hdf5 UNKNOWN IMPORTED) set_property(TARGET HDF5::hdf5 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${HDF5_INCLUDE_DIRS} ) set_property(TARGET HDF5::hdf5 PROPERTY IMPORTED_LOCATION ${HDF5_C_LIBRARY_hdf5} ) # 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 IMPORTED_TARGET yaml-cpp>=0.5) # cmake < 3.6 if(NOT TARGET PkgConfig::YAML) add_library(PkgConfig::YAML UNKNOWN IMPORTED) set_property(TARGET PkgConfig::YAML PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${YAML_INCLUDE_DIRS} ) set_property(TARGET PkgConfig::YAML PROPERTY IMPORTED_LOCATION ${YAML_LIBRARY_DIRS}/${YAML_LIBRARIES} ) endif() diff --git a/cmake/SpecMiCPOptions.cmake b/cmake/SpecMiCPOptions.cmake index 41672dd..af37e46 100644 --- a/cmake/SpecMiCPOptions.cmake +++ b/cmake/SpecMiCPOptions.cmake @@ -1,24 +1,27 @@ # 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 ) +# Linear algebra +option( SPECMICP_USE_BLAS "Eigen uses BLAS/LAPACK" 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 ) # 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 ) diff --git a/src/specmicp_common/CMakeLists.txt b/src/specmicp_common/CMakeLists.txt index 0eadf66..b62d380 100644 --- a/src/specmicp_common/CMakeLists.txt +++ b/src/specmicp_common/CMakeLists.txt @@ -1,186 +1,192 @@ # Main # ==== # var to store the files set(specmicp_common_srcs "" CACHE INTERNAL "specmicp_common files" FORCE) set(specmicp_common_headers "" CACHE INTERNAL "specmicp_common headers" FORCE ) # macro to add to vars macro(add_to_main_srcs_list LIST_NAME) set(tmp "") foreach (src ${${LIST_NAME}}) list(APPEND tmp ${CMAKE_CURRENT_SOURCE_DIR}/${src}) endforeach(src) set(specmicp_common_srcs "${specmicp_common_srcs};${tmp}" CACHE INTERNAL "specmicp common files" FORCE) endmacro(add_to_main_srcs_list) macro(add_to_main_headers_list LIST_NAME) set( tmp "") foreach(header ${${LIST_NAME}}) LIST(APPEND tmp ${CMAKE_CURRENT_SOURCE_DIR}/${header}) endforeach(header) set(specmicp_common_headers "${specmicp_common_headers};${tmp}" CACHE INTERNAL "headers for specmicp common" FORCE) endmacro(add_to_main_headers_list) # set( specmicp_common_main_srcs dateandtime.cpp filesystem.cpp log.cpp moving_average.cpp openmp_support.cpp string_algorithms.cpp timer.cpp ) add_to_main_srcs_list( specmicp_common_main_srcs ) set( specmicp_common_main_headers cached_vector.hpp compat.hpp dateandtime.hpp filesystem.hpp log_impl.hpp log.hpp macros.hpp moving_average.hpp openmp_support.hpp options_handler.hpp perfs_handler.hpp pimpl_ptr.hpp range_iterator.hpp range_iterator.inl scope_guard.hpp string_algorithms.hpp timer.hpp types.hpp ) add_to_main_headers_list( specmicp_common_main_headers ) INSTALL(FILES ${specmicp_common_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/specmicp_common ) add_subdirectory(cli) add_subdirectory(eigen) add_subdirectory(io) add_subdirectory(micpsolver) add_subdirectory(odeint) add_subdirectory(physics) add_subdirectory(plugins) add_subdirectory(sparse_solvers) set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS config.h.in) add_custom_target(config_h SOURCES config.h.in) configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h ) # build library # ============= set_pgo_flag(${specmicp_common_srcs}) add_library(objspecmicp_common OBJECT ${specmicp_common_srcs} ${specmicp_common_headers} ) set_property(TARGET objspecmicp_common PROPERTY POSITION_INDEPENDENT_CODE 1) target_include_directories(objspecmicp_common PUBLIC ${EIGEN3_INCLUDE_DIR} ${HDF5_INCLUDE_DIRS}) target_include_directories(objspecmicp_common PUBLIC ${YAML_INCLUDE_DIRS}) +target_include_directories(objspecmicp_common PUBLIC $) if(EIGEN3_UNSUPPORTED_FOUND) set_property(TARGET objspecmicp_common APPEND PROPERTY COMPILE_DEFINITIONS EIGEN3_UNSUPPORTED_FOUND) target_include_directories(objspecmicp_common PRIVATE ${EIGEN3_UNSUPPORTED_INCLUDE_DIR}) # added after endif(EIGEN3_UNSUPPORTED_FOUND) set_property(TARGET objspecmicp_common PROPERTY CXX_STANDARD ${SPECMICP_CXX_STANDARD}) set_property(TARGET objspecmicp_common PROPERTY CXX_STANDARD_REQUIRED ON) add_library(specmicp_common SHARED $) if (UNIX) LIST(APPEND specmicp_common_link_libraries dl) else() message(FATAL_ERROR "Plugin system only for POSIX at this time !") endif() install(TARGETS specmicp_common EXPORT ${SPECMICP_TARGET} LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} ) # static libraries # ---------------- if(SPECMICP_BUILD_STATIC) add_library(specmicp_common_static STATIC $ ) install(TARGETS specmicp_common_static EXPORT ${SPECMICP_TARGET} ARCHIVE DESTINATION ${STATIC_LIBRARY_INSTALL_DIR} ) else() add_library(specmicp_common_static EXCLUDE_FROM_ALL STATIC $ ) endif() set_target_properties(specmicp_common_static PROPERTIES OUTPUT_NAME specmicp_common) # link libraries and include directories # --------------------------------------- foreach(libtarget specmicp_common specmicp_common_static) target_link_libraries(${libtarget} PRIVATE ${specmicp_common_link_libraries}) target_link_libraries(${libtarget} PUBLIC PkgConfig::YAML) target_link_libraries(${libtarget} PUBLIC HDF5::hdf5) + target_link_libraries(${libtarget} INTERFACE Eigen::eigen) + + #if(SPECMICP_USE_BLAS) + # target_link_libraries(${libtarget} PUBLIC ${EIGEN3_EXTRA_LINKFLAGS}) + #endif() get_property(eigen_include_dirs TARGET Eigen::eigen PROPERTY INTERFACE_INCLUDE_DIRECTORIES) get_property(hdf5_include_dirs TARGET HDF5::hdf5 PROPERTY INTERFACE_INCLUDE_DIRECTORIES) get_property(yaml_include_dirs TARGET PkgConfig::YAML PROPERTY INTERFACE_INCLUDE_DIRECTORIES) - +target_include_directories(${libtarget} PUBLIC $) target_include_directories(${libtarget} PUBLIC $ $ ) target_include_directories(${libtarget} INTERFACE ${eigen_include_dirs} ) target_include_directories(${libtarget} INTERFACE ${hdf5_include_dirs} ) target_include_directories(${libtarget} INTERFACE ${yaml_include_dirs} ) # if(EIGEN3_UNSUPPORTED_FOUND) set_property(TARGET ${libtarget} APPEND PROPERTY COMPILE_DEFINITIONS EIGEN3_UNSUPPORTED_FOUND) target_include_directories(${libtarget} INTERFACE ${EIGEN3_UNSUPPORTED_INCLUDE_DIR}) # added after endif(EIGEN3_UNSUPPORTED_FOUND) spc_set_cxx_version_interface(${libtarget}) endforeach(libtarget) diff --git a/src/specmicp_common/config.h.in b/src/specmicp_common/config.h.in index 3c3dfae..fcdef29 100644 --- a/src/specmicp_common/config.h.in +++ b/src/specmicp_common/config.h.in @@ -1,50 +1,53 @@ /* ============================================================================= 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_COMMON_CONFIG_H #define SPECMICP_COMMON_CONFIG_H //! \file config.h.in //! \brief Compilation configuration header // defined if has the secure_getenv #cmakedefine SPECMICP_HAVE_SECURE_GETENV // defined if getrusage is found #cmakedefine SPECMICP_HAVE_GETRUSAGE // define if openmp is set #cmakedefine SPECMICP_HAVE_OPENMP +// define if eigen can use BLAS +#cmakedefine SPECMICP_USE_BLAS + #endif // SPECMICP_COMMON_CONFIG_H diff --git a/src/specmicp_common/eigen/incl_eigen_core.hpp b/src/specmicp_common/eigen/incl_eigen_core.hpp index ebbef2e..7037cdc 100644 --- a/src/specmicp_common/eigen/incl_eigen_core.hpp +++ b/src/specmicp_common/eigen/incl_eigen_core.hpp @@ -1,60 +1,68 @@ /* ============================================================================= 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_INCLEIGENCORE_HPP #define SPECMICP_INCLEIGENCORE_HPP //! \file eigen/incl_eigen_core.hpp //! \brief Include Eigen/Core with correct options //! \def EIGEN_DEFAULT_DENSE_INDEX_TYPE //! \brief The default type for an index in a dense matrix //! //! This may be redefined to be consistent. //! For more information see the Eigen documentation. #ifndef EIGEN_DEFAULT_DENSE_INDEX_TYPE #define EIGEN_DEFAULT_DENSE_INDEX_TYPE specmicp::index_t #endif +#include "specmicp_common/config.h" +// If asked by the user, eigen can use lapacke functions +// for dense matrix multiplications +#ifdef SPECMICP_USE_BLAS + #define EIGEN_USE_BLAS + #define EIGEN_USE_LAPACKE_STRICT +#endif + // avoid error due to binder1st and binder2nd in eigen... #if (defined __GNUC__) && (__GNUC__ >= 5) #pragma GCC diagnostic ignored "-Wdeprecated-declarations" #endif #include #if (defined __GNUC__) && (__GNUC__ >= 5) #pragma GCC diagnostic warning "-Wdeprecated-declarations" #endif #endif // SPECMICP_INCLEIGENCORE_HPP