5#ifndef GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_
6#define GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_
9#include <ginkgo/config.hpp>
15#include <ginkgo/core/base/dense_cache.hpp>
16#include <ginkgo/core/base/lin_op.hpp>
17#include <ginkgo/core/base/mpi.hpp>
18#include <ginkgo/core/base/std_extensions.hpp>
19#include <ginkgo/core/distributed/base.hpp>
20#include <ginkgo/core/distributed/index_map.hpp>
21#include <ginkgo/core/distributed/row_gatherer.hpp>
22#include <ginkgo/core/distributed/vector_cache.hpp>
29template <
typename ValueType,
typename IndexType>
39template <
typename ValueType,
typename IndexType>
53template <
typename Builder,
typename ValueType,
typename IndexType,
55struct is_matrix_type_builder : std::false_type {};
58template <
typename Builder,
typename ValueType,
typename IndexType>
59struct is_matrix_type_builder<
60 Builder, ValueType, IndexType,
62 decltype(std::declval<Builder>().template create<ValueType, IndexType>(
63 std::declval<std::shared_ptr<const Executor>>()))>>
67template <
template <
typename,
typename>
class MatrixType,
68 typename... CreateArgs>
69struct MatrixTypeBuilderFromValueAndIndex {
70 template <
typename ValueType,
typename IndexType, std::size_t... I>
71 auto create_impl(std::shared_ptr<const Executor> exec,
72 std::index_sequence<I...>)
74 return MatrixType<ValueType, IndexType>::create(
75 exec, std::get<I>(create_args)...);
79 template <
typename ValueType,
typename IndexType>
80 auto create(std::shared_ptr<const Executor> exec)
83 static constexpr auto size =
sizeof...(CreateArgs);
84 return create_impl<ValueType, IndexType>(
85 std::move(exec), std::make_index_sequence<size>{});
88 std::tuple<CreateArgs...> create_args;
126template <
template <
typename,
typename>
class MatrixType,
typename... Args>
129 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
130 std::forward_as_tuple(create_args...)};
134namespace experimental {
135namespace distributed {
150template <
typename LocalIndexType,
typename GlobalIndexType>
152template <
typename ValueType>
261 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
263 :
public EnableLinOp<Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
265 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
266#if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
267 public ConvertibleTo<Matrix<next_precision<ValueType, 2>, LocalIndexType,
270#if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
271 public ConvertibleTo<Matrix<next_precision<ValueType, 3>, LocalIndexType,
274 public DistributedBase {
282 using value_type = ValueType;
283 using index_type = GlobalIndexType;
284 using local_index_type = LocalIndexType;
285 using global_index_type = GlobalIndexType;
286 using global_vector_type =
288 using local_vector_type =
typename global_vector_type::local_vector_type;
293 GlobalIndexType>>::convert_to;
295 GlobalIndexType>>::move_to;
298 global_index_type>* result)
const override;
301 global_index_type>* result)
override;
303#if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
307 global_index_type>>::convert_to;
309 global_index_type>>::move_to;
312 global_index_type>* result)
const override;
315 global_index_type>* result)
override;
318#if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
322 global_index_type>>::convert_to;
324 global_index_type>>::move_to;
327 global_index_type>* result)
const override;
330 global_index_type>* result)
override;
427 return non_local_mtx_;
473 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
496 template <
typename MatrixType,
497 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
498 MatrixType, ValueType, LocalIndexType>::value>>
499 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
501 MatrixType matrix_template)
536 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
537 typename = std::enable_if_t<
538 gko::detail::is_matrix_type_builder<
539 LocalMatrixType, ValueType, LocalIndexType>::value &&
540 gko::detail::is_matrix_type_builder<
541 NonLocalMatrixType, ValueType, LocalIndexType>::value>>
544 LocalMatrixType local_matrix_template,
545 NonLocalMatrixType non_local_matrix_template)
551 non_local_matrix_template
606 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
608 std::shared_ptr<LinOp> local_linop);
629 "Please use the overload with an index_map instead.")]]
static std::
632 dim<2> size, std::shared_ptr<LinOp> local_linop,
633 std::shared_ptr<LinOp> non_local_linop,
634 std::vector<comm_index_type> recv_sizes,
635 std::vector<comm_index_type> recv_offsets,
654 std::shared_ptr<LinOp> local_linop,
655 std::shared_ptr<LinOp> non_local_linop);
676 explicit Matrix(std::shared_ptr<const Executor> exec,
679 explicit Matrix(std::shared_ptr<const Executor> exec,
684 explicit Matrix(std::shared_ptr<const Executor> exec,
686 std::shared_ptr<LinOp> local_linop);
688 explicit Matrix(std::shared_ptr<const Executor> exec,
691 std::shared_ptr<LinOp> local_linop,
692 std::shared_ptr<LinOp> non_local_linop);
694 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
697 LinOp* x)
const override;
700 std::shared_ptr<RowGatherer<LocalIndexType>> row_gatherer_;
702 gko::detail::ScalarCache one_scalar_;
703 detail::GenericVectorCache recv_buffer_;
704 detail::GenericVectorCache host_recv_buffer_;
705 std::shared_ptr<LinOp> local_mtx_;
706 std::shared_ptr<LinOp> non_local_mtx_;
ConvertibleTo interface is used to mark that the implementer can be converted to the object of Result...
Definition polymorphic_object.hpp:479
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
LinOp(const LinOp &)=default
Copy-constructs a LinOp.
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
This type is a device-side equivalent to matrix_data.
Definition device_matrix_data.hpp:36
std::shared_ptr< const LinOp > get_non_local_matrix() const
Get read access to the stored non-local matrix.
Definition matrix.hpp:425
Matrix(Matrix &&other) noexcept
Move constructs a Matrix.
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, index_map< local_index_type, global_index_type > imap, std::shared_ptr< LinOp > local_linop, std::shared_ptr< LinOp > non_local_linop)
Creates distributed matrix with existent local and non-local LinOp and the corresponding mapping to c...
void read_distributed(const matrix_data< value_type, global_index_type > &data, std::shared_ptr< const Partition< local_index_type, global_index_type > > row_partition, std::shared_ptr< const Partition< local_index_type, global_index_type > > col_partition, assembly_mode assembly_type=assembly_mode::local_only)
Reads a matrix from the matrix_data structure, a global row partition, and a global column partition.
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, ptr_param< const LinOp > local_matrix_template, ptr_param< const LinOp > non_local_matrix_template)
Creates an empty distributed matrix with specified types for the local matrix and the non-local matri...
void col_scale(ptr_param< const global_vector_type > scaling_factors)
Scales the columns of the matrix by the respective entries of the vector.
std::shared_ptr< const LinOp > get_local_matrix() const
Get read access to the stored local matrix.
Definition matrix.hpp:418
void read_distributed(const device_matrix_data< value_type, global_index_type > &data, std::shared_ptr< const Partition< local_index_type, global_index_type > > row_partition, std::shared_ptr< const Partition< local_index_type, global_index_type > > col_partition, assembly_mode assembly_type=assembly_mode::local_only)
Reads a matrix from the device_matrix_data structure, a global row partition, and a global column par...
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm)
Creates an empty distributed matrix.
void read_distributed(const matrix_data< value_type, global_index_type > &data, std::shared_ptr< const Partition< local_index_type, global_index_type > > partition, assembly_mode assembly_type=assembly_mode::local_only)
Reads a square matrix from the matrix_data structure and a global partition.
void row_scale(ptr_param< const global_vector_type > scaling_factors)
Scales the rows of the matrix by the respective entries of the vector.
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, dim< 2 > size, std::shared_ptr< LinOp > local_linop)
Creates a local-only distributed matrix with existent LinOp.
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, dim< 2 > size, std::shared_ptr< LinOp > local_linop, std::shared_ptr< LinOp > non_local_linop, std::vector< comm_index_type > recv_sizes, std::vector< comm_index_type > recv_offsets, array< local_index_type > recv_gather_idxs)
Creates distributed matrix with existent local and non-local LinOp and the corresponding mapping to c...
void read_distributed(const device_matrix_data< value_type, global_index_type > &data, std::shared_ptr< const Partition< local_index_type, global_index_type > > partition, assembly_mode assembly_type=assembly_mode::local_only)
Reads a square matrix from the device_matrix_data structure and a global partition.
Matrix(const Matrix &other)
Copy constructs a Matrix.
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, LocalMatrixType local_matrix_template, NonLocalMatrixType non_local_matrix_template)
Creates an empty distributed matrix with specified types for the local matrix and the non-local matri...
Definition matrix.hpp:542
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, MatrixType matrix_template)
Creates an empty distributed matrix with specified type for local matrices.
Definition matrix.hpp:499
Matrix & operator=(Matrix &&other)
Move assigns a Matrix.
Matrix & operator=(const Matrix &other)
Copy assigns a Matrix.
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, ptr_param< const LinOp > matrix_template)
Creates an empty distributed matrix with specified type for local matrices.
Represents a partition of a range of indices [0, size) into a disjoint set of parts.
Definition partition.hpp:83
Vector is a format which explicitly stores (multiple) distributed column vectors in a dense storage f...
Definition vector.hpp:77
This class defines mappings between global and local indices.
Definition index_map.hpp:68
A thin wrapper of MPI_Comm that supports most MPI calls.
Definition mpi.hpp:419
CSR is a matrix format which stores only the nonzero coefficients by compressing each row of the matr...
Definition csr.hpp:126
Parallel graph match (Pgm) is the aggregate method introduced in the paper M.
Definition pgm.hpp:52
This class is used for function parameters in the place of raw pointers.
Definition utils_helper.hpp:41
assembly_mode
assembly_mode defines how the read_distributed function of the distributed matrix treats non-local in...
Definition matrix.hpp:147
The matrix namespace.
Definition dense_cache.hpp:24
The multigrid components namespace.
Definition matrix.hpp:36
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:107
auto with_matrix_type(Args &&... create_args)
This function returns a type that delays a call to MatrixType::create.
Definition matrix.hpp:127
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:172
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:113
typename detail::find_precision_impl< T, -step >::type previous_precision
Obtains the previous move type of T in the singly-linked precision corresponding bfloat16/half.
Definition math.hpp:473
typename detail::find_precision_impl< T, step >::type next_precision
Obtains the next move type of T in the singly-linked precision corresponding bfloat16/half.
Definition math.hpp:466
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:26
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:126