Skip to content

Commit

Permalink
master: Change CPPAD_DEBUG_AND_RELEASE to a cmake parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbell committed Dec 24, 2023
1 parent 6f22110 commit d8f0f11
Show file tree
Hide file tree
Showing 17 changed files with 84 additions and 64 deletions.
25 changes: 21 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ command_line_arg(cppad_tape_addr_type "unsigned int" STRING
command_line_arg(cppad_static_lib FALSE BOOL
"If true (false) the cppad library will be static (shared)"
)
#
# cppad_debug_and_release
command_line_arg(cppad_debug_and_release TRUE BOOL
"If true the cppad library and tests will be able to mix debug and release"
)
# ----------------------------------------------------------------------------
#
# Ensure c++11 support
Expand Down Expand Up @@ -232,6 +237,13 @@ int main(void)
compile_source_test(${cmake_defined_ok} "${source}" use_cplusplus_2017_ok )
# ----------------------------------------------------------------------------
#
# cppad_debug_and_release_01
IF (cppad_debug_and_release )
SET(cppad_debug_and_release_01 1 )
ELSE (cppad_debug_and_release )
SET(cppad_debug_and_release_01 0 )
ENDIF ( )
#
# cppad_debug_which
# CMAKE_BUILD_TYPE
SET(debug_even_or_odd FALSE)
Expand Down Expand Up @@ -275,13 +287,18 @@ ELSE( ) # CMAKE_BUILD_TYPE
SET(debug_even_or_odd TRUE)
ENDIF( "${cppad_debug_which}" STREQUAL debug_all)
ENDIF( ) # CMAKE_BUILD_TYPE
IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
IF( debug_even_or_odd )
IF( debug_even_or_odd )
IF ( NOT cppad_debug_and_release )
MESSAGE(FATAL_ERROR
"cppad_debug_and_release is false and cppad_debug_wich = ${cppad_debug_which}"
)
ENDIF ( NOT cppad_debug_and_release )
IF( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
MESSAGE(FATAL_ERROR
"Cannot have cppad_debug_which equal ${cppad_debug_which} on Windows."
)
ENDIF( debug_even_or_odd )
ENDIF( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
ENDIF( ${CMAKE_SYSTEM_NAME} STREQUAL "Windows" )
ENDIF( debug_even_or_odd )
print_variable(CMAKE_SYSTEM_NAME)
print_variable(cppad_debug_which)
print_variable(CMAKE_BUILD_TYPE)
Expand Down
3 changes: 1 addition & 2 deletions appendix/whats_new/17.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,7 @@ is lower triangular to the speed test
=====

#. Add the capability to compile so that CppAD debug and release mode
can be mixed; see
:ref:`preprocessor@Documented Here@CPPAD_DEBUG_AND_RELEASE` .
can be mixed using ``CPPAD_DEBUG_AND_RELEASE`` .
#. Add the :ref:`cmake@cppad_debug_which` flags
that determines which files are compiled for debugging versus release
during the CppAD testing; see :ref:`cmake_check-name` .
Expand Down
3 changes: 1 addition & 2 deletions appendix/whats_new/19.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ when using :ref:`chkpoint_two-name` function.
:ref:`json_graph_op@sum` operator
in :ref:`from_json-name` .
#. Improve the documentation for mixing debug and release versions
of CppAD in the same program; see
:ref:`preprocessor@Documented Here@CPPAD_DEBUG_AND_RELEASE` .
of CppAD in the same program using ``CPPAD_DEBUG_AND_RELEASE`` .

08-10
=====
Expand Down
7 changes: 7 additions & 0 deletions appendix/whats_new/23.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ Changes and Additions to CppAD During 2023
mm-dd
*****

12-24
=====
Change the ``CPPAD_DEBUG_AND_RELEASE`` compiler flag to the cmake
:ref:`cmake@cppad_debug_and_release` configuration flag.
This changed the default behavior for compiling the CppAD library
so that it allows for mixing debug and release code.

09-08
=====
#. Add the :ref:`cmake@cppad_static_lib` option to the install.
Expand Down
3 changes: 0 additions & 3 deletions bin/check_define.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ file_list=`git ls-files '*.hpp' '*.in' |
sed -n -e '/^include\/cppad\//p'`
add_on_list='CG PY TMB MIXED'
#
# preprocessor symbol that may or may not be defined by user
echo 'CPPAD_DEBUG_AND_RELEASE' > check_define.1
#
# preprocessor symbols in user API
sed -n -e "/^# *undef /p" xrst/preprocessor.xrst | sed \
-e "s/^# *undef *\([A-Za-z0-9_]*\).*/\1/" > check_define.2
Expand Down
10 changes: 6 additions & 4 deletions bin/run_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ done
# cppad_cxx_flags
cppad_cxx_flags="-Wall -pedantic-errors -std=$standard -Wshadow"
cppad_cxx_flags="$cppad_cxx_flags -Wfloat-conversion -Wconversion"
if [ "$debug_which" == 'debug_odd' ] || [ "$debug_which" == 'debug_even' ]
then
cppad_cxx_flags="$cppad_cxx_flags -D CPPAD_DEBUG_AND_RELEASE"
fi
if [ "$callgrind" == 'yes' ]
then
if [ "$debug_which" != 'debug_none' ]
Expand Down Expand Up @@ -385,6 +381,12 @@ then
cmake_args="$cmake_args -D cppad_profile_flag=-pg"
fi
#
# debug_and_release
if [ "$debug_which" == 'debug_none' ]
then
cmake_args = "$cmake_args -D cppad_debug_and_release=false"
fi
#
# simple options
cmake_args="$cmake_args -D cppad_testvector=$testvector"
cmake_args="$cmake_args -D cppad_debug_which=$debug_which"
Expand Down
8 changes: 2 additions & 6 deletions cmake/set_compile_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
#
# Case debug_even:
# The files with an even (odd) index in source_list have debug (release) flags.
# In addition the compiler flag -DCPPAD_DEBUG_AND_RELEASE is added.
#
# Case debug_odd:
# The files with an odd (even) index in source_list have debug (release) flags.
# In addition the compiler flag -DCPPAD_DEBUG_AND_RELEASE is added.
#
# Case debug_all, debug_none, or empty string:
# The debug and release flags are not set by this routine.
Expand Down Expand Up @@ -62,12 +60,10 @@ FUNCTION(set_compile_flags program_name debug_which source_list)
ENDIF( count_mod_2 )
ENDFOREACH(source ${source_list})
SET_SOURCE_FILES_PROPERTIES(
${debug_list} PROPERTIES COMPILE_FLAGS
"${debug_flags} -D CPPAD_DEBUG_AND_RELEASE"
${debug_list} PROPERTIES COMPILE_FLAGS "${debug_flags}"
)
SET_SOURCE_FILES_PROPERTIES(
${release_list} PROPERTIES COMPILE_FLAGS
"${release_flags} -D CPPAD_DEBUG_AND_RELEASE"
${release_list} PROPERTIES COMPILE_FLAGS "${release_flags}"
)
# IF( ${program_name} STREQUAL "..." )
# print_variable( ... )
Expand Down
7 changes: 4 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ fi
#
# cppad_cxx_flags
cppad_cxx_flags=$( echo " $cxx_flags " | sed -e 's| -g ||' )
cppad_cxx_fags="$cppad_flags -D CPPAD_DEBUG_AND_RELEASE"
#
# cmake_install_libdirs
cmake_install_libdirs='lib;lib64'
Expand Down Expand Up @@ -679,7 +678,8 @@ echo cmake \
-D cppad_max_num_threads="$max_num_threads" \
-D cppad_tape_id_type="$tape_id_type" \
-D cppad_tape_addr_type="$tape_addr_type" \
-D cppad_debug_which='debug_none'
-D cppad_debug_which='debug_none' \
-D cppad_debug_and_release='true'
#
cmake \
-U .+ \
Expand Down Expand Up @@ -713,7 +713,8 @@ cmake \
-D cppad_max_num_threads="$max_num_threads" \
-D cppad_tape_id_type="$tape_id_type" \
-D cppad_tape_addr_type="$tape_addr_type" \
-D cppad_debug_which='debug_none'
-D cppad_debug_which='debug_none' \
-D cppad_debug_and_release='true'
# ----------------------------------------------------------------------------
echo 'configure: OK'
exit 0
2 changes: 1 addition & 1 deletion example/general/compare_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ bool compare_change(void)
AD<double>::abort_recording();
}
}
# ifdef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
if( missed_error )
{ // This routine is compiled for debugging, but the routine that checks
// operator indices was compiled for release.
Expand Down
2 changes: 1 addition & 1 deletion example/general/general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int main(void)
Run( unary_plus, "unary_plus" );
Run( vec_ad, "vec_ad" );
// END_SORT_THIS_LINE_MINUS_1
# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
Run( check_for_nan, "check_for_nan" );
# endif
# if CPPAD_HAS_ADOLC
Expand Down
11 changes: 11 additions & 0 deletions include/cppad/configure.hpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ The second operand in a divide operation evaluated to zero at compile time.
/* {xrst_code}
{xrst_spell_on}

CPPAD_DEBUG_AND_RELEASE
***********************
Starting with 2023-12-24,
this flag is set by the cmake command; see
:ref:`cmake@cppad_debug_and_release` .
Before then, one would add -D CPPAD_DEBUG_AND_RELEASE
when compiling CppAD code.
{xrst_code hpp} */
# define CPPAD_DEBUG_AND_RELEASE @cppad_debug_and_release_01@
/* {xrst_code}

CPPAD_USE_CPLUSPLUS_2011
************************
Deprecated 2020-12-03:
Expand Down
1 change: 1 addition & 0 deletions include/cppad/core/undef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ that are used by the CppAD examples and tests.
# undef CPPAD_COND_EXP_BASE_REL
# undef CPPAD_COND_EXP_REL
# undef CPPAD_CPPADVECTOR
# undef CPPAD_DEBUG_AND_RELEASE
# undef CPPAD_EIGENVECTOR
# undef CPPAD_FOLD_AD_VALUED_BINARY_OPERATOR
# undef CPPAD_FOLD_ASSIGNMENT_OPERATOR
Expand Down
14 changes: 7 additions & 7 deletions include/cppad/utility/thread_alloc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ class thread_alloc{
block_t root_available_[CPPAD_MAX_NUM_CAPACITY];
/*!
root of inuse list for this thread and each capacity
If NDEBUG or CPPAD_DEBUG_AND_RELEASE is defined, this memory is not
used, but it still helps to separate this structure from the structure
for the next thread.
If NDEBUG is defined or CPPAD_DEBUG_AND_RELEASE is true,
this memory is not used, but it still helps to separate
this structure from the structure for the next thread.
*/
block_t root_inuse_[CPPAD_MAX_NUM_CAPACITY];
};
Expand Down Expand Up @@ -788,7 +788,7 @@ Example
first_trace = false;
}

# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
// Root nodes for both lists. Note these are different for different
// threads because tc_index is different for different threads.
block_t* inuse_root = info->root_inuse_ + c_index;
Expand All @@ -808,7 +808,7 @@ Example
// return value for get_memory
void* v_ptr = reinterpret_cast<void*>(node + 1);
# ifndef NDEBUG
# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
// add node to inuse list
node->next_ = inuse_root->next_;
inuse_root->next_ = v_node;
Expand Down Expand Up @@ -844,7 +844,7 @@ Example
void* v_ptr = reinterpret_cast<void*>(node + 1);

# ifndef NDEBUG
# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
// add node to inuse list
node->next_ = inuse_root->next_;
inuse_root->next_ = v_node;
Expand Down Expand Up @@ -943,7 +943,7 @@ Example

thread_alloc_info* info = thread_info(thread);
# ifndef NDEBUG
# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
// remove node from inuse list
void* v_node = reinterpret_cast<void*>(node);
block_t* inuse_root = info->root_inuse_ + c_index;
Expand Down
6 changes: 2 additions & 4 deletions test_more/debug_rel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ ELSE( "${cppad_debug_which}" )
ENDIF( "${cppad_debug_which}" STREQUAL "debug_all" )
#
SET_SOURCE_FILES_PROPERTIES(
debug_rel.cpp debug.cpp PROPERTIES COMPILE_FLAGS
"${debug_flags} -DCPPAD_DEBUG_AND_RELEASE"
debug_rel.cpp debug.cpp PROPERTIES COMPILE_FLAGS "${debug_flags}"
)
#
SET_SOURCE_FILES_PROPERTIES(
release.cpp PROPERTIES COMPILE_FLAGS
"${release_flags} -DCPPAD_DEBUG_AND_RELEASE"
release.cpp PROPERTIES COMPILE_FLAGS "${release_flags}"
)

