Ginkgo: ginkgo/core/distributed/row_gatherer.hpp Source File

| Ginkgo Generated from branch based on main. Ginkgo version 1.11.0 A numerical linear algebra library targeting many-core architectures

Loading...
Searching...
No Matches
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/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
24namespace gko {
25namespace experimental {
26namespace distributed {
27
28
29template <typename LocalIndexType>
30class RowGatherer;
31
32
33namespace detail {
34
35
36// give access to test function on protected function
37template <typename LocalIndexType>
38std::shared_ptr<const gko::detail::Event> apply_prepare(
39 const RowGatherer<LocalIndexType>* rg, ptr_param<const LinOp> b);
40
41// give access to test function on protected function
42template <typename LocalIndexType>
43std::shared_ptr<const gko::detail::Event> apply_prepare(
44 const RowGatherer<LocalIndexType>* rg, ptr_param<const LinOp> b,
45 array<char>& workspace);
46
47// give access to test function on protected function
48template <typename LocalIndexType>
49mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
50 ptr_param<const LinOp> b, ptr_param<LinOp> x,
51 std::shared_ptr<const gko::detail::Event>);
52
53// give access to test function on protected function
54template <typename LocalIndexType>
55mpi::request apply_finalize(const RowGatherer<LocalIndexType>* rg,
56 ptr_param<const LinOp> b, ptr_param<LinOp> x,
57 std::shared_ptr<const gko::detail::Event>,
58 array<char>& workspace);
59
60
61} // namespace detail
62
63
90template <typename LocalIndexType = int32>
91 class RowGatherer final
92 : public EnablePolymorphicObject<RowGatherer<LocalIndexType>>,
93 public EnablePolymorphicAssignment<RowGatherer<LocalIndexType>>,
94 public DistributedBase {
95 friend class EnablePolymorphicObject<RowGatherer, PolymorphicObject>;
96 template <typename ValueT, typename LocalIndexT, typename GlobalIndexT>
97 friend class Matrix;
98 // for test purpose
99 friend std::shared_ptr<const gko::detail::Event>
100 detail::apply_prepare<LocalIndexType>(const RowGatherer* rg,
101 ptr_param<const LinOp> b);
102 friend std::shared_ptr<const gko::detail::Event>
103 detail::apply_prepare<LocalIndexType>(const RowGatherer* rg,
104 ptr_param<const LinOp> b,
105 array<char>& workspace);
106 friend mpi::request detail::apply_finalize<LocalIndexType>(
107 const RowGatherer* rg, ptr_param<const LinOp> b, ptr_param<LinOp> x,
108 std::shared_ptr<const gko::detail::Event>);
109 friend mpi::request detail::apply_finalize<LocalIndexType>(
110 const RowGatherer* rg, ptr_param<const LinOp> b, ptr_param<LinOp> x,
111 std::shared_ptr<const gko::detail::Event>, array<char>& workspace);
112
113public:
129 [[nodiscard]] mpi::request apply_async(ptr_param<const LinOp> b,
130 ptr_param<LinOp> x) const;
131
150 [[nodiscard]] mpi::request apply_async(ptr_param<const LinOp> b,
151 ptr_param<LinOp> x,
152 array<char>& workspace) const;
153
157 dim<2> get_size() const;
158
162 std::shared_ptr<const mpi::CollectiveCommunicator>
163 get_collective_communicator() const;
164
168 const LocalIndexType* get_const_send_idxs() const;
169
173 size_type get_num_send_idxs() const;
174
195 template <typename GlobalIndexType = int64,
196 typename = std::enable_if_t<sizeof(GlobalIndexType) >=
197 sizeof(LocalIndexType)>>
198 static std::unique_ptr<RowGatherer> create(
199 std::shared_ptr<const Executor> exec,
200 std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
201 const index_map<LocalIndexType, GlobalIndexType>& imap)
202 {
203 return std::unique_ptr<RowGatherer>(
204 new RowGatherer(std::move(exec), std::move(coll_comm), imap));
205 }
206
207 /*
208 * Create method for an empty RowGatherer.
209 */
210 static std::unique_ptr<RowGatherer> create(
211 std::shared_ptr<const Executor> exec, mpi::communicator comm);
212
213 /*
214 * Create method for an empty RowGatherer with an template for the
215 * collective communicator.
216 *
217 * This is mainly used for creating a new RowGatherer with the same runtime
218 * type for the collective communicator, e.g.:
219 * ```c++
220 * auto rg = RowGatherer<>::create(
221 * exec, std::make_shared<mpi::NeighborhoodCommunicator>(comm));
222 * ...
223 * rg = RowGatherer<>::create(
224 * exec,
225 * rg->get_collective_communicator()->create_with_same_type(comm, &imap),
226 * imap);
227 * ```
228 */
229 static std::unique_ptr<RowGatherer> create(
230 std::shared_ptr<const Executor> exec,
231 std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
232
233 RowGatherer(const RowGatherer& o);
234
235 RowGatherer(RowGatherer&& o) noexcept;
236
237 RowGatherer& operator=(const RowGatherer& o);
238
239 RowGatherer& operator=(RowGatherer&& o);
240
241protected:
242 std::shared_ptr<const gko::detail::Event> apply_prepare(
243 ptr_param<const LinOp> b) const;
244
245 std::shared_ptr<const gko::detail::Event> apply_prepare(
246 ptr_param<const LinOp> b, array<char>& workspace) const;
247
248 mpi::request apply_finalize(
249 ptr_param<const LinOp> b, ptr_param<LinOp> x,
250 std::shared_ptr<const gko::detail::Event>) const;
251
252 mpi::request apply_finalize(ptr_param<const LinOp> b, ptr_param<LinOp> x,
253 std::shared_ptr<const gko::detail::Event>,
254 array<char>& workspace) const;
255
256private:
262 template <typename GlobalIndexType>
263 RowGatherer(std::shared_ptr<const Executor> exec,
264 std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm,
265 const index_map<LocalIndexType, GlobalIndexType>& imap);
266
271 RowGatherer(std::shared_ptr<const Executor> exec, mpi::communicator comm);
272
277 RowGatherer(
278 std::shared_ptr<const Executor> exec,
279 std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_template);
280
281 dim<2> size_;
282 std::shared_ptr<const mpi::CollectiveCommunicator> coll_comm_;
283 array<LocalIndexType> send_idxs_;
284 mutable array<char> send_workspace_;
285};
286
287
288} // namespace distributed
289} // namespace experimental
290} // namespace gko
291
292#endif
293#endif // GKO_PUBLIC_CORE_DISTRIBUTED_ROW_GATHERER_HPP_
gko::EnablePolymorphicAssignment
This mixin is used to enable a default PolymorphicObject::copy_from() implementation for objects that...
Definition polymorphic_object.hpp:743
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
gko::PolymorphicObject
A PolymorphicObject is the abstract base for all "heavy" objects in Ginkgo that behave polymorphicall...
Definition polymorphic_object.hpp:52
gko::array
An array is a container which encapsulates fixed-sized arrays, stored on the Executor tied to the arr...
Definition array.hpp:166
gko::experimental::distributed::RowGatherer
The distributed::RowGatherer gathers the rows of distributed::Vector that are located on other proces...
Definition row_gatherer.hpp:94
gko::experimental::distributed::RowGatherer::apply_async
mpi::request apply_async(ptr_param< const LinOp > b, ptr_param< LinOp > x, array< char > &workspace) const
Asynchronous version of LinOp::apply.
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::RowGatherer::get_const_send_idxs
const LocalIndexType * get_const_send_idxs() const
Read access to the (local) rows indices.
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:198
gko::experimental::distributed::RowGatherer::get_size
dim< 2 > get_size() const
Returns the size of the row gatherer.
gko::experimental::distributed::RowGatherer::get_num_send_idxs
size_type get_num_send_idxs() const
Returns the number of (local) row indices.
gko::experimental::distributed::RowGatherer::get_collective_communicator
std::shared_ptr< const mpi::CollectiveCommunicator > get_collective_communicator() const
Get the used collective communicator.
gko::experimental::distributed::index_map
This class defines mappings between global and local indices.
Definition index_map.hpp:68
gko::experimental::mpi::communicator
A thin wrapper of MPI_Comm that supports most MPI calls.
Definition mpi.hpp:419
gko::experimental::mpi::request
The request class is a light, move-only wrapper around the MPI_Request handle.
Definition mpi.hpp:331
gko::ptr_param
This class is used for function parameters in the place of raw pointers.
Definition utils_helper.hpp:41
gko::experimental::distributed
The distributed namespace.
Definition polymorphic_object.hpp:19
gko
The Ginkgo namespace.
Definition abstract_factory.hpp:20
gko::int64
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:113
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
gko::dim
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:26