|
ADS
Algorithms and Data Structures
|
The mailbox of the processes of MPI, beyond the book, compiled only with ADS_WITH_MPI: the mailbox of the workers of Mailbox.h with a process of a communicator as each worker, and with the detection of the termination of the computation by the four counters of Mattern (see Messages, owners and termination). More...
#include "ADS/Contract.h"#include "ADS/distributed/MPIExecutor.h"#include "ADS/parallel/Mailbox.h"#include <concepts>#include <cstddef>#include <cstdint>#include <cstring>#include <span>#include <string>#include <type_traits>#include <utility>#include <vector>Go to the source code of this file.
Classes | |
| struct | ADS::MPICodec< std::string > |
| the bytes of a string More... | |
| struct | ADS::MPICodec< std::vector< T > > |
| the bytes of a vector of trivially copyable items More... | |
| class | ADS::MPIByteMailbox |
| the mailbox of the processes of a communicator for messages of bytes, each with a tag of its own, in batches of records More... | |
| class | ADS::MPIMailbox< Msg, bool > |
| the mailbox of the processes of a communicator, with outboxes of batches and the detection of the termination by the four counters of Mattern: for a trivially copyable Msg, the batches are arrays of messages, copied as bytes; otherwise [see the specialization below] each message is a record of the bytes that MPICodec< Msg > gives More... | |
| class | ADS::MPIMailbox< Msg, false > |
| the mailbox of the processes of a communicator for the messages that are not trivially copyable, each the record of the bytes that MPICodec< Msg > gives, on an MPIByteMailbox (the same waves, the same stop and the same leftovers()) More... | |
Namespaces | |
| namespace | ADS |
The mailbox of the processes of MPI, beyond the book, compiled only with ADS_WITH_MPI: the mailbox of the workers of Mailbox.h with a process of a communicator as each worker, and with the detection of the termination of the computation by the four counters of Mattern (see Messages, owners and termination).
A process sends by send( to , x ), which appends \( x \) to its outbox for the rank to and, when the outbox holds batch messages, sends it as one message of MPI that does not block (MPI_Isend), the buffer kept in a list of pending sends until MPI has completed it (MPI_Testsome); poll( f ) frees the buffers of the sends completed, then receives the batches that have come (MPI_Iprobe and MPI_Recv, from any process) and calls f( x ) on each message; quiescent(), called by a process with no work left, sends its outboxes and tells whether the whole computation has ended. The messages of a process to itself do not go through MPI. The mailbox duplicates the communicator, so that its messages and its reductions never meet those of the program.
The messages come in three forms, all on the same waves: MPIMailbox< Msg > of a trivially copyable Msg sends its batches as arrays of messages, copied as bytes (several kinds of such messages go as one std::variant, itself trivially copyable); MPIByteMailbox sends messages of any length, each made of bytes and of a tag of 32 bits (send( to , tag , bytes ), and poll( f ) calling f( tag , bytes )), packed into the records of a batch of batch bytes; and MPIMailbox< Msg > of a Msg that is not trivially copyable is an MPIByteMailbox whose messages are the bytes that the customization point MPICodec< Msg > gives (encode() and decode(), given for std::string and for the vectors of trivially copyable items). The waves count the messages, whatever their kind.
stop() ends the computation of all the processes at once, whatever the messages on their way: the process sends a note (an empty batch) to each other one, which stops when its poll() finds it; a process stopped posts and receives nothing more, and contributes to the waves as stopped, so that all the processes see the end at the first wave to which all have contributed stopped. leftovers( f ), a collective operation after quiescent() has returned true, then hands to \( f \) the messages left to the process: those still on their way to it, whose number each process learns by one reduction of the counts of all the senders (MPI_Reduce_scatter_block), those to itself and those of its outboxes; every message sent is so handed to a function exactly once, by a poll() or by leftovers() (see Messages, owners and termination). The destructor makes the same exchange, dropping the messages, if leftovers() was not called.
The termination is detected by waves of counters: each process counts the messages it has sent, \( s_i \), and those it has received, \( r_i \); a wave is a reduction that does not block (MPI_Iallreduce) of the pair \( ( s_i , r_i ) \) of each process into the sums \( ( S , R ) \), to which a process contributes only when it is passive, i.e., from quiescent(), and that it tests at each call of quiescent() while it waits, still receiving and working. A process starts a wave only after the previous one has completed, so that the contributions to a wave all come after those to the previous one; when the wave \( k \) completes with \( S_k = R_{k - 1} \) (the sends counted by the second wave equal the receipts counted by the first), the computation had ended when the wave \( k - 1 \) completed (Mattern's four counters), and every process, having the same sums, stops at the same wave. A wave costs \( O( \log P ) \) steps of latency on \( P \) processes, and the termination is known at most two waves after it happened.
The contracts [see Contract.h]: Msg is trivially copyable or has MPICodec< Msg >; every process of the communicator builds the mailbox and calls quiescent() until it returns true (its waves are collective), and leftovers() if any process calls it; a process sends only while active, i.e., before its first quiescent() or after a poll() that found messages, and becomes active only by receiving; a process that sees stopped() leaves its work and calls quiescent(); f does not throw and does not poll; one thread of the process calls the mailbox.