|
Tpetra Matrix/Vector Services
Version of the Day
|
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_MAP_DECL_HPP 00043 #define TPETRA_MAP_DECL_HPP 00044 00045 #include <Kokkos_DefaultNode.hpp> 00046 #include <Teuchos_Describable.hpp> 00047 00048 // enums and defines 00049 #include "Tpetra_ConfigDefs.hpp" 00050 00051 // mfh 27 Apr 2013: If HAVE_TPETRA_FIXED_HASH_TABLE is defined (which 00052 // it is by default), then Map will used the fixed-structure hash 00053 // table variant for global-to-local index lookups. Otherwise, it 00054 // will use the dynamic-structure hash table variant. 00055 // 00056 // mfh 23 Mar 2014: I've removed all code in Map that uses the 00057 // dynamic-structure hash table variant, since it has not been used 00058 // for at least a year. However, I am retaining the #define, in case 00059 // downstream code depends on it. 00060 00061 #ifndef HAVE_TPETRA_FIXED_HASH_TABLE 00062 # define HAVE_TPETRA_FIXED_HASH_TABLE 1 00063 #endif // HAVE_TPETRA_FIXED_HASH_TABLE 00064 00068 namespace Tpetra { 00069 00070 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00071 // Forward declaration of Directory. 00072 template <class LO, class GO, class N> class Directory; 00073 #endif // DOXYGEN_SHOULD_SKIP_THIS 00074 00075 namespace Details { 00076 00077 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00078 // Forward declaration of TieBreak 00079 template <class LO, class GO> class TieBreak; 00080 00081 template<class GlobalOrdinal, class LocalOrdinal> 00082 class FixedHashTable; 00083 #endif // DOXYGEN_SHOULD_SKIP_THIS 00084 00087 template<class OutMapType, class InMapType> 00088 struct MapCloner { 00089 typedef typename OutMapType::node_type out_node_type; 00090 typedef typename InMapType::node_type in_node_type; 00091 00092 static OutMapType 00093 clone (const InMapType& mapIn, 00094 const Teuchos::RCP<out_node_type>& node2); 00095 }; 00096 } // namespace Details 00097 00098 template<class Node> 00099 Teuchos::RCP<Node> defaultArgNode() { 00100 // Workaround function for a deferred visual studio bug 00101 // http://connect.microsoft.com/VisualStudio/feedback/details/719847/erroneous-error-c2783-could-not-deduce-template-argument 00102 // Use this function for default arguments rather than calling 00103 // what is the return value below. Also helps in reducing 00104 // duplication in various constructors. 00105 return KokkosClassic::Details::getNode<Node>(); 00106 } 00107 00257 template <class LocalOrdinal = int, 00258 class GlobalOrdinal = LocalOrdinal, 00259 class Node = KokkosClassic::DefaultNode::DefaultNodeType> 00260 class Map : public Teuchos::Describable { 00261 public: 00263 00264 00266 typedef LocalOrdinal local_ordinal_type; 00268 typedef GlobalOrdinal global_ordinal_type; 00270 typedef Node node_type; 00271 00273 00274 00275 00317 Map (global_size_t numGlobalElements, 00318 GlobalOrdinal indexBase, 00319 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00320 LocalGlobal lg=GloballyDistributed, 00321 const Teuchos::RCP<Node> &node = defaultArgNode<Node>()); 00322 00362 Map (global_size_t numGlobalElements, 00363 size_t numLocalElements, 00364 GlobalOrdinal indexBase, 00365 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00366 const Teuchos::RCP<Node> &node = defaultArgNode<Node>()); 00367 00402 Map (global_size_t numGlobalElements, 00403 const Teuchos::ArrayView<const GlobalOrdinal> &elementList, 00404 GlobalOrdinal indexBase, 00405 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00406 const Teuchos::RCP<Node> &node = defaultArgNode<Node>()); 00407 00408 00419 Map (); 00420 00422 ~Map (); 00423 00425 00426 00427 00432 bool isOneToOne () const; 00433 00435 inline global_size_t getGlobalNumElements() const { return numGlobalElements_; } 00436 00438 inline size_t getNodeNumElements() const { return numLocalElements_; } 00439 00441 inline GlobalOrdinal getIndexBase() const { return indexBase_; } 00442 00444 inline LocalOrdinal getMinLocalIndex() const { 00445 return Teuchos::OrdinalTraits<LocalOrdinal>::zero(); 00446 } 00447 00453 inline LocalOrdinal getMaxLocalIndex() const { 00454 if (getNodeNumElements () == 0) { 00455 return Teuchos::OrdinalTraits<LocalOrdinal>::invalid (); 00456 } 00457 else { // Local indices are always zero-based. 00458 return Teuchos::as<LocalOrdinal> (getNodeNumElements () - 1); 00459 } 00460 } 00461 00463 inline GlobalOrdinal getMinGlobalIndex() const { return minMyGID_; } 00464 00466 inline GlobalOrdinal getMaxGlobalIndex() const { return maxMyGID_; } 00467 00469 inline GlobalOrdinal getMinAllGlobalIndex() const { return minAllGID_; } 00470 00472 inline GlobalOrdinal getMaxAllGlobalIndex() const { return maxAllGID_; } 00473 00478 LocalOrdinal getLocalElement (GlobalOrdinal globalIndex) const; 00479 00484 GlobalOrdinal getGlobalElement (LocalOrdinal localIndex) const; 00485 00515 LookupStatus 00516 getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal>& GIDList, 00517 const Teuchos::ArrayView< int>& nodeIDList, 00518 const Teuchos::ArrayView< LocalOrdinal>& LIDList) const; 00519 00543 LookupStatus 00544 getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal> & GIDList, 00545 const Teuchos::ArrayView< int> & nodeIDList) const; 00546 00553 Teuchos::ArrayView<const GlobalOrdinal> getNodeElementList() const; 00554 00556 00557 00558 00560 bool isNodeLocalElement (LocalOrdinal localIndex) const; 00561 00563 bool isNodeGlobalElement (GlobalOrdinal globalIndex) const; 00564 00571 bool isUniform () const; 00572 00584 bool isContiguous () const; 00585 00605 bool isDistributed () const; 00606 00631 bool isCompatible (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const; 00632 00663 bool isSameAs (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const; 00664 00669 bool locallySameAs (const Map<LocalOrdinal, GlobalOrdinal, node_type>& map) const; 00670 00672 00673 00674 00676 Teuchos::RCP<const Teuchos::Comm<int> > getComm () const; 00677 00679 Teuchos::RCP<Node> getNode () const; 00680 00682 00683 00684 00686 std::string description() const; 00687 00689 void 00690 describe (Teuchos::FancyOStream &out, 00691 const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const; 00692 00694 00695 00696 00698 template <class NodeOut> 00699 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, NodeOut> > 00700 clone (const RCP<NodeOut>& nodeOut) const; 00701 00749 RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > 00750 removeEmptyProcesses () const; 00751 00779 RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> > 00780 replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const; 00782 00783 protected: 00784 // This lets other specializations of Map access all of this 00785 // specialization's internal methods and data, so that we can 00786 // implement clone() without exposing the details of Map to users. 00787 template <class LO, class GO, class N> friend class Map; 00788 00789 private: 00790 template<class OutMapType, class InMapType> 00791 friend struct Details::MapCloner; 00792 00800 void setupDirectory () const; 00801 00816 bool checkIsDist() const; 00817 00819 Teuchos::RCP<const Teuchos::Comm<int> > comm_; 00820 00822 Teuchos::RCP<Node> node_; 00823 00825 GlobalOrdinal indexBase_; 00826 00828 global_size_t numGlobalElements_; 00829 00831 size_t numLocalElements_; 00832 00834 GlobalOrdinal minMyGID_; 00835 00837 GlobalOrdinal maxMyGID_; 00838 00840 GlobalOrdinal minAllGID_; 00841 00843 GlobalOrdinal maxAllGID_; 00844 00851 GlobalOrdinal firstContiguousGID_; 00852 00866 GlobalOrdinal lastContiguousGID_; 00867 00873 bool uniform_; 00874 00876 bool contiguous_; 00877 00884 bool distributed_; 00885 00902 mutable Teuchos::ArrayRCP<GlobalOrdinal> lgMap_; 00903 00905 typedef Details::FixedHashTable<GlobalOrdinal, LocalOrdinal> global_to_local_table_type; 00906 00919 RCP<global_to_local_table_type> glMap_; 00920 00957 mutable Teuchos::RCP<Directory<LocalOrdinal,GlobalOrdinal,Node> > directory_; 00958 00959 }; // Map class 00960 00974 template <class LocalOrdinal, class GlobalOrdinal> 00975 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> > 00976 createLocalMap (size_t numElements, const Teuchos::RCP<const Teuchos::Comm<int> >& comm); 00977 00994 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00995 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > 00996 createLocalMapWithNode (size_t numElements, 00997 const Teuchos::RCP<const Teuchos::Comm<int> >& comm, 00998 const Teuchos::RCP<Node>& node = defaultArgNode<Node> ()); 00999 01007 template <class LocalOrdinal, class GlobalOrdinal> 01008 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal> > 01009 createUniformContigMap (global_size_t numElements, 01010 const Teuchos::RCP<const Teuchos::Comm<int> >& comm); 01011 01018 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01019 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > 01020 createUniformContigMapWithNode (global_size_t numElements, 01021 const Teuchos::RCP<const Teuchos::Comm<int> >& comm, 01022 const Teuchos::RCP<Node>& node = 01023 defaultArgNode<Node> ()); 01024 01033 template <class LocalOrdinal, class GlobalOrdinal> 01034 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> > 01035 createContigMap (global_size_t numElements, 01036 size_t localNumElements, 01037 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); 01038 01045 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01046 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > 01047 createContigMapWithNode (global_size_t numElements, 01048 size_t localNumElements, 01049 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 01050 const Teuchos::RCP<Node> &node); 01051 01060 template <class LocalOrdinal, class GlobalOrdinal> 01061 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> > 01062 createNonContigMap (const ArrayView<const GlobalOrdinal> &elementList, 01063 const RCP<const Teuchos::Comm<int> > &comm); 01064 01071 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01072 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 01073 createNonContigMapWithNode (const ArrayView<const GlobalOrdinal> &elementList, 01074 const RCP<const Teuchos::Comm<int> > &comm, 01075 const RCP<Node> &node); 01076 01083 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01084 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 01085 createWeightedContigMapWithNode (int thisNodeWeight, 01086 global_size_t numElements, 01087 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 01088 const Teuchos::RCP<Node> &node); 01089 01096 template<class LocalOrdinal, class GlobalOrdinal, class Node> 01097 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 01098 createOneToOne (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &M); 01099 01107 template<class LocalOrdinal, class GlobalOrdinal, class Node> 01108 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 01109 createOneToOne(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &M, 01110 const Tpetra::Details::TieBreak<LocalOrdinal,GlobalOrdinal> & tie_break); 01111 01112 } // Tpetra namespace 01113 01114 #include "Tpetra_Directory_decl.hpp" 01115 01116 namespace Tpetra { 01117 namespace Details { 01118 01119 template<class OutMapType, class InMapType> 01120 OutMapType 01121 MapCloner<OutMapType, InMapType>:: 01122 clone (const InMapType& mapIn, 01123 const Teuchos::RCP<out_node_type>& nodeOut) 01124 { 01125 typedef ::Tpetra::Directory<typename OutMapType::local_ordinal_type, 01126 typename OutMapType::global_ordinal_type, 01127 typename OutMapType::node_type> out_dir_type; 01128 01129 OutMapType mapOut; // Make an empty Map. 01130 01131 // Fill the new Map with shallow copies of all of the original 01132 // Map's data. This is safe because Map is immutable, so 01133 // users can't change the original Map. 01134 mapOut.comm_ = mapIn.comm_; 01135 mapOut.indexBase_ = mapIn.indexBase_; 01136 mapOut.numGlobalElements_ = mapIn.numGlobalElements_; 01137 mapOut.numLocalElements_ = mapIn.numLocalElements_; 01138 mapOut.minMyGID_ = mapIn.minMyGID_; 01139 mapOut.maxMyGID_ = mapIn.maxMyGID_; 01140 mapOut.minAllGID_ = mapIn.minAllGID_; 01141 mapOut.maxAllGID_ = mapIn.maxAllGID_; 01142 mapOut.firstContiguousGID_= mapIn.firstContiguousGID_; 01143 mapOut.lastContiguousGID_ = mapIn.lastContiguousGID_; 01144 mapOut.uniform_ = mapIn.uniform_; 01145 mapOut.contiguous_ = mapIn.contiguous_; 01146 mapOut.distributed_ = mapIn.distributed_; 01147 mapOut.lgMap_ = mapIn.lgMap_; 01148 mapOut.glMap_ = mapIn.glMap_; 01149 // New Map gets the new Node instance. 01150 mapOut.node_ = nodeOut; 01151 01152 // We could cleverly clone the Directory here if it is 01153 // initialized, but there is no harm in simply creating it 01154 // uninitialized. 01155 mapOut.directory_ = Teuchos::rcp (new out_dir_type ()); 01156 01157 return mapOut; 01158 } 01159 } // namespace Details 01160 01161 01162 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01163 template <class NodeOut> 01164 RCP<const Map<LocalOrdinal, GlobalOrdinal, NodeOut> > 01165 Map<LocalOrdinal,GlobalOrdinal,Node>:: 01166 clone (const Teuchos::RCP<NodeOut>& nodeOut) const 01167 { 01168 typedef Map<LocalOrdinal, GlobalOrdinal, Node> in_map_type; 01169 typedef Map<LocalOrdinal, GlobalOrdinal, NodeOut> out_map_type; 01170 typedef Details::MapCloner<out_map_type, in_map_type> cloner_type; 01171 // Copy constructor does a shallow copy. 01172 return Teuchos::rcp (new out_map_type (cloner_type::clone (*this, nodeOut))); 01173 } 01174 01175 } // namespace Tpetra 01176 01179 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01180 bool operator== (const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map1, 01181 const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map2) 01182 { return map1.isSameAs (map2); } 01183 01186 template <class LocalOrdinal, class GlobalOrdinal, class Node> 01187 bool operator!= (const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map1, 01188 const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map2) 01189 { return ! map1.isSameAs (map2); } 01190 01191 01192 #if defined(TPETRA_USE_KOKKOS_REFACTOR_MAP) 01193 // Include KokkosRefactor partial specialization if enabled 01194 # if defined(TPETRA_HAVE_KOKKOS_REFACTOR) 01195 # include "Tpetra_KokkosRefactor_Map_decl.hpp" 01196 # endif // defined(TPETRA_HAVE_KOKKOS_REFACTOR) 01197 #endif // defined(TPETRA_USE_KOKKOS_REFACTOR_MAP) 01198 01199 01200 #endif // TPETRA_MAP_DECL_HPP 01201
1.7.6.1