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.19.1.1
on
page 777
describes
the
data-sharing
attribute
rules
for
variables
referenced
in
a
construct.
Section 2.19.1.2
on
page 800
describes
the
data-sharing
attribute
rules
for
variables
referenced
in
a
region,
but
outside
any
construct.
2.19.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 as follows:
Variables
that
appear
in
threadprivate
directives
are
threadprivate.
Variables
with
automatic
storage
duration
that
are
declared
in
a
scope
inside
the
construct
are
private.
Objects
with
dynamic
storage
duration
are
shared.
Static
data
members
are
shared.
The
loop
iteration
variable(s)
in
the
associated
for-loop(s)
of
a
for,
parallelfor,
taskloop,
or
distribute
construct
is
(are)
private.
The
loop
iteration
variable
in
the
associated
for-loop
of
a
simd
construct
with
just
one
associated
for-loop
is
linear
with
a
linear-step
that
is
the
increment
of
the
associated
for-loop.
The
loop
iteration
variables
in
the
associated
for-loops
of
a
simd
construct
with
multiple
associated
for-loops
are
lastprivate.
The
loop
iteration
variable(s)
in
the
associated
for-loop(s)
of
a
loop
construct
is
(are)
lastprivate.
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.
Variables
and
common
blocks
that
appear
in
threadprivate
directives
are
threadprivate.
The
loop
iteration
variable(s)
in
the
associated
do-loop(s)
of
a
do,
paralleldo,
taskloop,
or
distribute
construct
is
(are)
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(s)
in
the
associated
do-loop(s)
of
a
loop
construct
is
(are)
lastprivate.
A
loop
iteration
variable
for
a
sequential
loop
in
a
parallel
or
task
generating
construct
is
private
in
the
innermost
such
construct
that
encloses
the
loop.
Implied-do
indices
and
forall
indices
are
private.
Cray
pointees
have
the
same
data-sharing
attribute
as
the
storage
with
which
their
Cray
pointers
are
associated.
Assumed-size
arrays
are
shared.
An
associate
name
preserves
the
association
with
the
selector
established
at
the
ASSOCIATE
or
SELECTTYPE
statement.
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(s)
in
the
associated
for-loop(s)
of
a
for,
parallelfor,
taskloop,
distribute,
or
loop
construct
may
be
listed
in
a
private
or
lastprivate
clause.
The
loop
iteration
variable
in
the
associated
for-loop
of
a
simd
construct
with
just
one
associated
for-loop
may
be
listed
in
a
private,
lastprivate,
or
linear
clause
with
a
linear-step
that
is
the
increment
of
the
associated
for-loop.
The
loop
iteration
variables
in
the
associated
for-loops
of
a
simd
construct
with
multiple
associated
for-loops
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
loop
iteration
variable(s)
in
the
associated
do-loop(s)
of
a
do,
paralleldo,
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.
Variables
used
as
loop
iteration
variables
in
sequential
loops
in
a
parallel
or
task
generating
construct
may
be
listed
in
data-sharing
attribute
clauses
on
the
construct
itself,
and
on
enclosed
constructs,
subject
to
other
restrictions.
Assumed-size
arrays
may
be
listed
in
a
shared
clause.
Additional restrictions on the variables that may appear in individual clauses are described with each clause
in Section 2.19.4 on page 842.
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.19.4.1
on
page 843).
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.19.7
on
page 934)
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.19.4.4 on page 852.
2.19.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.
Implied-do
indices,
forall
indices,
and
other
local
variables
declared
in
called
routines
in
the
region
are
private.