Ginkgo  Generated from pipelines/2837190956 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/dense.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 LinOp* b, LinOp* x) const override
148  {
149  this->get_composition()->apply(b, x);
150  }
151 
152  void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
153  LinOp* x) const override
154  {
155  this->get_composition()->apply(alpha, b, beta, x);
156  }
157 
158  explicit UniformCoarsening(std::shared_ptr<const Executor> exec)
159  : LinOp(std::move(exec))
160  {}
161 
162  explicit UniformCoarsening(const Factory* factory,
163  std::shared_ptr<const LinOp> system_matrix)
164  : LinOp(factory->get_executor(), system_matrix->get_size()),
165  EnableMultigridLevel<ValueType>(system_matrix),
166  parameters_{factory->get_parameters()},
167  system_matrix_{system_matrix}
168  {
169  if (system_matrix_->get_size()[0] != 0) {
170  // generate on the existing matrix
171  this->generate();
172  }
173  }
174 
175  void generate();
176 
177 
183  std::tuple<std::shared_ptr<LinOp>, std::shared_ptr<LinOp>,
184  std::shared_ptr<LinOp>>
185  generate_local(
186  std::shared_ptr<const matrix::Csr<ValueType, IndexType>> local_matrix);
187 
188 #if GINKGO_BUILD_MPI
189 
198  template <typename GlobalIndexType>
199  array<GlobalIndexType> communicate_non_local_agg(
200  std::shared_ptr<const experimental::distributed::Matrix<
201  ValueType, IndexType, GlobalIndexType>>
202  matrix,
203  std::shared_ptr<
204  experimental::distributed::Partition<IndexType, GlobalIndexType>>
205  coarse_partition,
206  const array<IndexType>& local_agg);
207 #endif
208 
209 private:
210  std::shared_ptr<const LinOp> system_matrix_{};
211  array<IndexType> coarse_rows_;
212 };
213 
214 
215 } // namespace multigrid
216 } // namespace gko
217 
218 
219 #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:117
gko::multigrid::UniformCoarsening
UniformCoarsening is a simple coarse grid generation algorithm.
Definition: matrix.hpp:43
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:186
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:899
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::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:169
gko::multigrid::UniformCoarsening::get_coarse_rows
IndexType * get_coarse_rows() noexcept
Returns the selected coarse rows.
Definition: uniform_coarsening.hpp:81