Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
row_scatterer.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_ROW_SCATTERER_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_ROW_SCATTERER_HPP_
7 
8 
9 #include <ginkgo/config.hpp>
10 
11 
12 #if GINKGO_BUILD_MPI
13 
14 
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/distributed/collective_communicator.hpp>
20 #include <ginkgo/core/distributed/index_map.hpp>
21 #include <ginkgo/core/distributed/row_gatherer.hpp>
22 
23 
24 namespace gko {
25 namespace experimental {
26 namespace distributed {
27 
28 
60 template <typename LocalIndexType = int32>
61 class RowScatterer final : public PolymorphicObject,
62  public EnableCloneable<RowScatterer<LocalIndexType>>,
63  public DistributedBase {
64  friend class EnableCloneable<RowScatterer>;
65 
66 public:
81  void apply_async(ptr_param<const AbstractMultiVector> local_values) const;
82 
95  ptr_param<AbstractMultiVector> distributed_target) const;
96 
100  dim<2> get_size() const;
101 
105  std::shared_ptr<const mpi::CollectiveCommunicator>
107 
112  const LocalIndexType* get_const_recv_idxs() const;
113 
118 
134  template <typename GlobalIndexType = int64,
135  typename = std::enable_if_t<sizeof(GlobalIndexType) >=
136  sizeof(LocalIndexType)>>
137  static std::unique_ptr<RowScatterer> create(
138  std::shared_ptr<const Executor> exec,
139  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
141  {
142  return std::unique_ptr<RowScatterer>(
143  new RowScatterer(std::move(exec), std::move(coll_comm), imap));
144  }
145 
158  static std::unique_ptr<RowScatterer> create_from_gatherer(
159  std::shared_ptr<const Executor> exec,
160  ptr_param<const RowGatherer<LocalIndexType>> gatherer);
161 
165  static std::unique_ptr<RowScatterer> create(
166  std::shared_ptr<const Executor> exec, mpi::communicator comm);
167 
168  RowScatterer(const RowScatterer& o);
169 
171 
172  RowScatterer& operator=(const RowScatterer& o);
173 
174  RowScatterer& operator=(RowScatterer&& o);
175 
176 private:
177  template <typename GlobalIndexType>
178  RowScatterer(std::shared_ptr<const Executor> exec,
179  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
181 
182  RowScatterer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
183 
184  RowScatterer(std::shared_ptr<const Executor> exec,
185  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
186  array<LocalIndexType> recv_idxs, dim<2> size);
187 
188  dim<2> size_;
189  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
190  array<LocalIndexType> recv_idxs_; // local indices to accumulate into
191  mutable gko::detail::GenericDenseCache send_cache_;
192  // request and receive buffer of the active apply_async, consumed by
193  // wait_and_accumulate
194  mutable mpi::request req_;
195  mutable std::shared_ptr<AbstractMultiVector> recv_buffer_;
196  mutable gko::detail::GenericDenseCache recv_cache_;
197 };
198 
199 
200 } // namespace distributed
201 } // namespace experimental
202 } // namespace gko
203 
204 #endif
205 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_ROW_SCATTERER_HPP_
gko::experimental::distributed::RowGatherer
The distributed::RowGatherer gathers the rows of distributed::Vector that are located on other proces...
Definition: row_gatherer.hpp:30
gko::experimental::distributed::RowScatterer::get_size
dim< 2 > get_size() const
Returns the size of the row scatterer.
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::experimental::distributed::RowScatterer::create
static std::unique_ptr< RowScatterer > create(std::shared_ptr< const Executor > exec, std::shared_ptr< const mpi::CollectiveCommunicator > coll_comm, const index_map< LocalIndexType, GlobalIndexType > &imap)
Creates a distributed::RowScatterer from a given collective communicator and index map.
Definition: row_scatterer.hpp:137
gko::experimental::mpi::request
The request class is a light, move-only wrapper around the MPI_Request handle.
Definition: mpi.hpp:330
gko::experimental::distributed::RowScatterer::get_num_recv_idxs
size_type get_num_recv_idxs() const
Returns the number of (local) row indices.
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::array< LocalIndexType >
gko::experimental::mpi::communicator
A thin wrapper of MPI_Comm that supports most MPI calls.
Definition: mpi.hpp:418
gko::dim< 2 >
gko::experimental::distributed::RowScatterer::wait_and_accumulate
void wait_and_accumulate(ptr_param< AbstractMultiVector > distributed_target) const
Wait for the scatter communication to complete and accumulate received values into the target: target...
gko::experimental::distributed::RowScatterer::get_const_recv_idxs
const LocalIndexType * get_const_recv_idxs() const
Read access to the (local) row indices into which the received values are accumulated.
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::experimental::distributed::RowScatterer::get_collective_communicator
std::shared_ptr< const mpi::CollectiveCommunicator > get_collective_communicator() const
Get the used collective communicator.
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:125
gko::experimental::distributed::RowScatterer::create_from_gatherer
static std::unique_ptr< RowScatterer > create_from_gatherer(std::shared_ptr< const Executor > exec, ptr_param< const RowGatherer< LocalIndexType >> gatherer)
Creates a distributed::RowScatterer from an existing RowGatherer.
gko::experimental::distributed::RowScatterer
The distributed::RowScatterer scatters local values to their owning processes and accumulates receive...
Definition: row_gatherer.hpp:33
gko::experimental::distributed::index_map
This class defines mappings between global and local indices.
Definition: index_map.hpp:70
gko::experimental::distributed::RowScatterer::apply_async
void apply_async(ptr_param< const AbstractMultiVector > local_values) const
Start scattering local values to their owning ranks.