MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::itl::basic_iteration< Real > Class Template Reference

Convergence controller: tracks iteration count, residual, and tolerance. More...

#include <basic_iteration.hpp>

Inheritance diagram for mtl::itl::basic_iteration< Real >:
mtl::itl::cyclic_iteration< Real > mtl::itl::noisy_iteration< Real >

Public Member Functions

template<Vector V>
 basic_iteration (const V &r0, int max_iter, Real rtol, Real atol=Real(0))
 Construct from initial residual vector r0.
 basic_iteration (Real norm_r0, int max_iter, Real rtol, Real atol=Real(0))
 Construct from precomputed norm of r0.
template<Vector V>
void reset (const V &r0)
 Prepare the object for another solve (issue 888): the iteration count back to 0, the tolerance's reference norm to ||r0||, the residual, error and finished state cleared.
void reset (Real norm_r0)
 reset from a precomputed norm of r0, as the second constructor takes.
template<Vector V>
bool finished (const V &r)
 Test convergence given residual vector r.
bool finished (Real r)
 Test convergence given scalar residual norm.
template<Vector V>
bool converged_now (const V &r)
 Convergence test only, without the iteration-limit test: for a check in the middle of an iteration (bicgstab's half step, bicgstab_ell's BiCG part), where reaching max_iter must not cut the iteration short (issue 866).
bool converged_now (Real r)
basic_iteration & operator++ ()
 Pre-increment iteration counter.
basic_iteration operator++ (int)
 Post-increment iteration counter.
bool first () const
 Returns true if this is the first iteration (i <= 1).
 operator int () const
 Error code: 0 = converged, 1 = max_iter exceeded, 2-5 breakdown, 6 = non-finite residual.
int error_code () const
int iterations () const
Real resid () const
Real relresid () const
Real tol () const
Real atol () const
Real norm_r0 () const
void fail (int code, const std::string &)
 Signal solver breakdown or other failure.
bool is_finished () const

Static Public Attributes

static constexpr int non_finite = 6
 Error code of a residual that is NaN or infinite.
static constexpr int not_positive_definite = 7
 Error code of a preconditioner found not to be positive definite: a v^H M^{-1} v negative beyond rounding, in a solver that requires an SPD (HPD) M.

Protected Member Functions

bool converged (Real r) const

Protected Attributes

int i_
int max_iter_
Real rtol_
Real atol_
Real my_norm_r0_
Real resid_
int error_
bool is_finished_

Detailed Description

template<typename Real>
class mtl::itl::basic_iteration< Real >

Convergence controller: tracks iteration count, residual, and tolerance.

Convergence test: resid <= rtol * norm_r0 || resid <= atol

Error codes: 0 converged, 1 max_iter reached, 2 to 5 a solver's breakdown (see the solver), non_finite (6) when a residual handed to finished() is NaN or infinite, and not_positive_definite (7) when a solver that requires an SPD (HPD) preconditioner finds that M is not (minres, cg; #949).

Constructor & Destructor Documentation

◆ basic_iteration() [1/2]

template<typename Real>
template<Vector V>
mtl::itl::basic_iteration< Real >::basic_iteration ( const V & r0,
int max_iter,
Real rtol,
Real atol = Real(0) )
inline

Construct from initial residual vector r0.

◆ basic_iteration() [2/2]

template<typename Real>
mtl::itl::basic_iteration< Real >::basic_iteration ( Real norm_r0,
int max_iter,
Real rtol,
Real atol = Real(0) )
inline

Construct from precomputed norm of r0.

Member Function Documentation

◆ atol()

template<typename Real>
Real mtl::itl::basic_iteration< Real >::atol ( ) const
inline

◆ converged()

template<typename Real>
bool mtl::itl::basic_iteration< Real >::converged ( Real r) const
inlineprotected

◆ converged_now() [1/2]

template<typename Real>
template<Vector V>
bool mtl::itl::basic_iteration< Real >::converged_now ( const V & r)
inline

Convergence test only, without the iteration-limit test: for a check in the middle of an iteration (bicgstab's half step, bicgstab_ell's BiCG part), where reaching max_iter must not cut the iteration short (issue 866).

Finishes, with error code 0, only when r converged.

◆ converged_now() [2/2]

template<typename Real>
bool mtl::itl::basic_iteration< Real >::converged_now ( Real r)
inline

◆ error_code()

