Prev Next ta_parallel_setup

@(@\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}} }@)@This is cppad-20221105 documentation. Here is a link to its current documentation .
Setup thread_alloc For Use in Multi-Threading Environment

Syntax
thread_alloc::parallel_setup(num_threadsin_parallelthread_num)

Purpose
By default there is only one thread and all execution is in sequential mode, i.e., multiple threads are not sharing the same memory; i.e. not in parallel mode.

Speed
It should be faster, even when num_thread is equal to one, for thread_alloc to hold onto memory. This can be accomplished using the function call
    thread_alloc::hold_memory(true)
see hold_memory .

num_threads
This argument has prototype
    size_t 
num_threads
and must be greater than zero. It specifies the number of threads that are sharing memory. The case num_threads == 1 is a special case that is used to terminate a multi-threading environment.

in_parallel
This function has prototype
    bool 
in_parallel(void)
It must return true if there is more than one thread currently executing. Otherwise it can return false.

In the special case where num_threads == 1 , the routine in_parallel is not used.

thread_num
This function has prototype
    size_t 
thread_num(void)
It must return a thread number that uniquely identifies the currently executing thread. Furthermore
    0 <= 
thread_num() < num_threads
. In the special case where num_threads == 1 , the routine thread_num is not used.

Note that this function is called by other routines so, as soon as a new thread is executing, one must be certain that thread_num() will work for that thread.

Restrictions
The function parallel_setup must be called before the program enters parallel execution mode. In addition, this function cannot be called while in parallel mode.

Example
The files simple_ad_openmp.cpp , simple_ad_bthread.cpp , and simple_ad_pthread.cpp , contain examples and tests that use this function.
Input File: include/cppad/utility/thread_alloc.hpp