Prev Next multi_atomic_run

@(@\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}} }@)@
Run Multi-Threaded User Atomic Calculation

Syntax
ok = multi_atomic_run(y_squaredsquare_root)

Thread
It is assumed that this function is called by thread zero and all the other threads are blocked (waiting).

y_squared
This argument has prototype
     const vector<double>& 
y_squared
and its size is equal to the number of threads. It is the values that we are computing the square root of.

square_root
This argument has prototype
     vector<double>& 
square_root
The input value of square_root does not matter. Upon return, it has the same size and is the element by element square root of y_squared .

ok
This return value has prototype
     bool 
ok
If it is false, multi_atomic_run detected an error.

Source

namespace {
bool multi_atomic_run(
     const vector<double>& y_squared  ,
     vector<double>&      square_root )
{
     bool ok = true;
     ok     &= thread_alloc::thread_num() == 0;

     // setup the work for multi-threading
     ok &= multi_atomic_setup(y_squared);

     // now do the work for each thread
     if( num_threads_ > 0 )
          team_work( multi_atomic_worker );
     else     multi_atomic_worker();

     // combine the result for each thread and takedown the multi-threading.
     ok &= multi_atomic_takedown(square_root);

     return ok;
}
}

Input File: example/multi_thread/multi_atomic.cpp