Sparse: lower-level API

Overview

ILU(k) level scheduling, test-matrix generation and workspace queries.

Functions

◆ random_sparse_hermitian_csr()

template<typename T>
Matrix< T, MatrixFormat::CSR > batchlas::csr_generators::random_sparse_hermitian_csr ( int n,
float density,
int batch_size = 1,
unsigned seed = 42,
typename base_type< T >::type diagonal_boost = typename base_type< T >::type(1),
bool shared_pattern = true )

Generates a batch of random sparse symmetric (real) or Hermitian (complex) n x n CSR matrices.

Every row holds its diagonal entry. Off-diagonal entries come in (i, j) / (j, i) pairs with conjugate values, drawn uniformly from [-1, 1] (real and imaginary parts independently). Each diagonal is real and set to the row's off-diagonal absolute sum (|re| + |im| for complex) plus diagonal_boost, so the matrix is strictly diagonally dominant with a positive diagonal. Column indices are sorted within each row. Storage is allocated and filled on the device; the call waits before returning. Equivalent to Matrix::RandomSparseHermitian().

Template Parameters
Tfloat, double, std::complex<float> or std::complex<double>
Parameters
nmatrix order
densitytarget fraction of stored entries over the full n x n matrix, diagonal included; clamped to [0, 1]. The count is rounded to nearest, raised to at least n, its off-diagonal part rounded up to even, and capped at n * n.
batch_sizenumber of matrices
seedRNG seed; equal seeds give identical matrices
diagonal_boostmargin added to each diagonal above its off-diagonal row sum
shared_patterntrue: every batch item has the same sparsity pattern (values still differ); false: one pattern per item
Returns
an owning CSR Matrix; nnz() is the same for every item
Exceptions
batchlas::invalid_argumentif n <= 0 or batch_size <= 0

◆ iluk_build_level_schedule()

template<typename T>
void batchlas::iluk_build_level_schedule ( ILUKPreconditioner< T > & M)

Builds the triangular-solve level schedule from M.lu's sparsity pattern.

iluk_factorize already does this; call it only for an ILUKPreconditioner assembled by hand, because iluk_apply requires a valid schedule. Runs on the host and reads M.lu's row offsets and column indices.

Parameters
Mfactor whose lu, n are set; its schedule fields are overwritten
Exceptions
batchlas::invalid_argumentif M.n <= 0

◆ iluk_buffer_size()

template<Backend B, typename T>
size_t batchlas::iluk_buffer_size ( Queue & ctx,
const MatrixView< T, MatrixFormat::CSR > & A,
const ILUKParams< T > & params = ILUKParams< T >() )

Bytes of workspace the Span overload of iluk_factorize needs for A.

An upper bound: it sizes against the symbolic ILU(k) pattern, and the numeric phase only prunes. Costs one host-side symbolic factorization of item 0.

Parameters
ctxqueue the factorization will run on
Athe matrix batch that will be factored
paramsthe parameters that will be used
Returns
required workspace size in bytes
Exceptions
batchlas::invalid_argumentfor a non-square A, out-of-range params, or validate_batch_sparsity == false with a batch of more than one

◆ iluk_apply_buffer_size() [1/2]

template<Backend B, typename T>
size_t batchlas::iluk_apply_buffer_size ( Queue & ctx,
const ILUKView< T > & M,
const MatrixView< T, MatrixFormat::Dense > & rhs,
const MatrixView< T, MatrixFormat::Dense > & out )

Bytes of workspace iluk_apply needs; currently always 0.

◆ iluk_apply_buffer_size() [2/2]

template<Backend B, typename T>
size_t batchlas::iluk_apply_buffer_size ( Queue & ctx,
const ILUKPreconditioner< T > & M,
const MatrixView< T, MatrixFormat::Dense > & rhs,
const MatrixView< T, MatrixFormat::Dense > & out )

iluk_apply_buffer_size on an owning factor; forwards M.view().

Definition at line 241 of file iluk.hh.

◆ spmm_buffer_size()

template<Backend B, typename T, MatrixFormat MFormat>
size_t batchlas::spmm_buffer_size ( Queue & ctx,
const MatrixView< T, MFormat > & A,
const MatrixView< T, MatrixFormat::Dense > & B_mat,
const MatrixView< T, MatrixFormat::Dense > & C,
T alpha,
T beta,
Transpose transA,
Transpose transB )

Bytes of workspace spmm needs for these arguments.

Resolves the same route as spmm and returns that route's need; a natively routed call needs zero bytes and is sized without touching device memory. Pass exactly the arguments the spmm call will get.

Template Parameters
Bbackend the call is compiled for
Tscalar type
MFormatstorage format of A; only MatrixFormat::CSR is instantiated
Parameters
ctxqueue the call will run on
Athe sparse operand of the spmm call
B_matthe dense operand of the spmm call
Cthe output of the spmm call
alphathe spmm call's alpha
betathe spmm call's beta
transAthe spmm call's transA
transBthe spmm call's transB
Returns
required workspace size in bytes (may be 0)
Exceptions
batchlas::NoRouteErrorunder the same conditions as spmm