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/mpi.hpp>
17#include <ginkgo/core/distributed/base.hpp>
18#include <ginkgo/core/distributed/index_map.hpp>
19#include <ginkgo/core/distributed/lin_op.hpp>
26template <
typename ValueType,
typename IndexType>
36template <
typename ValueType,
typename IndexType>
50template <
typename Builder,
typename ValueType,
typename IndexType,
52struct is_matrix_type_builder : std::false_type {};
55template <
typename Builder,
typename ValueType,
typename IndexType>
56struct is_matrix_type_builder<
57 Builder, ValueType, IndexType,
59 decltype(std::declval<Builder>().template create<ValueType, IndexType>(
60 std::declval<std::shared_ptr<const Executor>>()))>>
64template <
template <
typename,
typename>
class MatrixType,
65 typename... CreateArgs>
66struct MatrixTypeBuilderFromValueAndIndex {
67 template <
typename ValueType,
typename IndexType, std::size_t... I>
68 auto create_impl(std::shared_ptr<const Executor> exec,
69 std::index_sequence<I...>)
71 return MatrixType<ValueType, IndexType>::create(
72 exec, std::get<I>(create_args)...);
76 template <
typename ValueType,
typename IndexType>
77 auto create(std::shared_ptr<const Executor> exec)
80 static constexpr auto size =
sizeof...(CreateArgs);
81 return create_impl<ValueType, IndexType>(
82 std::move(exec), std::make_index_sequence<size>{});
85 std::tuple<CreateArgs...> create_args;
123template <
template <
typename,
typename>
class MatrixType,
typename... Args>
126 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
127 std::forward_as_tuple(create_args...)};
131namespace experimental {
132namespace distributed {
135template <
typename LocalIndexType,
typename GlobalIndexType>
137template <
typename ValueType>
246 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
249 Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
251 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
259 using value_type = ValueType;
260 using index_type = GlobalIndexType;
261 using local_index_type = LocalIndexType;
262 using global_index_type = GlobalIndexType;
270 GlobalIndexType>>::convert_to;
272 GlobalIndexType>>::move_to;
275 global_index_type>* result)
const override;
278 global_index_type>* result)
override;
369 return non_local_mtx_;
415 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
438 template <
typename MatrixType,
439 typename = std::enable_if_t<detail::is_matrix_type_builder<
440 MatrixType, ValueType, LocalIndexType>::value>>
441 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
443 MatrixType matrix_template)
478 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
479 typename = std::enable_if_t<
480 detail::is_matrix_type_builder<LocalMatrixType, ValueType,
481 LocalIndexType>::value &&
482 detail::is_matrix_type_builder<NonLocalMatrixType, ValueType,
483 LocalIndexType>::value>>
486 LocalMatrixType local_matrix_template,
487 NonLocalMatrixType non_local_matrix_template)
493 non_local_matrix_template
548 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
550 std::shared_ptr<LinOp> local_linop);
572 dim<2> size, std::shared_ptr<LinOp> local_linop,
573 std::shared_ptr<LinOp> non_local_linop,
574 std::vector<comm_index_type> recv_sizes,
575 std::vector<comm_index_type> recv_offsets,
579 explicit Matrix(std::shared_ptr<const Executor> exec,
582 explicit Matrix(std::shared_ptr<const Executor> exec,
587 explicit Matrix(std::shared_ptr<const Executor> exec,
589 std::shared_ptr<LinOp> local_linop);
591 explicit Matrix(std::shared_ptr<const Executor> exec,
593 std::shared_ptr<LinOp> local_linop,
594 std::shared_ptr<LinOp> non_local_linop,
595 std::vector<comm_index_type> recv_sizes,
596 std::vector<comm_index_type> recv_offsets,
607 mpi::request communicate(
const local_vector_type* local_b)
const;
609 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
612 LinOp* x)
const override;
615 std::vector<comm_index_type> send_offsets_;
616 std::vector<comm_index_type> send_sizes_;
617 std::vector<comm_index_type> recv_offsets_;
618 std::vector<comm_index_type> recv_sizes_;
621 gko::detail::DenseCache<value_type> one_scalar_;
622 gko::detail::DenseCache<value_type> host_send_buffer_;
623 gko::detail::DenseCache<value_type> host_recv_buffer_;
624 gko::detail::DenseCache<value_type> send_buffer_;
625 gko::detail::DenseCache<value_type> recv_buffer_;
626 std::shared_ptr<LinOp> local_mtx_;
627 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:471
Definition lin_op.hpp:118
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition logger.hpp:25
This type is a device-side equivalent to matrix_data.
Definition device_matrix_data.hpp:36
This mixin does the same as EnableLinOp, but for concrete types that are derived from distributed::Di...
Definition lin_op.hpp:45
This mixin does the same as EnablePolymorphicObject, but for concrete types that are derived from dis...
Definition polymorphic_object.hpp:54
A base class for distributed objects.
Definition base.hpp:32
The Matrix class defines a (MPI-)distributed matrix.
Definition matrix.hpp:252
std::shared_ptr< const LinOp > get_non_local_matrix() const
Get read access to the stored non-local matrix.
Definition matrix.hpp:367
Matrix(Matrix &&other) noexcept
Move constructs a Matrix.
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 read_distributed(const matrix_data< value_type, global_index_type > &data, std::shared_ptr< const Partition< local_index_type, global_index_type > > partition)
Reads a square matrix from the matrix_data structure and a global partition.
std::shared_ptr< const LinOp > get_local_matrix() const
Get read access to the stored local matrix.
Definition matrix.hpp:360
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 > > row_partition, std::shared_ptr< const Partition< local_index_type, global_index_type > > col_partition)
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, 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...
Matrix(const Matrix &other)
Copy constructs a Matrix.
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)
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, 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:484
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)
Reads a square matrix from the device_matrix_data structure and a global partition.
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:441
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 vector.hpp:28
Vector is a format which explicitly stores (multiple) distributed column vectors in a dense storage f...
Definition dense.hpp:30
A thin wrapper of MPI_Comm that supports most MPI calls.
Definition mpi.hpp:409
The request class is a light, move-only wrapper around the MPI_Request handle.
Definition mpi.hpp:320
Parallel graph match (Pgm) is the aggregate method introduced in the paper M.
Definition pgm.hpp:53
This class is used for function parameters in the place of raw pointers.
Definition utils_helper.hpp:43
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:103
typename detail::next_precision_impl< T >::type next_precision
Obtains the next type in the singly-linked precision list.
Definition math.hpp:462
auto with_matrix_type(Args &&... create_args)
This function returns a type that delays a call to MatrixType::create.
Definition matrix.hpp:124
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:171
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:109
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:27
This structure is used as an intermediate data type to store a sparse matrix.
Definition matrix_data.hpp:127