Ginkgo: ginkgo/core/distributed/preconditioner/schwarz.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
schwarz.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 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
26namespace gko {
27namespace experimental {
28namespace distributed {
34 namespace preconditioner {
35
36
67template <typename ValueType = default_precision,
68 typename LocalIndexType = int32, typename GlobalIndexType = int64>
69 class Schwarz
70 : public EnableLinOp<Schwarz<ValueType, LocalIndexType, GlobalIndexType>> {
71 friend class EnableLinOp<Schwarz>;
72 friend class EnablePolymorphicObject<Schwarz, LinOp>;
73 GKO_ASSERT_SUPPORTED_VALUE_AND_DIST_INDEX_TYPE;
74
75public:
76 using EnableLinOp<Schwarz>::convert_to;
77 using EnableLinOp<Schwarz>::move_to;
78 using value_type = ValueType;
79 using index_type = GlobalIndexType;
80 using local_index_type = LocalIndexType;
81 using global_index_type = GlobalIndexType;
82
91 bool apply_uses_initial_guess() const override;
92
93 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
94 {
98 std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
99 local_solver);
100
104 std::shared_ptr<const LinOp> GKO_FACTORY_PARAMETER_SCALAR(
105 generated_local_solver, nullptr);
106
118 bool GKO_FACTORY_PARAMETER_SCALAR(l1_smoother, false);
119
127 ValueType GKO_FACTORY_PARAMETER_SCALAR(coarse_weight, ValueType{-1.0});
128
137 std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
138 coarse_level);
139
143 std::shared_ptr<const LinOpFactory> GKO_DEFERRED_FACTORY_PARAMETER(
144 coarse_solver);
145 };
146 GKO_ENABLE_LIN_OP_FACTORY(Schwarz, parameters, Factory);
147 GKO_ENABLE_BUILD_METHOD(Factory);
148
163 static parameters_type parse(
164 const config::pnode& config, const config::registry& context,
165 const config::type_descriptor& td_for_child =
166 config::make_type_descriptor<ValueType, LocalIndexType,
167 GlobalIndexType>());
168
169protected:
175 explicit Schwarz(std::shared_ptr<const Executor> exec)
176 : EnableLinOp<Schwarz>(std::move(exec))
177 {}
178
186 explicit Schwarz(const Factory* factory,
187 std::shared_ptr<const LinOp> system_matrix)
188 : EnableLinOp<Schwarz>(factory->get_executor(),
189 gko::transpose(system_matrix->get_size())),
190 parameters_{factory->get_parameters()},
191 system_matrix_{system_matrix}
192 {
193 this->generate(system_matrix);
194 }
195
199 void generate(std::shared_ptr<const LinOp> system_matrix);
200
201 void apply_impl(const LinOp* b, LinOp* x) const override;
202
203 template <typename VectorType>
204 void apply_dense_impl(const VectorType* b, VectorType* x) const;
205
206 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
207 LinOp* x) const override;
208
209private:
215 void set_solver(std::shared_ptr<const LinOp> new_solver);
216
217 std::shared_ptr<const LinOp> local_solver_;
218 std::shared_ptr<const LinOp> system_matrix_;
219
220 // Used for advanced apply
221 detail::VectorCache<ValueType> cache_;
222 // Used in apply for two-level method
223 detail::VectorCache<ValueType> csol_cache_;
224 detail::VectorCache<ValueType> crhs_cache_;
225
226 std::shared_ptr<const LinOp> coarse_level_;
227 std::shared_ptr<const LinOp> coarse_solver_;
228 std::shared_ptr<const matrix::Dense<ValueType>> coarse_weight_;
229 std::shared_ptr<const matrix::Dense<ValueType>> local_weight_;
230};
231
232
233} // namespace preconditioner
234} // namespace distributed
235} // namespace experimental
236} // namespace gko
237
238
239#endif // GINKGO_BUILD_MPI
240#endif // GKO_PUBLIC_CORE_DISTRIBUTED_PRECONDITIONER_SCHWARZ_HPP_
gko::EnableLinOp
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
gko::LinOp
Definition lin_op.hpp:117
gko::config::pnode
pnode describes a tree of properties.
Definition property_tree.hpp:28
gko::config::registry
This class stores additional context for creating Ginkgo objects from configuration files.
Definition registry.hpp:167
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::experimental::distributed::preconditioner::Schwarz::Factory
Definition schwarz.hpp:146
gko::experimental::distributed::preconditioner::Schwarz
A Schwarz preconditioner is a simple domain decomposition preconditioner that generalizes the Block J...
Definition schwarz.hpp:70
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::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_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:280
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:445
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:394
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:1017
gko::experimental::distributed::preconditioner
The Preconditioner namespace.
Definition schwarz.hpp:34
gko::experimental::distributed
The distributed namespace.
Definition polymorphic_object.hpp:19
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::int32
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:107
gko::default_precision
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:172
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:113
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
std
STL namespace.
gko::experimental::distributed::preconditioner::Schwarz::parameters_type
Definition schwarz.hpp:94
gko::experimental::distributed::preconditioner::Schwarz::parameters_type::coarse_level
std::shared_ptr< const LinOpFactory > coarse_level
Operator factory list to generate the triplet (prolong_op, coarse_op, restrict_op),...
Definition schwarz.hpp:138
gko::experimental::distributed::preconditioner::Schwarz::parameters_type::generated_local_solver
std::shared_ptr< const LinOp > generated_local_solver
Generated Inner solvers.
Definition schwarz.hpp:105
gko::experimental::distributed::preconditioner::Schwarz::parameters_type::local_solver
std::shared_ptr< const LinOpFactory > local_solver
Local solver factory.
Definition schwarz.hpp:99
gko::experimental::distributed::preconditioner::Schwarz::parameters_type::coarse_solver
std::shared_ptr< const LinOpFactory > coarse_solver
Coarse solver factory.
Definition schwarz.hpp:144
gko::experimental::distributed::preconditioner::Schwarz::parameters_type::l1_smoother
bool l1_smoother
Enable l1 smoother.
Definition schwarz.hpp:118
gko::experimental::distributed::preconditioner::Schwarz::parameters_type::coarse_weight
ValueType coarse_weight
Coarse weighting.
Definition schwarz.hpp:127