CUSP
Loading...
Searching...
No Matches
cusp::monitor< ValueType > Class Template Reference

#include <monitor.h>

Inheritance diagram for cusp::monitor< ValueType >:
cusp::convergence_monitor< ValueType > cusp::default_monitor< ValueType > cusp::verbose_monitor< ValueType >

Public Types

typedef cusp::norm_type< ValueType >::type Real
 A real-valued type used for norms and tolerances.
 

Public Methods

template<typename VectorType >
 monitor (const VectorType &b, const size_t iteration_limit=500, const Real relative_tolerance=1e-5, const Real absolute_tolerance=0, const bool verbose=false)
 Constructs a monitor for a given right-hand-side b.
 
void operator++ (void)
 Increments the iteration count.
 
bool converged (void) const
 Indicates whether the last tested residual satisfies the convergence tolerance.
 
Real residual_norm (void) const
 Euclidean norm of last residual.
 
size_t iteration_count (void) const
 Returns the number of iterations that the monitor has executed.
 
size_t iteration_limit (void) const
 Returns the maximum number of iterations.
 
Real relative_tolerance (void) const
 Returns the relative tolerance.
 
Real absolute_tolerance (void) const
 Returns the absolute tolerance.
 
Real tolerance (void) const
 Return the tolerance equal to absolute_tolerance() + relative_tolerance() * ||b||.
 
template<typename Vector >
bool finished (const Vector &r)
 Applies convergence criteria to determine whether iteration is finished.
 
template<typename DerivedPolicy , typename Vector >
bool finished (thrust::execution_policy< DerivedPolicy > &exec, const Vector &r)
 Applies convergence criteria using an explicit execution policy.
 
void set_verbose (bool verbose_=true)
 Sets the verbosity level of the monitor.
 
bool is_verbose (void)
 Gets the verbosity level of the monitor.
 
template<typename Vector >
void reset (const Vector &b)
 Resets the monitor using same convergence criteria.
 
void print (void)
 Prints the number of iterations and convergence history information.
 
Real immediate_rate (void)
 Returns the immediate convergence rate.
 
Real geometric_rate (void)
 Returns the geometric convergence rate.
 
Real average_rate (void)
 Returns the average convergence rate.
 

Public Members

cusp::array1d< Real, cusp::host_memory > residuals
 Array holding the residuals per iteration.
 

Detailed description

template<typename ValueType>
class cusp::monitor< ValueType >

Implements standard convergence criteria and reporting for iterative solvers.

Template Parameters
ValueTypescalar type used in the solver (e.g. float or cusp::complex<double>).
Overview
The monitor terminates iteration when the residual norm satisfies the condition ||b - A x|| <= absolute_tolerance + relative_tolerance * ||b|| or when the iteration limit is reached. Classes to monitor iterative solver progress, check for convergence, etc. Follows the implementation of Iteration in the ITL:
See also
http://www.osl.iu.edu/research/itl/doc/Iteration.html
Example
The following code snippet demonstrates how to configure the monitor and use it with an iterative solver.
#include <cusp/monitor.h>
#include <cusp/krylov/cg.h>
int main(void)
{
// create an empty sparse matrix structure (CSR format)
// initialize matrix
// allocate storage for solution (x) and right hand side (b)
// set stopping criteria:
// iteration_limit = 100
// relative_tolerance = 1e-6
// solve the linear system A x = b
// report solver results
{
std::cout << "Solver converged to " << monitor.relative_tolerance() << " relative tolerance";
std::cout << " after " << monitor.iteration_count() << " iterations" << std::endl;
}
else
{
std::cout << "Solver reached iteration limit " << monitor.iteration_limit() << " before converging";
std::cout << " to " << monitor.relative_tolerance() << " relative tolerance " << std::endl;
}
return 0;
}
Conjugate Gradient (CG) method.
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition array1d.h:99
Compressed sparse row (CSR) representation a sparse matrix.
Definition csr_matrix.h:108
Implements standard convergence criteria and reporting for iterative solvers.
Definition monitor.h:102
Compressed Sparse Row matrix format.
void cg(const LinearOperator &A, VectorType1 &x, const VectorType2 &b, Monitor &monitor, Preconditioner &M)
Conjugate Gradient method.
Real relative_tolerance(void) const
Returns the relative tolerance.
bool converged(void) const
Indicates whether the last tested residual satisfies the convergence tolerance.
size_t iteration_count(void) const
Returns the number of iterations that the monitor has executed.
size_t iteration_limit(void) const
Returns the maximum number of iterations.
Monitor iterative solver convergence.
Poisson matrix generators.

Definition at line 101 of file monitor.h.