Dune Core Modules (2.6.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#include <dune/common/unused.hh>
19
39namespace Dune
40{
41
42 /* define some type that definitely differs from MPI_Comm */
43 struct No_Comm {};
44
45
78 template<typename Communicator>
80 {
81 public:
84 {}
85
90 CollectiveCommunication (const Communicator&)
91 {}
92
94 int rank () const
95 {
96 return 0;
97 }
98
100 int size () const
101 {
102 return 1;
103 }
104
108 template<typename T>
109 T sum (const T& in) const
110 {
111 return in;
112 }
113
119 template<typename T>
120 int sum (T* inout, int len) const
121 {
124 return 0;
125 }
126
130 template<typename T>
131 T prod (const T& in) const
132 {
133 return in;
134 }
135
141 template<typename T>
142 int prod (T* inout, int len) const
143 {
146 return 0;
147 }
148
152 template<typename T>
153 T min (const T& in) const
154 {
155 return in;
156 }
157
163 template<typename T>
164 int min (T* inout, int len) const
165 {
168 return 0;
169 }
170
174 template<typename T>
175 T max (const T& in) const
176 {
177 return in;
178 }
179
185 template<typename T>
186 int max (T* inout, int len) const
187 {
190 return 0;
191 }
192
196 int barrier () const
197 {
198 return 0;
199 }
200
204 template<typename T>
205 int broadcast (T* inout, int len, int root) const
206 {
210 return 0;
211 }
212
225 template<typename T>
226 int gather (const T* in, T* out, int len, int root) const // note out must have same size as in
227 {
229 for (int i=0; i<len; i++)
230 out[i] = in[i];
231 return 0;
232 }
233
253 template<typename T>
254 int gatherv (const T* in, int sendlen, T* out, int* recvlen, int* displ, int root) const
255 {
256 DUNE_UNUSED_PARAMETER(recvlen);
258 for (int i=*displ; i<sendlen; i++)
259 out[i] = in[i];
260 return 0;
261 }
262
276 template<typename T>
277 int scatter (const T* send, T* recv, int len, int root) const // note out must have same size as in
278 {
280 for (int i=0; i<len; i++)
281 recv[i] = send[i];
282 return 0;
283 }
284
303 template<typename T>
304 int scatterv (const T* send, int* sendlen, int* displ, T* recv, int recvlen, int root) const
305 {
306 DUNE_UNUSED_PARAMETER(recvlen);
308 for (int i=*displ; i<*sendlen; i++)
309 recv[i] = send[i];
310 return 0;
311 }
312
326 template<typename T>
327 int allgather(const T* sbuf, int count, T* rbuf) const
328 {
329 for(const T* end=sbuf+count; sbuf < end; ++sbuf, ++rbuf)
330 *rbuf=*sbuf;
331 return 0;
332 }
333
350 template<typename T>
351 int allgatherv (const T* in, int sendlen, T* out, int* recvlen, int* displ) const
352 {
353 DUNE_UNUSED_PARAMETER(recvlen);
354 for (int i=*displ; i<sendlen; i++)
355 out[i] = in[i];
356 return 0;
357 }
358
371 template<typename BinaryFunction, typename Type>
372 int allreduce(Type* inout, int len) const
373 {
376 return 0;
377 }
378
392 template<typename BinaryFunction, typename Type>
393 void allreduce(const Type* in, Type* out, int len) const
394 {
395 std::copy(in, in+len, out);
396 return;
397 }
398
399 };
400}
401
402#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:80
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: collectivecommunication.hh:304
int barrier() const
Wait until all processes have arrived at this point in the program.
Definition: collectivecommunication.hh:196
T max(const T &in) const
Compute the maximum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:175
int scatter(const T *send, T *recv, int len, int root) const
Scatter array from a root to all other task.
Definition: collectivecommunication.hh:277
CollectiveCommunication()
Construct default object.
Definition: collectivecommunication.hh:83
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:205
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:186
T min(const T &in) const
Compute the minimum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:153
int rank() const
Return rank, is between 0 and size()-1.
Definition: collectivecommunication.hh:94
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:120
T prod(const T &in) const
Compute the product of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:131
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:372
int allgather(const T *sbuf, int count, T *rbuf) const
Gathers data from all tasks and distribute it to all.
Definition: collectivecommunication.hh:327
void 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: collectivecommunication.hh:393
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:142
int size() const
Number of processes in set, is greater than 0.
Definition: collectivecommunication.hh:100
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: collectivecommunication.hh:351
T sum(const T &in) const
Compute the sum of the argument over all processes and return the result in every process....
Definition: collectivecommunication.hh:109
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: collectivecommunication.hh:254
int gather(const T *in, T *out, int len, int root) const
Gather arrays on root task.
Definition: collectivecommunication.hh:226
CollectiveCommunication(const Communicator &)
Constructor with a given communicator.
Definition: collectivecommunication.hh:90
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:164
A few common exception classes.
#define DUNE_UNUSED_PARAMETER(parm)
A macro to mark intentionally unused function parameters with.
Definition: unused.hh:25
Dune namespace.
Definition: alignedallocator.hh:10
Definition of the DUNE_UNUSED macro for the case that config.h is not available.
Creative Commons License   |  Legal Statements / Impressum  |  Hosted by TU Dresden  |  generated with Hugo v0.111.3 (Dec 26, 23:30, 2024)