Malcolm Cohen malcolm
Thu Jan 16 18:59:00 EST 2014

```Bill Long wrote:
> We can fix this by changing the requirement for OPERATOR to ?shall be a pure
> function with two scalar argument??.

Yes. This is the correct fix.

John Reid wrote:
>Surely we want it to be elemental since SOURCE may be any array.

Why?  We can apply pure procedures elementally, indeed that is what FORALL does
all the time.  Your argument says that FORALL does not work.  But it does!
(Often slowly, but it does work; the deficiencies of FORALL are not related to
purity...)

> Note
>that SUM, MAX, MIN are elemental.

No, SUM is not elemental.  None of SUM, MAX or MIN can be passed as dummy
arguments so are red herring elephants.

Bill Long continued:
> If we require that OPERATOR have two scalar dummy arguments of the right type,
> then for an array SOURCE in a CO_REDUCE call,  the operation is just applied
> to elements

Absolutely.  There is no difficulty doing this because CO_REDUCE is not
elemental (and therefore is permitted to have a procedure argument).  If the
arguments to CO_REDUCE are arrays, one could imagine that there is a FORALL
inside CO_REDUCE that applies the ***PURE*** procedure elementally ***in
parallel*** to the arrays.

John suggested:
>
>C1234 (R1223) A nonintrinsic elemental procedure shall not be used as an
>actual argument except in an invocation of the intrinsic subroutine
>CO_REDUCE.

This makes the language less useful, harder to use, and less consistent.  Just
NO.

Bill replied:
>Except that there is a reason for the constraint in the first place, and I don?t see how CO_REDUCE is sufficiently special to ignore that.

John wrote:
>I can't remember what the reason is.

I can.  It was to permit differing implementation methods for elemental
procedures, in particular (as Van noted) the mechanism where the underlying
procedure has descriptor arguments and for any elemental application there is
only one call to the underlying procedure and if any array traversal is needed
it happens inside that.

But anyway there is absolutely no need whatsoever for the operation argument of
CO_REDUCE to be elemental, not any need at all.  PURE is ***precisely*** what is
required.

Cheers,
--
................................Malcolm Cohen, Nihon NAG, Tokyo.

```