deal.II version GIT relicensing-2287-g6548a49e0a 2024-12-20 18:30:00+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
Utilities::MPI::Future< T > Class Template Reference

#include <deal.II/base/mpi.h>

Public Member Functions

template<typename W , typename G >
 Future (W &&wait_operation, G &&get_and_cleanup_operation)
 
 Future (const Future &)=delete
 
 Future (Future &&) noexcept=default
 
 ~Future ()
 
Futureoperator= (const Future &)=delete
 
Futureoperator= (Future &&) noexcept=default
 
void wait ()
 
get ()
 

Private Attributes

std::function< void()> wait_function
 
std::function< T()> get_and_cleanup_function
 
bool is_done
 
bool get_was_called
 

Detailed Description

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 that 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 457 of file mpi.h.

Constructor & Destructor Documentation

◆ Future() [1/3]

template<typename T >
template<typename W , typename G >
Utilities::MPI::Future< T >::Future ( W &&  wait_operation,
G &&  get_and_cleanup_operation 
)

Constructor. Take both the wait and clean-up functions mentioned in the class documentation as arguments.

◆ Future() [2/3]

template<typename T >
Utilities::MPI::Future< T >::Future ( const Future< T > &  )
delete

Copy constructor. This operation is not possible, as explained in the class documentation, and consequently the constructor is deleted.

◆ Future() [3/3]

template<typename T >
Utilities::MPI::Future< T >::Future ( Future< T > &&  )
defaultnoexcept

Move constructor.

◆ ~Future()

template<typename T >
Utilities::MPI::Future< T >::~Future ( )

Destructor.

Member Function Documentation

◆ operator=() [1/2]

template<typename T >
Future & Utilities::MPI::Future< T >::operator= ( const Future< T > &  )
delete

Copy operator. This operation is not possible, as explained in the class documentation, and consequently the operator is deleted.

◆ operator=() [2/2]

template<typename T >
Future & Utilities::MPI::Future< T >::operator= ( Future< T > &&  )
defaultnoexcept

Move operator.

◆ wait()

template<typename T >
void Utilities::MPI::Future< T >::wait ( )

Wait for the operation to complete. This function can safely be called more than once. It will wait for the operation to complete the first time it is called; because the operation will have completed once it has been called for the first time, it will immediately return if called again at a later time.

◆ get()

template<typename T >
T Utilities::MPI::Future< T >::get ( )

Wait for the operation to complete and return the object the operation produces (if T is not equal to void).

Like for std::future, this function can only be called once because the class does not store the object produced. (It can not store the object being produced because returning it from this function would require the ability to copy it; however, not all objects can be copied, whereas all useful objects can be moved.)

Member Data Documentation

◆ wait_function

template<typename T >
std::function<void()> Utilities::MPI::Future< T >::wait_function
private

Function objects encoding the wait and clean-up operations.

Definition at line 526 of file mpi.h.

◆ get_and_cleanup_function

template<typename T >
std::function<T()> Utilities::MPI::Future< T >::get_and_cleanup_function
private

Definition at line 527 of file mpi.h.

◆ is_done

template<typename T >
bool Utilities::MPI::Future< T >::is_done
private

Whether or not wait() has already been called.

Definition at line 532 of file mpi.h.

◆ get_was_called

template<typename T >
bool Utilities::MPI::Future< T >::get_was_called
private

Whether or not get() has already been called.

Definition at line 537 of file mpi.h.


The documentation for this class was generated from the following file: