Skip to main content

JacobiPreconditioner

Struct JacobiPreconditioner 

Source
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

Source

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.

Source

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, length n_cells, dimensionless.
  • z — output buffer, length n_cells. Fully overwritten.
  • backend — requested execution backend. Below crate::ldu_matrix::parallel::VECOP_MIN_ELEMENTS elements a ComputeBackend::CpuMulti request 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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.