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 two clauses support copying data values from private or threadprivate variables of an
implicit task or thread to the corresponding variables of other implicit tasks or threads in the
team.
The clauses accept a comma-separated list of list items (see Section 2.1). 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.
2.21.6.1 copyin Clause
Summary
The copyin clause provides a mechanism to copy the value of a threadprivate variable of the primary
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 performed after the team is formed and prior to the execution of the associated structured block.
For variables of non-array type, the copy is 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 primary thread to the
corresponding element of the array of all other threads.
For class types, the copy assignment operator is invoked. The order in which copy assignment operators for
different variables of the same class type are invoked is unspecified.
The copy is performed, as if by assignment, after the team is formed and prior to the 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 primary 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
primary
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
primary
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,
each
copy
inherits
the
declared
type
parameters
and
the
default
type
parameter
values
from
the
original
list
item.
Restrictions
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:
the
whole
common
block
does
not
need
to
be
specified.
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.
Summary
The 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)
Description
The 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.10.2), 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).
Restrictions
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.
∙ Any list item with the ALLOCATABLE attribute must have the allocation status of allocated when the
intrinsic assignment is performed.
∙ If a list item is a polymorphic variable with the ALLOCATABLE attribute, the behavior is
unspecified.