Skip to content

Commit

Permalink
master: parallel_ad: Increase the set of CheckSimpleVector cases init…
Browse files Browse the repository at this point in the history
…ialized.

check_simple_vector.hpp: Imporve parallel mode error message.
  • Loading branch information
bradbell committed Mar 9, 2024
1 parent cf2e93a commit 349d845
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ IF( POLICY CMP0054 )
ENDIF( POLICY CMP0054 )
#
# cppad_version is used by version.sh to get the version number.
SET(cppad_version "20240306")
SET(cppad_version "20240309")
SET(cppad_url "https://coin-or.github.io/CppAD" )
SET(cppad_description "Differentiation of C++ Algorithms" )
IF( NOT DEFINED CMAKE_BUILD_TYPE)
Expand Down
13 changes: 13 additions & 0 deletions appendix/whats_new/2024.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ Release Notes for 2024
mm-dd
*****

03-09
=====
The number of :ref:`parallel_ad@CheckSimpleVector` cases
called by parallel_ad<Base>() was increased to include the following::

CheckSimpleVector< bool, CppAD::vectorBool >()
CheckSimpleVector< size_t, CppAD::vector<size_t> >()
CheckSimpleVector< Base, std::vector<Base> >()
CheckSimpleVector< AD<Base>, std::vector< AD<Base> > >()

In addition, the CheckSimpleVector :ref:`CheckSimpleVector@Parallel Mode`
documentation and error message has been improved.

03-06
=====
#. The ``to_csrc`` parameters :ref:`to_csrc@nu` and :ref:`to_csrc@u`
Expand Down
22 changes: 15 additions & 7 deletions include/cppad/core/parallel_ad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# define CPPAD_CORE_PARALLEL_AD_HPP
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
// SPDX-FileContributor: 2003-23 Bradley M. Bell
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------
/*
{xrst_begin parallel_ad}
Expand Down Expand Up @@ -41,11 +41,11 @@ This routine does extra setup
CheckSimpleVector
*****************
This routine has the side effect of calling the routines
``CheckSimpleVector`` < *Type* , ``CppAD::vector<`` *Type* > >()
where *Type* is *Base* and ``AD`` < *Base* > .
This routine has the side effect of calling ``CheckSimpleVector``
for an unspecified number of cases of
:ref:`CheckSimpleVector@Vector` and :ref:`CheckSimpleVector@Scalar` .
The set of these cases may increase in the future so that the user
does not need to initialize them separately.
Example
*******
Expand Down Expand Up @@ -76,6 +76,8 @@ they must be initialized separately:
-----------------------------------------------------------------------------
*/

# include <vector>
# include <cppad/utility/vector.hpp>
# include <cppad/local/std_set.hpp>
# include <cppad/local/val_graph/enable_parallel.hpp>

Expand Down Expand Up @@ -123,9 +125,15 @@ void parallel_ad(void)
local::val_graph::enable_parallel<Base>(); // val_graph/*_op.hpp
discrete<Base>::List(); // discrete.hpp

// check_simple_vector.hpp
// Some check_simple_vector.hpp cases
//
CheckSimpleVector< bool, CppAD::vectorBool >();
CheckSimpleVector< size_t, CppAD::vector<size_t> >();
CheckSimpleVector< Base, CppAD::vector<Base> >();
CheckSimpleVector< AD<Base>, CppAD::vector< AD<Base> > >();
//
CheckSimpleVector< Base, std::vector<Base> >();
CheckSimpleVector< AD<Base>, std::vector< AD<Base> > >();

}

Expand Down
39 changes: 27 additions & 12 deletions include/cppad/utility/check_simple_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# define CPPAD_UTILITY_CHECK_SIMPLE_VECTOR_HPP
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
// SPDX-FileCopyrightText: Bradley M. Bell <[email protected]>
// SPDX-FileContributor: 2003-23 Bradley M. Bell
// SPDX-FileContributor: 2003-24 Bradley M. Bell
// ----------------------------------------------------------------------------
/*
{xrst_begin CheckSimpleVector}
Expand All @@ -12,12 +12,9 @@ Check Simple Vector Concept
Syntax
******
# ``include <cppad/utility/check_simple_vector.hpp>``
``CheckSimpleVector`` < *Scalar* , *Vector* >()
``CheckSimpleVector`` < *Scalar* , *Vector* >( *x* , *y* )
| # ``include <cppad/utility/check_simple_vector.hpp>``
| ``CheckSimpleVector`` < *Scalar* , *Vector* >()
| ``CheckSimpleVector`` < *Scalar* , *Vector* >( *x* , *y* )
Purpose
*******
Expand All @@ -29,6 +26,14 @@ a :ref:`SimpleVector-name` class with
If a requirement is not satisfied,
a an error message makes it clear what condition is not satisfied.
Vector
******
is the vector type we are checking.
Scalar
******
is the type corresponding to the elements of an *Vector* .
x, y
****
If the arguments *x* and *y* are present,
Expand Down Expand Up @@ -70,9 +75,12 @@ if the CppAD include files.
Parallel Mode
*************
The routine :ref:`thread_alloc::parallel_setup<ta_parallel_setup-name>`
must be called before it
can be used in :ref:`parallel<ta_in_parallel-name>` mode.
This routine must be called before entering parallel mode
because it has static variables that must be initialized.
If it's first call is not in parallel mode, and NDEBUG is not defined,
you will get an assertion. Running in the debugger and going to the
stack frame where CheckSimpleVector is called may help you determine
what the value of *Scalar* and *Vector* need to be initialized.
Example
*******
Expand Down Expand Up @@ -112,10 +120,17 @@ namespace CppAD {

template <class Scalar, class Vector>
void CheckSimpleVector(const Scalar& x, const Scalar& y)
{ CPPAD_ASSERT_FIRST_CALL_NOT_PARALLEL
static size_t count;
{ //
// count
static size_t count = 0;
if( count > 0 )
return;
CPPAD_ASSERT_KNOWN(
! CppAD::thread_alloc::in_parallel() ,
"In parallel mode and CheckSimpleVector was not previously called\n"
"with this Scalar and Vector type; see the heading\n"
"Parallel Mode in the CheckSimpleVector documentation."
);
count++;

// value_type must be type of elements of Vector
Expand Down
2 changes: 1 addition & 1 deletion user_guide.xrst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

{xrst_comment BEGIN: Before changing see new_release.sh and check_version.sh}

cppad-20240306: CppAD User's Manual
cppad-20240309: CppAD User's Manual
###################################

.. image:: {xrst_dir coin.png}
Expand Down

0 comments on commit 349d845

Please sign in to comment.