Prev Next multi_atomic_common

@(@\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-Threaded User Atomic Common Information

Purpose
This source code defines the common variables that are used by the multi_atomic_name functions.

Source

namespace {
     // Number of threads, set by multi_atomic_time
     // (zero means one thread with no multi-threading setup)
     size_t num_threads_ = 0;

     // Number of Newton iterations, set by multi_atomic_time
     size_t num_itr_;

     // We can use one atomic_user 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.
     atomic_user* a_square_root_ = 0;

     // structure with information for one thread
     typedef struct {
          // used by worker to compute the square root, set by multi_atomic_setup
          CppAD::ADFun<double>* fun;
          //
          // value we are computing square root of, set by multi_atomic_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_atomic_setup, freed by multi_atomic_takedown
     work_one_t* work_all_[CPPAD_MAX_NUM_THREADS];
}

Input File: example/multi_thread/multi_atomic.cpp