alphalinux.org high-perf list (1998-2001)
 help / color / mirror / Atom feed
* Optimizing CRS-Matrix routines
@ 1998-12-04 11:42 Thomas Bruns
  1998-12-04 19:52 ` Adam
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Bruns @ 1998-12-04 11:42 UTC (permalink / raw)


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

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 ?!?!

Any Information welcome !

        Thanks,	

                        Thomas

------------------------------------------------------

Dipl. Phys. Thomas Bruns                    phone : 0531/592-1217

Physikalisch Technische Bundesanstalt       Fax   :         -1205

Bundesalle 100                              e-mail: Thomas.Bruns@ptb.de

Postfach 3345

38023 Braunscweig

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Optimizing CRS-Matrix routines
  1998-12-04 11:42 Optimizing CRS-Matrix routines Thomas Bruns
@ 1998-12-04 19:52 ` Adam
  1998-12-05  2:06   ` pshimizu
  0 siblings, 1 reply; 4+ messages in thread
From: Adam @ 1998-12-04 19:52 UTC (permalink / raw)


[-- 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  | \||_> |

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Optimizing CRS-Matrix routines
  1998-12-04 19:52 ` Adam
@ 1998-12-05  2:06   ` pshimizu
  1998-12-08  0:36     ` Adam
  0 siblings, 1 reply; 4+ messages in thread
From: pshimizu @ 1998-12-05  2:06 UTC (permalink / raw)


I can be software pipelined also. :-)

In article <36683D70.5A8AEAF2@nist.gov>

adam.powell@nist.gov writes:

>>  An assembler version could be massively faster though...

If the vector/matrices size is large, the routine will cause extensive

miss of the cache, and it will run only with the memory speed. In that

case assembler will not help much, I think.

(Of course this assumption strongly depends on how dense the matrices are.)

Anyway, if we will write an assembler version, we should stay with

C/FORTRAN version for algorithm/strategy validation (as we did 

in the gemm code) until there is no other way to speed up. 

If we need, we can issue prefetch/preload instructions inline even within

the C code.

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

I would like to!

Naohiko Shimizu,

School of Engr. Tokai Univ.

http://shimizu-lab.et.u-tokai.ac.jp/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Optimizing CRS-Matrix routines
  1998-12-05  2:06   ` pshimizu
@ 1998-12-08  0:36     ` Adam
  0 siblings, 0 replies; 4+ messages in thread
From: Adam @ 1998-12-08  0:36 UTC (permalink / raw)


pshimizu@fa2.so-net.ne.jp wrote:

> I can be software pipelined also. :-)

>

> In article <36683D70.5A8AEAF2@nist.gov>

> adam.powell@nist.gov writes:

>

> >>  An assembler version could be massively faster though...

>

> If the vector/matrices size is large, the routine will cause extensive

> miss of the cache, and it will run only with the memory speed. In that

> case assembler will not help much, I think.

> (Of course this assumption strongly depends on how dense the matrices are.)

It seems that with this routine (essentially gemv), the matrix elements should

not be stored, since they're never re-used.  So, I was thinking, the right and

left side vectors could sit in cache (assuming their total size is smaller than

~10000 doubles), and the routine would be limited by either the processor or the

memory speed- probably memory speed- to slurp through the matrix and indices.

> Anyway, if we will write an assembler version, we should stay with

> C/FORTRAN version for algorithm/strategy validation (as we did

> in the gemm code) until there is no other way to speed up.

> If we need, we can issue prefetch/preload instructions inline even within

> the C code.

Cool.  So this means we can limit the cache profile of the matrix and indices, to

keep the vectors in cache, right?  Of course, if the vectors are too big to be

cached, the optimal loading strategy will depend on the matrix structure.  Ekh!

Sounds like a horrible problem!

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  | \||_> |

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1998-12-08  0:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-12-04 11:42 Optimizing CRS-Matrix routines Thomas Bruns
1998-12-04 19:52 ` Adam
1998-12-05  2:06   ` pshimizu
1998-12-08  0:36     ` Adam

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