Intel® Fortran Compiler 17.0 Developer Guide and Reference
Parallel Directive Clause: Provides a superset of the functionality provided by the PRIVATE clause. It declares one or more variables to be private to an implicit task, and causes the corresponding original variable to be updated after the end of the region.
LASTPRIVATE (list)
list |
Is the name of one or more variables or common blocks that are accessible to the scoping unit. Subobjects cannot be specified. Each name must be separated by a comma, and a named common block must appear between slashes (/ /). |
Variables that appear in a LASTPRIVATE list are subject to PRIVATE clause semantics. In addition, once the parallel region is exited, each variable has the value provided by the sequentially last section or loop iteration.
If the original variable has the POINTER attribute, its update occurs as if by pointer assignment.
If the original variable does not have the POINTER attribute, its update occurs as if by intrinsic assignment.
When the LASTPRIVATE clause appears in a DO directive, the thread that executes the sequentially last iteration updates the version of the object it had before the construct. When the LASTPRIVATE clause appears in a SECTIONS directive, the thread that executes the lexically last SECTION updates the version of the object it had before the construct.
Subobjects that are not assigned a value by the last iteration of the DO or the lexically last SECTION of the SECTIONS directive are undefined after the construct.
The original variable becomes defined at the end of the construct if there is an implicit barrier at that point. To avoid race conditions, concurrent reads or updates of the original variable must be synchronized with the update of the original variable that occurs as a result of the LASTPRIVATE clause.
If the LASTPRIVATE clause is used in a construct for which NOWAIT is specified, accesses to the original variable may create a data race. To avoid this, synchronization must be inserted to ensure that the sequentially last iteration or lexically last section construct has stored and flushed that variable.
The following are restrictions for the LASTPRIVATE clause:
A variable that is part of another variable (as an array or structure element) must not appear in a PRIVATE clause.
A variable that is private within a parallel region, or that appears in the REDUCTION clause of a PARALLEL construct, must not appear in a LASTPRIVATE clause on a worksharing construct if any of the corresponding worksharing regions ever binds to any of the corresponding parallel regions.
A variable that appears in a LASTPRIVATE clause must be definable.
An original variable with the ALLOCATABLE attribute must be in the allocated state at entry to the construct containing the LASTPRIVATE clause. The variable in the sequentially last iteration or lexically last section must be in the allocated state upon exit from that iteration or section with the same bounds as the corresponding original variable.
Assumed-size arrays must not appear in a PRIVATE clause.
Variables that appear in NAMELIST statements, in variable format expressions, and in expressions for statement function definitions, must not appear in a PRIVATE clause.
If a list item appears in both the FIRSTPRIVATE and LASTPRIVATE clauses, the update required for LASTPRIVATE occurs after all of the initializations for FIRSTPRIVATE.
If a variable appears in both FIRSTPRIVATE and LASTPRIVATE clauses, the update required for LASTPRIVATE occurs after all initializations for FIRSTPRIVATE..
Consider the following:
!$OMP DO PRIVATE(I) LASTPRIVATE(B)
DO I = 1, 1000
B = I
ENDDO
!$OMP END DO
In this case, after the construct is exited, variable B has the value 1000.
Consider the following:
!$OMP SECTIONS LASTPRIVATE(B)
!$OMP SECTION
B = 2
!$OMP SECTION
B = 4
!$OMP SECTION
D = 6
!$OMP END SECTIONS
In this case the thread that executes the lexically last SECTION updates the original variable B to have a value of 4. However, variable D was not specified in the LASTPRIVATE clause, so it has an undefined value after the construct is exited.