5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_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/temporary_conversion.hpp>
18 #include <ginkgo/core/distributed/base.hpp>
19 #include <ginkgo/core/matrix/multivector.hpp>
23 namespace experimental {
24 namespace distributed {
28 template <
typename ValueType>
35 template <
typename LocalIndexType,
typename GlobalIndexType>
63 template <
typename ValueType =
double>
64 class Vector :
public EnableMultiVector<Vector<ValueType>>,
65 public ConvertibleTo<Vector<next_precision<ValueType>>>,
66 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
67 public ConvertibleTo<Vector<next_precision<ValueType, 2>>>,
69 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
70 public ConvertibleTo<Vector<next_precision<ValueType, 3>>>,
72 public DistributedBase {
73 friend class EnableMultiVector<Vector>;
77 friend class detail::VectorCache<ValueType>;
78 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
83 using ConvertibleTo<Vector<next_precision<ValueType>>>::convert_to;
84 using ConvertibleTo<Vector<next_precision<ValueType>>>::move_to;
92 using const_device_view =
111 ptr_param<
const Partition<int64, int64>> partition);
114 ptr_param<
const Partition<int32, int64>> partition);
117 ptr_param<
const Partition<int32, int32>> partition);
129 ptr_param<
const Partition<int64, int64>> partition);
132 ptr_param<
const Partition<int32, int64>> partition);
135 ptr_param<
const Partition<int32, int32>> partition);
137 void convert_to(Vector<next_precision<ValueType>>* result)
const override;
139 void move_to(Vector<next_precision<ValueType>>* result)
override;
141 #if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
143 using ConvertibleTo<Vector<next_precision<ValueType, 2>>>::convert_to;
144 using ConvertibleTo<Vector<next_precision<ValueType, 2>>>::move_to;
147 Vector<next_precision<ValueType, 2>>* result)
const override;
149 void move_to(Vector<next_precision<ValueType, 2>>* result)
override;
152 #if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
154 using ConvertibleTo<Vector<next_precision<ValueType, 3>>>::convert_to;
155 using ConvertibleTo<Vector<next_precision<ValueType, 3>>>::move_to;
158 Vector<next_precision<ValueType, 3>>* result)
const override;
160 void move_to(Vector<next_precision<ValueType, 3>>* result)
override;
171 void compute_mean(ptr_param<AbstractMultiVector> result)
const;
184 void compute_mean(ptr_param<AbstractMultiVector> result,
185 array<char>& tmp)
const;
262 template <
typename OtherValueType,
263 typename = std::enable_if_t<is_complex<ValueType>() ==
264 is_complex<OtherValueType>()>>
265 [[nodiscard]] temporary_conversion<Vector<OtherValueType>>
as_precision();
279 template <
typename OtherValueType,
280 typename = std::enable_if_t<is_complex<ValueType>() ==
281 is_complex<OtherValueType>()>>
282 [[nodiscard]] temporary_conversion<const Vector<OtherValueType>>
296 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
297 mpi::communicator comm,
298 dim<2> global_size, dim<2> local_size,
312 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
313 mpi::communicator comm,
314 dim<2> global_size = {},
315 dim<2> local_size = {});
334 static std::unique_ptr<Vector>
create(
335 std::shared_ptr<const Executor> exec, mpi::communicator comm,
336 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
356 static std::unique_ptr<Vector>
create(
357 std::shared_ptr<const Executor> exec, mpi::communicator comm,
358 std::unique_ptr<local_vector_type> local_vector);
373 std::shared_ptr<const Executor> exec, mpi::communicator comm,
375 std::unique_ptr<const local_vector_type> local_vector);
390 std::shared_ptr<const Executor> exec, mpi::communicator comm,
391 std::unique_ptr<const local_vector_type> local_vector);
394 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
395 dim<2> global_size, dim<2> local_size,
size_type stride);
397 explicit Vector(std::shared_ptr<const Executor> exec,
398 mpi::communicator comm, dim<2> global_size = {},
399 dim<2> local_size = {});
401 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
402 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
404 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
405 std::unique_ptr<local_vector_type> local_vector);
407 void resize(dim<2> global_size, dim<2> local_size);
409 template <
typename LocalIndexType,
typename GlobalIndexType>
410 void read_distributed_impl(
411 const device_matrix_data<ValueType, GlobalIndexType>& data,
412 const Partition<LocalIndexType, GlobalIndexType>* partition);
414 void compute_absolute_inplace_impl()
override;
416 [[nodiscard]] std::unique_ptr<Vector> create_with_same_config_impl()
419 [[nodiscard]] std::unique_ptr<Vector> create_with_type_of_impl(
420 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
421 const dim<2>& local_size,
size_type stride)
const override;
423 [[nodiscard]] std::unique_ptr<Vector> create_subview_impl(
424 local_span rows, local_span columns)
override;
426 [[nodiscard]] std::unique_ptr<const Vector> create_subview_impl(
427 local_span rows, local_span columns)
const override;
429 [[nodiscard]] std::unique_ptr<Vector> create_subview_impl(
430 local_span rows, local_span columns, dim<2> global_size)
override;
432 [[nodiscard]] std::unique_ptr<const Vector> create_subview_impl(
433 local_span rows, local_span columns, dim<2> global_size)
const override;
435 [[nodiscard]] std::unique_ptr<const real_type> create_real_view_impl()
438 [[nodiscard]] std::unique_ptr<real_type> create_real_view_impl()
override;
440 [[nodiscard]] std::unique_ptr<absolute_type> compute_absolute_impl()
443 void compute_absolute_impl(absolute_type* result)
const override;
445 [[nodiscard]] std::unique_ptr<complex_type> make_complex_impl()
448 [[nodiscard]] std::unique_ptr<real_type> get_real_impl()
const override;
450 [[nodiscard]] std::unique_ptr<real_type> get_imag_impl()
const override;
452 void make_complex_impl(complex_type* result)
const override;
454 void get_real_impl(real_type* result)
const override;
456 void get_imag_impl(real_type* result)
const override;
458 void fill_impl(value_type value)
override;
460 void scale_impl(scaling_param<value_type> alpha)
override;
462 void inv_scale_impl(scaling_param<value_type> alpha)
override;
464 void add_scaled_impl(scaling_param<value_type> alpha,
465 const Vector* b)
override;
467 void sub_scaled_impl(scaling_param<value_type> alpha,
468 const Vector* b)
override;
470 void compute_dot_impl(
const Vector* b,
471 matrix::MultiVector<value_type>* result,
472 array<char>& tmp)
const override;
474 void compute_conj_dot_impl(
const Vector* b,
475 matrix::MultiVector<value_type>* result,
476 array<char>& tmp)
const override;
478 void compute_norm2_impl(norm_type* result, array<char>& tmp)
const override;
480 void compute_squared_norm2_impl(norm_type* result,
481 array<char>& tmp)
const override;
483 void compute_norm1_impl(norm_type* result, array<char>& tmp)
const override;
485 device_view get_local_device_view_impl()
override;
487 const_device_view get_const_local_device_view_impl()
const override;
490 local_vector_type local_;
491 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
492 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
511 template <
typename ValueType>
512 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
513 template <
typename SourceValueType,
514 typename = std::enable_if_t<is_complex<ValueType>() ==
515 is_complex<SourceValueType>()>>
516 static std::unique_ptr<experimental::distributed::Vector<ValueType>>
518 const experimental::distributed::Vector<SourceValueType>* source)
521 source->get_executor(), source->get_communicator());
530 #endif // GINKGO_BUILD_MPI
533 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_