[comp.lang.fortran] Why array notation

mercer@mozart.uucp (Randall Mercer) (11/04/88)

Does anyone know why FORTRAN-8x uses array notation rather than some 
form of parallel do loop?  What is the advantage of writing

	A(1:N)=B(2:N+1)+C(1:N)

rather than something like:

	PDO 10 I=1,N			! PDO for "PARALLEL DO"
10      A(I)=B(I+1)+C(I)

The latter requires minimal syntactic changes and, for long loops, is
more concise and readable.  Is the problem with the details of defining
"PDO", or is it some more strategic reason?

khb%chiba@Sun.COM (Keith Bierman - Sun Tactical Engineering) (11/05/88)

In article <689@convex.UUCP> mercer@mozart.UUCP (Randall Mercer) writes:
>Does anyone know why FORTRAN-8x uses array notation rather than some 
>form of parallel do loop?  What is the advantage of writing
>
>	A(1:N)=B(2:N+1)+C(1:N)
>
>rather than something like:
>
>	PDO 10 I=1,N			! PDO for "PARALLEL DO"
>10      A(I)=B(I+1)+C(I)
>
>The latter requires minimal syntactic changes and, for long loops, is
>more concise and readable.  Is the problem with the details of defining
>"PDO", or is it some more strategic reason?

As I recall, there were several reasons:

1)	Array notation was originally attractive to hardware types,
	and was intended to be relatively easy for existing and proposed
	array processors.

2)	Arrays are a mathematical "first class object" and providing
	them in the language will help fill a semantic gap between
	what scientists write, and what computers want.

3)	To a certain extent, it is adopting current practice, as
	extended fortrans (like the Q8 facility in CDC fortran) have
	similar notation.

4)	related to 2: in the most common case, where we want to
	operate on the arrays in the "natural" fashion, it is simpler, viz

		A = B+C  

	I think your case translates as

	        A = B(2:N+1)+C

Parallel structures were considered to be too researchy to be in f88,
array operations were not (since they do exist in some fortrans, all
APL's, and many other research languages).

Members of the committee (rather than Observers like myself) may have
more detailed recollections.

Keith H. Bierman
It's Not My Fault ---- I Voted for Bill & Opus

smryan@garth.UUCP (Steven Ryan) (11/06/88)

>	PDO 10 I=1,N			! PDO for "PARALLEL DO"
>10      A(I)=B(I+1)+C(I)
>
>The latter requires minimal syntactic changes and, for long loops, is
>more concise and readable.  Is the problem with the details of defining
>"PDO", or is it some more strategic reason?

perhaps:

(1) say what you mean, don't use something that looks sequential for parallel.

(2) what about

            PDO I=1,N
              A(I)=A(I+1)+A(I-1))

    or

            PDO I=1,N
              B(I)=A(I)+C(I)
              A(I)=A(I)+B(I+1)
              C(I)=C(I)+B(I-1)
-- 
                                                   -- s m ryan
+---------------------------------------+--------------------------------------+
|    ....such cultural highlights as    |    Nature is Time's way of having    |
|    Alan Thicke, and, uh,....          |    pausible deniability.             |
+---------------------------------------+--------------------------------------+

mercer@mozart.uucp (Randall Mercer) (11/07/88)

In article <1763@garth.UUCP> smryan@garth.UUCP (Steven Ryan) writes:
>>	PDO 10 I=1,N			! PDO for "PARALLEL DO"
>>10      A(I)=B(I+1)+C(I)
>>
>>The latter requires minimal syntactic changes and, for long loops, is
>>more concise and readable.  Is the problem with the details of defining
>>"PDO", or is it some more strategic reason?
>
>perhaps:
>
>(1) say what you mean, don't use something that looks sequential for parallel.
>
Use of PDO instead of DO should make it look parallel.  I think syntactic
simplicity is an advantage here.

>(2) what about
>
>            PDO I=1,N
>              A(I)=A(I+1)+A(I-1))
>
>    or
>
>            PDO I=1,N
>              B(I)=A(I)+C(I)
>              A(I)=A(I)+B(I+1)
>              C(I)=C(I)+B(I-1)

There are many different ways of resolving these problems, suggesting that
one might want more than one variety of PDO.  For example, you could 
define the statements to be executed sequentially, but each statement to
be executed as an array operation and array assignment.  Essentially that
would give FORTRAN 8x semantics with the triplet notation "factored" out
of several statements into the PDO.  A more useful definition for a vector
machine would prohibit recurrences and dependencies whose direction is
counter to statement order (like the antidependency from B(I+1) to B(I)=
in your second example.  A useful variant for a MIMD machine would
prohibit all dependencies between iterations.  For a SIMD machine, 
PDO could be defined to load all right-hand sides, then store all left-hand
sides.  Your first example would be quite meaningful with that definition.
I think I would rather have MIMD_PDO, SIMD_PDO, and VECTOR_PDO, then have
to learn a distinct syntax for each variation.

Other reasons I've seen in responses for preferring array notation are

	(1) it's easier to implement
	(2) it's usually more concise
	(3) it's less researchy and has already been done
	(4) it lets you manipulate arrays as "first-class" objects

I don't believe (1).
(2) is true for APL, but only sounds plausible for FORTRAN 8x.
I've seen FORTRAN code with very odd indexing that would translate to very
expansive and ugly triplet notation.
(3) is sort of true, but virtually every vectorizing or parallelizing compiler
has some kind of PDO equivalent implemented with directives.
(4) is an appealing reason to me.  How far does FORTRAN 8x go in providing
APL-like support for array manipulations?

lfm@fpssun.fps.com (Larry Meadows) (11/10/88)

[ bunch of stuff about Parallel DO versus array notation ]

Well, there was the FORALL statement in an earlier version
of '8X:
	FORALL (I=1:N) A(I) = B(I) + C(I)

FORALL says all iterations are done at once, so in simple
cases is equivalent to array assignments, but is less restrictive,
e.g.
	FORALL (I=1:N) A(I,I) = B(I)

Also, there are notations like that used by Kuck & Associates'
KAP tool:
	DOALL (I = 1:N)
	  A(I) = B(I) + C(I)
	END DOALL

DOALL says iterations may be executed in parallel in any order;
so:
	DOALL (I=1:N)
	  A(I) = (A(I-1) + A(I+1))/2
	END DOALL

gives undefined results.
-- 
Larry Meadows @ FPS			...!tektronix!fpssun!lfm
					...!nosun!fpssun!lfm