33 #ifndef GKO_CORE_STOP_CRITERION_HPP_ 34 #define GKO_CORE_STOP_CRITERION_HPP_ 37 #include <ginkgo/core/base/abstract_factory.hpp> 38 #include <ginkgo/core/base/array.hpp> 39 #include <ginkgo/core/base/lin_op.hpp> 40 #include <ginkgo/core/base/polymorphic_object.hpp> 41 #include <ginkgo/core/base/utils.hpp> 42 #include <ginkgo/core/log/logger.hpp> 43 #include <ginkgo/core/stop/stopping_status.hpp> 100 auto converged = parent_->
check(stoppingId, setFinalized,
101 stop_status, one_changed, *
this);
108 #define GKO_UPDATER_REGISTER_PARAMETER(_type, _name) \ 109 const Updater &_name(_type const &value) const \ 114 mutable _type _name##_ {} 116 GKO_UPDATER_REGISTER_PARAMETER(
size_type, num_iterations);
117 GKO_UPDATER_REGISTER_PARAMETER(
const LinOp *, residual);
118 GKO_UPDATER_REGISTER_PARAMETER(
const LinOp *, residual_norm);
119 GKO_UPDATER_REGISTER_PARAMETER(
const LinOp *, solution);
121 #undef GKO_UPDATER_REGISTER_PARAMETER 153 this->
template log<log::Logger::criterion_check_started>(
154 this, updater.num_iterations_, updater.residual_,
155 updater.residual_norm_, updater.solution_, stoppingId,
157 auto all_converged = this->check_impl(
158 stoppingId, setFinalized, stop_status, one_changed, updater);
159 this->
template log<log::Logger::criterion_check_completed>(
160 this, updater.num_iterations_, updater.residual_,
161 updater.residual_norm_, updater.solution_, stoppingId, setFinalized,
162 stop_status, *one_changed, all_converged);
163 return all_converged;
183 virtual bool check_impl(
uint8 stoppingId,
bool setFinalized,
185 bool *one_changed,
const Updater &updater) = 0;
197 void set_all_statuses(
uint8 stoppingId,
bool setFinalized,
200 explicit Criterion(std::shared_ptr<const gko::Executor> exec)
217 std::shared_ptr<const LinOp> system_matrix;
218 std::shared_ptr<const LinOp> b;
220 const LinOp *initial_residual;
224 std::shared_ptr<const LinOp> b,
const LinOp *x,
225 const LinOp *initial_residual =
nullptr)
226 : system_matrix{system_matrix},
229 initial_residual{initial_residual}
255 template <
typename ConcreteFactory,
typename ConcreteCriterion,
280 #define GKO_ENABLE_CRITERION_FACTORY(_criterion, _parameters_name, \ 283 const _parameters_name##_type &get_##_parameters_name() const \ 285 return _parameters_name##_; \ 288 class _factory_name \ 289 : public ::gko::stop::EnableDefaultCriterionFactory< \ 290 _factory_name, _criterion, _parameters_name##_type> { \ 291 friend class ::gko::EnablePolymorphicObject< \ 292 _factory_name, ::gko::stop::CriterionFactory>; \ 293 friend class ::gko::enable_parameters_type<_parameters_name##_type, \ 295 using ::gko::stop::EnableDefaultCriterionFactory< \ 296 _factory_name, _criterion, \ 297 _parameters_name##_type>::EnableDefaultCriterionFactory; \ 299 friend ::gko::stop::EnableDefaultCriterionFactory< \ 300 _factory_name, _criterion, _parameters_name##_type>; \ 303 _parameters_name##_type _parameters_name##_; \ 306 static_assert(true, \ 307 "This assert is used to counter the false positive extra " \ 308 "semi-colon warnings") 315 #endif // GKO_CORE_STOP_CRITERION_HPP_ This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:285
bool check(uint8 stoppingId, bool setFinalized, Array< stopping_status > *stop_status, bool *one_changed) const
Calls the parent Criterion object's check method.
Definition: criterion.hpp:97
bool check(uint8 stoppingId, bool setFinalized, Array< stopping_status > *stop_status, bool *one_changed, const Updater &updater)
This checks whether convergence was reached for a certain criterion.
Definition: criterion.hpp:149
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
Updater(const Updater &)=delete
Prevent copying and moving the object This is to enforce the use of argument passing and calling chec...
This mixin provides a default implementation of a concrete factory.
Definition: abstract_factory.hpp:148
Definition: lin_op.hpp:134
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:123
The Updater class serves for convenient argument passing to the Criterion's check function...
Definition: criterion.hpp:79
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition: abstract_factory.hpp:70
An Array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the Arr...
Definition: array.hpp:63
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:63
Updater update()
Returns the updater object.
Definition: criterion.hpp:134
This struct is used to pass parameters to the EnableDefaultCriterionFactoryCriterionFactory::generate...
Definition: criterion.hpp:216