home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / misc / 2940 < prev    next >
Encoding:
Internet Message Format  |  1992-09-07  |  4.6 KB

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!sdd.hp.com!swrinde!network.ucsd.edu!poincare.ucsd.edu!mbk
  2. From: mbk@poincare.ucsd.edu (Matt Kennel)
  3. Newsgroups: comp.lang.misc
  4. Subject: Re: Sather loops (was Re: Scientists as ...
  5. Message-ID: <188rq8INNkev@network.ucsd.edu>
  6. Date: 4 Sep 92 23:34:32 GMT
  7. References: <ARI.HUTTUNEN.92Sep4021832@supergirl.hut.fi>
  8. Organization: Institute For Nonlinear Science, UCSD
  9. Lines: 114
  10. NNTP-Posting-Host: poincare.ucsd.edu
  11. X-Newsreader: Tin 1.1 PL3
  12.  
  13. Ari.Huttunen@hut.fi (Ari Juhani Huttunen) writes:
  14. : ! IMHO the above are quite poor syntax for expressing the kinds of loops
  15. : ! that I see in numerical code.  Quite often it is possible to work in
  16. : ! parallel, and all the above do is make it harder to extract the
  17. : ! parallelism (of course so does the FORTRAN notation, but there is not
  18. : ! reason to make the same mistake :-).
  19. : I can't know what kinds of loops you see in numerical code, so I can't
  20. : comment on that. I got the impression from the previous article that
  21. : a for-loop is wanted. Now it is not wanted?
  22. : As for the parallelism... You *do not* extract parallelism from
  23. : a sequential program. You design a parallel program. That is not
  24. : the same thing. Extracting parallelism from a sequantial loop does
  25. : not help 0.01 cents if the computer has 64000 processors and now
  26. : it uses 3 of them instead of 1.
  27.  
  28. Right.  There should be a distinction between "Do F(X) for all X"
  29. (which is parallel) and "Repeat G until something H happens", which
  30. isn't.
  31.  
  32. : !  In the cases where it is not
  33. : ! numerical, syntax like the above is often useless as it is usually
  34. : ! restricted so that you can only iterate over integer indices (cf
  35. : ! Oberon-2).  Note some languages get this right and let you iterate
  36. : ! over whatever you want e.g. Eiffel and C (given Sather's parentage I
  37. : ! guess it does to)
  38.  
  39. But what you're iterating over has to be at least "isomorphic" to integers,
  40. no?
  41.  
  42. : Sather has the same loop construct that Eiffel has, and it is written
  43. : on my list. The reason why I put the for-loop in the list is that it
  44. : is so common. Take a look at this piece of code from the Sather library:
  45. :       -- Clear out the array. 
  46. :       i:INT; until i=asize1 loop
  47. :      j:INT; until j=asize2 loop
  48. :         k:INT; until k=asize3 loop
  49. :            [i,j,k]:=void;
  50. :            k:=k+1;
  51. :         end; -- loop
  52. :         j:=j+1;
  53. :      end; -- loop
  54. :      i:=i+1; 
  55. :       end; -- loop
  56. : With the for-loop it becomes shorter and much easier to read. To see
  57. : what I mean, note that at the first sight, you look at the beginning 
  58. : of the rows and see 'for ...'. You immediately notice a keyword. In
  59. : contrast the above code has 'k:INT; ...' at the beginning. 
  60. :       -- Clear out the array. 
  61. :       for i:INT to asize1 loop
  62. :      for j:INT to asize2 loop
  63. :         for k:INT to asize3 loop
  64. :            [i,j,k]:=void;
  65. :         end; -- loop
  66. :      end; -- loop
  67. :       end; -- loop
  68. : You wouldn't need the for-loop for iterating over the elements of a list
  69. : (for example), so it need not be overly general.
  70.  
  71. Again, if you're going to be doing real iteration like this (and almost
  72. always you're looping through some elements of an array), one really
  73. wants to say
  74.  
  75. forall(i,j,k) a[i,j,k] := 0.0 end;
  76.  
  77. and be done with it. (I think my posts on this same subject are iterating
  78. out to infinity....sorry).
  79.  
  80. Perhaps one needs a difference between a "forall"
  81. in which no sequential order of execution is enforced, and a
  82. "forallinsequence" (choose a better name) in which it is.  In many cases,
  83. following the exact sequential order is not required, but present languages
  84. don't make this distinction, and thus have to go through 9 circles of hades
  85. and back to figure this out when the programmer knew it all along.
  86.  
  87. : The existing loop is
  88. : perfect for that. You could, however, have something like:
  89. :     for r=0.0 to 5.3 step 0.1 loop
  90. :         ...
  91. :     end
  92.  
  93. No, I wouldn't like this.  I think there's a difference between:
  94.  
  95.     for i = 0 to 53 loop
  96.         r = 0.1 * i;
  97.  
  98.     end;
  99.  
  100. and 
  101.     r := 0.0;
  102.     until r > 5.3 loop
  103.  
  104.        r:= r + 0.1;
  105.     end;
  106.  
  107. that makes a big enough difference in reality that I think it's advisable
  108. for the user to have to say exactly which is desired.  Using the for
  109. statement like that may screw up new programmers who assume it works
  110. one way when in fact the other happens.
  111.  
  112. : ...............................................................................
  113. : Ari Huttunen                      Any similarity to other alien life forms
  114.  
  115. --
  116. -Matt Kennel          mbk@inls1.ucsd.edu
  117. -Institute for Nonlinear Science, University of California, San Diego
  118. -*** AD: Archive for nonlinear dynamics papers & programs: FTP to
  119. -***     lyapunov.ucsd.edu, username "anonymous".
  120.