|
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 #ifdef HAVE_TPETRA_UNORDERED_MAP 00049 # include <unordered_map> 00050 #endif // HAVE_TPETRA_UNORDERED_MAP 00051 00052 // enums and defines 00053 #include "Tpetra_ConfigDefs.hpp" 00054 00058 namespace Tpetra { 00059 00060 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00061 // Forward declaration of Directory. 00062 template <class LO, class GO, class N> class Directory; 00063 #endif 00064 00137 template <class LocalOrdinal, 00138 class GlobalOrdinal = LocalOrdinal, 00139 class Node = Kokkos::DefaultNode::DefaultNodeType> 00140 class Map : public Teuchos::Describable { 00141 public: 00143 00144 00172 Map (global_size_t numGlobalElements, 00173 GlobalOrdinal indexBase, 00174 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00175 LocalGlobal lg=GloballyDistributed, 00176 const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode()); 00177 00214 Map (global_size_t numGlobalElements, 00215 size_t numLocalElements, 00216 GlobalOrdinal indexBase, 00217 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00218 const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode()); 00219 00256 Map (global_size_t numGlobalElements, 00257 const Teuchos::ArrayView<const GlobalOrdinal> &elementList, 00258 GlobalOrdinal indexBase, 00259 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00260 const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode()); 00261 00263 ~Map(); 00264 00266 00267 00268 00270 inline global_size_t getGlobalNumElements() const { return numGlobalElements_; } 00271 00273 inline size_t getNodeNumElements() const { return numLocalElements_; } 00274 00276 inline GlobalOrdinal getIndexBase() const { return indexBase_; } 00277 00279 inline LocalOrdinal getMinLocalIndex() const { 00280 return Teuchos::OrdinalTraits<LocalOrdinal>::zero(); 00281 } 00282 00287 inline LocalOrdinal getMaxLocalIndex() const { 00288 using Teuchos::as; 00289 typedef LocalOrdinal LO; 00290 00291 if (getNodeNumElements () == 0) { 00292 return Teuchos::OrdinalTraits<LO>::invalid (); 00293 } 00294 else { 00295 // NOTE (mfh 08 May 2012) Local indices always have zero as 00296 // their index base. 00297 return as<LO> (getNodeNumElements ()) - as<LO> (1); 00298 } 00299 } 00300 00302 inline GlobalOrdinal getMinGlobalIndex() const { return minMyGID_; } 00303 00305 inline GlobalOrdinal getMaxGlobalIndex() const { return maxMyGID_; } 00306 00308 inline GlobalOrdinal getMinAllGlobalIndex() const { return minAllGID_; } 00309 00311 inline GlobalOrdinal getMaxAllGlobalIndex() const { return maxAllGID_; } 00312 00317 LocalOrdinal getLocalElement (GlobalOrdinal globalIndex) const; 00318 00323 GlobalOrdinal getGlobalElement (LocalOrdinal localIndex) const; 00324 00353 LookupStatus 00354 getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal>& GIDList, 00355 const Teuchos::ArrayView< int>& nodeIDList, 00356 const Teuchos::ArrayView< LocalOrdinal>& LIDList) const; 00357 00381 LookupStatus 00382 getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal> & GIDList, 00383 const Teuchos::ArrayView< int> & nodeIDList) const; 00384 00386 Teuchos::ArrayView<const GlobalOrdinal> getNodeElementList() const; 00387 00389 00390 00391 00393 bool isNodeLocalElement (LocalOrdinal localIndex) const; 00394 00396 bool isNodeGlobalElement (GlobalOrdinal globalIndex) const; 00397 00409 bool isContiguous () const; 00410 00430 bool isDistributed () const; 00431 00471 bool isCompatible (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const; 00472 00499 bool isSameAs (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const; 00500 00502 00503 00504 00506 const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const; 00507 00509 const Teuchos::RCP<Node> & getNode() const; 00510 00512 00513 00514 00516 std::string description() const; 00517 00519 void 00520 describe (Teuchos::FancyOStream &out, 00521 const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const; 00522 00524 00525 private: 00526 00528 void setupDirectory(); 00529 00544 bool checkIsDist() const; 00545 00547 Map(const Map<LocalOrdinal,GlobalOrdinal,Node> & source); 00548 00550 Map<LocalOrdinal,GlobalOrdinal,Node>& 00551 operator= (const Map<LocalOrdinal,GlobalOrdinal,Node> & source); 00552 00554 Teuchos::RCP<const Teuchos::Comm<int> > comm_; 00555 00562 Teuchos::RCP<Node> node_; 00563 00565 GlobalOrdinal indexBase_; 00567 global_size_t numGlobalElements_; 00569 size_t numLocalElements_; 00571 GlobalOrdinal minMyGID_, maxMyGID_; 00573 GlobalOrdinal minAllGID_, maxAllGID_; 00575 bool contiguous_; 00577 bool distributed_; 00578 00594 mutable Teuchos::ArrayRCP<GlobalOrdinal> lgMap_; 00595 00604 #ifdef HAVE_TPETRA_UNORDERED_MAP 00605 typedef std::unordered_map<GlobalOrdinal, LocalOrdinal> global_to_local_table_type; 00606 #else 00607 typedef std::map<GlobalOrdinal, LocalOrdinal> global_to_local_table_type; 00608 #endif // HAVE_TPETRA_UNORDERED_MAP 00609 00622 global_to_local_table_type glMap_; 00623 00632 Teuchos::RCP<Directory<LocalOrdinal,GlobalOrdinal,Node> > directory_; 00633 00634 }; // Map class 00635 00644 template <class LocalOrdinal, class GlobalOrdinal> 00645 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00646 createLocalMap(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm); 00647 00654 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00655 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00656 createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node); 00657 00666 template <class LocalOrdinal, class GlobalOrdinal> 00667 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00668 createUniformContigMap(global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm); 00669 00676 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00677 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00678 createUniformContigMapWithNode(global_size_t numElements, 00679 const Teuchos::RCP< const Teuchos::Comm< int > > &comm, 00680 const Teuchos::RCP< Node > &node); 00681 00690 template <class LocalOrdinal, class GlobalOrdinal> 00691 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00692 createContigMap (global_size_t numElements, 00693 size_t localNumElements, 00694 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); 00695 00702 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00703 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > 00704 createContigMapWithNode (global_size_t numElements, 00705 size_t localNumElements, 00706 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00707 const Teuchos::RCP<Node> &node); 00708 00717 template <class LocalOrdinal, class GlobalOrdinal> 00718 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00719 createNonContigMap (const ArrayView<const GlobalOrdinal> &elementList, 00720 const RCP<const Teuchos::Comm<int> > &comm); 00721 00728 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00729 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00730 createNonContigMapWithNode (const ArrayView<const GlobalOrdinal> &elementList, 00731 const RCP<const Teuchos::Comm<int> > &comm, 00732 const RCP<Node> &node); 00733 00740 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00741 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00742 createWeightedContigMapWithNode (int thisNodeWeight, 00743 global_size_t numElements, 00744 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00745 const Teuchos::RCP<Node> &node); 00746 00747 } // Tpetra namespace 00748 00751 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00752 bool operator== (const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map1, 00753 const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map2) 00754 { return map1.isSameAs(map2); } 00755 00758 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00759 bool operator!= (const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map1, 00760 const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map2) 00761 { return !map1.isSameAs(map2); } 00762 00763 #endif // TPETRA_MAP_DECL_HPP 00764
1.7.4