alphalinux.org high-perf list (1998-2001)
 help / color / mirror / Atom feed
From: Adam C. Powell, IV <adam.powell@nist.gov>
Subject: Re: Optimizing CRS-Matrix routines
Date: Fri, 04 Dec 1998 14:52:16 -0500	[thread overview]
Message-ID: <36683D70.5A8AEAF2@nist.gov> (raw)
In-Reply-To: <3667cc2e2696002@u8455.bs.ptb.de>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2670 bytes --]

Thomas Bruns wrote:

> Hi,

>

> recently I modified the code of a FEM-Application due to the

> information on loop otimization from Mr. Goto, and it was a real

> improvement.

> But those optimization base on fixed loop-boundaries.

>

> How can I optimize code as it is used in sparse matrix applications

> where the index of the non-zero-elements is a an array of it`s own

> like:

> ---------------------------

> double vector[MatrixDimension];

> double vector[MatrixDimension];

>

> double matrix[NumberOfNonZeroElements]; /* only nze of matrix */

> int matrix_idx[NumberOfNonZeroElements];     /* col_idxt */

> int matrix_ptr[MatrixDimension+1];      /* start of row */

>

> for (row=0; row<MaxRow; row++)

>         for(ptr=matrix_ptr[row];  ptr<matrixptr[row+1]; ptr++)

>                 vector[matrix_idx[ptr]] += matrix[ptr]*vector[matrix_idx[ptr]]

> ---------------------------

> You can't do manual loop-unrolling here, can you ?!?!

Why not just:

for (row=0; row<MaxRow; row++) {

  for(ptr=matrix_ptr[row];  ptr<matrix_ptr[row+1]-5; ptr+=6) {

    vector[matrix_idx[ptr]] += matrix[ptr]*vector[matrix_idx[ptr]];

    vector[matrix_idx[ptr+1]] += matrix[ptr+1]*vector[matrix_idx[ptr+1]];

    vector[matrix_idx[ptr+2]] += matrix[ptr+2]*vector[matrix_idx[ptr+2]];

    vector[matrix_idx[ptr+3]] += matrix[ptr+3]*vector[matrix_idx[ptr+3]];

    vector[matrix_idx[ptr+4]] += matrix[ptr+4]*vector[matrix_idx[ptr+4]];

    vector[matrix_idx[ptr+5]] += matrix[ptr+5]*vector[matrix_idx[ptr+5]]; }

  while(ptr<matrix_ptr[row+1]) {

    vector[matrix_idx[ptr]] += matrix[ptr]*vector[matrix_idx[ptr]]; ptr++; }}

(Untested, just threw it together, I hope Netscape doesn't line-wrap it to

death!)  Now, I don't know how much this will speed things up, if at all, because

of C's assumptions (see the case for fortran on the alphalinux.org high

performance page).  An assembler version could be massively faster though...

To optimize further, blocking (using some messy conditions in the for loop)

*might* help for some vectors of size >10000; but for FEM, the matrices tend to

be at least somewhat "blocked" anyway (depending on the node ordering) so I'm not

convinced it would help much.

But the point is, I think you do have fixed loop boundaries, because you know

matrix_ptr[row] and [row+1] in advance.  Right?

Anyone interested in collaborating on some fast sparse matrix routines? :-)

Zeen,

-Adam `Cold Fusion' Powell, IV http://www.ctcms.nist.gov/~powell/ ____

USDoC, National Institute of Standards & Technology (NIST)  |\ ||<  |

Center for Theoretical and Computational Materials Science  | \||_> |

  reply	other threads:[~1998-12-04 19:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-12-04 11:42 Optimizing CRS-Matrix routines Thomas Bruns
1998-12-04 19:52 ` Adam [this message]
1998-12-05  2:06   ` pshimizu
1998-12-08  0:36     ` Adam
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox