pub struct JacobiPreconditioner { /* private fields */ }Expand description
Diagonal (Jacobi) preconditioner: M = diag(A), so M^{-1} r = r / diag.
The cheapest possible preconditioner. It is always applicable and cannot break
down: any exactly-zero diagonal entry is treated as 1.0 (identity on that
row) so the reciprocal is finite. Stores the precomputed reciprocal diagonal,
length n_cells, each entry dimensionless.
Implementations§
Source§impl JacobiPreconditioner
impl JacobiPreconditioner
Sourcepub fn new(a: &LduMatrix) -> Self
pub fn new(a: &LduMatrix) -> Self
Build the reciprocal diagonal from a.
A diagonal entry that is exactly 0.0 (or non-finite) is replaced by a
unit reciprocal so apply never produces inf/NaN.
Sourcepub fn apply_on(&self, r: &[f64], z: &mut [f64], backend: ComputeBackend)
pub fn apply_on(&self, r: &[f64], z: &mut [f64], backend: ComputeBackend)
Apply z = M^{-1} r on the chosen ComputeBackend.
§Why this one parallelises and ILU(0) does not
Jacobi is the only preconditioner in this module that is embarrassingly
parallel: z_i depends on r_i and inv_diag[i] alone, so the loop has
no loop-carried dependence at all. Contrast
Ilu0Preconditioner::apply_on, whose triangular solves are inherently
sequential.
§Determinism
Bitwise identical on every backend and at any thread count. Each output
element is one independent multiplication, so — as for
crate::ldu_matrix::parallel::axpy and
crate::ldu_matrix::parallel::scale — there is no reduction to
reassociate. It is also bitwise identical to the serial loop this replaced,
so switching backend cannot change a solver’s iteration count or residual
history through this path.
§Arguments
r— residual to precondition, lengthn_cells, dimensionless.z— output buffer, lengthn_cells. Fully overwritten.backend— requested execution backend. Belowcrate::ldu_matrix::parallel::VECOP_MIN_ELEMENTSelements aComputeBackend::CpuMultirequest runs serially, because this kernel is memory-bandwidth bound at one multiply per element and threading it on a small vector costs more than it saves — the same floor and the same reasoning as the vector operations it sits beside.