Tpetra Matrix/Vector Services  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Tpetra_Map_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Tpetra: Templated Linear Algebra Services Package
5 // Copyright (2008) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 // @HEADER
41 
42 #ifndef TPETRA_MAP_DECL_HPP
43 #define TPETRA_MAP_DECL_HPP
44 
45 #include <Kokkos_DefaultNode.hpp>
46 #include <Teuchos_Describable.hpp>
47 
48 // enums and defines
49 #include "Tpetra_ConfigDefs.hpp"
50 
51 // mfh 27 Apr 2013: If HAVE_TPETRA_FIXED_HASH_TABLE is defined (which
52 // it is by default), then Map will used the fixed-structure hash
53 // table variant for global-to-local index lookups. Otherwise, it
54 // will use the dynamic-structure hash table variant.
55 
56 #ifndef HAVE_TPETRA_FIXED_HASH_TABLE
57 # define HAVE_TPETRA_FIXED_HASH_TABLE 1
58 #endif // HAVE_TPETRA_FIXED_HASH_TABLE
59 
63 namespace Tpetra {
64 
65 #ifndef DOXYGEN_SHOULD_SKIP_THIS
66  // Forward declaration of Directory.
67  template <class LO, class GO, class N> class Directory;
68 
69 # ifdef HAVE_TPETRA_FIXED_HASH_TABLE
70  namespace Details {
71  template<class GlobalOrdinal, class LocalOrdinal>
72  class FixedHashTable;
73  } // namespace Details
74 # else
75  namespace Details {
76  template<class GlobalOrdinal, class LocalOrdinal>
77  class HashTable;
78  } // namespace Details
79 # endif // HAVE_TPETRA_FIXED_HASH_TABLE
80 #endif // DOXYGEN_SHOULD_SKIP_THIS
81 
188  template <class LocalOrdinal,
189  class GlobalOrdinal = LocalOrdinal,
190  class Node = Kokkos::DefaultNode::DefaultNodeType>
191  class Map : public Teuchos::Describable {
192  public:
194 
195 
197  typedef LocalOrdinal local_ordinal_type;
199  typedef GlobalOrdinal global_ordinal_type;
201  typedef Node node_type;
202 
204 
205 
247  Map (global_size_t numGlobalElements,
248  GlobalOrdinal indexBase,
249  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
251  const Teuchos::RCP<Node> &node = Kokkos::Details::getNode<Node>());
252 
292  Map (global_size_t numGlobalElements,
293  size_t numLocalElements,
294  GlobalOrdinal indexBase,
295  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
296  const Teuchos::RCP<Node> &node = Kokkos::Details::getNode<Node>());
297 
332  Map (global_size_t numGlobalElements,
333  const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
334  GlobalOrdinal indexBase,
335  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
336  const Teuchos::RCP<Node> &node = Kokkos::Details::getNode<Node>());
337 
339  ~Map();
340 
342 
344 
346  inline global_size_t getGlobalNumElements() const { return numGlobalElements_; }
347 
349  inline size_t getNodeNumElements() const { return numLocalElements_; }
350 
352  inline GlobalOrdinal getIndexBase() const { return indexBase_; }
353 
355  inline LocalOrdinal getMinLocalIndex() const {
356  return Teuchos::OrdinalTraits<LocalOrdinal>::zero();
357  }
358 
364  inline LocalOrdinal getMaxLocalIndex() const {
365  if (getNodeNumElements () == 0) {
366  return Teuchos::OrdinalTraits<LocalOrdinal>::invalid ();
367  }
368  else { // Local indices are always zero-based.
369  return Teuchos::as<LocalOrdinal> (getNodeNumElements () - 1);
370  }
371  }
372 
374  inline GlobalOrdinal getMinGlobalIndex() const { return minMyGID_; }
375 
377  inline GlobalOrdinal getMaxGlobalIndex() const { return maxMyGID_; }
378 
380  inline GlobalOrdinal getMinAllGlobalIndex() const { return minAllGID_; }
381 
383  inline GlobalOrdinal getMaxAllGlobalIndex() const { return maxAllGID_; }
384 
389  LocalOrdinal getLocalElement (GlobalOrdinal globalIndex) const;
390 
395  GlobalOrdinal getGlobalElement (LocalOrdinal localIndex) const;
396 
427  getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal>& GIDList,
428  const Teuchos::ArrayView< int>& nodeIDList,
429  const Teuchos::ArrayView< LocalOrdinal>& LIDList) const;
430 
455  getRemoteIndexList (const Teuchos::ArrayView<const GlobalOrdinal> & GIDList,
456  const Teuchos::ArrayView< int> & nodeIDList) const;
457 
464  Teuchos::ArrayView<const GlobalOrdinal> getNodeElementList() const;
465 
467 
469 
471  bool isNodeLocalElement (LocalOrdinal localIndex) const;
472 
474  bool isNodeGlobalElement (GlobalOrdinal globalIndex) const;
475 
482  bool isUniform () const;
483 
495  bool isContiguous () const;
496 
517  bool isDistributed () const;
518 
543  bool isCompatible (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const;
544 
574  bool isSameAs (const Map<LocalOrdinal,GlobalOrdinal,Node> &map) const;
575 
577 
579 
581  const Teuchos::RCP<const Teuchos::Comm<int> > & getComm() const;
582 
584  const Teuchos::RCP<Node> & getNode() const;
585 
587 
589 
591  std::string description() const;
592 
594  void
595  describe (Teuchos::FancyOStream &out,
596  const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
597 
599 
601 
603  template <class Node2>
604  RCP<const Map<LocalOrdinal, GlobalOrdinal, Node2> > clone (const RCP<Node2>& node2) const;
605 
653  RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
654  removeEmptyProcesses () const;
655 
683  RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
684  replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const;
686 
687  protected:
688  // This lets other specializations of Map access all of this
689  // specialization's internal methods and data, so that we can
690  // implement clone() without exposing the details of Map to users.
691  template <class LO, class GO, class N> friend class Map;
692 
699  Map() {}
700 
701  private:
709  void setupDirectory () const;
710 
725  bool checkIsDist() const;
726 
729 
732  operator= (const Map<LocalOrdinal,GlobalOrdinal,Node> & source);
733 
735  Teuchos::RCP<const Teuchos::Comm<int> > comm_;
736 
743  Teuchos::RCP<Node> node_;
744 
746  GlobalOrdinal indexBase_;
748  global_size_t numGlobalElements_;
750  size_t numLocalElements_;
752  GlobalOrdinal minMyGID_, maxMyGID_;
754  GlobalOrdinal minAllGID_, maxAllGID_;
756  GlobalOrdinal firstContiguousGID_, lastContiguousGID_;
762  bool uniform_;
764  bool contiguous_;
766  bool distributed_;
767 
784  mutable Teuchos::ArrayRCP<GlobalOrdinal> lgMap_;
785 
786 #ifdef HAVE_TPETRA_FIXED_HASH_TABLE
787  typedef Details::FixedHashTable<GlobalOrdinal, LocalOrdinal> global_to_local_table_type;
789 #else
790  typedef Details::HashTable<GlobalOrdinal, LocalOrdinal> global_to_local_table_type;
792 #endif // HAVE_TPETRA_FIXED_HASH_TABLE
793 
806  RCP<global_to_local_table_type> glMap_;
807 
832  mutable Teuchos::RCP<Directory<LocalOrdinal,GlobalOrdinal,Node> > directory_;
833 
834  }; // Map class
835 
850  template <class LocalOrdinal, class GlobalOrdinal>
851  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> >
852  createLocalMap (size_t numElements, const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
853 
870  template <class LocalOrdinal, class GlobalOrdinal, class Node>
871  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
872  createLocalMapWithNode (size_t numElements,
873  const Teuchos::RCP<const Teuchos::Comm<int> >& comm,
874  const Teuchos::RCP<Node>& node = Kokkos::Details::getNode<Node> ());
875 
884  template <class LocalOrdinal, class GlobalOrdinal>
885  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal> >
886  createUniformContigMap(global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm);
887 
894  template <class LocalOrdinal, class GlobalOrdinal, class Node>
895  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
897  const Teuchos::RCP< const Teuchos::Comm< int > > &comm,
898  const Teuchos::RCP< Node > &node = Kokkos::Details::getNode<Node>());
899 
908  template <class LocalOrdinal, class GlobalOrdinal>
909  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> >
910  createContigMap (global_size_t numElements,
911  size_t localNumElements,
912  const Teuchos::RCP<const Teuchos::Comm<int> > &comm);
913 
920  template <class LocalOrdinal, class GlobalOrdinal, class Node>
921  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
923  size_t localNumElements,
924  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
925  const Teuchos::RCP<Node> &node);
926 
935  template <class LocalOrdinal, class GlobalOrdinal>
936  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Kokkos::DefaultNode::DefaultNodeType> >
937  createNonContigMap (const ArrayView<const GlobalOrdinal> &elementList,
938  const RCP<const Teuchos::Comm<int> > &comm);
939 
946  template <class LocalOrdinal, class GlobalOrdinal, class Node>
947  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
948  createNonContigMapWithNode (const ArrayView<const GlobalOrdinal> &elementList,
949  const RCP<const Teuchos::Comm<int> > &comm,
950  const RCP<Node> &node);
951 
958  template <class LocalOrdinal, class GlobalOrdinal, class Node>
959  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
960  createWeightedContigMapWithNode (int thisNodeWeight,
961  global_size_t numElements,
962  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
963  const Teuchos::RCP<Node> &node);
964 
971  template<class LocalOrdinal, class GlobalOrdinal, class Node>
972  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
973  createOneToOne(Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &M);
974 
975 } // Tpetra namespace
976 
977 #include "Tpetra_Directory_decl.hpp"
978 
979 namespace Tpetra {
980  template <class LocalOrdinal, class GlobalOrdinal, class Node>
981  template <class Node2>
982  RCP<const Map<LocalOrdinal, GlobalOrdinal, Node2> >
983  Map<LocalOrdinal,GlobalOrdinal,Node>::clone (const RCP<Node2> &node2) const
984  {
986  RCP<Map2> map = rcp (new Map2 ());
987  // Fill the new Map with shallow copies of all of the original
988  // Map's data. This is safe because Map is immutable, so users
989  // can't change the original Map.
990  map->comm_ = comm_;
991  map->indexBase_ = indexBase_;
992  map->numGlobalElements_ = numGlobalElements_;
993  map->numLocalElements_ = numLocalElements_;
994  map->minMyGID_ = minMyGID_;
995  map->maxMyGID_ = maxMyGID_;
996  map->minAllGID_ = minAllGID_;
997  map->maxAllGID_ = maxAllGID_;
998  map->firstContiguousGID_= firstContiguousGID_;
999  map->lastContiguousGID_ = lastContiguousGID_;
1000  map->uniform_ = uniform_;
1001  map->contiguous_ = contiguous_;
1002  map->distributed_ = distributed_;
1003  map->lgMap_ = lgMap_;
1004  map->glMap_ = glMap_;
1005  // New Map gets the new Node instance.
1006  map->node_ = node2;
1007  // mfh 02 Apr 2013: While Map only needs to create the Directory
1008  // on demand in getRemoteIndexList, we have a Directory here that
1009  // we can clone inexpensively, so there is no harm in creating it
1010  // here.
1011  if (! directory_.is_null ()) {
1012  // The weak reference prevents circularity.
1013  map->directory_ = directory_->template clone<Node2> (map.create_weak ());
1014  }
1015  return map;
1016  }
1017 } // namespace Tpetra
1018 
1021 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1024 { return map1.isSameAs (map2); }
1025 
1028 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1031 { return ! map1.isSameAs (map2); }
1032 
1033 #endif // TPETRA_MAP_DECL_HPP
1034 
~Map()
Destructor.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map&#39;s communicator with a subset communicator.
GlobalOrdinal global_ordinal_type
The type of global indices.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
const Teuchos::RCP< const Teuchos::Comm< int > > & getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
bool isCompatible(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is compatible with this Map.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Kokkos::DefaultNode::DefaultNodeType > > createNonContigMap(const ArrayView< const GlobalOrdinal > &elementList, const RCP< const Teuchos::Comm< int > > &comm)
Non-member constructor for a non-contiguous Map with the default Kokkos Node.
bool isUniform() const
Whether the range of global indices is uniform.
GlobalOrdinal getIndexBase() const
The index base for this Map.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
LocalOrdinal getMinLocalIndex() const
The minimum local index.
bool operator!=(const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map1, const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map2)
True if map1 is not the same as (in the sense of isSameAs()) map2, else false.
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createLocalMap(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a locally replicated Map with the default Kokkos Node.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createContigMapWithNode(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Non-member constructor for a (potentially) non-uniformly distributed, contiguous Map with a user-spec...
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node2 > > clone(const RCP< Node2 > &node2) const
Advanced methods.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createWeightedContigMapWithNode(int thisNodeWeight, global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node)
Non-member constructor for a contiguous Map with user-defined weights and a user-specified Kokkos Nod...
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
size_t global_size_t
Global size_t object.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createUniformContigMap(global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member constructor for a uniformly distributed, contiguous Map with the default Kokkos Node...
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > removeEmptyProcesses() const
Return a new Map with processes with zero elements removed.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a view of the global indices owned by this process.
bool operator==(const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map1, const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map2)
True if map1 is the same as (in the sense of isSameAs()) map2, else false.
Node node_type
The type of the Kokkos Node.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
Describes a parallel distribution of objects over processes.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Kokkos::DefaultNode::DefaultNodeType > > createContigMap(global_size_t numElements, size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member constructor for a (potentially) non-uniformly distributed, contiguous Map with the default...
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
LocalOrdinal local_ordinal_type
The type of local indices.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createNonContigMapWithNode(const ArrayView< const GlobalOrdinal > &elementList, const RCP< const Teuchos::Comm< int > > &comm, const RCP< Node > &node)
Non-member constructor for a non-contiguous Map with a user-specified Kokkos Node.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=Kokkos::Details::getNode< Node >())
Non-member constructor for a uniformly distributed, contiguous Map with a user-specified Kokkos Node...
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print this object with the given verbosity level to the given Teuchos::FancyOStream.
const Teuchos::RCP< Node > & getNode() const
Get this Map&#39;s Node object.
LocalOrdinal getMaxLocalIndex() const
The maximum local index on the calling process.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=Kokkos::Details::getNode< Node >())
Nonmember constructor for a locally replicated Map with a specified Kokkos Node.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createOneToOne(Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &M)
Creates a one-to-one version of the given Map where each GID is owned by only one process...
std::string description() const
Implementation of Teuchos::Describable.
Map()
Default constructor (that does nothing).