33#ifndef GKO_PUBLIC_CORE_STOP_CRITERION_HPP_
34#define GKO_PUBLIC_CORE_STOP_CRITERION_HPP_
37#include <ginkgo/core/base/abstract_factory.hpp>
38#include <ginkgo/core/base/array.hpp>
39#include <ginkgo/core/base/executor.hpp>
40#include <ginkgo/core/base/lin_op.hpp>
41#include <ginkgo/core/base/polymorphic_object.hpp>
42#include <ginkgo/core/base/utils.hpp>
43#include <ginkgo/core/log/logger.hpp>
44#include <ginkgo/core/stop/stopping_status.hpp>
104 auto converged = parent_->
check(stopping_id, set_finalized,
112#define GKO_UPDATER_REGISTER_PARAMETER(_type, _name) \
113 const Updater& _name(_type const& value) const \
118 mutable _type _name##_ {}
119#define GKO_UPDATER_REGISTER_PTR_PARAMETER(_type, _name) \
120 const Updater& _name(ptr_param<_type> value) const \
122 _name##_ = value.get(); \
125 mutable _type* _name##_ {}
127 GKO_UPDATER_REGISTER_PARAMETER(
size_type, num_iterations);
129 GKO_UPDATER_REGISTER_PARAMETER(
bool, ignore_residual_check);
130 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, residual);
131 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, residual_norm);
132 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp,
133 implicit_sq_residual_norm);
134 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, solution);
136#undef GKO_UPDATER_REGISTER_PTR_PARAMETER
137#undef GKO_UPDATER_REGISTER_PARAMETER
170 this, updater.num_iterations_,
updater.residual_,
176 this, updater.num_iterations_,
updater.residual_,
200 virtual bool check_impl(
uint8 stopping_id,
bool set_finalized,
214 void set_all_statuses(
uint8 stopping_id,
bool set_finalized,
217 explicit Criterion(std::shared_ptr<const gko::Executor> exec)
234 std::shared_ptr<const LinOp> system_matrix;
235 std::shared_ptr<const LinOp> b;
237 const LinOp* initial_residual;
241 std::shared_ptr<const LinOp> b,
const LinOp* x,
242 const LinOp* initial_residual =
nullptr)
243 : system_matrix{system_matrix},
246 initial_residual{initial_residual}
303#define GKO_ENABLE_CRITERION_FACTORY(_criterion, _parameters_name, \
306 const _parameters_name##_type& get_##_parameters_name() const \
308 return _parameters_name##_; \
311 class _factory_name \
312 : public ::gko::stop::EnableDefaultCriterionFactory< \
313 _factory_name, _criterion, _parameters_name##_type> { \
314 friend class ::gko::EnablePolymorphicObject< \
315 _factory_name, ::gko::stop::CriterionFactory>; \
316 friend class ::gko::enable_parameters_type<_parameters_name##_type, \
318 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
319 : ::gko::stop::EnableDefaultCriterionFactory< \
320 _factory_name, _criterion, _parameters_name##_type>( \
323 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec, \
324 const _parameters_name##_type& parameters) \
325 : ::gko::stop::EnableDefaultCriterionFactory< \
326 _factory_name, _criterion, _parameters_name##_type>( \
327 std::move(exec), parameters) \
330 friend ::gko::stop::EnableDefaultCriterionFactory< \
331 _factory_name, _criterion, _parameters_name##_type>; \
334 _parameters_name##_type _parameters_name##_; \
337 static_assert(true, \
338 "This assert is used to counter the false positive extra " \
339 "semi-colon warnings")
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition abstract_factory.hpp:75
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:374
This mixin provides a default implementation of a concrete factory.
Definition abstract_factory.hpp:154
Definition lin_op.hpp:146
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:187
The Updater class serves for convenient argument passing to the Criterion's check function.
Definition criterion.hpp:83
bool check(uint8 stopping_id, bool set_finalized, array< stopping_status > *stop_status, bool *one_changed) const
Calls the parent Criterion object's check method.
Definition criterion.hpp:101
Updater(const Updater &)=delete
Prevent copying and moving the object This is to enforce the use of argument passing and calling chec...
The Criterion class is a base class for all stopping criteria.
Definition criterion.hpp:64
Updater update()
Returns the updater object.
Definition criterion.hpp:150
bool check(uint8 stopping_id, bool set_finalized, array< stopping_status > *stop_status, bool *one_changed, const Updater &updater)
This checks whether convergence was reached for a certain criterion.
Definition criterion.hpp:165
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:149
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
This struct is used to pass parameters to the EnableDefaultCriterionFactoryCriterionFactory::generate...
Definition criterion.hpp:233