home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!sdd.hp.com!swrinde!network.ucsd.edu!poincare.ucsd.edu!mbk
- From: mbk@poincare.ucsd.edu (Matt Kennel)
- Newsgroups: comp.lang.misc
- Subject: Re: Sather loops (was Re: Scientists as ...
- Message-ID: <188rq8INNkev@network.ucsd.edu>
- Date: 4 Sep 92 23:34:32 GMT
- References: <ARI.HUTTUNEN.92Sep4021832@supergirl.hut.fi>
- Organization: Institute For Nonlinear Science, UCSD
- Lines: 114
- NNTP-Posting-Host: poincare.ucsd.edu
- X-Newsreader: Tin 1.1 PL3
-
- Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes:
- : ! IMHO the above are quite poor syntax for expressing the kinds of loops
- : ! that I see in numerical code. Quite often it is possible to work in
- : ! parallel, and all the above do is make it harder to extract the
- : ! parallelism (of course so does the FORTRAN notation, but there is not
- : ! reason to make the same mistake :-).
- :
- : I can't know what kinds of loops you see in numerical code, so I can't
- : comment on that. I got the impression from the previous article that
- : a for-loop is wanted. Now it is not wanted?
- :
- : As for the parallelism... You *do not* extract parallelism from
- : a sequential program. You design a parallel program. That is not
- : the same thing. Extracting parallelism from a sequantial loop does
- : not help 0.01 cents if the computer has 64000 processors and now
- : it uses 3 of them instead of 1.
-
- Right. There should be a distinction between "Do F(X) for all X"
- (which is parallel) and "Repeat G until something H happens", which
- isn't.
-
- : ! In the cases where it is not
- : ! numerical, syntax like the above is often useless as it is usually
- : ! restricted so that you can only iterate over integer indices (cf
- : ! Oberon-2). Note some languages get this right and let you iterate
- : ! over whatever you want e.g. Eiffel and C (given Sather's parentage I
- : ! guess it does to)
-
- But what you're iterating over has to be at least "isomorphic" to integers,
- no?
-
- : Sather has the same loop construct that Eiffel has, and it is written
- : on my list. The reason why I put the for-loop in the list is that it
- : is so common. Take a look at this piece of code from the Sather library:
- :
- : -- Clear out the array.
- : i:INT; until i=asize1 loop
- : j:INT; until j=asize2 loop
- : k:INT; until k=asize3 loop
- : [i,j,k]:=void;
- : k:=k+1;
- : end; -- loop
- : j:=j+1;
- : end; -- loop
- : i:=i+1;
- : end; -- loop
- :
- : With the for-loop it becomes shorter and much easier to read. To see
- : what I mean, note that at the first sight, you look at the beginning
- : of the rows and see 'for ...'. You immediately notice a keyword. In
- : contrast the above code has 'k:INT; ...' at the beginning.
- :
- : -- Clear out the array.
- : for i:INT to asize1 loop
- : for j:INT to asize2 loop
- : for k:INT to asize3 loop
- : [i,j,k]:=void;
- : end; -- loop
- : end; -- loop
- : end; -- loop
- :
- : You wouldn't need the for-loop for iterating over the elements of a list
- : (for example), so it need not be overly general.
-
- Again, if you're going to be doing real iteration like this (and almost
- always you're looping through some elements of an array), one really
- wants to say
-
- forall(i,j,k) a[i,j,k] := 0.0 end;
-
- and be done with it. (I think my posts on this same subject are iterating
- out to infinity....sorry).
-
- Perhaps one needs a difference between a "forall"
- in which no sequential order of execution is enforced, and a
- "forallinsequence" (choose a better name) in which it is. In many cases,
- following the exact sequential order is not required, but present languages
- don't make this distinction, and thus have to go through 9 circles of hades
- and back to figure this out when the programmer knew it all along.
-
- : The existing loop is
- : perfect for that. You could, however, have something like:
- :
- : for r=0.0 to 5.3 step 0.1 loop
- : ...
- : end
-
- No, I wouldn't like this. I think there's a difference between:
-
- for i = 0 to 53 loop
- r = 0.1 * i;
-
- end;
-
- and
- r := 0.0;
- until r > 5.3 loop
-
- r:= r + 0.1;
- end;
-
- that makes a big enough difference in reality that I think it's advisable
- for the user to have to say exactly which is desired. Using the for
- statement like that may screw up new programmers who assume it works
- one way when in fact the other happens.
-
- : ...............................................................................
- : Ari Huttunen Any similarity to other alien life forms
-
- --
- -Matt Kennel mbk@inls1.ucsd.edu
- -Institute for Nonlinear Science, University of California, San Diego
- -*** AD: Archive for nonlinear dynamics papers & programs: FTP to
- -*** lyapunov.ucsd.edu, username "anonymous".
-