public static void benchmarkLU() { int N = Constants.LU_SIZE; SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED); int Iterations = 2000; double[][] A = RandomMatrix(N, N, R); double[][] lu = new double[N][]; for (int i = 0; i < N; i++) { lu[i] = new double[N]; } int[] pivot = new int[N]; foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { for (int i = 0; i < Iterations; i++) { CopyMatrix(lu, A); LU.factor(lu, pivot); } } } validateLU(N, R, lu, A, pivot); }
public void SetupSOR() { Random R = new SciMark2.Random(Constants.RANDOM_SEED); int N = Constants.SOR_SIZE; inputSOR = RandomMatrix(N, N, R); }
public void SetupFFT() { Random R = new SciMark2.Random(Constants.RANDOM_SEED); int N = Constants.FFT_SIZE; inputFFT = RandomVector(2 * N, R); }
public static void benchMonteCarlo() { SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED); int Iterations = 40000000; foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { MonteCarlo.integrate(Iterations); } } }
public void SetupLU() { Random R = new SciMark2.Random(Constants.RANDOM_SEED); int N = Constants.LU_SIZE; inputLUA = RandomMatrix(N, N, R); inputLU = new double[N][]; for (int i = 0; i < N; i++) { inputLU[i] = new double[N]; } inputLUPivot = new int[N]; }
public static void benchSOR() { int N = Constants.SOR_SIZE; SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED); int Iterations = 20000; double[][] G = RandomMatrix(N, N, R); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { SOR.execute(1.25, G, Iterations); } } }
public static void validateLU(int N, SciMark2.Random R, double[][] lu, double[][] A, int[] pivot) { // verify that LU is correct double[] b = RandomVector(N, R); double[] x = NewVectorCopy(b); LU.solve(lu, pivot, x); const double EPS = 1.0e-12; if (normabs(b, matvec(A, x)) / N > EPS) { throw new Exception("LU failed to validate"); } }
public static void benchFFT() { SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED); int N = Constants.FFT_SIZE; long Iterations = 20000; double[] x = RandomVector(2 * N, R); foreach (var iteration in Benchmark.Iterations) { using (iteration.StartMeasurement()) { innerFFT(x, Iterations); } } validateFFT(N, x); }
public static double integrate(int Num_samples) { SciMark2.Random R = new SciMark2.Random(SEED); int under_curve = 0; for (int count = 0; count < Num_samples; count++) { double x = R.nextDouble(); double y = R.nextDouble(); if (x * x + y * y <= 1.0) under_curve++; } return ((double)under_curve / Num_samples) * 4.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); } } }
public static double integrate(int Num_samples) { SciMark2.Random R = new SciMark2.Random(SEED); int under_curve = 0; for (int count = 0; count < Num_samples; count++) { double x = R.nextDouble(); double y = R.nextDouble(); if (x * x + y * y <= 1.0) { under_curve++; } } return(((double)under_curve / Num_samples) * 4.0); }
public void SetupSparseMult() { Random R = new SciMark2.Random(Constants.RANDOM_SEED); int N = Constants.SPARSE_SIZE_M; int nz = Constants.SPARSE_SIZE_nz; inputSparseMultX = RandomVector(N, R); inputSparseMultY = new double[N]; int nr = nz / N; // average number of nonzeros per row int anz = nr * N; // _actual_ number of nonzeros inputSparseMultVal = RandomVector(anz, R); inputSparseMultCol = new int[anz]; inputSparseMultRow = new int[N + 1]; inputSparseMultRow[0] = 0; for (int r = 0; r < N; r++) { // initialize elements for row r int rowr = inputSparseMultRow[r]; inputSparseMultRow[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++) { inputSparseMultCol[rowr + i] = i * step; } } }
/// <summary> /// Benchmark 5 kernels with individual Mflops. /// "results[0]" has the average Mflop rate. /// </summary> public static int Main(System.String[] args) { #if DEBUG double min_time = Constants.RESOLUTION_TINY; #else double min_time = Constants.RESOLUTION_DEFAULT; #endif int FFT_size = Constants.FFT_SIZE; int SOR_size = Constants.SOR_SIZE; int Sparse_size_M = Constants.SPARSE_SIZE_M; int Sparse_size_nz = Constants.SPARSE_SIZE_nz; int LU_size = Constants.LU_SIZE; // look for runtime options if (args.Length > 0) { if (args[0].ToUpper().Equals("-h") || args[0].ToUpper().Equals("-help")) { Console.WriteLine("Usage: [-large] [iterations]"); return -1; } int current_arg = 0; if (args[current_arg].ToUpper().Equals("-LARGE")) { FFT_size = Constants.LG_FFT_SIZE; SOR_size = Constants.LG_SOR_SIZE; Sparse_size_M = Constants.LG_SPARSE_SIZE_M; Sparse_size_nz = Constants.LG_SPARSE_SIZE_nz; LU_size = Constants.LG_LU_SIZE; current_arg++; } if (args.Length > current_arg) min_time = Double.Parse(args[current_arg]); } Console.WriteLine("** **"); Console.WriteLine("** SciMark2a Numeric Benchmark, see http://math.nist.gov/scimark **"); Console.WriteLine("** **"); // run the benchmark double[] res = new double[6]; SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED); Console.WriteLine("Mininum running time = {0} seconds", min_time); res[1] = kernel.measureFFT(FFT_size, min_time, R); res[2] = kernel.measureSOR(SOR_size, min_time, R); res[3] = kernel.measureMonteCarlo(min_time, R); res[4] = kernel.measureSparseMatmult(Sparse_size_M, Sparse_size_nz, min_time, R); res[5] = kernel.measureLU(LU_size, min_time, R); res[0] = (res[1] + res[2] + res[3] + res[4] + res[5]) / 5; // print out results Console.WriteLine(); Console.WriteLine("Composite Score: {0:F2} MFlops", res[0]); Console.WriteLine("FFT : {0} - ({1})", res[1] == 0.0 ? "ERROR, INVALID NUMERICAL RESULT!" : res[1].ToString("F2"), FFT_size); Console.WriteLine("SOR : {1:F2} - ({0}x{0})", SOR_size, res[2]); Console.WriteLine("Monte Carlo : {0:F2}", res[3]); Console.WriteLine("Sparse MatMult : {2:F2} - (N={0}, nz={1})", Sparse_size_M, Sparse_size_nz, res[4]); Console.WriteLine("LU : {1} - ({0}x{0})", LU_size, res[1] == 0.0 ? "ERROR, INVALID NUMERICAL RESULT!" : res[5].ToString("F2")); return 100; }
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); } } }
/// <summary> /// Benchmark 5 kernels with individual Mflops. /// "results[0]" has the average Mflop rate. /// </summary> public static int Main(System.String[] args) { #if DEBUG double min_time = Constants.RESOLUTION_TINY; #else double min_time = Constants.RESOLUTION_DEFAULT; #endif int FFT_size = Constants.FFT_SIZE; int SOR_size = Constants.SOR_SIZE; int Sparse_size_M = Constants.SPARSE_SIZE_M; int Sparse_size_nz = Constants.SPARSE_SIZE_nz; int LU_size = Constants.LU_SIZE; // look for runtime options if (args.Length > 0) { if (args[0].ToUpper().Equals("-h") || args[0].ToUpper().Equals("-help")) { Console.WriteLine("Usage: [-large] [iterations]"); return(-1); } int current_arg = 0; if (args[current_arg].ToUpper().Equals("-LARGE")) { FFT_size = Constants.LG_FFT_SIZE; SOR_size = Constants.LG_SOR_SIZE; Sparse_size_M = Constants.LG_SPARSE_SIZE_M; Sparse_size_nz = Constants.LG_SPARSE_SIZE_nz; LU_size = Constants.LG_LU_SIZE; current_arg++; } if (args.Length > current_arg) { min_time = Double.Parse(args[current_arg]); } } Console.WriteLine("** **"); Console.WriteLine("** SciMark2a Numeric Benchmark, see http://math.nist.gov/scimark **"); Console.WriteLine("** **"); // run the benchmark double[] res = new double[6]; SciMark2.Random R = new SciMark2.Random(Constants.RANDOM_SEED); Console.WriteLine("Mininum running time = {0} seconds", min_time); res[1] = kernel.measureFFT(FFT_size, min_time, R); res[2] = kernel.measureSOR(SOR_size, min_time, R); res[3] = kernel.measureMonteCarlo(min_time, R); res[4] = kernel.measureSparseMatmult(Sparse_size_M, Sparse_size_nz, min_time, R); res[5] = kernel.measureLU(LU_size, min_time, R); res[0] = (res[1] + res[2] + res[3] + res[4] + res[5]) / 5; // print out results Console.WriteLine(); Console.WriteLine("Composite Score: {0:F2} MFlops", res[0]); Console.WriteLine("FFT : {0} - ({1})", res[1] == 0.0 ? "ERROR, INVALID NUMERICAL RESULT!" : res[1].ToString("F2"), FFT_size); Console.WriteLine("SOR : {1:F2} - ({0}x{0})", SOR_size, res[2]); Console.WriteLine("Monte Carlo : {0:F2}", res[3]); Console.WriteLine("Sparse MatMult : {2:F2} - (N={0}, nz={1})", Sparse_size_M, Sparse_size_nz, res[4]); Console.WriteLine("LU : {1} - ({0}x{0})", LU_size, res[1] == 0.0 ? "ERROR, INVALID NUMERICAL RESULT!" : res[5].ToString("F2")); return(100); }