Ginkgo  Generated from pipelines/2897303314 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
collective_communicator.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_DISTRIBUTED_COLLECTIVE_COMMUNICATOR_HPP_
6 #define GKO_PUBLIC_CORE_DISTRIBUTED_COLLECTIVE_COMMUNICATOR_HPP_
7 
8 
9 #include <ginkgo/config.hpp>
10 
11 
12 #if GINKGO_BUILD_MPI
13 
14 #include <variant>
15 
16 #include <ginkgo/core/base/mpi.hpp>
17 #include <ginkgo/core/distributed/index_map.hpp>
18 
19 
20 namespace gko {
21 namespace experimental {
22 namespace mpi {
23 
24 
32 public:
36  using index_map_ptr =
37  std::variant<const distributed::index_map<int32, int32>*,
40 
41  virtual ~CollectiveCommunicator() = default;
42 
43  explicit CollectiveCommunicator(communicator base = MPI_COMM_NULL);
44 
45  [[nodiscard]] const communicator& get_base_communicator() const;
46 
63  template <typename SendType, typename RecvType>
64  [[nodiscard]] request i_all_to_all_v(std::shared_ptr<const Executor> exec,
65  const SendType* send_buffer,
66  RecvType* recv_buffer) const;
67 
72  request i_all_to_all_v(std::shared_ptr<const Executor> exec,
73  const void* send_buffer, MPI_Datatype send_type,
74  void* recv_buffer, MPI_Datatype recv_type) const;
75 
84  [[nodiscard]] virtual std::unique_ptr<CollectiveCommunicator>
85  create_with_same_type(communicator base, index_map_ptr imap) const = 0;
86 
94  [[nodiscard]] virtual std::unique_ptr<CollectiveCommunicator>
95  create_inverse() const = 0;
96 
97 
123  [[nodiscard]] virtual std::pair<std::unique_ptr<CollectiveCommunicator>,
124  std::vector<comm_index_type>>
125  resize(std::shared_ptr<const Executor> exec,
126  const std::vector<comm_index_type>& send_factors) const = 0;
127 
134  [[nodiscard]] virtual comm_index_type get_recv_size() const = 0;
135 
142  [[nodiscard]] virtual comm_index_type get_send_size() const = 0;
143 
144 protected:
145  virtual request i_all_to_all_v_impl(std::shared_ptr<const Executor> exec,
146  const void* send_buffer,
147  MPI_Datatype send_type,
148  void* recv_buffer,
149  MPI_Datatype recv_type) const = 0;
150 
151 private:
152  communicator base_;
153 };
154 
155 
156 template <typename SendType, typename RecvType>
158  std::shared_ptr<const Executor> exec, const SendType* send_buffer,
159  RecvType* recv_buffer) const
160 {
161  return this->i_all_to_all_v(std::move(exec), send_buffer,
162  type_impl<SendType>::get_type(), recv_buffer,
164 }
165 
166 
167 namespace detail {
168 
169 
178 std::shared_ptr<CollectiveCommunicator> create_default_collective_communicator(
179  communicator base);
180 
181 
182 } // namespace detail
183 } // namespace mpi
184 } // namespace experimental
185 } // namespace gko
186 
187 
188 #endif
189 #endif // GKO_PUBLIC_CORE_DISTRIBUTED_COLLECTIVE_COMMUNICATOR_HPP_
gko::experimental::mpi::CollectiveCommunicator::create_with_same_type
virtual std::unique_ptr< CollectiveCommunicator > create_with_same_type(communicator base, index_map_ptr imap) const =0
Creates a new CollectiveCommunicator with the same dynamic type.
gko::experimental::mpi::CollectiveCommunicator::i_all_to_all_v
request i_all_to_all_v(std::shared_ptr< const Executor > exec, const SendType *send_buffer, RecvType *recv_buffer) const
Non-blocking all-to-all communication.
Definition: collective_communicator.hpp:157
gko::experimental::mpi::request
The request class is a light, move-only wrapper around the MPI_Request handle.
Definition: mpi.hpp:330
gko::experimental::mpi::CollectiveCommunicator
Interface for a collective communicator.
Definition: collective_communicator.hpp:31
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::experimental::mpi::CollectiveCommunicator::create_inverse
virtual std::unique_ptr< CollectiveCommunicator > create_inverse() const =0
Creates a CollectiveCommunicator with the inverse communication pattern than this object.
gko::experimental::mpi::CollectiveCommunicator::get_send_size
virtual comm_index_type get_send_size() const =0
Get the number of elements sent by this process within this communication pattern.
gko::experimental::mpi::communicator
A thin wrapper of MPI_Comm that supports most MPI calls.
Definition: mpi.hpp:418
gko::experimental::mpi::comm_index_type
int comm_index_type
Index type for enumerating processes in a distributed application.
Definition: types.hpp:1135
gko::experimental::mpi::type_impl
A struct that is used to determine the MPI_Datatype of a specified type.
Definition: mpi.hpp:76
gko::experimental::mpi::CollectiveCommunicator::index_map_ptr
std::variant< const distributed::index_map< int32, int32 > *, const distributed::index_map< int32, int64 > *, const distributed::index_map< int64, int64 > * > index_map_ptr
All allowed index_map types (as const *)
Definition: collective_communicator.hpp:39
gko::experimental::mpi::CollectiveCommunicator::get_recv_size
virtual comm_index_type get_recv_size() const =0
Get the number of elements received by this process within this communication pattern.
gko::experimental::mpi::CollectiveCommunicator::resize
virtual std::pair< std::unique_ptr< CollectiveCommunicator >, std::vector< comm_index_type > > resize(std::shared_ptr< const Executor > exec, const std::vector< comm_index_type > &send_factors) const =0
Create new communicator that sends and receives a different number of elements to/from each rank in i...
gko::experimental::distributed::index_map
This class defines mappings between global and local indices.
Definition: index_map.hpp:70