5#ifndef DUNE_COMMON_PARALLEL_MPIFUTURE_HH
6#define DUNE_COMMON_PARALLEL_MPIFUTURE_HH
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_))
135 std::swap(req_, f.req_);
136 std::swap(status_, f.status_);
140 std::swap(req_, f.req_);
141 std::swap(status_, f.status_);
142 std::swap(data_, f.data_);
143 std::swap(send_data_, f.send_data_);
154 MPI_Wait(&req_, &status_);
159 MPI_Test(&req_, &flag, &status_);
170 return send_data_.get();
Interface class to translate objects to a MPI_Datatype, void* and size used for MPI calls.
Implements an utility class that provides collective communication methods for sequential programs.
A few common exception classes.
#define DUNE_THROW(E,...)
Definition exceptions.hh:314
constexpr decltype(auto) operator*() const
Dereferencing operator.
Definition iteratorfacades.hh:1119
Dune namespace
Definition alignedallocator.hh:13
auto getMPIData(T &t)
Definition mpidata.hh:44
constexpr auto get(std::integer_sequence< T, II... >, std::integral_constant< std::size_t, pos >={})
Return the entry at position pos of the given sequence.
Definition integersequence.hh:22
Collective communication interface and sequential default implementation.
Definition communication.hh:100
This exception is thrown when ready(), wait() or get() is called on an invalid future....
Definition future.hh:20
MPIFuture(V &&recv_data, typename std::enable_if_t<!std::is_void< V >::value > *=0)
Definition mpifuture.hh:115
bool ready() const
Definition mpifuture.hh:157
bool valid() const
Definition mpifuture.hh:147
~MPIFuture()
Definition mpifuture.hh:120
MPIFuture(bool valid=false)
Definition mpifuture.hh:100
MPIFuture & operator=(MPIFuture &&f)
Definition mpifuture.hh:139
auto get_send_mpidata()
Definition mpifuture.hh:177
void wait()
Definition mpifuture.hh:151
auto get_mpidata()
Definition mpifuture.hh:173
R get()
Definition mpifuture.hh:163
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
S get_send_data()
Definition mpifuture.hh:168
MPIFuture(MPIFuture &&f)
Definition mpifuture.hh:130