HOME
| OPENMP API Specification: Version 5.0 November 2018

2.19.4  Data-Sharing Attribute Clauses

Several constructs accept clauses that allow a user to control the data-sharing attributes of variables referenced in the construct. Not all of the clauses listed in this section are valid on all directives. The set of clauses that is valid on a particular directive is described with the directive.

Most of the clauses accept a comma-separated list of list items (see Section 2.1 on page 104). All list items that appear in a clause must be visible, according to the scoping rules of the base language. With the exception of the default clause, clauses may be repeated as needed. A list item may not appear in more than one clause on the same directive, except that it may be specified in both firstprivate and lastprivate clauses.

The reduction data-sharing attribute clauses are explained in Section 2.19.5 on page 873.

SVG-Viewer needed.

If a variable referenced in a data-sharing attribute clause has a type derived from a template, and the program does not otherwise reference that variable then any behavior related to that variable is unspecified.

SVG-Viewer needed.

SVG-Viewer needed.

When a named common block appears in a private, firstprivate, lastprivate, or shared clause of a directive, none of its members may be declared in another data-sharing attribute clause in that directive. When individual members of a common block appear in a private, firstprivate, lastprivate, reduction, or linear clause of a directive, the storage of the specified variables is no longer Fortran associated with the storage of the common block itself.

SVG-Viewer needed.

2.19.4.1 default Clause

SummaryThe default clause explicitly determines the data-sharing attributes of variables that are referenced in a parallel, teams, or task generating construct and would otherwise be implicitly determined (see Section 2.19.1.1 on page 777).

Syntax

SVG-Viewer needed.

The syntax of the default clause is as follows:  

 
default(shared | none)  

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the default clause is as follows:  

 
default(private | firstprivate | shared | none)  

SVG-Viewer needed.

DescriptionThe default(shared) clause causes all variables referenced in the construct that have implicitly determined data-sharing attributes to be shared.

SVG-Viewer needed.

The default(firstprivate) clause causes all variables in the construct that have implicitly determined data-sharing attributes to be firstprivate.

The default(private) clause causes all variables referenced in the construct that have implicitly determined data-sharing attributes to be private.

SVG-Viewer needed.

The default(none) clause requires that each variable that is referenced in the construct, and that does not have a predetermined data-sharing attribute, must have its data-sharing attribute explicitly determined by being listed in a data-sharing attribute clause.

RestrictionsThe restrictions to the default clause are as follows:

2.19.4.2 shared Clause

SummaryThe shared clause declares one or more list items to be shared by tasks generated by a parallel, teams, or task generating construct.

Syntax

The syntax of the shared clause is as follows:  

 
shared(list)  

DescriptionAll references to a list item within a task refer to the storage area of the original variable at the point the directive was encountered. The programmer must ensure, by adding proper synchronization, that storage shared by an explicit task region does not reach the end of its lifetime before the explicit task region completes its execution.

SVG-Viewer needed.

The association status of a shared pointer becomes undefined upon entry to and exit from the parallel, teams, or task generating construct if it is associated with a target or a subobject of a target that appears as a privatized list item in a data-sharing attribute clause on the construct.

SVG-Viewer needed.

Note – Passing a shared variable to a procedure may result in the use of temporary storage in place of the actual argument when the corresponding dummy argument does not have the VALUE or CONTIGUOUS attribute and its data-sharing attribute is implementation-defined as per the rules in Section 2.19.1.2 on page 800. These conditions effectively result in references to, and definitions of, the temporary storage during the procedure reference. Furthermore, the value of the shared variable is copied into the intervening temporary storage before the procedure reference when the dummy argument does not have the INTENT(OUT) attribute, and is copied out of the temporary storage into the shared variable when the dummy argument does not have the INTENT(IN) attribute. Any references to (or definitions of) the shared storage that is associated with the dummy argument by any other task must be synchronized with the procedure reference to avoid possible data races.

SVG-Viewer needed.

SVG-Viewer needed.

RestrictionsThe restrictions for the shared clause are as follows:

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

SVG-Viewer needed.

2.19.4.3 private Clause

SummaryThe private clause declares one or more list items to be private to a task or to a SIMD lane.

Syntax

The syntax of the private clause is as follows:  

 
private(list)  

Description The private clause specifies that its list items are to be privatized according to Section 2.19.3 on page 827. Each task or SIMD lane that references a list item in the construct receives only one new list item, unless the construct has one or more associated loops and the order(concurrent) clause is also present.

List items that appear in a private, firstprivate, or reduction clause in a parallel construct may also appear in a private clause in an enclosed parallel, worksharing, loop, task, taskloop, simd, or target construct.

List items that appear in a private or firstprivate clause in a task or taskloop construct may also appear in a private clause in an enclosed parallel, loop, task, taskloop, simd, or target construct.

List items that appear in a private, firstprivate, lastprivate, or reduction clause in a worksharing construct may also appear in a private clause in an enclosed parallel, loop, task, simd, or target construct.

List items that appear in a private clause on a loop construct may also appear in a private clause in an enclosed loop, parallel, or simd construct.

RestrictionsThe restrictions to the private clause are as specified in Section 2.19.3.

Cross References

2.19.4.4 firstprivate Clause

SummaryThe firstprivate clause declares one or more list items to be private to a task, and initializes each of them with the value that the corresponding original item has when the construct is encountered.

Syntax

The syntax of the firstprivate clause is as follows:  

 
firstprivate(list)  

DescriptionThe firstprivate clause provides a superset of the functionality provided by the private clause. A list item that appears in a firstprivate clause is subject to the private clause semantics described in Section 2.19.4.3 on page 850, except as noted. In addition, the new list item is initialized from the original list item existing before the construct. The initialization of the new list item is done once for each task that references the list item in any statement in the construct. The initialization is done prior to the execution of the construct.

