|
| subroutine | gs_crystal_plan_init (this, send_pe, recv_pe, send_dof, recv_dof) |
| | Work out the routing plan for a gather-scatter schedule.
|
| subroutine | cr_final_dofs (this, rdest, rorig, rlen, nrec, recv_pe, recv_dof) |
| | Turn the records left at the end of the routing into the reduction order of the delivered words.
|
| subroutine | cr_meta_exchange (sbuf, nsrec, dst, rbuf, nrrec, src) |
| | Size-negotiated bidirectional exchange of record metadata with a partner. Either dst or src may be -1 to make that direction a no-op, which is how the unpaired ranks of an odd sized range are kept matched and deadlock free.
|
| subroutine | gs_crystal_plan_free (this) |
| | Release the routing plan.
|
The crystal router (see crystal_router) delivers records to arbitrary destinations in \( \lceil \log_2 P \rceil \) recursive-bisection stages, talking to at most one partner per stage instead of to every peer at once. For the halo exchange the peer set is fixed by the gather-scatter schedule, so the routing is the same for every gs operation and can be worked out once, here, rather than re-derived from the payload on every call.
The algorithm is the crystal router of Fox et al., "Solving Problems on
Concurrent Processors, Volume 1", Prentice-Hall, 1988.
What this module computes is that plan: for each stage, the partner ranks, the exact word counts to send and receive, and the index lists that move the words which stay put. The runtime is then a fixed sequence of Isend/Irecv of known size plus indexed gathers – no destination scan, no size negotiation, and no allocation, none of which the setup-phase router avoids because it cannot.
What the aggregation buys, and what it costs
One gs operation goes from \( k \) messages to \( k \) peers to at most one message per active stage. Because a partition's peers are close in rank index, most stages have nothing to send or receive and are dropped from the plan entirely, so the active stage count is set by the largest rank distance among the peers rather than by \( \log_2 P \). The price is store and forward: a word bound for a peer several stages away crosses the network once per stage it survives, and is copied locally each time. This trades bandwidth for message count and is worth it only where per-message overhead dominates – few elements per rank, coarse multigrid levels, or a runtime that handles many concurrent peers badly. Which is why the backends built on it are candidates for the runtime autotuning rather than a default.
Record identity
A record is the whole slab of shared dofs one rank sends to one peer, and it is routed intact. Its payload length and its originating rank are all a relay needs; the destination's local dof indices are never shipped, since the destination already knows them as recv_dof(origin). Contributions are therefore reduced at the destination only, exactly as in the pairwise backends. Folding contributions to the same dof at intermediate hops would cut the \( O(k^2) \) traffic of a multiplicity \( k \) vertex to \( O(k \log k) \), but needs the destination's dof identity at the relay and is deliberately left out here.