Ginkgo Generated from branch based on main. Ginkgo version 1.9.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#include <ginkgo/core/base/array.hpp>
14#include <ginkgo/core/base/exception_helpers.hpp>
15#include <ginkgo/core/base/lin_op.hpp>
16#include <ginkgo/core/base/math.hpp>
17#include <ginkgo/core/base/types.hpp>
18#include <ginkgo/core/config/config.hpp>
19#include <ginkgo/core/config/registry.hpp>
20#include <ginkgo/core/log/logger.hpp>
21#include <ginkgo/core/matrix/dense.hpp>
22#include <ginkgo/core/matrix/identity.hpp>
23#include <ginkgo/core/solver/solver_base.hpp>
24#include <ginkgo/core/stop/combined.hpp>
25#include <ginkgo/core/stop/criterion.hpp>
26
27
28namespace gko {
34namespace solver {
35
36
55template <typename ValueType = default_precision>
56class Idr
57 : public EnableLinOp<Idr<ValueType>>,
58 public EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>,
59 public Transposable {
60 friend class EnableLinOp<Idr>;
61 friend class EnablePolymorphicObject<Idr, LinOp>;
62
63public:
64 using value_type = ValueType;
66
67 std::unique_ptr<LinOp> transpose() const override;
68
69 std::unique_ptr<LinOp> conj_transpose() const override;
70
76 bool apply_uses_initial_guess() const override { return true; }
77
82 size_type get_subspace_dim() const { return parameters_.subspace_dim; }
83
88 void set_subspace_dim(const size_type other)
89 {
90 parameters_.subspace_dim = other;
91 }
92
98 remove_complex<ValueType> get_kappa() const { return parameters_.kappa; }
99
106 {
107 parameters_.kappa = other;
108 }
109
115 bool get_deterministic() const { return parameters_.deterministic; }
116
122 void set_deterministic(const bool other)
123 {
124 parameters_.deterministic = other;
125 }
126
132 bool get_complex_subspace() const { return parameters_.complex_subspace; }
133
140 GKO_DEPRECATED("Use set_complex_subspace instead")
141 void set_complex_subpsace(const bool other)
142 {
143 this->set_complex_subspace(other);
144 }
145
151 void set_complex_subspace(const bool other)
152 {
153 parameters_.complex_subspace = other;
154 }
155
156 class Factory;
157
197
211 static parameters_type parse(const config::pnode& config,
212 const config::registry& context,
213 const config::type_descriptor& td_for_child =
214 config::make_type_descriptor<ValueType>());
215
216protected:
217 void apply_impl(const LinOp* b, LinOp* x) const override;
218
219 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
220 LinOp* x) const override;
221
222 template <typename VectorType>
223 void iterate(const VectorType* dense_b, VectorType* dense_x) const;
224
225 explicit Idr(std::shared_ptr<const Executor> exec)
226 : EnableLinOp<Idr>(std::move(exec))
227 {}
228
229 explicit Idr(const Factory* factory,
230 std::shared_ptr<const LinOp> system_matrix)
231 : EnableLinOp<Idr>(factory->get_executor(),
232 gko::transpose(system_matrix->get_size())),
233 EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>{
234 std::move(system_matrix), factory->get_parameters()},
235 parameters_{factory->get_parameters()}
236 {}
237};
238
239
240template <typename ValueType>
241struct workspace_traits<Idr<ValueType>> {
242 using Solver = Idr<ValueType>;
243 // number of vectors used by this workspace
244 static int num_vectors(const Solver&);
245 // number of arrays used by this workspace
246 static int num_arrays(const Solver&);
247 // array containing the num_vectors names for the workspace vectors
248 static std::vector<std::string> op_names(const Solver&);
249 // array containing the num_arrays names for the workspace vectors
250 static std::vector<std::string> array_names(const Solver&);
251 // array containing all varying scalar vectors (independent of problem size)
252 static std::vector<int> scalars(const Solver&);
253 // array containing all varying vectors (dependent on problem size)
254 static std::vector<int> vectors(const Solver&);
255
256 // residual vector
257 constexpr static int residual = 0;
258 // v vector
259 constexpr static int v = 1;
260 // t vector
261 constexpr static int t = 2;
262 // helper vector
263 constexpr static int helper = 3;
264 // m multivector
265 constexpr static int m = 4;
266 // g multivector
267 constexpr static int g = 5;
268 // u multivector
269 constexpr static int u = 6;
270 // subspace multivector
271 constexpr static int subspace = 7;
272 // f "multiscalar"
273 constexpr static int f = 8;
274 // c "multiscalar"
275 constexpr static int c = 9;
276 // omega scalar
277 constexpr static int omega = 10;
278 // residual norm scalar
279 constexpr static int residual_norm = 11;
280 // T^H*T scalar
281 constexpr static int tht = 12;
282 // alpha "multiscalar"
283 constexpr static int alpha = 13;
284 // constant 1.0 scalar
285 constexpr static int one = 14;
286 // constant -1.0 scalar
287 constexpr static int minus_one = 15;
288 // constant -1.0 scalar
289 constexpr static int subspace_minus_one = 16;
290
291 // stopping status array
292 constexpr static int stop = 0;
293 // reduction tmp array
294 constexpr static int tmp = 1;
295};
296
297
298} // namespace solver
299} // namespace gko
300
301
302#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:879
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:662
Definition lin_op.hpp:117
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition lin_op.hpp:210
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:234
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:433
pnode describes a tree of properties.
Definition property_tree.hpp:28
This class stores additional context for creating Ginkgo objects from configuration files.
Definition registry.hpp:167
This class describes the value and index types to be used when building a Ginkgo type from a configur...
Definition type_descriptor.hpp:39
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition solver_base.hpp:787
Definition idr.hpp:195
IDR(s) is an efficient method for solving large nonsymmetric systems of linear equations.
Definition idr.hpp:59
void set_kappa(const remove_complex< ValueType > other)
Sets the kappa parameter of the solver.
Definition idr.hpp:105
void set_complex_subpsace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition idr.hpp:141
void set_subspace_dim(const size_type other)
Sets the subspace dimension of the solver.
Definition idr.hpp:88
void set_deterministic(const bool other)
Sets the deterministic parameter of the solver.
Definition idr.hpp:122
bool apply_uses_initial_guess() const override
Return true as iterative solvers use the data in x as an initial guess.
Definition idr.hpp:76
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:151
bool get_complex_subspace() const
Gets the complex_subspace parameter of the solver.
Definition idr.hpp:132
size_type get_subspace_dim() const
Gets the subspace dimension of the solver.
Definition idr.hpp:82
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType >())
Create the parameters from the property_tree.
bool get_deterministic() const
Gets the deterministic parameter of the solver.
Definition idr.hpp:115
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:98
#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:1017
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:630
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:260
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:89
STL namespace.
Definition idr.hpp:160
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:193
remove_complex< ValueType > kappa
Threshold to determine if Av_n and v_n are too close to being perpendicular.
Definition idr.hpp:173
bool deterministic
If set to true, the vectors spanning the subspace S are chosen deterministically.
Definition idr.hpp:184
size_type subspace_dim
Dimension of the subspace S.
Definition idr.hpp:165
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition solver_base.hpp:238