Skip to content

Commit

Permalink
Add options and option descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Praetorius authored and osander1 committed Nov 26, 2024
1 parent 1845c5a commit 94f9844
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 74 deletions.
3 changes: 3 additions & 0 deletions ADOL-C/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_DOCEXA OR ENABLE_ADDEXA OR ENABLE_PAREXA)
add_subdirectory(examples)
endif()
32 changes: 32 additions & 0 deletions ADOL-C/examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 3 additions & 2 deletions ADOL-C/include/adolc/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/adolc_settings.h
DESTINATION "include/adolc/internal")
target_include_directories(adolc
PRIVATE
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/ADOL-C/include>)
PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/ADOL-C/include>
$<INSTALL_INTERFACE:include>)
5 changes: 5 additions & 0 deletions ADOL-C/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ target_sources(adolc PRIVATE
)

add_subdirectory(drivers)
add_subdirectory(lie)
add_subdirectory(tapedoc)
if(ENABLE_SPARSE)
add_subdirectory(sparse)
endif()
3 changes: 3 additions & 0 deletions ADOL-C/src/lie/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target_sources(adolc PRIVATE
adolc_lie_c.c
adolc_lie.cpp)
3 changes: 3 additions & 0 deletions ADOL-C/src/sparse/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
target_sources(adolc PRIVATE
sparse_fo_rev.cpp
sparsedrivers.cpp)
2 changes: 2 additions & 0 deletions ADOL-C/src/tapedoc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target_sources(adolc PRIVATE
tapedoc.c)
166 changes: 98 additions & 68 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<$<BOOL:${ENABLE_MEDIPACK}>: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
$<$<BOOL:${ENABLE_PYTHON}>:ADOLC_python_SUPPORT=1>)
$<$<NOT:$<BOOL:${DISABLE_USE_CALLOC}>>: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
$<$<BOOL:${ENABLE_ACTIVITY_TRACKING}>:ADOLC_TRACK_ACTIVITY=1>
$<$<BOOL:${ENABLE_LATEINIT}>: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
$<$<BOOL:${ENABLE_ACTIVITY_TRACKING}>: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
$<$<NOT:$<BOOL:${DISABLE_USE_CALLOC}>>:ADOLC_USE_CALLOC=1>)
$<$<OR:$<CONFIG:Debug>,$<BOOL:${ENABLE_HARDDEBUG}>>:ADOLC_DEBUG=1>
$<$<BOOL:${ENABLE_HARDDEBUG}>: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
$<$<NOT:$<BOOL:${DISABLE_STDCZERO}>>: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
$<$<OR:$<CONFIG:Debug>,$<BOOL:${ENABLE_HARDDEBUG}>>:ADOLC_DEBUG=1>
$<$<BOOL:${ENABLE_HARDDEBUG}>: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()
$<$<BOOL:${ENABLE_LATEINIT}>: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
$<$<BOOL:${ENABLE_TSERRNO}>: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
$<$<NOT:$<BOOL:${DISABLE_TAPEDOC_VALUES}>>:ADOLC_TAPE_DOC_VALUES=1>)


# include subdirectories for handling of includes and source files
# ----------------------------------------------------------------
Expand Down
7 changes: 3 additions & 4 deletions adolc-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@)
Expand Down

0 comments on commit 94f9844

Please sign in to comment.