示例#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);
        }
示例#2
0
文件: kernel.cs 项目: wyrover/coreclr
        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");
            }
        }
示例#3
0
 public virtual double[] solve(double[] b)
 {
     double[] b1 = LU.new_copy(b);
     LU.solve(this.m_LU, this.m_pivot, b1);
     return(b1);
 }
示例#4
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);
        }