Ginkgo: ginkgo/core/reorder/rcm.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
rcm.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_REORDER_RCM_HPP_
6#define GKO_PUBLIC_CORE_REORDER_RCM_HPP_
7
8
9#include <memory>
10
11#include <ginkgo/core/base/abstract_factory.hpp>
12#include <ginkgo/core/base/array.hpp>
13#include <ginkgo/core/base/dim.hpp>
14#include <ginkgo/core/base/lin_op.hpp>
15#include <ginkgo/core/base/polymorphic_object.hpp>
16#include <ginkgo/core/base/types.hpp>
17#include <ginkgo/core/base/utils.hpp>
18#include <ginkgo/core/matrix/csr.hpp>
19#include <ginkgo/core/matrix/identity.hpp>
20#include <ginkgo/core/matrix/permutation.hpp>
21#include <ginkgo/core/matrix/sparsity_csr.hpp>
22#include <ginkgo/core/reorder/reordering_base.hpp>
23
24
25namespace gko {
31 namespace reorder {
32
33
34enum class starting_strategy { minimum_degree, pseudo_peripheral };
35
36
70template <typename ValueType = default_precision, typename IndexType = int32>
71 class Rcm : public EnablePolymorphicObject<Rcm<ValueType, IndexType>,
72 ReorderingBase<IndexType>>,
73 public EnablePolymorphicAssignment<Rcm<ValueType, IndexType>> {
74 friend class EnablePolymorphicObject<Rcm, ReorderingBase<IndexType>>;
75 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
76
77public:
78 using SparsityMatrix = matrix::SparsityCsr<ValueType, IndexType>;
79 using PermutationMatrix = matrix::Permutation<IndexType>;
80 using value_type = ValueType;
81 using index_type = IndexType;
82
89 std::shared_ptr<const PermutationMatrix> get_permutation() const
90 {
91 return permutation_;
92 }
93
100 std::shared_ptr<const PermutationMatrix> get_inverse_permutation() const
101 {
102 return inv_permutation_;
103 }
104
105 /*const array<index_type>& get_permutation_array() const override
106 {
107 return permutation_array_;
108 }*/
109
110 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
111 {
116 bool GKO_FACTORY_PARAMETER_SCALAR(construct_inverse_permutation, false);
117
122 starting_strategy GKO_FACTORY_PARAMETER_SCALAR(
123 strategy, starting_strategy::pseudo_peripheral);
124 };
125 GKO_ENABLE_REORDERING_BASE_FACTORY(Rcm, parameters, Factory);
126 GKO_ENABLE_BUILD_METHOD(Factory);
127
128protected:
129 explicit Rcm(std::shared_ptr<const Executor> exec);
130
131 explicit Rcm(const Factory* factory, const ReorderingBaseArgs& args);
132
133private:
134 std::shared_ptr<PermutationMatrix> permutation_;
135 std::shared_ptr<PermutationMatrix> inv_permutation_;
136};
137
138
139} // namespace reorder
140
141
142namespace experimental {
143namespace reorder {
144
145
146using rcm_starting_strategy = gko::reorder::starting_strategy;
147
148
174template <typename IndexType = int32>
175 class Rcm : public EnablePolymorphicObject<Rcm<IndexType>, LinOpFactory>,
176 public EnablePolymorphicAssignment<Rcm<IndexType>> {
177public:
178 struct parameters_type;
179 friend class EnablePolymorphicObject<Rcm<IndexType>, LinOpFactory>;
180 friend class enable_parameters_type<parameters_type, Rcm<IndexType>>;
181
182 using index_type = IndexType;
183 using permutation_type = matrix::Permutation<index_type>;
184
185 struct parameters_type
186 : public enable_parameters_type<parameters_type, Rcm<IndexType>> {
191 bool GKO_FACTORY_PARAMETER_SCALAR(skip_symmetrize, false);
192
197 rcm_starting_strategy GKO_FACTORY_PARAMETER_SCALAR(
198 strategy, rcm_starting_strategy::pseudo_peripheral);
199 };
200
206 const parameters_type& get_parameters() { return parameters_; }
207
215 std::unique_ptr<permutation_type> generate(
216 std::shared_ptr<const LinOp> system_matrix) const;
217
219 static parameters_type build() { return {}; }
220
221protected:
222 explicit Rcm(std::shared_ptr<const Executor> exec,
223 const parameters_type& params = {});
224
225 std::unique_ptr<LinOp> generate_impl(
226 std::shared_ptr<const LinOp> system_matrix) const override;
227
228 parameters_type parameters_;
229};
230
231
232} // namespace reorder
233} // namespace experimental
234} // namespace gko
235
236
237#endif // GKO_PUBLIC_CORE_REORDER_RCM_HPP_
gko::EnablePolymorphicAssignment
This mixin is used to enable a default PolymorphicObject::copy_from() implementation for objects that...
Definition polymorphic_object.hpp:743
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
gko::LinOpFactory
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition lin_op.hpp:385
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:211
gko::experimental::reorder::Rcm
Rcm (Reverse Cuthill-McKee) is a reordering algorithm minimizing the bandwidth of a matrix.
Definition rcm.hpp:176
gko::experimental::reorder::Rcm::get_parameters
const parameters_type & get_parameters()
Returns the parameters used to construct the factory.
Definition rcm.hpp:206
gko::experimental::reorder::Rcm::generate
std::unique_ptr< permutation_type > generate(std::shared_ptr< const LinOp > system_matrix) const
Creates a new product from the given components.
gko::experimental::reorder::Rcm::build
static parameters_type build()
Creates a new parameter_type to set up the factory.
Definition rcm.hpp:219
gko::matrix::Permutation
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition permutation.hpp:112
gko::matrix::SparsityCsr
SparsityCsr is a matrix format which stores only the sparsity pattern of a sparse matrix by compressi...
Definition sparsity_csr.hpp:56
gko::reorder::Rcm::Factory
Definition rcm.hpp:125
gko::reorder::Rcm::get_inverse_permutation
std::shared_ptr< const PermutationMatrix > get_inverse_permutation() const
Gets the inverse permutation (permutation matrix, output of the algorithm) of the linear operator.
Definition rcm.hpp:100
gko::reorder::Rcm::get_permutation
std::shared_ptr< const PermutationMatrix > get_permutation() const
Gets the permutation (permutation matrix, output of the algorithm) of the linear operator.
Definition rcm.hpp:89
gko::reorder::ReorderingBase
The ReorderingBase class is a base class for all the reordering algorithms.
Definition reordering_base.hpp:35
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::reorder
The Reorder namespace.
Definition rcm.hpp:31
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::experimental::reorder::Rcm::parameters_type
Definition rcm.hpp:186
gko::experimental::reorder::Rcm::parameters_type::skip_symmetrize
bool skip_symmetrize
If set to false, computes the RCM reordering on A + A^T, otherwise assumes that A is symmetric and us...
Definition rcm.hpp:191
gko::experimental::reorder::Rcm::parameters_type::strategy
rcm_starting_strategy strategy
This parameter controls the strategy used to determine a starting vertex.
Definition rcm.hpp:198
gko::reorder::Rcm::parameters_type::construct_inverse_permutation
bool construct_inverse_permutation
If this parameter is set then an inverse permutation matrix is also constructed along with the normal...
Definition rcm.hpp:116
gko::reorder::Rcm::parameters_type::strategy
starting_strategy strategy
This parameter controls the strategy used to determine a starting vertex.
Definition rcm.hpp:123
gko::reorder::ReorderingBaseArgs
This struct is used to pass parameters to the EnableDefaultReorderingBaseFactory::generate() method.
Definition reordering_base.hpp:65