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.