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-05 05:43:34 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!news.moneng.mei.com!uwm.edu!lll-winken.llnl.gov!decwrl!pa.dec.com!nntpd.lkg.dec.com!peavax.eng.pko.dec.com!i4get.enet.dec.com!henning From: henning@i4get.enet.dec.com (John L. Henning) Newsgroups: comp.benchmarks,comp.sys.dec Subject: Re: Cache, performance, and data structures used by simulations Date: 2 MAR 95 13:03:50 Organization: Digital Equipment Corporation Message-ID: <3j54js$79i@peavax.eng.pko.dec.com> References: <3j0ljg$in7@agate.berkeley.edu> NNTP-Posting-Host: i4get.enet.dec.com Xref: bga.com comp.benchmarks:2856 comp.sys.dec:9641 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