15#ifndef TPETRA_MAP_DEF_HPP
16#define TPETRA_MAP_DEF_HPP
23#include "Teuchos_as.hpp"
24#include "Teuchos_TypeNameTraits.hpp"
25#include "Teuchos_CommHelpers.hpp"
27#include "Tpetra_Directory.hpp"
29#include "Tpetra_Details_FixedHashTable.hpp"
34#include "Tpetra_Details_mpiIsInitialized.hpp"
41void checkMapInputArray(
const char ctorName[],
42 const void* indexList,
43 const size_t indexListSize,
44 const Teuchos::Comm<int>*
const comm) {
47 const bool debug = Behavior::debug(
"Map");
50 using Teuchos::outArg;
51 using Teuchos::REDUCE_MIN;
52 using Teuchos::reduceAll;
54 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
55 const bool verbose = Behavior::verbose(
"Map");
56 std::ostringstream lclErrStrm;
59 if (indexListSize != 0 && indexList ==
nullptr) {
62 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
64 << indexListSize <<
" != 0." << endl;
68 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
69 if (gblSuccess != 1) {
70 std::ostringstream gblErrStrm;
71 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
" detected a problem with the input array "
72 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
76 using ::Tpetra::Details::gathervPrint;
79 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
84template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
85void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
86 using LO = LocalOrdinal;
87 using GO = GlobalOrdinal;
88 using exec_space =
typename ViewType::device_type::execution_space;
89 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
90 const LO numLocalElements = entryList.extent(0);
94 typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
100 Kokkos::parallel_reduce(
101 range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
102 GO entry_0 = entryList[0];
103 GO entry_i = entryList[i];
106 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
107 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
108 l_firstCont = entry_0;
110 if (entry_i - entry_0 != i && l_lastCont.val >= i) {
112 l_lastCont.val = i - 1;
113 l_lastCont.loc = entryList[i - 1];
114 }
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
117 l_lastCont.loc = entry_i;
120 Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
123 lastContiguousGID_val = myMinLoc.loc;
124 lastContiguousGID_loc = myMinLoc.val;
131template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
136 , numGlobalElements_(0)
137 , numLocalElements_(0)
147 , distributed_(
false)
154template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
165 using Teuchos::broadcast;
166 using Teuchos::outArg;
167 using Teuchos::REDUCE_MAX;
168 using Teuchos::REDUCE_MIN;
169 using Teuchos::reduceAll;
170 using Teuchos::typeName;
173 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
174 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
176 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
180 std::unique_ptr<std::string>
prefix;
183 comm_.getRawPtr(),
"Map",
funcName);
184 std::ostringstream
os;
186 std::cerr <<
os.str();
204 std::invalid_argument,
exPfx <<
"All processes must "
205 "provide the same number of global elements. Process 0 set "
209 << comm->getRank() <<
" set "
212 "and max values over all processes are "
222 std::invalid_argument,
exPfx <<
"All processes must "
223 "provide the same indexBase argument. Process 0 set "
247 std::invalid_argument,
exPfx <<
"numGlobalElements (= " <<
numGlobalElements <<
") must be nonnegative.");
250 "Tpetra::global_size_t>::invalid(). This version of the "
251 "constructor requires a valid value of numGlobalElements. "
252 "You probably mistook this constructor for the \"contiguous "
253 "nonuniform\" constructor, which can compute the global "
254 "number of elements for you if you set numGlobalElements to "
255 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
258 if (
lOrG == GloballyDistributed) {
299 distributed_ =
false;
302 minAllGID_ = indexBase;
303 maxAllGID_ = indexBase + numGlobalElements - 1;
304 indexBase_ = indexBase;
305 numGlobalElements_ = numGlobalElements;
306 numLocalElements_ = numLocalElements;
307 firstContiguousGID_ = minMyGID_;
308 lastContiguousGID_ = maxMyGID_;
315 std::ostringstream os;
316 os << *prefix <<
"Done" << endl;
317 std::cerr << os.str();
321template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
326 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
332 using Teuchos::broadcast;
333 using Teuchos::outArg;
334 using Teuchos::REDUCE_MAX;
335 using Teuchos::REDUCE_MIN;
336 using Teuchos::REDUCE_SUM;
337 using Teuchos::reduceAll;
341 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
343 "Map(gblNumInds,lclNumInds,indexBase,comm)";
345 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
347 ". Please report this bug to the Tpetra developers.";
351 std::unique_ptr<std::string>
prefix;
354 comm_.getRawPtr(),
"Map",
funcName);
355 std::ostringstream
os;
357 std::cerr <<
os.str();
366 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
367 numGlobalElements, numLocalElements, indexBase, comm);
392 const int numProcs = comm->getSize();
397 numGlobalElements_ = globalSum;
401 TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx <<
"globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum << suffix);
404 numLocalElements_ = numLocalElements;
405 indexBase_ = indexBase;
406 minAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
407 maxAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
408 minMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
409 maxMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
410 firstContiguousGID_ = minMyGID_;
411 lastContiguousGID_ = maxMyGID_;
413 distributed_ = checkIsDist();
419 std::ostringstream os;
420 os << *prefix <<
"Done" << endl;
421 std::cerr << os.str();
425template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const {
439 using Teuchos::broadcast;
440 using Teuchos::outArg;
442 using Teuchos::REDUCE_MAX;
443 using Teuchos::REDUCE_MIN;
444 using Teuchos::REDUCE_SUM;
445 using Teuchos::reduceAll;
448 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
475 "must provide the same number of global elements, even if "
477 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
478 "(which signals that the Map should compute the global "
479 "number of elements). Process 0 set numGlobalElements"
492 std::invalid_argument,
errorMessagePrefix <<
"All processes must provide the same indexBase argument. "
493 "Process 0 set indexBase = "
496 << comm->getRank() <<
" set indexBase=" <<
indexBase <<
". The min and max values over all "
504 std::invalid_argument,
506 "indices over all processes, "
509 "would like this constructor to compute numGlobalElements "
510 "for you, you may set numGlobalElements="
511 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
512 "on input. Please note that this is NOT necessarily -1.");
517template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
527 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
530 using Kokkos::LayoutLeft;
531 using Kokkos::subview;
533 using Kokkos::view_alloc;
534 using Kokkos::WithoutInitializing;
536 using Teuchos::broadcast;
537 using Teuchos::outArg;
539 using Teuchos::REDUCE_MAX;
540 using Teuchos::REDUCE_MIN;
541 using Teuchos::REDUCE_SUM;
542 using Teuchos::reduceAll;
546 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
550 << Teuchos::TypeNameTraits<execution_space>::name()
551 <<
" has not been initialized. "
552 "Please initialize it before creating a Map.")
583 outArg(numGlobalElements_));
612 minMyGID_ = indexBase_;
613 maxMyGID_ = indexBase_;
623 if (numLocalElements_ > 0) {
629 Kokkos::create_mirror_view(Kokkos::HostSpace(),
lgMap);
638 lastContiguousGID_ = firstContiguousGID_ + 1;
648 for (;
i < numLocalElements_; ++
i) {
652 if (lastContiguousGID_ !=
curGid)
break;
659 ++lastContiguousGID_;
661 --lastContiguousGID_;
667 minMyGID_ = firstContiguousGID_;
668 maxMyGID_ = lastContiguousGID_;
679 "Tpetra::Map noncontiguous constructor: "
680 "nonContigGids_host.extent(0) = "
682 <<
" != entryList_host.extent(0) - i = "
685 <<
". Please report this bug to the Tpetra developers.");
695 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
708 for (;
i < numLocalElements_; ++
i) {
710 const LO
curLid =
static_cast<LO
>(
i);
725 Kokkos::deep_copy(execution_space(), lgMap, lgMap_host);
730 lgMapHost_ = lgMap_host;
733 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
734 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
738 firstContiguousGID_ = indexBase_ + 1;
739 lastContiguousGID_ = indexBase_;
764 if (std::numeric_limits<GO>::is_signed) {
767 (
as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
782 distributed_ = (comm_->getSize() > 1 &&
globalDist == 1);
787 distributed_ = checkIsDist();
793 minAllGID_ < indexBase_,
794 std::invalid_argument,
795 "Tpetra::Map constructor (noncontiguous): "
796 "Minimum global ID = "
797 << minAllGID_ <<
" over all process(es) is "
798 "less than the given indexBase = "
799 << indexBase_ <<
".");
805template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
811 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
817 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
819 const bool verbose = Details::Behavior::verbose(
"Map");
820 std::unique_ptr<std::string>
prefix;
822 prefix = Details::createPrefix(
823 comm_.getRawPtr(),
"Map",
funcName);
824 std::ostringstream
os;
826 std::cerr <<
os.str();
841 Kokkos::MemoryUnmanaged>
846 std::ostringstream
os;
848 std::cerr <<
os.str();
852template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
855 const Teuchos::ArrayView<const GlobalOrdinal>&
entryList,
857 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
862 const char*
funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
864 const bool verbose = Details::Behavior::verbose(
"Map");
865 std::unique_ptr<std::string>
prefix;
867 prefix = Details::createPrefix(
868 comm_.getRawPtr(),
"Map",
funcName);
869 std::ostringstream
os;
871 std::cerr <<
os.str();
888 Kokkos::MemoryUnmanaged>
893 std::ostringstream
os;
895 std::cerr <<
os.str();
899template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
902 const Kokkos::View<const GlobalOrdinal*, device_type>&
entryList,
904 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
908 using Kokkos::LayoutLeft;
909 using Kokkos::subview;
911 using Kokkos::view_alloc;
912 using Kokkos::WithoutInitializing;
915 using Teuchos::ArrayView;
917 using Teuchos::broadcast;
918 using Teuchos::outArg;
920 using Teuchos::REDUCE_MAX;
921 using Teuchos::REDUCE_MIN;
922 using Teuchos::REDUCE_SUM;
923 using Teuchos::reduceAll;
924 using Teuchos::typeName;
928 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
930 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
933 std::unique_ptr<std::string>
prefix;
936 comm_.getRawPtr(),
"Map",
funcName);
937 std::ostringstream
os;
939 std::cerr <<
os.str();
946 static_cast<size_t>(
entryList.extent(0)),
978 outArg(numGlobalElements_));
1004 numLocalElements_ = numLocalElements;
1005 indexBase_ = indexBase;
1007 minMyGID_ = indexBase_;
1008 maxMyGID_ = indexBase_;
1018 if (numLocalElements_ > 0) {
1026 Kokkos::deep_copy(
typename device_type::execution_space(),
lgMap,
entryList);
1040 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1041 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1045 firstContiguousGID_ = indexBase_ + 1;
1046 lastContiguousGID_ = indexBase_;
1071 if (std::numeric_limits<GO>::is_signed) {
1073 const GO localDist =
1074 (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
1077 minMaxInput[0] = -minMyGID_;
1078 minMaxInput[1] = maxMyGID_;
1079 minMaxInput[2] = localDist;
1082 minMaxOutput[0] = 0;
1083 minMaxOutput[1] = 0;
1084 minMaxOutput[2] = 0;
1085 reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1086 minAllGID_ = -minMaxOutput[0];
1087 maxAllGID_ = minMaxOutput[1];
1088 const GO globalDist = minMaxOutput[2];
1089 distributed_ = (comm_->getSize() > 1 && globalDist == 1);
1092 reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
1093 reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
1094 distributed_ = checkIsDist();
1097 contiguous_ =
false;
1099 TEUCHOS_TEST_FOR_EXCEPTION(
1100 minAllGID_ < indexBase_,
1101 std::invalid_argument,
1102 "Tpetra::Map constructor (noncontiguous): "
1103 "Minimum global ID = "
1104 << minAllGID_ <<
" over all process(es) is "
1105 "less than the given indexBase = "
1106 << indexBase_ <<
".");
1112 std::ostringstream
os;
1114 std::cerr <<
os.str();
1118template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1120 if (!Kokkos::is_initialized()) {
1121 std::ostringstream
os;
1122 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1123 "Kokkos::finalize() has been called. This is user error! There are "
1124 "two likely causes: "
1126 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1128 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1129 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1130 "or Tpetra::finalize()."
1133 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1136 this->getComm().getRawPtr());
1138 using ::Tpetra::Details::mpiIsFinalized;
1139 using ::Tpetra::Details::mpiIsInitialized;
1140 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1142 Teuchos::RCP<const Teuchos::Comm<int>> comm = this->getComm();
1143 if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
1144 mpiIsInitialized() && mpiIsFinalized()) {
1150 std::ostringstream
os;
1151 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1152 "MPI_Finalize() has been called. This is user error! There are "
1153 "two likely causes: "
1155 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1157 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1158 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1159 "Tpetra::finalize()."
1162 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1172template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1175 getComm().
is_null(), std::logic_error,
1176 "Tpetra::Map::isOneToOne: "
1177 "getComm() returns null. Please report this bug to the Tpetra "
1182 return directory_->isOneToOne(*
this);
1185template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1189 if (isContiguous()) {
1192 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1207template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1212 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
1214 if (isContiguous()) {
1226template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1229 auto const minGI = getMinGlobalIndex();
1230 auto const minLI = getMinLocalIndex();
1231 auto const maxLI = getMaxLocalIndex();
1232 if (isContiguous()) {
1233 for (
size_t i = 0;
i < numEntries;
i++) {
1238 globalIndices[i] = minGI + lclInd;
1246 for (
size_t i = 0; i < numEntries; i++) {
1247 auto lclInd = localIndices[i];
1248 if (lclInd < minLI || lclInd > maxLI) {
1251 globalIndices[i] = lgMapHost_[lclInd];
1257template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1267template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1271 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1274template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1279template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1284template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1289 getMinGlobalIndex(), getMaxGlobalIndex(),
1290 firstContiguousGID_, lastContiguousGID_,
1291 getLocalNumElements(), isContiguous());
1294template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1297 using Teuchos::outArg;
1298 using Teuchos::REDUCE_MIN;
1299 using Teuchos::reduceAll;
1308 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1313 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1317 }
else if (isContiguous() && isUniform() &&
1318 map.isContiguous() &&
map.isUniform()) {
1323 }
else if (!isContiguous() && !
map.isContiguous() &&
1324 lgMap_.extent(0) != 0 &&
map.lgMap_.extent(0) != 0 &&
1325 lgMap_.data() ==
map.lgMap_.data()) {
1340 getGlobalNumElements() !=
map.getGlobalNumElements(), std::logic_error,
1341 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1342 "checked that this condition is true above, but it's false here. "
1343 "Please report this bug to the Tpetra developers.");
1347 (getLocalNumElements() ==
map.getLocalNumElements()) ? 1 : 0;
1354template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1357 using Teuchos::ArrayView;
1373 }
else if (getLocalNumElements() !=
map.getLocalNumElements()) {
1375 }
else if (getMinGlobalIndex() !=
map.getMinGlobalIndex() ||
1376 getMaxGlobalIndex() !=
map.getMaxGlobalIndex()) {
1379 if (isContiguous()) {
1380 if (
map.isContiguous()) {
1384 !this->isContiguous() ||
map.isContiguous(), std::logic_error,
1385 "Tpetra::Map::locallySameAs: BUG");
1387 const GO
minLhsGid = this->getMinGlobalIndex();
1397 }
else if (
map.isContiguous()) {
1399 this->isContiguous() || !
map.isContiguous(), std::logic_error,
1400 "Tpetra::Map::locallySameAs: BUG");
1411 }
else if (this->lgMap_.data() ==
map.lgMap_.data()) {
1414 return this->getLocalNumElements() ==
map.getLocalNumElements();
1416 if (this->getLocalNumElements() !=
map.getLocalNumElements()) {
1419 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1425 Kokkos::parallel_reduce(
1426 "Tpetra::Map::locallySameAs",
1427 range_type(0, this->getLocalNumElements()),
1440template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1451 auto lmap2 = this->getLocalMap();
1461 if (
lmap1.isContiguous() &&
lmap2.isContiguous()) {
1463 return ((
lmap1.getMinGlobalIndex() ==
lmap2.getMinGlobalIndex()) &&
1464 (
lmap1.getMaxGlobalIndex() <=
lmap2.getMaxGlobalIndex()));
1467 if (
lmap1.getMinGlobalIndex() <
lmap2.getMinGlobalIndex() ||
1468 lmap1.getMaxGlobalIndex() >
lmap2.getMaxGlobalIndex()) {
1476 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1480 Kokkos::parallel_reduce(
1491template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1494 using Teuchos::outArg;
1495 using Teuchos::REDUCE_MIN;
1496 using Teuchos::reduceAll;
1505 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1510 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1514 }
else if (getMinAllGlobalIndex() !=
map.getMinAllGlobalIndex() ||
1515 getMaxAllGlobalIndex() !=
map.getMaxAllGlobalIndex() ||
1516 getIndexBase() !=
map.getIndexBase()) {
1520 }
else if (isDistributed() !=
map.isDistributed()) {
1524 }
else if (isContiguous() && isUniform() &&
1525 map.isContiguous() &&
map.isUniform()) {
1554template <
class LO,
class GO,
class DT>
1557 FillLgMap(
const Kokkos::View<GO*, DT>&
lgMap,
1561 Kokkos::RangePolicy<LO, typename DT::execution_space>
1562 range(
static_cast<LO
>(0),
static_cast<LO
>(
lgMap.size()));
1563 Kokkos::parallel_for(
range, *
this);
1566 KOKKOS_INLINE_FUNCTION
void operator()(
const LO& lid)
const {
1567 lgMap_(lid) = startGid_ +
static_cast<GO
>(lid);
1571 const Kokkos::View<GO*, DT> lgMap_;
1577template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1578typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
1584 using lg_view_type =
typename const_lg_view_type::non_const_type;
1588 std::unique_ptr<std::string>
prefix;
1591 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1592 std::ostringstream
os;
1594 std::cerr <<
os.str();
1601 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1605 std::ostringstream
os;
1607 std::cerr <<
os.str();
1613 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1614 "mapping (lgMap_) should have been set up already for a "
1615 "noncontiguous Map. Please report this bug to the Tpetra "
1618 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1620 using Kokkos::view_alloc;
1621 using Kokkos::WithoutInitializing;
1624 std::ostringstream
os;
1626 std::cerr <<
os.str();
1631 std::ostringstream
os;
1633 std::cerr <<
os.str();
1636 auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(),
lgMap);
1653 std::ostringstream
os;
1655 std::cerr <<
os.str();
1660template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1661typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
1667 using lg_view_type =
typename const_lg_view_type::non_const_type;
1671 std::unique_ptr<std::string>
prefix;
1674 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1675 std::ostringstream
os;
1677 std::cerr <<
os.str();
1684 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1688 std::ostringstream
os;
1690 std::cerr <<
os.str();
1696 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1697 "mapping (lgMap_) should have been set up already for a "
1698 "noncontiguous Map. Please report this bug to the Tpetra "
1701 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1703 using Kokkos::view_alloc;
1704 using Kokkos::WithoutInitializing;
1707 std::ostringstream
os;
1709 std::cerr <<
os.str();
1718 std::ostringstream
os;
1720 std::cerr <<
os.str();
1725template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1726Teuchos::ArrayView<const GlobalOrdinal>
1733 (
void)this->getMyGlobalIndices();
1741 return Teuchos::ArrayView<const GO>(
1743 lgMapHost_.extent(0),
1744 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1747template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1749 return distributed_;
1752template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1754 using Teuchos::TypeNameTraits;
1755 std::ostringstream
os;
1757 os <<
"Tpetra::Map: {"
1764 os <<
", Global number of entries: " << getGlobalNumElements()
1765 <<
", Number of processes: " << getComm()->getSize()
1766 <<
", Uniform: " << (isUniform() ?
"true" :
"false")
1767 <<
", Contiguous: " << (isContiguous() ?
"true" :
"false")
1768 <<
", Distributed: " << (isDistributed() ?
"true" :
"false")
1777template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1781 using LO = local_ordinal_type;
1785 if (
vl < Teuchos::VERB_HIGH) {
1786 return std::string();
1788 auto outStringP = Teuchos::rcp(
new std::ostringstream());
1789 Teuchos::RCP<Teuchos::FancyOStream> outp =
1790 Teuchos::getFancyOStream(outStringP);
1791 Teuchos::FancyOStream& out = *outp;
1793 auto comm = this->getComm();
1794 const int myRank = comm->getRank();
1795 const int numProcs = comm->getSize();
1796 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1797 Teuchos::OSTab tab1(out);
1799 const LO numEnt =
static_cast<LO
>(this->getLocalNumElements());
1800 out <<
"My number of entries: " << numEnt << endl
1801 <<
"My minimum global index: " << this->getMinGlobalIndex() << endl
1802 <<
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
1804 if (vl == Teuchos::VERB_EXTREME) {
1805 out <<
"My global indices: [";
1806 const LO minLclInd = this->getMinLocalIndex();
1807 for (LO k = 0; k < numEnt; ++k) {
1808 out << minLclInd + this->getGlobalElement(k);
1809 if (k + 1 < numEnt) {
1817 return outStringP->str();
1820template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1823 const Teuchos::EVerbosityLevel
verbLevel)
const {
1825 using Teuchos::TypeNameTraits;
1826 using Teuchos::VERB_DEFAULT;
1827 using Teuchos::VERB_HIGH;
1828 using Teuchos::VERB_LOW;
1829 using Teuchos::VERB_NONE;
1832 const Teuchos::EVerbosityLevel
vl =
1842 auto comm = this->getComm();
1843 if (comm.is_null()) {
1846 const int myRank = comm->getRank();
1847 const int numProcs = comm->getSize();
1856 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
1862 tab0 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1863 out <<
"\"Tpetra::Map\":" <<
endl;
1864 tab1 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1866 out <<
"Template parameters:" <<
endl;
1874 out <<
"Label: \"" << label <<
"\"" <<
endl;
1876 out <<
"Global number of entries: " << getGlobalNumElements() <<
endl
1877 <<
"Minimum global index: " << getMinAllGlobalIndex() <<
endl
1878 <<
"Maximum global index: " << getMaxAllGlobalIndex() <<
endl
1879 <<
"Index base: " << getIndexBase() <<
endl
1881 <<
"Uniform: " << (isUniform() ?
"true" :
"false") <<
endl
1882 <<
"Contiguous: " << (isContiguous() ?
"true" :
"false") <<
endl
1883 <<
"Distributed: " << (isDistributed() ?
"true" :
"false") <<
endl;
1888 const std::string
lclStr = this->localDescribeToString(
vl);
1893template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1894Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1912 return Teuchos::null;
1913 }
else if (
newComm->getSize() == 1) {
1926 newMap->indexBase_ = this->indexBase_;
1927 newMap->numGlobalElements_ = this->numLocalElements_;
1928 newMap->numLocalElements_ = this->numLocalElements_;
1929 newMap->minMyGID_ = this->minMyGID_;
1930 newMap->maxMyGID_ = this->maxMyGID_;
1931 newMap->minAllGID_ = this->minMyGID_;
1932 newMap->maxAllGID_ = this->maxMyGID_;
1933 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1934 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1937 newMap->uniform_ = this->uniform_;
1938 newMap->contiguous_ = this->contiguous_;
1941 newMap->distributed_ =
false;
1942 newMap->lgMap_ = this->lgMap_;
1943 newMap->lgMapHost_ = this->lgMapHost_;
1944 newMap->glMap_ = this->glMap_;
1945 newMap->glMapHost_ = this->glMapHost_;
1965 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
1981 auto lgMap = this->getMyGlobalIndices();
1983 typename std::decay<
decltype(
lgMap.extent(0))>::type;
1985 static_cast<size_type
>(this->getLocalNumElements());
1986 using Teuchos::TypeNameTraits;
1988 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
1992 <<
this->getLocalNumElements() <<
". The latter, upon being "
1993 "cast to size_type = "
1996 <<
lclNumInds <<
". Please report this bug to the Tpetra "
1999 Teuchos::ArrayView<const GO>
lgMap = this->getLocalElementList();
2002 const GO
indexBase = this->getIndexBase();
2009template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2010Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
2013 using Teuchos::Comm;
2014 using Teuchos::null;
2015 using Teuchos::outArg;
2018 using Teuchos::REDUCE_MIN;
2019 using Teuchos::reduceAll;
2026 const int color = (numLocalElements_ == 0) ? 0 : 1;
2043 map->indexBase_ = indexBase_;
2044 map->numGlobalElements_ = numGlobalElements_;
2045 map->numLocalElements_ = numLocalElements_;
2046 map->minMyGID_ = minMyGID_;
2047 map->maxMyGID_ = maxMyGID_;
2048 map->minAllGID_ = minAllGID_;
2049 map->maxAllGID_ = maxAllGID_;
2050 map->firstContiguousGID_ = firstContiguousGID_;
2051 map->lastContiguousGID_ = lastContiguousGID_;
2055 map->uniform_ = uniform_;
2056 map->contiguous_ = contiguous_;
2071 if (!distributed_ ||
newComm->getSize() == 1) {
2072 map->distributed_ =
false;
2074 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2080 map->lgMap_ = lgMap_;
2081 map->lgMapHost_ = lgMapHost_;
2082 map->glMap_ = glMap_;
2083 map->glMapHost_ = glMapHost_;
2100template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2103 directory_.is_null(), std::logic_error,
2104 "Tpetra::Map::setupDirectory: "
2105 "The Directory is null. "
2106 "Please report this bug to the Tpetra developers.");
2110 if (!directory_->initialized()) {
2111 directory_->initialize(*
this);
2115template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2119 const Teuchos::ArrayView<int>&
PIDs,
2120 const Teuchos::ArrayView<LocalOrdinal>&
LIDs)
const {
2123 using Tpetra::Details::OrdinalTraits;
2124 using size_type = Teuchos::ArrayView<int>::size_type;
2128 std::unique_ptr<std::string>
prefix;
2131 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2132 std::ostringstream
os;
2136 std::cerr <<
os.str();
2145 if (getGlobalNumElements() == 0) {
2146 if (
GIDs.size() == 0) {
2148 std::ostringstream
os;
2149 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2150 std::cerr <<
os.str();
2155 std::ostringstream
os;
2156 os << *
prefix <<
"Done: Map is empty on all processes, "
2157 "so all output PIDs & LIDs are invalid (-1)."
2159 std::cerr <<
os.str();
2161 for (size_type
k = 0;
k <
PIDs.size(); ++
k) {
2164 for (size_type
k = 0;
k <
LIDs.size(); ++
k) {
2176 std::ostringstream
os;
2178 std::cerr <<
os.str();
2182 std::ostringstream
os;
2183 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2184 std::cerr <<
os.str();
2187 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs,
LIDs);
2189 std::ostringstream
os;
2190 os << *
prefix <<
"Done; getDirectoryEntries returned "
2197 std::cerr <<
os.str();
2202template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2206 const Teuchos::ArrayView<int>&
PIDs)
const {
2212 std::unique_ptr<std::string>
prefix;
2215 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2216 std::ostringstream
os;
2220 std::cerr <<
os.str();
2223 if (getGlobalNumElements() == 0) {
2224 if (
GIDs.size() == 0) {
2226 std::ostringstream
os;
2227 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2228 std::cerr <<
os.str();
2233 std::ostringstream
os;
2234 os << *
prefix <<
"Done: Map is empty on all processes, "
2235 "so all output PIDs are invalid (-1)."
2237 std::cerr <<
os.str();
2239 for (Teuchos::ArrayView<int>::size_type
k = 0;
k <
PIDs.size(); ++
k) {
2240 PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2251 std::ostringstream
os;
2253 std::cerr <<
os.str();
2257 std::ostringstream
os;
2258 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2259 std::cerr <<
os.str();
2262 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs);
2264 std::ostringstream
os;
2265 os << *
prefix <<
"Done; getDirectoryEntries returned "
2270 std::cerr <<
os.str();
2275template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2277 using exec_space =
typename Node::device_type::execution_space;
2278 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2284 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2297template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2298Teuchos::RCP<const Teuchos::Comm<int>>
2303template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2308 using Teuchos::outArg;
2309 using Teuchos::REDUCE_MIN;
2310 using Teuchos::reduceAll;
2313 std::unique_ptr<std::string>
prefix;
2316 comm_.getRawPtr(),
"Map",
"checkIsDist");
2317 std::ostringstream
os;
2319 std::cerr <<
os.str();
2322 bool global =
false;
2323 if (comm_->getSize() > 1) {
2327 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2340 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2341 if (allLocalRep != 1) {
2351 std::ostringstream os;
2352 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2354 std::cerr << os.str();
2361template <
class LocalOrdinal,
class GlobalOrdinal>
2362Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2364 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2365 typedef LocalOrdinal LO;
2366 typedef GlobalOrdinal GO;
2367 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2368 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2371template <
class LocalOrdinal,
class GlobalOrdinal>
2372Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2374 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2375 typedef LocalOrdinal LO;
2376 typedef GlobalOrdinal GO;
2377 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2378 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2381template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2382Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2384 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2387 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2389 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2392template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2393Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2395 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2399 const GlobalOrdinal indexBase = 0;
2402 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2405template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2406Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2408 const size_t localNumElements,
2409 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2412 const GlobalOrdinal indexBase = 0;
2414 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2417template <
class LocalOrdinal,
class GlobalOrdinal>
2418Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2420 const size_t localNumElements,
2421 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2422 typedef LocalOrdinal LO;
2423 typedef GlobalOrdinal GO;
2429template <
class LocalOrdinal,
class GlobalOrdinal>
2430Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2432 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2433 typedef LocalOrdinal LO;
2434 typedef GlobalOrdinal GO;
2440template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2441Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2443 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2447 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2451 const GlobalOrdinal indexBase = 0;
2453 return rcp(
new map_type(INV, elementList, indexBase, comm));
2456template <
class LO,
class GO,
class NT>
2457Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2459 using Details::verbosePrintArray;
2462 using Teuchos::Array;
2463 using Teuchos::ArrayView;
2469 const bool verbose = Details::Behavior::verbose(
"Map");
2470 std::unique_ptr<std::string> prefix;
2472 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2473 prefix = Details::createPrefix(
2474 comm.getRawPtr(),
"createOneToOne(Map)");
2475 std::ostringstream os;
2476 os << *prefix <<
"Start" << endl;
2479 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2480 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2481 const int myRank = M->getComm()->getRank();
2487 if (!M->isDistributed()) {
2494 const GST numGlobalEntries = M->getGlobalNumElements();
2495 if (M->isContiguous()) {
2496 const size_t numLocalEntries =
2497 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2499 std::ostringstream os;
2500 os << *prefix <<
"Input is locally replicated & contiguous; "
2502 << numLocalEntries << endl;
2506 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2507 M->getIndexBase(), M->getComm()));
2509 std::ostringstream os;
2510 os << *prefix <<
"Done" << endl;
2516 std::ostringstream os;
2517 os << *prefix <<
"Input is locally replicated & noncontiguous"
2521 ArrayView<const GO> myGids =
2522 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2524 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2527 std::ostringstream os;
2528 os << *prefix <<
"Done" << endl;
2533 }
else if (M->isContiguous()) {
2535 std::ostringstream os;
2536 os << *prefix <<
"Input is distributed & contiguous" << endl;
2544 std::ostringstream os;
2545 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2549 const size_t numMyElems = M->getLocalNumElements();
2550 ArrayView<const GO> myElems = M->getLocalElementList();
2551 Array<int> owner_procs_vec(numMyElems);
2554 std::ostringstream os;
2555 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2560 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2562 std::ostringstream os;
2563 os << *prefix <<
"getDirectoryEntries result: ";
2569 Array<GO> myOwned_vec(numMyElems);
2570 size_t numMyOwnedElems = 0;
2571 for (
size_t i = 0; i < numMyElems; ++i) {
2572 const GO GID = myElems[i];
2573 const int owner = owner_procs_vec[i];
2575 if (myRank == owner) {
2576 myOwned_vec[numMyOwnedElems++] = GID;
2579 myOwned_vec.resize(numMyOwnedElems);
2582 std::ostringstream os;
2583 os << *prefix <<
"Create Map: ";
2588 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2589 M->getIndexBase(), M->getComm()));
2591 std::ostringstream os;
2592 os << *prefix <<
"Done" << endl;
2599template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2600Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2603 using Details::Behavior;
2604 using Details::verbosePrintArray;
2607 using Teuchos::Array;
2608 using Teuchos::ArrayView;
2611 using Teuchos::toString;
2612 using LO = LocalOrdinal;
2613 using GO = GlobalOrdinal;
2616 const bool verbose = Behavior::verbose(
"Map");
2617 std::unique_ptr<std::string> prefix;
2619 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2620 prefix = Details::createPrefix(
2621 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2622 std::ostringstream os;
2623 os << *prefix <<
"Start" << endl;
2626 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2633 std::ostringstream os;
2634 os << *prefix <<
"Initialize Directory" << endl;
2637 directory.initialize(*M, tie_break);
2639 std::ostringstream os;
2640 os << *prefix <<
"Done initializing Directory" << endl;
2643 size_t numMyElems = M->getLocalNumElements();
2644 ArrayView<const GO> myElems = M->getLocalElementList();
2645 Array<int> owner_procs_vec(numMyElems);
2647 std::ostringstream os;
2648 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2653 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2655 std::ostringstream os;
2656 os << *prefix <<
"getDirectoryEntries result: ";
2662 const int myRank = M->getComm()->getRank();
2663 Array<GO> myOwned_vec(numMyElems);
2664 size_t numMyOwnedElems = 0;
2665 for (
size_t i = 0; i < numMyElems; ++i) {
2666 const GO GID = myElems[i];
2667 const int owner = owner_procs_vec[i];
2668 if (myRank == owner) {
2669 myOwned_vec[numMyOwnedElems++] = GID;
2672 myOwned_vec.resize(numMyOwnedElems);
2677 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2679 std::ostringstream os;
2680 os << *prefix <<
"Create Map: ";
2685 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2688 std::ostringstream os;
2689 os << *prefix <<
"Done" << endl;
2703#define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2705 template class Map<LO, GO, NODE>; \
2707 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2708 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2709 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2711 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2712 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2713 const size_t localNumElements, \
2714 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2716 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2717 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2718 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2720 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2721 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2722 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2724 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2725 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2727 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2728 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2729 const Tpetra::Details::TieBreak<LO, GO>& tie_break);
2732#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2733 template Teuchos::RCP<const Map<LO, GO>> \
2734 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2736 template Teuchos::RCP<const Map<LO, GO>> \
2737 createContigMap<LO, GO>(global_size_t, size_t, \
2738 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2740 template Teuchos::RCP<const Map<LO, GO>> \
2741 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2742 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2744 template Teuchos::RCP<const Map<LO, GO>> \
2745 createUniformContigMap<LO, GO>(const global_size_t, \
2746 const Teuchos::RCP<const Teuchos::Comm<int>>&);
Functions for initializing and finalizing Tpetra.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
Declaration of a function that prints strings from each process.
Declaration of Tpetra::Details::initializeKokkos.
Declaration of Tpetra::Details::printOnce.
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
Description of Tpetra's behavior.
static void reject_unrecognized_env_vars()
Search the environment for TPETRA_ variables and reject unrecognized ones.
static bool debug()
Whether Tpetra is in debug mode.
static bool verbose()
Whether Tpetra is in verbose mode.
static size_t verbosePrintCountThreshold()
Number of entries below which arrays, lists, etc. will be printed in debug mode.
"Local" part of Map suitable for Kokkos kernels.
Interface for breaking ties in ownership.
Implement mapping from global ID to process ID and local ID.
A parallel distribution of indices over processes.
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.
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.
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.
typename device_type::execution_space execution_space
The Kokkos execution space.
LO 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.
bool isCompatible(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is compatible with this Map.
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).
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map's device.
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.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
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_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 Node::device_type device_type
This class' Kokkos::Device specialization.
Implementation details of Tpetra.
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x.
void printOnce(std::ostream &out, const std::string &s, const Teuchos::Comm< int > *comm)
Print on one process of the given communicator, or at least try to do so (if MPI is not initialized).
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
bool congruent(const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
Whether the two communicators are congruent.
void initializeKokkos()
Initialize Kokkos, using command-line arguments (if any) given to Teuchos::GlobalMPISession.
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator,...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
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.
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.
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.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
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...
size_t global_size_t
Global size_t object.
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,...
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.
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 ...
LocalGlobal
Enum for local versus global allocation of Map entries.
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...