Future Topics in OpenMP
Nested parallelism:
enabled with
OMP_NESTED
environment variable or theomp_set_nested(1)
routine.If a PARALLEL directive is encountered within another PARALLEL directive, a new term of threads will be created.
The new team will contain only one thread unless nested parallelism is enabled.
NUM_THREADS clause:
One way to control the number of threads used at each level is with the
num_threads(integer)
clause:The value set in the clause supersedes the value in the environment variable
OMP_NUM_THREADS
(or that set byomp_set_num_threads(integer)
)
Orphaned directives:
Directives are active in the dynamic scope of a parallel region, not just its lexical scope. e.g.
Useful as it allows a modular programming style
But also can be confusing if the call tree is complicated.
Extra rules about data scope attributes:
Variables in the argument list inherit their data scope attribute from the calling routine.
Global variables in C++ and COMMON blocks or module variables in Fortran are shared, unless declared
THREADPRIVATE
.static local variables in C/C++ and SAVE variables in Fortran are shared.
All other local variables are private.
Binding rules:
DO/FOR, SECTIONS, SINGLE, MASTER and BARRIER
directives always bind to the nearest enclosing PARALLEL directive.
Thread private global variables:
It can be convenient for each thread to have its own copy of variables with global scope.
Outside parallel regions and in
MASTER
directives, accesses to these variables refer to the master thread’s copy.#pragma omp threadprivate (list)
This directive must be at file or namespace scope, after all declarations of variables in list and before any references to variables in list or static variables.
Difference between
PRIVATE
: Reference to StackOverflow
Here is an example of
THREADPRIVATE
, which illustrates the lifetime of value and the storage association between master thread and program:
COPYIN clause:
Allows the values of the master thread’s
THREADPRIVATE
data to be copied to all other threads at the start of a parallel region.
Timing routines:
Return current wall clock time (relative to arbitrary origin) with:
double omp_get_wtime(void)
Return clock precision with:
double omp_get_wtick(void)
Timers are local to a thread, so must make both calls on the same thread to get the duration.
NO guarantee about resolution!
Reference
Last updated