ginkgo/core/solver/cgs.hpp Source File

ginkgo/core/solver/cgs.hpp Source File#

Reference API: ginkgo/core/solver/cgs.hpp Source File
Reference API
cgs.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_SOLVER_CGS_HPP_
6#define GKO_PUBLIC_CORE_SOLVER_CGS_HPP_
7
8
9#include <vector>
10
11#include <ginkgo/core/base/array.hpp>
12#include <ginkgo/core/base/exception_helpers.hpp>
13#include <ginkgo/core/base/lin_op.hpp>
14#include <ginkgo/core/base/math.hpp>
15#include <ginkgo/core/base/types.hpp>
16#include <ginkgo/core/config/config.hpp>
17#include <ginkgo/core/config/registry.hpp>
18#include <ginkgo/core/log/logger.hpp>
19#include <ginkgo/core/matrix/dense.hpp>
20#include <ginkgo/core/matrix/identity.hpp>
21#include <ginkgo/core/solver/solver_base.hpp>
22#include <ginkgo/core/stop/combined.hpp>
23#include <ginkgo/core/stop/criterion.hpp>
24
25
26namespace gko {
27namespace solver {
28
29
42template <typename ValueType = default_precision>
43class Cgs
44 : public EnableLinOp<Cgs<ValueType>>,
45 public EnablePreconditionedIterativeSolver<ValueType, Cgs<ValueType>>,
46 public Transposable {
47 friend class EnableLinOp<Cgs>;
48 friend class EnablePolymorphicObject<Cgs, LinOp>;
49
50public:
51 using value_type = ValueType;
53
54 std::unique_ptr<LinOp> transpose() const override;
55
56 std::unique_ptr<LinOp> conj_transpose() const override;
57
63 bool apply_uses_initial_guess() const override { return true; }
64
65 class Factory;
66
70
73
87 static parameters_type parse(const config::pnode& config,
88 const config::registry& context,
89 const config::type_descriptor& td_for_child =
90 config::make_type_descriptor<ValueType>());
91
92protected:
93 void apply_impl(const LinOp* b, LinOp* x) const override;
94
95 template <typename VectorType>
96 void apply_dense_impl(const VectorType* b, VectorType* x) const;
97
98 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
99 LinOp* x) const override;
100
101 explicit Cgs(std::shared_ptr<const Executor> exec)
102 : EnableLinOp<Cgs>(std::move(exec))
103 {}
104
105 explicit Cgs(const Factory* factory,
106 std::shared_ptr<const LinOp> system_matrix)
107 : EnableLinOp<Cgs>(factory->get_executor(),
108 gko::transpose(system_matrix->get_size())),
109 EnablePreconditionedIterativeSolver<ValueType, Cgs<ValueType>>{
110 std::move(system_matrix), factory->get_parameters()},
111 parameters_{factory->get_parameters()}
112 {}
113};
114
115
116template <typename ValueType>
117struct workspace_traits<Cgs<ValueType>> {
118 using Solver = Cgs<ValueType>;
119 // number of vectors used by this workspace
120 static int num_vectors(const Solver&);
121 // number of arrays used by this workspace
122 static int num_arrays(const Solver&);
123 // array containing the num_vectors names for the workspace vectors
124 static std::vector<std::string> op_names(const Solver&);
125 // array containing the num_arrays names for the workspace vectors
126 static std::vector<std::string> array_names(const Solver&);
127 // array containing all varying scalar vectors (independent of problem size)
128 static std::vector<int> scalars(const Solver&);
129 // array containing all varying vectors (dependent on problem size)
130 static std::vector<int> vectors(const Solver&);
131
132 // residual vector
133 constexpr static int r = 0;
134 // r tilde vector
135 constexpr static int r_tld = 1;
136 // p vector
137 constexpr static int p = 2;
138 // q vector
139 constexpr static int q = 3;
140 // u vector
141 constexpr static int u = 4;
142 // u hat vector
143 constexpr static int u_hat = 5;
144 // v hat vector
145 constexpr static int v_hat = 6;
146 // t vector
147 constexpr static int t = 7;
148 // alpha scalar
149 constexpr static int alpha = 8;
150 // beta scalar
151 constexpr static int beta = 9;
152 // beta scalar
153 constexpr static int gamma = 10;
154 // previous rho scalar
155 constexpr static int prev_rho = 11;
156 // current rho scalar
157 constexpr static int rho = 12;
158 // constant 1.0 scalar
159 constexpr static int one = 13;
160 // constant -1.0 scalar
161 constexpr static int minus_one = 14;
162
163 // stopping status array
164 constexpr static int stop = 0;
165 // reduction tmp array
166 constexpr static int tmp = 1;
167};
168
169
170} // namespace solver
171} // namespace gko
172
173
174#endif // GKO_PUBLIC_CORE_SOLVER_CGS_HPP_
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
std::shared_ptr< const Executor > get_executor() const noexcept
Definition polymorphic_object.hpp:243
Definition lin_op.hpp:433
Definition property_tree.hpp:28
Definition registry.hpp:167
Definition type_descriptor.hpp:39
Definition cgs.hpp:71
Definition cgs.hpp:46
bool apply_uses_initial_guess() const override
Definition cgs.hpp:63
std::unique_ptr< LinOp > conj_transpose() const override
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType >())
std::unique_ptr< LinOp > transpose() const override
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Definition abstract_factory.hpp:394
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
Definition lin_op.hpp:1016
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Definition math.hpp:630
STL namespace.
Definition solver_base.hpp:238