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>
27template <
typename ValueType,
typename IndexType>
37template <
typename ValueType,
typename IndexType>
51template <
typename Builder,
typename ValueType,
typename IndexType,
53struct is_matrix_type_builder : std::false_type {};
56template <
typename Builder,
typename ValueType,
typename IndexType>
57struct is_matrix_type_builder<
58 Builder, ValueType, IndexType,
60 decltype(std::declval<Builder>().template create<ValueType, IndexType>(
61 std::declval<std::shared_ptr<const Executor>>()))>>
65template <
template <
typename,
typename>
class MatrixType,
66 typename... CreateArgs>
67struct MatrixTypeBuilderFromValueAndIndex {
68 template <
typename ValueType,
typename IndexType, std::size_t... I>
69 auto create_impl(std::shared_ptr<const Executor> exec,
70 std::index_sequence<I...>)
72 return MatrixType<ValueType, IndexType>::create(
73 exec, std::get<I>(create_args)...);
77 template <
typename ValueType,
typename IndexType>
78 auto create(std::shared_ptr<const Executor> exec)
81 static constexpr auto size =
sizeof...(CreateArgs);
82 return create_impl<ValueType, IndexType>(
83 std::move(exec), std::make_index_sequence<size>{});
86 std::tuple<CreateArgs...> create_args;
124template <
template <
typename,
typename>
class MatrixType,
typename... Args>
127 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
128 std::forward_as_tuple(create_args...)};
132namespace experimental {
133namespace distributed {
148template <
typename LocalIndexType,
typename GlobalIndexType>
150template <
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
267 public ConvertibleTo<Matrix<next_precision<next_precision<ValueType>>,
268 LocalIndexType, GlobalIndexType>>,
272 friend class Matrix<previous_precision<ValueType>, LocalIndexType,
278 using value_type = ValueType;
279 using index_type = GlobalIndexType;
280 using local_index_type = LocalIndexType;
281 using global_index_type = GlobalIndexType;
289 GlobalIndexType>>::convert_to;
291 GlobalIndexType>>::move_to;
294 global_index_type>* result)
const override;
297 global_index_type>* result)
override;
298#if GINKGO_ENABLE_HALF
299 friend class Matrix<previous_precision<previous_precision<ValueType>>,
300 LocalIndexType, GlobalIndexType>;
303 global_index_type>>::convert_to;
305 local_index_type, global_index_type>>::move_to;
309 global_index_type>* result)
const override;
312 local_index_type, global_index_type>* result)
override;
410 return non_local_mtx_;
456 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
479 template <
typename MatrixType,
480 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
481 MatrixType, ValueType, LocalIndexType>::value>>
482 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
484 MatrixType matrix_template)
488 matrix_template.template create<ValueType, LocalIndexType>(exec));
519 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
520 typename = std::enable_if_t<
521 gko::detail::is_matrix_type_builder<
522 LocalMatrixType, ValueType, LocalIndexType>::value &&
523 gko::detail::is_matrix_type_builder<
524 NonLocalMatrixType, ValueType, LocalIndexType>::value>>
527 LocalMatrixType local_matrix_template,
528 NonLocalMatrixType non_local_matrix_template)
532 local_matrix_template.template create<ValueType, LocalIndexType>(
534 non_local_matrix_template
535 .template create<ValueType, LocalIndexType>(exec));
589 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
591 std::shared_ptr<LinOp> local_linop);
613 dim<2> size, std::shared_ptr<LinOp> local_linop,
614 std::shared_ptr<LinOp> non_local_linop,
615 std::vector<comm_index_type> recv_sizes,
616 std::vector<comm_index_type> recv_offsets,
638 explicit Matrix(std::shared_ptr<const Executor> exec,
641 explicit Matrix(std::shared_ptr<const Executor> exec,
646 explicit Matrix(std::shared_ptr<const Executor> exec,
648 std::shared_ptr<LinOp> local_linop);
650 explicit Matrix(std::shared_ptr<const Executor> exec,
652 std::shared_ptr<LinOp> local_linop,
653 std::shared_ptr<LinOp> non_local_linop,
654 std::vector<comm_index_type> recv_sizes,
655 std::vector<comm_index_type> recv_offsets,
668 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
671 LinOp* x)
const override;
674 std::vector<comm_index_type> send_offsets_;
675 std::vector<comm_index_type> send_sizes_;
676 std::vector<comm_index_type> recv_offsets_;
677 std::vector<comm_index_type> recv_sizes_;
680 gko::detail::DenseCache<value_type> one_scalar_;
681 gko::detail::DenseCache<value_type> host_send_buffer_;
682 gko::detail::DenseCache<value_type> host_recv_buffer_;
683 gko::detail::DenseCache<value_type> send_buffer_;
684 gko::detail::DenseCache<value_type> recv_buffer_;
685 std::shared_ptr<LinOp> local_mtx_;
686 std::shared_ptr<LinOp> non_local_mtx_;
Definition polymorphic_object.hpp:479
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition lin_op.hpp:117
Definition device_matrix_data.hpp:36
Definition matrix.hpp:270
std::shared_ptr< const LinOp > get_non_local_matrix() const
Definition matrix.hpp:408
Matrix(Matrix &&other) noexcept
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)
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)
void col_scale(ptr_param< const global_vector_type > scaling_factors)
std::shared_ptr< const LinOp > get_local_matrix() const
Definition matrix.hpp:401
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)
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm)
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)
void row_scale(ptr_param< const global_vector_type > scaling_factors)
mpi::request communicate(const local_vector_type *local_b) const
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, dim< 2 > size, std::shared_ptr< LinOp > local_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)
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)
Matrix(const Matrix &other)
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, LocalMatrixType local_matrix_template, NonLocalMatrixType non_local_matrix_template)
Definition matrix.hpp:525
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, MatrixType matrix_template)
Definition matrix.hpp:482
Matrix & operator=(Matrix &&other)
Matrix & operator=(const Matrix &other)
static std::unique_ptr< Matrix > create(std::shared_ptr< const Executor > exec, mpi::communicator comm, ptr_param< const LinOp > matrix_template)
Definition partition.hpp:83
Definition utils_helper.hpp:41
assembly_mode
Definition matrix.hpp:145
The Ginkgo namespace.
Definition abstract_factory.hpp:20
double default_precision
Definition types.hpp:171
std::int32_t int32
Definition types.hpp:106
auto with_matrix_type(Args &&... create_args)
Definition matrix.hpp:125
typename detail::next_precision_impl< T >::type next_precision
Definition math.hpp:438
std::int64_t int64
Definition types.hpp:112
Definition matrix_data.hpp:126