Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: henning@i4get.enet.dec.com (John L. Henning)
Subject: Re: Cache, performance, and data structures used by simulations
Date: 2 MAR 95 13:03:50	[thread overview]
Message-ID: <3j54js$79i@peavax.eng.pko.dec.com> (raw)
In-Reply-To: 3j0ljg$in7@agate.berkeley.edu


In article <3j0ljg$in7@agate.berkeley.edu>, peterm@tonks.EECS.Berkeley.EDU
(Peter Mardahl) writes that performance is consistent with expectations (when
comparing an AlphaStation 200 4/233 to an HP 712/80) if he uses a structure,
but not with an array.  The structure was:

>typedef struct {
>    double x,y;
>    double v1,v2,v3;
>} particle;
> 
>particle *particles;  /*  array has dimension #particles */

And the array was: 

>double *x, *y, *v1, *v2, *v3; /* each array has dimension #particles */
> 

Mr. Mardahl hypothesized cache effects and/or memory bandwidth as sources of
the difference, and asked for comments. 

First, a guess about the memory bandwidth. I suspect that it is not the
primary issue in this case, for two reasons: 1) I don't think HP has claimed
that memory bandwidth is a strong suit for the 712/80, but if I'm wrong please
correct me.  2) More main memory bandwidth can certainly help some benchmarks,
but it often seems like the bigger benefit comes from understanding cache
effects and dealing with them.  That is, the bigger bang-for-the-buck often
comes from making the best USE of whatever bandwidth you have.

Therefore, when you mention structures versus arrays I am reminded that I
recently heard this very recommendation from a compiler developer who
specializes in Alpha performance.  His point was that almost all cache-based
systems (not just Alpha) will tend to benefit from structures instead of
arrays because you are more likely to use a full cache line when it is brought
in.  

Recall that caches typically bring in more than just the item you have
requested; for example, if the cache linesize is 32 bytes and you are
processing 8 byte items, you get 4 items loaded every time a cache line is
refilled.  So if your program code is likely to use the surrounding items, you
make good use of your memory bandwidth; and if it is likely to ignore them
then you've wasted some bandwidth.  Structures can be very helpful.

The other point about multiple arrays is that they can cause cache thrashing.
RISC systems have many fewer cache locations than main memory locations, and
use various strategies to map main memory locations to cache locations (with
varying speeds and expenses).  Performance will suffer if you touch multiple
arrays simultaneously, and the locations of interest in different arrays (for
a given iteration) map to the same location in a cache. 

You may have stumbled across an array size that fits better in one system's
cache than in another system's cache, or that maps better in one than in
another.  To find out exactly what is happening would require specific,
detailed investigation.

But the point about structures tending to be more cache-friendly than arrays
is, I believe, generally applicable and a Good Performance Practice for
RISC-based systems.  

    /John Henning
     CSD Performance Group
     Digital Equipment Corporation
     henning@i4get.enet.dec.com
     Speaking for myself, not Digital


  parent reply	other threads:[~1995-03-02 18:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-03-01  2:19 Cache, performance, and data structures used by simulations Peter Mardahl
1995-03-01 23:30 ` Vivek Sadananda Pai
1995-03-02 23:05   ` Nick Maclaren
1995-03-04 19:01     ` John L. Henning
1995-03-06 20:08     ` Vivek Sadananda Pai
1995-03-13 18:10     ` Paul Repacholi
1995-03-02 18:03 ` John L. Henning [this message]
1995-03-03 16:52   ` Greg Lindahl
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