multi_chkpoint_two_common

View page source

Multi-Threaded chkpoint_two Common Information

Purpose

This source code defines the common variables that are used by the multi_chkpoint_two_ name functions.

Source

namespace {
   // Number of threads, set by multi_chkpoint_two_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::chkpoint_two<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_two_setup
      CppAD::ADFun<double>* fun;
      //
      // value we are computing square root of, set by multi_chkpoint_two_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_two_setup, freed by multi_chkpoint_two_takedown
   work_one_t* work_all_[CPPAD_MAX_NUM_THREADS];
}