Nektar++
Loading...
Searching...
No Matches
Classes | Namespaces | Functions
Transport.hpp File Reference

Personalised all-to-all exchange of opaque byte blobs, and the overview of the shared-id module built on it. More...

#include <algorithm>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <functional>
#include <limits>
#include <memory>
#include <set>
#include <type_traits>
#include <unordered_map>
#include <utility>
#include <vector>
#include <LibUtilities/BasicUtils/ErrorUtil.hpp>
#include <LibUtilities/Communication/Comm.h>

Go to the source code of this file.

Classes

struct  Nektar::LibUtilities::detail::CrystalStep
 Crystal-router routing decision for one bisection step. More...
 
struct  Nektar::LibUtilities::RoutedMessage
 An opaque byte payload plus routing metadata. More...
 
class  Nektar::LibUtilities::ITransport
 Abstract interface for a personalised all-to-all exchange of opaque byte blobs. More...
 
class  Nektar::LibUtilities::AlltoallvTransport
 ITransport implementation built on MPI_Alltoall (of counts) followed by MPI_Alltoallv (of data). More...
 
class  Nektar::LibUtilities::CrystalRouterTransport
 ITransport implementation performing a personalised all-to-all on a (bisected) hypercube (a Fox/gslib-style crystal router). More...
 
struct  Nektar::LibUtilities::CrystalRouterTransport::Record
 One message in flight, as an index into m_pool. More...
 

Namespaces

namespace  Nektar
 
namespace  Nektar::LibUtilities
 
namespace  Nektar::LibUtilities::detail
 

Functions

template<typename T >
void Nektar::LibUtilities::detail::PackPod (std::vector< std::byte > &buf, const T &v)
 Append a trivially-copyable POD value to a byte buffer.
 
template<typename T >
T Nektar::LibUtilities::detail::UnpackPod (const std::byte *&cur)
 Read a trivially-copyable POD value from a cursor and advance it.
 
CrystalStep Nektar::LibUtilities::detail::CrystalPlanStep (int lo, int hi, int rank)
 Compute this rank's routing decision for one bisection step of the crystal router.
 
bool Nektar::LibUtilities::detail::CrystalDestInMyHalf (const CrystalStep &s, int dest)
 Test whether a message destined for dest belongs in the querying rank's half of the current bisection.
 
int Nektar::LibUtilities::detail::RendezvousRank (int64_t id, int nproc)
 Bit-mixing hash (splitmix64 finaliser) mapping an entity id to its rendezvous rank, so sequential IDs spread across rendezvous ranks and don't create hot spots.
 
std::vector< RoutedMessage > Nektar::LibUtilities::detail::DrainBucketsToMessages (std::unordered_map< int, std::vector< std::byte > > &buckets, int selfRank)
 Move sparse per-destination byte buckets into transport messages, clearing the buckets.
 
CommSharedPtr Nektar::LibUtilities::detail::BuildNeighbourComm (const CommSharedPtr &base, int selfRank, const std::unordered_map< int64_t, std::vector< int > > &sharers)
 Build a persistent distributed-graph communicator over the discovered topological neighbours (self excluded).
 

Detailed Description

Personalised all-to-all exchange of opaque byte blobs, and the overview of the shared-id module built on it.

Where things live

This header is the bottom layer, holding #ITransport, its two implementations and the detail helpers the layers above share. Every other header in the module includes it, so the module overview lives here:

The problem being solved

Several places in the code need to answer "for every global entity ID I touch (vertex / edge / face, possibly periodically identified), find every other rank that also touches it and agree on a canonical value (e.g. the highest polynomial order)". The naive implementation AllReduces arrays sized by the global entity count onto every rank: O(N_global) memory per rank and O(N_global * P) total bandwidth. This does not scale to large rank counts.

Classes in the module

There are three main classes:

There are also some additional utility classes:

The approach (rendezvous / distributed directory)

  1. Each rank hashes each of its entity IDs to a "rendezvous" rank and ships (id, value) there. All contributions for a given ID meet on one rank.
  2. The rendezvous rank reduces the values and – for free – learns the complete set of ranks that touch each ID (the true topological neighbour set, including vertex-only and periodic adjacency).
  3. Results (and the sharer list) are shipped back to each contributor.

Memory per rank is O(local entities); nothing is ever sized by P or by the global entity count. Every map that persists past a call – Nektar::LibUtilities::SharedPayloadResolver::m_sharedPayloads and the ConnectivityResolver equivalent – is keyed only by entities this rank actually registered or was a rendezvous host for, so its size is bounded by local entity count plus, in expectation, N_global / P at the rendezvous step. No structure is ever sized by P or by N_global directly. The sharer lists let you build a persistent neighbourhood communicator (BuildNeighbourComm()) so downstream halo-style exchanges become cheap neighbourhood collectives.

This O(local) claim is about the number of entities, not the fan-out of any one of them: ConnectivityResolver's reply phase sends the full k-entry sharer list to each of an entity's k sharers, so wire volume for a single high-fan-out entity is O(k^2). Fine at the k=2-8 typical of facet/edge adjacency; worth watching for entities that can be shared by dozens of ranks (e.g. a partition corner with periodicity) or, at very large rank counts, a genuinely global entity.

Payloads are shipped as raw bytes (no custom MPI datatype), which assumes a homogeneous cluster: all ranks share the same endianness and struct layout for PayloadT. True of essentially every HPC deployment, but not checked or enforced here.

One-shot versus persistent

Out of the box a resolver answers its question once: every Resolve() rediscovers the sharers. That is optimal for a one-off agreement but wasteful when the same ids are resolved again and again with new values – the gslib use case. For that, #SharedIdPlan pays discovery once in its constructor, and every Gather() / Reduce() thereafter is a single neighbour exchange carrying only values – no ids, no counts, no rendezvous – over the backend chosen by #ExchangeBackend. SharedPayloadResolver offers the same split behind its id-keyed interface: Register() the ids once, call Setup() once, then update payloads with SetPayload() and Resolve() as often as needed.

SharedIdPlan plan(transport, ids); // discovery, once
for (int step = 0; step < nSteps; ++step)
{
plan.Gather(u.data(), std::plus<double>{}); // one neighbour exchange
}

Transport is pluggable

Example

auto transport = std::make_shared<CrystalRouterTransport>(comm);
SharedIdPlan plan(transport, ids); // ids[i] is slot i's entity id
std::vector<int> order = myOrders; // one per slot
plan.Gather(order.data(), [](int a, int b){ return std::max(a, b); });
// order[i] is now the highest order across every rank sharing ids[i].
CommSharedPtr nbr = plan.BuildNeighbourComm(comm); // for halo exchange

Definition in file Transport.hpp.