Ginkgo  Generated from tags/v1.0.0^0 branch based on master. Ginkgo version 1.0.0
A numerical linear algebra library targeting many-core architectures
convergence.hpp
1 /*******************************<GINKGO LICENSE>******************************
2 Copyright (c) 2017-2019, the Ginkgo authors
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************<GINKGO LICENSE>*******************************/
32 
33 #ifndef GKO_CORE_LOG_CONVERGENCE_HPP_
34 #define GKO_CORE_LOG_CONVERGENCE_HPP_
35 
36 
37 #include <ginkgo/core/log/logger.hpp>
38 
39 
40 #include <memory>
41 
42 
43 #include <ginkgo/core/matrix/dense.hpp>
44 #include <ginkgo/core/stop/criterion.hpp>
45 
46 
47 namespace gko {
53 namespace log {
54 
55 
67 template <typename ValueType = default_precision>
68 class Convergence : public Logger {
69 public:
71  const stop::Criterion *criterion, const size_type &num_iterations,
72  const LinOp *residual, const LinOp *residual_norm,
73  const LinOp *solution, const uint8 &stopping_id,
74  const bool &set_finalized, const Array<stopping_status> *status,
75  const bool &one_changed, const bool &all_converged) const override;
76 
91  static std::unique_ptr<Convergence> create(
92  std::shared_ptr<const Executor> exec,
93  const mask_type &enabled_events = Logger::all_events_mask)
94  {
95  return std::unique_ptr<Convergence>(
96  new Convergence(exec, enabled_events));
97  }
98 
104  const size_type &get_num_iterations() const noexcept
105  {
106  return num_iterations_;
107  }
108 
114  const LinOp *get_residual() const noexcept { return residual_.get(); }
115 
121  const LinOp *get_residual_norm() const noexcept
122  {
123  return residual_norm_.get();
124  }
125 
126 protected:
134  explicit Convergence(
135  std::shared_ptr<const gko::Executor> exec,
136  const mask_type &enabled_events = Logger::all_events_mask)
137  : Logger(exec, enabled_events)
138  {}
139 
140 private:
141  mutable size_type num_iterations_{};
142  mutable std::unique_ptr<LinOp> residual_{};
143  mutable std::unique_ptr<LinOp> residual_norm_{};
144 };
145 
146 
147 } // namespace log
148 } // namespace gko
149 
150 
151 #endif // GKO_CORE_LOG_CONVERGENCE_HPP_
Definition: logger.hpp:90
const LinOp * get_residual_norm() const noexcept
Returns the residual norm.
Definition: convergence.hpp:121
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
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_converged) const override
stop::Criterion&#39;s check completed event.
Definition: lin_op.hpp:134
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:123
const size_type & get_num_iterations() const noexcept
Returns the number of iterations.
Definition: convergence.hpp:104
An Array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the Arr...
Definition: array.hpp:63
static constexpr mask_type all_events_mask
Bitset Mask which activates all events.
Definition: logger.hpp:103
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:63
static std::unique_ptr< Convergence > create(std::shared_ptr< const Executor > exec, const mask_type &enabled_events=Logger::all_events_mask)
Creates a convergence logger.
Definition: convergence.hpp:91
const LinOp * get_residual() const noexcept
Returns the residual.
Definition: convergence.hpp:114
Convergence is a Logger which logs data strictly from the criterion_check_completed event...
Definition: convergence.hpp:68