33 #ifndef GKO_CORE_PRECONDITIONER_JACOBI_HPP_ 34 #define GKO_CORE_PRECONDITIONER_JACOBI_HPP_ 37 #include <ginkgo/core/base/array.hpp> 38 #include <ginkgo/core/base/lin_op.hpp> 39 #include <ginkgo/core/matrix/dense.hpp> 48 namespace preconditioner {
62 template <
typename IndexType>
88 return one<IndexType>() << group_power;
199 template <
typename ValueType = default_precision,
typename IndexType =
int32>
209 using value_type = ValueType;
210 using index_type = IndexType;
234 return storage_scheme_;
250 return blocks_.get_const_data();
264 return conditioning_.get_const_data();
274 return blocks_.get_num_elems();
322 struct storage_optimization_type {
324 : is_block_wise{
false}, of_all_blocks{p}
327 storage_optimization_type(
330 block_wise{block_wise_opt}
333 storage_optimization_type(
336 block_wise{std::move(block_wise_opt)}
454 explicit Jacobi(std::shared_ptr<const Executor> exec)
460 parameters_.block_pointers.set_executor(exec);
461 parameters_.storage_optimization.block_wise.set_executor(exec);
471 explicit Jacobi(
const Factory *factory,
472 std::shared_ptr<const LinOp> system_matrix)
476 storage_scheme_{compute_storage_scheme(parameters_.max_block_size)},
477 num_blocks_{parameters_.block_pointers.get_num_elems() - 1},
478 blocks_(factory->get_executor(),
479 storage_scheme_.compute_storage_space(
480 parameters_.block_pointers.get_num_elems() - 1)),
481 conditioning_(factory->get_executor())
483 if (parameters_.max_block_size >= 32 ||
484 parameters_.max_block_size < 1) {
485 GKO_NOT_SUPPORTED(
this);
487 parameters_.block_pointers.set_executor(this->get_executor());
488 parameters_.storage_optimization.block_wise.set_executor(
489 this->get_executor());
490 this->generate(
lend(system_matrix));
498 static constexpr
size_type max_block_stride_ = 32;
509 uint32 max_block_size) noexcept
511 const auto group_size =
static_cast<uint32>(
515 const auto group_offset = max_block_size * block_stride;
527 void generate(
const LinOp *system_matrix);
538 void apply_impl(
const LinOp *b, LinOp *x)
const override;
540 void apply_impl(
const LinOp *alpha,
const LinOp *b,
const LinOp *beta,
541 LinOp *x)
const override;
555 #endif // GKO_CORE_PRECONDITIONER_JACOBI_HPP_ constexpr int64 ceildiv(int64 num, int64 den)
Performs integer division with rounding up.
Definition: math.hpp:280
constexpr T get_superior_power(const T &base, const T &limit, const T &hint=T{1}) noexcept
Returns the smallest power of base not smaller than limit.
Definition: math.hpp:495
This class is used to encode storage precisions of low precision algorithms.
Definition: types.hpp:228
const parameters_type & get_parameters() const noexcept
Returns the parameters of the factory.
Definition: abstract_factory.hpp:175
size_type get_num_elems() const noexcept
Returns the number of elements in the Array.
Definition: array.hpp:388
const value_type * get_blocks() const noexcept
Returns the pointer to the memory used for storing the block data.
Definition: jacobi.hpp:248
IndexType block_offset
The offset between consecutive blocks within the group.
Definition: jacobi.hpp:67
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition: polymorphic_object.hpp:380
size_type compute_storage_space(size_type num_blocks) const noexcept
Computes the storage space required for the requested number of blocks.
Definition: jacobi.hpp:103
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:505
void write(StreamType &&os, MatrixType *matrix, layout_type layout=layout_type::array)
Reads a matrix stored in matrix market format from an input stream.
Definition: mtx_io.hpp:134
std::uint32_t uint32
32-bit unsigned integral type.
Definition: types.hpp:134
#define GKO_FACTORY_PARAMETER(_name,...)
Creates a factory parameter in the factory parameters structure.
Definition: lin_op.hpp:751
Defines the parameters of the interleaved block storage scheme used by block-Jacobi blocks...
Definition: jacobi.hpp:63
Definition: jacobi.hpp:445
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
IndexType get_stride() const noexcept
Returns the stride between columns of the block.
Definition: jacobi.hpp:154
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition: coo.hpp:51
IndexType group_offset
The offset between two block groups.
Definition: jacobi.hpp:72
constexpr uint32 get_significant_bit(const T &n, uint32 hint=0u) noexcept
Returns the position of the most significant bit of the number.
Definition: math.hpp:476
size_type get_num_stored_elements() const noexcept
Returns the number of elements explicitly stored in the matrix.
Definition: jacobi.hpp:272
IndexType get_group_offset(IndexType block_id) const noexcept
Returns the offset of the group belonging to the block with the given ID.
Definition: jacobi.hpp:118
const block_interleaved_storage_scheme< index_type > & get_storage_scheme() const noexcept
Returns the storage scheme used for storing Jacobi blocks.
Definition: jacobi.hpp:231
A block-Jacobi preconditioner is a block-diagonal linear operator, obtained by inverting the diagonal...
Definition: jacobi.hpp:200
uint32 group_power
Then base 2 power of the group.
Definition: jacobi.hpp:79
IndexType get_group_size() const noexcept
Returns the number of elements in the group.
Definition: jacobi.hpp:86
Dense is a matrix format which explicitly stores all values of the matrix.
Definition: coo.hpp:55
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:509
const remove_complex< value_type > * get_conditioning() const noexcept
Returns an array of 1-norm condition numbers of the blocks.
Definition: jacobi.hpp:262
IndexType get_global_block_offset(IndexType block_id) const noexcept
Returns the offset of the block with the given ID.
Definition: jacobi.hpp:142
size_type get_num_blocks() const noexcept
Returns the number of blocks of the operator.
Definition: jacobi.hpp:221
std::enable_if< detail::have_ownership< Pointer >), detail::pointee< Pointer > * >::type lend(const Pointer &p)
Returns a non-owning (plain) pointer to the object pointed to by p.
Definition: utils.hpp:249
IndexType get_block_offset(IndexType block_id) const noexcept
Returns the offset of the block with the given ID within its group.
Definition: jacobi.hpp:130
A LinOp implementing this interface can write its data to a matrix_data structure.
Definition: lin_op.hpp:446
#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: lin_op.hpp:611
typename detail::remove_complex_impl< T >::type remove_complex
Obtains a real counterpart of a std::complex type, and leaves the type unchanged if it is not a compl...
Definition: math.hpp:93
#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:691
#define GKO_ENABLE_BUILD_METHOD(_factory_name)
Defines a build method for the factory, simplifying its construction by removing the repetitive typin...
Definition: lin_op.hpp:730
This structure is used as an intermediate data type to store a sparse matrix.
Definition: matrix_data.hpp:102
constexpr dim< 2, DimensionType > transpose(const dim< 2, DimensionType > &dimensions) noexcept
Returns a dim<2> object with its dimensions swapped.
Definition: dim.hpp:234