home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / os / os2 / programm / 3705 < prev    next >
Encoding:
Internet Message Format  |  1992-07-21  |  5.8 KB

  1. Xref: sparky comp.os.os2.programmer:3705 comp.lang.fortran:2795
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!usc!cs.utexas.edu!rutgers!modus!gear!cadlab!martelli
  3. From: martelli@cadlab.sublink.org (Alex Martelli)
  4. Newsgroups: comp.os.os2.programmer,comp.lang.fortran
  5. Subject: Re: 32 Bit Fortran Compiler ??
  6. Message-ID: <1992Jul21.140038.27900@cadlab.sublink.org>
  7. Date: 21 Jul 92 14:00:38 GMT
  8. References: <hjkirch.710065189@morpheus> <ignacij.710085875@meishan.animal.uiuc.edu> <1992Jul06.073701.19620@cadlab.sublink.org> <ignacij.710603357@meishan.animal.uiuc.edu> <1992Jul15.155450.22340@cadlab.sublink.org> <ignacij.711385250@meishan.animal.uiuc.edu>
  9. Organization: CAD.LAB S.p.A., Bologna, Italia
  10. Lines: 176
  11.  
  12. ignacij@meishan.animal.uiuc.edu (Ignacy Misztal) writes:
  13.     ...
  14. :I agree that mixing types between the program and the subroutine should 
  15. :be avoided. What happens, if it brings a 4 times improvement in speed? 
  16. :Forget the standard if the code will run 1 week instead of 4, and it 
  17. :runs on almost every compiler.  The 4 time improvement example is below,
  18. :and it works with f77 compiler.
  19. :c this is a slow program with f77 compilers
  20. :       real x(1000)
  21. :       read(1)n,(x(i),i=1,n)
  22. :       end
  23. :
  24. :c this is a fast program with f77 compilers
  25. :       real x(1000)
  26. :       call get(n,x)
  27. :       end
  28. :       subroutine(n,x)
  29. :       character x*4000
  30. :       read(1)n,x(1:4*n)
  31. :       end
  32. :
  33. :I know that the inability of the f77 compilers to fold implicit loops
  34.  
  35. I have tried to reproduce your results and failed utterly.  First of
  36. all the runtimes of the above programs are of course in the noise.
  37. So I tried to amplify them a bit as follows: as p1.f I have:
  38. c this is an (allegedly) slow program with f77 compilers
  39.        real x(1000)
  40.        open(unit=1,file='pdat',form='unformatted')
  41.        do 10,j=1,100
  42.        rewind(1)
  43.        read(1)n,(x(i),i=1,n)
  44. 10     continue
  45.        end
  46.  
  47. As p2.f I have:
  48. c this is an (allegedly) fast program with f77 compilers
  49.        real x(1000)
  50.        open(unit=1,file='pdat',form='unformatted')
  51.        do 10,j=1,100
  52.        rewind(1)
  53.        call get(n,x)
  54. 10     continue
  55.        end
  56.        subroutine get(n,x)
  57.        character x*4000
  58.        read(1)n,x(1:4*n)
  59.        end
  60.  
  61. I compile each with "f77 -o p1 p1.f" and "f77 -o p2 p2.f" on the HP9000/400
  62. workstation I'm on at present.
  63. I build a datafile for them to read with the following program p3.f:
  64. c create file to try things out
  65.        real x(1000)
  66.        open(unit=1,file='pdat',form='unformatted')
  67.        n=567
  68.        do 10,i=1,n
  69. 10     x(i)=i/float(n)
  70.        write(1)n,(x(i),i=1,n)
  71.        end
  72.  
  73. compiled of course with "f77 -o p3 p3.f".  Then I perform:
  74. p3 ; p2 ; p1       # avoid caching effects
  75. for i in 1 2 3 4 5
  76. do
  77.     time p1
  78. done >p1.tim 2>&1
  79. for i in 1 2 3 4 5
  80. do
  81.     time p2
  82. done >p2.tim 2>&1
  83.  
  84. and here is p1.tim:
  85.  
  86. real    0m0.20s
  87. user    0m0.04s
  88. sys    0m0.14s
  89.  
  90. real    0m0.18s
  91. user    0m0.02s
  92. sys    0m0.12s
  93.  
  94. real    0m0.20s
  95. user    0m0.02s
  96. sys    0m0.16s
  97.  
  98. real    0m0.18s
  99. user    0m0.02s
  100. sys    0m0.12s
  101.  
  102. real    0m0.18s
  103. user    0m0.04s
  104. sys    0m0.14s
  105.  
  106. and here is p2.tim:
  107.  
  108. real    0m0.20s
  109. user    0m0.02s
  110. sys    0m0.16s
  111.  
  112. real    0m0.20s
  113. user    0m0.02s
  114. sys    0m0.16s
  115.  
  116. real    0m0.18s
  117. user    0m0.00s
  118. sys    0m0.16s
  119.  
  120. real    0m0.18s
  121. user    0m0.06s
  122. sys    0m0.10s
  123.  
  124. real    0m0.20s
  125. user    0m0.04s
  126. sys    0m0.16s
  127.  
  128.  
  129. I fail to notice ANY statistically significant difference between elapsed,
  130. usermode OR sysmode times of these two programs, MUCH LESS the alleged
  131. "FOUR TIMES" improvement!
  132.  
  133. I *assume* if I took the time and trouble to run these on our Apollo's,
  134. VAXen, IBM 6150's, DOS boxes, RS6000's, SONY NeWS's, DECsystems, and so
  135. on ad nauseam, I WOULD find situations in which either of these programs
  136. would surprisingly come out much faster than the other one.  ON THE OTHER
  137. HAND, I *KNOW FOR SURE* that I would find situations in which the second,
  138. standard-violating program would UNsurprisingly crash and burn, while the
  139. first, allegedly "slow on f77" one (which runs PERFECTLY FINE when
  140. compiled by f77 on this here 68030 box) WILL run on all of these boxes.
  141.  
  142. :in the read statement is a weakness that will be corrected soon (in
  143. :a couple of years?). But now, there is no alternative. I know that
  144. :some people will suggest breaking the read statement into 2, etc., at a
  145. :considerable cost. However, my program has to run fast now. 
  146.  
  147. Try separating out the I/O; on most of the boxes I have around here,
  148. doing the I/O *IN A C LANGUAGE SUBROUTINE* called from your Fortran
  149. program (sigh!) will, depending on various factors, accelerate your
  150. I/O bound programs by 20%-80%.  Sad, but true.  This will certainly
  151. not hold everywhere, so you'll have to have at hand a Fortran routine
  152. to link instead of the C one for the "exceptional" (HA!) boxes where
  153. the Fortran runtime I/O library IS as well-tuned as it SHOULD be.
  154.  
  155. :By the way, how can I equivalence a section of an integer vector
  156. :(position known at run time only), to a character string?
  157.  
  158. You equivalence the *total* integer vector to a LONG character string,
  159. or to an array of longish character strings.  There are of course no
  160. guarantees in the standard about how long you CAN make a character
  161. string, or an array of them, OR an array of integers for that matter
  162. (e.g. the infamous 64K-byte limits on old Fortran PC compilers), so
  163. you may run against one or more such limitations.
  164.  
  165. Example:
  166.       integer*4 iarra(1000)
  167.       character chst*4000
  168.       equivalence (iarra,chst)
  169.       call iwantints(iarra(40),60)
  170.       call iwantchar(chst(161:400))
  171.       end
  172.       subroutine iwantints(ints,n)
  173.       integer*4 n,ints(n)
  174. c whatever
  175.       end
  176.       subroutine iwantchar(chars)
  177.       character*(*) chars
  178. c whatever else
  179.       end
  180.  
  181. [SORRY for the NON-standard '*4' on 'integer', but after getting burned
  182. BADLY by old d*mned standard-VIOLATING 16-bit compilers where "integer"
  183. meant TWO bytes, I guess I'm psychologically scarred for life on this!-].
  184.  
  185. -- 
  186. Email: martelli@cadlab.sublink.org                   Phone: ++39 (51) 6130360
  187. CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia   Fax: ++39 (51) 6130294 
  188.