# now that we have the properties, add the executable
Expand Down
4 changes: 2 additions & 2 deletions test_more/general/forward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ bool ForwardOlder(void)
}

# ifndef NDEBUG
# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
void my_error_handler(
bool known ,
int line ,
Expand Down Expand Up @@ -239,7 +239,7 @@ bool Forward(void)
ok &= ForwardCases< std::valarray <double> >();
ok &= ForwardOlder();
# ifndef NDEBUG
# ifndef CPPAD_DEBUG_AND_RELEASE
# if CPPAD_DEBUG_AND_RELEASE
// CppAD does not check for nan when NDEBUG is defined
ok &= forward_nan();
# endif
Expand Down
27 changes: 17 additions & 10 deletions xrst/install/cmake.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ The full version of the command, with all its optional arguments is:
| |tab| ``-D cppad_tape_addr_type`` = *cppad_tape_addr_type* \\
| |tab| ``-D cppad_debug_which`` = *cppad_debug_which* \\
| |tab| ``-D cppad_static_lib`` = *cppad_static_lib* \\
| |tab| ``-D cppad_debug_and_release`` = *cppad_debug_and_release* \\
| |tab| \\
| |tab| ..

Expand Down Expand Up @@ -443,14 +444,6 @@ C++17
In order for the compiler to take advantage of features that are in C++17
,but not in C++11, the *cppad_cxx_flags* must enable these features.

debug and release
=================
The CppAD examples and tests decide which files to compile for debugging
and which to compile for release. Hence debug and release flags should
not be included in *cppad_cxx_flags* .
See also the
:ref:`preprocessor@Documented Here@CPPAD_DEBUG_AND_RELEASE`
compiler flag (which should not be included in *cppad_cxx_flags* ).

clang
=====
Expand Down Expand Up @@ -569,12 +562,26 @@ then *cppad_debug_which* must be the empty string (its default value).

cppad_static_lib
****************
This value should be either ``true`` or ``false`` .
The default value is ``false`` .
This value should be either ``true`` or ``false`` and
its default value is ``false`` .
If it is true (false), the cppad library will be a static (shared) library.
If the target system uses windows dlls, this setting should be true.
If it is false, a warning will be issued and it will be ignored.

cppad_debug_and_release
***********************
This value should be either ``true`` or ``false`` and its
default value is ``true`` .
If it is true,
and the debug and release versions of CppAD can be mixed in the same program.
This must be true if
:ref:`cmake@cppad_debug_which` is ``debug_even`` or ``debug_odd`` .
If ``NDEBUG`` is defined and *cppad_debug_and_release* is false,
:ref:`thread_alloc-name` does more error checking.
For programs that do a lot of memory allocation,
this can take a significant amount of time.
This is meant for testing CppAD and as a last resort when debugging.

{xrst_toc_hidden
bin/get_optional.sh
xrst/install/adolc.xrst
Expand Down
15 changes: 0 additions & 15 deletions xrst/preprocessor.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# ----------------------------------------------------------------------------
{xrst_begin preprocessor}
{xrst_spell
complier
nullptr
}

Expand Down Expand Up @@ -36,20 +35,6 @@ it is done as follows:
Documented Here
***************

CPPAD_DEBUG_AND_RELEASE
=======================
This flag is an exception because it is defined (or not) by the user
during the inclusion of the CppAD header files; e.g., when using ``g++``
one could put ``-D CPPAD_DEBUG_AND_RELEASE`` on the complier command line.
If it is defined, less error checking is done and the
debug and release versions of CppAD can be mixed in the same program.
Of particular note is that :ref:`thread_alloc-name` does less error checking.
For programs that do a lot of memory allocation,
this can be a significant time savings when ``NDEBUG`` is defined.
{xrst_comment
# undef CPPAD_DEBUG_AND_RELEASE
}

CPPAD_NULL
**********
Deprecated 2020-12-03:
Expand Down

0 comments on commit d8f0f11

Please sign in to comment.