Ginkgo  Generated from pipelines/3136675824 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(
44 
45 // give access to test function on protected function
46 template <typename LocalIndexType>
47 std::shared_ptr<const gko::detail::Event> apply_prepare(
50  gko::detail::GenericDenseCache& workspace);
51 
52 // give access to test function on protected function
53 template <typename LocalIndexType>
54 mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
57  std::shared_ptr<const gko::detail::Event>);
58 
59 // give access to test function on protected function
60 template <typename LocalIndexType>
61 mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
64  std::shared_ptr<const gko::detail::Event>,
65  gko::detail::GenericDenseCache& workspace);
66 
67 
68 } // namespace detail
69 
70 
101 template <typename LocalIndexType = int32>
102 class RowGatherer final : public PolymorphicObject,
103  public EnableCloneable<RowGatherer<LocalIndexType>>,
104  public DistributedBase {
105  friend class EnableCloneable<RowGatherer>;
106  template <typename ValueT, typename LocalIndexT, typename GlobalIndexT>
107  friend class Matrix;
108  // for test purpose
109  friend std::shared_ptr<const gko::detail::Event>
110  detail::apply_prepare<LocalIndexType>(
112  friend std::shared_ptr<const gko::detail::Event>
113  detail::apply_prepare<LocalIndexType>(
115  gko::detail::GenericDenseCache& workspace);
116  friend mpi::request detail::apply_finalize<LocalIndexType>(
119  std::shared_ptr<const gko::detail::Event>);
120  friend mpi::request detail::apply_finalize<LocalIndexType>(
123  std::shared_ptr<const gko::detail::Event>,
124  gko::detail::GenericDenseCache& workspace);
125 
126 public:
143  [[nodiscard]] mpi::request apply_async(
146 
166  [[nodiscard]] mpi::request apply_async(
169  gko::detail::GenericDenseCache& workspace) const;
170 
174  dim<2> get_size() const;
175 
179  std::shared_ptr<const mpi::CollectiveCommunicator>
181 
185  const LocalIndexType* get_const_send_idxs() const;
186 
191 
212  template <typename GlobalIndexType = int64,
213  typename = std::enable_if_t<sizeof(GlobalIndexType) >=
214  sizeof(LocalIndexType)>>
215  static std::unique_ptr<RowGatherer> create(
216  std::shared_ptr<const Executor> exec,
217  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
219  {
220  return std::unique_ptr<RowGatherer>(
221  new RowGatherer(std::move(exec), std::move(coll_comm), imap));
222  }
223 
236  static std::unique_ptr<RowGatherer> create_from_scatterer(
237  std::shared_ptr<const Executor> exec,
238  ptr_param<const RowScatterer<LocalIndexType>> scatterer);
239 
243  static std::unique_ptr<RowGatherer> create(
244  std::shared_ptr<const Executor> exec, mpi::communicator comm);
245 
262  static std::unique_ptr<RowGatherer> create(
263  std::shared_ptr<const Executor> exec,
264  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
265 
266  RowGatherer(const RowGatherer& o);
267 
269 
270  RowGatherer& operator=(const RowGatherer& o);
271 
272  RowGatherer& operator=(RowGatherer&& o);
273 
274 protected:
275  std::shared_ptr<const gko::detail::Event> apply_prepare(
277 
278  std::shared_ptr<const gko::detail::Event> apply_prepare(
280  gko::detail::GenericDenseCache& workspace) const;
281 
282  mpi::request apply_finalize(
285  std::shared_ptr<const gko::detail::Event>) const;
286 
287  mpi::request apply_finalize(
290  std::shared_ptr<const gko::detail::Event>,
291  gko::detail::GenericDenseCache& workspace) const;
292 
293 private:
299  template <typename GlobalIndexType>
300  RowGatherer(std::shared_ptr<const Executor> exec,
301  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
303 
308  RowGatherer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
309 
314  RowGatherer(
315  std::shared_ptr<const Executor> exec,
316  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
317 
318  RowGatherer(std::shared_ptr<const Executor> exec,
319  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
320  array<LocalIndexType> send_idxs, dim<2> size);
321 
322  dim<2> size_;
323  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
324  array<LocalIndexType> send_idxs_;
325  mutable gko::detail::GenericDenseCache send_cache_;
326 };
327 
328 
329 } // namespace distributed
330 } // namespace experimental
331 } // namespace gko
332 
333 #endif
334 #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:102
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::apply_async
mpi::request apply_async(ptr_param< const AbstractMultiVector > b, ptr_param< AbstractMultiVector > x) const
Asynchronous version of LinOp::apply.
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:215
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:372
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition: types.hpp:125
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