The omp threadprivate directive makes the named file-scope,
namespace-scope, or static block-scope variables private to a thread.
#pragma omp threadprivate (list)
where list is a comma-separated list of variables.
Each copy of an omp threadprivate data variable is initialized
once prior to first use of that copy. If an object is changed before
being used to initialize a threadprivate data variable, behavior is
unspecified.
A thread must not reference another thread's copy of an omp
threadprivate data variable. References will always be to the
master thread's copy of the data variable when executing serial and
master regions of the program.
Use of the omp threadprivate directive is governed by the
following points:
- An omp threadprivate directive must appear at file scope
outside of any definition or declaration.
- The omp threadprivate directive is applicable to static-block
scope variables and may appear in lexical blocks to reference those
block-scope variables. The directive must appear in the scope of the
variable and not in a nested scope, and must precede all references to
variables in its list.
- A data variable must be declared with file scope prior to inclusion in an
omp threadprivate directive list.
- An omp threadprivate directive and its list must
lexically precede any reference to a data variable found in that
list.
- A data variable specified in an omp threadprivate directive in
one translation unit must also be specified as such in all other translation
units in which it is declared.
- Data variables specified in an omp threadprivate
list must not appear in any clause other than the copyin,
copyprivate, if, num_threads, and
schedule clauses.
- The address of a data variable in an omp threadprivate
list is not an address constant.
- A data variable specified in an omp threadprivate
list must not have an incomplete or reference type.
Pragmas to Control Parallel Processing
