Beispiel #1
0
        public void Setup()
        {
            var rand = new Random(42);

            arrayOfStructs   = new VectorThatDontFitCacheLine[ArraySize];
            arrayOfStructsCL = new VectorThatFitCacheLine[ArraySize];
            vectors.arrayOfX = new float[ArraySize];
            vectors.arrayOfY = new float[ArraySize];
            vectors.arrayOfZ = new float[ArraySize];

            for (int i = 0; i < ArraySize; ++i)
            {
                vectors.arrayOfX[i] = (float)rand.NextDouble();
                vectors.arrayOfY[i] = (float)rand.NextDouble();
                vectors.arrayOfZ[i] = (float)rand.NextDouble();

                arrayOfStructs[i] = new VectorThatDontFitCacheLine
                {
                    X = vectors.arrayOfX[i],
                    Y = vectors.arrayOfY[i],
                    Z = vectors.arrayOfZ[i]
                };
                arrayOfStructsCL[i] = new VectorThatFitCacheLine
                {
                    X = vectors.arrayOfX[i],
                    Y = vectors.arrayOfY[i],
                    Z = vectors.arrayOfZ[i]
                };
            }
        }
Beispiel #2
0
        public void VectorNormAoS()
        {
            for (int i = 0; i < arrayOfStructs.Length; ++i)
            {
                VectorThatDontFitCacheLine pt = arrayOfStructs[i];

                float norm = (float)Math.Sqrt(pt.X * pt.X + pt.Y * pt.Y + pt.Z * pt.Z);

                pt.X /= norm;
                pt.Y /= norm;
                pt.Z /= norm;

                arrayOfStructs[i] = pt;
            }
        }