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/base/std_extensions.hpp>
18 #include <ginkgo/core/distributed/base.hpp>
19 #include <ginkgo/core/distributed/index_map.hpp>
20 #include <ginkgo/core/distributed/lin_op.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 {
136 template <
typename LocalIndexType,
typename GlobalIndexType>
138 template <
typename ValueType>
247 typename LocalIndexType =
int32,
typename GlobalIndexType =
int64>
250 Matrix<ValueType, LocalIndexType, GlobalIndexType>>,
252 Matrix<next_precision<ValueType>, LocalIndexType, GlobalIndexType>>,
260 using value_type = ValueType;
261 using index_type = GlobalIndexType;
262 using local_index_type = LocalIndexType;
263 using global_index_type = GlobalIndexType;
271 GlobalIndexType>>::convert_to;
273 GlobalIndexType>>::move_to;
276 global_index_type>* result)
const override;
279 global_index_type>* result)
override;
370 return non_local_mtx_;
416 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
439 template <
typename MatrixType,
440 typename = std::enable_if_t<gko::detail::is_matrix_type_builder<
441 MatrixType, ValueType, LocalIndexType>::value>>
442 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
444 MatrixType matrix_template)
448 matrix_template.template create<ValueType, LocalIndexType>(exec));
479 template <
typename LocalMatrixType,
typename NonLocalMatrixType,
480 typename = std::enable_if_t<
481 gko::detail::is_matrix_type_builder<
482 LocalMatrixType, ValueType, LocalIndexType>::value &&
483 gko::detail::is_matrix_type_builder<
484 NonLocalMatrixType, ValueType, LocalIndexType>::value>>
487 LocalMatrixType local_matrix_template,
488 NonLocalMatrixType non_local_matrix_template)
492 local_matrix_template.template create<ValueType, LocalIndexType>(
494 non_local_matrix_template
495 .template create<ValueType, LocalIndexType>(exec));
512 static std::unique_ptr<Matrix>
create(
532 static std::unique_ptr<Matrix>
create(
549 static std::unique_ptr<Matrix>
create(std::shared_ptr<const Executor> exec,
551 std::shared_ptr<LinOp> local_linop);
571 static std::unique_ptr<Matrix>
create(
573 dim<2> size, std::shared_ptr<LinOp> local_linop,
574 std::shared_ptr<LinOp> non_local_linop,
575 std::vector<comm_index_type> recv_sizes,
576 std::vector<comm_index_type> recv_offsets,
598 explicit Matrix(std::shared_ptr<const Executor> exec,
601 explicit Matrix(std::shared_ptr<const Executor> exec,
606 explicit Matrix(std::shared_ptr<const Executor> exec,
608 std::shared_ptr<LinOp> local_linop);
610 explicit Matrix(std::shared_ptr<const Executor> exec,
612 std::shared_ptr<LinOp> local_linop,
613 std::shared_ptr<LinOp> non_local_linop,
614 std::vector<comm_index_type> recv_sizes,
615 std::vector<comm_index_type> recv_offsets,
626 mpi::request communicate(
const local_vector_type* local_b)
const;
628 void apply_impl(
const LinOp* b,
LinOp* x)
const override;
631 LinOp* x)
const override;
634 std::vector<comm_index_type> send_offsets_;
635 std::vector<comm_index_type> send_sizes_;
636 std::vector<comm_index_type> recv_offsets_;
637 std::vector<comm_index_type> recv_sizes_;
640 gko::detail::DenseCache<value_type> one_scalar_;
641 gko::detail::DenseCache<value_type> host_send_buffer_;
642 gko::detail::DenseCache<value_type> host_recv_buffer_;
643 gko::detail::DenseCache<value_type> send_buffer_;
644 gko::detail::DenseCache<value_type> recv_buffer_;
645 std::shared_ptr<LinOp> local_mtx_;
646 std::shared_ptr<LinOp> non_local_mtx_;
658 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_MATRIX_HPP_