public class MumpsSolver extends DirectSolverBase
Matrix M; // matrix to be solved
VectorNd x, b; // solution vector and right-hand side
MumpsSolver solver = new MumpsSolver();
solver.analyze (M, M.rowSize(), Matrix.SYMMETRIC); // symbolic factorization
solver.factor(); // numeric factorization
solver.solve (x, b); // solution using factorization
solver.dispose(); // release resources when we are done
It is very important to call dispose() when the solver
is no longer required, in order to release internal native resources that
have been allocated for the MUMPS native code.
It is not necessary to call the analyze() and
factor() methods every time a solution is
required. analyze() needs to be called only when a matrix is
first presented to the solver or when its sparsity structure changes.
factor() needs to be called only when the numeric values of the
matrix change. For a given set of numeric values, once factor()
has been called, solve() can be called as many times as desired
to generate solutions for different right-hand sides.
It is also possible to avoid using a Matrix object, and
instead call analyze() and factor() with
compressed row storage (CRS) data structures directly, as in
solver.analyze (vals, colIdxs, rowOffs, size, matrixType);
solver.factor (vals);
Here vals, colIdxs, and rowOffs
descrive the sparse matrix structure using the CRS format as described
in the documentation for
Matrix.setCRSValues.
MUMPS itself uses an assembled coordinate format, in which the row and
column index of every non-zero element is given explicitly. The conversion
from CRS is done inside the native layer, once per analyze()
call, by expanding the row offsets into row indices. For symmetric
matrices, only the upper triangular portion is supplied, which MUMPS
accepts directly.
| Modifier and Type | Class and Description |
|---|---|
static class |
MumpsSolver.ReorderMethod
Describes the reorder methods that can be used during the analyze phase
to reduce factorization fill-in.
|
DirectSolver.IterativeMethod| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEFAULT_SHOW_PERTURBED_PIVOTS |
static boolean |
printThreadInfo |
static boolean |
supportsMultipleRhs |
static int |
WARN_COMPACT_MEMORY
Warning bit indicating insufficient memory to compact the internal
work array at the end of the factorization.
|
static int |
WARN_INDEX_OUT_OF_RANGE
Warning bit (returned in INFOG(1)) indicating that entries with
out-of-range indices were found and ignored.
|
static int |
WARN_RANK_REVEALING
Warning bit returned by the rank revealing feature.
|
static int |
WARN_REFINEMENT
Warning bit indicating that iterative refinement did not converge
within the allowed number of steps.
|
static int |
WARN_ZERO_SOLUTION
Warning bit indicating that the max-norm of the solution is close
to zero.
|
DEFAULT_GMRES_RESTARTANALYZED, DEFAULT_ITERATIVE_MAX_SOLVES, DEFAULT_ITERATIVE_TOLERANCE, FACTORED, UNSET| Constructor and Description |
|---|
MumpsSolver()
Creates a new MumpsSolver object.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getAnalysisMemoryUsage()
Returns the total amount of memory (in kbytes), summed over all
processes, that MUMPS estimated during the most recent
analyze() call would be needed for an in-core
factorization (MUMPS parameter INFOG(17)). |
boolean |
getApplyWeightedMatchings()
Returns whether or not weighted matchings are enabled.
|
int |
getFactorSolveMemoryUsage()
Returns the memory (in kbytes) actually used during the most recent
factor() call (MUMPS parameter INFOG(21)). |
static java.lang.String |
getInitErrorMessage()
Returns a message describing an error that occurred during
initialization, or
null if no error occurred. |
double[] |
getLastIterativeTimes()
Returns a time breakdown of the most recent call to
iterativeSolve(double[], double[], double[]), in msec: the total time spent in the native code, the
time spent in preconditioner solves, and the time spent in matrix-vector
products. |
int |
getMaxRefinementSteps()
Returns the maximum number of iterative refinement steps that MUMPS
should perform after a solve.
|
int |
getMaxWorkingMemory()
Returns the maximum size of the working memory, in Mbytes, that MUMPS is
allowed to allocate.
|
boolean |
getNullPivotDetection()
Queries whether null pivot detection is enabled.
|
double |
getNullPivotThreshold()
Returns the threshold used to identify null pivots.
|
int |
getNumDelayedPivots()
Returns the number of delayed pivots that occurred during the most
recent numeric factorization (MUMPS parameter INFOG(13)).
|
int |
getNumNegEigenvalues()
Returns the number of negative eigenvalues that were detected during the
most recent numeric factorization of a symmetric indefinite matrix (i.e.,
during the last
factor() call, MUMPS parameter INFOG(12)). |
long |
getNumNonZerosInFactors()
Returns the number of non-zeros elements in the factorization.
|
int |
getNumNullPivots()
Returns the number of null pivot rows that were detected during the most
recent numeric factorization (MUMPS parameter INFOG(28)), which
corresponds to the deficiency of the matrix.
|
int |
getNumPerturbedPivots()
Returns the number of pivots that were perturbed during the most recent
numeric factorization (i.e., during the last
factor()
call). |
int |
getNumPosEigenvalues()
Returns the number of positive eigenvalues that were detected during the
most recent numeric factorization of a symmetric indefinite matrix (i.e.,
during the last
factor() call). |
int |
getNumRefinementSteps()
Returns the number of iterative refinement steps that MUMPS
actually performed during the most recent call to
solve()
(MUMPS parameter INFOG(15)). |
int |
getNumTinyPivots()
Returns the number of tiny pivots that were modified by static pivoting
during the most recent numeric factorization (MUMPS parameter
INFOG(25)).
|
int |
getPeakAnalysisMemoryUsage()
Returns the maximum amount of memory (in kbytes) that MUMPS estimated,
during the most recent
analyze() call, would be needed by a
single process for an in-core factorization (MUMPS parameter INFOG(16)). |
MumpsSolver.ReorderMethod |
getReorderMethod()
Gets the reorder method that is used during the analyze phase to
reduced factorization fill-in (MUMPS parameter ICNTL(7)).
|
MumpsSolver.ReorderMethod |
getReorderMethodUsed()
Returns the reorder method that MUMPS actually used during the most
recent analyze phase (MUMPS parameter INFOG(7)).
|
int |
getScaling()
Returns the scaling which MUMPS applies to the matrix, as described for
setScaling(int). |
static boolean |
getShowPerturbedPivots()
Queries whether the "num perturbed pivots" message is enabled.
|
int |
getSPDZeroPivot()
If the solver detected null pivots during the most recent
factorization, this method returns the row number of the first such
pivot, as identified by the MUMPS PIVNUL_LIST array.
|
double |
getStaticPivotTolerance()
Returns the threshold used for static pivoting.
|
int |
getSymOrderingStrategy()
Returns the ordering strategy used for symmetric indefinite matrices.
|
int |
getWorkspaceIncrease()
Returns the percentage by which MUMPS increases the working space
estimated during the analyze phase.
|
boolean |
hasIterativeSolves()
Returns true if this solver supports iterative solving, using a recent
directly-factored matrix as a preconditioner.
|
boolean |
hasMultipleRhsSolves()
Returns true if this solver can solve for multiple right hand sides,
using
solve(X,B,nrhs). |
static boolean |
isAvailable()
Returns true if the MUMPS solver is available.
|
int |
iterativeSolve(double[] vals,
double[] x,
double[] b)
Solves the system
|
void |
setApplyWeightedMatchings(int enable)
Sets whether or not MUMPS should compute a weighted matching (maximum
transversal) for the matrix (MUMPS parameter ICNTL(6)).
|
void |
setMaxRefinementSteps(int nsteps)
Sets the maximum number of iterative refinement steps that MUMPS should
perform after a solve (MUMPS parameter ICNTL(10)).
|
void |
setMaxWorkingMemory(int mbytes)
Sets the maximum size of the working memory, in Mbytes, that MUMPS is
allowed to allocate (MUMPS parameter ICNTL(23)).
|
void |
setNullPivotDetection(boolean enable)
Enables or disables the detection of null pivot rows (MUMPS parameter
ICNTL(24)).
|
void |
setNullPivotThreshold(double thresh)
Sets the threshold used to identify null pivots (MUMPS parameter
CNTL(3)), when null pivot detection is enabled.
|
void |
setReorderMethod(MumpsSolver.ReorderMethod method)
Sets the reorder method that should be used during the analyze phase to
reduced factorization fill-in.
|
void |
setScaling(int value)
Sets the scaling which MUMPS applies to the matrix, as the value of the
MUMPS parameter ICNTL(8).
|
static void |
setShowPerturbedPivots(boolean enable)
Enables/disables the "num perturbed pivots" message (which usually
indicates a singular or ill-conditioned solve).
|
void |
setStaticPivotTolerance(double tol)
Sets the threshold used for static pivoting (MUMPS parameter CNTL(4)).
|
void |
setSymOrderingStrategy(int strategy)
Sets the ordering strategy that MUMPS uses for symmetric indefinite
matrices (MUMPS parameter ICNTL(12)).
|
void |
setWorkspaceIncrease(int percent)
Sets the percentage by which MUMPS should increase the working space
estimated during the analyze phase (MUMPS parameter ICNTL(14)).
|
analyze, analyze, analyzeAndFactor, dispose, factor, factor, finalize, getDefaultNumThreads, getErrorMessage, getGmresRestart, getIterativeMaxSolves, getIterativeMethod, getIterativeTolerance, getLastIterativeResidual, getLastIterativeSolves, getNumThreads, getPhysicalCoreCount, getState, getUseCriticalArrayAccess, residual, setDefaultNumThreads, setGmresRestart, setIterativeMaxSolves, setIterativeMethod, setIterativeTolerance, setNumThreads, setUseCriticalArrayAccess, solve, solve, solveequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waititerativeSolve, residualpublic static boolean printThreadInfo
public static boolean supportsMultipleRhs
public static final int WARN_INDEX_OUT_OF_RANGE
public static final int WARN_ZERO_SOLUTION
public static final int WARN_COMPACT_MEMORY
public static final int WARN_REFINEMENT
public static final int WARN_RANK_REVEALING
public static boolean DEFAULT_SHOW_PERTURBED_PIVOTS
public static boolean isAvailable()
public static java.lang.String getInitErrorMessage()
null if no error occurred.public static void setShowPerturbedPivots(boolean enable)
getNumPerturbedPivots().enable - if true, enables the messagepublic static boolean getShowPerturbedPivots()
true if the message is enabledpublic void setMaxRefinementSteps(int nsteps)
-nsteps) with no convergence test. More iterative refinement
steps will increase solution accuracy but slow down the solve.
Note: MUMPS silently disables iterative refinement whenever more than one right hand side is solved for.
nsteps - maximum number of iterative refinement stepsgetMaxRefinementSteps(),
getNumRefinementSteps()public int getMaxRefinementSteps()
setMaxRefinementSteps(int),
getNumRefinementSteps()public int getNumRefinementSteps()
solve()
(MUMPS parameter INFOG(15)).getMaxRefinementSteps(),
setMaxRefinementSteps(int)public MumpsSolver.ReorderMethod getReorderMethod()
setReorderMethod(maspack.solvers.MumpsSolver.ReorderMethod)public MumpsSolver.ReorderMethod getReorderMethodUsed()
getReorderMethod(), either because
DEFAULT was requested, or because the requested method was
not available or not compatible with other settings.public void setReorderMethod(MumpsSolver.ReorderMethod method)
DEFAULT
will cause MUMPS to choose the method automatically. For the symmetric
indefinite systems typically encountered in ArtiSynth,
METIS is usually the best choice.method - reorder methodgetReorderMethod()public void setStaticPivotTolerance(double tol)
getNumTinyPivots(). Values are interpreted as follows:
tol < 0tol == 0sqrt(eps)*norm(M);
tol > 0tol as an
absolute threshold.
Note: unlike the pivot perturbation used by Pardiso, this is
an absolute quantity rather than a factor applied to a norm of the
matrix. Also, MUMPS ignores static pivoting when null pivot detection is
enabled (see setNullPivotDetection(boolean)), which is the default for
this solver.
tol - static pivoting thresholdgetStaticPivotTolerance()public double getStaticPivotTolerance()
setStaticPivotTolerance(double)public void setNullPivotDetection(boolean enable)
setNullPivotThreshold(double) are treated as
null and the factorization continues, with the number of such pivots
returned by getNumNullPivots(). When disabled, a null pivot
instead causes the factorization to fail with a
NumericalException.
This is enabled by default, since it most closely matches the behavior of Pardiso, which perturbs zero pivots and continues.
enable - if true, enables null pivot detectiongetNullPivotDetection()public boolean getNullPivotDetection()
true if null pivot detection is enabledsetNullPivotDetection(boolean)public void setNullPivotThreshold(double thresh)
thresh > 0thresh*norm(M);
thresh == 0thresh < 0-thresh.
thresh - null pivot thresholdgetNullPivotThreshold()public double getNullPivotThreshold()
setNullPivotThreshold(double)public void setScaling(int value)
The default is -1, which lets the solver choose between
analysis and factorization scaling for each matrix, since neither suits
all of them and the choice also affects the ordering MUMPS selects.
Setting any other value pins ICNTL(8) and disables that choice. The
policy is described where it is implemented, in Mumps::adaptStrategy().
value - value for ICNTL(8)getScaling()public int getScaling()
setScaling(int). If MUMPS was left to choose, the value it actually
used is returned once a solve phase has been run.setScaling(int)public void setApplyWeightedMatchings(int enable)
enable as follows: enable > 0 enables them, enable = 0 disables them, and enable < 0 causes MUMPS to choose
automatically (the default). Weighted matchings are always disabled for
SPD matrices.enable - enables/disables weighted matchingsgetApplyWeightedMatchings()public boolean getApplyWeightedMatchings()
setApplyWeightedMatchings(int)public void setSymOrderingStrategy(int strategy)
AMF reorder method). Setting this to 2 can significantly
reduce the number of delayed pivots (see getNumDelayedPivots())
for augmented systems, at the cost of increased fill-in.strategy - symmetric ordering strategygetSymOrderingStrategy()public int getSymOrderingStrategy()
setSymOrderingStrategy(int)public void setWorkspaceIncrease(int percent)
< 0 causes MUMPS to use its default value
(between 20 and 35 percent). Numerical pivoting can cause significantly
more fill-in than was predicted by the analysis, in which case the
factorization will fail because the working space is too small; this
solver responds by automatically increasing the workspace and retrying,
but setting a larger value here in advance will avoid the wasted
factorizations.percent - percentage increase in the estimated working spacegetWorkspaceIncrease()public int getWorkspaceIncrease()
setWorkspaceIncrease(int)public void setMaxWorkingMemory(int mbytes)
<= 0 (the default) places no limit other than that implied by
setWorkspaceIncrease(int).mbytes - maximum working memory, in MbytesgetMaxWorkingMemory()public int getMaxWorkingMemory()
setMaxWorkingMemory(int)public long getNumNonZerosInFactors()
factor() call, this is the actual number (MUMPS parameter
INFOG(29)); otherwise, it is the number estimated by the most recent
analyze() call (MUMPS parameter INFOG(20)).public int getNumNegEigenvalues()
factor() call, MUMPS parameter INFOG(12)).
For matrices that are not symmetric indefinite, -1 is returned.
Note that when null pivot detection is enabled (the default), null pivots are excluded from this count, even if their sign is negative.
public int getNumPosEigenvalues()
factor() call). MUMPS does not report this
directly; it is inferred from the matrix size and the numbers of
negative and null pivots. For matrices that are not symmetric
indefinite, -1 is returned.public int getNumPerturbedPivots()
factor()
call). This is the sum of the null pivots detected (see getNumNullPivots()) and the tiny pivots modified by static pivoting (see
getNumTinyPivots()); only one of these mechanisms can be active
at a time. As with the perturbed pivots reported by Pardiso, a non-zero
value generally indicates a singular, or very nearly singular, matrix.public int getNumNullPivots()
setNullPivotDetection(boolean)).public int getNumTinyPivots()
setStaticPivotTolerance(double)).public int getNumDelayedPivots()
setApplyWeightedMatchings(), setScaling(), or setSymOrderingStrategy().public int getSPDZeroPivot()
public int getPeakAnalysisMemoryUsage()
analyze() call, would be needed by a
single process for an in-core factorization (MUMPS parameter INFOG(16)).
MUMPS reports memory in Mbytes, so the returned value is a multiple of
1024.public int getAnalysisMemoryUsage()
analyze() call would be needed for an in-core
factorization (MUMPS parameter INFOG(17)). MUMPS reports memory in
Mbytes, so the returned value is a multiple of 1024.public int getFactorSolveMemoryUsage()
factor() call (MUMPS parameter INFOG(21)). MUMPS reports
memory in Mbytes, so the returned value is a multiple of 1024.public boolean hasMultipleRhsSolves()
solve(X,B,nrhs).public boolean hasIterativeSolves()
DirectSolver.IterativeMethod are available, as are the
settings DirectSolver.setIterativeMethod(maspack.solvers.DirectSolver.IterativeMethod), DirectSolver.setIterativeMaxSolves(int) and
DirectSolver.setIterativeTolerance(double).public int iterativeSolve(double[] vals,
double[] x,
double[] b)
M x = biteratively, using the most recent factorization as a preconditioner and the matrix values supplied by
vals. If the current values
are close to those associated with the factorization, this can be
considerably faster than an explicit factor()
and solve(). The method, maximum number
of preconditioner solves and tolerance are set by DirectSolver.setIterativeMethod(maspack.solvers.DirectSolver.IterativeMethod), DirectSolver.setIterativeMaxSolves(int) and DirectSolver.setIterativeTolerance(double).
This method is only available if DirectSolver.hasIterativeSolves() returns
true; otherwise, it returns 0 and the caller should fall
back on factoring and solving directly.
MUMPS does not provide iterative solves itself. Instead, the iteration is performed in the native wrapper, using the most recent factorization as a preconditioner and the supplied values for matrix products.
vals - current values of the non-zero matrix elements, in the same
ordering as that supplied to analyze()x - vector in which the result is returnedb - right hand vector of the matrix equation<= 0 if the
iterative solve was not performed or did not succeedpublic double[] getLastIterativeTimes()
iterativeSolve(double[], double[], double[]), in msec: the total time spent in the native code, the
time spent in preconditioner solves, and the time spent in matrix-vector
products. The remainder of the total is vector operations and setup.
Intended for performance analysis.null if not available