Ginkgo: ginkgo/core/log/convergence.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
convergence.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_LOG_CONVERGENCE_HPP_
6#define GKO_PUBLIC_CORE_LOG_CONVERGENCE_HPP_
7
8
9#include <memory>
10
11#include <ginkgo/core/log/logger.hpp>
12#include <ginkgo/core/matrix/dense.hpp>
13#include <ginkgo/core/stop/criterion.hpp>
14
15
16namespace gko {
22 namespace log {
23
24
36template <typename ValueType = default_precision>
37 class Convergence : public Logger {
38 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
39
40public:
41 void on_criterion_check_completed(
42 const stop::Criterion* criterion, const size_type& num_iterations,
43 const LinOp* residual, const LinOp* residual_norm,
44 const LinOp* solution, const uint8& stopping_id,
45 const bool& set_finalized, const array<stopping_status>* status,
46 const bool& one_changed, const bool& all_stopped) const override;
47
48 void on_criterion_check_completed(
49 const stop::Criterion* criterion, const size_type& num_iterations,
50 const LinOp* residual, const LinOp* residual_norm,
51 const LinOp* implicit_sq_resnorm, const LinOp* solution,
52 const uint8& stopping_id, const bool& set_finalized,
53 const array<stopping_status>* status, const bool& one_changed,
54 const bool& all_stopped) const override;
55
56 void on_iteration_complete(const LinOp* solver, const LinOp* b,
57 const LinOp* x, const size_type& num_iterations,
58 const LinOp* residual,
59 const LinOp* residual_norm,
60 const LinOp* implicit_resnorm_sq,
61 const array<stopping_status>* status,
62 bool stopped) const override;
63
74 GKO_DEPRECATED("use single-parameter create")
75 static std::unique_ptr<Convergence> create(
76 std::shared_ptr<const Executor>,
77 const mask_type& enabled_events = Logger::criterion_events_mask |
78 Logger::iteration_complete_mask)
79 {
80 return std::unique_ptr<Convergence>(new Convergence(enabled_events));
81 }
82
92 static std::unique_ptr<Convergence> create(
93 const mask_type& enabled_events = Logger::criterion_events_mask |
94 Logger::iteration_complete_mask)
95 {
96 return std::unique_ptr<Convergence>(new Convergence(enabled_events));
97 }
98
104 bool has_converged() const noexcept { return convergence_status_; }
105
109 void reset_convergence_status() { this->convergence_status_ = false; }
110
116 const size_type& get_num_iterations() const noexcept
117 {
118 return num_iterations_;
119 }
120
126 const LinOp* get_residual() const noexcept { return residual_.get(); }
127
133 const LinOp* get_residual_norm() const noexcept
134 {
135 return residual_norm_.get();
136 }
137
143 const LinOp* get_implicit_sq_resnorm() const noexcept
144 {
145 return implicit_sq_resnorm_.get();
146 }
147
148protected:
156 GKO_DEPRECATED("use single-parameter constructor")
157 explicit Convergence(
158 std::shared_ptr<const gko::Executor>,
159 const mask_type& enabled_events = Logger::criterion_events_mask |
160 Logger::iteration_complete_mask)
161 : Logger(enabled_events)
162 {}
163
170 explicit Convergence(
171 const mask_type& enabled_events = Logger::criterion_events_mask |
172 Logger::iteration_complete_mask)
173 : Logger(enabled_events)
174 {}
175
176private:
177 mutable bool convergence_status_{false};
178 mutable size_type num_iterations_{};
179 mutable std::unique_ptr<LinOp> residual_{};
180 mutable std::unique_ptr<LinOp> residual_norm_{};
181 mutable std::unique_ptr<LinOp> implicit_sq_resnorm_{};
182};
183
184
185} // namespace log
186} // namespace gko
187
188
189#endif // GKO_PUBLIC_CORE_LOG_CONVERGENCE_HPP_
gko::Executor
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:615
gko::LinOp
Definition lin_op.hpp:117
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
gko::log::Convergence
Convergence is a Logger which logs data strictly from the criterion_check_completed event.
Definition convergence.hpp:37
gko::log::Convergence::has_converged
bool has_converged() const noexcept
Returns true if the solver has converged.
Definition convergence.hpp:104
gko::log::Convergence::create
static std::unique_ptr< Convergence > create(const mask_type &enabled_events=Logger::criterion_events_mask|Logger::iteration_complete_mask)
Creates a convergence logger.
Definition convergence.hpp:92
gko::log::Convergence::get_num_iterations
const size_type & get_num_iterations() const noexcept
Returns the number of iterations.
Definition convergence.hpp:116
gko::log::Convergence::on_criterion_check_completed
void on_criterion_check_completed(const stop::Criterion *criterion, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *implicit_sq_resnorm, const LinOp *solution, const uint8 &stopping_id, const bool &set_finalized, const array< stopping_status > *status, const bool &one_changed, const bool &all_stopped) const override
stop::Criterion's check completed event.
gko::log::Convergence::on_criterion_check_completed
void on_criterion_check_completed(const stop::Criterion *criterion, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *solution, const uint8 &stopping_id, const bool &set_finalized, const array< stopping_status > *status, const bool &one_changed, const bool &all_stopped) const override
stop::Criterion's check completed event.
gko::log::Convergence::get_residual
const LinOp * get_residual() const noexcept
Returns the residual.
Definition convergence.hpp:126
gko::log::Convergence::get_residual_norm
const LinOp * get_residual_norm() const noexcept
Returns the residual norm.
Definition convergence.hpp:133
gko::log::Convergence::on_iteration_complete
void on_iteration_complete(const LinOp *solver, const LinOp *b, const LinOp *x, const size_type &num_iterations, const LinOp *residual, const LinOp *residual_norm, const LinOp *implicit_resnorm_sq, const array< stopping_status > *status, bool stopped) const override
Register the iteration_complete event which logs every completed iterations.
gko::log::Convergence::create
static std::unique_ptr< Convergence > create(std::shared_ptr< const Executor >, const mask_type &enabled_events=Logger::criterion_events_mask|Logger::iteration_complete_mask)
Creates a convergence logger.
Definition convergence.hpp:75
gko::log::Convergence::reset_convergence_status
void reset_convergence_status()
Resets the convergence status to false.
Definition convergence.hpp:109
gko::log::Convergence::get_implicit_sq_resnorm
const LinOp * get_implicit_sq_resnorm() const noexcept
Returns the implicit squared residual norm.
Definition convergence.hpp:143
gko::log::Logger
Definition logger.hpp:74
gko::log::Logger::criterion_events_mask
static constexpr mask_type criterion_events_mask
Bitset Mask which activates all criterion events.
Definition logger.hpp:673
gko::stop::Criterion
The Criterion class is a base class for all stopping criteria.
Definition criterion.hpp:36
gko::log
The logger namespace .
Definition convergence.hpp:22
gko::log::profile_event_category::criterion
@ criterion
Stopping criterion events.
Definition profiler_hook.hpp:36
gko::solver
The ginkgo Solve namespace.
Definition bicg.hpp:28
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:119
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
std
STL namespace.