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/distributed/base.hpp>
18 #include <ginkgo/core/distributed/lin_op.hpp>
19 #include <ginkgo/core/matrix/dense.hpp>
23 namespace experimental {
24 namespace distributed {
27 template <
typename LocalIndexType,
typename GlobalIndexType>
58 template <
typename ValueType =
double>
60 :
public EnableDistributedLinOp<Vector<ValueType>>,
61 public ConvertibleTo<Vector<next_precision<ValueType>>>,
62 public EnableAbsoluteComputation<remove_complex<Vector<ValueType>>>,
63 public DistributedBase {
64 friend class EnableDistributedPolymorphicObject<Vector,
LinOp>;
72 using ConvertibleTo<Vector<next_precision<ValueType>>>::convert_to;
73 using ConvertibleTo<Vector<next_precision<ValueType>>>::move_to;
75 using value_type = ValueType;
76 using absolute_type = remove_complex<Vector>;
77 using real_type = absolute_type;
78 using complex_type = Vector<to_complex<value_type>>;
88 ptr_param<const Vector> other);
103 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec);
118 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec,
119 const dim<2>& global_size,
const dim<2>& local_size,
size_type stride);
136 ptr_param<
const Partition<int64, int64>> partition);
139 ptr_param<
const Partition<int32, int64>> partition);
142 ptr_param<
const Partition<int32, int32>> partition);
154 ptr_param<
const Partition<int64, int64>> partition);
157 ptr_param<
const Partition<int32, int64>> partition);
160 ptr_param<
const Partition<int32, int32>> partition);
162 void convert_to(Vector<next_precision<ValueType>>* result)
const override;
164 void move_to(Vector<next_precision<ValueType>>* result)
override;
181 void make_complex(ptr_param<complex_type> result)
const;
187 std::unique_ptr<real_type>
get_real()
const;
192 void get_real(ptr_param<real_type> result)
const;
198 std::unique_ptr<real_type>
get_imag()
const;
204 void get_imag(ptr_param<real_type> result)
const;
211 void fill(ValueType value);
222 void scale(ptr_param<const LinOp> alpha);
233 void inv_scale(ptr_param<const LinOp> alpha);
244 void add_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
254 void sub_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
265 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result)
const;
279 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result,
280 array<char>& tmp)
const;
292 ptr_param<LinOp> result)
const;
307 array<char>& tmp)
const;
353 void compute_norm2(ptr_param<LinOp> result, array<char>& tmp)
const;
375 void compute_norm1(ptr_param<LinOp> result, array<char>& tmp)
const;
398 void compute_mean(ptr_param<LinOp> result, array<char>& tmp)
const;
488 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
489 mpi::communicator comm,
490 dim<2> global_size, dim<2> local_size,
504 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
505 mpi::communicator comm,
506 dim<2> global_size = {},
507 dim<2> local_size = {});
526 static std::unique_ptr<Vector>
create(
527 std::shared_ptr<const Executor> exec, mpi::communicator comm,
528 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
548 static std::unique_ptr<Vector>
create(
549 std::shared_ptr<const Executor> exec, mpi::communicator comm,
550 std::unique_ptr<local_vector_type> local_vector);
565 std::shared_ptr<const Executor> exec, mpi::communicator comm,
567 std::unique_ptr<const local_vector_type> local_vector);
582 std::shared_ptr<const Executor> exec, mpi::communicator comm,
583 std::unique_ptr<const local_vector_type> local_vector);
586 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
587 dim<2> global_size, dim<2> local_size,
size_type stride);
589 explicit Vector(std::shared_ptr<const Executor> exec,
590 mpi::communicator comm, dim<2> global_size = {},
591 dim<2> local_size = {});
593 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
594 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
596 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
597 std::unique_ptr<local_vector_type> local_vector);
599 void resize(dim<2> global_size, dim<2> local_size);
601 template <
typename LocalIndexType,
typename GlobalIndexType>
602 void read_distributed_impl(
603 const device_matrix_data<ValueType, GlobalIndexType>& data,
604 const Partition<LocalIndexType, GlobalIndexType>* partition);
606 void apply_impl(
const LinOp*,
LinOp*)
const override;
609 LinOp*)
const override;
617 virtual std::unique_ptr<Vector> create_with_same_config()
const;
631 virtual std::unique_ptr<Vector> create_with_type_of_impl(
632 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
633 const dim<2>& local_size,
size_type stride)
const;
636 local_vector_type local_;
637 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
638 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
649 template <
typename TargetType>
650 struct conversion_target_helper;
662 template <
typename ValueType>
663 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
664 using target_type = experimental::distributed::Vector<ValueType>;
666 experimental::distributed::Vector<previous_precision<ValueType>>;
668 static std::unique_ptr<target_type> create_empty(
const source_type* source)
670 return target_type::create(source->get_executor(),
671 source->get_communicator());
680 #endif // GINKGO_BUILD_MPI
683 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_