CUSP
Loading...
Searching...
No Matches
monitor.h
Go to the documentation of this file.
1/*
2 * Copyright 2008-2014 NVIDIA Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
21#pragma once
22
23#include <cusp/detail/config.h>
24#include <cusp/blas/blas.h>
25#include <cusp/complex.h>
26
27#include <limits>
28#include <iostream>
29#include <iomanip>
30
31namespace cusp
32{
100template <typename ValueType>
102{
103public:
105 typedef typename cusp::norm_type<ValueType>::type Real;
106
118 template <typename VectorType>
119 monitor(const VectorType& b,
120 const size_t iteration_limit = 500,
121 const Real relative_tolerance = 1e-5,
122 const Real absolute_tolerance = 0,
123 const bool verbose = false);
124
128 void operator++(void);
129
135 bool converged(void) const;
136
142 Real residual_norm(void) const;
143
149 size_t iteration_count(void) const;
150
156 size_t iteration_limit(void) const;
157
164
171
177 Real tolerance(void) const;
178
185 template <typename Vector>
186 bool finished(const Vector& r);
187
195 template <typename DerivedPolicy, typename Vector>
196 bool finished(thrust::execution_policy<DerivedPolicy> &exec, const Vector& r);
197
204 void set_verbose(bool verbose_ = true);
205
211 bool is_verbose(void);
212
219 template <typename Vector>
220 void reset(const Vector& b);
221
225 void print(void);
226
233
240
247
250
251private:
252
254 Real b_norm;
255 Real r_norm;
256 size_t iteration_limit_;
257 size_t iteration_count_;
258 Real relative_tolerance_;
259 Real absolute_tolerance_;
260 bool verbose;
262};
263
264// TODO : Remove convergence, default, and verbose monitors in v0.6.0
265
271template <typename ValueType>
272class convergence_monitor : public monitor<ValueType>
273{
274private:
275
277
278public:
279
281 typedef typename Parent::Real Real;
282
296 template <typename VectorType>
297 CUSP_DEPRECATED
298 convergence_monitor(const VectorType& b,
299 const size_t iteration_limit = 500,
300 const Real relative_tolerance = 1e-5,
301 const Real absolute_tolerance = 0)
303};
304
310template <typename ValueType>
311class default_monitor : public monitor<ValueType>
312{
313private:
314
316
317public:
318
320 typedef typename Parent::Real Real;
321
335 template <typename VectorType>
336 CUSP_DEPRECATED
337 default_monitor(const VectorType& b,
338 const size_t iteration_limit = 500,
339 const Real relative_tolerance = 1e-5,
340 const Real absolute_tolerance = 0)
342};
343
349template <typename ValueType>
350class verbose_monitor : public monitor<ValueType>
351{
352private:
353
355
356public:
357
359 typedef typename Parent::Real Real;
360
374 template <typename VectorType>
375 CUSP_DEPRECATED
376 verbose_monitor(const VectorType& b,
377 const size_t iteration_limit = 500,
378 const Real relative_tolerance = 1e-5,
379 const Real absolute_tolerance = 0)
381};
382
383} // end namespace cusp
384
385#include <cusp/detail/monitor.inl>
BLAS-like functions.
The array1d class is a 1D vector container that may contain elements stored in "host" or "device" mem...
Definition array1d.h:99
Deprecated convergence monitor.
Definition monitor.h:273
Deprecated default monitor.
Definition monitor.h:312
Implements standard convergence criteria and reporting for iterative solvers.
Definition monitor.h:102
Deprecated verbose monitor.
Definition monitor.h:351
Complex numbers.
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.
Real geometric_rate(void)
Returns the geometric convergence rate.
CUSP_DEPRECATED convergence_monitor(const VectorType &b, const size_t iteration_limit=500, const Real relative_tolerance=1e-5, const Real absolute_tolerance=0)
Constructs a convergence_monitor for a given right-hand-side b.
Definition monitor.h:298
Parent::Real Real
A real-valued type used for norms and tolerances.
Definition monitor.h:359
void print(void)
Prints the number of iterations and convergence history information.
Real residual_norm(void) const
Euclidean norm of last residual.
Real tolerance(void) const
Return the tolerance equal to absolute_tolerance() + relative_tolerance() * ||b||.
CUSP_DEPRECATED verbose_monitor(const VectorType &b, const size_t iteration_limit=500, const Real relative_tolerance=1e-5, const Real absolute_tolerance=0)
Constructs a verbose_monitor for a given right-hand-side b.
Definition monitor.h:376
Real immediate_rate(void)
Returns the immediate convergence rate.
cusp::array1d< Real, cusp::host_memory > residuals
Array holding the residuals per iteration.
Definition monitor.h:249
void reset(const Vector &b)
Resets the monitor using same convergence criteria.
bool finished(thrust::execution_policy< DerivedPolicy > &exec, const Vector &r)
Applies convergence criteria using an explicit execution policy.
Real relative_tolerance(void) const
Returns the relative tolerance.
cusp::norm_type< ValueType >::type Real
A real-valued type used for norms and tolerances.
Definition monitor.h:105
bool converged(void) const
Indicates whether the last tested residual satisfies the convergence tolerance.
bool is_verbose(void)
Gets the verbosity level of the monitor.
void set_verbose(bool verbose_=true)
Sets the verbosity level of the monitor.
void operator++(void)
Increments the iteration count.
Parent::Real Real
A real-valued type used for norms and tolerances.
Definition monitor.h:281
bool finished(const Vector &r)
Applies convergence criteria to determine whether iteration is finished.
Real average_rate(void)
Returns the average convergence rate.
size_t iteration_count(void) const
Returns the number of iterations that the monitor has executed.
Parent::Real Real
A real-valued type used for norms and tolerances.
Definition monitor.h:320
Real absolute_tolerance(void) const
Returns the absolute tolerance.
CUSP_DEPRECATED default_monitor(const VectorType &b, const size_t iteration_limit=500, const Real relative_tolerance=1e-5, const Real absolute_tolerance=0)
Constructs a default_monitor for a given right-hand-side b.
Definition monitor.h:337
size_t iteration_limit(void) const
Returns the maximum number of iterations.