alphalinux.org high-perf list (1998-2001)
 help / color / mirror / Atom feed
From: Adam C. Powell <hazelsct@MIT.EDU>
Subject: Re: little unrolling trick
Date: Sun, 20 Dec 1998 14:44:55 +0000	[thread overview]
Message-ID: <367D0D60.C111AB59@mit.edu> (raw)
In-Reply-To: <36777c8c1153002@u8455.bs.ptb.de>

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

Thomas Bruns wrote:

> Hi Adam,

>

> > From:          "Adam C. Powell, IV" <hazelsct@MIT.EDU>

> > of a way to speed this up?  By the way, Thomas (Bruns), did you notice

> > any performance improvement using my little "loop unrolling" trick?

>

> Sorry, I did some other work on my app the last days so it took some

> time to post results

>

> your suggestion was:

>

> >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++; }}

>

> But, I think this can´t be right, since you modify the vector you

> need to multiply with ???

Oops!  You're absolutely right.  My mistake. :-)

> Anyway your `little unrolling trick´ gave me the direction to some

> faster code:

>

> my suggestion:

>

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

>         {

>         result[row] = 0;

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

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

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

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

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

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

>                                 +matrix[ptr+5]*vector[matrix_idx[ptr+5]];

>

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

>                 {

>                 result[row] +=  matrix[ptr]*vector[matrix_idx[ptr]];

>                 ptr ++;

>                 }

>         }

>

> which gave me a speedup of about 30% in that routine, which is quite

> good (I think) for now, because the matrices are quite small (~50x50

> .... 100x100) with 8 to 30 non zeros in a row.

That's great to hear!  Perhaps there is some hope for faster sparse matrix

routines after all.  It's hard to know how big to make the "blocks"- six

works here because your rows have at least 6 nonzeroes each.  For some

applications, e.g. on structured grids, it might be more efficient to treat

the "matrix" as a set of vectors and use level 1 BLAS to multiply them by

vectors (again hoping "vector" and "result" stay in cache while the vectors

that make up the matrix get swapped out).

> I did the timing with the times(....) routine of gnu-C, I don`t know

> how accurate that is.

That's what I use too. :-)

> So thank you very much for the inspiration !

You're welcome.

Zeen,

-Adam      "...the firmament sheweth His handywork" (Ps 19:1)    ///

............................................................__  ///|

Adam "Cold Fusion" Powell IV Firmament Science & Engineering\\\///_|

http://lyre.mit.edu/~powell/ Standing on the Solid State Rock\XX/  |MIGA

           reply	other threads:[~1998-12-20 14:44 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <36777c8c1153002@u8455.bs.ptb.de>]
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