Sharing Rules
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.
C type | Fortran type | Predetermined status |
---|---|---|
variable in threadprivate | variable in threadprivate | threadprivate |
heap allocated storage | shared | |
static data members | shared | |
const variables with no mutable member | shared | |
OpenMP for loop iteration variable | all do loop iteration variables | private |
automatic variable declared in scope inside construct | implied-do and forall indices | private |
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.