Ginkgo: ginkgo/core/preconditioner/batch_jacobi.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
batch_jacobi.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_PRECONDITIONER_BATCH_JACOBI_HPP_
6#define GKO_PUBLIC_CORE_PRECONDITIONER_BATCH_JACOBI_HPP_
7
8
9#include <ginkgo/core/base/array.hpp>
10#include <ginkgo/core/base/batch_lin_op.hpp>
11#include <ginkgo/core/base/batch_multi_vector.hpp>
12#include <ginkgo/core/base/exception_helpers.hpp>
13#include <ginkgo/core/base/lin_op.hpp>
14#include <ginkgo/core/base/types.hpp>
15#include <ginkgo/core/matrix/batch_csr.hpp>
16#include <ginkgo/core/matrix/batch_dense.hpp>
17#include <ginkgo/core/matrix/csr.hpp>
18
19
20namespace gko {
21namespace batch {
22namespace preconditioner {
23
24
49template <typename ValueType = default_precision, typename IndexType = int32>
50 class Jacobi final : public EnableBatchLinOp<Jacobi<ValueType, IndexType>> {
51 friend class EnableBatchLinOp<Jacobi>;
52 friend class EnablePolymorphicObject<Jacobi, BatchLinOp>;
53 GKO_ASSERT_SUPPORTED_VALUE_AND_INDEX_TYPE;
54
55public:
56 using EnableBatchLinOp<Jacobi>::convert_to;
57 using EnableBatchLinOp<Jacobi>::move_to;
58 using value_type = ValueType;
59 using index_type = IndexType;
60 using matrix_type = batch::matrix::Csr<ValueType, IndexType>;
61
68 const index_type* get_const_block_pointers() const noexcept
69 {
70 return block_pointers_.get_const_data();
71 }
72
79 const index_type* get_const_map_block_to_row() const noexcept
80 {
81 return map_block_to_row_.get_const_data();
82 }
83
90 const index_type* get_const_blocks_cumulative_offsets() const noexcept
91 {
92 return blocks_cumulative_offsets_.get_const_data();
93 }
94
100 uint32 get_max_block_size() const noexcept
101 {
102 return parameters_.max_block_size;
103 }
104
110 size_type get_num_blocks() const noexcept { return num_blocks_; }
111
130 const value_type* get_const_blocks() const noexcept
131 {
132 return blocks_.get_const_data();
133 }
134
144 size_type get_num_stored_elements() const noexcept
145 {
146 return blocks_.get_size();
147 }
148
149 GKO_CREATE_FACTORY_PARAMETERS(parameters, Factory)
150 {
163 uint32 GKO_FACTORY_PARAMETER_SCALAR(max_block_size, 8u);
164
191 gko::array<index_type> GKO_FACTORY_PARAMETER_VECTOR(block_pointers,
192 nullptr);
193 };
194 GKO_ENABLE_BATCH_LIN_OP_FACTORY(Jacobi, parameters, Factory);
195 GKO_ENABLE_BUILD_METHOD(Factory);
196
197private:
198 explicit Jacobi(std::shared_ptr<const Executor> exec);
199
200 explicit Jacobi(const Factory* factory,
201 std::shared_ptr<const BatchLinOp> system_matrix);
202
203 void generate_precond(const BatchLinOp* const system_matrix);
204
205 size_type compute_storage_space(const size_type num_batch) const noexcept;
206
207 void detect_blocks(
208 const gko::matrix::Csr<ValueType, IndexType>* system_matrix);
209
210 array<index_type> block_pointers_;
211 size_type num_blocks_;
212 array<value_type> blocks_;
213 array<index_type> map_block_to_row_;
214 array<index_type> blocks_cumulative_offsets_;
215};
216
217
218} // namespace preconditioner
219} // namespace batch
220} // namespace gko
221
222
223#endif // GKO_PUBLIC_CORE_PRECONDITIONER_BATCH_JACOBI_HPP_
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
gko::batch::BatchLinOp
Definition batch_lin_op.hpp:59
gko::batch::EnableBatchLinOp
The EnableBatchLinOp mixin can be used to provide sensible default implementations of the majority of...
Definition batch_lin_op.hpp:252
gko::batch::matrix::Csr
Csr is a general sparse matrix format that stores the column indices for each nonzero entry and a cum...
Definition batch_csr.hpp:55
gko::batch::preconditioner::Jacobi::Factory
Definition batch_jacobi.hpp:194
gko::batch::preconditioner::Jacobi::get_const_block_pointers
const index_type * get_const_block_pointers() const noexcept
Returns the block pointers.
Definition batch_jacobi.hpp:68
gko::batch::preconditioner::Jacobi::get_max_block_size
uint32 get_max_block_size() const noexcept
Returns the max block size.
Definition batch_jacobi.hpp:100
gko::batch::preconditioner::Jacobi::get_const_map_block_to_row
const index_type * get_const_map_block_to_row() const noexcept
Returns the mapping between the blocks and the row id.
Definition batch_jacobi.hpp:79
gko::batch::preconditioner::Jacobi::get_const_blocks_cumulative_offsets
const index_type * get_const_blocks_cumulative_offsets() const noexcept
Returns the cumulative blocks storage array.
Definition batch_jacobi.hpp:90
gko::batch::preconditioner::Jacobi::get_num_blocks
size_type get_num_blocks() const noexcept
Returns the number of blocks in an individual batch entry.
Definition batch_jacobi.hpp:110
gko::batch::preconditioner::Jacobi::get_const_blocks
const value_type * get_const_blocks() const noexcept
Returns the pointer to the memory used for storing the block data.
Definition batch_jacobi.hpp:130
gko::batch::preconditioner::Jacobi::get_num_stored_elements
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the dense blocks.
Definition batch_jacobi.hpp:144
gko::matrix::Csr
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition csr.hpp:126
GKO_ENABLE_BATCH_LIN_OP_FACTORY
#define GKO_ENABLE_BATCH_LIN_OP_FACTORY(_batch_lin_op, _parameters_name, _factory_name)
This macro will generate a default implementation of a BatchLinOpFactory for the BatchLinOp subclass ...
Definition batch_lin_op.hpp:358
GKO_CREATE_FACTORY_PARAMETERS
#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:280
GKO_FACTORY_PARAMETER_SCALAR
#define GKO_FACTORY_PARAMETER_SCALAR(_name, _default)
Creates a scalar factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:445
GKO_ENABLE_BUILD_METHOD
#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:394
GKO_FACTORY_PARAMETER_VECTOR
#define GKO_FACTORY_PARAMETER_VECTOR(_name,...)
Creates a vector factory parameter in the factory parameters structure.
Definition abstract_factory.hpp:461
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::uint32
std::uint32_t uint32
32-bit unsigned integral type.
Definition types.hpp:130
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
gko::batch::preconditioner::Jacobi::parameters_type::max_block_size
uint32 max_block_size
Maximal size of diagonal blocks.
Definition batch_jacobi.hpp:163
gko::batch::preconditioner::Jacobi::parameters_type::block_pointers
gko::array< index_type > block_pointers
Starting (row / column) indexes of individual blocks, for a single batch item.
Definition batch_jacobi.hpp:192