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"
42inline void checkMapInputArray(
const char ctorName[],
43 const void* indexList,
44 const size_t indexListSize,
45 const Teuchos::Comm<int>*
const comm) {
48 const bool debug = Behavior::debug(
"Map");
51 using Teuchos::outArg;
52 using Teuchos::REDUCE_MIN;
53 using Teuchos::reduceAll;
55 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
56 const bool verbose = Behavior::verbose(
"Map");
57 std::ostringstream lclErrStrm;
60 if (indexListSize != 0 && indexList ==
nullptr) {
63 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
65 << indexListSize <<
" != 0." << endl;
69 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
70 if (gblSuccess != 1) {
71 std::ostringstream gblErrStrm;
72 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
" detected a problem with the input array "
73 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
77 using ::Tpetra::Details::gathervPrint;
80 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
85template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
86void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
87 using LO = LocalOrdinal;
88 using GO = GlobalOrdinal;
89 using exec_space =
typename ViewType::device_type::execution_space;
90 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
91 const LO numLocalElements = entryList.extent(0);
95 typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
101 Kokkos::parallel_reduce(
102 range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
103 GO entry_0 = entryList[0];
104 GO entry_i = entryList[i];
107 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
108 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
109 l_firstCont = entry_0;
111 if (entry_i - entry_0 != i && l_lastCont.val >= i) {
113 l_lastCont.val = i - 1;
114 l_lastCont.loc = entryList[i - 1];
115 }
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
118 l_lastCont.loc = entry_i;
121 Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
124 lastContiguousGID_val = myMinLoc.loc;
125 lastContiguousGID_loc = myMinLoc.val;
130template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
135 , numGlobalElements_(0)
136 , numLocalElements_(0)
146 , distributed_(
false)
153template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
157 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
164 using Teuchos::broadcast;
165 using Teuchos::outArg;
166 using Teuchos::REDUCE_MAX;
167 using Teuchos::REDUCE_MIN;
168 using Teuchos::reduceAll;
169 using Teuchos::typeName;
172 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
173 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
175 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
179 std::unique_ptr<std::string>
prefix;
182 comm_.getRawPtr(),
"Map",
funcName);
183 std::ostringstream
os;
185 std::cerr <<
os.str();
203 std::invalid_argument,
exPfx <<
"All processes must "
204 "provide the same number of global elements. Process 0 set "
208 << comm->getRank() <<
" set "
211 "and max values over all processes are "
221 std::invalid_argument,
exPfx <<
"All processes must "
222 "provide the same indexBase argument. Process 0 set "
246 std::invalid_argument,
exPfx <<
"numGlobalElements (= " <<
numGlobalElements <<
") must be nonnegative.");
249 "Tpetra::global_size_t>::invalid(). This version of the "
250 "constructor requires a valid value of numGlobalElements. "
251 "You probably mistook this constructor for the \"contiguous "
252 "nonuniform\" constructor, which can compute the global "
253 "number of elements for you if you set numGlobalElements to "
254 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
257 if (
lOrG == GloballyDistributed) {
298 distributed_ =
false;
306 firstContiguousGID_ = minMyGID_;
307 lastContiguousGID_ = maxMyGID_;
314 std::ostringstream
os;
316 std::cerr <<
os.str();
320template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
325 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
331 using Teuchos::broadcast;
332 using Teuchos::outArg;
333 using Teuchos::REDUCE_MAX;
334 using Teuchos::REDUCE_MIN;
335 using Teuchos::REDUCE_SUM;
336 using Teuchos::reduceAll;
340 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
342 "Map(gblNumInds,lclNumInds,indexBase,comm)";
344 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
346 ". Please report this bug to the Tpetra developers.";
350 std::unique_ptr<std::string>
prefix;
353 comm_.getRawPtr(),
"Map",
funcName);
354 std::ostringstream
os;
356 std::cerr <<
os.str();
365 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
366 numGlobalElements, numLocalElements, indexBase, comm);
391 const int numProcs = comm->getSize();
396 numGlobalElements_ = globalSum;
400 TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx <<
"globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum << suffix);
403 numLocalElements_ = numLocalElements;
404 indexBase_ = indexBase;
405 minAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
406 maxAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
407 minMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
408 maxMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
409 firstContiguousGID_ = minMyGID_;
410 lastContiguousGID_ = maxMyGID_;
412 distributed_ = checkIsDist();
418 std::ostringstream os;
419 os << *prefix <<
"Done" << endl;
420 std::cerr << os.str();
424template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
432 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const {
438 using Teuchos::broadcast;
439 using Teuchos::outArg;
441 using Teuchos::REDUCE_MAX;
442 using Teuchos::REDUCE_MIN;
443 using Teuchos::REDUCE_SUM;
444 using Teuchos::reduceAll;
447 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
474 "must provide the same number of global elements, even if "
476 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
477 "(which signals that the Map should compute the global "
478 "number of elements). Process 0 set numGlobalElements"
491 std::invalid_argument,
errorMessagePrefix <<
"All processes must provide the same indexBase argument. "
492 "Process 0 set indexBase = "
495 << comm->getRank() <<
" set indexBase=" <<
indexBase <<
". The min and max values over all "
503 std::invalid_argument,
505 "indices over all processes, "
508 "would like this constructor to compute numGlobalElements "
509 "for you, you may set numGlobalElements="
510 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
511 "on input. Please note that this is NOT necessarily -1.");
516template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
526 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
529 using Kokkos::LayoutLeft;
530 using Kokkos::subview;
532 using Kokkos::view_alloc;
533 using Kokkos::WithoutInitializing;
535 using Teuchos::broadcast;
536 using Teuchos::outArg;
538 using Teuchos::REDUCE_MAX;
539 using Teuchos::REDUCE_MIN;
540 using Teuchos::REDUCE_SUM;
541 using Teuchos::reduceAll;
545 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
549 << Teuchos::TypeNameTraits<execution_space>::name()
550 <<
" has not been initialized. "
551 "Please initialize it before creating a Map.")
582 outArg(numGlobalElements_));
611 minMyGID_ = indexBase_;
612 maxMyGID_ = indexBase_;
622 if (numLocalElements_ > 0) {
628 Kokkos::create_mirror_view(Kokkos::HostSpace(),
lgMap);
637 lastContiguousGID_ = firstContiguousGID_ + 1;
647 for (;
i < numLocalElements_; ++
i) {
651 if (lastContiguousGID_ !=
curGid)
break;
658 ++lastContiguousGID_;
660 --lastContiguousGID_;
666 minMyGID_ = firstContiguousGID_;
667 maxMyGID_ = lastContiguousGID_;
678 "Tpetra::Map noncontiguous constructor: "
679 "nonContigGids_host.extent(0) = "
681 <<
" != entryList_host.extent(0) - i = "
684 <<
". Please report this bug to the Tpetra developers.");
694 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
707 for (;
i < numLocalElements_; ++
i) {
724 Kokkos::deep_copy(execution_space(), lgMap, lgMap_host);
729 lgMapHost_ = lgMap_host;
732 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
733 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
737 firstContiguousGID_ = indexBase_ + 1;
738 lastContiguousGID_ = indexBase_;
763 if (std::numeric_limits<GO>::is_signed) {
766 (
as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
781 distributed_ = (comm_->getSize() > 1 &&
globalDist == 1);
786 distributed_ = checkIsDist();
792 minAllGID_ < indexBase_,
793 std::invalid_argument,
794 "Tpetra::Map constructor (noncontiguous): "
795 "Minimum global ID = "
796 << minAllGID_ <<
" over all process(es) is "
797 "less than the given indexBase = "
798 << indexBase_ <<
".");
804template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
810 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
816 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
818 const bool verbose = Details::Behavior::verbose(
"Map");
819 std::unique_ptr<std::string>
prefix;
821 prefix = Details::createPrefix(
822 comm_.getRawPtr(),
"Map",
funcName);
823 std::ostringstream
os;
825 std::cerr <<
os.str();
830 Impl::checkMapInputArray(
"(GST, const GO[], LO, GO, comm)",
840 Kokkos::MemoryUnmanaged>
845 std::ostringstream
os;
847 std::cerr <<
os.str();
851template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
854 const Teuchos::ArrayView<const GlobalOrdinal>&
entryList,
856 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
861 const char*
funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
863 const bool verbose = Details::Behavior::verbose(
"Map");
864 std::unique_ptr<std::string>
prefix;
866 prefix = Details::createPrefix(
867 comm_.getRawPtr(),
"Map",
funcName);
868 std::ostringstream
os;
870 std::cerr <<
os.str();
876 Impl::checkMapInputArray(
"(GST, ArrayView, GO, comm)",
887 Kokkos::MemoryUnmanaged>
892 std::ostringstream
os;
894 std::cerr <<
os.str();
898template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
901 const Kokkos::View<const GlobalOrdinal*, device_type>&
entryList,
903 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
907 using Kokkos::LayoutLeft;
908 using Kokkos::subview;
910 using Kokkos::view_alloc;
911 using Kokkos::WithoutInitializing;
914 using Teuchos::ArrayView;
916 using Teuchos::broadcast;
917 using Teuchos::outArg;
919 using Teuchos::REDUCE_MAX;
920 using Teuchos::REDUCE_MIN;
921 using Teuchos::REDUCE_SUM;
922 using Teuchos::reduceAll;
923 using Teuchos::typeName;
927 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
929 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
932 std::unique_ptr<std::string>
prefix;
935 comm_.getRawPtr(),
"Map",
funcName);
936 std::ostringstream
os;
938 std::cerr <<
os.str();
943 Impl::checkMapInputArray(
"(GST, Kokkos::View, GO, comm)",
945 static_cast<size_t>(
entryList.extent(0)),
977 outArg(numGlobalElements_));
1003 numLocalElements_ = numLocalElements;
1004 indexBase_ = indexBase;
1006 minMyGID_ = indexBase_;
1007 maxMyGID_ = indexBase_;
1017 if (numLocalElements_ > 0) {
1025 Kokkos::deep_copy(
typename device_type::execution_space(),
lgMap,
entryList);
1039 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1040 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1044 firstContiguousGID_ = indexBase_ + 1;
1045 lastContiguousGID_ = indexBase_;
1070 if (std::numeric_limits<GO>::is_signed) {
1072 const GO localDist =
1073 (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
1076 minMaxInput[0] = -minMyGID_;
1077 minMaxInput[1] = maxMyGID_;
1078 minMaxInput[2] = localDist;
1081 minMaxOutput[0] = 0;
1082 minMaxOutput[1] = 0;
1083 minMaxOutput[2] = 0;
1084 reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1085 minAllGID_ = -minMaxOutput[0];
1086 maxAllGID_ = minMaxOutput[1];
1087 const GO globalDist = minMaxOutput[2];
1088 distributed_ = (comm_->getSize() > 1 && globalDist == 1);
1091 reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
1092 reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
1093 distributed_ = checkIsDist();
1096 contiguous_ =
false;
1098 TEUCHOS_TEST_FOR_EXCEPTION(
1099 minAllGID_ < indexBase_,
1100 std::invalid_argument,
1101 "Tpetra::Map constructor (noncontiguous): "
1102 "Minimum global ID = "
1103 << minAllGID_ <<
" over all process(es) is "
1104 "less than the given indexBase = "
1105 << indexBase_ <<
".");
1111 std::ostringstream
os;
1113 std::cerr <<
os.str();
1117template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1119 if (!Kokkos::is_initialized()) {
1120 std::ostringstream
os;
1121 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1122 "Kokkos::finalize() has been called. This is user error! There are "
1123 "two likely causes: "
1125 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1127 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1128 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1129 "or Tpetra::finalize()."
1132 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1135 this->getComm().getRawPtr());
1137 using ::Tpetra::Details::mpiIsFinalized;
1138 using ::Tpetra::Details::mpiIsInitialized;
1139 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1141 Teuchos::RCP<const Teuchos::Comm<int>> comm = this->getComm();
1142 if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
1143 mpiIsInitialized() && mpiIsFinalized()) {
1149 std::ostringstream
os;
1150 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1151 "MPI_Finalize() has been called. This is user error! There are "
1152 "two likely causes: "
1154 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1156 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1157 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1158 "Tpetra::finalize()."
1161 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1171template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1174 getComm().
is_null(), std::logic_error,
1175 "Tpetra::Map::isOneToOne: "
1176 "getComm() returns null. Please report this bug to the Tpetra "
1181 return directory_->isOneToOne(*
this);
1184template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1188 if (isContiguous()) {
1191 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1206template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1211 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
1213 if (isContiguous()) {
1225template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1228 auto const minGI = getMinGlobalIndex();
1229 auto const minLI = getMinLocalIndex();
1230 auto const maxLI = getMaxLocalIndex();
1231 if (isContiguous()) {
1232 for (
size_t i = 0;
i < numEntries;
i++) {
1237 globalIndices[i] = minGI + lclInd;
1245 for (
size_t i = 0; i < numEntries; i++) {
1246 auto lclInd = localIndices[i];
1247 if (lclInd < minLI || lclInd > maxLI) {
1250 globalIndices[i] = lgMapHost_[lclInd];
1256template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1266template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1270 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1273template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1278template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1283template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1288 getMinGlobalIndex(), getMaxGlobalIndex(),
1289 firstContiguousGID_, lastContiguousGID_,
1290 getLocalNumElements(), isContiguous());
1293template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1296 using Teuchos::outArg;
1297 using Teuchos::REDUCE_MIN;
1298 using Teuchos::reduceAll;
1307 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1312 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1316 }
else if (isContiguous() && isUniform() &&
1317 map.isContiguous() &&
map.isUniform()) {
1322 }
else if (!isContiguous() && !
map.isContiguous() &&
1323 lgMap_.extent(0) != 0 &&
map.lgMap_.extent(0) != 0 &&
1324 lgMap_.data() ==
map.lgMap_.data()) {
1339 getGlobalNumElements() !=
map.getGlobalNumElements(), std::logic_error,
1340 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1341 "checked that this condition is true above, but it's false here. "
1342 "Please report this bug to the Tpetra developers.");
1346 (getLocalNumElements() ==
map.getLocalNumElements()) ? 1 : 0;
1353template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1356 using Teuchos::ArrayView;
1372 }
else if (getLocalNumElements() !=
map.getLocalNumElements()) {
1374 }
else if (getMinGlobalIndex() !=
map.getMinGlobalIndex() ||
1375 getMaxGlobalIndex() !=
map.getMaxGlobalIndex()) {
1378 if (isContiguous()) {
1379 if (
map.isContiguous()) {
1383 !this->isContiguous() ||
map.isContiguous(), std::logic_error,
1384 "Tpetra::Map::locallySameAs: BUG");
1386 const GO
minLhsGid = this->getMinGlobalIndex();
1396 }
else if (
map.isContiguous()) {
1398 this->isContiguous() || !
map.isContiguous(), std::logic_error,
1399 "Tpetra::Map::locallySameAs: BUG");
1410 }
else if (this->lgMap_.data() ==
map.lgMap_.data()) {
1413 return this->getLocalNumElements() ==
map.getLocalNumElements();
1415 if (this->getLocalNumElements() !=
map.getLocalNumElements()) {
1418 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1424 Kokkos::parallel_reduce(
1425 "Tpetra::Map::locallySameAs",
1426 range_type(0, this->getLocalNumElements()),
1439template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1450 auto lmap2 = this->getLocalMap();
1460 if (
lmap1.isContiguous() &&
lmap2.isContiguous()) {
1462 return ((
lmap1.getMinGlobalIndex() ==
lmap2.getMinGlobalIndex()) &&
1463 (
lmap1.getMaxGlobalIndex() <=
lmap2.getMaxGlobalIndex()));
1466 if (
lmap1.getMinGlobalIndex() <
lmap2.getMinGlobalIndex() ||
1467 lmap1.getMaxGlobalIndex() >
lmap2.getMaxGlobalIndex()) {
1475 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1479 Kokkos::parallel_reduce(
1490template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1493 using Teuchos::outArg;
1494 using Teuchos::REDUCE_MIN;
1495 using Teuchos::reduceAll;
1504 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1509 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1513 }
else if (getMinAllGlobalIndex() !=
map.getMinAllGlobalIndex() ||
1514 getMaxAllGlobalIndex() !=
map.getMaxAllGlobalIndex() ||
1515 getIndexBase() !=
map.getIndexBase()) {
1519 }
else if (isDistributed() !=
map.isDistributed()) {
1523 }
else if (isContiguous() && isUniform() &&
1524 map.isContiguous() &&
map.isUniform()) {
1553template <
class LO,
class GO,
class DT>
1556 FillLgMap(
const Kokkos::View<GO*, DT>&
lgMap,
1560 Kokkos::RangePolicy<LO, typename DT::execution_space>
1561 range(
static_cast<LO
>(0),
static_cast<LO
>(
lgMap.size()));
1562 Kokkos::parallel_for(
range, *
this);
1565 KOKKOS_INLINE_FUNCTION
void operator()(
const LO& lid)
const {
1566 lgMap_(lid) = startGid_ +
static_cast<GO
>(lid);
1570 const Kokkos::View<GO*, DT> lgMap_;
1576template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1577typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
1583 using lg_view_type =
typename const_lg_view_type::non_const_type;
1587 std::unique_ptr<std::string>
prefix;
1590 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1591 std::ostringstream
os;
1593 std::cerr <<
os.str();
1600 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1604 std::ostringstream
os;
1606 std::cerr <<
os.str();
1612 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1613 "mapping (lgMap_) should have been set up already for a "
1614 "noncontiguous Map. Please report this bug to the Tpetra "
1617 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1619 using Kokkos::view_alloc;
1620 using Kokkos::WithoutInitializing;
1623 std::ostringstream
os;
1625 std::cerr <<
os.str();
1630 std::ostringstream
os;
1632 std::cerr <<
os.str();
1635 auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(),
lgMap);
1652 std::ostringstream
os;
1654 std::cerr <<
os.str();
1659template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1660typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
1666 using lg_view_type =
typename const_lg_view_type::non_const_type;
1670 std::unique_ptr<std::string>
prefix;
1673 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1674 std::ostringstream
os;
1676 std::cerr <<
os.str();
1683 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1687 std::ostringstream
os;
1689 std::cerr <<
os.str();
1695 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1696 "mapping (lgMap_) should have been set up already for a "
1697 "noncontiguous Map. Please report this bug to the Tpetra "
1700 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1702 using Kokkos::view_alloc;
1703 using Kokkos::WithoutInitializing;
1706 std::ostringstream
os;
1708 std::cerr <<
os.str();
1717 std::ostringstream
os;
1719 std::cerr <<
os.str();
1724template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1725Teuchos::ArrayView<const GlobalOrdinal>
1732 (
void)this->getMyGlobalIndices();
1740 return Teuchos::ArrayView<const GO>(
1742 lgMapHost_.extent(0),
1743 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1746template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1748 return distributed_;
1751template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1753 using Teuchos::TypeNameTraits;
1754 std::ostringstream
os;
1756 os <<
"Tpetra::Map: {"
1763 os <<
", Global number of entries: " << getGlobalNumElements()
1764 <<
", Number of processes: " << getComm()->getSize()
1765 <<
", Uniform: " << (isUniform() ?
"true" :
"false")
1766 <<
", Contiguous: " << (isContiguous() ?
"true" :
"false")
1767 <<
", Distributed: " << (isDistributed() ?
"true" :
"false")
1776template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1780 using LO = local_ordinal_type;
1784 if (
vl < Teuchos::VERB_HIGH) {
1785 return std::string();
1787 auto outStringP = Teuchos::rcp(
new std::ostringstream());
1788 Teuchos::RCP<Teuchos::FancyOStream> outp =
1789 Teuchos::getFancyOStream(outStringP);
1790 Teuchos::FancyOStream& out = *outp;
1792 auto comm = this->getComm();
1793 const int myRank = comm->getRank();
1794 const int numProcs = comm->getSize();
1795 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1796 Teuchos::OSTab tab1(out);
1798 const LO numEnt =
static_cast<LO
>(this->getLocalNumElements());
1799 out <<
"My number of entries: " << numEnt << endl
1800 <<
"My minimum global index: " << this->getMinGlobalIndex() << endl
1801 <<
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
1803 if (vl == Teuchos::VERB_EXTREME) {
1804 out <<
"My global indices: [";
1805 const LO minLclInd = this->getMinLocalIndex();
1806 for (LO k = 0; k < numEnt; ++k) {
1807 out << minLclInd + this->getGlobalElement(k);
1808 if (k + 1 < numEnt) {
1816 return outStringP->str();
1819template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1822 const Teuchos::EVerbosityLevel
verbLevel)
const {
1824 using Teuchos::TypeNameTraits;
1825 using Teuchos::VERB_DEFAULT;
1826 using Teuchos::VERB_HIGH;
1827 using Teuchos::VERB_LOW;
1828 using Teuchos::VERB_NONE;
1831 const Teuchos::EVerbosityLevel
vl =
1841 auto comm = this->getComm();
1842 if (comm.is_null()) {
1845 const int myRank = comm->getRank();
1846 const int numProcs = comm->getSize();
1855 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
1861 tab0 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1862 out <<
"\"Tpetra::Map\":" <<
endl;
1863 tab1 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1865 out <<
"Template parameters:" <<
endl;
1873 out <<
"Label: \"" << label <<
"\"" <<
endl;
1875 out <<
"Global number of entries: " << getGlobalNumElements() <<
endl
1876 <<
"Minimum global index: " << getMinAllGlobalIndex() <<
endl
1877 <<
"Maximum global index: " << getMaxAllGlobalIndex() <<
endl
1878 <<
"Index base: " << getIndexBase() <<
endl
1880 <<
"Uniform: " << (isUniform() ?
"true" :
"false") <<
endl
1881 <<
"Contiguous: " << (isContiguous() ?
"true" :
"false") <<
endl
1882 <<
"Distributed: " << (isDistributed() ?
"true" :
"false") <<
endl;
1887 const std::string
lclStr = this->localDescribeToString(
vl);
1892template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1893Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1911 return Teuchos::null;
1912 }
else if (
newComm->getSize() == 1) {
1925 newMap->indexBase_ = this->indexBase_;
1926 newMap->numGlobalElements_ = this->numLocalElements_;
1927 newMap->numLocalElements_ = this->numLocalElements_;
1928 newMap->minMyGID_ = this->minMyGID_;
1929 newMap->maxMyGID_ = this->maxMyGID_;
1930 newMap->minAllGID_ = this->minMyGID_;
1931 newMap->maxAllGID_ = this->maxMyGID_;
1932 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1933 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1936 newMap->uniform_ = this->uniform_;
1937 newMap->contiguous_ = this->contiguous_;
1940 newMap->distributed_ =
false;
1941 newMap->lgMap_ = this->lgMap_;
1942 newMap->lgMapHost_ = this->lgMapHost_;
1943 newMap->glMap_ = this->glMap_;
1944 newMap->glMapHost_ = this->glMapHost_;
1964 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
1980 auto lgMap = this->getMyGlobalIndices();
1982 typename std::decay<
decltype(
lgMap.extent(0))>::type;
1984 static_cast<size_type
>(this->getLocalNumElements());
1985 using Teuchos::TypeNameTraits;
1987 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
1991 <<
this->getLocalNumElements() <<
". The latter, upon being "
1992 "cast to size_type = "
1995 <<
lclNumInds <<
". Please report this bug to the Tpetra "
1998 Teuchos::ArrayView<const GO>
lgMap = this->getLocalElementList();
2001 const GO
indexBase = this->getIndexBase();
2008template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2009Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
2012 using Teuchos::Comm;
2013 using Teuchos::null;
2014 using Teuchos::outArg;
2017 using Teuchos::REDUCE_MIN;
2018 using Teuchos::reduceAll;
2025 const int color = (numLocalElements_ == 0) ? 0 : 1;
2042 map->indexBase_ = indexBase_;
2043 map->numGlobalElements_ = numGlobalElements_;
2044 map->numLocalElements_ = numLocalElements_;
2045 map->minMyGID_ = minMyGID_;
2046 map->maxMyGID_ = maxMyGID_;
2047 map->minAllGID_ = minAllGID_;
2048 map->maxAllGID_ = maxAllGID_;
2049 map->firstContiguousGID_ = firstContiguousGID_;
2050 map->lastContiguousGID_ = lastContiguousGID_;
2054 map->uniform_ = uniform_;
2055 map->contiguous_ = contiguous_;
2070 if (!distributed_ ||
newComm->getSize() == 1) {
2071 map->distributed_ =
false;
2073 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2079 map->lgMap_ = lgMap_;
2080 map->lgMapHost_ = lgMapHost_;
2081 map->glMap_ = glMap_;
2082 map->glMapHost_ = glMapHost_;
2099template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2102 directory_.is_null(), std::logic_error,
2103 "Tpetra::Map::setupDirectory: "
2104 "The Directory is null. "
2105 "Please report this bug to the Tpetra developers.");
2109 if (!directory_->initialized()) {
2110 directory_->initialize(*
this);
2114template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2118 const Teuchos::ArrayView<int>&
PIDs,
2119 const Teuchos::ArrayView<LocalOrdinal>&
LIDs)
const {
2122 using Tpetra::Details::OrdinalTraits;
2123 using size_type = Teuchos::ArrayView<int>::size_type;
2127 std::unique_ptr<std::string>
prefix;
2130 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2131 std::ostringstream
os;
2135 std::cerr <<
os.str();
2144 if (getGlobalNumElements() == 0) {
2145 if (
GIDs.size() == 0) {
2147 std::ostringstream
os;
2148 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2149 std::cerr <<
os.str();
2154 std::ostringstream
os;
2155 os << *
prefix <<
"Done: Map is empty on all processes, "
2156 "so all output PIDs & LIDs are invalid (-1)."
2158 std::cerr <<
os.str();
2160 for (size_type
k = 0;
k <
PIDs.size(); ++
k) {
2163 for (size_type
k = 0;
k <
LIDs.size(); ++
k) {
2175 std::ostringstream
os;
2177 std::cerr <<
os.str();
2181 std::ostringstream
os;
2182 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2183 std::cerr <<
os.str();
2186 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs,
LIDs);
2188 std::ostringstream
os;
2189 os << *
prefix <<
"Done; getDirectoryEntries returned "
2196 std::cerr <<
os.str();
2201template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2205 const Teuchos::ArrayView<int>&
PIDs)
const {
2211 std::unique_ptr<std::string>
prefix;
2214 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2215 std::ostringstream
os;
2219 std::cerr <<
os.str();
2222 if (getGlobalNumElements() == 0) {
2223 if (
GIDs.size() == 0) {
2225 std::ostringstream
os;
2226 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2227 std::cerr <<
os.str();
2232 std::ostringstream
os;
2233 os << *
prefix <<
"Done: Map is empty on all processes, "
2234 "so all output PIDs are invalid (-1)."
2236 std::cerr <<
os.str();
2238 for (Teuchos::ArrayView<int>::size_type
k = 0;
k <
PIDs.size(); ++
k) {
2239 PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2250 std::ostringstream
os;
2252 std::cerr <<
os.str();
2256 std::ostringstream
os;
2257 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2258 std::cerr <<
os.str();
2261 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs);
2263 std::ostringstream
os;
2264 os << *
prefix <<
"Done; getDirectoryEntries returned "
2269 std::cerr <<
os.str();
2274template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2276 using exec_space =
typename Node::device_type::execution_space;
2277 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2283 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2296template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2297Teuchos::RCP<const Teuchos::Comm<int>>
2302template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2307 using Teuchos::outArg;
2308 using Teuchos::REDUCE_MIN;
2309 using Teuchos::reduceAll;
2312 std::unique_ptr<std::string>
prefix;
2315 comm_.getRawPtr(),
"Map",
"checkIsDist");
2316 std::ostringstream
os;
2318 std::cerr <<
os.str();
2321 bool global =
false;
2322 if (comm_->getSize() > 1) {
2326 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2339 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2340 if (allLocalRep != 1) {
2350 std::ostringstream os;
2351 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2353 std::cerr << os.str();
2360template <
class LocalOrdinal,
class GlobalOrdinal>
2361Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2363 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2364 typedef LocalOrdinal LO;
2365 typedef GlobalOrdinal GO;
2366 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2367 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2370template <
class LocalOrdinal,
class GlobalOrdinal>
2371Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2373 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2374 typedef LocalOrdinal LO;
2375 typedef GlobalOrdinal GO;
2376 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2377 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2380template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2381Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2383 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2386 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2388 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2391template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2392Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2394 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2398 const GlobalOrdinal indexBase = 0;
2401 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2404template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2405Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2407 const size_t localNumElements,
2408 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2411 const GlobalOrdinal indexBase = 0;
2413 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2416template <
class LocalOrdinal,
class GlobalOrdinal>
2417Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2419 const size_t localNumElements,
2420 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2421 typedef LocalOrdinal LO;
2422 typedef GlobalOrdinal GO;
2428template <
class LocalOrdinal,
class GlobalOrdinal>
2429Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2431 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2432 typedef LocalOrdinal LO;
2433 typedef GlobalOrdinal GO;
2439template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2440Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2442 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2446 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2450 const GlobalOrdinal indexBase = 0;
2452 return rcp(
new map_type(INV, elementList, indexBase, comm));
2455template <
class LO,
class GO,
class NT>
2456Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2458 using Details::verbosePrintArray;
2461 using Teuchos::Array;
2462 using Teuchos::ArrayView;
2468 const bool verbose = Details::Behavior::verbose(
"Map");
2469 std::unique_ptr<std::string> prefix;
2471 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2472 prefix = Details::createPrefix(
2473 comm.getRawPtr(),
"createOneToOne(Map)");
2474 std::ostringstream os;
2475 os << *prefix <<
"Start" << endl;
2478 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2479 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2480 const int myRank = M->getComm()->getRank();
2486 if (!M->isDistributed()) {
2493 const GST numGlobalEntries = M->getGlobalNumElements();
2494 if (M->isContiguous()) {
2495 const size_t numLocalEntries =
2496 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2498 std::ostringstream os;
2499 os << *prefix <<
"Input is locally replicated & contiguous; "
2501 << numLocalEntries << endl;
2505 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2506 M->getIndexBase(), M->getComm()));
2508 std::ostringstream os;
2509 os << *prefix <<
"Done" << endl;
2515 std::ostringstream os;
2516 os << *prefix <<
"Input is locally replicated & noncontiguous"
2520 ArrayView<const GO> myGids =
2521 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2523 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2526 std::ostringstream os;
2527 os << *prefix <<
"Done" << endl;
2532 }
else if (M->isContiguous()) {
2534 std::ostringstream os;
2535 os << *prefix <<
"Input is distributed & contiguous" << endl;
2543 std::ostringstream os;
2544 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2548 const size_t numMyElems = M->getLocalNumElements();
2549 ArrayView<const GO> myElems = M->getLocalElementList();
2550 Array<int> owner_procs_vec(numMyElems);
2553 std::ostringstream os;
2554 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2559 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2561 std::ostringstream os;
2562 os << *prefix <<
"getDirectoryEntries result: ";
2568 Array<GO> myOwned_vec(numMyElems);
2569 size_t numMyOwnedElems = 0;
2570 for (
size_t i = 0; i < numMyElems; ++i) {
2571 const GO GID = myElems[i];
2572 const int owner = owner_procs_vec[i];
2574 if (myRank == owner) {
2575 myOwned_vec[numMyOwnedElems++] = GID;
2578 myOwned_vec.resize(numMyOwnedElems);
2581 std::ostringstream os;
2582 os << *prefix <<
"Create Map: ";
2587 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2588 M->getIndexBase(), M->getComm()));
2590 std::ostringstream os;
2591 os << *prefix <<
"Done" << endl;
2598template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2599Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2602 using Details::Behavior;
2603 using Details::verbosePrintArray;
2606 using Teuchos::Array;
2607 using Teuchos::ArrayView;
2610 using Teuchos::toString;
2611 using LO = LocalOrdinal;
2612 using GO = GlobalOrdinal;
2615 const bool verbose = Behavior::verbose(
"Map");
2616 std::unique_ptr<std::string> prefix;
2618 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2619 prefix = Details::createPrefix(
2620 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2621 std::ostringstream os;
2622 os << *prefix <<
"Start" << endl;
2625 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2632 std::ostringstream os;
2633 os << *prefix <<
"Initialize Directory" << endl;
2636 directory.initialize(*M, tie_break);
2638 std::ostringstream os;
2639 os << *prefix <<
"Done initializing Directory" << endl;
2642 size_t numMyElems = M->getLocalNumElements();
2643 ArrayView<const GO> myElems = M->getLocalElementList();
2644 Array<int> owner_procs_vec(numMyElems);
2646 std::ostringstream os;
2647 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2652 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2654 std::ostringstream os;
2655 os << *prefix <<
"getDirectoryEntries result: ";
2661 const int myRank = M->getComm()->getRank();
2662 Array<GO> myOwned_vec(numMyElems);
2663 size_t numMyOwnedElems = 0;
2664 for (
size_t i = 0; i < numMyElems; ++i) {
2665 const GO GID = myElems[i];
2666 const int owner = owner_procs_vec[i];
2667 if (myRank == owner) {
2668 myOwned_vec[numMyOwnedElems++] = GID;
2671 myOwned_vec.resize(numMyOwnedElems);
2676 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2678 std::ostringstream os;
2679 os << *prefix <<
"Create Map: ";
2684 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2687 std::ostringstream os;
2688 os << *prefix <<
"Done" << endl;
2702#define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2704 template class Map<LO, GO, NODE>; \
2706 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2707 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2708 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2710 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2711 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2712 const size_t localNumElements, \
2713 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2715 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2716 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2717 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2719 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2720 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2721 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2723 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2724 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2726 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2727 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2728 const Tpetra::Details::TieBreak<LO, GO>& tie_break);
2731#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2732 template Teuchos::RCP<const Map<LO, GO>> \
2733 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2735 template Teuchos::RCP<const Map<LO, GO>> \
2736 createContigMap<LO, GO>(global_size_t, size_t, \
2737 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2739 template Teuchos::RCP<const Map<LO, GO>> \
2740 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2741 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2743 template Teuchos::RCP<const Map<LO, GO>> \
2744 createUniformContigMap<LO, GO>(const global_size_t, \
2745 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...