### 15.2.2.6 REDUCTION Clause (TU*X only)

The REDUCTION clause performs a commutative reduction operation on the specified variables. It takes the following form:

  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 scalar variables or intrinsic type 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 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 Table 15-2).

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.

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.

Table 15-2 lists the operators and intrinsics and their initialization values. The actual initialization value will be consistent with the data type of the reduction variable.

Table 15-2 Initialization Values for REDUCTION Operators and Intrinsics (TU*X only)

Operator | Initialization Value
--- | ---
+ | 0
* | 1
- | 0
.AND. | .TRUE.
.OR. | .FALSE.
.EQV. | .TRUE.
.NEQV. | .FALSE.
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.

Previous Page Next Page Table of Contents