Dune Core Modules (2.5.0)

collectivecommunication.hh
Go to the documentation of this file.
1// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2// vi: set et ts=4 sw=2 sts=2:
3#ifndef DUNE_COLLECTIVECOMMUNICATION_HH
4#define DUNE_COLLECTIVECOMMUNICATION_HH
12#include <iostream>
13#include <complex>
14#include <algorithm>
15
18
38namespace Dune
39{
40
41 /* define some type that definitely differs from MPI_Comm */
42 struct No_Comm {};
43
44
77 template<typename Communicator>
79 {
80 public:
83 {}
84
89 CollectiveCommunication (const Communicator&)
90 {}
91
93 int rank () const
94 {
95 return 0;
96 }
97
99 int size () const
100 {
101 return 1;
102 }
103
107 template<typename T>
108 T sum (T& in) const // MPI does not know about const :-(
109 {
110 return in;
111 }
112
118 template<typename T>
119 int sum (T* inout, int len) const
120 {
121 return 0;
122 }
123
127 template<typename T>
128 T prod (T& in) const // MPI does not know about const :-(
129 {
130 return in;
131 }
132
138 template<typename T>
139 int prod (T* inout, int len) const
140 {
141 return 0;
142 }
143
147 template<typename T>
148 T min (T& in) const // MPI does not know about const :-(
149 {
150 return in;
151 }
152
158 template<typename T>
159 int min (T* inout, int len) const
160 {
161 return 0;
162 }
163
167 template<typename T>
168 T max (T& in) const // MPI does not know about const :-(
169 {
170 return in;
171 }
172
178 template<typename T>
179 int max (T* inout, int len) const
180 {
181 return 0;
182 }
183
187 int barrier () const
188 {
189 return 0;
190 }
191
195 template<typename T>
196 int broadcast (T* inout, int len, int root) const
197 {
198 return 0;
199 }
200
213 template<typename T>
214 int gather (T* in, T* out, int len, int root) const // note out must have same size as in
215 {
216 for (int i=0; i<len; i++)
217 out[i] = in[i];
218 return 0;
219 }
220
240 template<typename T>
241 int gatherv (T* in, int sendlen, T* out, int* recvlen, int* displ, int root) const
242 {
243 for (int i=*displ; i<sendlen; i++)
244 out[i] = in[i];
245 return 0;
246 }
247
261 template<typename T>
262 int scatter (T* send, T* recv, int len, int root) const // note out must have same size as in
263 {
264 for (int i=0; i<len; i++)
265 recv[i] = send[i];
266 return 0;
267 }
268
287 template<typename T>
288 int scatterv (T* send, int* sendlen, int* displ, T* recv, int recvlen, int root) const
289 {
290 for (int i=*displ; i<*sendlen; i++)
291 recv[i] = send[i];
292 return 0;
293 }
294
308 template<typename T>
309 int allgather(T* sbuf, int count, T* rbuf) const
310 {
311 for(T* end=sbuf+count; sbuf < end; ++sbuf, ++rbuf)
312 *rbuf=*sbuf;
313 return 0;
314 }
315
332 template<typename T>
333 int allgatherv (T* in, int sendlen, T* out, int* recvlen, int* displ) const
334 {
335 for (int i=*displ; i<sendlen; i++)
336 out[i] = in[i];
337 return 0;
338 }
339
352 template<typename BinaryFunction, typename Type>
353 int allreduce(Type* inout, int len) const
354 {
355 return 0;
356 }
357
371 template<typename BinaryFunction, typename Type>
372 void allreduce(Type* in, Type* out, int len) const
373 {
374 std::copy(in, in+len, out);
375 return;
376 }
377
378 };
379}
380
381#endif
Various helper classes derived from from std::binary_function for stl-style functional programming.
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: collectivecommunication.hh:187
T min(T &in) const
Compute the minimum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:148
void allreduce(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: collectivecommunication.hh:372
T max(T &in) const
Compute the maximum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:168
int scatterv(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: collectivecommunication.hh:288
T prod(T &in) const
Compute the product of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:128
CollectiveCommunication()
Construct default object.
Definition: collectivecommunication.hh:82
int broadcast(T *inout, int len, int root) const
Distribute an array from the process with rank root to all other processes.
Definition: collectivecommunication.hh:196
int max(T *inout, int len) const
Compute the maximum over all processes for each component of an array and return the result in every ...
Definition: collectivecommunication.hh:179
int scatter(T *send, T *recv, int len, int root) const
Scatter array from a root to all other task.
Definition: collectivecommunication.hh:262
int rank() const
Return rank, is between 0 and size()-1.
Definition: collectivecommunication.hh:93
int gather(T *in, T *out, int len, int root) const
Gather arrays on root task.
Definition: collectivecommunication.hh:214
int allgather(T *sbuf, int count, T *rbuf) const
Gathers data from all tasks and distribute it to all.
Definition: collectivecommunication.hh:309
int sum(T *inout, int len) const
Compute the sum over all processes for each component of an array and return the result in every proc...
Definition: collectivecommunication.hh:119
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: collectivecommunication.hh:353
int allgatherv(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: collectivecommunication.hh:333
int gatherv(T *in, int sendlen, T *out, int *recvlen, int *displ, int root) const
Gather arrays of variable size on root task.
Definition: collectivecommunication.hh:241
int prod(T *inout, int len) const
Compute the product over all processes for each component of an array and return the result in every ...
Definition: collectivecommunication.hh:139
int size() const
Number of processes in set, is greater than 0.
Definition: collectivecommunication.hh:99
T sum(T &in) const
Compute the sum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:108
CollectiveCommunication(const Communicator &)
Constructor with a given communicator.
Definition: collectivecommunication.hh:89
int min(T *inout, int len) const
Compute the minimum over all processes for each component of an array and return the result in every ...
Definition: collectivecommunication.hh:159
A few common exception classes.
Dune namespace.
Definition: alignment.hh:11
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Jul 15, 22:36, 2024)