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
pgm.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_MULTIGRID_PGM_HPP_
34#define GKO_PUBLIC_CORE_MULTIGRID_PGM_HPP_
35
36
37#include <vector>
38
39
40#include <ginkgo/core/base/composition.hpp>
41#include <ginkgo/core/base/exception_helpers.hpp>
42#include <ginkgo/core/base/lin_op.hpp>
43#include <ginkgo/core/base/types.hpp>
44#include <ginkgo/core/matrix/csr.hpp>
45#include <ginkgo/core/matrix/dense.hpp>
46#include <ginkgo/core/multigrid/multigrid_level.hpp>
47
48namespace gko {
49namespace multigrid {
50
51
74template <typename ValueType = default_precision, typename IndexType = int32>
75class Pgm : public EnableLinOp<Pgm<ValueType, IndexType>>,
76 public EnableMultigridLevel<ValueType> {
77 friend class EnableLinOp<Pgm>;
78 friend class EnablePolymorphicObject<Pgm, LinOp>;
79
80public:
81 using value_type = ValueType;
82 using index_type = IndexType;
83
89 std::shared_ptr<const LinOp> get_system_matrix() const
90 {
91 return system_matrix_;
92 }
93
103 IndexType* get_agg() noexcept { return agg_.get_data(); }
104
112 const IndexType* get_const_agg() const noexcept
113 {
114 return agg_.get_const_data();
115 }
116
118 {
124 unsigned GKO_FACTORY_PARAMETER_SCALAR(max_iterations, 15u);
125
132 double GKO_FACTORY_PARAMETER_SCALAR(max_unassigned_ratio, 0.05);
133
141 bool GKO_FACTORY_PARAMETER_SCALAR(deterministic, false);
142
153 bool GKO_FACTORY_PARAMETER_SCALAR(skip_sorting, false);
154 };
157
158protected:
159 void apply_impl(const LinOp* b, LinOp* x) const override
160 {
161 this->get_composition()->apply(b, x);
162 }
163
164 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
165 LinOp* x) const override
166 {
167 this->get_composition()->apply(alpha, b, beta, x);
168 }
169
170 explicit Pgm(std::shared_ptr<const Executor> exec)
171 : EnableLinOp<Pgm>(std::move(exec))
172 {}
173
174 explicit Pgm(const Factory* factory,
175 std::shared_ptr<const LinOp> system_matrix)
176 : EnableLinOp<Pgm>(factory->get_executor(), system_matrix->get_size()),
177 EnableMultigridLevel<ValueType>(system_matrix),
178 parameters_{factory->get_parameters()},
179 system_matrix_{system_matrix},
180 agg_(factory->get_executor(), system_matrix_->get_size()[0])
181 {
182 GKO_ASSERT(parameters_.max_unassigned_ratio <= 1.0);
183 GKO_ASSERT(parameters_.max_unassigned_ratio >= 0.0);
184 if (system_matrix_->get_size()[0] != 0) {
185 // generate on the existed matrix
186 this->generate();
187 }
188 }
189
190 void generate();
191
192private:
193 std::shared_ptr<const LinOp> system_matrix_{};
194 array<IndexType> agg_;
195};
196
197
198template <typename ValueType = default_precision, typename IndexType = int32>
199using AmgxPgm GKO_DEPRECATED(
200 "This class is deprecated and will be removed in the next "
201 "major release. Please use Pgm instead.") = Pgm<ValueType, IndexType>;
202
203
204} // namespace multigrid
205} // namespace gko
206
207
208#endif // GKO_PUBLIC_CORE_MULTIGRID_PGM_HPP_
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
Definition lin_op.hpp:146
std::shared_ptr< const Executor > get_executor() const noexcept
Returns the Executor of the object.
Definition polymorphic_object.hpp:263
std::shared_ptr< Composition< ValueType > > get_composition() const
Returns the composition operators.
Definition composition.hpp:214
value_type * get_data() noexcept
Returns a pointer to the block of memory used to store the elements of the array.
Definition array.hpp:646
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:655
The EnableMultigridLevel gives the default implementation of MultigridLevel with composition and prov...
Definition multigrid_level.hpp:111
Definition pgm.hpp:155
Parallel graph match (Pgm) is the aggregate method introduced in the paper M.
Definition pgm.hpp:76
const IndexType * get_const_agg() const noexcept
Returns the aggregate group.
Definition pgm.hpp:112
IndexType * get_agg() noexcept
Returns the aggregate group.
Definition pgm.hpp:103
std::shared_ptr< const LinOp > get_system_matrix() const
Returns the system operator (matrix) of the linear system.
Definition pgm.hpp:89
#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
#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:1046
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
double max_unassigned_ratio
The maximum ratio of unassigned number, which is valid in the interval 0.0 ~ 1.0.
Definition pgm.hpp:132