Tpetra Matrix/Vector Services Version of the Day
Tpetra_DirectoryImpl_decl.hpp
00001 // @HEADER
00002 // ***********************************************************************
00003 //
00004 //          Tpetra: Templated Linear Algebra Services Package
00005 //                 Copyright (2008) Sandia Corporation
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 
00042 #ifndef __Tpetra_DirectoryImpl_decl_hpp
00043 #define __Tpetra_DirectoryImpl_decl_hpp
00044 
00045 #include <Tpetra_ConfigDefs.hpp>
00046 #include "Tpetra_TieBreak.hpp"
00047 
00048 //
00049 // mfh 13-15 May 2013: HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX governs
00050 // the fix for Bug 5822.  The fix is enabled by default.  To disable
00051 // the fix, uncomment out the three lines below that undefine
00052 // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX, and comment out the three
00053 // lines below them that define that macro.
00054 //
00055 // mfh 23 Mar 2014: I want Bug 5822 to stay fixed, so I am removing
00056 // all references to HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX.  I hope no
00057 // downstream code is using that macro, but just in case, I will leave
00058 // it defined.
00059 
00060 #ifndef HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
00061 #  define HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX 1
00062 #endif // HAVE_TPETRA_DIRECTORY_SPARSE_MAP_FIX
00063 
00064 #include <Tpetra_Details_FixedHashTable_decl.hpp>
00065 
00066 
00067 namespace Tpetra {
00068   // Forward declaration.
00069   template <class LocalOrdinal, class GlobalOrdinal, class Node> class Map;
00070 
00071   namespace Details {
00072     // Forward declaration.
00073     template <class LocalOrdinal, class GlobalOrdinal> class TieBreak;
00074 
00082     template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
00083     class Directory : public Teuchos::Describable {
00084     public:
00085       typedef LocalOrdinal local_ordinal_type;
00086       typedef GlobalOrdinal global_ordinal_type;
00087       typedef NodeType node_type;
00088       typedef Tpetra::Map<LocalOrdinal, GlobalOrdinal, NodeType> map_type;
00089 
00097       Directory ();
00098 
00131       LookupStatus
00132       getEntries (const map_type& map,
00133                   const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
00134                   const Teuchos::ArrayView<int> &nodeIDs,
00135                   const Teuchos::ArrayView<LocalOrdinal> &localIDs,
00136                   const bool computeLIDs) const;
00137 
00144       virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const = 0;
00145 
00146     protected:
00148       virtual LookupStatus
00149       getEntriesImpl (const map_type& map,
00150                       const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
00151                       const Teuchos::ArrayView<int> &nodeIDs,
00152                       const Teuchos::ArrayView<LocalOrdinal> &localIDs,
00153                       const bool computeLIDs) const = 0;
00154     };
00155 
00158     template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
00159     class ReplicatedDirectory :
00160       public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
00161     public:
00162       typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type;
00163       typedef typename base_type::map_type map_type;
00164 
00166       ReplicatedDirectory (const map_type& map);
00167 
00169       ReplicatedDirectory ();
00170 
00171       virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
00172 
00173       template <class Node2>
00174       RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
00175       clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
00176       {
00177         typedef ReplicatedDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2;
00178         return rcp (new Dir2 (cloneMap));
00179       }
00180 
00182 
00183 
00185       std::string description () const;
00187     protected:
00189       LookupStatus
00190       getEntriesImpl (const map_type& map,
00191                       const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
00192                       const Teuchos::ArrayView<int> &nodeIDs,
00193                       const Teuchos::ArrayView<LocalOrdinal> &localIDs,
00194                       const bool computeLIDs) const;
00195 
00196     private:
00198       const int numProcs_;
00199     };
00200 
00201 
00210     template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
00211     class ContiguousUniformDirectory :
00212       public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
00213     private:
00214       // This friend declaration lets us implement clone().
00215       template <class LO, class GO, class N> friend class ContiguousUniformDirectory;
00216 
00218       ContiguousUniformDirectory () {}
00219 
00220     public:
00221       typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type;
00222       typedef typename base_type::map_type map_type;
00223 
00225       ContiguousUniformDirectory (const map_type& map);
00226 
00227       virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
00228         return true;
00229       }
00230 
00231       template <class Node2>
00232       RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
00233       clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
00234       {
00235         typedef ContiguousUniformDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2;
00236         return rcp (new Dir2 (cloneMap));
00237       }
00238 
00240 
00241 
00243       std::string description () const;
00245 
00246     protected:
00248       LookupStatus
00249       getEntriesImpl (const map_type& map,
00250                       const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
00251                       const Teuchos::ArrayView<int> &nodeIDs,
00252                       const Teuchos::ArrayView<LocalOrdinal> &localIDs,
00253                       const bool computeLIDs) const;
00254     };
00255 
00256 
00259     template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
00260     class DistributedContiguousDirectory :
00261       public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
00262     private:
00263       template <class LO, class GO, class N> friend class DistributedContiguousDirectory;
00264 
00266       DistributedContiguousDirectory () {}
00267 
00268     public:
00269       typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type;
00270       typedef typename base_type::map_type map_type;
00271 
00273       DistributedContiguousDirectory (const map_type& map);
00274 
00275       virtual bool isOneToOne (const Teuchos::Comm<int>&) const {
00276         return true;
00277       }
00278 
00279       template <class Node2>
00280       RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
00281       clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
00282       {
00283         typedef DistributedContiguousDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2;
00284         RCP<Dir2> dir = rcp (new Dir2 (cloneMap));
00285         dir->allMinGIDs_ = allMinGIDs_;
00286         return dir;
00287       }
00288 
00290 
00291 
00293       std::string description () const;
00295 
00296     protected:
00298       LookupStatus
00299       getEntriesImpl (const map_type& map,
00300                       const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
00301                       const Teuchos::ArrayView<int> &nodeIDs,
00302                       const Teuchos::ArrayView<LocalOrdinal> &localIDs,
00303                       const bool computeLIDs) const;
00304 
00305     private:
00329       Teuchos::ArrayRCP<GlobalOrdinal> allMinGIDs_;
00330     };
00331 
00334     template<class LocalOrdinal, class GlobalOrdinal, class NodeType>
00335     class DistributedNoncontiguousDirectory :
00336       public Directory<LocalOrdinal, GlobalOrdinal, NodeType> {
00337     private:
00338       template <class LO, class GO, class N> friend class DistributedNoncontiguousDirectory;
00340       DistributedNoncontiguousDirectory () {}
00341 
00342     public:
00343       typedef Tpetra::Details::TieBreak<LocalOrdinal, GlobalOrdinal> tie_break_type;
00344       typedef Directory<LocalOrdinal, GlobalOrdinal, NodeType> base_type;
00345       typedef typename base_type::map_type map_type;
00346 
00348       DistributedNoncontiguousDirectory (const map_type& map);
00349 
00351       DistributedNoncontiguousDirectory (const map_type& map,
00352                                          const tie_break_type& tie_break);
00353 
00354       virtual bool isOneToOne (const Teuchos::Comm<int>& comm) const;
00355 
00356       template <class Node2>
00357       RCP<Directory<LocalOrdinal,GlobalOrdinal,Node2> >
00358       clone (const Map<LocalOrdinal,GlobalOrdinal,Node2>& cloneMap) const
00359       {
00360         typedef DistributedNoncontiguousDirectory<LocalOrdinal,GlobalOrdinal,Node2> Dir2;
00361         RCP<Dir2> dir (new Dir2 (cloneMap));
00362 
00363         dir->directoryMap_ =
00364           directoryMap_->template clone<Node2> (cloneMap.getNode ());
00365         dir->PIDs_ = PIDs_;
00366         dir->LIDs_ = LIDs_;
00367         dir->lidToPidTable_ = lidToPidTable_;
00368         dir->lidToLidTable_ = lidToLidTable_;
00369         dir->useHashTables_ = useHashTables_;
00370 
00371         return dir;
00372       }
00373 
00375 
00376 
00378       std::string description () const;
00380     protected:
00382       LookupStatus
00383       getEntriesImpl (const map_type& map,
00384                       const Teuchos::ArrayView<const GlobalOrdinal> &globalIDs,
00385                       const Teuchos::ArrayView<int> &nodeIDs,
00386                       const Teuchos::ArrayView<LocalOrdinal> &localIDs,
00387                       const bool computeLIDs) const;
00388     private:
00395       void
00396       initialize (const map_type& map,
00397                   Teuchos::Ptr<const tie_break_type> tie_break);
00398 
00411       bool isLocallyOneToOne () const {
00412         return locallyOneToOne_;
00413       }
00414 
00432       Teuchos::RCP<const map_type> directoryMap_;
00433 
00435 
00436 
00442       Teuchos::ArrayRCP<int> PIDs_;
00443 
00449       Teuchos::ArrayRCP<LocalOrdinal> LIDs_;
00450 
00452 
00453 
00454 
00460       Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, int> > lidToPidTable_;
00461 
00467       Teuchos::RCP<Details::FixedHashTable<LocalOrdinal, LocalOrdinal> > lidToLidTable_;
00469 
00476       mutable enum EOneToOneResult {
00477         ONE_TO_ONE_NOT_CALLED_YET,
00478         ONE_TO_ONE_FALSE,
00479         ONE_TO_ONE_TRUE
00480       } oneToOneResult_;
00481 
00485       bool locallyOneToOne_;
00486 
00494       bool useHashTables_;
00495     };
00496   } // namespace Details
00497 } // namespace Tpetra
00498 
00499 #endif // __Tpetra_DirectoryImpl_decl_hpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines