Dune Core Modules (2.4.2)

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
71 template<typename C>
73 {
74 public:
77 {}
79 {}
80
82 int rank () const
83 {
84 return 0;
85 }
86
88 int size () const
89 {
90 return 1;
91 }
92
96 template<typename T>
97 T sum (T& in) const // MPI does not know about const :-(
98 {
99 return in;
100 }
101
105 template<typename T>
106 int sum (T* inout, int len) const
107 {
108 return 0;
109 }
110
114 template<typename T>
115 T prod (T& in) const // MPI does not know about const :-(
116 {
117 return in;
118 }
119
124 template<typename T>
125 int prod (T* inout, int len) const
126 {
127 return 0;
128 }
129
133 template<typename T>
134 T min (T& in) const // MPI does not know about const :-(
135 {
136 return in;
137 }
138
143 template<typename T>
144 int min (T* inout, int len) const
145 {
146 return 0;
147 }
148
152 template<typename T>
153 T max (T& in) const // MPI does not know about const :-(
154 {
155 return in;
156 }
157
162 template<typename T>
163 int max (T* inout, int len) const
164 {
165 return 0;
166 }
167
170 int barrier () const
171 {
172 return 0;
173 }
174
177 template<typename T>
178 int broadcast (T* inout, int len, int root) const
179 {
180 return 0;
181 }
182
194 template<typename T>
195 int gather (T* in, T* out, int len, int root) const // note out must have same size as in
196 {
197 for (int i=0; i<len; i++)
198 out[i] = in[i];
199 return 0;
200 }
201
220 template<typename T>
221 int gatherv (T* in, int sendlen, T* out, int* recvlen, int* displ, int root) const
222 {
223 for (int i=*displ; i<sendlen; i++)
224 out[i] = in[i];
225 return 0;
226 }
227
240 template<typename T>
241 int scatter (T* send, T* recv, int len, int root) const // note out must have same size as in
242 {
243 for (int i=0; i<len; i++)
244 recv[i] = send[i];
245 return 0;
246 }
247
265 template<typename T>
266 int scatterv (T* send, int* sendlen, int* displ, T* recv, int recvlen, int root) const
267 {
268 for (int i=*displ; i<*sendlen; i++)
269 recv[i] = send[i];
270 return 0;
271 }
272
285 template<typename T>
286 int allgather(T* sbuf, int count, T* rbuf) const
287 {
288 for(T* end=sbuf+count; sbuf < end; ++sbuf, ++rbuf)
289 *rbuf=*sbuf;
290 return 0;
291 }
292
308 template<typename T>
309 int allgatherv (T* in, int sendlen, T* out, int* recvlen, int* displ) const
310 {
311 for (int i=*displ; i<sendlen; i++)
312 out[i] = in[i];
313 return 0;
314 }
315
327 template<typename BinaryFunction, typename Type>
328 int allreduce(Type* inout, int len) const
329 {
330 return 0;
331 }
332
345 template<typename BinaryFunction, typename Type>
346 void allreduce(Type* in, Type* out, int len) const
347 {
348 std::copy(in, in+len, out);
349 return;
350 }
351
352 };
353}
354
355#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:73
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:144
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:163
int rank() const
Return rank, is between 0 and size()-1.
Definition: collectivecommunication.hh:82
int size() const
Number of processes in set, is greater than 0.
Definition: collectivecommunication.hh:88
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:328
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: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:106
int barrier() const
Wait until all processes have arrived at this point in the program.
Definition: collectivecommunication.hh:170
int gather(T *in, T *out, int len, int root) const
Gather arrays on root task.
Definition: collectivecommunication.hh:195
T max(T &in) const
Compute the maximum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:153
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:266
int scatter(T *send, T *recv, int len, int root) const
Scatter array from a root to all other task.
Definition: collectivecommunication.hh:241
T min(T &in) const
Compute the minimum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:134
T sum(T &in) const
Compute the sum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:97
int allgather(T *sbuf, int count, T *rbuf) const
Gathers data from all tasks and distribute it to all.
Definition: collectivecommunication.hh:286
CollectiveCommunication()
Construct default object.
Definition: collectivecommunication.hh:76
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:221
T prod(T &in) const
Compute the product of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:115
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:178
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:125
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:346
A few common exception classes.
Dune namespace.
Definition: alignment.hh:10
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 21, 23:30, 2024)