\(\newcommand{\W}[1]{ \; #1 \; }\) \(\newcommand{\R}[1]{ {\rm #1} }\) \(\newcommand{\B}[1]{ {\bf #1} }\) \(\newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} }\) \(\newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} }\) \(\newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} }\) \(\newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }\)
multi_chkpoint_one_common¶
View page sourceMulti-Threaded chkpoint_one Common Information¶
Purpose¶
This source code defines the common variables that are used by
the multi_chkpoint_one_
name functions.
Source¶
namespace {
// Number of threads, set by multi_chkpoint_one_time
// (zero means one thread with no multi-threading setup)
size_t num_threads_ = 0;
// We can use one checkpoint function for all threads because
// there is no member data that gets changed during worker call.
// This needs to stay in scope for as long as a recording will use it.
// We cannot be in parallel mode when this object is created or deleted.
// We use a pointer so that there is no left over memory in thread zero.
CppAD::checkpoint<double>* a_square_root_ = nullptr;
// structure with information for one thread
typedef struct {
// used by worker to compute the square root,
// set by multi_chkpoint_one_setup
CppAD::ADFun<double>* fun;
//
// value we are computing square root of, set by multi_chkpoint_one_setup
vector<double>* y_squared;
//
// square root, set by worker
vector<double>* square_root;
//
// false if an error occurs, true otherwise, set by worker
bool ok;
} work_one_t;
//
// Vector with information for all threads
// (uses pointers instead of values to avoid false sharing)
// allocated by multi_chkpoint_one_setup, freed by multi_chkpoint_one_takedown
work_one_t* work_all_[CPPAD_MAX_NUM_THREADS];
}