Intel® Fortran Compiler 16.0 User and Reference Guide

LASTPRIVATE

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:

Note

If a variable appears in both FIRSTPRIVATE and LASTPRIVATE clauses, the update required for LASTPRIVATE occurs after all initializations for FIRSTPRIVATE..

Example

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.

See Also