pinfo.hh

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

Generated on Thu Apr 2 10:40:15 2009 for dune-istl by  doxygen 1.5.6