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