Column-wise data storage for matrices in C, any advantage(s)?

Stanley Friesen sarima at tdatirv.UUCP
Sun Feb 3 05:10:07 AEST 1991


In article <1991Feb1.214342.4982 at portia.Stanford.EDU> fangchin at elaine46.stanford.edu (Chin Fang) writes:
>Now, note that this algorithm requires most rapid changes in indixing occuring
>in COLUMNS, not rows!
>
>I believe in default C design, data is stored in rows (discussed in K&R II)
>instead in columns. ...
>However, if a so declared matrix is used in gaxpy, the memory traffic caused
>by pointer jumping (figuratively speaking) for a large matrix is significant

Good grief!!  The answer is really quite simple.  Store the 'transpose' of
the external matrix in the C matrix!  That is reverse the order of the
indexes, storing the 'real' columns in C 'rows'.   The whole thing is just
a linguistic convention anyway - if you define the last index as refering
to columns instead of rows, the columns are now magically varying the fastest.

In this mode it is only during input and output that you do the nasty pointer
jumping. And I/O delays will dominate over any inefficiencies there, so it
doesn't really matter as much as during calculations.
-- 
---------------
uunet!tdatirv!sarima				(Stanley Friesen)



More information about the Comp.lang.c mailing list