CO_REDUCE — Reduction of values on the current set of images#
-
CO_REDUCE(A, OPERATOR, RESULT_IMAGE, STAT, ERRMSG)#
CO_REDUCEdetermines element-wise the reduction of the value ofAon all images of the current team. The pure function passed asOPERATIONis used to pairwise reduce the values ofAby passing either the value ofAof different images or the result values of such a reduction as argument. IfAis an array, the deduction is done element wise. IfRESULT_IMAGEis present, the result values are returned inAon the specified image only and the value ofAon the other images become undefined. IfRESULT_IMAGEis not present, the value is returned on all images. If the execution was successful andSTATis present, it is assigned the value zero. If the execution failed,STATgets assigned a nonzero value and, if present,ERRMSGgets assigned a value describing the occurred error.- Parameters:
A – is an
INTENT(INOUT)argument and shall be nonpolymorphic. If it is allocatable, it shall be allocated; if it is a pointer, it shall be associated.Ashall have the same type and type parameters on all images of the team; if it is an array, it shall have the same shape on all images.OPERATION – 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 asA. The function shall be the same on all images and with regards to the arguments mathematically commutative and associative. Note thatOPERATIONmay 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 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
- Standard:
Technical Specification (TS) 18508 or later
- Class:
Collective subroutine
- Syntax:
CALL CO_REDUCE(A, OPERATION, [, RESULT_IMAGE, STAT, ERRMSG])
- Example:
program test integer :: val val = this_image () call co_reduce (val, result_image=1, operation=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
- Note:
While the rules permit in principle an intrinsic function, none of the intrinsics in the standard fulfill the criteria of having a specific function, which takes two arguments of the same type and returning that type as result.
- See also:
CO_MIN — Minimal value on the current set of images, CO_MAX — Maximal value on the current set of images, CO_SUM — Sum of values on the current set of images, CO_BROADCAST — Copy a value to all images the current set of images