Intel® Fortran Compiler 18.0 Developer Guide and Reference

PRIVATE Clause

Parallel Directive Clause: Declares one or more variables to be private to each thread in a team.

PRIVATE (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 (/ /).

This clause allows each thread to have its own copy of the variable and makes it a local variable to the thread.

The following occurs when variables are declared in a PRIVATE clause:

The value and allocation status of the original variable will change only in the following cases:

If a variable has the ALLOCATABLE attribute, the following rules apply:

A variable that appears in a PRIVATE clause may be storage-associated with other variables when the PRIVATE clause is encountered by constructs such as EQUIVALENCE or COMMON. If A is a variable appearing in a PRIVATE clause and B is a variable that is storage-associated with A, then the following applies:

The following are restrictions for the PRIVATE clause:

Variables in a list can appear in other clauses as follows:

NOTE

Variables that are used as counters for explicit or implicit DO loops or FORALL commands, or common blocks that are specified to be THREADPRIVATE become automatically private to each thread, even though they are not explicitly included inside a PRIVATE clause at the beginning of the scope of the parallel region.

Example

Consider the following:

!$OMP PARALLEL PRIVATE(A, B)

In this simple case, each thread will have its own copy of variables A and B. The variables can have different values in each thread because the variables are local to the thread.

See Also