For a firstprivate clause on a parallel, task, taskloop, target, or teams construct, the initial value of the new list item is the value of the original list item that exists immediately prior to the construct in the task region where the construct is encountered unless otherwise specified. For a firstprivate clause on a worksharing construct, the initial value of the new list item for each implicit task of the threads that execute the worksharing construct is the value of the original list item that exists in the implicit task immediately prior to the point in time that the worksharing construct is encountered unless otherwise specified.

To avoid data races, concurrent updates of the original list item must be synchronized with the read of the original list item that occurs as a result of the firstprivate clause.

SVG-Viewer needed.

For variables of non-array type, the initialization occurs by copy assignment. For an array of elements of non-array type, each element is initialized as if by assignment from an element of the original array to the corresponding element of the new array.

SVG-Viewer needed.

SVG-Viewer needed.

For each variable of class type:

If copy constructors are called, the order in which copy constructors for different variables of class type are called is unspecified.

SVG-Viewer needed.

SVG-Viewer needed.

If the original list item does not have the POINTER attribute, initialization of the new list items occurs 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, the new list items will have the same status.

If the original list item has the POINTER attribute, the new list items receive the same association status of the original list item as if by pointer assignment.

SVG-Viewer needed.

RestrictionsThe restrictions to the firstprivate clause are as follows:

2.19.4.5 lastprivate Clause

SummaryThe lastprivate clause declares one or more list items to be private to an implicit task or to a SIMD lane, and causes the corresponding original list item to be updated after the end of the region.

Syntax

The syntax of the lastprivate clause is as follows:  

 
lastprivate([ lastprivate-modifier:] list)  

where lastprivate-modifier is:  

 
conditional  

DescriptionThe lastprivate clause provides a superset of the functionality provided by the private clause. A list item that appears in a lastprivate clause is subject to the private clause semantics described in Section 2.19.4.3 on page 850. In addition, when a lastprivate clause without the conditional modifier appears on a directive, the value of each new list item from the sequentially last iteration of the associated loops, or the lexically last section construct, is assigned to the original list item. When the conditional modifier appears on the clause, if an assignment to a list item is encountered in the construct then the original list item is assigned the value that is assigned to the new list item in the sequentially last iteration or lexically last section in which such an assignment is encountered.

SVG-Viewer needed.

For an array of elements of non-array type, each element is assigned to the corresponding element of the original array.

SVG-Viewer needed.

SVG-Viewer needed.

If the original list item does not have the POINTER attribute, its update occurs as if by intrinsic assignment unless it has a type bound procedure as a defined assignment.

If the original list item has the POINTER attribute, its update occurs as if by pointer assignment.

SVG-Viewer needed.

When the conditional modifier does not appear on the lastprivate clause, list items that are not assigned a value by the sequentially last iteration of the loops, or by the lexically last section construct, have unspecified values after the construct. Unassigned subcomponents also have unspecified values after the construct.

If the lastprivate clause is used on a construct to which neither the nowait nor the nogroup clauses are applied, the original list item becomes defined at the end of the construct. To avoid data races, concurrent reads or updates of the original list item must be synchronized with the update of the original list item that occurs as a result of the lastprivate clause.

Otherwise, If the lastprivate clause is used on a construct to which the nowait or the nogroup clauses are applied, accesses to the original list item may create a data race. To avoid this data race, if an assignment to the original list item occurs then synchronization must be inserted to ensure that the assignment completes and the original list item is flushed to memory.

If a list item that appears in a lastprivate clause with the conditional modifier is modified in the region by an assignment outside the construct or not to the list item then the value assigned to the original list item is unspecified.

RestrictionsThe restrictions to the lastprivate clause are as follows:

2.19.4.6 linear Clause

SummaryThe linear clause declares one or more list items to be private and to have a linear relationship with respect to the iteration space of a loop associated with the construct on which the clause appears.

Syntax

SVG-Viewer needed.

The syntax of the linear clause is as follows:  

 
linear(linear-list[ : linear-step])  

where linear-list is one of the following  

 
list 
modifier(list)  

where modifier is one of the following:  

 
val  

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the linear clause is as follows:  

 
linear(linear-list[ : linear-step])  

where linear-list is one of the following  

 
list 
modifier(list)  

where modifier is one of the following:  

 
ref 
val 
uval  

SVG-Viewer needed.

SVG-Viewer needed.

The syntax of the linear clause is as follows:  

 
linear(linear-list[ : linear-step])  

where linear-list is one of the following  

 
list 
modifier(list)  

where modifier is one of the following:  

 
ref 
val 
uval  

SVG-Viewer needed.

DescriptionThe linear clause provides a superset of the functionality provided by the private clause. A list item that appears in a linear clause is subject to the private clause semantics described in Section 2.19.4.3 on page 850 except as noted. If linear-step is not specified, it is assumed to be 1. When a linear clause is specified on a construct, the value of the new list item on each iteration of the associated loop(s) corresponds to the value of the original list item before entering the construct plus the logical number of the iteration times linear-step. The value corresponding to the sequentially last iteration of the associated loop(s) is assigned to the original list item.

When a linear clause is specified on a declarative directive, all list items must be formal parameters (or, in Fortran, dummy arguments) of a function that will be invoked concurrently on each SIMD lane. If no modifier is specified or the val or uval modifier is specified, the value of each list item on each lane corresponds to the value of the list item upon entry to the function plus the logical number of the lane times linear-step. If the uval modifier is specified, each invocation uses the same storage location for each SIMD lane; this storage location is updated with the final value of the logically last lane. If the ref modifier is specified, the storage location of each list item on each lane corresponds to an array at the storage location upon entry to the function indexed by the logical number of the lane times linear-step.

Restrictions