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>
27 template <
typename ValueType,
typename IndexType>
37 template <
typename ValueType,
typename IndexType>
51 template <
typename Builder,
typename ValueType,
typename IndexType,
53 struct is_matrix_type_builder : std::false_type {};
56 template <
typename Builder,
typename ValueType,
typename IndexType>
57 struct 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>>()))>>
65 template <
template <
typename,
typename>
class MatrixType,
66 typename... CreateArgs>
67 struct 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;
124 template <
template <
typename,
typename>
class MatrixType,
typename... Args>
127 return detail::MatrixTypeBuilderFromValueAndIndex<MatrixType, Args...>{
128 std::forward_as_tuple(create_args...)};
132 namespace experimental {
133 namespace distributed {
148 template <
typename LocalIndexType,
typename GlobalIndexType>
150 template <
typename ValueType>
259 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
261 :
public EnableLinOp<Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
263 LocalIndexType, GlobalIndexType>>,
271 using value_type = ValueType;
272 using index_type = GlobalIndexType;
273 using local_index_type = LocalIndexType;
274 using global_index_type = GlobalIndexType;
282 GlobalIndexType>>::convert_to;
284 GlobalIndexType>>::move_to;
287 global_index_type>* result)
const override;
290 global_index_type>* result)
override;
387 return non_local_mtx_;
433 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
456 template <
typename MatrixType,
457 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
458 MatrixType, ValueType, LocalIndexType>::value>>
459 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
461 MatrixType matrix_template)
465 matrix_template.template create<ValueType, LocalIndexType>(exec));
496 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
497 typename = std::enable_if_t<
498 gko::detail::is_matrix_type_builder<
499 LocalMatrixType, ValueType, LocalIndexType>::value &&
500 gko::detail::is_matrix_type_builder<
501 NonLocalMatrixType, ValueType, LocalIndexType>::value>>
504 LocalMatrixType local_matrix_template,
505 NonLocalMatrixType non_local_matrix_template)
509 local_matrix_template.template create<ValueType, LocalIndexType>(
511 non_local_matrix_template
512 .template create<ValueType, LocalIndexType>(exec));
529 static std::unique_ptr<Matrix>
create(
549 static std::unique_ptr<Matrix>
create(
566 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
568 std::shared_ptr<LinOp> local_linop);
588 static std::unique_ptr<Matrix>
create(
590 dim<2> size, std::shared_ptr<LinOp> local_linop,
591 std::shared_ptr<LinOp> non_local_linop,
592 std::vector<comm_index_type> recv_sizes,
593 std::vector<comm_index_type> recv_offsets,
615 explicit Matrix(std::shared_ptr<const Executor> exec,
618 explicit Matrix(std::shared_ptr<const Executor> exec,
623 explicit Matrix(std::shared_ptr<const Executor> exec,
625 std::shared_ptr<LinOp> local_linop);
627 explicit Matrix(std::shared_ptr<const Executor> exec,
629 std::shared_ptr<LinOp> local_linop,
630 std::shared_ptr<LinOp> non_local_linop,
631 std::vector<comm_index_type> recv_sizes,
632 std::vector<comm_index_type> recv_offsets,
643 mpi::request communicate(
const local_vector_type* local_b)
const;
645 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
648 LinOp* x)
const override;
651 std::vector<comm_index_type> send_offsets_;
652 std::vector<comm_index_type> send_sizes_;
653 std::vector<comm_index_type> recv_offsets_;
654 std::vector<comm_index_type> recv_sizes_;
657 gko::detail::DenseCache<value_type> one_scalar_;
658 gko::detail::DenseCache<value_type> host_send_buffer_;
659 gko::detail::DenseCache<value_type> host_recv_buffer_;
660 gko::detail::DenseCache<value_type> send_buffer_;
661 gko::detail::DenseCache<value_type> recv_buffer_;
662 std::shared_ptr<LinOp> local_mtx_;
663 std::shared_ptr<LinOp> non_local_mtx_;
675 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_