home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / c / 16441 < prev    next >
Encoding:
Text File  |  1992-11-12  |  2.1 KB  |  52 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!europa.asd.contel.com!darwin.sura.net!udel!sbcs.sunysb.edu!csws8.ic.sunysb.edu!rhorn
  3. From: rhorn@csws8.ic.sunysb.edu (Robert Horn)
  4. Subject: Re: Reasons for using C vs. Fortran or vice/versa
  5. Message-ID: <1992Nov13.043250.28205@sbcs.sunysb.edu>
  6. Sender: usenet@sbcs.sunysb.edu (Usenet poster)
  7. Nntp-Posting-Host: csws8.ic.sunysb.edu
  8. Organization: State University of New York at Stony Brook
  9. References: <1992Nov12.135901.15191@ccd.harris.com> <1992Nov12.205823.13951@u.washington.edu> <gay.721614205@sfu.ca>
  10. Distribution: usa
  11. Date: Fri, 13 Nov 1992 04:32:50 GMT
  12. Lines: 38
  13.  
  14. rons@hardy.u.washington.edu (Ronald Schoenberg) writes:
  15. >  Fortran arrays are column echelon for a
  16. >reason, and C arrays are row echelon slowing down matrix operations
  17. >relative to Fortran.     
  18.  
  19. Wouldn't FORTRAN arrays actually be slower? consider the normal
  20.  
  21.   for(index = 0; index < kRows; index++) {
  22.     for(jndex = 0; jndex < kColumns; jndex++) {
  23.       myArray[index][jndex] ...
  24.     }
  25.   }
  26.  
  27. one normally accesses matrices in a row major fashion (index changes less
  28. often than jndex), so if your array is stored row major, and your cache is
  29. nice enough to bring in the words around what you need (since you may well
  30. access these as well), the time to access each element should be slightly
  31. faster with row major than column major (if you access like above (as does
  32. nearly everyone)). Also, the compiler can compute myArray[index] at the top of
  33. the loop and use an offset from that to compute the location of the jndexth
  34. element. psuedo-assembly code might look like...
  35.  
  36.   lea        myArray,a2
  37.   ;; asm for index for loop
  38.   ;; asm for jndex for loop
  39.   ;; assuming ints to be 2 bytes long
  40.   move.w     2*jndex(a2),d0             ;; access myArray[index][jndex]
  41.   ;; end jndex for loop
  42.   add.l       #2*kColumns,a2
  43.   ;; end index for loop
  44.  
  45. I've always heard that column major matrices were one of the stupidest aspects
  46. of FORTRAN.
  47.  
  48.  
  49. -- 
  50. rhorn@ic.sunysb.edu         Never choose a college because it has a duckpond.
  51. $@`                                             Send me hate mail, I love it.
  52.