| Prev | Next |  |  |  |  |  | multi_atomic_common |

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