Example #1
0
        public static double measureLU(int N, double min_time, Random R)
        {
            double[][] A         = kernel.RandomMatrix(N, N, R);
            double[][] numArray1 = new double[N][];
            int        index     = 0;

            while (index < N)
            {
                numArray1[index] = new double[N];
                checked { ++index; }
            }
            int[]     numArray2 = new int[N];
            Stopwatch stopwatch = new Stopwatch();
            int       num1      = 4095;

            stopwatch.start();
            int num2 = 0;

            while (num2 < num1)
            {
                kernel.CopyMatrix(numArray1, A);
                LU.factor(numArray1, numArray2);
                checked { ++num2; }
            }
            stopwatch.stop();
            double[] x         = kernel.RandomVector(N, R);
            double[] numArray3 = kernel.NewVectorCopy(x);
            LU.solve(numArray1, numArray2, numArray3);
            if (kernel.normabs(x, kernel.matvec(A, numArray3)) / (double)N > 0.0 / 1.0)
            {
                return(0.0);
            }
            return(LU.num_flops(N) * (double)num1 / stopwatch.read() * 1E-06);
        }
Example #2
0
        public static double measureLU(int N, double min_time, Random R)
        {
            // compute approx Mlfops, or O if LU yields large errors

            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];

            Stopwatch Q = new Stopwatch();

            int cycles = 1;

            while (true)
            {
                Q.start();
                for (int i = 0; i < cycles; i++)
                {
                    CopyMatrix(lu, A);
                    LU.factor(lu, pivot);
                }
                Q.stop();
                if (Q.read() >= min_time)
                {
                    break;
                }

                cycles *= 2;
            }

            validateLU(N, R, lu, A, pivot);

            return(LU.num_flops(N) * cycles / Q.read() * 1.0e-6);
        }
Example #3
0
        public static double measureLU(int N, double min_time, Random R)
        {
            // compute approx Mlfops, or O if LU yields large errors

            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];

            Stopwatch clock = new Stopwatch();
            Stopwatch watch = new Stopwatch();

            int  cycles     = 1;
            long copyTime   = 0;
            long factorTime = 0;

            while (true)
            {
                clock.Start();
                for (int i = 0; i < cycles; i++)
                {
                    watch.Start();
                    CopyMatrix(lu, A);
                    watch.Stop();
                    copyTime += watch.ElapsedMilliseconds;
                    watch.Reset();
                    watch.Start();
                    LU.factor(lu, pivot);
                    watch.Stop();
                    factorTime += watch.ElapsedMilliseconds;
                    watch.Reset();
                }
                clock.Stop();
                if (clock.Elapsed.TotalSeconds >= min_time)
                {
                    break;
                }

                cycles *= 2;
            }

            Console.WriteLine("Time spent in measureLU:\nCopyMatrix: {0} ms\nLU.factor: {1} ms\ncycles: {2}", copyTime, factorTime, cycles);


            // 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)
            {
                return(0.0);
            }


            // else return approx Mflops
            //
            return(LU.num_flops(N) * cycles / clock.Elapsed.TotalMilliseconds * 1.0e-3);
        }