Ginkgo  Generated from pipelines/3035309441 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 template <typename LocalIndexType>
34 
35 
36 namespace detail {
37 
38 
39 // give access to test function on protected function
40 template <typename LocalIndexType>
41 std::shared_ptr<const gko::detail::Event> apply_prepare(
43 
44 // give access to test function on protected function
45 template <typename LocalIndexType>
46 std::shared_ptr<const gko::detail::Event> apply_prepare(
48  gko::detail::GenericDenseCache& workspace);
49 
50 // give access to test function on protected function
51 template <typename LocalIndexType>
52 mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
54  std::shared_ptr<const gko::detail::Event>);
55 
56 // give access to test function on protected function
57 template <typename LocalIndexType>
58 mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
60  std::shared_ptr<const gko::detail::Event>,
61  gko::detail::GenericDenseCache& workspace);
62 
63 
64 } // namespace detail
65 
66 
97 template <typename LocalIndexType = int32>
98 class RowGatherer final : public PolymorphicObject,
99  public EnableCloneable<RowGatherer<LocalIndexType>>,
100  public DistributedBase {
101  friend class EnableCloneable<RowGatherer>;
102  template <typename ValueT, typename LocalIndexT, typename GlobalIndexT>
103  friend class Matrix;
104  // for test purpose
105  friend std::shared_ptr<const gko::detail::Event>
106  detail::apply_prepare<LocalIndexType>(const RowGatherer* rg,
108  friend std::shared_ptr<const gko::detail::Event> detail::apply_prepare<
109  LocalIndexType>(const RowGatherer* rg, ptr_param<const LinOp> b,
110  gko::detail::GenericDenseCache& workspace);
111  friend mpi::request detail::apply_finalize<LocalIndexType>(
113  std::shared_ptr<const gko::detail::Event>);
114  friend mpi::request detail::apply_finalize<LocalIndexType>(
116  std::shared_ptr<const gko::detail::Event>,
117  gko::detail::GenericDenseCache& workspace);
118 
119 public:
137  ptr_param<LinOp> x) const;
138 
158  [[nodiscard]] mpi::request apply_async(
160  gko::detail::GenericDenseCache& workspace) const;
161 
165  dim<2> get_size() const;
166 
170  std::shared_ptr<const mpi::CollectiveCommunicator>
172 
176  const LocalIndexType* get_const_send_idxs() const;
177 
182 
203  template <typename GlobalIndexType = int64,
204  typename = std::enable_if_t<sizeof(GlobalIndexType) >=
205  sizeof(LocalIndexType)>>
206  static std::unique_ptr<RowGatherer> create(
207  std::shared_ptr<const Executor> exec,
208  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
210  {
211  return std::unique_ptr<RowGatherer>(
212  new RowGatherer(std::move(exec), std::move(coll_comm), imap));
213  }
214 
227  static std::unique_ptr<RowGatherer> create_from_scatterer(
228  std::shared_ptr<const Executor> exec,
229  ptr_param<const RowScatterer<LocalIndexType>> scatterer);
230 
234  static std::unique_ptr<RowGatherer> create(
235  std::shared_ptr<const Executor> exec, mpi::communicator comm);
236 
253  static std::unique_ptr<RowGatherer> create(
254  std::shared_ptr<const Executor> exec,
255  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
256 
257  RowGatherer(const RowGatherer& o);
258 
260 
261  RowGatherer& operator=(const RowGatherer& o);
262 
263  RowGatherer& operator=(RowGatherer&& o);
264 
265 protected:
266  std::shared_ptr<const gko::detail::Event> apply_prepare(
267  ptr_param<const LinOp> b) const;
268 
269  std::shared_ptr<const gko::detail::Event> apply_prepare(
271  gko::detail::GenericDenseCache& workspace) const;
272 
273  mpi::request apply_finalize(
275  std::shared_ptr<const gko::detail::Event>) const;
276 
277  mpi::request apply_finalize(
279  std::shared_ptr<const gko::detail::Event>,
280  gko::detail::GenericDenseCache& workspace) const;
281 
282 private:
288  template <typename GlobalIndexType>
289  RowGatherer(std::shared_ptr<const Executor> exec,
290  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
292 
297  RowGatherer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
298 
303  RowGatherer(
304  std::shared_ptr<const Executor> exec,
305  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
306 
307  RowGatherer(std::shared_ptr<const Executor> exec,
308  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
309  array<LocalIndexType> send_idxs, dim<2> size);
310 
311  dim<2> size_;
312  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
313  array<LocalIndexType> send_idxs_;
314  mutable gko::detail::GenericDenseCache send_cache_;
315 };
316 
317 
318 } // namespace distributed
319 } // namespace experimental
320 } // namespace gko
321 
322 #endif
323 #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:268
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:101
gko::experimental::mpi::request
The request class is a light, move-only wrapper around the MPI_Request handle.
Definition: mpi.hpp:330
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
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:418
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:206
gko::experimental::distributed::RowGatherer::create_from_scatterer
static std::unique_ptr< RowGatherer > create_from_scatterer(std::shared_ptr< const Executor > exec, ptr_param< const RowScatterer< LocalIndexType >> scatterer)
Creates a distributed::RowGatherer from an existing RowScatterer.
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:376
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:124
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::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