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
idr.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_IDR_HPP_
34#define GKO_PUBLIC_CORE_SOLVER_IDR_HPP_
35
36
37#include <random>
38#include <typeinfo>
39#include <vector>
40
41
42#include <ginkgo/core/base/array.hpp>
43#include <ginkgo/core/base/exception_helpers.hpp>
44#include <ginkgo/core/base/lin_op.hpp>
45#include <ginkgo/core/base/math.hpp>
46#include <ginkgo/core/base/types.hpp>
47#include <ginkgo/core/log/logger.hpp>
48#include <ginkgo/core/matrix/dense.hpp>
49#include <ginkgo/core/matrix/identity.hpp>
50#include <ginkgo/core/solver/solver_base.hpp>
51#include <ginkgo/core/stop/combined.hpp>
52#include <ginkgo/core/stop/criterion.hpp>
53
54
55namespace gko {
61namespace solver {
62
63
82template <typename ValueType = default_precision>
83class Idr
84 : public EnableLinOp<Idr<ValueType>>,
85 public EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>,
86 public Transposable {
87 friend class EnableLinOp<Idr>;
88 friend class EnablePolymorphicObject<Idr, LinOp>;
89
90public:
91 using value_type = ValueType;
93
94 std::unique_ptr<LinOp> transpose() const override;
95
96 std::unique_ptr<LinOp> conj_transpose() const override;
97
103 bool apply_uses_initial_guess() const override { return true; }
104
109 size_type get_subspace_dim() const { return parameters_.subspace_dim; }
110
116 {
117 parameters_.subspace_dim = other;
118 }
119
125 remove_complex<ValueType> get_kappa() const { return parameters_.kappa; }
126
133 {
134 parameters_.kappa = other;
135 }
136
142 bool get_deterministic() const { return parameters_.deterministic; }
143
149 void set_deterministic(const bool other)
150 {
151 parameters_.deterministic = other;
152 }
153
159 bool get_complex_subspace() const { return parameters_.complex_subspace; }
160
167 GKO_DEPRECATED("Use set_complex_subspace instead")
169 {
170 this->set_complex_subspace(other);
171 }
172
179 {
180 parameters_.complex_subspace = other;
181 }
182
183 class Factory;
184
224
225protected:
226 void apply_impl(const LinOp* b, LinOp* x) const override;
227
228 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
229 LinOp* x) const override;
230
231 template <typename VectorType>
232 void iterate(const VectorType* dense_b, VectorType* dense_x) const;
233
234 explicit Idr(std::shared_ptr<const Executor> exec)
235 : EnableLinOp<Idr>(std::move(exec))
236 {}
237
238 explicit Idr(const Factory* factory,
239 std::shared_ptr<const LinOp> system_matrix)
240 : EnableLinOp<Idr>(factory->get_executor(),
241 gko::transpose(system_matrix->get_size())),
242 EnablePreconditionedIterativeSolver<ValueType, Idr<ValueType>>{
243 std::move(system_matrix), factory->get_parameters()},
244 parameters_{factory->get_parameters()}
245 {}
246};
247
248
249template <typename ValueType>
250struct workspace_traits<Idr<ValueType>> {
251 using Solver = Idr<ValueType>;
252 // number of vectors used by this workspace
253 static int num_vectors(const Solver&);
254 // number of arrays used by this workspace
255 static int num_arrays(const Solver&);
256 // array containing the num_vectors names for the workspace vectors
257 static std::vector<std::string> op_names(const Solver&);
258 // array containing the num_arrays names for the workspace vectors
259 static std::vector<std::string> array_names(const Solver&);
260 // array containing all varying scalar vectors (independent of problem size)
261 static std::vector<int> scalars(const Solver&);
262 // array containing all varying vectors (dependent on problem size)
263 static std::vector<int> vectors(const Solver&);
264
265 // residual vector
266 constexpr static int residual = 0;
267 // v vector
268 constexpr static int v = 1;
269 // t vector
270 constexpr static int t = 2;
271 // helper vector
272 constexpr static int helper = 3;
273 // m multivector
274 constexpr static int m = 4;
275 // g multivector
276 constexpr static int g = 5;
277 // u multivector
278 constexpr static int u = 6;
279 // subspace multivector
280 constexpr static int subspace = 7;
281 // f "multiscalar"
282 constexpr static int f = 8;
283 // c "multiscalar"
284 constexpr static int c = 9;
285 // omega scalar
286 constexpr static int omega = 10;
287 // residual norm scalar
288 constexpr static int residual_norm = 11;
289 // T^H*T scalar
290 constexpr static int tht = 12;
291 // alpha "multiscalar"
292 constexpr static int alpha = 13;
293 // constant 1.0 scalar
294 constexpr static int one = 14;
295 // constant -1.0 scalar
296 constexpr static int minus_one = 15;
297 // constant -1.0 scalar
298 constexpr static int subspace_minus_one = 16;
299
300 // stopping status array
301 constexpr static int stop = 0;
302 // reduction tmp array
303 constexpr static int tmp = 1;
304};
305
306
307} // namespace solver
308} // namespace gko
309
310
311#endif // GKO_PUBLIC_CORE_SOLVER_IDR_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
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:462
A LinOp implementing this interface stores a system matrix and stopping criterion factory.
Definition solver_base.hpp:816
Definition idr.hpp:222
IDR(s) is an efficient method for solving large nonsymmetric systems of linear equations.
Definition idr.hpp:86
void set_kappa(const remove_complex< ValueType > other)
Sets the kappa parameter of the solver.
Definition idr.hpp:132
void set_complex_subpsace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition idr.hpp:168
void set_subspace_dim(const size_type other)
Sets the subspace dimension of the solver.
Definition idr.hpp:115
void set_deterministic(const bool other)
Sets the deterministic parameter of the solver.
Definition idr.hpp:149
bool apply_uses_initial_guess() const override
Return true as iterative solvers use the data in x as an initial guess.
Definition idr.hpp:103
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
void set_complex_subspace(const bool other)
Sets the complex_subspace parameter of the solver.
Definition idr.hpp:178
bool get_complex_subspace() const
Gets the complex_subspace parameter of the solver.
Definition idr.hpp:159
size_type get_subspace_dim() const
Gets the subspace dimension of the solver.
Definition idr.hpp:109
bool get_deterministic() const
Gets the deterministic parameter of the solver.
Definition idr.hpp:142
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
remove_complex< ValueType > get_kappa() const
Gets the kappa parameter of the solver.
Definition idr.hpp:125
#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
typename detail::remove_complex_s< T >::type remove_complex
Obtain the type which removed the complex of complex/scalar type or the template parameter of class b...
Definition math.hpp:354
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
Definition idr.hpp:187
bool complex_subspace
If set to true, IDR will use a complex subspace S also for real problems, allowing for faster converg...
Definition idr.hpp:220
remove_complex< ValueType > kappa
Threshold to determine if Av_n and v_n are too close to being perpendicular.
Definition idr.hpp:200
bool deterministic
If set to true, the vectors spanning the subspace S are chosen deterministically.
Definition idr.hpp:211
size_type subspace_dim
Dimension of the subspace S.
Definition idr.hpp:192
Traits class providing information on the type and location of workspace vectors inside a solver.
Definition solver_base.hpp:267