From: vivek@noel.cs.rice.edu (Vivek Sadananda Pai)
Subject: Re: Cache, performance, and data structures used by simulations
Date: 6 Mar 1995 20:08:14 GMT [thread overview]
Message-ID: <3jfq3e$k02@larry.rice.edu> (raw)
In-Reply-To: 3j5j0b$b8n@lyra.csx.cam.ac.uk
In article <3j5j0b$b8n@lyra.csx.cam.ac.uk>, nmm1@cus.cam.ac.uk (Nick Maclaren) writes:
|> In article <3j301q$lue@larry.rice.edu>,
|> Vivek Sadananda Pai <vivek@noel.cs.rice.edu> wrote:
[ in response to a question about a performance hit on an Alpha ]
|> >If your code uses the same element location from many arrays at
|> >the same time (or close to each other), you're probably better off
|> >switching to structures. The exact speedup you'll see depends on
|> >a number of factors including #cache conflicts, memory bandwidth,
|> >reuse, etc.
|>
|> Um, yes, but there is another solution: make each array slightly
|> bigger than it needs to be, so that each starts on a different
|> cache slot. This is done automatically (!) by some run-time systems,
|> where they keep chaining information on allocated blocks, and means
|> that it is the very devil to compare cache-dependent programs on
|> different systems.
My apologies - I should have been clearer in that last paragraph. I
was assuming that the page-alignment was not an issue that could be
controlled. Yes, you're correct that if you have control over where
the arrays can be placed, you can get around this issue. However, in
the areas that I'm working on, almost everything gets page-aligned,
so I was unnecessarily confining my response.
As another poster pointed out, many malloc() implementations will
page-align memory requests, especially those for large blocks (such
as arrays). If you face this situation, and you don't want to re-write
your code, you could essentially do a sleazy hack as follows:
instead of
array = (element *) malloc(bigsize)
do
arrayTemp = (element *) malloc(bigsize+OFFSET*sizeof(element))
array = &arrayTemp[OFFSET];
If you do this for all of your (conflicting) arrays, and vary OFFSET
for each one, you can work it such that element X of each array falls
into a different cache line. Of course, you need to do this for all
of your arrays that conflict, but this may be a more palatable choice
than doing a large re-write.
-Vivek
next prev parent reply other threads:[~1995-03-06 20:08 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 [this message]
1995-03-13 18:10 ` Paul Repacholi
1995-03-02 18:03 ` John L. Henning
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