コード例 #1
0
        protected override IDisposableSolver <double> CreateSolver(CompressedColumnStorage <double> matrix, bool symmetric)
        {
            int mtype = symmetric ? PardisoMatrixType.RealStructurallySymmetric : PardisoMatrixType.RealNonsymmetric;

            var solver = new Pardiso((SparseMatrix)matrix, mtype);

            var options = solver.Options;

            // Fill-in reordering from METIS.
            options.ColumnOrderingMethod = PardisoOrdering.NestedDissection;

            // Max numbers of iterative refinement steps.
            options.IterativeRefinement = 2;

            // Perturb the pivot elements with 1E-13.
            options.PivotingPerturbation = 13;

            // Use nonsymmetric permutation and scaling MPS.
            options.Scaling = true;

            // Maximum weighted matching algorithm is switched-on (default for non-symmetric).
            options.WeightedMatching = true;

            if (symmetric)
            {
                // Maximum weighted matching algorithm is switched-off (default for symmetric).
                // Try to enable in case of inappropriate accuracy.
                options.WeightedMatching = false;
            }

            options.ZeroBasedIndexing = true;
            options.CheckMatrix       = true;

            return(solver);
        }
コード例 #2
0
ファイル: pardiso.cs プロジェクト: mluksevics/BFE.Net
        public static int Main(string[] args)
        {
            /* Matrix data. */
            int n = 8;

            int[] ia /*[9]*/  = new int[] { 1, 5, 8, 10, 12, 15, 17, 18, 19 };
            int[] ja /*[18]*/ = new int[]
            {
                1, 3, 6, 7,
                2, 3, 5,
                3, 8,
                4, 7,
                5, 6, 7,
                6, 8,
                7,
                8
            };
            double[] a /*[18]*/ = new double[]
            {
                7.0, 1.0, 2.0, 7.0,
                -4.0, 8.0, 2.0,
                1.0, 5.0,
                7.0, 9.0,
                5.0, 1.0, 5.0,
                -1.0, 5.0,
                11.0,
                5.0
            };
            int mtype = -2; /* Real symmetric matrix */

            /* RHS and solution vectors. */
            double[] b    = new double[8];
            double[] x    = new double[8];
            int      nrhs = 1; /* Number of right hand sides. */

            /* Internal solver memory pointer pt, */
            /* 32-bit: int pt[64]; 64-bit: long int pt[64] */
            /* or void *pt[64] should be OK on both architectures */
            /* void *pt[64]; */
            IntPtr[] pt = new IntPtr[64];
            /* Pardiso control parameters. */
            int[] iparm = new int[64];
            int   maxfct, mnum, phase, error, msglvl;
            /* Auxiliary variables. */
            int i;

            double[] ddum = new double[1]; /* Double dummy */
            int[]    idum = new int[1];    /* Integer dummy. */
            /* ----------------------------------------------------------------- */
            /* .. Setup Pardiso control parameters. */
            /* ----------------------------------------------------------------- */
            for (i = 0; i < 64; i++)
            {
                iparm[i] = 0;
            }
            iparm[0] = 1; /* No solver default */
            iparm[1] = 2; /* Fill-in reordering from METIS */
            /* Numbers of processors, value of OMP_NUM_THREADS */
            iparm[2]  = 1;
            iparm[3]  = 0;  /* No iterative-direct algorithm */
            iparm[4]  = 0;  /* No user fill-in reducing permutation */
            iparm[5]  = 0;  /* Write solution into x */
            iparm[6]  = 0;  /* Not in use */
            iparm[7]  = 2;  /* Max numbers of iterative refinement steps */
            iparm[8]  = 0;  /* Not in use */
            iparm[9]  = 13; /* Perturb the pivot elements with 1E-13 */
            iparm[10] = 1;  /* Use nonsymmetric permutation and scaling MPS */
            iparm[11] = 0;  /* Not in use */
            iparm[12] = 0;  /* Maximum weighted matching algorithm is switched-off
                             * (default for symmetric). Try iparm[12] = 1 in case of
                             *  inappropriate accuracy */
            iparm[13] = 0;  /* Output: Number of perturbed pivots */
            iparm[14] = 0;  /* Not in use */
            iparm[15] = 0;  /* Not in use */
            iparm[16] = 0;  /* Not in use */
            iparm[17] = -1; /* Output: Number of nonzeros in the factor LU */
            iparm[18] = -1; /* Output: Mflops for LU factorization */
            iparm[19] = 0;  /* Output: Numbers of CG Iterations */
            maxfct    = 1;  /* Maximum number of numerical factorizations. */
            mnum      = 1;  /* Which factorization to use. */
            msglvl    = 1;  /* Print statistical information in file */
            error     = 0;  /* Initialize error flag */
            /* ----------------------------------------------------------------- */
            /* .. Initialize the internal solver memory pointer. This is only */
            /* necessary for the FIRST call of the PARDISO solver. */
            /* ----------------------------------------------------------------- */
            for (i = 0; i < 64; i++)
            {
                pt[i] = IntPtr.Zero;
            }
            /* ----------------------------------------------------------------- */
            /* .. Reordering and Symbolic Factorization. This step also allocates */
            /* all memory that is necessary for the factorization. */
            /* ----------------------------------------------------------------- */
            phase = 11;
            Pardiso.pardiso(pt, ref maxfct, ref mnum, ref mtype, ref phase,
                            ref n, a, ia, ja, idum, ref nrhs,
                            iparm, ref msglvl, ddum, ddum, ref error);
            if (error != 0)
            {
                Console.WriteLine("\nERROR during symbolic factorization: " + error);
                return(1);
            }
            Console.Write("\nReordering completed ... ");
            Console.Write("\nNumber of nonzeros in factors = " + iparm[17]);
            Console.WriteLine("\nNumber of factorization MFLOPS = " + iparm[18]);
            /* ----------------------------------------------------------------- */
            /* .. Numerical factorization. */
            /* ----------------------------------------------------------------- */
            phase = 22;
            Pardiso.pardiso(pt, ref maxfct, ref mnum, ref mtype, ref phase,
                            ref n, a, ia, ja, idum, ref nrhs,
                            iparm, ref msglvl, ddum, ddum, ref error);
            if (error != 0)
            {
                Console.WriteLine("\nERROR during numerical factorization: " + error);
                return(2);
            }
            Console.WriteLine("\nFactorization completed ... ");
            /* ----------------------------------------------------------------- */
            /* .. Back substitution and iterative refinement. */
            /* ----------------------------------------------------------------- */
            phase    = 33;
            iparm[7] = 2; /* Max numbers of iterative refinement steps. */
            /* Set right hand side to one. */
            for (i = 0; i < n; i++)
            {
                b[i] = 1;
            }
            Pardiso.pardiso(pt, ref maxfct, ref mnum, ref mtype, ref phase,
                            ref n, a, ia, ja, idum, ref nrhs,
                            iparm, ref msglvl, b, x, ref error);
            if (error != 0)
            {
                Console.WriteLine("\nERROR during solution: " + error);
                return(3);
            }
            Console.WriteLine("\nSolve completed ... ");
            Console.WriteLine("\nThe solution of the system is: ");
            for (i = 0; i < n; i++)
            {
                Console.Write("\n x [" + i + "] = " + x[i]);
            }
            Console.WriteLine();
            /* ----------------------------------------------------------------- */
            /* .. Termination and release of memory. */
            /* ----------------------------------------------------------------- */
            phase = -1; /* Release internal memory. */
            Pardiso.pardiso(pt, ref maxfct, ref mnum, ref mtype, ref phase,
                            ref n, ddum, ia, ja, idum, ref nrhs,
                            iparm, ref msglvl, ddum, ddum, ref error);
            Console.WriteLine("TEST PASSED");
            Console.WriteLine();
            return(0);
        }