Tpetra parallel linear algebra Version of the Day
Loading...
Searching...
No Matches
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"
19#include "Tpetra_Map_fwd.hpp"
23#include "Tpetra_KokkosCompat_DefaultNode.hpp"
24#include "Kokkos_DualView.hpp"
25#include "Teuchos_Array.hpp"
26#include "Teuchos_Comm.hpp"
27#include "Teuchos_Describable.hpp"
28
29namespace Tpetra {
30
195template <class LocalOrdinal, class GlobalOrdinal, class Node>
196class Map : public Teuchos::Describable {
197 public:
199
200
203
206
212 using device_type = typename Node::device_type;
213
215 using execution_space = typename device_type::execution_space;
216
218 using memory_space = typename device_type::memory_space;
219
221 using node_type = Node;
222
240
242
244
296 const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
297 const LocalGlobal lg = GloballyDistributed);
298
335 const size_t numLocalElements,
337 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
338
388 const Kokkos::View<const global_ordinal_type*, device_type>& indexList,
390 const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
391 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
392
443 const global_ordinal_type indexList[],
446 const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
447 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
448
499 const Teuchos::ArrayView<const global_ordinal_type>& indexList,
501 const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
502 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
503
517 Map();
518
521
524
526 Map&
528
530 Map&
532
542 virtual ~Map();
543
545
547
552 bool isOneToOne() const;
553
560 return numGlobalElements_;
561 }
562
568 size_t getLocalNumElements() const {
569 return numLocalElements_;
570 }
571
578 return indexBase_;
579 }
580
587 return static_cast<local_ordinal_type>(0);
588 }
589
601 if (this->getLocalNumElements() == 0) {
602 return Tpetra::Details::OrdinalTraits<local_ordinal_type>::invalid();
603 } else { // Local indices are always zero-based.
604 return static_cast<local_ordinal_type>(this->getLocalNumElements() - 1);
605 }
606 }
607
613 global_ordinal_type getMinGlobalIndex() const {
614 return minMyGID_;
615 }
616
623 return maxMyGID_;
624 }
625
632 TEUCHOS_TEST_FOR_EXCEPTION(!haveGlobalConstants(), std::logic_error, "\"Map::getMinAllGlobalIndex\" called, but global constants have not been computed with \"Map::computeGlobalConstants\".");
633 return minAllGID_;
634 }
635
642 TEUCHOS_TEST_FOR_EXCEPTION(!haveGlobalConstants(), std::logic_error, "\"Map::getMaxAllGlobalIndex\" called, but global constants have not been computed with \"Map::computeGlobalConstants\".");
643 return maxAllGID_;
644 }
645
659
669
670 bool getGlobalElements(
671 const local_ordinal_type localIndices[], size_t numEntries, global_ordinal_type globalIndices[]) const;
672
678
709 getRemoteIndexList(const Teuchos::ArrayView<const global_ordinal_type>& GIDList,
710 const Teuchos::ArrayView<int>& nodeIDList,
711 const Teuchos::ArrayView<local_ordinal_type>& LIDList) const;
712
737 getRemoteIndexList(const Teuchos::ArrayView<const global_ordinal_type>& GIDList,
738 const Teuchos::ArrayView<int>& nodeIDList) const;
739
740 private:
752 typedef Kokkos::View<const global_ordinal_type*,
753 Kokkos::LayoutLeft,
754 Kokkos::HostSpace>
755 global_indices_array_type;
756
757 typedef Kokkos::View<const global_ordinal_type*,
759 global_indices_array_device_type;
760
761 public:
781 global_indices_array_type getMyGlobalIndices() const;
782
784 global_indices_array_device_type getMyGlobalIndicesDevice() const;
785
796 Teuchos::ArrayView<const global_ordinal_type> getLocalElementList() const;
797
799
801
809
817
824 bool isUniform() const;
825
837 bool isContiguous() const;
838
859 bool isDistributed() const;
860
886
918
924
941
943
945
947 Teuchos::RCP<const Teuchos::Comm<int>> getComm() const;
948
950
952
954 std::string description() const;
955
977 void
978 describe(Teuchos::FancyOStream& out,
979 const Teuchos::EVerbosityLevel verbLevel =
980 Teuchos::Describable::verbLevel_default) const;
982
984
1033 Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node>>
1034 removeEmptyProcesses() const;
1035
1063 Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node>>
1064 replaceCommWithSubset(const Teuchos::RCP<const Teuchos::Comm<int>>& newComm) const;
1066
1067 private:
1072 std::string
1073 localDescribeToString(const Teuchos::EVerbosityLevel vl) const;
1074
1082 void setupDirectory() const;
1083
1098 bool checkIsDist() const;
1099
1108 initialNonuniformDebugCheck(
1109 const char errorMessagePrefix[],
1111 const size_t numLocalElements,
1113 const Teuchos::RCP<const Teuchos::Comm<int>>& comm) const;
1114
1115 void
1116 initWithNonownedHostIndexList(
1117 const char errorMessagePrefix[],
1119 const Kokkos::View<const global_ordinal_type*,
1120 Kokkos::LayoutLeft,
1121 Kokkos::HostSpace,
1122 Kokkos::MemoryUnmanaged>& entryList,
1124 const Teuchos::RCP<const Teuchos::Comm<int>>& comm,
1125 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
1126
1127 public:
1132 void lazyPushToHost() const;
1133
1134 private:
1136 Teuchos::RCP<const Teuchos::Comm<int>> comm_;
1137
1139 global_ordinal_type indexBase_;
1140
1143 global_size_t numGlobalElements_;
1144
1146 size_t numLocalElements_;
1147
1149 global_ordinal_type minMyGID_;
1150
1152 global_ordinal_type maxMyGID_;
1153
1156 mutable global_ordinal_type minAllGID_;
1157
1160 mutable global_ordinal_type maxAllGID_;
1161
1168 global_ordinal_type firstContiguousGID_;
1169
1183 global_ordinal_type lastContiguousGID_;
1184
1190 bool uniform_;
1191
1193 bool contiguous_;
1194
1203 mutable bool distributed_;
1204
1205 private:
1206 mutable bool haveGlobalConstants_ = false;
1207
1208 public:
1209 bool haveGlobalConstants() const { return haveGlobalConstants_; }
1210
1214 void computeGlobalConstants() const;
1215
1220 void copyGlobalConstants(const Map<local_ordinal_type, global_ordinal_type, Node>& map);
1221
1251 mutable Kokkos::View<const global_ordinal_type*,
1252 Kokkos::LayoutLeft,
1255
1263#ifndef SWIG
1264 mutable Kokkos::View<const global_ordinal_type*,
1265 Kokkos::LayoutLeft,
1266 Kokkos::HostSpace>
1268#endif
1269
1274
1288
1291 global_ordinal_type, local_ordinal_type, Kokkos::HostSpace::device_type>
1293
1300
1337 mutable Teuchos::RCP<
1338 Directory<
1341}; // Map class
1342
1356template <class LocalOrdinal, class GlobalOrdinal>
1357Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1359 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1360
1375template <class LocalOrdinal, class GlobalOrdinal, class Node>
1376Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1378 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1379
1387template <class LocalOrdinal, class GlobalOrdinal>
1388Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1390 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1391
1398template <class LocalOrdinal, class GlobalOrdinal, class Node>
1399Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1401 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1402
1409template <class LocalOrdinal, class GlobalOrdinal>
1410Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1412 const size_t localNumElements,
1413 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1414
1423template <class LocalOrdinal, class GlobalOrdinal, class Node>
1424Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1426 const size_t localNumElements,
1427 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1428
1435template <class LocalOrdinal, class GlobalOrdinal>
1436Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal>>
1437createNonContigMap(const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
1438 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1439
1447template <class LocalOrdinal, class GlobalOrdinal, class Node>
1448Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1449createNonContigMapWithNode(const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
1450 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1451
1462template <class LocalOrdinal, class GlobalOrdinal, class Node>
1463Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1465
1471template <class LocalOrdinal, class GlobalOrdinal, class Node>
1472Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1474 const ::Tpetra::Details::TieBreak<LocalOrdinal, GlobalOrdinal>& tie_break);
1475
1481
1482template <class LO, class GO, class NT>
1483Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
1485
1486} // namespace Tpetra
1487
1488#include "Tpetra_Directory_decl.hpp"
1489
1492template <class LocalOrdinal, class GlobalOrdinal, class Node>
1495
1498template <class LocalOrdinal, class GlobalOrdinal, class Node>
1501
1502#endif // TPETRA_MAP_DECL_HPP
Declaration and definition of the Tpetra::Map class, an implementation detail of Tpetra::Map.
Declaration of Tpetra::Details::iallreduce.
Forward declaration of Tpetra::Directory.
Forward declaration of Tpetra::Map.
Forward declaration for Tpetra::TieBreak.
Struct that holds views of the contents of a CrsMatrix.
"Local" part of Map suitable for Kokkos kernels.
Implement mapping from global ID to process ID and local ID.
A parallel distribution of indices over processes.
Map & operator=(Map< local_ordinal_type, global_ordinal_type, node_type > &&)=default
Move assigment (shallow move).
Map & operator=(const Map< local_ordinal_type, global_ordinal_type, node_type > &)=default
Copy assigment (shallow copy).
Map(Map< local_ordinal_type, global_ordinal_type, node_type > &&)=default
Move constructor (shallow move).
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
bool isOneToOne() const
Whether the Map is one to one.
std::string description() const
Implementation of Teuchos::Describable.
Teuchos::ArrayView< const global_ordinal_type > getLocalElementList() const
Return a NONOWNING view of the global indices owned by this process.
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.
global_ordinal_type getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
::Tpetra::Details::FixedHashTable< global_ordinal_type, local_ordinal_type, device_type > global_to_local_table_type
Type of a mapping from global IDs to local IDs.
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.
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 getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
Node node_type
Legacy typedef that will go away at some point.
Kokkos::View< const global_ordinal_type *, Kokkos::LayoutLeft, device_type > lgMap_
A mapping from local IDs to global IDs.
Map()
Default constructor (that does nothing).
GlobalOrdinal global_ordinal_type
The type of global indices.
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.
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.
bool isNodeLocalElement(local_ordinal_type localIndex) const
Whether the given local index is valid for this Map on the calling process.
bool isUniform() const
Whether the range of global indices is uniform.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
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.
typename device_type::execution_space execution_space
The Kokkos execution space.
LocalOrdinal local_ordinal_type
The type of local indices.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > removeEmptyProcesses() const
Advanced methods.
void lazyPushToHost() const
Push the device data to host, if needed.
void copyGlobalConstants(const Map< local_ordinal_type, global_ordinal_type, Node > &map)
Copy global constants from a different map.
global_ordinal_type getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
bool isCompatible(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is compatible with this Map.
global_ordinal_type getIndexBase() const
The index base for this Map.
Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > createOneToOneAndMakeOverlappingMapFitted(Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &M)
Creates a one-to-one version of the given Map where each GID lives on only one process....
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...
bool locallySameAs(const Map< local_ordinal_type, global_ordinal_type, node_type > &map) const
Is this Map locally the same as the input Map?
global_to_local_table_host_type glMapHost_
Host View of glMap_.
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 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.
virtual ~Map()
Destructor (virtual for memory safety of derived classes).
::Tpetra::Details::FixedHashTable< global_ordinal_type, local_ordinal_type, Kokkos::HostSpace::device_type > global_to_local_table_host_type
Type of a mapping from global IDs to local IDs on host.
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,...
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map's device.
global_ordinal_type getMinGlobalIndex() const
The minimum global index owned by the calling process.
local_ordinal_type getLocalElement(global_ordinal_type globalIndex) const
The local index corresponding to the given global index.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map's communicator with a subset communicator.
::Tpetra::Details::LocalMap< local_ordinal_type, global_ordinal_type, device_type > local_map_type
Type of the "local" Map.
global_ordinal_type getMaxGlobalIndex() const
The maximum global index owned by the calling process.
Map(const Map< local_ordinal_type, global_ordinal_type, node_type > &)=default
Copy constructor (shallow copy).
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.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
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 ...
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.
bool isNodeGlobalElement(global_ordinal_type globalIndex) const
Whether the given global index is owned by this Map on the calling process.
Kokkos::View< const global_ordinal_type *, Kokkos::LayoutLeft, Kokkos::HostSpace > lgMapHost_
Host View of lgMap_.
bool isSameAs(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is identical to this Map.
local_ordinal_type getMinLocalIndex() const
The minimum local index.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
global_to_local_table_type glMap_
A mapping from global IDs to local IDs.
local_map_type getLocalMap() const
Get the LocalMap for Kokkos-Kernels.
global_indices_array_type getMyGlobalIndices() const
Return a view of the global indices owned by this process.
typename device_type::memory_space memory_space
The Kokkos memory space.
local_ordinal_type getMaxLocalIndex() const
The maximum local index on the calling process.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createOneToOne(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &M, const ::Tpetra::Details::TieBreak< LocalOrdinal, GlobalOrdinal > &tie_break)
Creates a one-to-one version of the given Map where each GID lives on only one process....
void computeGlobalConstants() const
Compute global constants for the map. This method needs to be called collectively over all processes ...
Teuchos::RCP< Directory< local_ordinal_type, global_ordinal_type, node_type > > directory_
Object that can find the process rank and local index for any given global index.
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...
typename Node::device_type device_type
This class' Kokkos::Device specialization.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
size_t global_size_t
Global size_t object.
LocalGlobal
Enum for local versus global allocation of Map entries.