diff --git a/ADOL-C/CMakeLists.txt b/ADOL-C/CMakeLists.txt index 755c566a..f569a847 100644 --- a/ADOL-C/CMakeLists.txt +++ b/ADOL-C/CMakeLists.txt @@ -1,3 +1,7 @@ +add_subdirectory(doc) add_subdirectory(include) add_subdirectory(src) -add_subdirectory(doc) +if(ENABLE_DOCEXA OR ENABLE_ADDEXA OR ENABLE_PAREXA) + add_subdirectory(examples) +endif() + diff --git a/ADOL-C/examples/CMakeLists.txt b/ADOL-C/examples/CMakeLists.txt new file mode 100644 index 00000000..f82e0197 --- /dev/null +++ b/ADOL-C/examples/CMakeLists.txt @@ -0,0 +1,32 @@ +add_executable(detexam detexam.cpp) +target_link_libraries(detexam PRIVATE adolc) + +add_executable(luexam luexam.cpp) +target_link_libraries(luexam PRIVATE adolc) + +add_executable(odexam odexam.cpp) +target_link_libraries(odexam PRIVATE adolc) + +add_executable(powexam powexam.cpp) +target_link_libraries(powexam PRIVATE adolc) + +add_executable(speelpenning speelpenning.cpp) +target_link_libraries(speelpenning PRIVATE adolc) + +add_executable(traceless_scalar traceless_scalar.cpp) +target_link_libraries(traceless_scalar PRIVATE adolc) + +add_executable(traceless_vector traceless_vector.cpp) +target_link_libraries(traceless_vector PRIVATE adolc) + +add_executable(traceless_higher_order traceless_higher_order.cpp) +target_link_libraries(traceless_higher_order PRIVATE adolc) + +if(ENABLE_SPARSE) + add_executable(traceless_vector_indo traceless_vector_indo.cpp) + target_link_libraries(traceless_vector_indo PRIVATE adolc) +endif() + +if(ENABLE_ADDEXA OR ENABLE_PAREXA) + # add_subdirectory(additional_examples) # TODO +endif() \ No newline at end of file diff --git a/ADOL-C/include/adolc/internal/CMakeLists.txt b/ADOL-C/include/adolc/internal/CMakeLists.txt index bd877a09..2c37381c 100644 --- a/ADOL-C/include/adolc/internal/CMakeLists.txt +++ b/ADOL-C/include/adolc/internal/CMakeLists.txt @@ -11,5 +11,6 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/adolc_settings.h DESTINATION "include/adolc/internal") target_include_directories(adolc - PRIVATE - $) + PUBLIC + $ + $) diff --git a/ADOL-C/src/CMakeLists.txt b/ADOL-C/src/CMakeLists.txt index 7f63d5b5..044a99b8 100644 --- a/ADOL-C/src/CMakeLists.txt +++ b/ADOL-C/src/CMakeLists.txt @@ -56,3 +56,8 @@ target_sources(adolc PRIVATE ) add_subdirectory(drivers) +add_subdirectory(lie) +add_subdirectory(tapedoc) +if(ENABLE_SPARSE) + add_subdirectory(sparse) +endif() diff --git a/ADOL-C/src/lie/CMakeLists.txt b/ADOL-C/src/lie/CMakeLists.txt new file mode 100644 index 00000000..be959018 --- /dev/null +++ b/ADOL-C/src/lie/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(adolc PRIVATE + adolc_lie_c.c + adolc_lie.cpp) \ No newline at end of file diff --git a/ADOL-C/src/sparse/CMakeLists.txt b/ADOL-C/src/sparse/CMakeLists.txt new file mode 100644 index 00000000..57d73d71 --- /dev/null +++ b/ADOL-C/src/sparse/CMakeLists.txt @@ -0,0 +1,3 @@ +target_sources(adolc PRIVATE + sparse_fo_rev.cpp + sparsedrivers.cpp) \ No newline at end of file diff --git a/ADOL-C/src/tapedoc/CMakeLists.txt b/ADOL-C/src/tapedoc/CMakeLists.txt new file mode 100644 index 00000000..ae989001 --- /dev/null +++ b/ADOL-C/src/tapedoc/CMakeLists.txt @@ -0,0 +1,2 @@ +target_sources(adolc PRIVATE + tapedoc.c) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3beaf3cd..331f2a90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,16 +43,159 @@ target_include_directories(adolc $) -# handle the options -# ------------------ +# define options +# -------------- + +include(FeatureSummary) + +# Whether to build ADOL-C with MeDiPack (MPI) support +option(ENABLE_MEDIPACK "Build ADOL-C with MeDiPack (MPI) support" FALSE) +add_feature_info(ENABLE_MEDIPACK ENABLE_MEDIPACK "MeDiPack: MPI wrapper for Algorithmic Differentiation tools.") +target_compile_definitions(adolc PRIVATE + $<$:ADOLC_MEDIPACK_SUPPORT=1>) +if(ENABLE_MEDIPACK) + find_package(MPI REQUIRED) + find_package(MeDiPack 1.0...<1.2 REQUIRED) # cmake >= 3.19 + target_link_libraries(adolc PUBLIC MeDiPack MPI::MPI_CXX) +endif() + +# Whether to use calloc or malloc for memory allocation +option(DISABLE_USE_CALLOC "Disable use of calloc and use malloc instead for memory allocation" FALSE) +add_feature_info(DISABLE_USE_CALLOC DISABLE_USE_CALLOC "Use malloc instead of calloc for memory allocation.") +target_compile_definitions(adolc PRIVATE + $<$>:ADOLC_USE_CALLOC=1>) + +# Whether to use 32-bit or 64-bit locations +option(ENABLE_ULONG "Enable 64-bit locations (only available on 64-bit systems)" FALSE) +add_feature_info(ENABLE_ULONG ENABLE_ULONG "Use 64-bit unsigned integers to determine how many adoubles can be simultaneously alive.") +if(ENABLE_ULONG) + set(UINT_TYPE uint64_t) +else() + set(UINT_TYPE uint32_t) +endif() + +# Whether to use single or double precision +option(DISABLE_DOUBLE "Disable double precision arithmetic (untested)" FALSE) +add_feature_info(DISABLE_DOUBLE DISABLE_DOUBLE "Use float instead of double precision arithmetic.") +if (DISABLE_DOUBLE) + message(WARNING "using 'float' is not well tested, please report bugs if you find any...") + set(REAL_TYPE float) +else() + set(REAL_TYPE double) +endif() + +# The boolean valued comparison operators with two adouble arguments will +# not return boolean results but the active results may be used to automatically +# switch branches in conjunction with condassign or advector (see manual). +option(ENABLE_ADVANCED_BRANCHING "Enable advanced branching operations to reduce retaping" FALSE) +add_feature_info(ENABLE_ADVANCED_BRANCHING ENABLE_ADVANCED_BRANCHING "Advanced branching operations to reduce retaping.") +if(ENABLE_ADVANCED_BRANCHING) + set(ADVBRANCH "#define ADOLC_ADVANCED_BRANCHING 1") +else() + set(ADVBRANCH "#undef ADOLC_ADVANCED_BRANCHING") +endif() + +# With this enabled some additional checks will be conducted when setting the +# number of directional derivatives for tapeless numbers using the SetNumDir() +# function. +option(ENABLE_TRACELESS_REFCOUNTING "Enable reference counting for tapeless numbers" FALSE) +add_feature_info(ENABLE_TRACELESS_REFCOUNTING ENABLE_TRACELESS_REFCOUNTING "Reference counting for tapeless numbers.") +if(ENABLE_TRACELESS_REFCOUNTING) + set(ADTL_REFCNT "#define USE_ADTL_REFCOUNTING 1") +else() + set(ADTL_REFCNT "#undef USE_ADTL_REFCOUNTING") +endif() -set(UINT_TYPE uint32_t) -set(REAL_TYPE double) +# Only the operations involving actual dependency relationships from the +# independent variables will be recorded on the trace, this however +# requires more checks to be performed during the tracing and increases +# tracing time. Useful only if memory is a constraint and tracing is +# done fewer times than derivative computations. +option(ENABLE_ACTIVITY_TRACKING "Enable activity tracking to reduce trace size but increased tracing time" FALSE) +add_feature_info(ENABLE_ACTIVITY_TRACKING ENABLE_ACTIVITY_TRACKING "Activity tracking to reduce trace size but increased tracing time.") +target_compile_definitions(adolc PRIVATE + $<$:ADOLC_TRACK_ACTIVITY=1>) + +# Whether to use ADOL-C hard debug mode +option(ENABLE_HARDDEBUG "Enable ADOL-C hard debug mode" FALSE) +add_feature_info(ENABLE_HARDDEBUG ENABLE_HARDDEBUG "Hard debug mode.") +if (ENABLE_HARDDEBUG) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) +endif (ENABLE_HARDDEBUG) +target_compile_definitions(adolc PRIVATE + $<$,$>:ADOLC_DEBUG=1> + $<$:ADOLC_HARDDEBUG=1>) + +# The adouble default constructor does not initialize the value to zero +# (improves performance but yields incorrect results for implicit array initializations, see manual) +option(DISABLE_STDCZERO "adouble default constructor does not initialize the value to zero" FALSE) +add_feature_info(DISABLE_STDCZERO DISABLE_STDCZERO "Do not initialize the values to zero.") +target_compile_definitions(adolc PRIVATE + $<$>:ADOLC_ADOUBLE_STDCZERO=1>) -set(ADVBRANCH "#undef ADOLC_ADVANCED_BRANCHING") -set(ADTL_REFCNT "#undef USE_ADTL_REFCOUNTING") +# adouble constructors need to be called. With malloc or realloc that is not the case. +# With this option the adouble can do a late initialization.) +option(ENABLE_LATEINIT "Whether the adouble variables have a late initialize option for functions like malloc/realloc" FALSE) +add_feature_info(ENABLE_LATEINIT ENABLE_LATEINIT "adouble can do a late initialization.") +target_compile_definitions(adolc PRIVATE + $<$:ADOLC_ADOUBLE_LATEINIT=1>) + +# Whether errno is thread save +option(ENABLE_TSERRNO "Use errno as thread number cache" FALSE) +add_feature_info(ENABLE_TSERRNO ENABLE_TSERRNO "Use errno as thread number cache.") +target_compile_definitions(adolc PRIVATE + $<$:ADOLC_THREADSAVE_ERRNO=1>) + +# Whether to enable OpenMP +option(ENABLE_OPENMP "Enable OpenMP" FALSE) +add_feature_info(ENABLE_OPENMP ENABLE_OPENMP "Enable OpenMP.") +if(ENABLE_OPENMP) + find_package(OpenMP REQUIRED) + target_link_libraries(adolc PUBLIC OpenMP::OpenMP_CXX) +endif() + + +find_package(Boost 1.54 COMPONENTS system) +set(WITH_BOOST 0) +if(Boost_FOUND) + target_link_libraries(adolc PUBLIC Boost::boost Boost::system) + set(WITH_BOOST 1) + # TODO: check for header boost/pool/pool_alloc.hpp + set(USE_BOOST_POOL "#define USE_BOOST_POOL 1") + if(NOT ENABLE_OPENMP) + # Boost pool should not assume multithreading + target_compile_definitions(adolc PRIVATE BOOST_POOL_NO_MT=1) + endif() +endif() + +# Whether to build sparse drivers +option(ENABLE_SPARSE "build sparse drivers" FALSE) +add_feature_info(ENABLE_SPARSE ENABLE_SPARSE "build sparse drivers") set(SPARSE_DRIVERS "#undef SPARSE_DRIVERS") -set(USE_BOOST_POOL "#undef USE_BOOST_POOL") +if(ENABLE_SPARSE) + set(SPARSE_DRIVERS "#define SPARSE_DRIVERS 1") + target_compile_definitions(adolc PRIVATE SPARSE=1) +endif() + +# Whether to build documented examples +option(ENABLE_DOCEXA "build documented examples" FALSE) +add_feature_info(ENABLE_DOCEXA ENABLE_DOCEXA "build documented examples") + +# Whether to build additional examples +option(ENABLE_ADDEXA "build additional examples" FALSE) +add_feature_info(ENABLE_ADDEXA ENABLE_ADDEXA "build additional examples") + +# Whether to build parallel example +include(CMakeDependentOption) +cmake_dependent_option(ENABLE_PAREXA "build parallel example" FALSE ENABLE_OPENMP FALSE) +add_feature_info(ENABLE_PAREXA ENABLE_PAREXA "build parallel example") + +# Whether tape_doc should compute values as it prints the tape contents +option(DISABLE_TAPEDOC_VALUES "should the tape_doc routine compute the values as it interprets and prints the tape contents" TRUE) +add_feature_info(DISABLE_TAPEDOC_VALUES DISABLE_TAPEDOC_VALUES "should the tape_doc routine compute the values as it interprets and prints the tape contents") +target_compile_definitions(adolc PRIVATE + $<$>:ADOLC_TAPE_DOC_VALUES=1>) + # include subdirectories for handling of includes and source files # ---------------------------------------------------------------- @@ -112,6 +255,23 @@ install(EXPORT adolcTargets NAMESPACE adolc:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc) +write_basic_package_version_file(adolc-config-version.cmake + VERSION ${adol-c_VERSION} + COMPATIBILITY SameMinorVersion) # cmake >= 3.11 + +configure_package_config_file(adolc-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/adolc-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/adolc-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/adolc-config-version.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/adolc) +export(TARGETS adolc NAMESPACE adolc:: FILE adolc-targets.cmake) +# print a summary of found packages and set options +# ------------------------------------------------- +include(FeatureSummary) +feature_summary(WHAT ALL) diff --git a/adolc-config.cmake.in b/adolc-config.cmake.in new file mode 100644 index 00000000..4f89149f --- /dev/null +++ b/adolc-config.cmake.in @@ -0,0 +1,27 @@ +set(ADOLC_VERSION @adol-c_VERSION@) + +@PACKAGE_INIT@ + +set(ADOLC_INCLUDE_DIR "@CMAKE_INSTALL_FULL_INCLUDEDIR@" ) +set(ADOLC_DATA_DIR "@CMAKE_INSTALL_PREFIX@/@RELATIVE_DATA_INSTALL_DIR@" ) + +include(CMakeFindDependencyMacro) + +set(ENABLE_MEDIPACK @ENABLE_MEDIPACK@) +if(ENABLE_MEDIPACK) + find_dependency(MPI) + find_dependency(MeDiPack) +endif() + +set(ENABLE_OPENMP @ENABLE_OPENMP@) +if(ENABLE_OPENMP) + find_dependency(OpenMP) +endif() + +set(WITH_BOOST @WITH_BOOST@) +if(WITH_BOOST) + find_dependency(Boost 1.54 REQUIRED COMPONENTS system) +endif() + +# Add the targets file +include("${CMAKE_CURRENT_LIST_DIR}/adolc-targets.cmake") \ No newline at end of file