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>
80 auto converged = parent_->
check(stopping_id, set_finalized,
81 stop_status, one_changed, *
this);
88 #define GKO_UPDATER_REGISTER_PARAMETER(_type, _name) \
89 const Updater& _name(_type const& value) const \
94 mutable _type _name##_ {}
95 #define GKO_UPDATER_REGISTER_PTR_PARAMETER(_type, _name) \
96 const Updater& _name(ptr_param<_type> value) const \
98 _name##_ = value.get(); \
101 mutable _type* _name##_ {}
103 GKO_UPDATER_REGISTER_PARAMETER(
size_type, num_iterations);
105 GKO_UPDATER_REGISTER_PARAMETER(
bool, ignore_residual_check);
106 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, residual);
107 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, residual_norm);
108 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp,
109 implicit_sq_residual_norm);
110 GKO_UPDATER_REGISTER_PTR_PARAMETER(
const LinOp, solution);
112 #undef GKO_UPDATER_REGISTER_PTR_PARAMETER
113 #undef GKO_UPDATER_REGISTER_PARAMETER
145 this->
template log<log::Logger::criterion_check_started>(
146 this, updater.num_iterations_, updater.residual_,
147 updater.residual_norm_, updater.solution_, stopping_id,
149 auto all_converged = this->check_impl(
150 stopping_id, set_finalized, stop_status, one_changed, updater);
151 this->
template log<log::Logger::criterion_check_completed>(
152 this, updater.num_iterations_, updater.residual_,
153 updater.residual_norm_, updater.implicit_sq_residual_norm_,
154 updater.solution_, stopping_id, set_finalized, stop_status,
155 *one_changed, all_converged);
156 return all_converged;
176 virtual bool check_impl(
uint8 stopping_id,
bool set_finalized,
178 bool* one_changed,
const Updater& updater) = 0;
190 void set_all_statuses(
uint8 stopping_id,
bool set_finalized,
193 explicit Criterion(std::shared_ptr<const gko::Executor> exec)
210 std::shared_ptr<const LinOp> system_matrix;
211 std::shared_ptr<const LinOp> b;
213 const LinOp* initial_residual;
217 std::shared_ptr<const LinOp> b,
const LinOp* x,
218 const LinOp* initial_residual =
nullptr)
219 : system_matrix{system_matrix},
222 initial_residual{initial_residual}
248 template <
typename ConcreteFactory,
typename ConcreteCriterion,
279 #define GKO_ENABLE_CRITERION_FACTORY(_criterion, _parameters_name, \
282 const _parameters_name##_type& get_##_parameters_name() const \
284 return _parameters_name##_; \
287 class _factory_name \
288 : public ::gko::stop::EnableDefaultCriterionFactory< \
289 _factory_name, _criterion, _parameters_name##_type> { \
290 friend class ::gko::enable_parameters_type<_parameters_name##_type, \
292 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec) \
293 : ::gko::stop::EnableDefaultCriterionFactory< \
294 _factory_name, _criterion, _parameters_name##_type>( \
297 explicit _factory_name(std::shared_ptr<const ::gko::Executor> exec, \
298 const _parameters_name##_type& parameters) \
299 : ::gko::stop::EnableDefaultCriterionFactory< \
300 _factory_name, _criterion, _parameters_name##_type>( \
301 std::move(exec), parameters) \
304 friend ::gko::stop::EnableDefaultCriterionFactory< \
305 _factory_name, _criterion, _parameters_name##_type>; \
308 _parameters_name##_type _parameters_name##_; \
311 static_assert(true, \
312 "This assert is used to counter the false positive extra " \
313 "semi-colon warnings")
320 #endif // GKO_PUBLIC_CORE_STOP_CRITERION_HPP_