 |
Ginkgo
Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
|
5 #ifndef GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
6 #define GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
11 #include <ginkgo/core/base/array.hpp>
12 #include <ginkgo/core/base/math.hpp>
13 #include <ginkgo/core/base/types.hpp>
14 #include <ginkgo/core/base/utils.hpp>
15 #include <ginkgo/core/matrix/multivector.hpp>
16 #include <ginkgo/core/stop/criterion.hpp>
37 enum class mode { absolute, initial_resnorm, rhs_norm };
49 template <
typename ValueType>
51 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
56 using NormVector =
typename Vector::norm_type;
62 :
Criterion(exec), device_storage_{exec, 1}
67 absolute_type reduction_factor,
mode baseline);
70 std::unique_ptr<NormVector> starting_tau_{};
71 std::unique_ptr<NormVector> u_dense_tau_{};
76 mode baseline_{mode::rhs_norm};
77 std::shared_ptr<const LinOp> system_matrix_{};
78 std::shared_ptr<const AbstractMultiVector> b_{};
80 std::shared_ptr<const Vector> one_{};
81 std::shared_ptr<const Vector> neg_one_{};
85 std::unique_ptr<AbstractMultiVector> residual_{};
126 template <
typename ValueType = default_precision>
130 using NormVector =
typename Vector::norm_type;
138 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
142 this->reduction_factor = value;
156 explicit ResidualNorm(std::shared_ptr<const gko::Executor> exec)
163 factory->get_parameters().reduction_factor,
164 factory->get_parameters().baseline),
165 parameters_{factory->get_parameters()}
207 template <
typename ValueType = default_precision>
211 using NormVector =
typename Vector::norm_type;
219 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
223 this->reduction_factor = value;
252 factory->get_parameters().reduction_factor,
253 factory->get_parameters().baseline),
254 parameters_{factory->get_parameters()}
318 GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
340 template <
typename ValueType = default_precision>
341 class GKO_DEPRECATED(
342 "Please use the class
ResidualNorm with the factory parameter baseline =
"
343 "mode::initial_resnorm
") ResidualNormReduction
344 : public ResidualNormBase<ValueType> {
346 using Vector = matrix::MultiVector<ValueType>;
347 using NormVector = typename Vector::norm_type;
349 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
354 remove_complex<ValueType> reduction_factor{
355 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
357 parameters_type& with_reduction_factor(remove_complex<ValueType> value)
359 this->reduction_factor = value;
363 GKO_ENABLE_CRITERION_FACTORY(ResidualNormReduction<ValueType>, parameters,
365 GKO_ENABLE_BUILD_METHOD(Factory);
368 explicit ResidualNormReduction(std::shared_ptr<const gko::Executor> exec)
369 : ResidualNormBase<ValueType>(exec)
372 explicit ResidualNormReduction(const Factory* factory,
373 const CriterionArgs& args)
374 : ResidualNormBase<ValueType>(
375 factory->get_executor(), args,
376 factory->get_parameters().reduction_factor,
377 mode::initial_resnorm),
378 parameters_{factory->get_parameters()}
401 template <typename ValueType = default_precision>
402 class GKO_DEPRECATED(
403 "Please use the
class ResidualNorm with the factory parameter baseline =
"
404 "mode::rhs_norm
") RelativeResidualNorm
405 : public ResidualNormBase<ValueType> {
407 using Vector = matrix::MultiVector<ValueType>;
408 using NormVector = typename Vector::norm_type;
410 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
415 remove_complex<ValueType> tolerance{
416 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
419 parameters_type& with_tolerance(remove_complex<ValueType> value)
421 this->tolerance = value;
425 GKO_ENABLE_CRITERION_FACTORY(RelativeResidualNorm<ValueType>, parameters,
427 GKO_ENABLE_BUILD_METHOD(Factory);
430 explicit RelativeResidualNorm(std::shared_ptr<const gko::Executor> exec)
431 : ResidualNormBase<ValueType>(exec)
434 explicit RelativeResidualNorm(const Factory* factory,
435 const CriterionArgs& args)
436 : ResidualNormBase<ValueType>(factory->get_executor(), args,
437 factory->get_parameters().tolerance,
439 parameters_{factory->get_parameters()}
461 template <typename ValueType = default_precision>
462 class GKO_DEPRECATED(
463 "Please use the
class ResidualNorm with the factory parameter baseline =
"
464 "mode::absolute
") AbsoluteResidualNorm
465 : public ResidualNormBase<ValueType> {
467 using Vector = matrix::MultiVector<ValueType>;
468 using NormVector = typename Vector::norm_type;
470 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
475 remove_complex<ValueType> tolerance{
476 5 * std ::numeric_limits<remove_complex<ValueType>>::epsilon()};
478 parameters_type& with_tolerance(remove_complex<ValueType> value)
480 this->tolerance = value;
484 GKO_ENABLE_CRITERION_FACTORY(AbsoluteResidualNorm<ValueType>, parameters,
486 GKO_ENABLE_BUILD_METHOD(Factory);
489 explicit AbsoluteResidualNorm(std::shared_ptr<const gko::Executor> exec)
490 : ResidualNormBase<ValueType>(exec)
493 explicit AbsoluteResidualNorm(const Factory* factory,
494 const CriterionArgs& args)
495 : ResidualNormBase<ValueType>(factory->get_executor(), args,
496 factory->get_parameters().tolerance,
498 parameters_{factory->get_parameters()}
503 GKO_END_DISABLE_DEPRECATION_WARNINGS
510 #endif // GKO_PUBLIC_CORE_STOP_RESIDUAL_NORM_HPP_
This struct is used to pass parameters to the EnableDefaultCriterionFactoryCriterionFactory::generate...
Definition: criterion.hpp:211
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:131
deferred_factory_parameter< CriterionFactory > initial_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
deferred_factory_parameter< CriterionFactory > absolute_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
deferred_factory_parameter< CriterionFactory > absolute_implicit_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
deferred_factory_parameter< CriterionFactory > relative_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:469
The result of a stopping criterion check over all vectors.
Definition: stopping_status.hpp:161
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition: array.hpp:26
Stopping criterion based on the explicit residual norm .
Definition: residual_norm.hpp:127
Definition: residual_norm.hpp:234
deferred_factory_parameter< CriterionFactory > initial_implicit_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:36
mode
The mode for the residual norm criterion.
Definition: residual_norm.hpp:37
Definition: residual_norm.hpp:152
MultiVector is a multivector format which explicitly stores all values of the vector.
Definition: dense_cache.hpp:28
The Updater class serves for convenient argument passing to the Criterion's check function.
Definition: criterion.hpp:59
Definition: residual_norm.hpp:132
Definition: residual_norm.hpp:213
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition: abstract_factory.hpp:418
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
This Macro will generate a new type containing the parameters for the factory _factory_name.
Definition: abstract_factory.hpp:304
Stopping criterion based on a solver-maintained squared residual-norm estimate .
Definition: residual_norm.hpp:208
The ResidualNormBase class provides a framework for stopping criteria related to the residual norm.
Definition: residual_norm.hpp:50
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:69
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition: math.hpp:263
deferred_factory_parameter< CriterionFactory > relative_implicit_residual_norm(double tolerance)
Creates the precursor to a ResidualNorm stopping criterion factory, to be used in conjunction with ....