5#ifndef GKO_PUBLIC_CORE_STOP_CRITERION_HPP_
6#define GKO_PUBLIC_CORE_STOP_CRITERION_HPP_
9#include <ginkgo/core/base/abstract_factory.hpp>
10#include <ginkgo/core/base/array.hpp>
11#include <ginkgo/core/base/executor.hpp>
12#include <ginkgo/core/base/lin_op.hpp>
13#include <ginkgo/core/base/polymorphic_object.hpp>
14#include <ginkgo/core/base/utils.hpp>
15#include <ginkgo/core/log/logger.hpp>
16#include <ginkgo/core/stop/stopping_status.hpp>
56 friend class Criterion;
76 auto converged = parent_->check(stopping_id, set_finalized,
77 stop_status, one_changed, *
this);
84#define GKO_UPDATER_REGISTER_PARAMETER(_type, _name) \
85 const Updater& _name(_type const& value) const \
90 mutable _type _name##_ {}
91#define GKO_UPDATER_REGISTER_PTR_PARAMETER(_type, _name) \
92 const Updater& _name(ptr_param<_type> value) const \
94 _name##_ = value.get(); \
97 mutable _type* _name##_ {}
99 GKO_UPDATER_REGISTER_PARAMETER(
size_type, num_iterations);
101 GKO_UPDATER_REGISTER_PARAMETER(
bool, ignore_residual_check);
102 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, residual);
103 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, residual_norm);
104 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp,
105 implicit_sq_residual_norm);
106 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, solution);
108#undef GKO_UPDATER_REGISTER_PTR_PARAMETER
109#undef GKO_UPDATER_REGISTER_PARAMETER
112 Updater(Criterion* parent) : parent_{parent} {}
141 this->
template log<log::Logger::criterion_check_started>(
142 this, updater.num_iterations_, updater.residual_,
143 updater.residual_norm_, updater.solution_, stopping_id,
145 auto all_converged = this->check_impl(
146 stopping_id, set_finalized, stop_status, one_changed, updater);
147 this->
template log<log::Logger::criterion_check_completed>(
148 this, updater.num_iterations_, updater.residual_,
149 updater.residual_norm_, updater.implicit_sq_residual_norm_,
150 updater.solution_, stopping_id, set_finalized, stop_status,
151 *one_changed, all_converged);
152 return all_converged;
172 virtual bool check_impl(
uint8 stopping_id,
bool set_finalized,
174 bool* one_changed,
const Updater& updater) = 0;
186 void set_all_statuses(
uint8 stopping_id,
bool set_finalized,
189 explicit Criterion(std::shared_ptr<const gko::Executor> exec)
205struct CriterionArgs {
206 std::shared_ptr<const LinOp> system_matrix;
207 std::shared_ptr<const LinOp> b;
209 const LinOp* initial_residual;
212 CriterionArgs(std::shared_ptr<const LinOp> system_matrix,
213 std::shared_ptr<const LinOp> b,
const LinOp* x,
214 const LinOp* initial_residual =
nullptr)
215 : system_matrix{system_matrix},
218 initial_residual{initial_residual}
244template <
typename ConcreteFactory,
typename ConcreteCriterion,
275#define GKO_ENABLE_CRITERION_FACTORY(_criterion, _parameters_name, \
278 const _parameters_name##_type& get_##_parameters_name() const \
280 return _parameters_name##_; \
283 class _factory_name \
284 : public ::gko::stop::EnableDefaultCriterionFactory< \
285 _factory_name, _criterion, _parameters_name##_type> { \
286 friend class ::gko::EnablePolymorphicObject< \
287 _factory_name, ::gko::stop::CriterionFactory>; \
288 friend class ::gko::enable_parameters_type<_parameters_name##_type, \
290 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
291 : ::gko::stop::EnableDefaultCriterionFactory< \
292 _factory_name, _criterion, _parameters_name##_type>( \
295 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec, \
296 const _parameters_name##_type& parameters) \
297 : ::gko::stop::EnableDefaultCriterionFactory< \
298 _factory_name, _criterion, _parameters_name##_type>( \
299 std::move(exec), parameters) \
302 friend ::gko::stop::EnableDefaultCriterionFactory< \
303 _factory_name, _criterion, _parameters_name##_type>; \
306 _parameters_name##_type _parameters_name##_; \
309 static_assert(true, \
310 "This assert is used to counter the false positive extra " \
311 "semi-colon warnings")
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition abstract_factory.hpp:47
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:354
This mixin provides a default implementation of a concrete factory.
Definition abstract_factory.hpp:126
Definition lin_op.hpp:117
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
The Updater class serves for convenient argument passing to the Criterion's check function.
Definition criterion.hpp:55
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:73
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:36
Updater update()
Returns the updater object.
Definition criterion.hpp:122
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:137
The Stopping criterion namespace.
Definition logger.hpp:50
AbstractFactory< Criterion, CriterionArgs > CriterionFactory
Declares an Abstract Factory specialized for Criterions.
Definition criterion.hpp:226
EnableDefaultFactory< ConcreteFactory, ConcreteCriterion, ParametersType, PolymorphicBase > EnableDefaultCriterionFactory
This is an alias for the EnableDefaultFactory mixin, which correctly sets the template parameters to ...
Definition criterion.hpp:246
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:119
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90