Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
ic.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_PRECONDITIONER_IC_HPP_
6 #define GKO_PUBLIC_CORE_PRECONDITIONER_IC_HPP_
7 
8 
9 #include <memory>
10 #include <type_traits>
11 
12 #include <ginkgo/core/base/abstract_factory.hpp>
13 #include <ginkgo/core/base/composition.hpp>
14 #include <ginkgo/core/base/exception.hpp>
15 #include <ginkgo/core/base/exception_helpers.hpp>
16 #include <ginkgo/core/base/lin_op.hpp>
17 #include <ginkgo/core/base/type_traits.hpp>
18 #include <ginkgo/core/config/config.hpp>
19 #include <ginkgo/core/config/registry.hpp>
20 #include <ginkgo/core/factorization/par_ic.hpp>
21 #include <ginkgo/core/solver/solver_traits.hpp>
22 #include <ginkgo/core/solver/triangular.hpp>
23 #include <ginkgo/core/stop/combined.hpp>
24 #include <ginkgo/core/stop/iteration.hpp>
25 #include <ginkgo/core/stop/residual_norm.hpp>
26 
27 
28 namespace gko {
29 namespace preconditioner {
30 
31 
79 template <typename ValueType = default_precision, typename IndexType = int32>
80 class Ic : public LinOp, public Transposable {
81 public:
82  using value_type = ValueType;
83  using index_type = IndexType;
84  using transposed_type = Ic;
85 
86  class Factory;
87 
89  : public enable_parameters_type<parameters_type, Factory> {
93  std::shared_ptr<const LinOpFactory> l_solver_factory{};
94 
98  std::shared_ptr<const LinOpFactory> factorization_factory{};
99 
107  {
108  this->l_solver_generator = std::move(solver);
109  this->deferred_factories["l_solver"] = [](const auto& exec,
110  auto& params) {
111  if (!params.l_solver_generator.is_empty()) {
112  params.l_solver_factory =
113  params.l_solver_generator.on(exec);
114  }
115  };
116  return *this;
117  }
118 
119  parameters_type& with_factorization(
121  {
122  this->factorization_generator = std::move(factorization);
123  this->deferred_factories["factorization"] = [](const auto& exec,
124  auto& params) {
125  if (!params.factorization_generator.is_empty()) {
126  params.factorization_factory =
127  params.factorization_generator.on(exec);
128  }
129  };
130  return *this;
131  }
132 
133  private:
134  deferred_factory_parameter<const LinOpFactory> l_solver_generator;
135 
136  deferred_factory_parameter<const LinOpFactory> factorization_generator;
137  };
138 
141 
160  static parameters_type parse(
161  const config::pnode& config, const config::registry& context,
162  const config::type_descriptor& td_for_child =
163  config::make_type_descriptor<value_type, index_type>());
164 
170  std::shared_ptr<const LinOp> get_l_solver() const { return l_solver_; }
171 
177  std::shared_ptr<const LinOp> get_lh_solver() const { return lh_solver_; }
178 
179  std::unique_ptr<LinOp> transpose() const override;
180 
181  std::unique_ptr<LinOp> conj_transpose() const override;
182 
188  Ic& operator=(const Ic& other);
189 
196  Ic& operator=(Ic&& other);
197 
202  Ic(const Ic& other);
203 
209  Ic(Ic&& other);
210 
211 protected:
212  void apply_impl(const AbstractMultiVector* b,
213  AbstractMultiVector* x) const override;
214 
215  void apply_impl(const AbstractMultiVector* alpha,
216  const AbstractMultiVector* b,
217  const AbstractMultiVector* beta,
218  AbstractMultiVector* x) const override;
219 
220  explicit Ic(std::shared_ptr<const Executor> exec);
221 
222  explicit Ic(const Factory* factory, std::shared_ptr<const LinOp> lin_op);
223 
231  void set_cache_to(const AbstractMultiVector* b) const;
232 
233 private:
234  std::shared_ptr<const LinOp> l_solver_{};
235  std::shared_ptr<const LinOp> lh_solver_{};
246  mutable struct cache_struct {
247  cache_struct() = default;
248  ~cache_struct() = default;
249  cache_struct(const cache_struct&) {}
250  cache_struct(cache_struct&&) noexcept {}
251  cache_struct& operator=(const cache_struct&) { return *this; }
252  cache_struct& operator=(cache_struct&&) noexcept { return *this; }
253  std::unique_ptr<matrix::MultiVector<value_type>> intermediate{};
254  } cache_;
255 };
256 
257 
258 } // namespace preconditioner
259 } // namespace gko
260 
261 
262 #endif // GKO_PUBLIC_CORE_PRECONDITIONER_IC_HPP_
gko::preconditioner::Ic::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::LinOp
Definition: lin_op.hpp:163
gko::preconditioner::Ic::parameters_type::factorization_factory
std::shared_ptr< const LinOpFactory > factorization_factory
Factory for the factorization.
Definition: ic.hpp:98
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:596
gko::preconditioner::Ic
The Incomplete Cholesky (IC) preconditioner solves the equation for a given lower triangular matrix ...
Definition: ic.hpp:80
gko::preconditioner::Ic::parse
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< value_type, index_type >())
Create the parameters from the property_tree.
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::preconditioner::Ic::get_lh_solver
std::shared_ptr< const LinOp > get_lh_solver() const
Returns the solver which is used for the matrix.
Definition: ic.hpp:177
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::preconditioner::Ic::parameters_type
Definition: ic.hpp:88
gko::preconditioner::Ic::parameters_type::with_l_solver
parameters_type & with_l_solver(deferred_factory_parameter< const LinOpFactory > solver)
When LSolverTypeOrValueType is a concrete solver type, this only accepts the factory from the same co...
Definition: ic.hpp:105
gko::preconditioner::Ic::get_l_solver
std::shared_ptr< const LinOp > get_l_solver() const
Returns the solver which is used for the provided matrix.
Definition: ic.hpp:170
gko::preconditioner::Ic::operator=
Ic & operator=(const Ic &other)
Copy-assigns an IC preconditioner.
gko::preconditioner::Ic::Factory
Definition: ic.hpp:139
gko::preconditioner::Ic::parameters_type::l_solver_factory
std::shared_ptr< const LinOpFactory > l_solver_factory
Factory for the solver.
Definition: ic.hpp:93
gko::preconditioner::Ic::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::preconditioner::Ic::Ic
Ic(const Ic &other)
Copy-constructs an IC preconditioner.
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::enable_parameters_type
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition: abstract_factory.hpp:235
gko::deferred_factory_parameter
Represents a factory parameter of factory type that can either initialized by a pre-existing factory ...
Definition: abstract_factory.hpp:333