3#ifndef DUNE_COMMON_PARALLEL_MPIFUTURE_HH
4#define DUNE_COMMON_PARALLEL_MPIFUTURE_HH
6#include <dune/common/std/optional.hh>
8#include <dune/common/parallel/future.hh>
19 value = std::make_unique<T>();
23 : value(
std::make_unique<T>(
std::forward<V>(t)))
25 std::unique_ptr<T> value;
27 T tmp = std::move(*value);
31 operator bool ()
const {
34 T& operator *()
const{
41 Buffer(
bool valid =
false)
48 : value(
std::forward<V>(t))
50 Std::optional<std::reference_wrapper<T>> value;
56 operator bool ()
const{
59 T& operator *()
const{
67 Buffer(
bool valid =
false)
70 operator bool ()
const{
81 template<
class R,
class S =
void>
83 mutable MPI_Request req_;
84 mutable MPI_Status status_;
85 impl::Buffer<R> data_;
86 impl::Buffer<S> send_data_;
90 : req_(MPI_REQUEST_NULL)
95 template<
class V = R,
class U = S>
96 MPIFuture(V&& recv_data, U&& send_data,
typename std::enable_if_t<!std::is_void<V>::value && !std::is_void<U>::value>* = 0) :
97 req_(MPI_REQUEST_NULL)
98 , data_(std::forward<R>(recv_data))
99 , send_data_(std::forward<S>(send_data))
103 template<
class V = R>
104 MPIFuture(V&& recv_data,
typename std::enable_if_t<!std::is_void<V>::value>* = 0)
105 : req_(MPI_REQUEST_NULL)
106 , data_(std::forward<V>(recv_data))
110 if(req_ != MPI_REQUEST_NULL){
113 MPI_Request_free(&req_);
120 : req_(MPI_REQUEST_NULL)
121 , data_(std::move(f.data_))
122 , send_data_(std::move(f.send_data_))
124 std::swap(req_, f.req_);
125 std::swap(status_, f.status_);
129 std::swap(req_, f.req_);
130 std::swap(status_, f.status_);
131 std::swap(data_, f.data_);
132 std::swap(send_data_, f.send_data_);
143 MPI_Wait(&req_, &status_);
148 MPI_Test(&req_, &flag, &status_);
159 return send_data_.get();
163 return getMPIData<R>(*data_);
166 auto get_send_mpidata(){
167 return getMPIData<S>(*send_data_);
Collective communication interface and sequential default implementation.
Definition: communication.hh:81
This exception is thrown when ready(), wait() or get() is called on an invalid future....
Definition: future.hh:16
Provides a future-like object for MPI communication. It contains the object that will be received and...
Definition: mpifuture.hh:82
Implements an utility class that provides collective communication methods for sequential programs.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
Interface class to translate objects to a MPI_Datatype, void* and size used for MPI calls.
Dune namespace.
Definition: alignedallocator.hh:14