5 #ifndef DUNE_COMMON_PARALLEL_MPIFUTURE_HH 6 #define DUNE_COMMON_PARALLEL_MPIFUTURE_HH 13 #include <type_traits> 30 value = std::make_unique<T>();
34 : value(
std::make_unique<T>(
std::forward<V>(t)))
36 std::unique_ptr<T> value;
38 T tmp = std::move(*value);
42 operator bool ()
const {
52 Buffer(
bool valid =
false)
59 : value(
std::forward<V>(t))
61 std::optional<std::reference_wrapper<T>> value;
67 operator bool ()
const{
78 Buffer(
bool valid =
false)
81 operator bool ()
const{
92 template<
class R,
class S =
void>
94 mutable MPI_Request req_;
95 mutable MPI_Status status_;
96 Impl::Buffer<R> data_;
97 Impl::Buffer<S> send_data_;
101 : req_(MPI_REQUEST_NULL)
106 template<
class V = R,
class U = S>
107 MPIFuture(V&& recv_data, U&& send_data,
typename std::enable_if_t<!std::is_void<V>::value && !std::is_void<U>::value>* = 0) :
108 req_(MPI_REQUEST_NULL)
109 , data_(
std::forward<R>(recv_data))
110 , send_data_(
std::forward<S>(send_data))
114 template<
class V = R>
115 MPIFuture(V&& recv_data,
typename std::enable_if_t<!std::is_void<V>::value>* = 0)
116 : req_(MPI_REQUEST_NULL)
117 , data_(
std::forward<V>(recv_data))
121 if(req_ != MPI_REQUEST_NULL){
124 MPI_Request_free(&req_);
131 : req_(MPI_REQUEST_NULL)
132 , data_(
std::move(f.data_))
133 , send_data_(
std::move(f.send_data_))
154 MPI_Wait(&req_, &status_);
159 MPI_Test(&req_, &flag, &status_);
170 return send_data_.get();
184 #endif // DUNE_COMMON_PARALLEL_MPIFUTURE_HH bool ready() const
Definition: mpifuture.hh:157
~MPIFuture()
Definition: mpifuture.hh:120
MPIFuture(V &&recv_data, typename std::enable_if_t<!std::is_void< V >::value > *=0)
Definition: mpifuture.hh:115
auto getMPIData(T &t)
Definition: mpidata.hh:44
auto get_send_mpidata()
Definition: mpifuture.hh:177
void wait()
Definition: mpifuture.hh:151
bool valid() const
Definition: mpifuture.hh:147
auto get_mpidata()
Definition: mpifuture.hh:173
MPIFuture(bool valid=false)
Definition: mpifuture.hh:100
S get_send_data()
Definition: mpifuture.hh:168
bigunsignedint< k > operator*(const bigunsignedint< k > &x, std::uintmax_t y)
Definition: bigunsignedint.hh:572
Interface class to translate objects to a MPI_Datatype, void* and size used for MPI calls...
MPIFuture(V &&recv_data, U &&send_data, typename std::enable_if_t<!std::is_void< V >::value &&!std::is_void< U >::value > *=0)
Definition: mpifuture.hh:107
This exception is thrown when ready(), wait() or get() is called on an invalid future. A future is valid until get() is called and if it is not default-constructed and it was not moved from.
Definition: future.hh:19
Collective communication interface and sequential default implementation.
Definition: communication.hh:99
Dune namespace
Definition: alignedallocator.hh:12
#define DUNE_THROW(E,...)
Definition: exceptions.hh:314
MPIFuture & operator=(MPIFuture &&f)
Definition: mpifuture.hh:139
A few common exception classes.
void swap(T &v1, T &v2, bool mask)
Definition: simd.hh:472
Implements an utility class that provides collective communication methods for sequential programs...
Provides a future-like object for MPI communication. It contains the object that will be received and...
Definition: mpifuture.hh:93
MPIFuture(MPIFuture &&f)
Definition: mpifuture.hh:130