Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 6/24/2024
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

FIRSTPRIVATE

Parallel Directive Clause: Provides a superset of the functionality provided by the PRIVATE clause. It declares one or more variables to be private to each thread in a team, and initializes each of them with the value of the corresponding original variable.

Syntax

FIRSTPRIVATE (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 FIRSTPRIVATE list are subject to PRIVATE clause semantics. In addition, private (local) copies of each variable in the different threads are initialized to the value the variable had upon entering the parallel region.

To avoid race conditions, which are caused by unintended sharing of data, concurrent updates of the original variable must be synchronized with the read of the original variable that occurs as a result of the FIRSTPRIVATE clause.

If the original variable has the POINTER attribute, the new variable receives the same association status of the original variable as if by pointer assignment.

If the original variable does not have the POINTER attribute, initialization of the new variable occurs as if by intrinsic assignment, unless the original variable has the allocation status of "not currently allocated". In this case, the new variable also has the status of " not currently un allocated".

The following are restrictions for the FIRSTPRIVATE clause:

  • A variable that is part of another variable (as an array or structure element) must not appear in a FIRSTPRIVATE clause.

  • A variable that is private within a parallel region must not appear in a FIRSTPRIVATE clause in a worksharing construct if any of the worksharing regions arising from the worksharing construct ever bind to any of the parallel regions arising from the parallel construct.

  • A variable that appears in a REDUCTION clause of a PARALLEL construct must not appear in a FIRSTPRIVATE clause in a worksharing or task construct if any of the worksharing or task regions arising from the worksharing or task construct ever bind to any of the parallel regions arising from the parallel construct.

  • A variable that appears in a REDUCTION clause in a WORKSHARE construct must not appear in a FIRSTPRIVATE clause in a task construct encountered during execution of any of the worksharing regions arising from the worksharing construct.

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

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:

A = 3
B = 4
!$OMP PARALLEL PRIVATE(A) FIRSTPRIVATE(B)

In this case, variable A has an undefined value at the beginning of the parallel region. However, variable B has the value 4, which was specified in the serial region preceding the parallel region.