dune-common 2.1.1
collectivecommunication.hh
Go to the documentation of this file.
00001 #ifndef DUNE_COLLECTIVECOMMUNICATION_HH
00002 #define DUNE_COLLECTIVECOMMUNICATION_HH
00003 
00004 #include<iostream>
00005 #include<complex>
00006 #include<algorithm>
00007 
00008 #include"exceptions.hh"
00009 
00024 namespace Dune
00025 {
00026 
00027   /* define some type that definitely differs from MPI_Comm */
00028   struct No_Comm {};
00029 
00030 
00057   template<typename C>
00058   class CollectiveCommunication
00059   {
00060   public:
00062     CollectiveCommunication()
00063     {}
00064         CollectiveCommunication (const C&)
00065         {}
00066 
00068         int rank () const
00069         {
00070           return 0;
00071         }
00072 
00074         int size () const
00075         {
00076           return 1;
00077         }
00078 
00082         template<typename T>
00083         T sum (T& in) const // MPI does not know about const :-(
00084         {
00085           return in;
00086         }
00087 
00091         template<typename T>
00092         int sum (T* inout, int len) const
00093         {
00094           return 0;
00095         }
00096 
00100         template<typename T>
00101         T prod (T& in) const // MPI does not know about const :-(
00102         {
00103           return in;
00104         }
00105 
00110         template<typename T>
00111         int prod (T* inout, int len) const
00112         {
00113           return 0;
00114         }
00115 
00119         template<typename T>
00120         T min (T& in) const // MPI does not know about const :-(
00121         {
00122           return in;
00123         }
00124 
00129         template<typename T>
00130         int min (T* inout, int len) const
00131         {
00132           return 0;
00133         }
00134 
00138         template<typename T>
00139         T max (T& in) const // MPI does not know about const :-(
00140         {
00141           return in;
00142         }
00143 
00148         template<typename T>
00149         int max (T* inout, int len) const
00150         {
00151           return 0;
00152         }
00153 
00156         int barrier () const
00157         {
00158           return 0;
00159         }
00160 
00163         template<typename T>
00164         int broadcast (T* inout, int len, int root) const
00165         {
00166           return 0;
00167         }
00168 
00173         template<typename T>
00174         int gather (T* in, T* out, int len, int root) const // note out must have same size as in
00175         {
00176           for (int i=0; i<len; i++)
00177                 out[i] = in[i];
00178           return 0;
00179         }
00180 
00192     template<typename BinaryFunction, typename Type>
00193     int allreduce(Type* inout, int len) const
00194     {
00195       return 0;
00196     }
00197     
00210     template<typename BinaryFunction, typename Type>
00211     void allreduce(Type* in, Type* out, int len) const
00212     {
00213       std::copy(in, in+len, out);
00214       return;
00215     }
00216     
00217   };
00218 }
00219 
00220 #endif