| OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"
5.1.1 Variables Referenced in a Construct
The data-sharing attributes of variables that are referenced in a construct can be predetermined, explicitly
determined, or implicitly determined, according to the rules outlined in this section.
Specifying a variable in a copyprivate clause or a data-sharing attribute clause other than the
private clause on an enclosed construct causes an implicit reference to the variable in the enclosing
construct. Specifying a variable in a map clause of an enclosed construct may cause an implicit reference to
the variable in the enclosing construct. Such implicit references are also subject to the data-sharing attribute
rules outlined in this section.
A type parameter inquiry or complex part designator that is referenced in a construct is treated as if its
designator is referenced.
Certain variables and objects have predetermined data-sharing attributes for the construct in which they are
referenced. The first matching rule from the following list of predetermined data-sharing attribute rules
applies for variables and objects that are referenced in a construct.
- Variables
declared
within
a
BLOCK
construct
inside
a
construct
that
do
not
have
the
SAVE
attribute
are
private.
- Variables
and
common
blocks
(in
Fortran)
that
appear
as
arguments
in
threadprivate
directives
or
variables
with
the
_Thread_local
(in
C)
or
thread_local
(in
C++)
storage-class
specifier
are
threadprivate.
- Variables
with
automatic
storage
duration
that
are
declared
in
a
scope
inside
the
construct
are
private.
- Variables
of
non-reference
type
with
automatic
storage
duration
that
are
declared
in
a
scope
inside
the
construct
are
private.
- Objects
with
dynamic
storage
duration
are
shared.
- The
loop
iteration
variable
in
the
associated
loop
of
a
simd
construct
with
just
one
associated
loop
is
linear
with
a
linear-step
that
is
the
increment
of
the
associated
loop.
- The
loop
iteration
variables
in
the
associated
loops
of
a
simd
construct
with
multiple
associated
loops
are
lastprivate.
- The
loop
iteration
variable
in
any
associated
loop
of
a
loop
construct
is
lastprivate.
- The
loop
iteration
variable
in
any
associated
loop
of
a
loop-associated
construct
is
otherwise
private.
- The
implicitly
declared
variables
of
a
range-based
for
loop
are
private.
- Loop
iteration
variables
inside
parallel,
teams,
or
task
generating
constructs
are
private
in
the
innermost
such
construct
that
encloses
the
loop.
- Implied-do,
FORALL
and
DO CONCURRENT
indices
are
private.
- Variables
with
static
storage
duration
that
are
declared
in
a
scope
inside
the
construct
are
shared.
- If
a
list
item
in
a
map
clause
on
the
target
construct
has
a
base
pointer,
and
the
base
pointer
is
a
scalar
variable
that
does
not
appear
in
a
map
clause
on
the
construct,
the
base
pointer
is
firstprivate.
- If
a
list
item
in
a
reduction
or
in_reduction
clause
on
the
construct
has
a
base
pointer
then
the
base
pointer
is
private.
- Static
data
members
are
shared.
- The
__func__
variable
and
similar
function-local
predefined
variables
are
shared.
- Cray
pointees
have
the
same
data-sharing
attribute
as
the
storage
with
which
their
Cray
pointers
are
associated.
Cray
pointer
support
has
been
deprecated.
- Assumed-size
arrays
and
named constants
are
shared.
- An
associate
name
that
may
appear
in
a
variable
definition
context
is
shared
if
its
association
occurs
outside
of
the
construct
and
otherwise
it
has
the
same
data-sharing
attribute
as
the
selector
with
which
it
is
associated.
Variables with predetermined data-sharing attributes may not be listed in data-sharing attribute clauses,
except for the cases listed below. For these exceptions only, listing a predetermined variable in a
data-sharing attribute clause is allowed and overrides the variable’s predetermined data-sharing
attributes.
- The
loop
iteration
variable
in
any
associated
loop
of
a
loop-associated
construct
may
be
listed
in
a
private
or
lastprivate
clause.
- If
a
simd
construct
has
just
one
associated
loop
then
its
loop
iteration
variable
may
be
listed
in
a
linear
clause
with
a
linear-step
that
is
the
increment
of
the
associated
loop.
- Variables
with
const-qualified
type
with
no
mutable
members
may
be
listed
in
a
firstprivate
clause,
even
if
they
are
static
data
members.
- The
__func__
variable
and
similar
function-local
predefined
variables
may
be
listed
in
a
shared
or
firstprivate
clause.
- Loop
iteration
variables
of
loops
that
are
not
associated
with
any
OpenMP
directive
may
be
listed
in
data-sharing
attribute
clauses
on
the
surrounding
teams,
parallel
or
task
generating
construct,
and
on
enclosed
constructs,
subject
to
other
restrictions.
- Assumed-size
arrays
may
be
listed
in
a
shared
clause.
- Named constants
may
be
listed
in
a
shared
or
firstprivate
clause.
Additional restrictions on the variables that may appear in individual clauses are described with each clause
in Section 5.4.
Variables with explicitly determined data-sharing attributes are those that are referenced in a given construct
and are listed in a data-sharing attribute clause on the construct.
Variables with implicitly determined data-sharing attributes are those that are referenced in a given
construct and do not have predetermined or explicitly determined data-sharing attributes in that
construct.
Rules for variables with implicitly determined data-sharing attributes are as follows:
- In
a
parallel,
teams,
or
task
generating
construct,
the
data-sharing
attributes
of
these
variables
are
determined
by
the
default
clause,
if
present
(see
Section 5.4.1).
- In
a
parallel
construct,
if
no
default
clause
is
present,
these
variables
are
shared.
- For
constructs
other
than
task
generating
constructs,
if
no
default
clause
is
present,
these
variables
reference
the
variables
with
the
same
names
that
exist
in
the
enclosing
context.
- In
a
target
construct,
variables
that
are
not
mapped
after
applying
data-mapping
attribute
rules
(see
Section 5.8)
are
firstprivate.
- In
an
orphaned
task
generating
construct,
if
no
default
clause
is
present,
formal
arguments
passed
by
reference
are
firstprivate.
- In
an
orphaned
task
generating
construct,
if
no
default
clause
is
present,
dummy
arguments
are
firstprivate.
- In
a
task
generating
construct,
if
no
default
clause
is
present,
a
variable
for
which
the
data-sharing
attribute
is
not
determined
by
the
rules
above
and
that
in
the
enclosing
context
is
determined
to
be
shared
by
all
implicit
tasks
bound
to
the
current
team
is
shared.
- In
a
task
generating
construct,
if
no
default
clause
is
present,
a
variable
for
which
the
data-sharing
attribute
is
not
determined
by
the
rules
above
is
firstprivate.
A program is non-conforming if a variable in a task generating construct is implicitly determined to be
firstprivate according to the above rules but is not permitted to appear in a firstprivate clause
according to the restrictions specified in Section 5.4.4.