Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!tdatirv!sarima From: sarima@tdatirv.UUCP (Stanley Friesen) Newsgroups: comp.lang.c Subject: Re: Column-wise data storage for matrices in C, any advantage(s)? Keywords: store data in rows/columns, memory traffic, gaxpy rich Message-ID: <123@tdatirv.UUCP> Date: 2 Feb 91 18:10:07 GMT References: <1991Feb1.214342.4982@portia.Stanford.EDU> Reply-To: sarima@tdatirv.UUCP (Stanley Friesen) Distribution: na Organization: Teradata Corp., Irvine Lines: 21 In article <1991Feb1.214342.4982@portia.Stanford.EDU> fangchin@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)