ginkgo/core/solver/triangular.hpp Source File

ginkgo/core/solver/triangular.hpp Source File#

Reference API: ginkgo/core/solver/triangular.hpp Source File
Reference API
triangular.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_SOLVER_TRIANGULAR_HPP_
6#define GKO_PUBLIC_CORE_SOLVER_TRIANGULAR_HPP_
7
8
9#include <memory>
10#include <utility>
11
12#include <ginkgo/core/base/abstract_factory.hpp>
13#include <ginkgo/core/base/array.hpp>
14#include <ginkgo/core/base/dim.hpp>
15#include <ginkgo/core/base/exception_helpers.hpp>
16#include <ginkgo/core/base/lin_op.hpp>
17#include <ginkgo/core/base/polymorphic_object.hpp>
18#include <ginkgo/core/base/types.hpp>
19#include <ginkgo/core/base/utils.hpp>
20#include <ginkgo/core/config/config.hpp>
21#include <ginkgo/core/config/registry.hpp>
22#include <ginkgo/core/log/logger.hpp>
23#include <ginkgo/core/matrix/csr.hpp>
24#include <ginkgo/core/matrix/identity.hpp>
25#include <ginkgo/core/solver/solver_base.hpp>
26
27
28namespace gko {
29namespace solver {
30
31
32struct SolveStruct;
33
34
40enum class trisolve_algorithm { sparselib, syncfree };
41
42
43template <typename ValueType, typename IndexType>
44class UpperTrs;
45
46
63template <typename ValueType = default_precision, typename IndexType = int32>
64class LowerTrs : public EnableLinOp<LowerTrs<ValueType, IndexType>>,
65 public EnableSolverBase<LowerTrs<ValueType, IndexType>,
66 matrix::Csr<ValueType, IndexType>>,
67 public Transposable {
68 friend class EnableLinOp<LowerTrs>;
70 friend class UpperTrs<ValueType, IndexType>;
71
72public:
73 using value_type = ValueType;
74 using index_type = IndexType;
76
77 std::unique_ptr<LinOp> transpose() const override;
78
79 std::unique_ptr<LinOp> conj_transpose() const override;
80
82 {
90
95 bool GKO_FACTORY_PARAMETER_SCALAR(unit_diagonal, false);
96
104 algorithm, trisolve_algorithm::sparselib);
105 };
108
123 const config::pnode& config, const config::registry& context,
124 const config::type_descriptor& td_for_child =
125 config::make_type_descriptor<ValueType, IndexType>());
126
133
141
148
155
156protected:
158
159 void apply_impl(const LinOp* b, LinOp* x) const override;
160
161 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
162 LinOp* x) const override;
163
168 void generate();
169
170 explicit LowerTrs(std::shared_ptr<const Executor> exec)
171 : EnableLinOp<LowerTrs>(std::move(exec))
172 {}
173
174 explicit LowerTrs(const Factory* factory,
175 std::shared_ptr<const LinOp> system_matrix)
176 : EnableLinOp<LowerTrs>(factory->get_executor(),
177 gko::transpose(system_matrix->get_size())),
178 EnableSolverBase<LowerTrs<ValueType, IndexType>, CsrMatrix>{
179 copy_and_convert_to<CsrMatrix>(factory->get_executor(),
180 system_matrix)},
181 parameters_{factory->get_parameters()}
182 {
183 this->generate();
184 }
185
186private:
187 std::shared_ptr<solver::SolveStruct> solve_struct_;
188};
189
190
191template <typename ValueType, typename IndexType>
192struct workspace_traits<LowerTrs<ValueType, IndexType>> {
194 // number of vectors used by this workspace
195 static int num_vectors(const Solver&);
196 // number of arrays used by this workspace
197 static int num_arrays(const Solver&);
198 // array containing the num_vectors names for the workspace vectors
199 static std::vector<std::string> op_names(const Solver&);
200 // array containing the num_arrays names for the workspace vectors
201 static std::vector<std::string> array_names(const Solver&);
202 // array containing all varying scalar vectors (independent of problem size)
203 static std::vector<int> scalars(const Solver&);
204 // array containing all varying vectors (dependent on problem size)
205 static std::vector<int> vectors(const Solver&);
206
207 // transposed input vector
208 constexpr static int transposed_b = 0;
209 // transposed output vector
210 constexpr static int transposed_x = 1;
211};
212
213
230template <typename ValueType = default_precision, typename IndexType = int32>
231class UpperTrs : public EnableLinOp<UpperTrs<ValueType, IndexType>>,
232 public EnableSolverBase<UpperTrs<ValueType, IndexType>,
233 matrix::Csr<ValueType, IndexType>>,
234 public Transposable {
235 friend class EnableLinOp<UpperTrs>;
237 friend class LowerTrs<ValueType, IndexType>;
238
239public:
240 using value_type = ValueType;
241 using index_type = IndexType;
243
244 std::unique_ptr<LinOp> transpose() const override;
245
246 std::unique_ptr<LinOp> conj_transpose() const override;
247
249 {
257
262 bool GKO_FACTORY_PARAMETER_SCALAR(unit_diagonal, false);
263
271 algorithm, trisolve_algorithm::sparselib);
272 };
275
290 const config::pnode& config, const config::registry& context,
291 const config::type_descriptor& td_for_child =
292 config::make_type_descriptor<ValueType, IndexType>());
293
300
308
315
322
323protected:
325
326 void apply_impl(const LinOp* b, LinOp* x) const override;
327
328 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
329 LinOp* x) const override;
330
335 void generate();
336
337 explicit UpperTrs(std::shared_ptr<const Executor> exec)
338 : EnableLinOp<UpperTrs>(std::move(exec))
339 {}
340
341 explicit UpperTrs(const Factory* factory,
342 std::shared_ptr<const LinOp> system_matrix)
343 : EnableLinOp<UpperTrs>(factory->get_executor(),
344 gko::transpose(system_matrix->get_size())),
345 EnableSolverBase<UpperTrs<ValueType, IndexType>, CsrMatrix>{
346 copy_and_convert_to<CsrMatrix>(factory->get_executor(),
347 system_matrix)},
348 parameters_{factory->get_parameters()}
349 {
350 this->generate();
351 }
352
353private:
354 std::shared_ptr<solver::SolveStruct> solve_struct_;
355};
356
357
358template <typename ValueType, typename IndexType>
359struct workspace_traits<UpperTrs<ValueType, IndexType>> {
361 // number of vectors used by this workspace
362 static int num_vectors(const Solver&);
363 // number of arrays used by this workspace
364 static int num_arrays(const Solver&);
365 // array containing the num_vectors names for the workspace vectors
366 static std::vector<std::string> op_names(const Solver&);
367 // array containing the num_arrays names for the workspace vectors
368 static std::vector<std::string> array_names(const Solver&);
369 // array containing all varying scalar vectors (independent of problem size)
370 static std::vector<int> scalars(const Solver&);
371 // array containing all varying vectors (dependent on problem size)
372 static std::vector<int> vectors(const Solver&);
373
374 // transposed input vector
375 constexpr static int transposed_b = 0;
376 // transposed output vector
377 constexpr static int transposed_x = 1;
378};
379
380
381} // namespace solver
382} // namespace gko
383
384
385#endif // GKO_PUBLIC_CORE_SOLVER_TRIANGULAR_HPP_
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
std::shared_ptr< const Executor > get_executor() const noexcept
Definition polymorphic_object.hpp:243
Definition lin_op.hpp:433
Definition property_tree.hpp:28
Definition registry.hpp:167
Definition type_descriptor.hpp:39
Definition csr.hpp:123
Definition solver_base.hpp:539
Definition triangular.hpp:106
Definition triangular.hpp:67
LowerTrs & operator=(LowerTrs &&)
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType, IndexType >())
LowerTrs(const LowerTrs &)
std::unique_ptr< LinOp > transpose() const override
LowerTrs & operator=(const LowerTrs &)
std::unique_ptr< LinOp > conj_transpose() const override
LowerTrs(LowerTrs &&)
Definition triangular.hpp:273
Definition triangular.hpp:234
UpperTrs(UpperTrs &&)
UpperTrs(const UpperTrs &)
std::unique_ptr< LinOp > conj_transpose() const override
UpperTrs & operator=(UpperTrs &&)
std::unique_ptr< LinOp > transpose() const override
UpperTrs & operator=(const UpperTrs &)
static parameters_type parse(const config::pnode &config, const config::registry &context, const config::type_descriptor &td_for_child=config::make_type_descriptor< ValueType, IndexType >())
#define GKO_CREATE_FACTORY_PARAMETERS(_parameters_name, _factory_name)
Definition abstract_factory.hpp:280
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Definition abstract_factory.hpp:445
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Definition abstract_factory.hpp:394
#define GKO_ENABLE_LIN_OP_FACTORY(_lin_op, _parameters_name, _factory_name)
Definition lin_op.hpp:1016
trisolve_algorithm
Definition triangular.hpp:40
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::size_t size_type
Definition types.hpp:89
STL namespace.
Definition triangular.hpp:82
Definition triangular.hpp:249
Definition solver_base.hpp:238