5#ifndef DUNE_COMMON_PARALLEL_MPIFUTURE_HH
6#define DUNE_COMMON_PARALLEL_MPIFUTURE_HH
20#include <dune/common/parallel/future.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 {
45 T& operator *()
const{
52 Buffer(
bool valid =
false)
59 : value(
std::forward<V>(t))
61 std::optional<std::reference_wrapper<T>> value;
67 operator bool ()
const{
70 T& operator *()
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();
174 return getMPIData(*data_);
177 auto get_send_mpidata(){
178 return getMPIData(*send_data_);
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
Provides a future-like object for MPI communication. It contains the object that will be received and...
Definition: mpifuture.hh:93
Implements an utility class that provides collective communication methods for sequential programs.
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:218
Interface class to translate objects to a MPI_Datatype, void* and size used for MPI calls.
Dune namespace.
Definition: alignedallocator.hh:13
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