Inside an OpenMP construct, the sharing rules for variables may be implicitly determined, explicitly determined, or predetermined by restrictions on certain types of variables.

In most cases, the sharing rules are implicitly determined. In a parallel construct, variables that have not been given any other data-sharing attribute are shared by default. The implicit data-sharing attributes of variables may be changed through a default clause. For constructs other than the parallel construct, the implicit data-sharing attributes are inherited from the enclosing context.

Variables are said to be explicitly determined for a region if they appear in a data-sharing clause for that region. For example, if a parallel directive has a private(x) clause, it causes variable x to be treated as private to each thread in the parallel region.

The program can declare variables in a way that restricts their data-sharing attributes. Common predetermined variables in C and Fortran are shown in the table.
C type Fortran type Predetermined status
variable in threadprivatevariable in threadprivatethreadprivate
heap allocated storageshared
static data membersshared
const variables with no mutable membershared
OpenMP for loop iteration variableall do loop iteration variablesprivate
automatic variable declared in scope inside constructimplied-do and forall indicesprivate

Variables listed above may not be used in data-sharing attribute clauses on OpenMP constructs with the following exceptions: loop iteration variables of OpenMP loop constructs may appear in private or lastprivate clauses, and Fortran loop iteration variables in other loops inside a parallel construct may appear in private, firstprivate, lastprivate, shared, or reduction clauses.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement