Tpetra parallel linear algebra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 // ************************************************************************
38 // @HEADER
39 
40 #ifndef TPETRA_MAP_DECL_HPP
41 #define TPETRA_MAP_DECL_HPP
42 
46 
47 #include "Tpetra_ConfigDefs.hpp"
48 #include "Tpetra_Map_fwd.hpp"
49 #include "Tpetra_Directory_fwd.hpp"
50 #include "Tpetra_TieBreak_fwd.hpp"
52 #include "Tpetra_KokkosCompat_DefaultNode.hpp"
53 #include "Kokkos_DualView.hpp"
54 #include "Teuchos_Array.hpp"
55 #include "Teuchos_Comm.hpp"
56 #include "Teuchos_Describable.hpp"
57 
58 
59 namespace Tpetra {
60 
225  template <class LocalOrdinal,
226  class GlobalOrdinal,
227  class Node>
228  class Map : public Teuchos::Describable {
229  public:
231 
232 
234  using local_ordinal_type = LocalOrdinal;
235 
237  using global_ordinal_type = GlobalOrdinal;
238 
244  using device_type = typename Node::device_type;
245 
247  using execution_space = typename device_type::execution_space;
248 
250  using memory_space = typename device_type::memory_space;
251 
253  using node_type = Node;
254 
268  using local_map_type =
272 
274 
276 
326  Map (const global_size_t numGlobalElements,
327  const global_ordinal_type indexBase,
328  const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
329  const LocalGlobal lg=GloballyDistributed);
330 
331 
367  Map (const global_size_t numGlobalElements,
368  const size_t numLocalElements,
369  const global_ordinal_type indexBase,
370  const Teuchos::RCP<const Teuchos::Comm<int> > &comm);
371 
372 
413  Map (const global_size_t numGlobalElements,
414  const Kokkos::View<const global_ordinal_type*, device_type>& indexList,
415  const global_ordinal_type indexBase,
416  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
417 
459  Map (const global_size_t numGlobalElements,
460  const global_ordinal_type indexList[],
461  const local_ordinal_type indexListSize,
462  const global_ordinal_type indexBase,
463  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
464 
506  Map (const global_size_t numGlobalElements,
507  const Teuchos::ArrayView<const global_ordinal_type>& indexList,
508  const global_ordinal_type indexBase,
509  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
510 
511 
525  Map ();
526 
529 
532 
534  Map&
536 
538  Map&
540 
550  virtual ~Map ();
551 
553 
555 
560  bool isOneToOne () const;
561 
568  return numGlobalElements_;
569  }
570 
576  size_t getLocalNumElements () const {
577  return numLocalElements_;
578  }
579 
586  return indexBase_;
587  }
588 
595  return static_cast<local_ordinal_type> (0);
596  }
597 
609  if (this->getLocalNumElements () == 0) {
610  return Tpetra::Details::OrdinalTraits<local_ordinal_type>::invalid ();
611  } else { // Local indices are always zero-based.
612  return static_cast<local_ordinal_type> (this->getLocalNumElements () - 1);
613  }
614  }
615 
622  return minMyGID_;
623  }
624 
631  return maxMyGID_;
632  }
633 
640  return minAllGID_;
641  }
642 
649  return maxAllGID_;
650  }
651 
665 
675 
680  local_map_type getLocalMap () const;
681 
712  getRemoteIndexList (const Teuchos::ArrayView<const global_ordinal_type>& GIDList,
713  const Teuchos::ArrayView< int>& nodeIDList,
714  const Teuchos::ArrayView< local_ordinal_type>& LIDList) const;
715 
740  getRemoteIndexList (const Teuchos::ArrayView<const global_ordinal_type> & GIDList,
741  const Teuchos::ArrayView< int> & nodeIDList) const;
742 
743  private:
755  typedef Kokkos::View<const global_ordinal_type*,
756  Kokkos::LayoutLeft,
757  Kokkos::HostSpace> global_indices_array_type;
758 
759  typedef Kokkos::View<const global_ordinal_type*,
760  device_type> global_indices_array_device_type;
761 
762  public:
782  global_indices_array_type getMyGlobalIndices () const;
783 
785  global_indices_array_device_type getMyGlobalIndicesDevice () const;
786 
787 
798  Teuchos::ArrayView<const global_ordinal_type> getLocalElementList() const;
799 
801 
803 
810  bool isNodeLocalElement (local_ordinal_type localIndex) const;
811 
818  bool isNodeGlobalElement (global_ordinal_type globalIndex) const;
819 
826  bool isUniform () const;
827 
839  bool isContiguous () const;
840 
861  bool isDistributed () const;
862 
888 
920 
926 
943 
945 
947 
949  Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
950 
951 
953 
955 
957  std::string description () const;
958 
980  void
981  describe (Teuchos::FancyOStream &out,
982  const Teuchos::EVerbosityLevel verbLevel =
983  Teuchos::Describable::verbLevel_default) const;
985 
987 
1036  Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node> >
1037  removeEmptyProcesses () const;
1038 
1066  Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node> >
1067  replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const;
1069 
1070  private:
1075  std::string
1076  localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
1077 
1085  void setupDirectory () const;
1086 
1101  bool checkIsDist() const;
1102 
1111  initialNonuniformDebugCheck(
1112  const char errorMessagePrefix[],
1113  const global_size_t numGlobalElements,
1114  const size_t numLocalElements,
1115  const global_ordinal_type indexBase,
1116  const Teuchos::RCP<const Teuchos::Comm<int>>& comm) const;
1117 
1118  void
1119  initWithNonownedHostIndexList(
1120  const char errorMessagePrefix[],
1121  const global_size_t numGlobalElements,
1122  const Kokkos::View<const global_ordinal_type*,
1123  Kokkos::LayoutLeft,
1124  Kokkos::HostSpace,
1125  Kokkos::MemoryUnmanaged>& entryList,
1126  const global_ordinal_type indexBase,
1127  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1128 
1130  void lazyPushToHost() const;
1131 
1133  Teuchos::RCP<const Teuchos::Comm<int> > comm_;
1134 
1136  global_ordinal_type indexBase_;
1137 
1140  global_size_t numGlobalElements_;
1141 
1143  size_t numLocalElements_;
1144 
1146  global_ordinal_type minMyGID_;
1147 
1149  global_ordinal_type maxMyGID_;
1150 
1153  global_ordinal_type minAllGID_;
1154 
1157  global_ordinal_type maxAllGID_;
1158 
1165  global_ordinal_type firstContiguousGID_;
1166 
1180  global_ordinal_type lastContiguousGID_;
1181 
1187  bool uniform_;
1188 
1190  bool contiguous_;
1191 
1200  bool distributed_;
1201 
1231  mutable Kokkos::View<const global_ordinal_type*,
1232  Kokkos::LayoutLeft,
1233  device_type> lgMap_;
1234 
1242 #ifndef SWIG
1243  mutable Kokkos::View<const global_ordinal_type*,
1244  Kokkos::LayoutLeft,
1245  Kokkos::HostSpace> lgMapHost_;
1246 #endif
1247 
1249  typedef ::Tpetra::Details::FixedHashTable<global_ordinal_type,
1250  local_ordinal_type, device_type> global_to_local_table_type;
1251 
1264  global_to_local_table_type glMap_;
1265 
1267  typedef ::Tpetra::Details::FixedHashTable<
1268  global_ordinal_type, local_ordinal_type, Kokkos::HostSpace::device_type>
1269  global_to_local_table_host_type;
1270 
1276  mutable global_to_local_table_host_type glMapHost_;
1277 
1314  mutable Teuchos::RCP<
1315  Directory<
1317  >
1318  > directory_;
1319  }; // Map class
1320 
1334  template <class LocalOrdinal, class GlobalOrdinal>
1335  Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal> >
1336  createLocalMap (const size_t numElements,
1337  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1338 
1353  template <class LocalOrdinal, class GlobalOrdinal, class Node>
1354  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
1355  createLocalMapWithNode (const size_t numElements,
1356  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1357 
1358 
1366  template <class LocalOrdinal, class GlobalOrdinal>
1367  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal> >
1368  createUniformContigMap (const global_size_t numElements,
1369  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1370 
1377  template <class LocalOrdinal, class GlobalOrdinal, class Node>
1378  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
1379  createUniformContigMapWithNode (const global_size_t numElements,
1380  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1381 
1382 
1389  template <class LocalOrdinal, class GlobalOrdinal>
1390  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> >
1391  createContigMap (const global_size_t numElements,
1392  const size_t localNumElements,
1393  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1394 
1403  template <class LocalOrdinal, class GlobalOrdinal, class Node>
1404  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
1405  createContigMapWithNode (const global_size_t numElements,
1406  const size_t localNumElements,
1407  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1408 
1409 
1416  template <class LocalOrdinal, class GlobalOrdinal>
1417  Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> >
1418  createNonContigMap (const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
1419  const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1420 
1428  template <class LocalOrdinal, class GlobalOrdinal, class Node>
1429  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
1430  createNonContigMapWithNode (const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
1431  const Teuchos::RCP<const Teuchos::Comm<int> > &comm);
1432 
1440 
1445  template<class LocalOrdinal, class GlobalOrdinal, class Node>
1446  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
1447  createOneToOne (const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >& M);
1448 
1454  template<class LocalOrdinal, class GlobalOrdinal, class Node>
1455  Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
1456  createOneToOne(const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &M,
1457  const ::Tpetra::Details::TieBreak<LocalOrdinal,GlobalOrdinal> & tie_break);
1458 
1459 } // namespace Tpetra
1460 
1461 #include "Tpetra_Directory_decl.hpp"
1462 
1465 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1468 { return map1.isSameAs (map2); }
1469 
1472 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1475 { return ! map1.isSameAs (map2); }
1476 
1477 
1478 #endif // TPETRA_MAP_DECL_HPP
global_ordinal_type getMaxGlobalIndex() const
The maximum global index owned by the calling process.
LO local_ordinal_type
The type of local indices.
virtual ~Map()
Destructor (virtual for memory safety of derived classes).
GO global_ordinal_type
The type of global indices.
bool isSameAs(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is identical to this Map.
global_indices_array_type getMyGlobalIndices() const
Return a view of the global indices owned by this process.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
bool isLocallyFitted(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is locally fitted to this Map.
bool isUniform() const
Whether the range of global indices is uniform.
Declaration and definition of the Tpetra::Map class, an implementation detail of Tpetra::Map.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createContigMapWithNode(const global_size_t numElements, const size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a (potentially) nonuniformly distributed, contiguous Map for a user-specifi...
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map&#39;s device.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > removeEmptyProcesses() const
Advanced methods.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
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.
typename device_type::memory_space memory_space
The Kokkos memory space.
local_ordinal_type getMinLocalIndex() const
The minimum local index.
&quot;Local&quot; part of Map suitable for Kokkos kernels.
Teuchos::ArrayView< const global_ordinal_type > getLocalElementList() const
Return a NONOWNING view of the global indices owned by this process.
size_t global_size_t
Global size_t object.
bool isCompatible(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is compatible with this Map.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createOneToOne(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &M)
Nonmember constructor for a contiguous Map with user-defined weights and a user-specified, possibly nondefault Kokkos Node type.
global_ordinal_type getIndexBase() const
The index base for this Map.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
Forward declaration of Tpetra::Directory.
local_ordinal_type getMaxLocalIndex() const
The maximum local index on the calling process.
bool isNodeLocalElement(local_ordinal_type localIndex) const
Whether the given local index is valid for this Map on the calling process.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map&#39;s communicator with a subset communicator.
bool isNodeGlobalElement(global_ordinal_type globalIndex) const
Whether the given global index is owned by this Map on the calling process.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createUniformContigMap(const 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...
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.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createContigMap(const global_size_t numElements, const size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member constructor for a (potentially) non-uniformly distributed, contiguous Map using the defaul...
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createLocalMap(const size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a locally replicated Map with the default Kokkos Node.
local_map_type getLocalMap() const
Get the local Map for Kokkos kernels.
global_ordinal_type getMinGlobalIndex() const
The minimum global index owned by the calling process.
typename device_type::execution_space execution_space
The Kokkos execution space.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(const global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member constructor for a uniformly distributed, contiguous Map with a user-specified Kokkos Node...
A parallel distribution of indices over processes.
global_ordinal_type getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
local_ordinal_type getLocalElement(global_ordinal_type globalIndex) const
The local index corresponding to the given global index.
Implement mapping from global ID to process ID and local ID.
bool isOneToOne() const
Whether the Map is one to one.
bool locallySameAs(const Map< local_ordinal_type, global_ordinal_type, node_type > &map) const
Is this Map locally the same as the input Map?
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(const size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a locally replicated Map with a specified Kokkos Node.
Map & operator=(const Map< local_ordinal_type, global_ordinal_type, node_type > &)=default
Copy assigment (shallow copy).
typename node_type::device_type device_type
This class&#39; Kokkos::Device specialization.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createNonContigMap(const Teuchos::ArrayView< const GlobalOrdinal > &elementList, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a non-contiguous Map using the default Kokkos::Device type.
LocalGlobal
Enum for local versus global allocation of Map entries.
::Tpetra::Details::LocalMap< local_ordinal_type, global_ordinal_type, device_type > local_map_type
Type of the &quot;local&quot; Map.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const global_ordinal_type > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< local_ordinal_type > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Describe this object in a human-readable way to the given output stream.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createNonContigMapWithNode(const Teuchos::ArrayView< const GlobalOrdinal > &elementList, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Nonmember constructor for a noncontiguous Map with a user-specified, possibly nondefault Kokkos Node ...
node_type node_type
Legacy typedef that will go away at some point.
global_ordinal_type getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
Forward declaration of Tpetra::Map.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
Forward declaration for Tpetra::TieBreak.
std::string description() const
Implementation of Teuchos::Describable.
Map()
Default constructor (that does nothing).