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//
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"
52#include "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
59namespace Tpetra {
60
225 template <class LocalOrdinal,
226 class GlobalOrdinal,
227 class Node>
228 class Map : public Teuchos::Describable {
229 public:
231
232
235
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
256#ifdef KOKKOS_ENABLE_CUDA
257 using no_uvm_memory_space = typename std::conditional<std::is_same<memory_space, Kokkos::CudaUVMSpace>::value,
258 Kokkos::CudaSpace, memory_space>::type;
259 using no_uvm_device_type = Kokkos::Device<execution_space, no_uvm_memory_space>;
260#else
262#endif
263
281
283
285
337 const Teuchos::RCP<const Teuchos::Comm<int> > &comm,
338 const LocalGlobal lg=GloballyDistributed);
339
340
377 const size_t numLocalElements,
379 const Teuchos::RCP<const Teuchos::Comm<int> > &comm);
380
381
423 const Kokkos::View<const global_ordinal_type*, device_type>& indexList,
425 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
426
472 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
473
516 const Teuchos::ArrayView<const global_ordinal_type>& indexList,
518 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
519
520
534 Map ();
535
538
541
543 Map&
545
547 Map&
549
559 virtual ~Map ();
560
562
564
569 bool isOneToOne () const;
570
577 return numGlobalElements_;
578 }
579
585 size_t getLocalNumElements () const {
586 return numLocalElements_;
587 }
588
595 return indexBase_;
596 }
597
604 return static_cast<local_ordinal_type> (0);
605 }
606
618 if (this->getLocalNumElements () == 0) {
619 return Tpetra::Details::OrdinalTraits<local_ordinal_type>::invalid ();
620 } else { // Local indices are always zero-based.
621 return static_cast<local_ordinal_type> (this->getLocalNumElements () - 1);
622 }
623 }
624
630 global_ordinal_type getMinGlobalIndex () const {
631 return minMyGID_;
632 }
633
640 return maxMyGID_;
641 }
642
649 return minAllGID_;
650 }
651
658 return maxAllGID_;
659 }
660
674
684
690
721 getRemoteIndexList (const Teuchos::ArrayView<const global_ordinal_type>& GIDList,
722 const Teuchos::ArrayView< int>& nodeIDList,
723 const Teuchos::ArrayView< local_ordinal_type>& LIDList) const;
724
749 getRemoteIndexList (const Teuchos::ArrayView<const global_ordinal_type> & GIDList,
750 const Teuchos::ArrayView< int> & nodeIDList) const;
751
752 private:
764 typedef Kokkos::View<const global_ordinal_type*,
765 Kokkos::LayoutLeft,
766 Kokkos::HostSpace> global_indices_array_type;
767
768 public:
788 global_indices_array_type getMyGlobalIndices () const;
789
800 Teuchos::ArrayView<const global_ordinal_type> getLocalElementList() const;
801
803
805
813
821
828 bool isUniform () const;
829
841 bool isContiguous () const;
842
863 bool isDistributed () const;
864
890
922
928
945
947
949
951 Teuchos::RCP<const Teuchos::Comm<int> > getComm () const;
952
953
955
957
959 std::string description () const;
960
982 void
983 describe (Teuchos::FancyOStream &out,
984 const Teuchos::EVerbosityLevel verbLevel =
985 Teuchos::Describable::verbLevel_default) const;
987
989
1038 Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node> >
1039 removeEmptyProcesses () const;
1040
1068 Teuchos::RCP<const Map<local_ordinal_type, global_ordinal_type, Node> >
1069 replaceCommWithSubset (const Teuchos::RCP<const Teuchos::Comm<int> >& newComm) const;
1071
1072 private:
1077 std::string
1078 localDescribeToString (const Teuchos::EVerbosityLevel vl) const;
1079
1087 void setupDirectory () const;
1088
1103 bool checkIsDist() const;
1104
1113 initialNonuniformDebugCheck(
1114 const char errorMessagePrefix[],
1116 const size_t numLocalElements,
1118 const Teuchos::RCP<const Teuchos::Comm<int>>& comm) const;
1119
1120 void
1121 initWithNonownedHostIndexList(
1122 const char errorMessagePrefix[],
1124 const Kokkos::View<const global_ordinal_type*,
1125 Kokkos::LayoutLeft,
1126 Kokkos::HostSpace,
1127 Kokkos::MemoryUnmanaged>& entryList,
1129 const Teuchos::RCP<const Teuchos::Comm<int>>& comm);
1130
1132 Teuchos::RCP<const Teuchos::Comm<int> > comm_;
1133
1135 global_ordinal_type indexBase_;
1136
1139 global_size_t numGlobalElements_;
1140
1142 size_t numLocalElements_;
1143
1145 global_ordinal_type minMyGID_;
1146
1148 global_ordinal_type maxMyGID_;
1149
1152 global_ordinal_type minAllGID_;
1153
1156 global_ordinal_type maxAllGID_;
1157
1164 global_ordinal_type firstContiguousGID_;
1165
1179 global_ordinal_type lastContiguousGID_;
1180
1186 bool uniform_;
1187
1189 bool contiguous_;
1190
1199 bool distributed_;
1200
1230 mutable Kokkos::View<const global_ordinal_type*,
1231 Kokkos::LayoutLeft,
1232 no_uvm_device_type> lgMap_;
1233
1241#ifndef SWIG
1242 mutable Kokkos::View<const global_ordinal_type*,
1243 Kokkos::LayoutLeft,
1244 Kokkos::HostSpace> lgMapHost_;
1245#endif
1246
1249 local_ordinal_type, no_uvm_device_type> global_to_local_table_type;
1250
1263 global_to_local_table_type glMap_;
1264
1267 global_ordinal_type, local_ordinal_type, Kokkos::HostSpace::device_type>
1268 global_to_local_table_host_type;
1269
1275 global_to_local_table_host_type glMapHost_;
1276
1313 mutable Teuchos::RCP<
1314 Directory<
1316 >
1317 > directory_;
1318 }; // Map class
1319
1333 template <class LocalOrdinal, class GlobalOrdinal>
1334 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal> >
1336 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1337
1352 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1353 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
1355 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1356
1357
1365 template <class LocalOrdinal, class GlobalOrdinal>
1366 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal> >
1368 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1369
1376 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1377 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
1379 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1380
1381
1388 template <class LocalOrdinal, class GlobalOrdinal>
1389 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> >
1391 const size_t localNumElements,
1392 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1393
1402 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1403 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> >
1405 const size_t localNumElements,
1406 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1407
1408
1415 template <class LocalOrdinal, class GlobalOrdinal>
1416 Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal> >
1417 createNonContigMap (const Teuchos::ArrayView<const GlobalOrdinal>& elementList,
1418 const Teuchos::RCP<const Teuchos::Comm<int> >& comm);
1419
1427 template <class LocalOrdinal, class GlobalOrdinal, class Node>
1428 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
1429 createNonContigMapWithNode (const Teuchos::ArrayView<const GlobalOrdinal> &elementList,
1430 const Teuchos::RCP<const Teuchos::Comm<int> > &comm);
1431
1439
1444 template<class LocalOrdinal, class GlobalOrdinal, class Node>
1445 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
1447
1453 template<class LocalOrdinal, class GlobalOrdinal, class Node>
1454 Teuchos::RCP< const Map<LocalOrdinal,GlobalOrdinal,Node> >
1456 const ::Tpetra::Details::TieBreak<LocalOrdinal,GlobalOrdinal> & tie_break);
1457
1458} // namespace Tpetra
1459
1460#include "Tpetra_Directory_decl.hpp"
1461
1464template <class LocalOrdinal, class GlobalOrdinal, class Node>
1468
1471template <class LocalOrdinal, class GlobalOrdinal, class Node>
1475
1476
1477#endif // TPETRA_MAP_DECL_HPP
Declaration and definition of the Tpetra::Map class, an implementation detail of Tpetra::Map.
Forward declaration of Tpetra::Directory.
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.
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.
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=(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).
::Tpetra::Details::LocalMap< local_ordinal_type, global_ordinal_type, device_type > local_map_type
Type of the "local" Map.
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.
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.
Map()
Default constructor (that does nothing).
GlobalOrdinal global_ordinal_type
The type of global indices.
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....
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.
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 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?
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.
virtual ~Map()
Destructor (virtual for memory safety of derived classes).
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_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.
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.
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.
local_map_type getLocalMap() const
Get the local Map 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 > > 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...
device_type no_uvm_device_type
The hash will be CudaSpace, not CudaUVMSpace.
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.