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 // Tpetra: Templated Linear Algebra Services Package
4 //
5 // Copyright 2008 NTESS and the Tpetra contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef TPETRA_MAP_DECL_HPP
11 #define TPETRA_MAP_DECL_HPP
12 
16 
17 #include "Tpetra_ConfigDefs.hpp"
18 #include "Tpetra_Map_fwd.hpp"
19 #include "Tpetra_Directory_fwd.hpp"
20 #include "Tpetra_TieBreak_fwd.hpp"
22 #include "Tpetra_KokkosCompat_DefaultNode.hpp"
23 #include "Kokkos_DualView.hpp"
24 #include "Teuchos_Array.hpp"
25 #include "Teuchos_Comm.hpp"
26 #include "Teuchos_Describable.hpp"
27 
28 namespace Tpetra {
29 
194 template <class LocalOrdinal,
195  class GlobalOrdinal,
196  class Node>
197 class Map : public Teuchos::Describable {
198  public:
200 
201 
203  using local_ordinal_type = LocalOrdinal;
204 
206  using global_ordinal_type = GlobalOrdinal;
207 
213  using device_type = typename Node::device_type;
214 
216  using execution_space = typename device_type::execution_space;
217 
219  using memory_space = typename device_type::memory_space;
220 
222  using node_type = Node;
223 
237  using local_map_type =
241 
243 
245 
295  Map(const global_size_t numGlobalElements,
296  const global_ordinal_type indexBase,
297  const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
298  const LocalGlobal lg = GloballyDistributed);
299 
335  Map(const global_size_t numGlobalElements,
336  const size_t numLocalElements,
337  const global_ordinal_type indexBase,
338  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
339 
380  Map(const global_size_t numGlobalElements,
381  const Kokkos::View<const global_ordinal_type*, device_type>& indexList,
382  const global_ordinal_type indexBase,
383  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
384 
426  Map(const global_size_t numGlobalElements,
427  const global_ordinal_type indexList[],
428  const local_ordinal_type indexListSize,
429  const global_ordinal_type indexBase,
430  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
431 
473  Map(const global_size_t numGlobalElements,
474  const Teuchos::ArrayView<const global_ordinal_type>& indexList,
475  const global_ordinal_type indexBase,
476  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
477 
491  Map();
492 
495 
498 
500  Map&
502 
504  Map&
506 
516  virtual ~Map();
517 
519 
521 
526  bool isOneToOne() const;
527 
534  return numGlobalElements_;
535  }
536 
542  size_t getLocalNumElements() const {
543  return numLocalElements_;
544  }
545 
552  return indexBase_;
553  }
554 
561  return static_cast<local_ordinal_type>(0);
562  }
563 
575  if (this->getLocalNumElements() == 0) {
576  return Tpetra::Details::OrdinalTraits<local_ordinal_type>::invalid();
577  } else { // Local indices are always zero-based.
578  return static_cast<local_ordinal_type>(this->getLocalNumElements() - 1);
579  }
580  }
581 
588  return minMyGID_;
589  }
590 
597  return maxMyGID_;
598  }
599 
606  return minAllGID_;
607  }
608 
615  return maxAllGID_;
616  }
617 
631 
641 
646  local_map_type getLocalMap() const;
647 
678  getRemoteIndexList(const Teuchos::ArrayView<const global_ordinal_type>& GIDList,
679  const Teuchos::ArrayView<int>& nodeIDList,
680  const Teuchos::ArrayView<local_ordinal_type>& LIDList) const;
681 
706  getRemoteIndexList(const Teuchos::ArrayView<const global_ordinal_type>& GIDList,
707  const Teuchos::ArrayView<int>& nodeIDList) const;
708 
709  private:
721  typedef Kokkos::View<const global_ordinal_type*,
722  Kokkos::LayoutLeft,
723  Kokkos::HostSpace>
724  global_indices_array_type;
725 
726  typedef Kokkos::View<const global_ordinal_type*,
727  device_type>
728  global_indices_array_device_type;
729 
730  public:
750  global_indices_array_type getMyGlobalIndices() const;
751 
753  global_indices_array_device_type getMyGlobalIndicesDevice() const;
754 
765  Teuchos::ArrayView<const global_ordinal_type> getLocalElementList() const;
766 
768 
770 
777  bool isNodeLocalElement(local_ordinal_type localIndex) const;
778 
785  bool isNodeGlobalElement(global_ordinal_type globalIndex) const;
786 
793  bool isUniform() const;
794 
806  bool isContiguous() const;
807 
828  bool isDistributed() const;
829 
855 
887 
893 
910 
912 
914 
916  Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
917 
919 
921 
923  std::string description() const;
924 
946  void
947  describe(Teuchos::FancyOStream& out,
948  const Teuchos::EVerbosityLevel verbLevel =
949  Teuchos::Describable::verbLevel_default) const;
951 
953 
1002  Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node>>
1003  removeEmptyProcesses() const;
1004 
1032  Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node>>
1033  replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& newComm) const;
1035 
1036  private:
1041  std::string
1042  localDescribeToString(const Teuchos::EVerbosityLevel vl) const;
1043 
1051  void setupDirectory() const;
1052 
1067  bool checkIsDist() const;
1068 
1077  initialNonuniformDebugCheck(
1078  const char errorMessagePrefix[],
1079  const global_size_t numGlobalElements,
1080  const size_t numLocalElements,
1081  const global_ordinal_type indexBase,
1082  const Teuchos::RCP<const Teuchos::Comm<int>>& comm) const;
1083 
1084  void
1085  initWithNonownedHostIndexList(
1086  const char errorMessagePrefix[],
1087  const global_size_t numGlobalElements,
1088  const Kokkos::View<const global_ordinal_type*,
1089  Kokkos::LayoutLeft,
1090  Kokkos::HostSpace,
1091  Kokkos::MemoryUnmanaged>& entryList,
1092  const global_ordinal_type indexBase,
1093  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1094 
1096  void lazyPushToHost() const;
1097 
1099  Teuchos::RCP<const Teuchos::Comm<int>> comm_;
1100 
1102  global_ordinal_type indexBase_;
1103 
1106  global_size_t numGlobalElements_;
1107 
1109  size_t numLocalElements_;
1110 
1112  global_ordinal_type minMyGID_;
1113 
1115  global_ordinal_type maxMyGID_;
1116 
1119  global_ordinal_type minAllGID_;
1120 
1123  global_ordinal_type maxAllGID_;
1124 
1131  global_ordinal_type firstContiguousGID_;
1132 
1146  global_ordinal_type lastContiguousGID_;
1147 
1153  bool uniform_;
1154 
1156  bool contiguous_;
1157 
1166  bool distributed_;
1167 
1197  mutable Kokkos::View<const global_ordinal_type*,
1198  Kokkos::LayoutLeft,
1199  device_type>
1200  lgMap_;
1201 
1209 #ifndef SWIG
1210  mutable Kokkos::View<const global_ordinal_type*,
1211  Kokkos::LayoutLeft,
1212  Kokkos::HostSpace>
1213  lgMapHost_;
1214 #endif
1215 
1217  typedef ::Tpetra::Details::FixedHashTable<global_ordinal_type,
1219  global_to_local_table_type;
1220 
1233  global_to_local_table_type glMap_;
1234 
1236  typedef ::Tpetra::Details::FixedHashTable<
1237  global_ordinal_type, local_ordinal_type, Kokkos::HostSpace::device_type>
1238  global_to_local_table_host_type;
1239 
1245  mutable global_to_local_table_host_type glMapHost_;
1246 
1283  mutable Teuchos::RCP<
1284  Directory<
1286  directory_;
1287 }; // Map class
1288 
1302 template <class LocalOrdinal, class GlobalOrdinal>
1303 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1304 createLocalMap(const size_t numElements,
1305  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1306 
1321 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1322 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1323 createLocalMapWithNode(const size_t numElements,
1324  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1325 
1333 template <class LocalOrdinal, class GlobalOrdinal>
1334 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1335 createUniformContigMap(const global_size_t numElements,
1336  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1337 
1344 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1345 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1347  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1348 
1355 template <class LocalOrdinal, class GlobalOrdinal>
1356 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1357 createContigMap(const global_size_t numElements,
1358  const size_t localNumElements,
1359  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1360 
1369 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1370 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1371 createContigMapWithNode(const global_size_t numElements,
1372  const size_t localNumElements,
1373  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1374 
1381 template <class LocalOrdinal, class GlobalOrdinal>
1382 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1383 createNonContigMap(const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
1384  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1385 
1393 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1394 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1395 createNonContigMapWithNode(const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
1396  const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1397 
1405 
1410 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1411 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1412 createOneToOne(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>& M);
1413 
1419 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1420 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1421 createOneToOne(const Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>& M,
1422  const ::Tpetra::Details::TieBreak<LocalOrdinal, GlobalOrdinal>& tie_break);
1423 
1424 } // namespace Tpetra
1425 
1426 #include "Tpetra_Directory_decl.hpp"
1427 
1430 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1432  const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& map2) { return map1.isSameAs(map2); }
1433 
1436 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1438  const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>& map2) { return !map1.isSameAs(map2); }
1439 
1440 #endif // TPETRA_MAP_DECL_HPP
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.
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.
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.
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.
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 > > 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< 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.
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.
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.
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.
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, 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.
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...
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.
local_map_type getLocalMap() const
Get the LocalMap 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.
A parallel distribution of indices over processes.
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 ...
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.
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 locallySameAs(const Map< local_ordinal_type, global_ordinal_type, node_type > &map) const
Is this Map locally the same as the input Map?
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.
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.
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...
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.
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).