Tpetra Matrix/Vector Services Version of the Day
Tpetra_BlockMap_decl.hpp
Go to the documentation of this file.
00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 //          Tpetra: Templated Linear Algebra Services Package
00005 //                 Copyright (2008) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Michael A. Heroux (maherou@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef TPETRA_BLOCKMAP_DECL_HPP
00030 #define TPETRA_BLOCKMAP_DECL_HPP
00031 
00032 #include <map>
00033 
00034 #include "Tpetra_Map.hpp"
00035 
00040 namespace Tpetra {
00041 
00047 template <class LocalOrdinal, class GlobalOrdinal = LocalOrdinal, class Node = Kokkos::DefaultNode::DefaultNodeType>
00048 class BlockMap : public Teuchos::Describable {
00049  public:
00050   typedef LocalOrdinal  local_ordinal_type;
00051   typedef GlobalOrdinal global_ordinal_type;
00052   typedef Node          node_type;
00053 
00055 
00056 
00059   BlockMap(global_size_t numGlobalBlocks,
00060            LocalOrdinal blockSize,
00061            GlobalOrdinal indexBase,
00062            const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00063            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00064 
00067   BlockMap(global_size_t numGlobalBlocks,
00068            size_t numLocalBlocks,
00069            LocalOrdinal blockSize,
00070            GlobalOrdinal indexBase,
00071            const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00072            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00073 
00076   BlockMap(global_size_t numGlobalBlocks,
00077       const Teuchos::ArrayView<const GlobalOrdinal>& myGlobalBlockIDs,
00078       const Teuchos::ArrayView<const GlobalOrdinal>& myFirstGlobalPointInBlocks,
00079       const Teuchos::ArrayView<const LocalOrdinal>& myBlockSizes,
00080       GlobalOrdinal indexBase,
00081       const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00082       const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00083 
00090   BlockMap(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& pointMap,
00091            const Teuchos::ArrayView<const GlobalOrdinal>& myGlobalBlockIDs,
00092            const Teuchos::ArrayView<const LocalOrdinal>& myBlockSizes,
00093            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00094 
00096   ~BlockMap(){}
00097 
00099 
00101 
00102 
00103   const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& getPointMap() const
00104     { return pointMap_; }
00105 
00106   global_size_t getGlobalNumBlocks() const;
00107 
00109   size_t getNodeNumBlocks() const;
00110 
00111   Teuchos::ArrayView<const GlobalOrdinal> getNodeBlockIDs() const;
00112 
00113   bool isBlockSizeConstant() const;
00114 
00116   Teuchos::ArrayRCP<const LocalOrdinal> getNodeFirstPointInBlocks() const;
00117 
00119 
00122   Teuchos::ArrayRCP<const LocalOrdinal> getNodeFirstPointInBlocks_Device() const;
00123 
00125 
00127   GlobalOrdinal getGlobalBlockID(LocalOrdinal localBlockID) const;
00128 
00130 
00132   LocalOrdinal getLocalBlockID(GlobalOrdinal globalBlockID) const;
00133 
00135 
00138   LocalOrdinal getLocalBlockSize(LocalOrdinal localBlockID) const;
00139 
00141 
00144   LocalOrdinal getFirstLocalPointInLocalBlock(LocalOrdinal localBlockID) const;
00145 
00147 
00150   GlobalOrdinal getFirstGlobalPointInLocalBlock(LocalOrdinal localBlockID) const;
00151 
00153 
00154  private:
00155   void setup_noncontig_mapping();
00156 
00157   Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > pointMap_;
00158   global_size_t globalNumBlocks_;
00159   Teuchos::Array<GlobalOrdinal> myGlobalBlockIDs_;
00160   Teuchos::ArrayRCP<LocalOrdinal> pbuf_firstPointInBlock_;
00161   Teuchos::ArrayRCP<const LocalOrdinal> view_firstPointInBlock_;
00162   bool blockIDsAreContiguous_;
00163   LocalOrdinal constantBlockSize_;
00164   std::map<GlobalOrdinal,LocalOrdinal> map_global_to_local_; //need to use a hash (unordered_map) here instead of a map...
00165 };//class BlockMap
00166 
00167 //-----------------------------------------------------------------
00168 template<class LocalOrdinal,class GlobalOrdinal,class Node>
00169 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
00170 convertBlockMapToPointMap(const Teuchos::RCP<const Tpetra::BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& blockMap)
00171 {
00172   global_size_t numGlobalElems = Teuchos::OrdinalTraits<global_size_t>::invalid();
00173   GlobalOrdinal indexBase = blockMap->getPointMap()->getIndexBase();
00174   const Teuchos::RCP<const Teuchos::Comm<int> >& comm = blockMap->getPointMap()->getComm();
00175   const Teuchos::RCP<Node>& node = blockMap->getPointMap()->getNode();
00176 
00177   //Create a point-entry map where each point
00178   //corresponds to a block in the block-map:
00179   return Teuchos::rcp(new Map<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElems, blockMap->getNodeBlockIDs(), indexBase, comm, node));
00180 }
00181 
00182 }//namespace Tpetra
00183 
00184 #endif
00185 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines