Intel® Fortran Compiler 18.0 Developer Guide and Reference

REDUCTION

Parallel Directive Clause: Performs a reduction operation on the specified variables.

REDUCTION (operator| intrinsic: list)

operator

Is one of the following: +, *, -, .AND., .OR., .EQV., or .NEQV.

intrinsic

Is one of the following: MAX, MIN, IAND, IOR, or IEOR.

list

Is the name of one or more variables of intrinsic type that are accessible to the scoping unit. Each list item must be definable. Each name must be separated by a comma.

Assumed-size arrays, procedure pointers, and dummy arguments that are pointers with the INTENT (IN) attribute are not allowed. Array sections are allowed.

For each list item, the number of copies is unspecified.

The same list item cannot appear in both a REDUCTION and an IN_REDUCTION clause.

Variables that appear in a REDUCTION clause must be SHARED in the enclosing context. A private copy of each variable in list is created for each thread as if the PRIVATE clause had been used. The private copy is initialized according to the operator (see the table below). A dummy argument that is a pointer with the INTENT (IN) attribute must not appear in a REDUCTION clause.

At the end of the REDUCTION, the shared variable is updated to reflect the result of combining the original value of the shared reduction variable with the final value of each of the private copies using the operator specified. The reduction operators are all associative (except for subtraction), and the compiler can freely reassociate the computation of the final value; the partial results of a subtraction reduction are added to form the final value.

The value of the shared variable becomes undefined when the first thread reaches the clause containing the reduction, and it remains undefined until the reduction computation is complete. Normally, the computation is complete at the end of the REDUCTION construct.

However, if the REDUCTION clause is used in a construct to which NOWAIT is also applied, the shared variable remains undefined until a barrier synchronization has been performed. This ensures that all the threads complete the REDUCTION clause.

Any list item copies associated with the reduction must be initialized before they are accessed by the tasks participating in the reduction. After the end of the region, the original list item contains the result of the reduction.

An original list item with the POINTER attribute, or any pointer component of an original list item that is referenced, must be associated at entry to the construct that contains the REDUCTION clause. Also, the list item, or the pointer component of the list item, must not be deallocated, allocated, or pointer assigned within the region.

An original list item with the ALLOCATABLE attribute, or any allocatable component of an original list item that is referenced, must be in the allocated state at entry to the construct that contains the REDUCTION clause. Also, the list item, or the allocatable component of the list item, must be neither deallocated nor allocated within the region.

Any number of REDUCTION clauses can be specified on the directive, but a list item can appear only once in REDUCTION clauses for that directive.

If a list item is an array section, the following applies:

The REDUCTION clause must be used in a region or worksharing construct where the reduction variable is used only in a reduction statement having one of the following forms:

  x = x operator expr

  x = expr operator x (except for subtraction)

  x = intrinsic (x, expr)

  x = intrinsic (expr, x)

Some reductions can be expressed in other forms. For instance, a MAX reduction can be expressed as follows:

  IF (x .LT. expr) x = expr

Alternatively, the reduction might be hidden inside a subroutine call. Be careful that the operator you specify in the REDUCTION clause matches the reduction operation.

The following table lists the operators and intrinsics and their initialization values. The actual initialization value will be consistent with the data type of the reduction variable.

Initialization Values for REDUCTION Operators

Operator

Initialization Value

+

0

*

1

-

0

.AND.

.TRUE.

.OR.

.FALSE.

.EQV.

.TRUE.

.NEQV.

.FALSE.

Initialization Values for REDUCTION Intrinsics

Intrinsic

Initialization Value

MAX

Smallest representable number

MIN

Largest representable number

IAND

All bits on

IOR

0

IEOR

0

If a directive allows REDUCTION clauses, the number you can specify is not limited. However, each variable name can appear in only one of the clauses.

NOTE

If a variable appears in a REDUCTION clause on a combined construct for which the first construct is TARGET, it is treated as if it had appeared in a MAP clause with a map-type of TOFROM.

See Also