CO_REDUCE— Reduction of values on the current set of images
CO_REDUCEdetermines element-wise the reduction of the value of A on all images of the current team. The pure function passed as OPERATOR is used to pairwise reduce the values of A by passing either the value of A of different images or the result values of such a reduction as argument. If A is an array, the deduction is done element wise. If RESULT_IMAGE is present, the result values are returned in A on the specified image only and the value of A on the other images become undefined. If RESULT_IMAGE is not present, the value is returned on all images. If the execution was successful and STAT is present, it is assigned the value zero. If the execution failed, STAT gets assigned a nonzero value and, if present, ERRMSG gets assigned a value describing the occurred error.
CALL CO_REDUCE(A, OPERATOR, [, RESULT_IMAGE, STAT, ERRMSG])
|A||is an |
|OPERATOR||pure function with two scalar nonallocatable
arguments, which shall be nonpolymorphic and have the same type and type
parameters as A. The function shall return a nonallocatable scalar of
the same type and type parameters as A. The function shall be the same on
all images and with regards to the arguments mathematically commutative and
associative. Note that OPERATOR may not be an elemental function, unless
it is an intrisic function.
|RESULT_IMAGE||(optional) a scalar integer expression; if
present, it shall have the same the same value on all images and refer to an
image of the current team.
|STAT||(optional) a scalar integer variable
|ERRMSG||(optional) a scalar character variable
program test integer :: val val = this_image () call co_reduce (val, result_image=1, operator=myprod) if (this_image() == 1) then write(*,*) "Product value", val ! prints num_images() factorial end if contains pure function myprod(a, b) integer, value :: a, b integer :: myprod myprod = a * b end function myprod end program test