Ginkgo  Generated from pipelines/3035309441 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 LinOp> local_values) const;
82 
94  void wait_and_accumulate(ptr_param<LinOp> distributed_target) const;
95 
99  dim<2> get_size() const;
100 
104  std::shared_ptr<const mpi::CollectiveCommunicator>
106 
111  const LocalIndexType* get_const_recv_idxs() const;
112 
117 
133  template <typename GlobalIndexType = int64,
134  typename = std::enable_if_t<sizeof(GlobalIndexType) >=
135  sizeof(LocalIndexType)>>
136  static std::unique_ptr<RowScatterer> create(
137  std::shared_ptr<const Executor> exec,
138  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
140  {
141  return std::unique_ptr<RowScatterer>(
142  new RowScatterer(std::move(exec), std::move(coll_comm), imap));
143  }
144 
157  static std::unique_ptr<RowScatterer> create_from_gatherer(
158  std::shared_ptr<const Executor> exec,
159  ptr_param<const RowGatherer<LocalIndexType>> gatherer);
160 
164  static std::unique_ptr<RowScatterer> create(
165  std::shared_ptr<const Executor> exec, mpi::communicator comm);
166 
167  RowScatterer(const RowScatterer& o);
168 
170 
171  RowScatterer& operator=(const RowScatterer& o);
172 
173  RowScatterer& operator=(RowScatterer&& o);
174 
175 private:
176  template <typename GlobalIndexType>
177  RowScatterer(std::shared_ptr<const Executor> exec,
178  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
180 
181  RowScatterer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
182 
183  RowScatterer(std::shared_ptr<const Executor> exec,
184  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
185  array<LocalIndexType> recv_idxs, dim<2> size);
186 
187  dim<2> size_;
188  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
189  array<LocalIndexType> recv_idxs_; // local indices to accumulate into
190  mutable gko::detail::GenericDenseCache send_cache_;
191  // request and receive buffer of the active apply_async, consumed by
192  // wait_and_accumulate
193  mutable mpi::request req_;
194  mutable std::shared_ptr<LinOp> recv_buffer_;
195  mutable gko::detail::GenericDenseCache recv_cache_;
196 };
197 
198 
199 } // namespace distributed
200 } // namespace experimental
201 } // namespace gko
202 
203 #endif
204 #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:101
gko::experimental::distributed::RowScatterer::wait_and_accumulate
void wait_and_accumulate(ptr_param< LinOp > distributed_target) const
Wait for the scatter communication to complete and accumulate received values into the target: target...
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:136
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::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:124
gko::experimental::distributed::RowScatterer::apply_async
void apply_async(ptr_param< const LinOp > local_values) const
Start scattering local values to their owning ranks.
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