Ejemplo n.º 1
0
        public static void benchSparseMult()
        {
            int N          = Constants.SPARSE_SIZE_M;
            int nz         = Constants.SPARSE_SIZE_nz;
            int Iterations = 100000;

            SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED);

            double[] x   = RandomVector(N, R);
            double[] y   = new double[N];
            int      nr  = nz / N; // average number of nonzeros per row
            int      anz = nr * N; // _actual_ number of nonzeros

            double[] val = RandomVector(anz, R);
            int[]    col = new int[anz];
            int[]    row = new int[N + 1];

            row[0] = 0;
            for (int r = 0; r < N; r++)
            {
                // initialize elements for row r

                int rowr = row[r];
                row[r + 1] = rowr + nr;
                int step = r / nr;
                if (step < 1)
                {
                    step = 1;
                }
                // take at least unit steps

                for (int i = 0; i < nr; i++)
                {
                    col[rowr + i] = i * step;
                }
            }

            foreach (var iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    SparseCompRow.matmult(y, val, row, col, x, Iterations);
                }
            }
        }
Ejemplo n.º 2
0
        public static double measureSparseMatmult(int N, int nz, double min_time, Random R)
        {
            double[] x    = kernel.RandomVector(N, R);
            double[] y    = new double[N];
            int      num1 = nz / N;
            int      N1   = checked (num1 * N);

            double[] val = kernel.RandomVector(N1, R);
            int[]    col = new int[N1];
            int[]    row = new int[checked (N + 1)];
            row[0] = 0;
            int index = 0;

            while (index < N)
            {
                int num2 = row[index];
                row[checked (index + 1)] = checked (num2 + num1);
                int num3 = index / num1;
                if (num3 < 1)
                {
                    num3 = 1;
                }
                int num4 = 0;
                while (num4 < num1)
                {
                    col[checked (num2 + num4)] = checked (num4 * num3);
                    checked { ++num4; }
                }
                checked { ++index; }
            }
            Stopwatch stopwatch = new Stopwatch();
            int       num5      = 150000;

            stopwatch.start();
            SparseCompRow.matmult(y, val, row, col, x, num5);
            stopwatch.stop();
            return(SparseCompRow.num_flops(N, nz, num5) / stopwatch.read() * 1E-06);
        }
Ejemplo n.º 3
0
        public static double measureSparseMatmult(int N, int nz, double min_time, Random R)
        {
            // initialize vector multipliers and storage for result
            // y = A*y;

            double[] x = RandomVector(N, R);
            double[] y = new double[N];

            // initialize square sparse matrix
            //
            // for this test, we create a sparse matrix wit M/nz nonzeros
            // per row, with spaced-out evenly between the begining of the
            // row to the main diagonal.  Thus, the resulting pattern looks
            // like
            //             +-----------------+
            //             +*                +
            //             +***              +
            //             +* * *            +
            //             +** *  *          +
            //             +**  *   *        +
            //             +* *   *   *      +
            //             +*  *   *    *    +
            //             +*   *    *    *  +
            //             +-----------------+
            //
            // (as best reproducible with integer artihmetic)
            // Note that the first nr rows will have elements past
            // the diagonal.

            int nr  = nz / N; // average number of nonzeros per row
            int anz = nr * N; // _actual_ number of nonzeros


            double[] val = RandomVector(anz, R);
            int[]    col = new int[anz];
            int[]    row = new int[N + 1];

            row[0] = 0;
            for (int r = 0; r < N; r++)
            {
                // initialize elements for row r

                int rowr = row[r];
                row[r + 1] = rowr + nr;
                int step = r / nr;
                if (step < 1)
                {
                    step = 1;
                }
                // take at least unit steps

                for (int i = 0; i < nr; i++)
                {
                    col[rowr + i] = i * step;
                }
            }

            Stopwatch Q = new Stopwatch();

            int cycles = 1;

            while (true)
            {
                Q.start();
                SparseCompRow.matmult(y, val, row, col, x, cycles);
                Q.stop();
                if (Q.read() >= min_time)
                {
                    break;
                }

                cycles *= 2;
            }

            // approx Mflops
            return(SparseCompRow.num_flops(N, nz, cycles) / Q.read() * 1.0e-6);
        }
Ejemplo n.º 4
0
        public void benchSparseMult()
        {
            int Iterations = 100000;

            SparseCompRow.matmult(inputSparseMultY, inputSparseMultVal, inputSparseMultRow, inputSparseMultCol, inputSparseMultX, Iterations);
        }