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 {
28 template <
typename ValueType>
35 template <
typename LocalIndexType,
typename GlobalIndexType>
66 template <
typename ValueType =
double>
68 :
public EnableDistributedLinOp<Vector<ValueType>>,
69 public ConvertibleTo<Vector<next_precision<ValueType>>>,
70 public EnableAbsoluteComputation<remove_complex<Vector<ValueType>>>,
71 public DistributedBase {
72 friend class EnableDistributedPolymorphicObject<Vector,
LinOp>;
76 friend class detail::VectorCache<ValueType>;
81 using ConvertibleTo<Vector<next_precision<ValueType>>>::convert_to;
82 using ConvertibleTo<Vector<next_precision<ValueType>>>::move_to;
84 using value_type = ValueType;
85 using absolute_type = remove_complex<Vector>;
86 using real_type = absolute_type;
87 using complex_type = Vector<to_complex<value_type>>;
97 ptr_param<const Vector> other);
112 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec);
127 ptr_param<const Vector> other, std::shared_ptr<const Executor> exec,
128 const dim<2>& global_size,
const dim<2>& local_size,
size_type stride);
145 ptr_param<
const Partition<int64, int64>> partition);
148 ptr_param<
const Partition<int32, int64>> partition);
151 ptr_param<
const Partition<int32, int32>> partition);
163 ptr_param<
const Partition<int64, int64>> partition);
166 ptr_param<
const Partition<int32, int64>> partition);
169 ptr_param<
const Partition<int32, int32>> partition);
171 void convert_to(Vector<next_precision<ValueType>>* result)
const override;
173 void move_to(Vector<next_precision<ValueType>>* result)
override;
190 void make_complex(ptr_param<complex_type> result)
const;
196 std::unique_ptr<real_type>
get_real()
const;
201 void get_real(ptr_param<real_type> result)
const;
207 std::unique_ptr<real_type>
get_imag()
const;
213 void get_imag(ptr_param<real_type> result)
const;
220 void fill(ValueType value);
231 void scale(ptr_param<const LinOp> alpha);
242 void inv_scale(ptr_param<const LinOp> alpha);
253 void add_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
263 void sub_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
274 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result)
const;
288 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result,
289 array<char>& tmp)
const;
301 ptr_param<LinOp> result)
const;
316 array<char>& tmp)
const;
362 void compute_norm2(ptr_param<LinOp> result, array<char>& tmp)
const;
384 void compute_norm1(ptr_param<LinOp> result, array<char>& tmp)
const;
407 void compute_mean(ptr_param<LinOp> result, array<char>& tmp)
const;
497 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
498 mpi::communicator comm,
499 dim<2> global_size, dim<2> local_size,
513 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
514 mpi::communicator comm,
515 dim<2> global_size = {},
516 dim<2> local_size = {});
535 static std::unique_ptr<Vector>
create(
536 std::shared_ptr<const Executor> exec, mpi::communicator comm,
537 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
557 static std::unique_ptr<Vector>
create(
558 std::shared_ptr<const Executor> exec, mpi::communicator comm,
559 std::unique_ptr<local_vector_type> local_vector);
574 std::shared_ptr<const Executor> exec, mpi::communicator comm,
576 std::unique_ptr<const local_vector_type> local_vector);
591 std::shared_ptr<const Executor> exec, mpi::communicator comm,
592 std::unique_ptr<const local_vector_type> local_vector);
595 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
596 dim<2> global_size, dim<2> local_size,
size_type stride);
598 explicit Vector(std::shared_ptr<const Executor> exec,
599 mpi::communicator comm, dim<2> global_size = {},
600 dim<2> local_size = {});
602 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
603 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
605 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
606 std::unique_ptr<local_vector_type> local_vector);
608 void resize(dim<2> global_size, dim<2> local_size);
610 template <
typename LocalIndexType,
typename GlobalIndexType>
611 void read_distributed_impl(
612 const device_matrix_data<ValueType, GlobalIndexType>& data,
613 const Partition<LocalIndexType, GlobalIndexType>* partition);
615 void apply_impl(
const LinOp*,
LinOp*)
const override;
618 LinOp*)
const override;
626 virtual std::unique_ptr<Vector> create_with_same_config()
const;
640 virtual std::unique_ptr<Vector> create_with_type_of_impl(
641 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
642 const dim<2>& local_size,
size_type stride)
const;
645 local_vector_type local_;
646 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
647 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
658 template <
typename TargetType>
659 struct conversion_target_helper;
671 template <
typename ValueType>
672 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
673 using target_type = experimental::distributed::Vector<ValueType>;
675 experimental::distributed::Vector<previous_precision<ValueType>>;
677 static std::unique_ptr<target_type> create_empty(
const source_type* source)
679 return target_type::create(source->get_executor(),
680 source->get_communicator());
689 #endif // GINKGO_BUILD_MPI
692 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_