This section describes the copyin clause (allowed on the parallel construct and combined parallel
worksharing constructs) and the copyprivate clause (allowed on the single construct).
These clauses support the copying of data values from private or threadprivate variables on one
implicit task or thread to the corresponding variables on other implicit tasks or threads in the
team.
The clauses accept a comma-separated list of list items (see Section 2.1 on page 104). All list items
appearing in a clause must be visible, according to the scoping rules of the base language. Clauses may be
repeated as needed, but a list item that specifies a given variable may not appear in more than one clause on
the same directive.
An associate name preserves the association with the selector established at the ASSOCIATE statement. A
list item that appears in a data copying clause may be a selector of an ASSOCIATE construct. If the
construct association is established prior to a parallel region, the association between the associate name and
the original list item will be retained in the region.
2.19.6.1 copyin Clause
SummaryThe copyin clause provides a mechanism to copy the value of a threadprivate variable of the
master thread to the threadprivate variable of each other member of the team that is executing the
parallel region.
Syntax
The syntax of the copyin clause is as follows:
copyin(list)
Description
The copy is done after the team is formed and prior to the start of execution of the associated
structured block. For variables of non-array type, the copy occurs by copy assignment. For
an array of elements of non-array type, each element is copied as if by assignment from an
element of the array of the master thread to the corresponding element of the array of the other
thread.
For class types, the copy assignment operator is invoked. The order in which copy assignment operators for
different variables of class type are called is unspecified.
The copy is done, as if by assignment, after the team is formed and prior to the start of execution of the
associated structured block.
On entry to any parallel region, each thread’s copy of a variable that is affected by a copyin clause for
the parallel region will acquire the type parameters, allocation, association, and definition status of the
copy of the master thread, according to the following rules:
If
the
original
list
item
has
the
POINTER
attribute,
each
copy
receives
the
same
association
status
as
that
of
the
copy
of
the
master
thread
as
if
by
pointer
assignment.
If
the
original
list
item
does
not
have
the
POINTER
attribute,
each
copy
becomes
defined
with
the
value
of
the
copy
of
the
master
thread
as
if
by
intrinsic
assignment
unless
the
list
item
has
a
type
bound
procedure
as
a
defined
assignment.
If
the
original
list
item
that
does
not
have
the
POINTER
attribute
has
the
allocation
status
of
unallocated,
each
copy
will
have
the
same
status.
If
the
original
list
item
is
unallocated
or
unassociated,
the
copy
of
the
other
thread
inherits
the
declared
type
parameters
and
the
default
type
parameter
values
from
the
original
list
item.
RestrictionsThe restrictions to the copyin clause are as follows:
A
list
item
that
appears
in
a
copyin
clause
must
be
threadprivate.
A
variable
of
class
type
(or
array
thereof)
that
appears
in
a
copyin
clause
requires
an
accessible,
unambiguous
copy
assignment
operator
for
the
class
type.
A
list
item
that
appears
in
a
copyin
clause
must
be
threadprivate.
Named
variables
that
appear
in
a
threadprivate
common
block
may
be
specified:
it
is
not
necessary
to
specify
the
whole
common
block.
A
common
block
name
that
appears
in
a
copyin
clause
must
be
declared
to
be
a
common
block
in
the
same
scoping
unit
in
which
the
copyin
clause
appears.
If
the
list
item
is
a
polymorphic
variable
with
the
ALLOCATABLE
attribute,
the
behavior
is
unspecified.
threadprivate
directive,
see
Section 2.19.2
on
page 809.
2.19.6.2 copyprivate Clause
SummaryThe copyprivate clause provides a mechanism to use a private variable to broadcast a value
from the data environment of one implicit task to the data environments of the other implicit tasks that
belong to the parallel region.
To avoid data races, concurrent reads or updates of the list item must be synchronized with the update of the
list item that occurs as a result of the copyprivate clause.
Syntax
The syntax of the copyprivate clause is as follows:
copyprivate(list)
DescriptionThe effect of the copyprivate clause on the specified list items occurs after the
execution of the structured block associated with the single construct (see Section 2.8.2
on page 256), and before any of the threads in the team have left the barrier at the end of the
construct.
In all other implicit tasks that belong to the parallel region, each specified list item becomes defined
with the value of the corresponding list item in the implicit task associated with the thread that executed the
structured block. For variables of non-array type, the definition occurs by copy assignment. For an array of
elements of non-array type, each element is copied by copy assignment from an element of the array in the
data environment of the implicit task that is associated with the thread that executed the structured
block to the corresponding element of the array in the data environment of the other implicit
tasks
For class types, a copy assignment operator is invoked. The order in which copy assignment operators for
different variables of class type are called is unspecified.
If a list item does not have the POINTER attribute, then in all other implicit tasks that belong to the
parallel region, the list item becomes defined as if by intrinsic assignment with the value of the
corresponding list item in the implicit task that is associated with the thread that executed the structured
block. If the list item has a type bound procedure as a defined assignment, the assignment is performed by
the defined assignment.
If the list item has the POINTER attribute, then, in all other implicit tasks that belong to the parallel
region, the list item receives, as if by pointer assignment, the same association status of the
corresponding list item in the implicit task that is associated with the thread that executed the structured
block.
The order in which any final subroutines for different variables of a finalizable type are called is
unspecified.
Note – The copyprivate clause is an alternative to using a shared variable for the value when providing
such a shared variable would be difficult (for example, in a recursion requiring a different variable at each
level).
RestrictionsThe restrictions to the copyprivate clause are as follows:
All
list
items
that
appear
in
the
copyprivate
clause
must
be
either
threadprivate
or
private
in
the
enclosing
context.
A
list
item
that
appears
in
a
copyprivate
clause
may
not
appear
in
a
private
or
firstprivate
clause
on
the
single
construct.
∙ A variable of class type (or array thereof) that appears in a copyprivate clause requires an accessible
unambiguous copy assignment operator for the class type.
∙ A common block that appears in a copyprivate clause must be threadprivate.
∙ Pointers with the INTENT(IN) attribute may not appear in the copyprivate clause.
∙ The list item with the ALLOCATABLE attribute must have the allocation status of allocated when the
intrinsic assignment is performed.
∙ If the list item is a polymorphic variable with the ALLOCATABLE attribute, the behavior is
unspecified.