]>
Commit | Line | Data |
---|---|---|
c63539ff ML |
1 | .. |
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. | |
5 | ||
6 | .. _co_reduce: | |
7 | ||
8 | CO_REDUCE --- Reduction of values on the current set of images | |
9 | ************************************************************** | |
10 | ||
11 | .. index:: CO_REDUCE, Collectives, generic reduction | |
12 | ||
13 | .. function:: CO_REDUCE(A, OPERATOR, RESULT_IMAGE, STAT, ERRMSG) | |
14 | ||
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 | |
26 | the occurred error. | |
27 | ||
28 | :param A: | |
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 | |
33 | images. | |
34 | ||
35 | :param OPERATION: | |
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. | |
43 | ||
44 | :param RESULT_IMAGE: | |
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. | |
48 | ||
49 | :param STAT: | |
50 | (optional) a scalar integer variable | |
51 | ||
52 | :param ERRMSG: | |
53 | (optional) a scalar character variable | |
54 | ||
55 | Standard: | |
56 | Technical Specification (TS) 18508 or later | |
57 | ||
58 | Class: | |
59 | Collective subroutine | |
60 | ||
61 | Syntax: | |
62 | .. code-block:: fortran | |
63 | ||
64 | CALL CO_REDUCE(A, OPERATION, [, RESULT_IMAGE, STAT, ERRMSG]) | |
65 | ||
66 | Example: | |
67 | .. code-block:: fortran | |
68 | ||
69 | program test | |
70 | integer :: val | |
71 | val = this_image () | |
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 | |
75 | end if | |
76 | contains | |
77 | pure function myprod(a, b) | |
78 | integer, value :: a, b | |
79 | integer :: myprod | |
80 | myprod = a * b | |
81 | end function myprod | |
82 | end program test | |
83 | ||
84 | Note: | |
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 | |
88 | type as result. | |
89 | ||
90 | See also: | |
91 | :ref:`CO_MIN`, | |
92 | :ref:`CO_MAX`, | |
93 | :ref:`CO_SUM`, | |
3ed1b4ce | 94 | :ref:`CO_BROADCAST` |