Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
row_gatherer.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_GATHERER_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_ROW_GATHERER_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/event.hpp>
17 #include <ginkgo/core/base/lin_op.hpp>
18 #include <ginkgo/core/base/mpi.hpp>
19 #include <ginkgo/core/distributed/base.hpp>
20 #include <ginkgo/core/distributed/collective_communicator.hpp>
21 #include <ginkgo/core/distributed/index_map.hpp>
22 
23 
24 namespace gko {
25 namespace experimental {
26 namespace distributed {
27 
28 
29 template <typename LocalIndexType>
31 
32 
33 namespace detail {
34 
35 
36 // give access to test function on protected function
37 template <typename LocalIndexType>
38 std::shared_ptr<const gko::detail::Event> apply_prepare(
40 
41 // give access to test function on protected function
42 template <typename LocalIndexType>
43 std::shared_ptr<const gko::detail::Event> apply_prepare(
45  gko::detail::GenericDenseCache& workspace);
46 
47 // give access to test function on protected function
48 template <typename LocalIndexType>
49 mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
51  std::shared_ptr<const gko::detail::Event>);
52 
53 // give access to test function on protected function
54 template <typename LocalIndexType>
55 mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
57  std::shared_ptr<const gko::detail::Event>,
58  gko::detail::GenericDenseCache& workspace);
59 
60 
61 } // namespace detail
62 
63 
90 template <typename LocalIndexType = int32>
91 class RowGatherer final : public PolymorphicObject,
92  public EnableCloneable<RowGatherer<LocalIndexType>>,
93  public DistributedBase {
94  friend class EnableCloneable<RowGatherer>;
95  template <typename ValueT, typename LocalIndexT, typename GlobalIndexT>
96  friend class Matrix;
97  // for test purpose
98  friend std::shared_ptr<const gko::detail::Event>
99  detail::apply_prepare<LocalIndexType>(const RowGatherer* rg,
101  friend std::shared_ptr<const gko::detail::Event> detail::apply_prepare<
102  LocalIndexType>(const RowGatherer* rg, ptr_param<const LinOp> b,
103  gko::detail::GenericDenseCache& workspace);
104  friend mpi::request detail::apply_finalize<LocalIndexType>(
106  std::shared_ptr<const gko::detail::Event>);
107  friend mpi::request detail::apply_finalize<LocalIndexType>(
109  std::shared_ptr<const gko::detail::Event>,
110  gko::detail::GenericDenseCache& workspace);
111 
112 public:
129  ptr_param<LinOp> x) const;
130 
149  [[nodiscard]] mpi::request apply_async(
151  gko::detail::GenericDenseCache& workspace) const;
152 
156  dim<2> get_size() const;
157 
161  std::shared_ptr<const mpi::CollectiveCommunicator>
163 
167  const LocalIndexType* get_const_send_idxs() const;
168 
173 
194  template <typename GlobalIndexType = int64,
195  typename = std::enable_if_t<sizeof(GlobalIndexType) >=
196  sizeof(LocalIndexType)>>
197  static std::unique_ptr<RowGatherer> create(
198  std::shared_ptr<const Executor> exec,
199  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
201  {
202  return std::unique_ptr<RowGatherer>(
203  new RowGatherer(std::move(exec), std::move(coll_comm), imap));
204  }
205 
206  /*
207  * Create method for an empty RowGatherer.
208  */
209  static std::unique_ptr<RowGatherer> create(
210  std::shared_ptr<const Executor> exec, mpi::communicator comm);
211 
212  /*
213  * Create method for an empty RowGatherer with an template for the
214  * collective communicator.
215  *
216  * This is mainly used for creating a new RowGatherer with the same runtime
217  * type for the collective communicator, e.g.:
218  * ```c++
219  * auto rg = RowGatherer<>::create(
220  * exec, std::make_shared<mpi::NeighborhoodCommunicator>(comm));
221  * ...
222  * rg = RowGatherer<>::create(
223  * exec,
224  * rg->get_collective_communicator()->create_with_same_type(comm, &imap),
225  * imap);
226  * ```
227  */
228  static std::unique_ptr<RowGatherer> create(
229  std::shared_ptr<const Executor> exec,
230  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
231 
232  RowGatherer(const RowGatherer& o);
233 
234  RowGatherer(RowGatherer&& o) noexcept;
235 
236  RowGatherer& operator=(const RowGatherer& o);
237 
238  RowGatherer& operator=(RowGatherer&& o);
239 
240 protected:
241  std::shared_ptr<const gko::detail::Event> apply_prepare(
242  ptr_param<const LinOp> b) const;
243 
244  std::shared_ptr<const gko::detail::Event> apply_prepare(
246  gko::detail::GenericDenseCache& workspace) const;
247 
248  mpi::request apply_finalize(
250  std::shared_ptr<const gko::detail::Event>) const;
251 
252  mpi::request apply_finalize(
254  std::shared_ptr<const gko::detail::Event>,
255  gko::detail::GenericDenseCache& workspace) const;
256 
257 private:
263  template <typename GlobalIndexType>
264  RowGatherer(std::shared_ptr<const Executor> exec,
265  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
267 
272  RowGatherer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
273 
278  RowGatherer(
279  std::shared_ptr<const Executor> exec,
280  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
281 
282  dim<2> size_;
283  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
284  array<LocalIndexType> send_idxs_;
285  mutable gko::detail::GenericDenseCache send_cache_;
286 };
287 
288 
289 } // namespace distributed
290 } // namespace experimental
291 } // namespace gko
292 
293 #endif
294 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_ROW_GATHERER_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::Matrix
The Matrix class defines a (MPI-)distributed matrix.
Definition: matrix.hpp:262
gko::experimental::distributed::RowGatherer::get_size
dim< 2 > get_size() const
Returns the size of the row gatherer.
gko::PolymorphicObject
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition: polymorphic_object.hpp:46
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
gko::experimental::mpi::request
The request class is a light, move-only wrapper around the MPI_Request handle.
Definition: mpi.hpp:331
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::array< LocalIndexType >
gko::experimental::distributed::RowGatherer::get_num_send_idxs
size_type get_num_send_idxs() const
Returns the number of (local) row indices.
gko::experimental::mpi::communicator
A thin wrapper of MPI_Comm that supports most MPI calls.
Definition: mpi.hpp:419
gko::dim< 2 >
gko::experimental::distributed::RowGatherer::create
static std::unique_ptr< RowGatherer > create(std::shared_ptr< const Executor > exec, std::shared_ptr< const mpi::CollectiveCommunicator > coll_comm, const index_map< LocalIndexType, GlobalIndexType > &imap)
Creates a distributed::RowGatherer from a given collective communicator and index map.
Definition: row_gatherer.hpp:197
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:43
gko::experimental::distributed::RowGatherer::get_const_send_idxs
const LocalIndexType * get_const_send_idxs() const
Read access to the (local) rows indices.
gko::experimental::distributed::RowGatherer::get_collective_communicator
std::shared_ptr< const mpi::CollectiveCommunicator > get_collective_communicator() const
Get the used collective communicator.
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:369
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:113
gko::experimental::distributed::RowGatherer::apply_async
mpi::request apply_async(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Asynchronous version of LinOp::apply.
gko::experimental::distributed::DistributedBase
A base class for distributed objects.
Definition: base.hpp:32
gko::experimental::distributed::index_map
This class defines mappings between global and local indices.
Definition: index_map.hpp:68