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

ID 767251
Date 7/13/2023
Public

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

Document Table of Contents

CO_REDUCE

Collective Intrinsic Subroutine (Generic): Performs generalized reduction across images.

CALL CO_REDUCE (a, operation [, result_image, stat, errmsg])

a

(Input; output) Must be non-polymorphic, non-coindexed, with the same shape, type and type parameters in corresponding references. It may not be a coindexed object. If a is scalar, the computed value is the result of the reduction of applying operation to the values of a in all corresponding references. If a is an array, each element of the computed value is equal to the result of the reduction of the reduction operation of applying operation to corresponding elements of a in all corresponding references.

If no error occurs, the computed value is assigned to a on all images of the current team if result_image is not present, or on the executing image if the executing image is the image identified by result_image. Otherwise, a becomes undefined.

operation

Is a pure function with exactly two arguments whose result and each argument are a scalar, nonallocatable, nonpointer, nonpolymorphic data object with the same type and kind type parameters as a. Neither argument can be optional. If one argument has the attribute TARGET, VOLATILE, or ASYNCHRONOUS, the other argument must have that attribute. operation must implement a mathematical associative operation and be the same in each corresponding reference. If operation is not commutative, the computed value may depend on the order of evaluation.

The computed value of a reduction operation over a set of values is the result of an iterative process. Each iteration evaluates operation (x, y) for x and y in that set, the removal of x and y from that set, and the addition of the result of operation (x, y) to that set. The process ends when the set has a single value, which is the computed value.

result_image

(Input; optional) Must be a scalar integer. If present, it must be present with the same value in all corresponding references and be a valid image index in the current team. If result_image is not present, it cannot be present in any corresponding reference.

stat

(Output; optional) Must be a non-coindexed integer scalar with a decimal exponent range of at least four (KIND=2 or greater). The value assigned to stat is specified in Overview of Collective Subroutines. If stat is not present and an error condition occurs, error termination is initiated.

errmsg

(Input; output; optional) Must be a non-coindexed default character scalar variable. The semantics of errmsg is described inOverview of Collective Subroutines.

Example

The following subroutine demonstrates how CO_REDUCE can be used to create a collective version of the intrinsic function ANY.

SUBROUTINE CO_ANY (VALUE)
  LOGICAL,INTENT(INOUT) :: VALUE
  CALL CO_REDUCE (VALUE, COMBINER)
  CONTAINS
    PURE FUNCTION COMBINER (OPND1, OPND2)RESULT = LOGICAL_SUM
      LOGICAL                  :: LOGICAL_SUM
      LOGICAL,INTENT(IN)       :: OPND1, OPND2
      LOGICAL_SUM = OPND1 .OR. OPND2
    END FUNCTION COMBINER
END SUBROUTINE CO_ANY

If the number of images is two, and R is a four-element logical array with the value [.T., .T., .F., .F.] on image one and [.T., .F., .T., .F.] on image two, CALL CO_REDUCE (R, CO_ANY) causes the value of R to become defined with the value of [.T., .T., .T., .F.] on both images if no error occurs during the reference.