Ginkgo Generated from develop branch based on develop. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
idr.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
6#define GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
7
8
9#include <random>
10#include <typeinfo>
11#include <vector>
12
13
14#include <ginkgo/core/base/array.hpp>
15#include <ginkgo/core/base/exception_helpers.hpp>
16#include <ginkgo/core/base/lin_op.hpp>
17#include <ginkgo/core/base/math.hpp>
18#include <ginkgo/core/base/types.hpp>
19#include <ginkgo/core/log/logger.hpp>
20#include <ginkgo/core/matrix/dense.hpp>
21#include <ginkgo/core/matrix/identity.hpp>
22#include <ginkgo/core/solver/solver_base.hpp>
23#include <ginkgo/core/stop/combined.hpp>
24#include <ginkgo/core/stop/criterion.hpp>
25
26
27namespace gko {
33namespace solver {
34
35
54template <typename ValueType = default_precision>
55class Idr
56 : public EnableLinOp<Idr<ValueType>>,
57 public EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>,
58 public Transposable {
59 friend class EnableLinOp<Idr>;
60 friend class EnablePolymorphicObject<Idr, LinOp>;
61
62public:
63 using value_type = ValueType;
65
66 std::unique_ptr<LinOp> transpose() const override;
67
68 std::unique_ptr<LinOp> conj_transpose() const override;
69
75 bool apply_uses_initial_guess() const override { return true; }
76
81 size_type get_subspace_dim() const { return parameters_.subspace_dim; }
82
88 {
89 parameters_.subspace_dim = other;
90 }
91
97 remove_complex<ValueType> get_kappa() const { return parameters_.kappa; }
98
105 {
106 parameters_.kappa = other;
107 }
108
114 bool get_deterministic() const { return parameters_.deterministic; }
115
121 void set_deterministic(const bool other)
122 {
123 parameters_.deterministic = other;
124 }
125
131 bool get_complex_subspace() const { return parameters_.complex_subspace; }
132
139 GKO_DEPRECATED("Use set_complex_subspace instead")
141 {
142 this->set_complex_subspace(other);
143 }
144
151 {
152 parameters_.complex_subspace = other;
153 }
154
155 class Factory;
156
196
197protected:
198 void apply_impl(const LinOp* b, LinOp* x) const override;
199
200 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
201 LinOp* x) const override;
202
203 template <typename VectorType>
204 void iterate(const VectorType* dense_b, VectorType* dense_x) const;
205
206 explicit Idr(std::shared_ptr<const Executor> exec)
207 : EnableLinOp<Idr>(std::move(exec))
208 {}
209
210 explicit Idr(const Factory* factory,
211 std::shared_ptr<const LinOp> system_matrix)
212 : EnableLinOp<Idr>(factory->get_executor(),
213 gko::transpose(system_matrix->get_size())),
214 EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>{
215 std::move(system_matrix), factory->get_parameters()},
216 parameters_{factory->get_parameters()}
217 {}
218};
219
220
221template <typename ValueType>
222struct workspace_traits<Idr<ValueType>> {
223 using Solver = Idr<ValueType>;
224 // number of vectors used by this workspace
225 static int num_vectors(const Solver&);
226 // number of arrays used by this workspace
227 static int num_arrays(const Solver&);
228 // array containing the num_vectors names for the workspace vectors
229 static std::vector<std::string> op_names(const Solver&);
230 // array containing the num_arrays names for the workspace vectors
231 static std::vector<std::string> array_names(const Solver&);
232 // array containing all varying scalar vectors (independent of problem size)
233 static std::vector<int> scalars(const Solver&);
234 // array containing all varying vectors (dependent on problem size)
235 static std::vector<int> vectors(const Solver&);
236
237 // residual vector
238 constexpr static int residual = 0;
239 // v vector
240 constexpr static int v = 1;
241 // t vector
242 constexpr static int t = 2;
243 // helper vector
244 constexpr static int helper = 3;
245 // m multivector
246 constexpr static int m = 4;
247 // g multivector
248 constexpr static int g = 5;
249 // u multivector
250 constexpr static int u = 6;
251 // subspace multivector
252 constexpr static int subspace = 7;
253 // f "multiscalar"
254 constexpr static int f = 8;
255 // c "multiscalar"
256 constexpr static int c = 9;
257 // omega scalar
258 constexpr static int omega = 10;
259 // residual norm scalar
260 constexpr static int residual_norm = 11;
261 // T^H*T scalar
262 constexpr static int tht = 12;
263 // alpha "multiscalar"
264 constexpr static int alpha = 13;
265 // constant 1.0 scalar
266 constexpr static int one = 14;
267 // constant -1.0 scalar
268 constexpr static int minus_one = 15;
269 // constant -1.0 scalar
270 constexpr static int subspace_minus_one = 16;
271
272 // stopping status array
273 constexpr static int stop = 0;
274 // reduction tmp array
275 constexpr static int tmp = 1;
276};
277
278
279} // namespace solver
280} // namespace gko
281
282
283#endif // GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:880
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:663
Definition lin_op.hpp:118
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:235
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:434
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition solver_base.hpp:788
Definition idr.hpp:194
IDR(s) is an efficient method for solving large nonsymmetric systems of linear equations.
Definition idr.hpp:58
void set_kappa(const remove_complex< ValueType > other)
Sets the kappa parameter of the solver.
Definition idr.hpp:104
void set_complex_subpsace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition idr.hpp:140
void set_subspace_dim(const size_type other)
Sets the subspace dimension of the solver.
Definition idr.hpp:87
void set_deterministic(const bool other)
Sets the deterministic parameter of the solver.
Definition idr.hpp:121
bool apply_uses_initial_guess() const override
Return true as iterative solvers use the data in x as an initial guess.
Definition idr.hpp:75
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
void set_complex_subspace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition idr.hpp:150
bool get_complex_subspace() const
Gets the complex_subspace parameter of the solver.
Definition idr.hpp:131
size_type get_subspace_dim() const
Gets the subspace dimension of the solver.
Definition idr.hpp:81
bool get_deterministic() const
Gets the deterministic parameter of the solver.
Definition idr.hpp:114
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
remove_complex< ValueType > get_kappa() const
Gets the kappa parameter of the solver.
Definition idr.hpp:97
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:445
#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:394
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a LinOpFactory for the LinOp subclass it is defi...
Definition lin_op.hpp:1018
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:775
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:326
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:92
Definition idr.hpp:159
bool complex_subspace
If set to true, IDR will use a complex subspace S also for real problems, allowing for faster converg...
Definition idr.hpp:192
remove_complex< ValueType > kappa
Threshold to determine if Av_n and v_n are too close to being perpendicular.
Definition idr.hpp:172
bool deterministic
If set to true, the vectors spanning the subspace S are chosen deterministically.
Definition idr.hpp:183
size_type subspace_dim
Dimension of the subspace S.
Definition idr.hpp:164
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition solver_base.hpp:239