00001
00002
00003 #ifndef DUNE_COLLECTIVECOMMUNICATION_HH
00004 #define DUNE_COLLECTIVECOMMUNICATION_HH
00005
00012 #include <iostream>
00013 #include <complex>
00014 #include <algorithm>
00015
00016 #include <dune/common/binaryfunctions.hh>
00017 #include <dune/common/exceptions.hh>
00018
00038 namespace Dune
00039 {
00040
00041
00042 struct No_Comm {};
00043
00044
00077 template<typename Communicator>
00078 class CollectiveCommunication
00079 {
00080 public:
00082 CollectiveCommunication()
00083 {}
00084
00089 CollectiveCommunication (const Communicator&)
00090 {}
00091
00093 int rank () const
00094 {
00095 return 0;
00096 }
00097
00099 int size () const
00100 {
00101 return 1;
00102 }
00103
00107 template<typename T>
00108 T sum (T& in) const
00109 {
00110 return in;
00111 }
00112
00118 template<typename T>
00119 int sum (T* inout, int len) const
00120 {
00121 return 0;
00122 }
00123
00127 template<typename T>
00128 T prod (T& in) const
00129 {
00130 return in;
00131 }
00132
00138 template<typename T>
00139 int prod (T* inout, int len) const
00140 {
00141 return 0;
00142 }
00143
00147 template<typename T>
00148 T min (T& in) const
00149 {
00150 return in;
00151 }
00152
00158 template<typename T>
00159 int min (T* inout, int len) const
00160 {
00161 return 0;
00162 }
00163
00167 template<typename T>
00168 T max (T& in) const
00169 {
00170 return in;
00171 }
00172
00178 template<typename T>
00179 int max (T* inout, int len) const
00180 {
00181 return 0;
00182 }
00183
00187 int barrier () const
00188 {
00189 return 0;
00190 }
00191
00195 template<typename T>
00196 int broadcast (T* inout, int len, int root) const
00197 {
00198 return 0;
00199 }
00200
00213 template<typename T>
00214 int gather (T* in, T* out, int len, int root) const
00215 {
00216 for (int i=0; i<len; i++)
00217 out[i] = in[i];
00218 return 0;
00219 }
00220
00240 template<typename T>
00241 int gatherv (T* in, int sendlen, T* out, int* recvlen, int* displ, int root) const
00242 {
00243 for (int i=*displ; i<sendlen; i++)
00244 out[i] = in[i];
00245 return 0;
00246 }
00247
00261 template<typename T>
00262 int scatter (T* send, T* recv, int len, int root) const
00263 {
00264 for (int i=0; i<len; i++)
00265 recv[i] = send[i];
00266 return 0;
00267 }
00268
00287 template<typename T>
00288 int scatterv (T* send, int* sendlen, int* displ, T* recv, int recvlen, int root) const
00289 {
00290 for (int i=*displ; i<*sendlen; i++)
00291 recv[i] = send[i];
00292 return 0;
00293 }
00294
00308 template<typename T>
00309 int allgather(T* sbuf, int count, T* rbuf) const
00310 {
00311 for(T* end=sbuf+count; sbuf < end; ++sbuf, ++rbuf)
00312 *rbuf=*sbuf;
00313 return 0;
00314 }
00315
00332 template<typename T>
00333 int allgatherv (T* in, int sendlen, T* out, int* recvlen, int* displ) const
00334 {
00335 for (int i=*displ; i<sendlen; i++)
00336 out[i] = in[i];
00337 return 0;
00338 }
00339
00352 template<typename BinaryFunction, typename Type>
00353 int allreduce(Type* inout, int len) const
00354 {
00355 return 0;
00356 }
00357
00371 template<typename BinaryFunction, typename Type>
00372 void allreduce(Type* in, Type* out, int len) const
00373 {
00374 std::copy(in, in+len, out);
00375 return;
00376 }
00377
00378 };
00379 }
00380
00381 #endif