Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
idr.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 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/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 
27 namespace gko {
33 namespace solver {
34 
35 
81 template <typename ValueType = default_precision>
82 class Idr
83  : public LinOp,
84  public EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>,
85  public Transposable {
86  GKO_ASSERT_SUPPORTED_VALUE_TYPE;
87 
88 public:
89  using value_type = ValueType;
91 
92  std::unique_ptr<LinOp> transpose() const override;
93 
94  std::unique_ptr<LinOp> conj_transpose() const override;
95 
101  bool apply_uses_initial_guess() const override { return true; }
102 
107  size_type get_subspace_dim() const { return parameters_.subspace_dim; }
108 
113  void set_subspace_dim(const size_type other)
114  {
115  parameters_.subspace_dim = other;
116  }
117 
123  remove_complex<ValueType> get_kappa() const { return parameters_.kappa; }
124 
131  {
132  parameters_.kappa = other;
133  }
134 
140  bool get_deterministic() const { return parameters_.deterministic; }
141 
147  void set_deterministic(const bool other)
148  {
149  parameters_.deterministic = other;
150  }
151 
157  bool get_complex_subspace() const { return parameters_.complex_subspace; }
158 
165  GKO_DEPRECATED("Use set_complex_subspace instead")
166  void set_complex_subpsace(const bool other)
167  {
168  this->set_complex_subspace(other);
169  }
170 
176  void set_complex_subspace(const bool other)
177  {
178  parameters_.complex_subspace = other;
179  }
180 
181  class Factory;
182 
185  parameters_type, Factory> {
191 
199 
210 
219  };
222 
236  static parameters_type parse(const config::pnode& config,
237  const config::registry& context,
238  const config::type_descriptor& td_for_child =
239  config::make_type_descriptor<ValueType>());
240 
241 protected:
242  void apply_impl(const AbstractMultiVector* b,
243  AbstractMultiVector* x) const override;
244 
245  void apply_impl(const AbstractMultiVector* alpha,
246  const AbstractMultiVector* b,
247  const AbstractMultiVector* beta,
248  AbstractMultiVector* x) const override;
249 
250  template <typename VectorType>
251  void iterate(const VectorType* dense_b, VectorType* dense_x) const;
252 
253  explicit Idr(std::shared_ptr<const Executor> exec) : LinOp(std::move(exec))
254  {}
255 
256  explicit Idr(const Factory* factory,
257  std::shared_ptr<const LinOp> system_matrix)
258  : LinOp(factory->get_executor(),
259  gko::transpose(system_matrix->get_size())),
260  EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>{
261  std::move(system_matrix), factory->get_parameters()},
262  parameters_{factory->get_parameters()}
263  {}
264 };
265 
266 
267 template <typename ValueType>
268 struct workspace_traits<Idr<ValueType>> {
269  using Solver = Idr<ValueType>;
270  // number of vectors used by this workspace
271  static int num_vectors(const Solver&);
272  // number of arrays used by this workspace
273  static int num_arrays(const Solver&);
274  // array containing the num_vectors names for the workspace vectors
275  static std::vector<std::string> op_names(const Solver&);
276  // array containing the num_arrays names for the workspace vectors
277  static std::vector<std::string> array_names(const Solver&);
278  // array containing all varying scalar vectors (independent of problem size)
279  static std::vector<int> scalars(const Solver&);
280  // array containing all varying vectors (dependent on problem size)
281  static std::vector<int> vectors(const Solver&);
282 
283  // residual vector
284  constexpr static int residual = 0;
285  // v vector
286  constexpr static int v = 1;
287  // t vector
288  constexpr static int t = 2;
289  // helper vector
290  constexpr static int helper = 3;
291  // m multivector
292  constexpr static int m = 4;
293  // g multivector
294  constexpr static int g = 5;
295  // u multivector
296  constexpr static int u = 6;
297  // subspace multivector
298  constexpr static int subspace = 7;
299  // f "multiscalar"
300  constexpr static int f = 8;
301  // c "multiscalar"
302  constexpr static int c = 9;
303  // omega scalar
304  constexpr static int omega = 10;
305  // residual norm scalar
306  constexpr static int residual_norm = 11;
307  // T^H*T scalar
308  constexpr static int tht = 12;
309  // alpha "multiscalar"
310  constexpr static int alpha = 13;
311  // constant 1.0 scalar
312  constexpr static int one = 14;
313  // constant -1.0 scalar
314  constexpr static int minus_one = 15;
315  // constant -1.0 scalar
316  constexpr static int subspace_minus_one = 16;
317 
318  // stopping status array
319  constexpr static int stop = 0;
320  // reduction tmp array
321  constexpr static int tmp = 1;
322 };
323 
324 
325 } // namespace solver
326 } // namespace gko
327 
328 
329 #endif // GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
gko::solver::Idr::parameters_type
Definition: idr.hpp:183
gko::solver::Idr::set_kappa
void set_kappa(const remove_complex< ValueType > other)
Sets the kappa parameter of the solver.
Definition: idr.hpp:130
gko::solver::Idr::parameters_type::complex_subspace
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:218
gko::solver::Idr::apply_uses_initial_guess
bool apply_uses_initial_guess() const override
Return true as iterative solvers use the data in x as an initial guess.
Definition: idr.hpp:101
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::log::profile_event_category::solver
Solver events.
gko::LinOp
Definition: lin_op.hpp:163
gko::solver::Idr::set_complex_subspace
void set_complex_subspace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition: idr.hpp:176
gko::solver::Idr::set_subspace_dim
void set_subspace_dim(const size_type other)
Sets the subspace dimension of the solver.
Definition: idr.hpp:113
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:596
gko::solver::Idr::get_deterministic
bool get_deterministic() const
Gets the deterministic parameter of the solver.
Definition: idr.hpp:140
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::solver::enable_preconditioned_iterative_solver_factory_parameters
Definition: solver_base.hpp:1134
GKO_FACTORY_PARAMETER_SCALAR
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition: abstract_factory.hpp:469
gko::solver::Idr::parameters_type::deterministic
bool deterministic
If set to true, the vectors spanning the subspace S are chosen deterministically.
Definition: idr.hpp:209
gko::config::type_descriptor
This class describes the value and index types to be used when building a Ginkgo type from a configur...
Definition: type_descriptor.hpp:39
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::solver::Idr::Factory
Definition: idr.hpp:220
gko::solver::Idr::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::solver::Idr::set_deterministic
void set_deterministic(const bool other)
Sets the deterministic parameter of the solver.
Definition: idr.hpp:147
gko::solver::Idr::set_complex_subpsace
void set_complex_subpsace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition: idr.hpp:166
gko::solver::Idr
IDR(s) is an efficient method for solving large nonsymmetric systems of linear equations.
Definition: idr.hpp:82
gko::solver::Idr::get_subspace_dim
size_type get_subspace_dim() const
Gets the subspace dimension of the solver.
Definition: idr.hpp:107
GKO_ENABLE_LIN_OP_FACTORY
#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:1192
gko::solver::Idr::parse
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.
gko::solver::Idr::parameters_type::kappa
remove_complex< ValueType > kappa
Threshold to determine if and are too close to being perpendicular.
Definition: idr.hpp:198
gko::solver::Idr::get_complex_subspace
bool get_complex_subspace() const
Gets the complex_subspace parameter of the solver.
Definition: idr.hpp:157
gko::solver::Idr::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::config::registry
This class stores additional context for creating Ginkgo objects from configuration files.
Definition: registry.hpp:167
GKO_ENABLE_BUILD_METHOD
#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:418
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81
gko::PolymorphicObject::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:69
gko::solver::workspace_traits
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition: solver_base.hpp:258
gko::LinOp::get_size
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:259
gko::remove_complex
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:263
gko::solver::EnablePreconditionedIterativeSolver
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition: solver_base.hpp:841
gko::solver::Idr::parameters_type::subspace_dim
size_type subspace_dim
Dimension of the subspace S.
Definition: idr.hpp:190
gko::one
constexpr T one()
Returns the multiplicative identity for T.
Definition: math.hpp:653
gko::solver::Idr::get_kappa
remove_complex< ValueType > get_kappa() const
Gets the kappa parameter of the solver.
Definition: idr.hpp:123