pinfo.hh

00001 // $Id: pinfo.hh 727 2007-03-16 14:05:10Z mblatt $
00002 #ifndef DUNE_AMG_PINFO_HH
00003 #define DUNE_AMG_PINFO_HH
00004 
00005 #include<dune/common/collectivecommunication.hh>
00006 
00007 #if HAVE_MPI
00008 
00009 #include<dune/common/mpicollectivecommunication.hh>
00010 #include<dune/istl/mpitraits.hh>
00011 #include<dune/istl/remoteindices.hh>
00012 #include<dune/istl/interface.hh>
00013 #include<dune/istl/communicator.hh>
00014 
00015 #endif
00016 
00017 #include<dune/istl/solvercategory.hh>
00018 namespace Dune
00019 {
00020   namespace Amg
00021   {
00022 
00023 #if HAVE_MPI
00024 
00025     template<class T>
00026     class ParallelInformation
00027     {
00028     public:
00029       typedef T ParallelIndexSet;
00030       typedef RemoteIndices<ParallelIndexSet> RemoteIndices;
00031       typedef Interface<ParallelIndexSet> Interface;
00032       typedef BufferedCommunicator<ParallelIndexSet>Communicator;
00033       typedef GlobalLookupIndexSet<ParallelIndexSet> GlobalLookupIndexSet;
00034       typedef CollectiveCommunication<MPI_Comm> MPICommunicator;
00035       
00036       enum{
00037         category = SolverCategory::overlapping
00038           };
00039       
00040       ParallelInformation(const MPI_Comm& comm);
00041       
00042       ~ParallelInformation();
00043       
00044       const MPICommunicator& communicator() const;
00045 
00046       template<bool ignorePublic>
00047       void rebuildRemoteIndices();
00048       
00049       template<typename OverlapFlags>
00050       void buildInterface();
00051       
00052       template<typename Data>
00053       void buildCommunicator(const Data& source, const Data& dest);
00054       
00055       void freeCommunicator();
00056       
00057       template<class GatherScatter, class Data>
00058       void communicateForward(const Data& source, Data& dest);
00059       
00060       template<class GatherScatter, class Data>
00061       void communicateBackward(Data& source, const Data& dest);
00062 
00063       ParallelIndexSet& indexSet();
00064       
00065       const ParallelIndexSet& indexSet() const;
00066 
00067       RemoteIndices& remoteIndices();
00068       
00069       const RemoteIndices& remoteIndices() const;
00070 
00071       Interface& interface();
00072       
00073       const Interface& interface() const;
00074 
00075       void buildGlobalLookup(std::size_t);
00076 
00077       void freeGlobalLookup();
00078 
00079       const GlobalLookupIndexSet& globalLookup() const;
00080       
00081     private:
00082       ParallelIndexSet* indexSet_;
00083       RemoteIndices* remoteIndices_;
00084       Interface* interface_;
00085       Communicator* communicator_;
00086       MPICommunicator mpiCommunicator_;
00087       GlobalLookupIndexSet* globalLookup_;
00088     };
00089 
00090 #endif    
00091 
00092     class SequentialInformation
00093     {
00094     public:
00095       typedef CollectiveCommunication<void*> MPICommunicator;
00096       typedef EmptySet<int> CopyFlags;
00097       
00098       enum{
00099         category = SolverCategory::sequential
00100           };
00101 
00102       MPICommunicator communicator() const
00103       {
00104         return comm_;
00105       }
00106 
00107       int procs() const
00108       {
00109         return 1;
00110       }
00111 
00112       template<typename T>
00113       T globalSum(const T& t) const
00114       {
00115         return t;
00116       }
00117       
00118       typedef int GlobalLookupIndexSet;
00119       
00120       void buildGlobalLookup(std::size_t){};
00121 
00122       void freeGlobalLookup(){};
00123 
00124       const GlobalLookupIndexSet& globalLookup() const
00125       {
00126         return gli;
00127       }
00128 
00129       template<class V>
00130       void copyOwnerToAll(V& v, V& v1) const
00131       {}
00132 
00133       template<class V>
00134       void project(V& v) const
00135       {}
00136       
00137       SequentialInformation(const CollectiveCommunication<void*>&)
00138       {}
00139 
00140       SequentialInformation()
00141       {}
00142 
00143       SequentialInformation(const SequentialInformation&)
00144       {}
00145     private:
00146       MPICommunicator comm_;
00147       GlobalLookupIndexSet gli;
00148     };
00149 
00150 #if HAVE_MPI    
00151     template<class T>
00152     ParallelInformation<T>::ParallelInformation(const MPI_Comm& comm)
00153       : indexSet_(new ParallelIndexSet()), 
00154         remoteIndices_(new RemoteIndices(*indexSet_, *indexSet_, comm)),
00155         interface_(new Interface()), communicator_(new Communicator()),
00156         mpiCommunicator_(comm), globalLookup_(0)
00157     {}
00158     
00159     template<class T>
00160     ParallelInformation<T>::~ParallelInformation()
00161     {
00162       delete communicator_;
00163       delete interface_;
00164       delete remoteIndices_;
00165       delete indexSet_;
00166     }
00167 
00168     template<class T>
00169     inline const typename ParallelInformation<T>::MPICommunicator&
00170     ParallelInformation<T>::communicator() const
00171     {
00172       return mpiCommunicator_;
00173     }
00174         
00175     template<class T>
00176     template<bool ignorePublic>
00177     inline void ParallelInformation<T>::rebuildRemoteIndices()
00178     {
00179       remoteIndices_->template rebuild<ignorePublic>();
00180     }
00181     
00182     template<class T>
00183     template<typename OverlapFlags>
00184     inline void ParallelInformation<T>::buildInterface()
00185     {
00186       interface_->build(*remoteIndices_, NegateSet<OverlapFlags>(), 
00187                         OverlapFlags());
00188     }
00189     
00190     
00191     template<class T>
00192     template<typename Data>
00193     inline void ParallelInformation<T>::buildCommunicator(const Data& source,
00194                                                    const Data& dest)
00195     {
00196       communicator_->build(source, dest, *interface_);
00197     }
00198     
00199     
00200     template<class T>
00201     inline void ParallelInformation<T>::freeCommunicator()
00202     {
00203       communicator_->free();
00204     }
00205     
00206     template<class T>
00207     template<class GatherScatter, class Data>
00208     inline void ParallelInformation<T>::communicateForward(const Data& source, Data& dest)
00209     {
00210       communicator_->template forward<GatherScatter>(source, dest);
00211     }
00212     
00213     template<class T>
00214     template<class GatherScatter, class Data>
00215     inline void ParallelInformation<T>::communicateBackward(Data& source, const Data& dest)
00216     {
00217       communicator_->template backward<GatherScatter>(source, dest);
00218     }
00219     
00220     template<class T>
00221     typename ParallelInformation<T>::ParallelIndexSet& ParallelInformation<T>::indexSet(){
00222       return *indexSet_;
00223     }
00224       
00225     template<class T>
00226     const typename ParallelInformation<T>::ParallelIndexSet& ParallelInformation<T>::indexSet() const{
00227       return *indexSet_;
00228     }
00229 
00230     template<class T>
00231     typename ParallelInformation<T>::RemoteIndices& ParallelInformation<T>::remoteIndices(){
00232       return *remoteIndices_;
00233     }
00234       
00235     template<class T>
00236     const typename ParallelInformation<T>::RemoteIndices& ParallelInformation<T>::remoteIndices() const{
00237       return *remoteIndices_;
00238     }
00239 
00240     template<class T>
00241     typename ParallelInformation<T>::Interface& ParallelInformation<T>::interface(){
00242       return *interface_;
00243     }
00244       
00245     template<class T>
00246     const typename ParallelInformation<T>::Interface& ParallelInformation<T>::interface() const{
00247       return *interface_;
00248     }
00249 
00250     template<class T>
00251     void ParallelInformation<T>::buildGlobalLookup(std::size_t size)
00252     {
00253       globalLookup_ = new GlobalLookupIndexSet(*indexSet_, size);
00254     }
00255     
00256     template<class T>
00257     void ParallelInformation<T>::freeGlobalLookup()
00258     {
00259       delete globalLookup_;
00260       globalLookup_=0;
00261     }    
00262 
00263     template<class T>
00264     const typename ParallelInformation<T>::GlobalLookupIndexSet& 
00265     ParallelInformation<T>::globalLookup() const
00266     {
00267       assert(globalLookup_ != 0);
00268       return *globalLookup_;
00269     }
00270     
00271 #endif
00272 
00273   }// namespace Amg
00274 } //namespace Dune
00275 #endif

Generated on 12 Dec 2007 with Doxygen (ver 1.5.1)