3 #ifndef DUNE_COMMON_PARALLEL_COMMUNICATION_HH
4 #define DUNE_COMMON_PARALLEL_COMMUNICATION_HH
96 template<
typename Communicator>
133 int send([[maybe_unused]]
const T& data,
134 [[maybe_unused]]
int dest_rank,
135 [[maybe_unused]]
int tag)
145 [[maybe_unused]]
int dest_rank,
146 [[maybe_unused]]
int tag)
155 T
recv([[maybe_unused]] T&& data,
156 [[maybe_unused]]
int source_rank,
157 [[maybe_unused]]
int tag,
158 [[maybe_unused]]
void* status = 0)
168 [[maybe_unused]]
int source_rank,
169 [[maybe_unused]]
int tag)
176 [[maybe_unused]]
int source_rank,
177 [[maybe_unused]]
int tag,
178 [[maybe_unused]]
void* status = 0)
const
197 int sum ([[maybe_unused]] T* inout, [[maybe_unused]]
int len)
const
217 int prod ([[maybe_unused]] T* inout, [[maybe_unused]]
int len)
const
237 int min ([[maybe_unused]] T* inout, [[maybe_unused]]
int len)
const
257 int max ([[maybe_unused]] T* inout, [[maybe_unused]]
int len)
const
283 [[maybe_unused]]
int len,
284 [[maybe_unused]]
int root)
const
294 return {std::forward<T>(data)};
311 int gather (
const T* in, T* out,
int len, [[maybe_unused]]
int root)
const
313 for (
int i=0; i<len; i++)
321 template<
class TIN,
class TOUT = std::vector<TIN>>
323 *(data_out.begin()) = std::forward<TIN>(data_in);
324 return {std::forward<TOUT>(data_out)};
351 [[maybe_unused]]
int* recvDataLen,
353 [[maybe_unused]]
int root)
const
355 for (
int i=*displ; i<sendDataLen; i++)
374 int scatter (
const T* sendData, T* recvData,
int len, [[maybe_unused]]
int root)
const
376 for (
int i=0; i<len; i++)
377 recvData[i] = sendData[i];
384 template<
class TIN,
class TOUT = TIN>
386 data_out = *(std::forward<TIN>(data_in).begin());
387 return {std::forward<TOUT>(data_out)};
409 int scatterv (
const T* sendData,
int* sendDataLen,
int* displ, T* recvData,
410 [[maybe_unused]]
int recvDataLen, [[maybe_unused]]
int root)
const
412 for (
int i=*displ; i<*sendDataLen; i++)
413 recvData[i] = sendData[i];
433 for(
const T* end=sbuf+count; sbuf < end; ++sbuf, ++rbuf)
442 template<
class TIN,
class TOUT = TIN>
444 return {std::forward<TOUT>(data_out)};
464 int allgatherv (
const T* in,
int sendDataLen, T* out, [[maybe_unused]]
int* recvDataLen,
int* displ)
const
466 for (
int i=*displ; i<sendDataLen; i++)
483 template<
typename BinaryFunction,
typename Type>
484 int allreduce([[maybe_unused]] Type* inout, [[maybe_unused]]
int len)
const
493 template<
class BinaryFunction,
class TIN,
class TOUT = TIN>
495 data_out = std::forward<TIN>(data_in);
496 return {std::forward<TOUT>(data_out)};
503 template<
class BinaryFunction,
class T>
505 return {std::forward<T>(data)};
522 template<
typename BinaryFunction,
typename Type>
525 std::copy(in, in+len, out);
helper classes to provide unique types for standard functions
A few common exception classes.
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
EnableIfInterOperable< T1, T2, bool >::type operator!=(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for inequality.
Definition: iteratorfacades.hh:257
EnableIfInterOperable< T1, T2, bool >::type operator==(const ForwardIteratorFacade< T1, V1, R1, D > &lhs, const ForwardIteratorFacade< T2, V2, R2, D > &rhs)
Checks for equality.
Definition: iteratorfacades.hh:235
Dune namespace.
Definition: alignedallocator.hh:11
Default exception if an error in the parallel communication of the program occurred.
Definition: exceptions.hh:285
Definition: communication.hh:44
Collective communication interface and sequential default implementation.
Definition: communication.hh:98
PseudoFuture< void > ibarrier() const
Nonblocking barrier.
Definition: communication.hh:273
PseudoFuture< T > irecv([[maybe_unused]] T &&data, [[maybe_unused]] int source_rank, [[maybe_unused]] int tag)
Receives the data from the source_rank nonblocking.
Definition: communication.hh:167
int allreduce(const Type *in, Type *out, int len) const
Compute something over all processes for each component of an array and return the result in every pr...
Definition: communication.hh:523
T max(const T &in) const
Compute the maximum of the argument over all processes and return the result in every process....
Definition: communication.hh:246
int gatherv(const T *in, int sendDataLen, T *out, [[maybe_unused]] int *recvDataLen, int *displ, [[maybe_unused]] int root) const
Gather arrays of variable size on root task.
Definition: communication.hh:348
int broadcast([[maybe_unused]] T *inout, [[maybe_unused]] int len, [[maybe_unused]] int root) const
Distribute an array from the process with rank root to all other processes.
Definition: communication.hh:282
int rank() const
Return rank, is between 0 and size()-1.
Definition: communication.hh:112
T sum(const T &in) const
Compute the sum of the argument over all processes and return the result in every process....
Definition: communication.hh:186
int prod([[maybe_unused]] T *inout, [[maybe_unused]] int len) const
Compute the product over all processes for each component of an array and return the result in every ...
Definition: communication.hh:217
int size() const
Number of processes in set, is greater than 0.
Definition: communication.hh:124
int scatterv(const T *sendData, int *sendDataLen, int *displ, T *recvData, [[maybe_unused]] int recvDataLen, [[maybe_unused]] int root) const
Scatter arrays of variable length from a root to all other tasks.
Definition: communication.hh:409
T rrecv([[maybe_unused]] T &&data, [[maybe_unused]] int source_rank, [[maybe_unused]] int tag, [[maybe_unused]] void *status=0) const
Definition: communication.hh:175
PseudoFuture< TOUT > iallreduce(TIN &&data_in, TOUT &&data_out)
Compute something over all processes nonblocking.
Definition: communication.hh:494
T min(const T &in) const
Compute the minimum of the argument over all processes and return the result in every process....
Definition: communication.hh:226
int allgather(const T *sbuf, int count, T *rbuf) const
Gathers data from all tasks and distribute it to all.
Definition: communication.hh:431
PseudoFuture< TOUT > iallgather(TIN &&data_in, TOUT &&data_out)
Gathers data from all tasks and distribute it to all nonblocking.
Definition: communication.hh:443
int scatter(const T *sendData, T *recvData, int len, [[maybe_unused]] int root) const
Scatter array from a root to all other task.
Definition: communication.hh:374
PseudoFuture< T > isend([[maybe_unused]] const T &&data, [[maybe_unused]] int dest_rank, [[maybe_unused]] int tag)
Sends the data to the dest_rank nonblocking.
Definition: communication.hh:144
Communication(const Communicator &)
Constructor with a given communicator.
Definition: communication.hh:108
PseudoFuture< T > iallreduce(T &&data)
Compute something over all processes nonblocking and in-place.
Definition: communication.hh:504
int gather(const T *in, T *out, int len, [[maybe_unused]] int root) const
Gather arrays on root task.
Definition: communication.hh:311
T prod(const T &in) const
Compute the product of the argument over all processes and return the result in every process....
Definition: communication.hh:206
PseudoFuture< T > ibroadcast(T &&data, int root) const
Distribute an array from the process with rank root to all other processes nonblocking.
Definition: communication.hh:293
int min([[maybe_unused]] T *inout, [[maybe_unused]] int len) const
Compute the minimum over all processes for each component of an array and return the result in every ...
Definition: communication.hh:237
PseudoFuture< TOUT > igather(TIN &&data_in, TOUT &&data_out, int root)
Gather arrays on root task nonblocking.
Definition: communication.hh:322
int send([[maybe_unused]] const T &data, [[maybe_unused]] int dest_rank, [[maybe_unused]] int tag)
Sends the data to the dest_rank.
Definition: communication.hh:133
T recv([[maybe_unused]] T &&data, [[maybe_unused]] int source_rank, [[maybe_unused]] int tag, [[maybe_unused]] void *status=0)
Receives the data from the source_rank.
Definition: communication.hh:155
int barrier() const
Wait until all processes have arrived at this point in the program.
Definition: communication.hh:265
int max([[maybe_unused]] T *inout, [[maybe_unused]] int len) const
Compute the maximum over all processes for each component of an array and return the result in every ...
Definition: communication.hh:257
PseudoFuture< TOUT > iscatter(TIN &&data_in, TOUT &&data_out, int root)
Scatter array from a root to all other task nonblocking.
Definition: communication.hh:385
int allgatherv(const T *in, int sendDataLen, T *out, [[maybe_unused]] int *recvDataLen, int *displ) const
Gathers data of variable length from all tasks and distribute it to all.
Definition: communication.hh:464
int sum([[maybe_unused]] T *inout, [[maybe_unused]] int len) const
Compute the sum over all processes for each component of an array and return the result in every proc...
Definition: communication.hh:197
Communication()
Construct default object.
Definition: communication.hh:101
int allreduce([[maybe_unused]] Type *inout, [[maybe_unused]] int len) const
Compute something over all processes for each component of an array and return the result in every pr...
Definition: communication.hh:484
A wrapper-class for a object which is ready immediately.
Definition: future.hh:120
Definition: future.hh:158