ginkgo/core/solver/bicgstab.hpp Source File

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

Reference API: ginkgo/core/solver/bicgstab.hpp Source File
Reference API
bicgstab.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_SOLVER_BICGSTAB_HPP_
6#define GKO_PUBLIC_CORE_SOLVER_BICGSTAB_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 {
32namespace solver {
33
34
48template <typename ValueType = default_precision>
50 : public EnableLinOp<Bicgstab<ValueType>>,
52 Bicgstab<ValueType>>,
53 public Transposable {
54 friend class EnableLinOp<Bicgstab>;
56
57public:
58 using value_type = ValueType;
60
61 std::unique_ptr<LinOp> transpose() const override;
62
63 std::unique_ptr<LinOp> conj_transpose() const override;
64
70 bool apply_uses_initial_guess() const override { return true; }
71
72 class Factory;
76
79
93 static parameters_type parse(const config::pnode& config,
94 const config::registry& context,
95 const config::type_descriptor& td_for_child =
96 config::make_type_descriptor<ValueType>());
97
98protected:
99 void apply_impl(const LinOp* b, LinOp* x) const override;
100
101 template <typename VectorType>
102 void apply_dense_impl(const VectorType* b, VectorType* x) const;
103
104 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
105 LinOp* x) const override;
106
107 explicit Bicgstab(std::shared_ptr<const Executor> exec)
108 : EnableLinOp<Bicgstab>(std::move(exec))
109 {}
110
111 explicit Bicgstab(const Factory* factory,
112 std::shared_ptr<const LinOp> system_matrix)
113 : EnableLinOp<Bicgstab>(factory->get_executor(),
114 gko::transpose(system_matrix->get_size())),
115 EnablePreconditionedIterativeSolver<ValueType, Bicgstab<ValueType>>{
116 std::move(system_matrix), factory->get_parameters()},
117 parameters_{factory->get_parameters()}
118 {}
119};
120
121
122template <typename ValueType>
123struct workspace_traits<Bicgstab<ValueType>> {
125 // number of vectors used by this workspace
126 static int num_vectors(const Solver&);
127 // number of arrays used by this workspace
128 static int num_arrays(const Solver&);
129 // array containing the num_vectors names for the workspace vectors
130 static std::vector<std::string> op_names(const Solver&);
131 // array containing the num_arrays names for the workspace vectors
132 static std::vector<std::string> array_names(const Solver&);
133 // array containing all varying scalar vectors (independent of problem size)
134 static std::vector<int> scalars(const Solver&);
135 // array containing all varying vectors (dependent on problem size)
136 static std::vector<int> vectors(const Solver&);
137
138 // residual vector
139 constexpr static int r = 0;
140 // preconditioned residual vector
141 constexpr static int z = 1;
142 // y vector
143 constexpr static int y = 2;
144 // v vector
145 constexpr static int v = 3;
146 // s vector
147 constexpr static int s = 4;
148 // t vector
149 constexpr static int t = 5;
150 // p vector
151 constexpr static int p = 6;
152 // rr vector
153 constexpr static int rr = 7;
154 // alpha scalar
155 constexpr static int alpha = 8;
156 // beta scalar
157 constexpr static int beta = 9;
158 // gamma scalar
159 constexpr static int gamma = 10;
160 // previous rho scalar
161 constexpr static int prev_rho = 11;
162 // current rho scalar
163 constexpr static int rho = 12;
164 // omega scalar
165 constexpr static int omega = 13;
166 // constant 1.0 scalar
167 constexpr static int one = 14;
168 // constant -1.0 scalar
169 constexpr static int minus_one = 15;
170
171 // stopping status array
172 constexpr static int stop = 0;
173 // reduction tmp array
174 constexpr static int tmp = 1;
175};
176
177
178} // namespace solver
179} // namespace gko
180
181
182#endif // GKO_PUBLIC_CORE_SOLVER_BICGSTAB_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 bicgstab.hpp:77
Definition bicgstab.hpp:53
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
bool apply_uses_initial_guess() const override
Definition bicgstab.hpp:70
#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 bicgstab.hpp:75
Definition solver_base.hpp:238