Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
schwarz.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_PRECONDITIONER_SCHWARZ_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_PRECONDITIONER_SCHWARZ_HPP_
7 
8 
9 #include <ginkgo/config.hpp>
10 
11 
12 #if GINKGO_BUILD_MPI
13 
14 
15 #include <ginkgo/core/base/abstract_factory.hpp>
16 #include <ginkgo/core/base/lin_op.hpp>
17 #include <ginkgo/core/config/config.hpp>
18 #include <ginkgo/core/config/registry.hpp>
19 #include <ginkgo/core/config/type_descriptor.hpp>
20 #include <ginkgo/core/distributed/matrix.hpp>
21 #include <ginkgo/core/distributed/vector.hpp>
22 #include <ginkgo/core/distributed/vector_cache.hpp>
23 #include <ginkgo/core/solver/solver_base.hpp>
24 
25 
26 namespace gko {
27 namespace experimental {
28 namespace distributed {
34 namespace preconditioner {
35 
36 
67 template <typename ValueType = default_precision,
68  typename LocalIndexType = int32, typename GlobalIndexType = int64>
69 class Schwarz : public LinOp {
70  GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
71 
72 public:
73  using value_type = ValueType;
74  using index_type = GlobalIndexType;
75  using local_index_type = LocalIndexType;
76  using global_index_type = GlobalIndexType;
77 
86  bool apply_uses_initial_guess() const override;
87 
89  {
93  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
94  local_solver);
95 
99  std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
100  generated_local_solver, nullptr);
101 
113  bool GKO_FACTORY_PARAMETER_SCALAR(l1_smoother, false);
114 
122  ValueType GKO_FACTORY_PARAMETER_SCALAR(coarse_weight, ValueType{-1.0});
123 
132  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
133  coarse_level);
134 
138  std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
139  coarse_solver);
140  };
143 
158  static parameters_type parse(
159  const config::pnode& config, const config::registry& context,
160  const config::type_descriptor& td_for_child =
161  config::make_type_descriptor<ValueType, LocalIndexType,
162  GlobalIndexType>());
163 
164 protected:
170  explicit Schwarz(std::shared_ptr<const Executor> exec)
171  : LinOp(std::move(exec))
172  {}
173 
181  explicit Schwarz(const Factory* factory,
182  std::shared_ptr<const LinOp> system_matrix)
183  : LinOp(factory->get_executor(),
184  gko::transpose(system_matrix->get_size())),
185  parameters_{factory->get_parameters()},
186  system_matrix_{system_matrix}
187  {
188  this->generate(system_matrix);
189  }
190 
194  void generate(std::shared_ptr<const LinOp> system_matrix);
195 
196  void apply_impl(const LinOp* b, LinOp* x) const override;
197 
198  template <typename VectorType>
199  void apply_dense_impl(const VectorType* b, VectorType* x) const;
200 
201  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
202  LinOp* x) const override;
203 
204 private:
210  void set_solver(std::shared_ptr<const LinOp> new_solver);
211 
212  std::shared_ptr<const LinOp> local_solver_;
213  std::shared_ptr<const LinOp> system_matrix_;
214 
215  // Used for advanced apply
216  detail::VectorCache<ValueType> cache_;
217  // Used in apply for two-level method
218  detail::VectorCache<ValueType> csol_cache_;
219  detail::VectorCache<ValueType> crhs_cache_;
220 
221  std::shared_ptr<const LinOp> coarse_level_;
222  std::shared_ptr<const LinOp> coarse_solver_;
223  std::shared_ptr<const matrix::Dense<ValueType>> coarse_weight_;
224  std::shared_ptr<const matrix::Dense<ValueType>> local_weight_;
225 };
226 
227 
228 } // namespace preconditioner
229 } // namespace distributed
230 } // namespace experimental
231 } // namespace gko
232 
233 
234 #endif // GINKGO_BUILD_MPI
235 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_PRECONDITIONER_SCHWARZ_HPP_
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::experimental::distributed::preconditioner::Schwarz::apply_uses_initial_guess
bool apply_uses_initial_guess() const override
Return whether the local solvers use the data in x as an initial guess.
gko::LinOp
Definition: lin_op.hpp:117
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:437
gko::experimental::distributed::preconditioner::Schwarz::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, LocalIndexType, GlobalIndexType >())
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:20
gko::experimental::distributed::preconditioner::Schwarz::Factory
Definition: schwarz.hpp:141
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:900
gko::transpose
batch_dim< 2, DimensionType > transpose(const batch_dim< 2, DimensionType > &input)
Returns a batch_dim object with its dimensions swapped for batched operators.
Definition: batch_dim.hpp:119
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:113
gko::default_precision
double default_precision
Precision used if no precision is explicitly specified.
Definition: types.hpp:172
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition: types.hpp:107
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:386
GKO_CREATE_FACTORY_PARAMETERS
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
This Macro will generate a new type containing the parameters for the factory _factory_name.
Definition: abstract_factory.hpp:272
gko::PolymorphicObject::get_executor
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition: polymorphic_object.hpp:62
gko::LinOp::get_size
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:169
gko::experimental::distributed::preconditioner::Schwarz
A Schwarz preconditioner is a simple domain decomposition preconditioner that generalizes the Block J...
Definition: schwarz.hpp:69