From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f57db,df5754e791c11702 X-Google-Attributes: gidf57db,public X-Google-Thread: 1164f8,df5754e791c11702 X-Google-Attributes: gid1164f8,public X-Google-ArrivalTime: 1995-03-07 10:25:37 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swrinde!news.uh.edu!bti!news.sesqui.net!rice!vivek From: vivek@noel.cs.rice.edu (Vivek Sadananda Pai) Newsgroups: comp.benchmarks,comp.sys.dec Subject: Re: Cache, performance, and data structures used by simulations Date: 6 Mar 1995 20:08:14 GMT Organization: Rice University, Houston, Texas Distribution: world Message-ID: <3jfq3e$k02@larry.rice.edu> References: <3j0ljg$in7@agate.berkeley.edu> <3j301q$lue@larry.rice.edu> <3j5j0b$b8n@lyra.csx.cam.ac.uk> NNTP-Posting-Host: noel.cs.rice.edu Originator: vivek@noel.cs.rice.edu Xref: bga.com comp.benchmarks:2870 comp.sys.dec:9708 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 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