Exemplo n.º 1
0
        /// <summary>
        /// Solution of the system
        /// <see cref="LaplaceMtx"/>*<see cref="T"/> + <see cref="LaplaceAffine"/> = <see cref="RHS"/>
        /// using a black-box solver
        /// </summary>
        private void ClassicSolve(out double mintime, out double maxtime, out bool Converged, out int NoOfIter)
        {
            mintime   = double.MaxValue;
            maxtime   = double.MinValue;
            Converged = false;
            NoOfIter  = int.MaxValue;

            for (int i = 0; i < base.Control.NoOfSolverRuns; i++)
            {
                // create sparse solver
                // --------------------
                ISparseSolver    ipSolver;
                LinearSolverCode solvercodes = LinearSolverCode.classic_pardiso;

                switch (solvercodes)
                {
                case LinearSolverCode.classic_pardiso:
                    ipSolver = new ilPSP.LinSolvers.PARDISO.PARDISOSolver()
                    {
                        CacheFactorization = true,
                        UseDoublePrecision = true
                    };
                    break;

                case LinearSolverCode.classic_mumps:
                    ipSolver = new ilPSP.LinSolvers.MUMPS.MUMPSSolver();
                    break;

                case LinearSolverCode.classic_cg:
                    ipSolver = new ilPSP.LinSolvers.monkey.CG()
                    {
                        MaxIterations = 1000000,
                        Tolerance     = 1.0e-10,
                        DevType       = ilPSP.LinSolvers.monkey.DeviceType.Cuda
                    };
                    break;

                default:
                    throw new ArgumentException();
                }
                ipSolver.DefineMatrix(LaplaceMtx);

                // call solver
                // -----------
                T.Clear();

                Console.WriteLine("RUN " + i + ": solving system...");

                var RHSvec = RHS.CoordinateVector.ToArray();
                BLAS.daxpy(RHSvec.Length, -1.0, this.LaplaceAffine, 1, RHSvec, 1);

                T.Clear();
                SolverResult solRes = ipSolver.Solve(T.CoordinateVector, RHSvec);
                mintime = Math.Min(solRes.RunTime.TotalSeconds, mintime);
                maxtime = Math.Max(solRes.RunTime.TotalSeconds, maxtime);

                Converged = solRes.Converged;
                NoOfIter  = solRes.NoOfIterations;

                Console.WriteLine("Pardiso phase 11: " + ilPSP.LinSolvers.PARDISO.PARDISOSolver.Phase_11.Elapsed.TotalSeconds);
                Console.WriteLine("Pardiso phase 22: " + ilPSP.LinSolvers.PARDISO.PARDISOSolver.Phase_22.Elapsed.TotalSeconds);
                Console.WriteLine("Pardiso phase 33: " + ilPSP.LinSolvers.PARDISO.PARDISOSolver.Phase_33.Elapsed.TotalSeconds);

                ipSolver.Dispose();
            }
        }