Class SparseDirectSolver<T>
- Namespace
- NVMathNet.Sparse
- Assembly
- NVMath.Net.dll
Sparse direct solver for A·X = B backed by NVIDIA cuDSS. Mirrors the staged workflow of
nvmath-python's DirectSolver:
- NVMathNet.Sparse.SparseDirectSolver`1.Analyze — reordering and symbolic factorisation (depends only on the sparsity pattern).
- NVMathNet.Sparse.SparseDirectSolver`1.Factorize — numerical factorisation.
- NVMathNet.Sparse.SparseDirectSolver`1.Solve(NVMathNet.DeviceBuffer{`0},NVMathNet.DeviceBuffer{`0},System.Int32) — forward/backward substitution; call repeatedly for new right-hand sides.
- Change the values of A in place and call NVMathNet.Sparse.SparseDirectSolver`1.Refactorize to reuse the analysis.
Requires the cuDSS runtime library (cudss64_0.dll / libcudss.so.0) on the library path.
The CSR matrix must have sorted column indices and must outlive this solver.
public sealed class SparseDirectSolver<T> : IDisposable where T : unmanaged, INumberBase<T>Type Parameters
T-
System.Single, System.Double or System.Numerics.Complex (double-precision complex; use the Hermitian structures for Hermitian matrices).
Inheritance
Implements
Inherited Members
Constructors
SparseDirectSolver(CsrMatrix<T>, DirectSolverOptions?, CudaStream?)
Creates a solver for matrix.
public SparseDirectSolver(CsrMatrix<T> matrix, DirectSolverOptions? options = null, CudaStream? stream = null)Parameters
matrixCsrMatrix<T>-
Square CSR matrix; must outlive the solver.
optionsDirectSolverOptions?-
Solver options;
nulluses defaults. streamCudaStream?-
Optional CUDA stream; a private stream is created if
null.
Properties
FactorNonZeros
Number of non-zeros in the factors; available after NVMathNet.Sparse.SparseDirectSolver`1.Factorize.
public long FactorNonZeros { get; }Property Value
PerturbedPivots
Number of pivots cuDSS perturbed during the last factorisation.
public int PerturbedPivots { get; }Property Value
Methods
Analyze()
Reordering and symbolic factorisation. Depends only on the sparsity pattern, so it is done once even if the values change.
public void Analyze()AnalyzeAsync(CancellationToken)
Asynchronous version of NVMathNet.Sparse.SparseDirectSolver`1.Analyze (runs on the thread pool).
public Task AnalyzeAsync(CancellationToken ct = default)Parameters
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()Factorize()
Numerical factorisation. Runs NVMathNet.Sparse.SparseDirectSolver`1.Analyze first if it has not been done. Throws System.InvalidOperationException if cuDSS reports a failure (for example a singular matrix).
public void Factorize()FactorizeAsync(CancellationToken)
Asynchronous version of NVMathNet.Sparse.SparseDirectSolver`1.Factorize (runs on the thread pool).
public Task FactorizeAsync(CancellationToken ct = default)Parameters
Returns
Refactorize()
Re-factorises after the values of the matrix changed in place (same sparsity pattern), reusing the analysis.
public void Refactorize()RefactorizeAsync(CancellationToken)
Asynchronous version of NVMathNet.Sparse.SparseDirectSolver`1.Refactorize (runs on the thread pool).
public Task RefactorizeAsync(CancellationToken ct = default)Parameters
Returns
SetValues(DeviceBuffer<T>)
Points the solver at a different values array (same sparsity pattern). NVMathNet.Sparse.SparseDirectSolver`1.Solve(NVMathNet.DeviceBuffer{`0},NVMathNet.DeviceBuffer{`0},System.Int32) refactorises automatically afterwards; call NVMathNet.Sparse.SparseDirectSolver`1.Refactorize explicitly to do it earlier.
public void SetValues(DeviceBuffer<T> values)Parameters
valuesDeviceBuffer<T>
Solve(DeviceBuffer<T>, DeviceBuffer<T>, int)
Solves A·X = B. Runs NVMathNet.Sparse.SparseDirectSolver`1.Factorize first if it has not been done.
public void Solve(DeviceBuffer<T> b, DeviceBuffer<T> x, int nrhs = 1)Parameters
bDeviceBuffer<T>-
Right-hand sides, column-major
n × nrhs(leading dimension n). xDeviceBuffer<T>-
Solution, column-major
n × nrhs; must not aliasb. nrhsint-
Number of right-hand sides.
SolveAsync(DeviceBuffer<T>, DeviceBuffer<T>, int, CancellationToken)
Asynchronous version of NVMathNet.Sparse.SparseDirectSolver`1.Solve(NVMathNet.DeviceBuffer{`0},NVMathNet.DeviceBuffer{`0},System.Int32) (runs on the thread pool).
public Task SolveAsync(DeviceBuffer<T> b, DeviceBuffer<T> x, int nrhs = 1, CancellationToken ct = default)Parameters
bDeviceBuffer<T>xDeviceBuffer<T>nrhsintctCancellationToken