\(\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}} }\)
team_thread.hpp¶
View page sourceSpecifications for A Team of AD Threads¶
Syntax¶
include
"team_thread.hpp"
team_create
( num_threads )team_work
( worker )team_destroy
()team_name
()Prototype¶
extern bool team_create(size_t num_threads);
extern bool team_work(void worker(void));
extern bool team_destroy(void);
extern const char* team_name(void);
Purpose¶
These routines start, use, and stop a team of threads that can
be used with the CppAD type AD<double>
.
Examples are provided for
OpenMP threads, Posix threads, Boost threads and Standard threads.
Restrictions¶
Calls to the routines
team_create
,
team_work
, and
team_destroy
, must all be done by the master thread; i.e.,
thread_num must be zero.
In addition, they must all be done in sequential execution mode; i.e.,
when the master thread is the only thread that is running
(in_parallel must be false).
team_create¶
The argument num_threads > 0
specifies the number of threads in this team.
This initializes both AD<double>
and team_work
to be used with num_threads .
If num_threads > 1 ,
num_threads - 1
new threads are created
and put in a waiting state until team_work
is called.
team_work¶
This routine may be called one or more times
between the call to team_create
and team_destroy
.
Each call to team_work
runs num_threads versions
of worker with the corresponding value of
thread_num
between zero and num_threads - 1
and
different for each thread,
team_destroy¶
This routine terminates all the other threads except for thread number zero; i.e., it terminates the threads corresponding to
thread_num = 1 , … , num_threads
-1
team_name¶
This routines returns a name that identifies this threading system.
The return value is a statically allocated '\0'
terminated C string.
ok¶
The return value ok
is false
if an error is detected during the
corresponding call.
Otherwise it is true
.
Example Use¶
Example use of these specifications can be found in the file team_example.cpp .
Example Implementation¶
Example implementations of these specifications can be found in the files:
team_openmp.cpp |
|
team_bthread.cpp |
|
team_pthread.cpp |
|
team_sthread.cpp |
Speed Test of Implementation¶
Speed tests of using CppAD with the team implementations above can be found in:
harmonic.cpp |
|
multi_newton.cpp |