Usenet comp.os.linux.alpha (1997-2013)
 help / color / mirror / Atom feed
From: harley@pauillac.inria.fr (Robert Harley)
Subject: Re: MFlops Comparison using g77 (bad news)
Date: 1997/09/17	[thread overview]
Message-ID: <5voauv$duu@news-rocq.inria.fr> (raw)



Luke Lonergan (luke@navo.hpc.mil) writes:
>[...]
>I implemented the kernel in C this morning.  [...]
>
>----------------------------------------------------------------------------
>/*    Operation count = 9 operations/grid point */
>
>        for (j=1;j<*ny-1;j++) {
>
>          indj   = (*nx)*j;
>          indjp1 = (*nx)*(j+1);
>          indjm1 = (*nx)*(j-1);
>
>          for (i=1;i<*nx-1;i++) {
>            indx   = i+indj;
>            psi_new[indx] = (*a1)*psi[indx+1]+(*a2)*psi[indx-1]+
>                           (*a3)*psi[i+indjp1]+(*a4)*psi[i+indjm1]-
>                           (*a5)*f[indx];
>          }
>        }
>----------------------------------------------------------------------------
>
>[...]
>The answer is still dramatically (factor of 2?) lower than I would
>like, but interesting.  I thought the code generator was the culprit,
>but apparently the front end is involved in the Alpha's poor
>performance as well.

Your code loads *a1...*a6 and *nx repeatedly even though they
(presumably) don't change.  All these loads waste time and serialize
things that could otherwise be scheduled to make use of pipelining.
Use the forc^H^H^H^Hregisters, Luke!

Try something like the code below and let us know what happens.

Bye,
  Rob.
     .-.                     Robert.Harley@inria.fr                    .-.
    /   \           .-.                                 .-.           /   \
   /     \         /   \       .-.     _     .-.       /   \         /     \
  /       \       /     \     /   \   / \   /   \     /     \       /       \
 /         \     /       \   /     `-'   `-'     \   /       \     /         \
            \   /         `-'                     `-'         \   /
             `-'  Linux + 500MHz Alpha + 256MB SDRAM = heaven  `-'


/* > jacobi.c
 * Purpose: Ocean model kernel for Luke Lonergan (llonerga@worldnet.att.net).
 * Copyright: (c) Robert J. Harley, 17-Sep-1997
 * Contact: Robert.Harley@inria.fr
 * Legalese: You can do what you want with this code as long as this
 *           comment stays attached in a prominent position in
 *           human-readable form, any distribution of this or
 *           derived products is made without profit and includes
 *           full source and is subject to the same conditions.
 */

#ifndef __alpha
#error Use an Alpha!
#endif


/*== #defines ==============================================================*/

#ifdef DBL_PRECISION
#define FLOAT double
#else
#define FLOAT float
#endif


/*== Function declarations =================================================*/

extern void jacobi
  ( FLOAT *psi_new, FLOAT *psi, FLOAT *f
  , FLOAT *pa1, FLOAT *pa2, FLOAT *pa3, FLOAT *pa4, FLOAT *pa5
  , long *pnx, long *pny, long *pnx_max, long *pny_max
  );


/*== Function definitions ==================================================*/

/*-- jacobi ----------------------------------------------------------------*/

/* Rob's version. */
void jacobi
  ( FLOAT *psi_new, FLOAT *psi, FLOAT *f
  , FLOAT *pa1, FLOAT *pa2, FLOAT *pa3, FLOAT *pa4, FLOAT *pa5
  , long *pnx, long *pny, long *pnx_max, long *pny_max
  ) {

  long i, j, nx, ny, tmp;
  FLOAT a1, a2, a3, a4, a5, *ff, *out, *pu, *pv, *pw;

  /** Arguments are all pointers (for Fortran), dereference some of them. **/
  nx = *pnx; ny = *pny;
  a1 = *pa1; a2 = *pa2; a3 = *pa3; a4 = *pa4; a5 = *pa5;

  /** Main loop. **/
  for (j = 1; j < ny-1; ++j) {

    /* Inner loop unrolled four times. */
    tmp = j*nx+1; pv = psi+tmp; ff = f+tmp; out = psi_new+tmp;
    i = nx-2;

    /* Do chunks of four. */
    while (i >= 4) {
      FLOAT u0,u1,u2,u3, vm,v0,v1,v2,v3,v4, w0,w1,w2,w3, f0,f1,f2,f3;

      pu = pv-nx; pw = pv+nx;

                   u0 = pu[0]; u1 = pu[1]; u2 = pu[2]; u3 = pu[3];
      vm = pv[-1]; v0 = pv[0]; v1 = pv[1]; v2 = pv[2]; v3 = pv[3]; v4 = pv[4];
                   w0 = pw[0]; w1 = pw[1]; w2 = pw[2]; w3 = pw[3];

                   f0 = ff[0]; f1 = ff[1]; f2 = ff[2]; f3 = ff[3];
      
      out[0] = a1*v1 + a2*vm + a3*w0 + a4*u0 - a5*f0;
      out[1] = a1*v2 + a2*v0 + a3*w1 + a4*u1 - a5*f1;
      out[2] = a1*v3 + a2*v1 + a3*w2 + a4*u2 - a5*f2;
      out[3] = a1*v4 + a2*v2 + a3*w3 + a4*u3 - a5*f3;

      i -= 4; pv += 4; ff += 4; out += 4;
    } /* end while */

    /* Do last 0, 1, 2 or 3. */
    while (i) {
      *out = a1*pv[1] + a2*pv[-1] + a3*pv[nx] + a4*pv[-nx] - a5*ff[0];
      --i; ++pv; ++ff; ++out;
    } /* end while */

  } /* end for (j) */

} /* end jacobi */


/*== end of file jacobi.c ==================================================*/





             reply	other threads:[~1997-09-17  4:00 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-17  4:00 Robert Harley [this message]
1997-09-22  4:00 ` MFlops Comparison using g77 (bad news) Luke Lonergan
  -- strict thread matches above, loose matches on Subject: below --
1997-09-16  4:00 Luke Lonergan
1997-09-16  4:00 ` Craig Burley
1997-09-16  4:00 ` Ulrich Ruede
1997-09-16  4:00 ` H.W. Stockman
1997-09-16  4:00   ` Greg Lindahl
1997-09-16  4:00 ` Toon Moene
1997-09-16  4:00   ` Luke Lonergan
1997-09-17  4:00     ` Linus Torvalds
1997-09-17  4:00       ` Rowan D. Hughes
1997-09-17  4:00         ` Xiaoguang Zhang
1997-09-17  4:00       ` Greg Lindahl
1997-09-17  4:00       ` Luke Lonergan
1997-09-19  4:00     ` James Lewis Nance
1997-09-22  4:00       ` Luke Lonergan
1997-09-16  4:00   ` Greg Lindahl
1997-09-18  4:00 ` Greg Lindahl
1997-09-19  4:00   ` Burkhard Neidecker-Lutz
1997-09-20  4:00     ` Toon Moene
1997-09-22  4:00   ` Luke Lonergan
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