On Sunday, May 3, 2020 at 8:28:38 AM UTC+10,
ga...@u.washington.edu wrote:
> On Saturday, May 2, 2020 at 5:32:31 AM UTC-7,
r......@gmail.com wrote:
>
> (snip, I wrote)
>
> > > Just a note on one not so obvious difference between Fortran
> > > and PL/I regarding array expressions.
>
> > > Fortran gives the value as if (if it doesn't actually) the whole
> > > right side is evaluated before changing the left side. Consider:
>
> > > A = A + A(5)
>
> > That's because an array assignment is treated as loop in which
> > the elements are are processed in order, thus:
>
> > DO I = 1 TO N;
> > A(I) = A(I) + A(5);
> > END;
>
> That is the Fortran example, which does NOT treat it that way.
No, that's the PL/I example. That's how PL/I does it.
Note that no temporary array is created.
> > > Fortran guarantees NOT to use the changed value of A(5).
>
> > > PL/I, on the other hand, designed when memory was small, or otherwise,
> > > guarantees to use the changed value. That is, as if (if not actually)
> > > it is done element by element in memory order.
>
> Yes, PL/I treats it like a loop, but even more, requires it to
> be done that way. They could have left it undefined, such that
> future parallel processors could do it without a loop.
There's nothing to stop PL/I array operations from being done
by parallel processors.
That particular case [A = A + A(5); ] would probably have to be done
by looping over all the elements.
It's not the sort of thing one would write in an array operation.
BTW, A = RANDOM(); when A is an array, generates an array filled
with random numbers, because the assignment is carried out in a loop.
The random function returns one pseudo-random number at each call.
> Fortran, on the other hand, requires a temporary
Not particularly efficient when the elements need to be copied
one at a time to the target array. On non-parallel hardware,
essentially, there are two loops -- one to evaluate an expression
and to store the result in a temporary array, and the other
to copy the elements from the temporary array to the target array.