\(\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}} }\)
ta_parallel_setup¶
View page sourceSetup thread_alloc For Use in Multi-Threading Environment¶
Syntax¶
thread_alloc::parallel_setup
( num_threads , in_parallel , thread_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 openmp_get_started.cpp , bthread_get_started.cpp , and pthread_get_started.cpp , contain examples and tests that use this function.