#ifndef BUFFEREXCHANGE_DEFINED #include "base.h" // // Swap data buffers with a specified set of peer ranks. // template class BufferExchange { protected: IntVec ranks; std::vector recv_reqs, send_reqs; IntVec recv_lengths, send_lengths; // temporary, used in FullExchange() - don't rely on these for anything else! int full_exchange_length_tag, full_exchange_buffer_tag, exchange_tag; int _wait( std::vector &reqs ); void _waitall( std::vector &reqs ); public: // ensure the data buffers are publically accessible. std::vector< std::vector > recv_buffers, send_buffers; BufferExchange(); ~BufferExchange(); // // Resets the internal state to reflect a new set of peer ranks. // void Clear( IntVec &_ranks ); // // For when we don't know the sizes of recv_buffers, but we know the sizes of send_buffers. // This is a fully blocking method, it won't return until all comms complete. // void FullExchange(); // // Nonblocking; assumes the lengths of the receive and send buffers are correct. // void PostRecvs(); void PostSends(); // // Blocking wait on ALL receives / sends to complete. // void WaitRecvs(); void WaitSends(); // // Blocking wait on any complete operation. Return index into buffer arrays (NOT MPI RANKS!) // of a completed recv/send. // Return -1 where all outstanding operations are complete. // int WaitRecv(); int WaitSend(); // // Blocks until all cancellations have completed. // void CancelRecvs(); }; #define BUFFEREXCHANGE_DEFINED #endif