This section describes how the data-sharing attributes of variables referenced in data environments are
determined. The following two cases are described separately:
Section 2.21.1.1
describes
the
data-sharing
attribute
rules
for
variables
referenced
in
a
construct.
Section 2.21.1.2
describes
the
data-sharing
attribute
rules
for
variables
referenced
in
a
region,
but
outside
any
construct.
2.21.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 data-sharing attribute clause, except for the private clause, or copyprivate
clause of 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.
Certain variables and objects have predetermined data-sharing attributes with respect to 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 that appear 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 any associated loop of a for, parallelfor, taskloop, or
distribute construct is private.
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 implicitly declared variables of a range-based for loop 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 a 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.
Variables
declared
within
a
BLOCK
construct
inside
a
construct
that
do
not
have
the
SAVE
attribute
are
private.
Variables
and
common
blocks
that
appear
in
threadprivate
directives
are
threadprivate.
The
loop
iteration
variable
in
any
associated
do-loop
of
a
do,
paralleldo,
taskloop,
or
distribute
construct
is
private.
The
loop
iteration
variable
in
the
associated
do-loop
of
a
simd
construct
with
just
one
associated
do-loop
is
linear
with
a
linear-step
that
is
the
increment
of
the
associated
do-loop.
The
loop
iteration
variables
in
the
associated
do-loops
of
a
simd
construct
with
multiple
associated
do-loops
are
lastprivate.
The
loop
iteration
variable
in
any
associated
do-loop
of
a
loop
construct
is
lastprivate.
Loop
iteration
variables
inside
parallel
or
task
generating
constructs
are
private
in
the
innermost
such
construct
that
encloses
the
loop.
Implied-do,
FORALL
and
DOCONCURRENT
indices
are
private.
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
are
shared.
Namedconstants
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
for,
taskloop,
distribute,
or
loop
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
private,
lastprivate,
or
linear
clause
with
a
linear-step
that
is
the
increment
of
the
associated
loop.
If
a
simd
construct
has
more
than
one
associated
loop
then
their
loop
iteration
variables
may
be
listed
in
a
private
or
lastprivate
clause.
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.
The
loop
iteration
variable
in
any
associated
do-loop
of
a
do,
taskloop,
distribute,
or
loop
construct
may
be
listed
in
a
private
or
lastprivate
clause.
The
loop
iteration
variable
in
the
associated
do-loop
of
a
simd
construct
with
just
one
associated
do-loop
may
be
listed
in
a
private,
lastprivate,
or
linear
clause
with
a
linear-step
that
is
the
increment
of
the
associated
loop.
The
loop
iteration
variables
in
the
associated
do-loops
of
a
simd
construct
with
multiple
associated
do-loops
may
be
listed
in
a
private
or
lastprivate
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.
Namedconstants
may
be
listed
in
a
firstprivate
clause.
Additional restrictions on the variables that may appear in individual clauses are described with each clause
in Section 2.21.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, do not have predetermined data-sharing attributes, and are not listed in a data-sharing attribute
clause on the 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 2.21.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 2.21.7)
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.
Additional restrictions on the variables for which data-sharing attributes cannot be implicitly determined in
a task generating construct are described in Section 2.21.4.4.
2.21.1.2 Variables Referenced in a Region but not in a Construct
The data-sharing attributes of variables that are referenced in a region, but not in a construct, are determined
as follows:
Variables
with
static
storage
duration
that
are
declared
in
called
routines
in
the
region
are
shared.
File-scope
or
namespace-scope
variables
referenced
in
called
routines
in
the
region
are
shared
unless
they
appear
in
a
threadprivate
directive.
Objects
with
dynamic
storage
duration
are
shared.
Static
data
members
are
shared
unless
they
appear
in
a
threadprivate
directive.
In
C++,
formal
arguments
of
called
routines
in
the
region
that
are
passed
by
reference
have
the
same
data-sharing
attributes
as
the
associated
actual
arguments.
Other
variables
declared
in
called
routines
in
the
region
are
private.
Local
variables
declared
in
called
routines
in
the
region
and
that
have
the
save
attribute,
or
that
are
data
initialized,
are
shared
unless
they
appear
in
a
threadprivate
directive.
Variables
belonging
to
common
blocks,
or
accessed
by
host
or
use
association,
and
referenced
in
called
routines
in
the
region
are
shared
unless
they
appear
in
a
threadprivate
directive.
Dummy
arguments
of
called
routines
in
the
region
that
have
the
VALUE
attribute
are
private.
Dummy
arguments
of
called
routines
in
the
region
that
do
not
have
the
VALUE
attribute
are
private
if
the
associated
actual
argument
is
not
shared.
Dummy
arguments
of
called
routines
in
the
region
that
do
not
have
the
VALUE
attribute
are
shared
if
the
actual
argument
is
shared
and
it
is
a
scalar
variable,
structure,
an
array
that
is
not
a
pointer
or
assumed-shape
array,
or
a
simply
contiguous
array
section.
Otherwise,
the
data-sharing
attribute
of
the
dummy
argument
is
implementation-defined
if
the
associated
actual
argument
is
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.
Implied-do
indices,
DOCONCURRENT
indices,
FORALL
indices,
and
other
local
variables
declared
in
called
routines
in
the
region
are
private.