Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
uniform_coarsening.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MULTIGRID_UNIFORM_COARSENING_HPP_
6 #define GKO_PUBLIC_CORE_MULTIGRID_UNIFORM_COARSENING_HPP_
7 
8 
9 #include <vector>
10 
11 #include <ginkgo/core/base/composition.hpp>
12 #include <ginkgo/core/base/exception_helpers.hpp>
13 #include <ginkgo/core/base/lin_op.hpp>
14 #include <ginkgo/core/base/types.hpp>
15 #include <ginkgo/core/config/config.hpp>
16 #include <ginkgo/core/config/registry.hpp>
17 #include <ginkgo/core/config/type_descriptor.hpp>
18 #include <ginkgo/core/matrix/csr.hpp>
19 #include <ginkgo/core/matrix/multivector.hpp>
20 #include <ginkgo/core/multigrid/multigrid_level.hpp>
21 
22 namespace gko {
23 namespace experimental {
24 namespace distributed {
25 
26 
27 template <typename ValueType, typename LocalIndexType, typename GlobalIndexType>
28 class Matrix;
29 
30 template <typename LocalIndexType, typename GlobalIndexType>
31 class Partition;
32 
33 
34 } // namespace distributed
35 } // namespace experimental
36 
37 
38 namespace multigrid {
39 
40 
58 template <typename ValueType = default_precision, typename IndexType = int32>
59 class UniformCoarsening : public LinOp, public EnableMultigridLevel<ValueType> {
60  GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
61 
62 public:
63  using value_type = ValueType;
64  using index_type = IndexType;
65 
71  std::shared_ptr<const LinOp> get_system_matrix() const
72  {
73  return system_matrix_;
74  }
75 
81  IndexType* get_coarse_rows() noexcept { return coarse_rows_.get_data(); }
82 
90  const IndexType* get_const_coarse_rows() const noexcept
91  {
92  return coarse_rows_.get_const_data();
93  }
94 
95 
97  {
101  int GKO_FACTORY_PARAMETER_SCALAR(coarse_skip, 2);
102 
111  bool GKO_FACTORY_PARAMETER_SCALAR(aggregation, true);
112 
123  bool GKO_FACTORY_PARAMETER_SCALAR(skip_sorting, false);
124  };
127 
141  static parameters_type parse(
142  const config::pnode& config, const config::registry& context,
143  const config::type_descriptor& td_for_child =
144  config::make_type_descriptor<ValueType, IndexType>());
145 
146 protected:
147  void apply_impl(const AbstractMultiVector* b,
148  AbstractMultiVector* x) const override
149  {
150  this->get_composition()->apply(b, x);
151  }
152 
153  void apply_impl(const AbstractMultiVector* alpha,
154  const AbstractMultiVector* b,
155  const AbstractMultiVector* beta,
156  AbstractMultiVector* x) const override
157  {
158  this->get_composition()->apply(alpha, b, beta, x);
159  }
160 
161  explicit UniformCoarsening(std::shared_ptr<const Executor> exec)
162  : LinOp(std::move(exec))
163  {}
164 
165  explicit UniformCoarsening(const Factory* factory,
166  std::shared_ptr<const LinOp> system_matrix)
167  : LinOp(factory->get_executor(), system_matrix->get_size()),
168  EnableMultigridLevel<ValueType>(system_matrix),
169  parameters_{factory->get_parameters()},
170  system_matrix_{system_matrix}
171  {
172  if (system_matrix_->get_size()[0] != 0) {
173  // generate on the existing matrix
174  this->generate();
175  }
176  }
177 
178  void generate();
179 
180 
186  std::tuple<std::shared_ptr<LinOp>, std::shared_ptr<LinOp>,
187  std::shared_ptr<LinOp>>
188  generate_local(
189  std::shared_ptr<const matrix::Csr<ValueType, IndexType>> local_matrix);
190 
191 #if GINKGO_BUILD_MPI
192 
201  template <typename GlobalIndexType>
202  array<GlobalIndexType> communicate_non_local_agg(
203  std::shared_ptr<const experimental::distributed::Matrix<
204  ValueType, IndexType, GlobalIndexType>>
205  matrix,
206  std::shared_ptr<
207  experimental::distributed::Partition<IndexType, GlobalIndexType>>
208  coarse_partition,
209  const array<IndexType>& local_agg);
210 #endif
211 
212 private:
213  std::shared_ptr<const LinOp> system_matrix_{};
214  array<IndexType> coarse_rows_;
215 };
216 
217 
218 } // namespace multigrid
219 } // namespace gko
220 
221 
222 #endif // GKO_PUBLIC_CORE_MULTIGRID_UNIFORM_COARSENING_HPP_
gko::multigrid::UniformCoarsening::get_const_coarse_rows
const IndexType * get_const_coarse_rows() const noexcept
Returns the selected coarse rows.
Definition: uniform_coarsening.hpp:90
gko::config::pnode
pnode describes a tree of properties.
Definition: property_tree.hpp:28
gko::LinOp
Definition: lin_op.hpp:163
gko::multigrid::UniformCoarsening
UniformCoarsening is a simple coarse grid generation algorithm.
Definition: matrix.hpp:46
gko::multigrid::UniformCoarsening::get_system_matrix
std::shared_ptr< const LinOp > get_system_matrix() const
Returns the system operator (matrix) of the linear system.
Definition: uniform_coarsening.hpp:71
gko::multigrid::UniformCoarsening::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, IndexType >())
Create the parameters from the property_tree.
gko::multigrid::UniformCoarsening::Factory
Definition: uniform_coarsening.hpp:125
gko::UseComposition::get_composition
std::shared_ptr< Composition< ValueType > > get_composition() const
Returns the composition operators.
Definition: composition.hpp:189
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::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_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::array::get_data
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:686
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_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:304
gko::array::get_const_data
const value_type * get_const_data() const noexcept
Returns a constant pointer to the block of memory used to store the elements of the array.
Definition: array.hpp:695
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::LinOp::get_size
const dim< 2 > & get_size() const noexcept
Returns the size of the operator.
Definition: lin_op.hpp:259
gko::multigrid::UniformCoarsening::get_coarse_rows
IndexType * get_coarse_rows() noexcept
Returns the selected coarse rows.
Definition: uniform_coarsening.hpp:81