2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
8 CO_REDUCE --- Reduction of values on the current set of images
9 **************************************************************
11 .. index:: CO_REDUCE, Collectives, generic reduction
13 .. function:: CO_REDUCE(A, OPERATOR, RESULT_IMAGE, STAT, ERRMSG)
15 ``CO_REDUCE`` determines element-wise the reduction of the value of :samp:`{A}`
16 on all images of the current team. The pure function passed as :samp:`{OPERATION}`
17 is used to pairwise reduce the values of :samp:`{A}` by passing either the value
18 of :samp:`{A}` of different images or the result values of such a reduction as
19 argument. If :samp:`{A}` is an array, the deduction is done element wise. If
20 :samp:`{RESULT_IMAGE}` is present, the result values are returned in :samp:`{A}` on
21 the specified image only and the value of :samp:`{A}` on the other images become
22 undefined. If :samp:`{RESULT_IMAGE}` is not present, the value is returned on all
23 images. If the execution was successful and :samp:`{STAT}` is present, it is
24 assigned the value zero. If the execution failed, :samp:`{STAT}` gets assigned
25 a nonzero value and, if present, :samp:`{ERRMSG}` gets assigned a value describing
29 is an ``INTENT(INOUT)`` argument and shall be
30 nonpolymorphic. If it is allocatable, it shall be allocated; if it is a pointer,
31 it shall be associated. :samp:`{A}` shall have the same type and type parameters on
32 all images of the team; if it is an array, it shall have the same shape on all
36 pure function with two scalar nonallocatable
37 arguments, which shall be nonpolymorphic and have the same type and type
38 parameters as :samp:`{A}`. The function shall return a nonallocatable scalar of
39 the same type and type parameters as :samp:`{A}`. The function shall be the same on
40 all images and with regards to the arguments mathematically commutative and
41 associative. Note that :samp:`{OPERATION}` may not be an elemental function, unless
42 it is an intrisic function.
45 (optional) a scalar integer expression; if
46 present, it shall have the same value on all images and refer to an
47 image of the current team.
50 (optional) a scalar integer variable
53 (optional) a scalar character variable
56 Technical Specification (TS) 18508 or later
62 .. code-block:: fortran
64 CALL CO_REDUCE(A, OPERATION, [, RESULT_IMAGE, STAT, ERRMSG])
67 .. code-block:: fortran
72 call co_reduce (val, result_image=1, operation=myprod)
73 if (this_image() == 1) then
74 write(*,*) "Product value", val ! prints num_images() factorial
77 pure function myprod(a, b)
78 integer, value :: a, b
85 While the rules permit in principle an intrinsic function, none of the
86 intrinsics in the standard fulfill the criteria of having a specific
87 function, which takes two arguments of the same type and returning that