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
cb_gmres.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_SOLVER_CB_GMRES_HPP_
34#define GKO_PUBLIC_CORE_SOLVER_CB_GMRES_HPP_
35
36
37#include <memory>
38#include <vector>
39
40
41#include <ginkgo/core/base/array.hpp>
42#include <ginkgo/core/base/exception_helpers.hpp>
43#include <ginkgo/core/base/lin_op.hpp>
44#include <ginkgo/core/base/math.hpp>
45#include <ginkgo/core/base/types.hpp>
46#include <ginkgo/core/log/logger.hpp>
47#include <ginkgo/core/matrix/dense.hpp>
48#include <ginkgo/core/matrix/identity.hpp>
49#include <ginkgo/core/solver/solver_base.hpp>
50#include <ginkgo/core/stop/combined.hpp>
51#include <ginkgo/core/stop/criterion.hpp>
52
53
54namespace gko {
55namespace solver {
56
57
58namespace cb_gmres {
59
60
88enum class storage_precision {
89 keep,
90 reduce1,
91 reduce2,
92 integer,
93 ireduce1,
94 ireduce2
95};
96
97
98} // namespace cb_gmres
99
100
122template <typename ValueType = default_precision>
123class CbGmres : public EnableLinOp<CbGmres<ValueType>>,
125 CbGmres<ValueType>> {
126 friend class EnableLinOp<CbGmres>;
128
129public:
130 using value_type = ValueType;
131
137 size_type get_krylov_dim() const { return parameters_.krylov_dim; }
138
145
151 cb_gmres::storage_precision get_storage_precision() const
152 {
153 return parameters_.storage_precision;
154 }
155
156 class Factory;
157
160 parameters_type, Factory> {
164 cb_gmres::storage_precision GKO_FACTORY_PARAMETER_SCALAR(
165 storage_precision, cb_gmres::storage_precision::reduce1);
166
171 };
172
175
176protected:
177 void apply_impl(const LinOp* b, LinOp* x) const override;
178
179 void apply_dense_impl(const matrix::Dense<ValueType>* b,
180 matrix::Dense<ValueType>* x) const;
181
182 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
183 LinOp* x) const override;
184
185 explicit CbGmres(std::shared_ptr<const Executor> exec)
186 : EnableLinOp<CbGmres>(std::move(exec))
187 {}
188
189 explicit CbGmres(const Factory* factory,
190 std::shared_ptr<const LinOp> system_matrix)
191 : EnableLinOp<CbGmres>(factory->get_executor(),
192 transpose(system_matrix->get_size())),
193 EnablePreconditionedIterativeSolver<ValueType, CbGmres<ValueType>>{
194 std::move(system_matrix), factory->get_parameters()},
195 parameters_{factory->get_parameters()}
196 {}
197};
198
199
200} // namespace solver
201} // namespace gko
202
203
204#endif // GKO_PUBLIC_CORE_SOLVER_CB_GMRES_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
Dense is a matrix format which explicitly stores all values of the matrix.
Definition dense.hpp:136
Definition cb_gmres.hpp:173
CB-GMRES or the compressed basis generalized minimal residual method is an iterative type Krylov subs...
Definition cb_gmres.hpp:125
size_type get_krylov_dim() const
Returns the Krylov dimension.
Definition cb_gmres.hpp:137
void set_krylov_dim(size_type other)
Sets the Krylov dimension.
Definition cb_gmres.hpp:144
cb_gmres::storage_precision get_storage_precision() const
Returns the storage precision used internally.
Definition cb_gmres.hpp:151
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition solver_base.hpp:816
#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
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
batch_dim< 2, DimensionType > transpose(const batch_dim< 2, DimensionType > &input)
Returns a batch_dim object with its dimensions swapped for batched operators.
Definition batch_dim.hpp:148
Definition cb_gmres.hpp:160
size_type krylov_dim
Krylov dimension factory.
Definition cb_gmres.hpp:170
cb_gmres::storage_precision storage_precision
Determines which storage type is used.
Definition cb_gmres.hpp:165