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, error not 0

Raised by the calls of PardisoSolver when 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, 22 or 33.

errorint

Error code returned by PARDISO, see the manual of oneMKL, e.g. -4 for 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 stored

iparm is the array of the parameters of PARDISO, indexed from 0, i.e. iparm[i - 1] is iparm(i) of the manual of oneMKL: all zeros, the default parameters, which PARDISO fills, or set by the user with iparm[0] = 1. After a factorization, iparm[13] is the number of perturbed pivots and iparm[21] and iparm[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

True after a factorization of phase 12, until free(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, A having its pattern)

The indices of A are sorted first when needed. The values of A are kept, not copied, until the next factorization or free().

Parameters:
Ascipy.sparse.csr_matrix

Square float64 matrix of size n x n, its upper triangle with every diagonal term stored for a symmetric mtype.

phaseint, optional

12 (default) or 22.

Raises:
ValueError

When A is not square, not float64, has an empty row, when phase is neither 12 nor 22, 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), b of shape (n,) or (n, nrhs)

b is converted to a Fortran-ordered float64 array 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 b does not have n rows.

PardisoError

When PARDISO fails.

structsolve.pardiso.available()#

Whether PARDISO can be used, i.e. mkl_rt is found

Calls load_mkl() and catches its ImportError.

Returns:
availablebool

True when load_mkl() found the library.

structsolve.pardiso.load_mkl()#

The function pardiso of the shared library mkl_rt, loaded once

The library is looked for at the path of the environment variable STRUCTSOLVE_MKL_RT, otherwise by ctypes.util.find_library(), otherwise under the lib or Library/bin folder of sys.prefix and then in any of its subfolders or of the user site, shorter paths first. The first library that loads and has pardiso is kept for the process.

Returns:
pardisoctypes function

The function pardiso of oneMKL, with its argument types set.

Raises:
ImportError

When no library mkl_rt with the function pardiso is found.