home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!ungar
- From: ungar@leland.Stanford.EDU (Jeffrey Ungar)
- Subject: Re: Reasons for using C vs. Fortran or vice/versa
- Message-ID: <1992Nov13.075506.29134@leland.Stanford.EDU>
- Sender: news@leland.Stanford.EDU (Mr News)
- Organization: DSG, Stanford University, CA 94305, USA
- References: <1992Nov12.205823.13951@u.washington.edu> <gay.721614205@sfu.ca> <1992Nov13.060701.6917@u.washington.edu>
- Distribution: usa
- Date: Fri, 13 Nov 92 07:55:06 GMT
- Lines: 70
-
- In article <1992Nov13.060701.6917@u.washington.edu> rons@hardy.u.washington.edu (Ronald Schoenberg) writes:
- >
- >The most important matrix operation in numerical work is the gaxpy
- >("generalized a times x plus y"). Numerical routines are written to
- >be rich in gaxpies (see Matrix Computations by Golub and Van Loan for
-
- [misleading(?) stuff about column vs. row major order deleted]
-
- >
- >#include <stdio.h>
- >
- >void main()
- >{
- > float a_col[] = { 1,5,9,13,2,6,10,14,3,7,11,15,4,8,12,16 };
- > float a_row[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
- > float x[] = { 1,2,3,4 };
- > float z[4];
- >
- > int m = 4, n = 4;
- > int i, j, k;
- >
- >/*
- >** column echelon gaxpy
- >*/
- > for (i = 0; i < m; i++) {
- > z[i] = 0;
- > k = i;
- > for (j = 0; j < n; j++) {
- > z[i] += a_col[k] * x[j];
- > k += n;
- > }
- > }
-
- This looks OK...
-
- >
- >/*
- >** row echelon gaxpy
- >*/
- > for (i = 0; i < m; i++) {
- > z[i] = 0;
- > for (j = 0; j < n; j++) {
- > k = i * n + j;
- > z[i] += a_row[k] * x[j];
- > }
- > }
- >}
-
- Well small wonder row major looks slower! It isn't coded
- like a C programmer would do it! :-) Why not
-
- k=0;
- for ( i=0; i<m; i++ ) {
- z[i]=0;
- for ( j=0; j<n; j++ ) {
- z[i]+=a_row[k]*x[j];
- k++;
- }
- }
-
- I'm sure the reason the BLAS used in M++ uses column major order is
- that it came from Fortran. There do not have to be any
- appreciable speed differences resulting from either choice. Row major
- order makes the code a little easier to understand from my perspective,
- however.
-
- Jeff
-
-
-
-