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/lin_op.hpp>
17 #include <ginkgo/core/base/mpi.hpp>
18 #include <ginkgo/core/distributed/base.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 EnableLinOp<Vector<ValueType>>,
69 public ConvertibleTo<Vector<next_precision_base<ValueType>>>,
70 public EnableAbsoluteComputation<remove_complex<Vector<ValueType>>>,
71 public DistributedBase {
72 friend class EnablePolymorphicObject<Vector,
LinOp>;
76 friend class detail::VectorCache<ValueType>;
81 using ConvertibleTo<Vector<next_precision_base<ValueType>>>::convert_to;
82 using ConvertibleTo<Vector<next_precision_base<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);
172 Vector<next_precision_base<ValueType>>* result)
const override;
174 void move_to(Vector<next_precision_base<ValueType>>* result)
override;
191 void make_complex(ptr_param<complex_type> result)
const;
197 std::unique_ptr<real_type>
get_real()
const;
202 void get_real(ptr_param<real_type> result)
const;
208 std::unique_ptr<real_type>
get_imag()
const;
214 void get_imag(ptr_param<real_type> result)
const;
221 void fill(ValueType value);
232 void scale(ptr_param<const LinOp> alpha);
243 void inv_scale(ptr_param<const LinOp> alpha);
254 void add_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
264 void sub_scaled(ptr_param<const LinOp> alpha, ptr_param<const LinOp> b);
275 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result)
const;
289 void compute_dot(ptr_param<const LinOp> b, ptr_param<LinOp> result,
290 array<char>& tmp)
const;
302 ptr_param<LinOp> result)
const;
317 array<char>& tmp)
const;
363 void compute_norm2(ptr_param<LinOp> result, array<char>& tmp)
const;
385 void compute_norm1(ptr_param<LinOp> result, array<char>& tmp)
const;
408 void compute_mean(ptr_param<LinOp> result, array<char>& tmp)
const;
498 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
499 mpi::communicator comm,
500 dim<2> global_size, dim<2> local_size,
514 static std::unique_ptr<Vector>
create(std::shared_ptr<const Executor> exec,
515 mpi::communicator comm,
516 dim<2> global_size = {},
517 dim<2> local_size = {});
536 static std::unique_ptr<Vector>
create(
537 std::shared_ptr<const Executor> exec, mpi::communicator comm,
538 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
558 static std::unique_ptr<Vector>
create(
559 std::shared_ptr<const Executor> exec, mpi::communicator comm,
560 std::unique_ptr<local_vector_type> local_vector);
575 std::shared_ptr<const Executor> exec, mpi::communicator comm,
577 std::unique_ptr<const local_vector_type> local_vector);
592 std::shared_ptr<const Executor> exec, mpi::communicator comm,
593 std::unique_ptr<const local_vector_type> local_vector);
596 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
597 dim<2> global_size, dim<2> local_size,
size_type stride);
599 explicit Vector(std::shared_ptr<const Executor> exec,
600 mpi::communicator comm, dim<2> global_size = {},
601 dim<2> local_size = {});
603 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
604 dim<2> global_size, std::unique_ptr<local_vector_type> local_vector);
606 Vector(std::shared_ptr<const Executor> exec, mpi::communicator comm,
607 std::unique_ptr<local_vector_type> local_vector);
609 void resize(dim<2> global_size, dim<2> local_size);
611 template <
typename LocalIndexType,
typename GlobalIndexType>
612 void read_distributed_impl(
613 const device_matrix_data<ValueType, GlobalIndexType>& data,
614 const Partition<LocalIndexType, GlobalIndexType>* partition);
616 void apply_impl(
const LinOp*,
LinOp*)
const override;
619 LinOp*)
const override;
627 virtual std::unique_ptr<Vector> create_with_same_config()
const;
641 virtual std::unique_ptr<Vector> create_with_type_of_impl(
642 std::shared_ptr<const Executor> exec,
const dim<2>& global_size,
643 const dim<2>& local_size,
size_type stride)
const;
646 local_vector_type local_;
647 ::gko::detail::DenseCache<ValueType> host_reduction_buffer_;
648 ::gko::detail::DenseCache<remove_complex<ValueType>> host_norm_buffer_;
659 template <
typename TargetType>
660 struct conversion_target_helper;
672 template <
typename ValueType>
673 struct conversion_target_helper<experimental::distributed::Vector<ValueType>> {
674 using target_type = experimental::distributed::Vector<ValueType>;
676 experimental::distributed::Vector<previous_precision_base<ValueType>>;
678 static std::unique_ptr<target_type> create_empty(
const source_type* source)
680 return target_type::create(source->get_executor(),
681 source->get_communicator());
690 #endif // GINKGO_BUILD_MPI
693 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_VECTOR_HPP_