Ginkgo  Generated from pipelines/1868155508 branch based on main. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
row_gatherer.hpp
1 // SPDX-FileCopyrightText: 2017 - 2025 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/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 
22 
23 namespace gko {
24 namespace experimental {
25 namespace distributed {
26 
27 
54 template <typename LocalIndexType = int32>
55 class RowGatherer final
56  : public EnablePolymorphicObject<RowGatherer<LocalIndexType>>,
57  public EnablePolymorphicAssignment<RowGatherer<LocalIndexType>>,
58  public DistributedBase {
60 
61 public:
77  ptr_param<LinOp> x) const;
78 
98  array<char>& workspace) const;
99 
103  dim<2> get_size() const;
104 
108  std::shared_ptr<const mpi::CollectiveCommunicator>
110 
114  const LocalIndexType* get_const_send_idxs() const;
115 
120 
141  template <typename GlobalIndexType = int64,
142  typename = std::enable_if_t<sizeof(GlobalIndexType) >=
143  sizeof(LocalIndexType)>>
144  static std::unique_ptr<RowGatherer> create(
145  std::shared_ptr<const Executor> exec,
146  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
148  {
149  return std::unique_ptr<RowGatherer>(
150  new RowGatherer(std::move(exec), std::move(coll_comm), imap));
151  }
152 
153  /*
154  * Create method for an empty RowGatherer.
155  */
156  static std::unique_ptr<RowGatherer> create(
157  std::shared_ptr<const Executor> exec, mpi::communicator comm);
158 
159  RowGatherer(const RowGatherer& o);
160 
161  RowGatherer(RowGatherer&& o) noexcept;
162 
163  RowGatherer& operator=(const RowGatherer& o);
164 
165  RowGatherer& operator=(RowGatherer&& o);
166 
167 private:
173  template <typename GlobalIndexType>
174  RowGatherer(std::shared_ptr<const Executor> exec,
175  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
177 
182  RowGatherer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
183 
184  dim<2> size_;
185  std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
186  array<LocalIndexType> send_idxs_;
187  mutable array<char> send_workspace_;
188  // This object might not hold an actual MPI request, so we can't use the
189  // always owning mpi::request. Its destructor would otherwise make the
190  // program crash.
191  mutable MPI_Request req_listener_{MPI_REQUEST_NULL};
192 };
193 
194 
195 } // namespace distributed
196 } // namespace experimental
197 } // namespace gko
198 
199 #endif
200 #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:55
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:52
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:90
gko::EnablePolymorphicAssignment
This mixin is used to enable a default PolymorphicObject::copy_from() implementation for objects that...
Definition: polymorphic_object.hpp:743
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< char >
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:144
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition: utils_helper.hpp:41
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::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
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:667