template<typename Real>
int mtl::itl::basic_iteration< Real >::error_code ( ) const
inline

◆ fail()

template<typename Real>
void mtl::itl::basic_iteration< Real >::fail ( int code,
const std::string &  )
inline

Signal solver breakdown or other failure.

◆ finished() [1/2]

template<typename Real>
template<Vector V>
bool mtl::itl::basic_iteration< Real >::finished ( const V & r)
inline

Test convergence given residual vector r.

◆ finished() [2/2]

template<typename Real>
bool mtl::itl::basic_iteration< Real >::finished ( Real r)
inline

Test convergence given scalar residual norm.

◆ first()

template<typename Real>
bool mtl::itl::basic_iteration< Real >::first ( ) const
inline

Returns true if this is the first iteration (i <= 1).

The solvers do not use it to start their recurrences: an iteration object reused for a second solve is past its first iteration (issue 866).

◆ is_finished()

template<typename Real>
bool mtl::itl::basic_iteration< Real >::is_finished ( ) const
inline

◆ iterations()

template<typename Real>
int mtl::itl::basic_iteration< Real >::iterations ( ) const
inline

◆ norm_r0()

template<typename Real>
Real mtl::itl::basic_iteration< Real >::norm_r0 ( ) const
inline

◆ operator int()

template<typename Real>
mtl::itl::basic_iteration< Real >::operator int ( ) const
inline

Error code: 0 = converged, 1 = max_iter exceeded, 2-5 breakdown, 6 = non-finite residual.

◆ operator++() [1/2]

template<typename Real>
basic_iteration & mtl::itl::basic_iteration< Real >::operator++ ( )
inline

Pre-increment iteration counter.

◆ operator++() [2/2]

template<typename Real>
basic_iteration mtl::itl::basic_iteration< Real >::operator++ ( int )
inline

Post-increment iteration counter.

◆ relresid()

template<typename Real>
Real mtl::itl::basic_iteration< Real >::relresid ( ) const
inline

◆ reset() [1/2]

template<typename Real>
template<Vector V>
void mtl::itl::basic_iteration< Real >::reset ( const V & r0)
inline

Prepare the object for another solve (issue 888): the iteration count back to 0, the tolerance's reference norm to ||r0||, the residual, error and finished state cleared.

Without reset, an object reused for a second solve keeps counting toward max_iter (a budget over all the solves) and measures the relative tolerance against the first r0's norm (#866 made reuse work, and pins that behaviour); a solver can't reset it, because what r0 means (b, b - A x0, ...) is the caller's.

◆ reset() [2/2]

template<typename Real>
void mtl::itl::basic_iteration< Real >::reset ( Real norm_r0)
inline

reset from a precomputed norm of r0, as the second constructor takes.

◆ resid()

template<typename Real>
Real mtl::itl::basic_iteration< Real >::resid ( ) const
inline

◆ tol()

template<typename Real>
Real mtl::itl::basic_iteration< Real >::tol ( ) const
inline

Member Data Documentation

◆ atol_

template<typename Real>
Real mtl::itl::basic_iteration< Real >::atol_
protected

◆ error_

template<typename Real>
int mtl::itl::basic_iteration< Real >::error_
protected

◆ i_

template<typename Real>
int mtl::itl::basic_iteration< Real >::i_
protected

◆ is_finished_

template<typename Real>
bool mtl::itl::basic_iteration< Real >::is_finished_
protected

◆ max_iter_

template<typename Real>
int mtl::itl::basic_iteration< Real >::max_iter_
protected

◆ my_norm_r0_

template<typename Real>
Real mtl::itl::basic_iteration< Real >::my_norm_r0_
protected

◆ non_finite

template<typename Real>
int mtl::itl::basic_iteration< Real >::non_finite = 6
staticconstexpr

Error code of a residual that is NaN or infinite.

◆ not_positive_definite

template<typename Real>
int mtl::itl::basic_iteration< Real >::not_positive_definite = 7
staticconstexpr

Error code of a preconditioner found not to be positive definite: a v^H M^{-1} v negative beyond rounding, in a solver that requires an SPD (HPD) M.

The same code in every solver (#949).

◆ resid_

template<typename Real>
Real mtl::itl::basic_iteration< Real >::resid_
protected

◆ rtol_

template<typename Real>
Real mtl::itl::basic_iteration< Real >::rtol_
protected

The documentation for this class was generated from the following file: