|
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 00158 template <class LocalOrdinal, 00159 class GlobalOrdinal = LocalOrdinal, 00160 class Node = Kokkos::DefaultNode::DefaultNodeType> 00161 class Map : public Teuchos::Describable { 00162 public: 00164 00165 00193 Map (global_size_t numGlobalElements, 00194 GlobalOrdinal indexBase, 00195 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00196 LocalGlobal lg=GloballyDistributed, 00197 const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode()); 00198 00235 Map (global_size_t numGlobalElements, 00236 size_t numLocalElements, 00237 GlobalOrdinal indexBase, 00238 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00239 const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode()); 00240 00277 Map (global_size_t numGlobalElements, 00278 const Teuchos::ArrayView<const GlobalOrdinal> &elementList, 00279 GlobalOrdinal indexBase, 00280 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00281 const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode()); 00282 00284 ~Map(); 00285 00287 00288 00289 00291 inline global_size_t getGlobalNumElements() const { return numGlobalElements_; } 00292 00294 inline size_t getNodeNumElements() const { return numLocalElements_; } 00295 00297 inline GlobalOrdinal getIndexBase() const { return indexBase_; } 00298 00300 inline LocalOrdinal getMinLocalIndex() const { 00301 return Teuchos::OrdinalTraits<LocalOrdinal>::zero(); 00302 } 00303 00308 inline LocalOrdinal getMaxLocalIndex() const { 00309 using Teuchos::as; 00310 typedef LocalOrdinal LO; 00311 00312 if (getNodeNumElements () == 0) { 00313 return Teuchos::OrdinalTraits<LO>::invalid (); 00314 } 00315 else { 00316 // NOTE (mfh 08 May 2012) Local indices always have zero as 00317 // their index base. 00318 return as<LO> (getNodeNumElements ()) - as<LO> (1); 00319 } 00320 } 00321 00323 inline GlobalOrdinal getMinGlobalIndex() const { return minMyGID_; } 00324 00326 inline GlobalOrdinal getMaxGlobalIndex() const { return maxMyGID_; } 00327 00329 inline GlobalOrdinal getMinAllGlobalIndex() const { return minAllGID_; } 00330 00332 inline GlobalOrdinal getMaxAllGlobalIndex() const { return maxAllGID_; } 00333 00338 LocalOrdinal getLocalElement (GlobalOrdinal globalIndex) const; 00339 00344 GlobalOrdinal getGlobalElement (LocalOrdinal localIndex) const; 00345 00374 LookupStatus 00375 getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal>& GIDList, 00376 const Teuchos::ArrayView< int>& nodeIDList, 00377 const Teuchos::ArrayView< LocalOrdinal>& LIDList) const; 00378 00402 LookupStatus 00403 getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal> & GIDList, 00404 const Teuchos::ArrayView< int> & nodeIDList) const; 00405 00407 Teuchos::ArrayView<const GlobalOrdinal> getNodeElementList() const; 00408 00410 00411 00412 00414 bool isNodeLocalElement (LocalOrdinal localIndex) const; 00415 00417 bool isNodeGlobalElement (GlobalOrdinal globalIndex) const; 00418 00430 bool isContiguous () const; 00431 00451 bool isDistributed () const; 00452 00492 bool isCompatible (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const; 00493 00520 bool isSameAs (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const; 00521 00523 00524 00525 00527 const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const; 00528 00530 const Teuchos::RCP<Node> & getNode() const; 00531 00533 00534 00535 00537 std::string description() const; 00538 00540 void 00541 describe (Teuchos::FancyOStream &out, 00542 const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const; 00543 00545 00546 private: 00547 00549 void setupDirectory(); 00550 00565 bool checkIsDist() const; 00566 00568 Map(const Map<LocalOrdinal,GlobalOrdinal,Node> & source); 00569 00571 Map<LocalOrdinal,GlobalOrdinal,Node>& 00572 operator= (const Map<LocalOrdinal,GlobalOrdinal,Node> & source); 00573 00575 Teuchos::RCP<const Teuchos::Comm<int> > comm_; 00576 00583 Teuchos::RCP<Node> node_; 00584 00586 GlobalOrdinal indexBase_; 00588 global_size_t numGlobalElements_; 00590 size_t numLocalElements_; 00592 GlobalOrdinal minMyGID_, maxMyGID_; 00594 GlobalOrdinal minAllGID_, maxAllGID_; 00596 bool contiguous_; 00598 bool distributed_; 00599 00615 mutable Teuchos::ArrayRCP<GlobalOrdinal> lgMap_; 00616 00625 #ifdef HAVE_TPETRA_UNORDERED_MAP 00626 typedef std::unordered_map<GlobalOrdinal, LocalOrdinal> global_to_local_table_type; 00627 #else 00628 typedef std::map<GlobalOrdinal, LocalOrdinal> global_to_local_table_type; 00629 #endif // HAVE_TPETRA_UNORDERED_MAP 00630 00643 global_to_local_table_type glMap_; 00644 00653 Teuchos::RCP<Directory<LocalOrdinal,GlobalOrdinal,Node> > directory_; 00654 00655 }; // Map class 00656 00665 template <class LocalOrdinal, class GlobalOrdinal> 00666 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00667 createLocalMap(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm); 00668 00675 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00676 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00677 createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node); 00678 00687 template <class LocalOrdinal, class GlobalOrdinal> 00688 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00689 createUniformContigMap(global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm); 00690 00697 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00698 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00699 createUniformContigMapWithNode(global_size_t numElements, 00700 const Teuchos::RCP< const Teuchos::Comm< int > > &comm, 00701 const Teuchos::RCP< Node > &node); 00702 00711 template <class LocalOrdinal, class GlobalOrdinal> 00712 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00713 createContigMap (global_size_t numElements, 00714 size_t localNumElements, 00715 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); 00716 00723 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00724 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > 00725 createContigMapWithNode (global_size_t numElements, 00726 size_t localNumElements, 00727 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00728 const Teuchos::RCP<Node> &node); 00729 00738 template <class LocalOrdinal, class GlobalOrdinal> 00739 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> > 00740 createNonContigMap (const ArrayView<const GlobalOrdinal> &elementList, 00741 const RCP<const Teuchos::Comm<int> > &comm); 00742 00749 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00750 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00751 createNonContigMapWithNode (const ArrayView<const GlobalOrdinal> &elementList, 00752 const RCP<const Teuchos::Comm<int> > &comm, 00753 const RCP<Node> &node); 00754 00761 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00762 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00763 createWeightedContigMapWithNode (int thisNodeWeight, 00764 global_size_t numElements, 00765 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, 00766 const Teuchos::RCP<Node> &node); 00767 00774 template<class LocalOrdinal, class GlobalOrdinal, class Node> 00775 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> > 00776 createOneToOne(Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &M); 00777 } // Tpetra namespace 00778 00781 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00782 bool operator== (const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map1, 00783 const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map2) 00784 { return map1.isSameAs(map2); } 00785 00788 template <class LocalOrdinal, class GlobalOrdinal, class Node> 00789 bool operator!= (const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map1, 00790 const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> &map2) 00791 { return !map1.isSameAs(map2); } 00792 00793 #endif // TPETRA_MAP_DECL_HPP 00794
1.7.6.1