PARDISO of Intel oneMKL (structsolve.pardiso)#
Interface to the sparse direct solver PARDISO of Intel oneMKL
Used by Analysis.linear_solver = 'pardiso', see static._factorize().
The shared library mkl_rt of oneMKL is given by the environment variable
STRUCTSOLVE_MKL_RT, otherwise found by ctypes.util.find_library()
or under sys.prefix or the user site, as installed by pip install mkl
(the optional dependency structsolve[pardiso]) or by conda.
PardisoSolver calls the phases of PARDISO separately, in particular
the phase 22, a numerical factorization that reuses the analysis (ordering
and symbolic factorization) of the last phase 12 for a matrix of the same
pattern.
- structsolve.pardiso.MKL_RT_ENV = 'STRUCTSOLVE_MKL_RT'#
Environment variable with the path of the shared library
mkl_rt
- exception structsolve.pardiso.PardisoError(phase, error)#
Error code of PARDISO,
errornot 0Raised by the calls of
PardisoSolverwhen PARDISO returns a non-zero error code; the message gives the phase and the code.- Parameters:
- phaseint
Phase of PARDISO that failed, e.g.
12,22or33.- errorint
Error code returned by PARDISO, see the manual of oneMKL, e.g.
-4for a zero pivot.
- class structsolve.pardiso.PardisoSolver(mtype=-2)#
PARDISO solver of one real matrix, by default symmetric indefinite (
mtype = -2), given by its upper triangle in CSR format with every diagonal term storediparmis the array of the parameters of PARDISO, indexed from 0, i.e.iparm[i - 1]isiparm(i)of the manual of oneMKL: all zeros, the default parameters, which PARDISO fills, or set by the user withiparm[0] = 1. After a factorization,iparm[13]is the number of perturbed pivots andiparm[21]andiparm[22]the numbers of positive and negative eigenvalues (mtype = -2).The matrix of the last factorization is kept, not copied, for the iterative refinement of
solve(), and must not be changed.- Parameters:
- mtypeint, optional
Matrix type of PARDISO, see the manual of oneMKL. Default
-2, real symmetric indefinite.
- Raises:
- ImportError
When oneMKL is not found, see
load_mkl().
- property analyzed#
Whether the solver holds an analysis, for the phase 22
Trueafter a factorization of phase 12, untilfree(everything=True).
- factorize(A, phase=12)#
Factorization of the CSR matrix
A,float64, with the phase 12 (analysis and numerical factorization) or 22 (numerical factorization with the analysis of the last phase 12,Ahaving its pattern)The indices of
Aare sorted first when needed. The values ofAare kept, not copied, until the next factorization orfree().- Parameters:
- Ascipy.sparse.csr_matrix
Square
float64matrix of sizen x n, its upper triangle with every diagonal term stored for a symmetricmtype.- phaseint, optional
12(default) or22.
- Raises:
- ValueError
When
Ais not square, notfloat64, has an empty row, whenphaseis neither12nor22, or for the phase 22 without the analysis of a matrix of the same size and number of stored terms.- PardisoError
When PARDISO fails.
- free(everything=False)#
Frees the memory of the factorization (phase 0), keeping the analysis for the phase 22, or all the memory of PARDISO (phase -1)
Nothing is passed to PARDISO when the solver holds neither an analysis nor a factorization.
- Parameters:
- everythingbool, optional
Whether the analysis is freed as well (phase -1). Default
False.
- solve(b)#
Solution of the last factorization (phase 33),
bof shape(n,)or(n, nrhs)bis converted to a Fortran-orderedfloat64array for PARDISO, which applies its iterative refinement with the values of the last factorization.- Parameters:
- barray-like
Right-hand side(s), converted to
float64, of shape(n,)or(n, nrhs).
- Returns:
- xndarray
Solution of the shape of
b, C-contiguous.
- Raises:
- ValueError
When there is no factorization or
bdoes not havenrows.- PardisoError
When PARDISO fails.
- structsolve.pardiso.available()#
Whether PARDISO can be used, i.e.
mkl_rtis foundCalls
load_mkl()and catches itsImportError.- Returns:
- availablebool
Truewhenload_mkl()found the library.
- structsolve.pardiso.load_mkl()#
The function
pardisoof the shared librarymkl_rt, loaded onceThe library is looked for at the path of the environment variable
STRUCTSOLVE_MKL_RT, otherwise byctypes.util.find_library(), otherwise under theliborLibrary/binfolder ofsys.prefixand then in any of its subfolders or of the user site, shorter paths first. The first library that loads and haspardisois kept for the process.- Returns:
- pardisoctypes function
The function
pardisoof oneMKL, with its argument types set.
- Raises:
- ImportError
When no library
mkl_rtwith the functionpardisois found.