template<typename T>
class Utilities::MPI::Future< T >
An object that acts like a std::future object except that it does not encode the operation of waiting for an operation to finish what may be happening on a different thread, but for an "immediate" MPI operation such as MPI_Isend or MPI_Irecv. An object of this kind is returned, for example, by the isend() and irecv() functions in this namespace.
If the operation being waited for produces a result (such as a receive operation, then the produced result is returned by the get() function and its type is indicated by the template argument T. If the operation does not produce a result (such as waiting for a send operation to complete), then T=void is the right choice for the template argument.
Implementation
Immediate MPI operations are typically associated with two additional actions. The first is that one has to be able to wait for them to finish. In many cases, this is done using a call to MPI_Wait that is given an MPI_Request object (in the case of send operations) or a call to MPI_Probe or a variant of this function (in the case of receive operations). The wait operation may be called more than once and would immediately return once the first one has succeeded.
Secondly, immediate MPI operations often require clean-up actions that must be executed once the operation has finished. An example is releasing a buffer in which data has been stored (for an immediate send operation), or allocating a receive buffer, calling the MPI function that puts the received data into this buffer, calling the unpacking function for the data received, and releasing the receive buffer (for an immediate receive operation).
This class models these two steps by taking two constructor arguments that correspond to these two operations. It ensures that upon destruction of the current object, both the wait and clean-up functions are called. Because the clean-up function can only be called once, objects of the current class can not be copied, but they can be moved.
Definition at line 465 of file mpi.h.
Destructor.
If the current object has not been the right hand side of a move operation, and if get() has not been called on the current object, then the destructor blocks until the operation is completed so that the clean-up operations can be performed. As a consequence, if you write code such as
Future< void > isend(const T &object, MPI_Comm communicator, const unsigned int target_rank, const unsigned int mpi_tag=0)
where you do not capture the isend() functions' returned object, then the destructor of the returned object will run immediately at the end of executing this line, and this implies waiting for the isend() function's operations to finish – in other words, you are turning the "immediate send" into a "waiting send" where the line only terminates once the data has been sent and the send buffer is no longer needed. (Note, however, that that is not the same as MPI's concept of a "synchronous send" in which the function only returns once the data has been received.)
Of course, the same happens if you write
where you do capture the returned object, but the destructor is run at the closing brace – also immediately after returning from isend().