3 #ifndef DUNE_MPICOLLECTIVECOMMUNICATION_HH 4 #define DUNE_MPICOLLECTIVECOMMUNICATION_HH 35 template<
typename Type,
typename BinaryFunction>
44 op = std::shared_ptr<MPI_Op>(
new MPI_Op);
45 MPI_Op_create((
void (*)(
void*,
void*,
int*, MPI_Datatype*))&operation,
true,op.get());
50 static void operation (Type *in, Type *inout,
int *len, MPI_Datatype*)
54 for (
int i=0; i< *len; ++i, ++in, ++inout) {
56 temp = func(*in, *inout);
62 static std::shared_ptr<MPI_Op> op;
66 template<
typename Type,
typename BinaryFunction>
69 #define ComposeMPIOp(type,func,op) \ 71 class Generic_MPI_Op<type, func<type> >{ \ 73 static MPI_Op get(){ \ 78 Generic_MPI_Op (const Generic_MPI_Op & ) {}\ 149 if(communicator!=MPI_COMM_NULL) {
151 MPI_Initialized(&initialized);
153 DUNE_THROW(
ParallelError,
"You must call MPIHelper::instance(argc,argv) in your main() function before using the MPI CollectiveCommunication!");
154 MPI_Comm_rank(communicator,&me);
155 MPI_Comm_size(communicator,&procs);
179 allreduce<std::plus<T> >(&in,&out,1);
185 int sum (T* inout,
int len)
const 187 return allreduce<std::plus<T> >(inout,len);
195 allreduce<std::multiplies<T> >(&in,&out,1);
201 int prod (T* inout,
int len)
const 203 return allreduce<std::multiplies<T> >(inout,len);
211 allreduce<Min<T> >(&in,&out,1);
217 int min (T* inout,
int len)
const 219 return allreduce<Min<T> >(inout,len);
228 allreduce<Max<T> >(&in,&out,1);
234 int max (T* inout,
int len)
const 236 return allreduce<Max<T> >(inout,len);
242 return MPI_Barrier(communicator);
255 int gather (
const T* in, T* out,
int len,
int root)
const 264 int gatherv (
const T* in,
int sendlen, T* out,
int* recvlen,
int* displ,
int root)
const 274 int scatter (
const T* send, T* recv,
int len,
int root)
const 283 int scatterv (
const T* send,
int* sendlen,
int* displ, T* recv,
int recvlen,
int root)
const 291 operator MPI_Comm ()
const 297 template<
typename T,
typename T1>
307 int allgatherv (
const T* in,
int sendlen, T* out,
int* recvlen,
int* displ)
const 315 template<
typename BinaryFunction,
typename Type>
318 Type* out =
new Type[len];
319 int ret = allreduce<BinaryFunction>(inout,out,len);
320 std::copy(out, out+len, inout);
326 template<
typename BinaryFunction,
typename Type>
334 MPI_Comm communicator;
int scatterv(const T *send, int *sendlen, int *displ, T *recv, int recvlen, int root) const
Scatter arrays of variable length from a root to all other tasks.
Definition: mpicollectivecommunication.hh:283
int sum(T *inout, int len) const
Compute the sum of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:185
Implements an utility class that provides collective communication methods for sequential programs...
T min(const T &in) const
Compute the minimum of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:208
int broadcast(T *inout, int len, int root) const
Distribute an array from the process with rank root to all other processes.
Definition: mpicollectivecommunication.hh:247
int gatherv(const T *in, int sendlen, T *out, int *recvlen, int *displ, int root) const
Gather arrays of variable size on root task.
Definition: mpicollectivecommunication.hh:264
Traits classes for mapping types onto MPI_Datatype.
int size() const
Number of processes in set, is greater than 0.
Definition: mpicollectivecommunication.hh:169
Collective communication interface and sequential default implementation.
Definition: collectivecommunication.hh:79
int barrier() const
Wait until all processes have arrived at this point in the program.
Definition: mpicollectivecommunication.hh:240
int allreduce(const Type *in, Type *out, int len) const
Definition: mpicollectivecommunication.hh:327
T sum(const T &in) const
Compute the sum of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:176
int max(T *inout, int len) const
Compute the maximum of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:234
A few common exception classes.
Dune namespace.
Definition: alignedallocator.hh:9
int scatter(const T *send, T *recv, int len, int root) const
Scatter array from a root to all other task.
Definition: mpicollectivecommunication.hh:274
int allgatherv(const T *in, int sendlen, T *out, int *recvlen, int *displ) const
Gathers data of variable length from all tasks and distribute it to all.
Definition: mpicollectivecommunication.hh:307
Various helper classes derived from from std::binary_function for stl-style functional programming...
int allgather(const T *sbuf, int count, T1 *rbuf) const
Gathers data from all tasks and distribute it to all.
Definition: mpicollectivecommunication.hh:298
int min(T *inout, int len) const
Compute the minimum of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:217
CollectiveCommunication(const MPI_Comm &c=MPI_COMM_WORLD)
Instantiation using a MPI communicator.
Definition: mpicollectivecommunication.hh:146
int prod(T *inout, int len) const
Compute the product of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:201
T max(const T &in) const
Compute the maximum of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:225
A traits class describing the mapping of types onto MPI_Datatypes.
Definition: bigunsignedint.hh:25
ComposeMPIOp(char, std::plus, MPI_SUM)
int gather(const T *in, T *out, int len, int root) const
Gather arrays on root task.
Definition: mpicollectivecommunication.hh:255
int allreduce(Type *inout, int len) const
Compute something over all processes for each component of an array and return the result in every pr...
Definition: mpicollectivecommunication.hh:316
T prod(const T &in) const
Compute the product of the argument over all processes and return the result in every process...
Definition: mpicollectivecommunication.hh:192
Definition: mpicollectivecommunication.hh:36
Default exception if an error in the parallel communication of the program occurred.
Definition: exceptions.hh:285
#define DUNE_THROW(E, m)
Definition: exceptions.hh:216
int rank() const
Return rank, is between 0 and size()-1.
Definition: mpicollectivecommunication.hh:163