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.
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). 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.21.5.
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.
If individual members of a common block appear in a data-sharing attribute clause other than the shared clause, the variables no longer have a Fortran storage association with the common block.
Summary The 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.21.1.1).
Syntax
The syntax of the default clause is as follows:
default(data-sharing-attribute)
where data-sharing-attribute is one of the following:
shared
firstprivate
private
none
Description If data-sharing-attribute is shared or, for Fortran, firstprivate or private, the data-sharing attribute of all variables referenced in the construct that have implicitly determined data-sharing attributes will be data-sharing-attribute.
If data-sharing-attribute is firstprivate or private, each variable with static storage duration that is declared in a namespace or global scope and 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. The data-sharing attribute of all other variables that are referenced in the construct and that have implicitly determined data-sharing attributes will be data-sharing-attribute.
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.
Restrictions Restrictions to the default clause are as follows:
Summary The 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)
Description All 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.
The association status of a shared pointer becomes undefined upon entry to and exit from a 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.
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.21.1.2. 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.
Restrictions Restrictions to the shared clause are as follows:
Summary The 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.21.3. 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 an order clause that specifies concurrent is also present.
Restrictions Restrictions to the private clause are as specified in Section 2.21.3.
Summary The 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)
Description The firstprivate clause provides a superset of the functionality provided by the private clause.
The list items that appear in a firstprivate clause may include named constants.
A list item that appears in a firstprivate clause is subject to the private clause semantics described in Section 2.21.4.3, except as noted. In addition, the new list item is initialized from the original list item that exists 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.
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.
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.
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 original list item has a compatible type-bound defined assignment, in which case initialization of the new list items occurs as if by the 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.
Restrictions Restrictions to the firstprivate clause are as follows:
∙ A variable of class type (or array thereof) that appears in a firstprivate clause requires an accessible, unambiguous copy constructor for the class type.
∙ If a list item in a firstprivate clause on a worksharing construct has a reference type then it must bind to the same object for all threads of the team.
∙ If the list item is a polymorphic variable with the ALLOCATABLE attribute, the behavior is unspecified.
Summary The 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
Description The 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.21.4.3. In addition, when a lastprivate clause without the conditional modifier appears on a directive and the list item is not an iteration variable of one of the associated loops, 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 or the list item is an iteration variable of one of the associated loops, if sequential execution of the loop nest would assign a value to the list item then the original list item is assigned the value that the list item would have after sequential execution of the loop nest.
For an array of elements of non-array type, each element is assigned to the corresponding element of the original array.
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.
When the conditional modifier does not appear on the lastprivate clause, any list item that is not an iteration variable of the associated loops and that is not assigned a value by the sequentially last iteration of the loops, or by the lexically last section construct, has an unspecified value after the construct. When the conditional modifier does not appear on the lastprivate clause, a list item that is the iteration variable of an associated loop and that would not be assigned a value during sequential execution of the loop nest has an unspecified value 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.
Restrictions Restrictions to the lastprivate clause are as follows:
∙ A variable of class type (or array thereof) that appears in a lastprivate clause requires an accessible, unambiguous default constructor for the class type, unless the list item is also specified in a firstprivate clause. ∙ A variable of class type (or array thereof) that appears in a lastprivate clause requires an accessible, unambiguous copy assignment operator for the class type. The order in which copy assignment operators for different variables of class type are called is unspecified.
∙ If a list item in a lastprivate clause on a worksharing construct has a reference type then it must bind to the same object for all threads of the team.
∙ A variable that appears in a lastprivate clause must be definable. ∙ If the original list item has the ALLOCATABLE attribute, the corresponding list item of which the value is assigned to the original item must have an allocation status of allocated upon exit from the sequentially last iteration or lexically last section construct. ∙ If the list item is a polymorphic variable with the ALLOCATABLE attribute, the behavior is unspecified.
Summary The 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.
Description The 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.21.4.3 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 logical iteration of the associated loops 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 logical iteration of the associated loops 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 Restrictions to the linear clause are as follows:
∙ A list-item that appears in a linear clause must be of integral or pointer type.
∙ A list-item that appears in a linear clause without the ref modifier must be of integral or pointer type, or must be a reference to an integral or pointer type. ∙ The ref or uval modifier can only be used if the list-item is of a reference type. ∙ If a list item in a linear clause on a worksharing construct has a reference type then it must bind to the same object for all threads of the team. ∙ If the list item is of a reference type and the ref modifier is not specified and if any write to the list item occurs before any read of the list item then the result is unspecified.
∙ A list-item that appears in a linear clause without the ref modifier must be of type integer. ∙ The ref or uval modifier can only be used if the list-item is a dummy argument without the VALUE attribute. ∙ Variables that have the POINTER attribute and Cray pointers may not appear in a linear clause. Cray pointer support has been deprecated. ∙ If the list item has the ALLOCATABLE attribute and the ref modifier is not specified, the allocation status of the list item in the sequentially last iteration must be allocated upon exit from that iteration. ∙ If the ref modifier is specified, variables with the ALLOCATABLE attribute, assumed-shape arrays and polymorphic variables may not appear in the linear clause. ∙ If the list item is a dummy argument without the VALUE attribute and the ref modifier is not specified, any read of the list item must occur before any write to the list item. ∙ A common block name cannot appear in a linear clause.