HOME
| OPENMP API Specification: Version 5.1 November 2020

2.21.6  Data Copying Clauses

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

SVG-Viewer needed.

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.

SVG-Viewer needed.

SVG-Viewer needed.

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.

SVG-Viewer needed.

SVG-Viewer needed.

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:

SVG-Viewer needed.

Restrictions Restrictions to the copyin clause are as follows:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

Cross References

2.21.6.2 copyprivate Clause

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.

SVG-Viewer needed.

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.

SVG-Viewer needed.

SVG-Viewer needed.

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.

SVG-Viewer needed.

SVG-Viewer needed.

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.

SVG-Viewer needed.

SVG-Viewer needed.

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).

SVG-Viewer needed.

Restrictions Restrictions to the copyprivate clause are as follows:

Cross References