On Thu, Jul 9, 2009 at 4:19 PM, Andreas Schäfer<gent...@gmx.de> wrote: > Hey guys, > > I noticed a strange performance hit in one of our stencil codes, > causing it to run twice as long. > > To nail down the error, I reduced our code to the two attached demo > programs. Basically they take two matrices and average each matrix > element with its four direct neighbors. Depending on how these > matrices are allocated, the performance hit occurs -- or does not. > > Here is the diff of the two files: > @@ -17,8 +17,7 @@ > > void test(double (*grid)[GRID_WIDTH]) > { > - double (*gridOld)[GRID_WIDTH] = > - malloc(GRID_WIDTH * GRID_HEIGHT * sizeof(double)); > + double (*gridOld)[GRID_WIDTH] = gridOldArray; > double (*gridNew)[GRID_WIDTH] = gridNewArray; > printAddress(&gridNew[0][0]); > printAddress(&gridOld[0][0]); > > where gridOldArray is a statically allocated array. Depending on the > machines processor the performance hit varies from negligible to > dramatic: > > > Processor GCC Version Time(slow) Time(fast) Performance Hit > ------------------ ----------- ---------- ---------- --------------- > Core 2 Quad Q9550 4.3.3 12.19s 5.11s 138% > Athlon 64 X2 3800+ 4.3.3 7.34s 6.61s 11% > Opteron 2378 4.3.2 6.13s 5.60s 9% > Opteron 2352 4.3.3 8.16s 7.96s 2% > Xeon 3.00GHz 4.3.3 18.98s 14.67s 29% > > Apparently Intel systems are more susceptible to this effect. > > Can anyone reproduce these results? > And could anyone explain, why this happens?
Depends on the GCC version used. First of all printAddress(&gridNew[0][0]); printAddress(&gridOld[0][0]); makes the addresses escape and GCC versions other than the current development trunk think that the malloced address can alias the global variables. Richard. > Thanks in advance > -Andreas > > > -- > ============================================ > Andreas Schäfer > Cluster and Metacomputing Working Group > Friedrich-Schiller-Universität Jena, Germany > 0049/3641-9-46376 > PGP/GPG key via keyserver > I'm a bright... http://www.the-brights.net > ============================================ > > (\___/) > (+'.'+) > (")_(") > This is Bunny. Copy and paste Bunny into your > signature to help him gain world domination! >