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 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_BLOCKMAP_DECL_HPP
00043 #define TPETRA_BLOCKMAP_DECL_HPP
00044 
00045 #include <map>
00046 
00047 #include "Tpetra_Map.hpp"
00048 
00053 namespace Tpetra {
00054 
00070 template <class LocalOrdinal, class GlobalOrdinal = LocalOrdinal, class Node = Kokkos::DefaultNode::DefaultNodeType>
00071 class BlockMap : public Teuchos::Describable {
00072  public:
00073   typedef LocalOrdinal  local_ordinal_type;
00074   typedef GlobalOrdinal global_ordinal_type;
00075   typedef Node          node_type;
00076 
00078 
00079 
00082   BlockMap(global_size_t numGlobalBlocks,
00083            LocalOrdinal blockSize,
00084            GlobalOrdinal indexBase,
00085            const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00086            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00087 
00090   BlockMap(global_size_t numGlobalBlocks,
00091            size_t numLocalBlocks,
00092            LocalOrdinal blockSize,
00093            GlobalOrdinal indexBase,
00094            const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00095            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00096 
00099   BlockMap(global_size_t numGlobalBlocks,
00100       const Teuchos::ArrayView<const GlobalOrdinal>& myGlobalBlockIDs,
00101       const Teuchos::ArrayView<const GlobalOrdinal>& myFirstGlobalPointInBlocks,
00102       const Teuchos::ArrayView<const LocalOrdinal>& myBlockSizes,
00103       GlobalOrdinal indexBase,
00104       const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
00105       const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00106 
00113   BlockMap(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& pointMap,
00114            const Teuchos::ArrayView<const GlobalOrdinal>& myGlobalBlockIDs,
00115            const Teuchos::ArrayView<const LocalOrdinal>& myBlockSizes,
00116            const Teuchos::RCP<Node> &node = Kokkos::DefaultNode::getDefaultNode());
00117 
00119   ~BlockMap(){}
00120 
00122 
00124 
00125 
00127   const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& getPointMap() const
00128     { return pointMap_; }
00129 
00131   global_size_t getGlobalNumBlocks() const;
00132 
00134   size_t getNodeNumBlocks() const;
00135 
00137   Teuchos::ArrayView<const GlobalOrdinal> getNodeBlockIDs() const;
00138 
00140   bool isBlockSizeConstant() const;
00141 
00143   Teuchos::ArrayRCP<const LocalOrdinal> getNodeFirstPointInBlocks() const;
00144 
00146 
00149   Teuchos::ArrayRCP<const LocalOrdinal> getNodeFirstPointInBlocks_Device() const;
00150 
00152 
00154   GlobalOrdinal getGlobalBlockID(LocalOrdinal localBlockID) const;
00155 
00157 
00159   LocalOrdinal getLocalBlockID(GlobalOrdinal globalBlockID) const;
00160 
00162 
00165   LocalOrdinal getLocalBlockSize(LocalOrdinal localBlockID) const;
00166 
00168 
00171   LocalOrdinal getFirstLocalPointInLocalBlock(LocalOrdinal localBlockID) const;
00172 
00174 
00177   GlobalOrdinal getFirstGlobalPointInLocalBlock(LocalOrdinal localBlockID) const;
00178 
00180   void getRemoteBlockInfo(const Teuchos::ArrayView<const GlobalOrdinal>& GBIDs,
00181                           const Teuchos::ArrayView<GlobalOrdinal>& firstGlobalPointInBlocks,
00182                           const Teuchos::ArrayView<LocalOrdinal>& blockSizes) const;
00184 
00185  private:
00186   void setup_noncontig_mapping();
00187 
00188   Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > pointMap_;
00189   global_size_t globalNumBlocks_;
00190   Teuchos::Array<GlobalOrdinal> myGlobalBlockIDs_;
00191   Teuchos::ArrayRCP<LocalOrdinal> pbuf_firstPointInBlock_;
00192   Teuchos::ArrayRCP<const LocalOrdinal> view_firstPointInBlock_;
00193   bool blockIDsAreContiguous_;
00194   LocalOrdinal constantBlockSize_;
00195   std::map<GlobalOrdinal,LocalOrdinal> map_global_to_local_; //need to use a hash (unordered_map) here instead of a map...
00196 };//class BlockMap
00197 
00198 //-----------------------------------------------------------------
00199 template<class LocalOrdinal,class GlobalOrdinal,class Node>
00200 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
00201 convertBlockMapToPointMap(const Tpetra::BlockMap<LocalOrdinal,GlobalOrdinal,Node>& blockMap)
00202 {
00203   global_size_t numGlobalElems = Teuchos::OrdinalTraits<global_size_t>::invalid();
00204   GlobalOrdinal indexBase = blockMap.getPointMap()->getIndexBase();
00205   const Teuchos::RCP<const Teuchos::Comm<int> >& comm = blockMap.getPointMap()->getComm();
00206   const Teuchos::RCP<Node>& node = blockMap.getPointMap()->getNode();
00207 
00208   //Create a point-entry map where each point
00209   //corresponds to a block in the block-map:
00210   return Teuchos::rcp(new Map<LocalOrdinal,GlobalOrdinal,Node>(numGlobalElems, blockMap.getNodeBlockIDs(), indexBase, comm, node));
00211 }
00212 
00213 }//namespace Tpetra
00214 
00215 #endif
00216 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines