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 
00057 template <class LocalOrdinal, class GlobalOrdinal = LocalOrdinal, class Node = Kokkos::DefaultNode::DefaultNodeType>
00058 class BlockMap : public Teuchos::Describable {
00059  public:
00060   typedef LocalOrdinal  local_ordinal_type;
00061   typedef GlobalOrdinal global_ordinal_type;
00062   typedef Node          node_type;
00063 
00065 
00066 
00069   BlockMap(global_size_t numGlobalBlocks,
00070            LocalOrdinal blockSize,
00071            GlobalOrdinal indexBase,
00072            const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00073            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00074 
00077   BlockMap(global_size_t numGlobalBlocks,
00078            size_t numLocalBlocks,
00079            LocalOrdinal blockSize,
00080            GlobalOrdinal indexBase,
00081            const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00082            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00083 
00086   BlockMap(global_size_t numGlobalBlocks,
00087       const Teuchos::ArrayView<const GlobalOrdinal>& myGlobalBlockIDs,
00088       const Teuchos::ArrayView<const GlobalOrdinal>& myFirstGlobalPointInBlocks,
00089       const Teuchos::ArrayView<const LocalOrdinal>& myBlockSizes,
00090       GlobalOrdinal indexBase,
00091       const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00092       const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00093 
00100   BlockMap(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& pointMap,
00101            const Teuchos::ArrayView<const GlobalOrdinal>& myGlobalBlockIDs,
00102            const Teuchos::ArrayView<const LocalOrdinal>& myBlockSizes,
00103            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00104 
00106   ~BlockMap(){}
00107 
00109 
00111 
00112 
00114   const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& getPointMap() const
00115     { return pointMap_; }
00116 
00118   global_size_t getGlobalNumBlocks() const;
00119 
00121   size_t getNodeNumBlocks() const;
00122 
00124   Teuchos::ArrayView<const GlobalOrdinal> getNodeBlockIDs() const;
00125 
00127   bool isBlockSizeConstant() const;
00128 
00130   Teuchos::ArrayRCP<const LocalOrdinal> getNodeFirstPointInBlocks() const;
00131 
00133 
00136   Teuchos::ArrayRCP<const LocalOrdinal> getNodeFirstPointInBlocks_Device() const;
00137 
00139 
00141   GlobalOrdinal getGlobalBlockID(LocalOrdinal localBlockID) const;
00142 
00144 
00146   LocalOrdinal getLocalBlockID(GlobalOrdinal globalBlockID) const;
00147 
00149 
00152   LocalOrdinal getLocalBlockSize(LocalOrdinal localBlockID) const;
00153 
00155 
00158   LocalOrdinal getFirstLocalPointInLocalBlock(LocalOrdinal localBlockID) const;
00159 
00161 
00164   GlobalOrdinal getFirstGlobalPointInLocalBlock(LocalOrdinal localBlockID) const;
00165 
00167   void getRemoteBlockInfo(const Teuchos::ArrayView<const GlobalOrdinal>& GBIDs,
00168                           const Teuchos::ArrayView<GlobalOrdinal>& firstGlobalPointInBlocks,
00169                           const Teuchos::ArrayView<LocalOrdinal>& blockSizes) const;
00171 
00172  private:
00173   void setup_noncontig_mapping();
00174 
00175   Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > pointMap_;
00176   global_size_t globalNumBlocks_;
00177   Teuchos::Array<GlobalOrdinal> myGlobalBlockIDs_;
00178   Teuchos::ArrayRCP<LocalOrdinal> pbuf_firstPointInBlock_;
00179   Teuchos::ArrayRCP<const LocalOrdinal> view_firstPointInBlock_;
00180   bool blockIDsAreContiguous_;
00181   LocalOrdinal constantBlockSize_;
00182   std::map<GlobalOrdinal,LocalOrdinal> map_global_to_local_; //need to use a hash (unordered_map) here instead of a map...
00183 };//class BlockMap
00184 
00185 //-----------------------------------------------------------------
00186 template<class LocalOrdinal,class GlobalOrdinal,class Node>
00187 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
00188 convertBlockMapToPointMap(const Tpetra::BlockMap<LocalOrdinal,GlobalOrdinal,Node>& blockMap)
00189 {
00190   global_size_t numGlobalElems = Teuchos::OrdinalTraits<global_size_t>::invalid();
00191   GlobalOrdinal indexBase = blockMap.getPointMap()->getIndexBase();
00192   const Teuchos::RCP<const Teuchos::Comm<int> >& comm = blockMap.getPointMap()->getComm();
00193   const Teuchos::RCP<Node>& node = blockMap.getPointMap()->getNode();
00194 
00195   //Create a point-entry map where each point
00196   //corresponds to a block in the block-map:
00197   return Teuchos::rcp(new Map<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElems, blockMap.getNodeBlockIDs(), indexBase, comm, node));
00198 }
00199 
00200 }//namespace Tpetra
00201 
00202 #endif
00203 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines