16#include <kamping/communicator.hpp>
17#include <kamping/span.hpp>
18#include <kamping/topology_communicator.hpp>
36 template <
typename ContiguousRange>
47 template <
typename ContiguousRange>
62 return _in_ranks.size();
75 return _out_ranks.size();
87 return _in_weights.has_value();
139 std::optional<SpanType> _in_weights;
140 std::optional<SpanType> _out_weights;
147template <
typename NeighborhoodRange>
149 using NeighborType =
typename NeighborhoodRange::value_type;
150#ifdef KAMPING_ENABLE_REFLECTION
152 kamping::internal::tuple_size<NeighborType> == 1 || kamping::internal::tuple_size<NeighborType> == 2,
153 "Neighbor type has to be a scalar (in the unweighted case) or pair-like (in the weighted case) type"
155 return kamping::internal::tuple_size<NeighborType> == 2;
160 return !std::is_integral_v<NeighborType>;
170template <
template <
typename...>
typename DefaultContainer = std::vector>
185 template <
typename InNeighborsRange,
typename OutNeighborsRange>
191 "If weighted neighborhoods are passed, they must be provided for both in and out neighbors!"
195 auto const& [rank,
_] =
edge;
196 return static_cast<int>(rank);
198 return static_cast<int>(
edge);
212 return static_cast<int>(
weight);
220 _in_weights.value().data(),
226 _out_weights.value().data(),
235 : _in_ranks{
std::
move(in_ranks)},
236 _out_ranks{
std::
move(out_ranks)} {}
246 : _in_ranks{
std::
move(in_ranks)},
247 _out_ranks{
std::
move(out_ranks)},
248 _in_weights{
std::
move(in_weights)},
249 _out_weights{
std::
move(out_weights)} {}
253 template <
typename NeighborRange>
259 if (_in_weights.has_value()) {
277 template <
typename Map = std::unordered_map<
size_t,
size_t>>
280 for (
size_t i = 0;
i < _out_ranks.size(); ++
i) {
281 size_t rank =
static_cast<size_t>(_out_ranks.data()[
i]);
288 template <
typename ReadFromRange,
typename WriteToContainer,
typename TransformOp>
295 DefaultContainer<int> _in_ranks;
296 DefaultContainer<int> _out_ranks;
297 std::optional<DefaultContainer<int>> _in_weights;
298 std::optional<DefaultContainer<int>> _out_weights;
310 template <
typename...>
typename DefaultContainerType = std::vector,
311 template <
typename,
template <
typename...>
typename>
315 public Plugins<DistributedGraphCommunicator<DefaultContainerType, Plugins...>, DefaultContainerType>... {
320 template <
typename...
Args>
328 template <
typename Communicator>
342 template <
typename Communicator>
373 std::move(out_ranks),
374 std::move(in_weights),
375 std::move(out_weights)
Local view of a a distributed communication graph from the perspective of the current rank....
Definition distributed_graph_communicator.hpp:27
SpanType out_ranks() const
Returns view on the out-going edges.
Definition distributed_graph_communicator.hpp:96
MPI_Comm create_mpi_graph_communicator(MPI_Comm comm) const
Creates a distributed graph communicator based on the view of the given communication graph using MPI...
Definition distributed_graph_communicator.hpp:115
size_t out_degree() const
Returns out degree of the rank, i.e. the number of out-going edges/communication links starting at th...
Definition distributed_graph_communicator.hpp:74
CommunicationGraphLocalView(ContiguousRange const &in_ranks, ContiguousRange const &out_ranks, ContiguousRange const &in_weights, ContiguousRange const &out_weights)
Constructs a view of an unweighted communication graph.
Definition distributed_graph_communicator.hpp:48
CommunicationGraphLocalView(ContiguousRange const &in_ranks, ContiguousRange const &out_ranks)
Constructs a view of an unweighted communication graph.
Definition distributed_graph_communicator.hpp:37
int out_degree_signed() const
Returns out degree of the rank, i.e. the number of out-going edges/communication links starting at th...
Definition distributed_graph_communicator.hpp:81
int in_degree_signed() const
Returns in degree of the rank, i.e. the number of in-going edges/communication links towards the rank...
Definition distributed_graph_communicator.hpp:67
bool is_weighted() const
Returns whether the communication graph is weighted or not.
Definition distributed_graph_communicator.hpp:86
size_t in_degree() const
Returns in degree of the rank, i.e. the number of in-going edges/communication links towards the rank...
Definition distributed_graph_communicator.hpp:61
std::optional< SpanType > out_weights() const
Returns view on the out-going edge weights if present.
Definition distributed_graph_communicator.hpp:106
std::optional< SpanType > in_weights() const
Returns view on the in-going edge weights if present.
Definition distributed_graph_communicator.hpp:101
kamping::Span< int const > SpanType
type to be used for views on ranks and weights
Definition distributed_graph_communicator.hpp:29
SpanType in_ranks() const
Returns view on the in-going edges.
Definition distributed_graph_communicator.hpp:91
Wrapper for MPI communicator providing access to rank() and size() of the communicator....
Definition communicator.hpp:49
MPI_Comm _comm
Corresponding MPI communicator.
Definition communicator.hpp:640
MPI_Comm mpi_communicator() const
MPI communicator corresponding to this communicator.
Definition communicator.hpp:192
A (vertex-centric) distributed communication graph. Each vertex of the graph corresponds to a rank an...
Definition distributed_graph_communicator.hpp:171
DistributedCommunicationGraph(NeighborRange const &neighbors)
Constructs a communication graph based where in and out neighbors are the same, i....
Definition distributed_graph_communicator.hpp:254
DistributedCommunicationGraph(DefaultContainer< int > &&in_ranks, DefaultContainer< int > &&out_ranks, DefaultContainer< int > &&in_weights, DefaultContainer< int > &&out_weights)
Constructs a communication graph based on a range of weighted in-going and out-going neighbors....
Definition distributed_graph_communicator.hpp:240
DistributedCommunicationGraph(InNeighborsRange const &in_neighbors, OutNeighborsRange const &out_neighbors)
Constructs a communication graph based on a range of in-going and out-going edges which might be weig...
Definition distributed_graph_communicator.hpp:186
DistributedCommunicationGraph(DefaultContainer< int > &&in_ranks, DefaultContainer< int > &&out_ranks)
Constructs a communication graph based on a range of unweighted in-going and out-going neighbors,...
Definition distributed_graph_communicator.hpp:234
auto get_rank_to_out_neighbor_idx_mapping()
In neighborhood collectives the order of sent and received data depends on the ordering of the underl...
Definition distributed_graph_communicator.hpp:278
DistributedCommunicationGraph()=default
Default constructor.
CommunicationGraphLocalView get_view() const
Returns a view of the communication graph.
Definition distributed_graph_communicator.hpp:258
A Communicator which possesses an additional virtual topology and supports neighborhood collectives (...
Definition distributed_graph_communicator.hpp:315
DistributedGraphCommunicator(Communicator const &comm, DistributedCommunicationGraph< DefaultContainerType > const &comm_graph)
Construtor based on a given communicator and a communication graph.
Definition distributed_graph_communicator.hpp:343
auto get_communication_graph()
Returns the communicators underlying communication graph by calling MPI_Dist_graph_neighbors.
Definition distributed_graph_communicator.hpp:349
bool is_weighted() const
Returns whether the communicator's underlying communication graph is weighted.
Definition distributed_graph_communicator.hpp:384
DistributedGraphCommunicator(Communicator const &comm, CommunicationGraphLocalView comm_graph_view)
Construtor based on a given communicator and a view of a communication graph.
Definition distributed_graph_communicator.hpp:329
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
A Communicator which possesses an additional virtual topology and supports neighborhood collectives (...
Definition topology_communicator.hpp:37
int out_degree_signed() const
Returns the out degree of the process' rank, i.e. the number of out-going edges/communication links s...
Definition topology_communicator.hpp:67
size_t in_degree() const
Returns the in degree of the process' rank, i.e. the number of in-going edges/communication links tow...
Definition topology_communicator.hpp:47
size_t out_degree() const
Returns the out degree of the process' rank, i.e. the number of out-going edges/communication links s...
Definition topology_communicator.hpp:60
int in_degree_signed() const
Returns the in degree of the process' rank, i.e. the number of in-going edges/communication links tow...
Definition topology_communicator.hpp:53
constexpr bool are_neighborhoods_weighted()
Returns whether a given range of neighbors is weighted or not at compile time, i.e....
Definition distributed_graph_communicator.hpp:148