From 94f984420b4362e95a58f95616d14dab0e7e792b Mon Sep 17 00:00:00 2001 From: Simon Praetorius Date: Thu, 20 Jun 2024 17:35:17 +0200 Subject: [PATCH] Add options and option descriptions --- ADOL-C/CMakeLists.txt | 3 + ADOL-C/examples/CMakeLists.txt | 32 ++++ ADOL-C/include/adolc/internal/CMakeLists.txt | 5 +- ADOL-C/src/CMakeLists.txt | 5 + ADOL-C/src/lie/CMakeLists.txt | 3 + ADOL-C/src/sparse/CMakeLists.txt | 3 + ADOL-C/src/tapedoc/CMakeLists.txt | 2 + CMakeLists.txt | 166 +++++++++++-------- adolc-config.cmake.in | 7 +- 9 files changed, 152 insertions(+), 74 deletions(-) create mode 100644 ADOL-C/examples/CMakeLists.txt create mode 100644 ADOL-C/src/lie/CMakeLists.txt create mode 100644 ADOL-C/src/sparse/CMakeLists.txt create mode 100644 ADOL-C/src/tapedoc/CMakeLists.txt diff --git a/ADOL-C/CMakeLists.txt b/ADOL-C/CMakeLists.txt index 5953fcd2..dade6090 100644 --- a/ADOL-C/CMakeLists.txt +++ b/ADOL-C/CMakeLists.txt @@ -1,2 +1,5 @@ add_subdirectory(include) add_subdirectory(src) +if(ENABLE_DOCEXA OR ENABLE_ADDEXA OR ENABLE_PAREXA) + add_subdirectory(examples) +endif() \ No newline at end of file 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 2ba85326..331f2a90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,126 +46,156 @@ target_include_directories(adolc # define options # -------------- -option(ENABLE_MEDIPACK "Build ADOL-C with MeDiPack (MPI) support" FALSE) -option(ENABLE_PYTHON "Build ADOL-C with python/swig support" FALSE) -option(ENABLE_ULONG "Enable 64-bit locations (only available on 64-bit systems)" FALSE) - -# 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) - -# 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) - -# 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) - -option(ENABLE_HARDDEBUG "Enable ADOL-C hard debug mode" FALSE) -if (ENABLE_HARDDEBUG) - set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) -endif (ENABLE_HARDDEBUG) - -# 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) - -option(DISABLE_USE_CALLOC "Disable use of calloc and use malloc instead for memory allocation" FALSE) -option(DISABLE_DOUBLE "Disable double precision arithmetic (untested)" FALSE) -option(DISABLE_STDCZERO "adouble default constructor does not initialize the value to zero" FALSE) - - -# handle the options -# ------------------ +include(FeatureSummary) -# Whether to build ADOL-C with adjoinable MPI (AMPI) or MeDiPack (MPI) support +# 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() -# enable python and swig +# 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_python_SUPPORT=1>) + $<$>:ADOLC_USE_CALLOC=1>) -if(ENABLE_PYTHON) - find_package(Python3 3.8 REQUIRED) - find_package(SWIG REQUIRED COMPONENTS python) +# 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() -target_compile_definitions(adolc PRIVATE - $<$:ADOLC_TRACK_ACTIVITY=1> - $<$:ADOLC_ADOUBLE_LATEINIT=1>) - -# Enable advanced branching operations to reduce retaping [default=no]. # 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() -# Enable reference counting for tapeless numbers [default=no]. # 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 compile flags depending on the disabled features +# 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_USE_CALLOC=1>) + $<$,$>: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>) -# Debug mode enabled +# 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_DEBUG=1> - $<$:ADOLC_HARDDEBUG=1>) - -# define data types to use, based on the options ENABLE_ULONG and DISABLE_DOUBLE -if(ENABLE_ULONG) - set(UINT_TYPE uint64_t) -else() - set(UINT_TYPE uint32_t) -endif() + $<$:ADOLC_ADOUBLE_LATEINIT=1>) -if (DISABLE_DOUBLE) - set(REAL_TYPE float) -else() - set(REAL_TYPE double) +# 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() -set(SPARSE_DRIVERS "") # TODO 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() - set(USE_BOOST_POOL "") # TODO +# 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") +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 # ---------------------------------------------------------------- diff --git a/adolc-config.cmake.in b/adolc-config.cmake.in index fcf0d632..4f89149f 100644 --- a/adolc-config.cmake.in +++ b/adolc-config.cmake.in @@ -13,10 +13,9 @@ if(ENABLE_MEDIPACK) find_dependency(MeDiPack) endif() -set(ENABLE_PYTHON @ENABLE_PYTHON@) -if(ENABLE_PYTHON) - find_dependency(Python3 3.8) - find_dependency(SWIG COMPONENTS python) +set(ENABLE_OPENMP @ENABLE_OPENMP@) +if(ENABLE_OPENMP) + find_dependency(OpenMP) endif() set(WITH_BOOST @WITH_BOOST@)