Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
rcm.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_REORDER_RCM_HPP_
34#define GKO_PUBLIC_CORE_REORDER_RCM_HPP_
35
36
37#include <memory>
38
39
40#include <ginkgo/core/base/abstract_factory.hpp>
41#include <ginkgo/core/base/array.hpp>
42#include <ginkgo/core/base/dim.hpp>
43#include <ginkgo/core/base/lin_op.hpp>
44#include <ginkgo/core/base/polymorphic_object.hpp>
45#include <ginkgo/core/base/types.hpp>
46#include <ginkgo/core/base/utils.hpp>
47#include <ginkgo/core/matrix/csr.hpp>
48#include <ginkgo/core/matrix/identity.hpp>
49#include <ginkgo/core/matrix/permutation.hpp>
50#include <ginkgo/core/matrix/sparsity_csr.hpp>
51#include <ginkgo/core/reorder/reordering_base.hpp>
52
53
54namespace gko {
60namespace reorder {
61
62
63enum class starting_strategy { minimum_degree, pseudo_peripheral };
64
65
99template <typename ValueType = default_precision, typename IndexType = int32>
100class Rcm : public EnablePolymorphicObject<Rcm<ValueType, IndexType>,
101 ReorderingBase<IndexType>>,
102 public EnablePolymorphicAssignment<Rcm<ValueType, IndexType>> {
103 friend class EnablePolymorphicObject<Rcm, ReorderingBase<IndexType>>;
104
105public:
108 using value_type = ValueType;
109 using index_type = IndexType;
110
117 std::shared_ptr<const PermutationMatrix> get_permutation() const
118 {
119 return permutation_;
120 }
121
128 std::shared_ptr<const PermutationMatrix> get_inverse_permutation() const
129 {
130 return inv_permutation_;
131 }
132
133 /*const array<index_type>& get_permutation_array() const override
134 {
135 return permutation_array_;
136 }*/
137
139 {
144 bool GKO_FACTORY_PARAMETER_SCALAR(construct_inverse_permutation, false);
145
150 starting_strategy GKO_FACTORY_PARAMETER_SCALAR(
151 strategy, starting_strategy::pseudo_peripheral);
152 };
153 GKO_ENABLE_REORDERING_BASE_FACTORY(Rcm, parameters, Factory);
155
156protected:
157 explicit Rcm(std::shared_ptr<const Executor> exec);
158
159 explicit Rcm(const Factory* factory, const ReorderingBaseArgs& args);
160
161private:
162 std::shared_ptr<PermutationMatrix> permutation_;
163 std::shared_ptr<PermutationMatrix> inv_permutation_;
164};
165
166
167} // namespace reorder
168
169
170namespace experimental {
171namespace reorder {
172
173
174using rcm_starting_strategy = gko::reorder::starting_strategy;
175
176
202template <typename IndexType = int32>
203class Rcm : public EnablePolymorphicObject<Rcm<IndexType>, LinOpFactory>,
204 public EnablePolymorphicAssignment<Rcm<IndexType>> {
205public:
206 struct parameters_type;
207 friend class EnablePolymorphicObject<Rcm<IndexType>, LinOpFactory>;
208 friend class enable_parameters_type<parameters_type, Rcm<IndexType>>;
209
210 using index_type = IndexType;
212
214 : public enable_parameters_type<parameters_type, Rcm<IndexType>> {
220
225 rcm_starting_strategy GKO_FACTORY_PARAMETER_SCALAR(
226 strategy, rcm_starting_strategy::pseudo_peripheral);
227 };
228
234 const parameters_type& get_parameters() { return parameters_; }
235
243 std::unique_ptr<permutation_type> generate(
244 std::shared_ptr<const LinOp> system_matrix) const;
245
247 static parameters_type build() { return {}; }
248
249protected:
250 explicit Rcm(std::shared_ptr<const Executor> exec,
251 const parameters_type& params = {});
252
253 std::unique_ptr<LinOp> generate_impl(
254 std::shared_ptr<const LinOp> system_matrix) const override;
255
256 parameters_type parameters_;
257};
258
259
260} // namespace reorder
261} // namespace experimental
262} // namespace gko
263
264
265#endif // GKO_PUBLIC_CORE_REORDER_RCM_HPP_
This mixin is used to enable a default PolymorphicObject::copy_from() implementation for objects that...
Definition polymorphic_object.hpp:752
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition lin_op.hpp:414
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition abstract_factory.hpp:239
Rcm (Reverse Cuthill-McKee) is a reordering algorithm minimizing the bandwidth of a matrix.
Definition rcm.hpp:204
const parameters_type & get_parameters()
Returns the parameters used to construct the factory.
Definition rcm.hpp:234
std::unique_ptr< permutation_type > generate(std::shared_ptr< const LinOp > system_matrix) const
static parameters_type build()
Creates a new parameter_type to set up the factory.
Definition rcm.hpp:247
Permutation is a matrix format that represents a permutation matrix, i.e.
Definition permutation.hpp:142
SparsityCsr is a matrix format which stores only the sparsity pattern of a sparse matrix by compressi...
Definition sparsity_csr.hpp:87
Definition rcm.hpp:153
Rcm (Reverse Cuthill-McKee) is a reordering algorithm minimizing the bandwidth of a matrix.
Definition rcm.hpp:102
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:128
std::shared_ptr< const PermutationMatrix > get_permutation() const
Gets the permutation (permutation matrix, output of the algorithm) of the linear operator.
Definition rcm.hpp:117
The ReorderingBase class is a base class for all the reordering algorithms.
Definition reordering_base.hpp:64
#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:308
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:473
#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:422
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
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:219
rcm_starting_strategy strategy
This parameter controls the strategy used to determine a starting vertex.
Definition rcm.hpp:226
This struct is used to pass parameters to the EnableDefaultReorderingBaseFactory::generate() method.
Definition reordering_base.hpp:94