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 "Kokkos_Sort.hpp"
29#include "Tpetra_Directory.hpp"
32#include "Tpetra_Details_FixedHashTable.hpp"
38#include "Tpetra_Details_mpiIsInitialized.hpp"
46inline void checkMapInputArray(
const char ctorName[],
47 const void* indexList,
48 const size_t indexListSize,
49 const Teuchos::Comm<int>*
const comm) {
52 const bool debug = Behavior::debug(
"Map");
55 using Teuchos::outArg;
56 using Teuchos::REDUCE_MIN;
57 using Teuchos::reduceAll;
59 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
60 const bool verbose = Behavior::verbose(
"Map");
61 std::ostringstream lclErrStrm;
64 if (indexListSize != 0 && indexList ==
nullptr) {
67 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
69 << indexListSize <<
" != 0." << endl;
73 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
74 if (gblSuccess != 1) {
75 std::ostringstream gblErrStrm;
76 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
" detected a problem with the input array "
77 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
81 using ::Tpetra::Details::gathervPrint;
84 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
89template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
90void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
91 using LO = LocalOrdinal;
92 using GO = GlobalOrdinal;
93 using exec_space =
typename ViewType::device_type::execution_space;
94 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
95 const LO numLocalElements = entryList.extent(0);
99 typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
100 minloc_type myMinLoc;
105 Kokkos::parallel_reduce(
106 range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
107 GO entry_0 = entryList[0];
108 GO entry_i = entryList[i];
111 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
112 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
113 l_firstCont = entry_0;
115 if (entry_i - entry_0 != i && l_lastCont.val >= i) {
117 l_lastCont.val = i - 1;
118 l_lastCont.loc = entryList[i - 1];
119 }
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
122 l_lastCont.loc = entry_i;
125 Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
128 lastContiguousGID_val = myMinLoc.loc;
129 lastContiguousGID_loc = myMinLoc.val;
134template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 , numGlobalElements_(0)
140 , numLocalElements_(0)
150 , distributed_(
false)
151 , haveGlobalConstants_(
true)
158template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
162 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
169 using Teuchos::broadcast;
170 using Teuchos::outArg;
171 using Teuchos::REDUCE_MAX;
172 using Teuchos::REDUCE_MIN;
173 using Teuchos::reduceAll;
174 using Teuchos::typeName;
177 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
178 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
180 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
184 std::unique_ptr<std::string>
prefix;
187 comm_.getRawPtr(),
"Map",
funcName);
188 std::ostringstream
os;
190 std::cerr <<
os.str();
208 std::invalid_argument,
exPfx <<
"All processes must "
209 "provide the same number of global elements. Process 0 set "
213 << comm->getRank() <<
" set "
216 "and max values over all processes are "
226 std::invalid_argument,
exPfx <<
"All processes must "
227 "provide the same indexBase argument. Process 0 set "
251 std::invalid_argument,
exPfx <<
"numGlobalElements (= " <<
numGlobalElements <<
") must be nonnegative.");
254 "Tpetra::global_size_t>::invalid(). This version of the "
255 "constructor requires a valid value of numGlobalElements. "
256 "You probably mistook this constructor for the \"contiguous "
257 "nonuniform\" constructor, which can compute the global "
258 "number of elements for you if you set numGlobalElements to "
259 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
262 if (
lOrG == GloballyDistributed) {
278 const GST myRank =
static_cast<GST>(comm_->getRank());
303 distributed_ =
false;
306 minAllGID_ = indexBase;
307 maxAllGID_ = indexBase + numGlobalElements - 1;
308 indexBase_ = indexBase;
309 numGlobalElements_ = numGlobalElements;
310 numLocalElements_ = numLocalElements;
311 firstContiguousGID_ = minMyGID_;
312 lastContiguousGID_ = maxMyGID_;
314 haveGlobalConstants_ =
true;
320 std::ostringstream os;
321 os << *prefix <<
"Done" << endl;
322 std::cerr << os.str();
326template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
331 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
337 using Teuchos::broadcast;
338 using Teuchos::outArg;
339 using Teuchos::REDUCE_MAX;
340 using Teuchos::REDUCE_MIN;
341 using Teuchos::REDUCE_SUM;
342 using Teuchos::reduceAll;
346 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
348 "Map(gblNumInds,lclNumInds,indexBase,comm)";
350 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
352 ". Please report this bug to the Tpetra developers.";
356 std::unique_ptr<std::string>
prefix;
359 comm_.getRawPtr(),
"Map",
funcName);
360 std::ostringstream
os;
362 std::cerr <<
os.str();
397 const int numProcs = comm->getSize();
402 numGlobalElements_ = globalSum;
406 TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx <<
"globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum << suffix);
409 numLocalElements_ = numLocalElements;
410 indexBase_ = indexBase;
411 minAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
412 maxAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
413 minMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
414 maxMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
415 firstContiguousGID_ = minMyGID_;
416 lastContiguousGID_ = maxMyGID_;
418 distributed_ = (comm->getSize() > 1);
419 haveGlobalConstants_ =
true;
425 std::ostringstream os;
426 os << *prefix <<
"Done" << endl;
427 std::cerr << os.str();
431template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433Map<LocalOrdinal, GlobalOrdinal, Node>::
434 initialNonuniformDebugCheck(
435 const char errorMessagePrefix[],
437 const size_t numLocalElements,
438 const global_ordinal_type indexBase,
439 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const {
445 using Teuchos::broadcast;
446 using Teuchos::outArg;
448 using Teuchos::REDUCE_MAX;
449 using Teuchos::REDUCE_MIN;
450 using Teuchos::REDUCE_SUM;
451 using Teuchos::reduceAll;
452 using GO = global_ordinal_type;
454 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
481 "must provide the same number of global elements, even if "
483 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
484 "(which signals that the Map should compute the global "
485 "number of elements). Process 0 set numGlobalElements"
498 std::invalid_argument,
errorMessagePrefix <<
"All processes must provide the same indexBase argument. "
499 "Process 0 set indexBase = "
502 << comm->getRank() <<
" set indexBase=" <<
indexBase <<
". The min and max values over all "
510 std::invalid_argument,
512 "indices over all processes, "
515 "would like this constructor to compute numGlobalElements "
516 "for you, you may set numGlobalElements="
517 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
518 "on input. Please note that this is NOT necessarily -1.");
523template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
524void Map<LocalOrdinal, GlobalOrdinal, Node>::
525 initWithNonownedHostIndexList(
526 const char errorMessagePrefix[],
528 const Kokkos::View<
const global_ordinal_type*,
531 Kokkos::MemoryUnmanaged>& entryList_host,
532 const global_ordinal_type indexBase,
533 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
534 const Teuchos::RCP<Teuchos::ParameterList>& params) {
537 using Kokkos::LayoutLeft;
538 using Kokkos::subview;
540 using Kokkos::view_alloc;
541 using Kokkos::WithoutInitializing;
543 using Teuchos::broadcast;
544 using Teuchos::outArg;
546 using Teuchos::REDUCE_MAX;
547 using Teuchos::REDUCE_MIN;
548 using Teuchos::REDUCE_SUM;
549 using Teuchos::reduceAll;
553 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
557 << Teuchos::TypeNameTraits<execution_space>::name()
558 <<
" has not been initialized. "
559 "Please initialize it before creating a Map.")
618 numLocalElements_ = numLocalElements;
619 indexBase_ = indexBase;
621 minMyGID_ = indexBase_;
622 maxMyGID_ = indexBase_;
632 if (numLocalElements_ > 0) {
637 typename decltype(lgMap_)::non_const_type lgMap(view_alloc(
"lgMap", WithoutInitializing), numLocalElements_);
639 Kokkos::create_mirror_view(Kokkos::HostSpace(), lgMap);
647 firstContiguousGID_ = entryList_host[0];
648 lastContiguousGID_ = firstContiguousGID_ + 1;
656 lgMap_host[0] = firstContiguousGID_;
658 for (;
i < numLocalElements_; ++
i) {
662 if (lastContiguousGID_ !=
curGid)
break;
669 ++lastContiguousGID_;
671 --lastContiguousGID_;
677 minMyGID_ = firstContiguousGID_;
678 maxMyGID_ = lastContiguousGID_;
689 "Tpetra::Map noncontiguous constructor: "
690 "nonContigGids_host.extent(0) = "
692 <<
" != entryList_host.extent(0) - i = "
695 <<
". Please report this bug to the Tpetra developers.");
705 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
718 for (;
i < numLocalElements_; ++
i) {
720 const LO
curLid =
static_cast<LO
>(
i);
728 if (curGid > maxMyGID_) {
735 Kokkos::deep_copy(execution_space(), lgMap, lgMap_host);
743 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
744 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
748 firstContiguousGID_ = indexBase_ + 1;
749 lastContiguousGID_ = indexBase_;
755 if (req) req->wait();
757 const bool callComputeGlobalConstants = (params.get() ==
nullptr) ||
758 params->get(
"compute global constants",
true) ||
759 (comm->getSize() == 1);
761 if (callComputeGlobalConstants)
762 computeGlobalConstants();
764 distributed_ = params->get(
"distributed",
true);
771template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
777 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
778 const Teuchos::RCP<Teuchos::ParameterList>&
params)
784 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
787 std::unique_ptr<std::string>
prefix;
790 comm_.getRawPtr(),
"Map",
funcName);
791 std::ostringstream
os;
793 std::cerr <<
os.str();
798 Impl::checkMapInputArray(
"(GST, const GO[], LO, GO, comm)",
808 Kokkos::MemoryUnmanaged>
813 std::ostringstream
os;
815 std::cerr <<
os.str();
819template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
822 const Teuchos::ArrayView<const GlobalOrdinal>&
entryList,
824 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
825 const Teuchos::RCP<Teuchos::ParameterList>&
params)
830 const char*
funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
832 const bool verbose = Details::Behavior::verbose(
"Map");
833 std::unique_ptr<std::string>
prefix;
835 prefix = Details::createPrefix(
836 comm_.getRawPtr(),
"Map",
funcName);
837 std::ostringstream
os;
839 std::cerr <<
os.str();
845 Impl::checkMapInputArray(
"(GST, ArrayView, GO, comm)",
856 Kokkos::MemoryUnmanaged>
861 std::ostringstream
os;
863 std::cerr <<
os.str();
867template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
870 const Kokkos::View<const GlobalOrdinal*, device_type>&
entryList,
872 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
873 const Teuchos::RCP<Teuchos::ParameterList>&
params)
877 using Kokkos::LayoutLeft;
878 using Kokkos::subview;
880 using Kokkos::view_alloc;
881 using Kokkos::WithoutInitializing;
884 using Teuchos::ArrayView;
886 using Teuchos::broadcast;
887 using Teuchos::outArg;
889 using Teuchos::REDUCE_MAX;
890 using Teuchos::REDUCE_MIN;
891 using Teuchos::REDUCE_SUM;
892 using Teuchos::reduceAll;
893 using Teuchos::typeName;
896 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
898 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
901 std::unique_ptr<std::string>
prefix;
904 comm_.getRawPtr(),
"Map",
funcName);
905 std::ostringstream
os;
907 std::cerr <<
os.str();
912 Impl::checkMapInputArray(
"(GST, Kokkos::View, GO, comm)",
914 static_cast<size_t>(
entryList.extent(0)),
941 std::shared_ptr<Details::CommRequest>
req;
977 minMyGID_ = indexBase_;
978 maxMyGID_ = indexBase_;
988 if (numLocalElements_ > 0) {
996 Kokkos::deep_copy(
typename device_type::execution_space(),
lgMap,
entryList);
1010 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1011 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1015 firstContiguousGID_ = indexBase_ + 1;
1016 lastContiguousGID_ = indexBase_;
1020 if (req) req->wait();
1022 const bool callComputeGlobalConstants = (params.get() ==
nullptr) ||
1023 params->get(
"compute global constants",
true) ||
1024 (comm->getSize() == 1);
1026 if (callComputeGlobalConstants)
1029 distributed_ = params->get(
"distributed",
true);
1032 contiguous_ =
false;
1038 std::ostringstream
os;
1040 std::cerr <<
os.str();
1044template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1049 if (haveGlobalConstants_)
1052 if (comm_->getSize() == 1) {
1053 minAllGID_ = minMyGID_;
1054 maxAllGID_ = maxMyGID_;
1055 distributed_ =
false;
1056 haveGlobalConstants_ =
true;
1083 Kokkos::View<GO*, Kokkos::HostSpace>
minMaxInput(Kokkos::ViewAllocateWithoutInitializing(
"minMaxInput"), 3);
1084 Kokkos::View<GO*, Kokkos::HostSpace>
minMaxOutput(Kokkos::ViewAllocateWithoutInitializing(
"minMaxOutput"), 3);
1086 minMaxInput[0] = std::numeric_limits<GO>::max() - minMyGID_;
1088 minMaxInput[2] = std::numeric_limits<GO>::max() -
static_cast<GO
>(numLocalElements_);
1092 minAllGID_ = std::numeric_limits<GO>::max() -
minMaxOutput[0];
1098 haveGlobalConstants_ =
true;
1101 minAllGID_ < indexBase_,
1102 std::invalid_argument,
1103 "Tpetra::Map constructor (noncontiguous): "
1104 "Minimum global ID = "
1105 << minAllGID_ <<
" over all process(es) is "
1106 "less than the given indexBase = "
1107 << indexBase_ <<
".");
1110template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1112 if (!Kokkos::is_initialized()) {
1113 std::ostringstream
os;
1114 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1115 "Kokkos::finalize() has been called. This is user error! There are "
1116 "two likely causes: "
1118 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1120 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1121 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1122 "or Tpetra::finalize()."
1125 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1128 this->getComm().getRawPtr());
1130 using ::Tpetra::Details::mpiIsFinalized;
1131 using ::Tpetra::Details::mpiIsInitialized;
1132 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1134 Teuchos::RCP<const Teuchos::Comm<int>> comm = this->getComm();
1135 if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
1136 mpiIsInitialized() && mpiIsFinalized()) {
1142 std::ostringstream
os;
1143 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1144 "MPI_Finalize() has been called. This is user error! There are "
1145 "two likely causes: "
1147 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1149 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1150 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1151 "Tpetra::finalize()."
1154 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1164template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1167 getComm().
is_null(), std::logic_error,
1168 "Tpetra::Map::isOneToOne: "
1169 "getComm() returns null. Please report this bug to the Tpetra "
1174 return directory_->isOneToOne(*
this);
1177template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1181 if (isContiguous()) {
1184 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1199template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1204 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
1206 if (isContiguous()) {
1218template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1219bool Map<LocalOrdinal, GlobalOrdinal, Node>::getGlobalElements(
1220 const local_ordinal_type localIndices[],
size_t numEntries, global_ordinal_type globalIndices[])
const {
1221 auto const minGI = getMinGlobalIndex();
1222 auto const minLI = getMinLocalIndex();
1223 auto const maxLI = getMaxLocalIndex();
1224 if (isContiguous()) {
1225 for (
size_t i = 0; i < numEntries; i++) {
1226 auto lclInd = localIndices[i];
1227 if (lclInd < minLI || lclInd > maxLI) {
1230 globalIndices[i] = minGI + lclInd;
1238 for (
size_t i = 0; i < numEntries; i++) {
1239 auto lclInd = localIndices[i];
1240 if (lclInd < minLI || lclInd > maxLI) {
1243 globalIndices[i] = lgMapHost_[lclInd];
1249template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1259template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1263 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1266template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1271template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1276template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1281 getMinGlobalIndex(), getMaxGlobalIndex(),
1282 firstContiguousGID_, lastContiguousGID_,
1283 getLocalNumElements(), isContiguous());
1286template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1289 using Teuchos::outArg;
1290 using Teuchos::REDUCE_MIN;
1291 using Teuchos::reduceAll;
1300 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1305 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1309 }
else if (isContiguous() && isUniform() &&
1310 map.isContiguous() &&
map.isUniform()) {
1315 }
else if (!isContiguous() && !
map.isContiguous() &&
1316 lgMap_.extent(0) != 0 &&
map.lgMap_.extent(0) != 0 &&
1317 lgMap_.data() ==
map.lgMap_.data()) {
1332 getGlobalNumElements() !=
map.getGlobalNumElements(), std::logic_error,
1333 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1334 "checked that this condition is true above, but it's false here. "
1335 "Please report this bug to the Tpetra developers.");
1339 (getLocalNumElements() ==
map.getLocalNumElements()) ? 1 : 0;
1346template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1349 using Teuchos::ArrayView;
1365 }
else if (getLocalNumElements() !=
map.getLocalNumElements()) {
1367 }
else if (getMinGlobalIndex() !=
map.getMinGlobalIndex() ||
1368 getMaxGlobalIndex() !=
map.getMaxGlobalIndex()) {
1371 if (isContiguous()) {
1372 if (
map.isContiguous()) {
1376 !this->isContiguous() ||
map.isContiguous(), std::logic_error,
1377 "Tpetra::Map::locallySameAs: BUG");
1379 const GO
minLhsGid = this->getMinGlobalIndex();
1389 }
else if (
map.isContiguous()) {
1391 this->isContiguous() || !
map.isContiguous(), std::logic_error,
1392 "Tpetra::Map::locallySameAs: BUG");
1403 }
else if (this->lgMap_.data() ==
map.lgMap_.data()) {
1406 return this->getLocalNumElements() ==
map.getLocalNumElements();
1408 if (this->getLocalNumElements() !=
map.getLocalNumElements()) {
1411 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1417 Kokkos::parallel_reduce(
1418 "Tpetra::Map::locallySameAs",
1419 range_type(0, this->getLocalNumElements()),
1432template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1443 auto lmap2 = this->getLocalMap();
1453 if (
lmap1.isContiguous() &&
lmap2.isContiguous()) {
1455 return ((
lmap1.getMinGlobalIndex() ==
lmap2.getMinGlobalIndex()) &&
1456 (
lmap1.getMaxGlobalIndex() <=
lmap2.getMaxGlobalIndex()));
1459 if (
lmap1.getMinGlobalIndex() <
lmap2.getMinGlobalIndex() ||
1460 lmap1.getMaxGlobalIndex() >
lmap2.getMaxGlobalIndex()) {
1468 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1472 Kokkos::parallel_reduce(
1483template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1486 using Teuchos::outArg;
1487 using Teuchos::REDUCE_MIN;
1488 using Teuchos::reduceAll;
1497 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1502 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1506 }
else if (haveGlobalConstants() &&
map.haveGlobalConstants() && (getMinAllGlobalIndex() !=
map.getMinAllGlobalIndex() || getMaxAllGlobalIndex() !=
map.getMaxAllGlobalIndex() || getIndexBase() !=
map.getIndexBase())) {
1510 }
else if (haveGlobalConstants() &&
map.haveGlobalConstants() && (isDistributed() !=
map.isDistributed())) {
1514 }
else if (isContiguous() && isUniform() &&
1515 map.isContiguous() &&
map.isUniform()) {
1544template <
class LO,
class GO,
class DT>
1547 FillLgMap(
const Kokkos::View<GO*, DT>&
lgMap,
1551 Kokkos::RangePolicy<LO, typename DT::execution_space>
1552 range(
static_cast<LO
>(0),
static_cast<LO
>(
lgMap.size()));
1553 Kokkos::parallel_for(
range, *
this);
1556 KOKKOS_INLINE_FUNCTION
void operator()(
const LO& lid)
const {
1557 lgMap_(lid) = startGid_ +
static_cast<GO
>(lid);
1561 const Kokkos::View<GO*, DT> lgMap_;
1567template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1568typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
1574 using lg_view_type =
typename const_lg_view_type::non_const_type;
1578 std::unique_ptr<std::string>
prefix;
1581 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1582 std::ostringstream
os;
1584 std::cerr <<
os.str();
1591 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1595 std::ostringstream
os;
1597 std::cerr <<
os.str();
1603 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1604 "mapping (lgMap_) should have been set up already for a "
1605 "noncontiguous Map. Please report this bug to the Tpetra "
1608 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1610 using Kokkos::view_alloc;
1611 using Kokkos::WithoutInitializing;
1614 std::ostringstream
os;
1616 std::cerr <<
os.str();
1621 std::ostringstream
os;
1623 std::cerr <<
os.str();
1626 auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(),
lgMap);
1643 std::ostringstream
os;
1645 std::cerr <<
os.str();
1650template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1651typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
1657 using lg_view_type =
typename const_lg_view_type::non_const_type;
1661 std::unique_ptr<std::string>
prefix;
1664 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1665 std::ostringstream
os;
1667 std::cerr <<
os.str();
1674 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1678 std::ostringstream
os;
1680 std::cerr <<
os.str();
1686 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1687 "mapping (lgMap_) should have been set up already for a "
1688 "noncontiguous Map. Please report this bug to the Tpetra "
1691 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1693 using Kokkos::view_alloc;
1694 using Kokkos::WithoutInitializing;
1697 std::ostringstream
os;
1699 std::cerr <<
os.str();
1708 std::ostringstream
os;
1710 std::cerr <<
os.str();
1715template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1716Teuchos::ArrayView<const GlobalOrdinal>
1723 (
void)this->getMyGlobalIndices();
1731 return Teuchos::ArrayView<const GO>(
1733 lgMapHost_.extent(0),
1734 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1737template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1739 return distributed_;
1742template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1744 using Teuchos::TypeNameTraits;
1745 std::ostringstream
os;
1747 os <<
"Tpetra::Map: {"
1754 os <<
", Global number of entries: " << getGlobalNumElements()
1755 <<
", Number of processes: " << getComm()->getSize()
1756 <<
", Uniform: " << (isUniform() ?
"true" :
"false")
1757 <<
", Contiguous: " << (isContiguous() ?
"true" :
"false")
1758 <<
", Distributed: " << (isDistributed() ?
"true" :
"false")
1767template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1771 using LO = local_ordinal_type;
1775 if (
vl < Teuchos::VERB_HIGH) {
1776 return std::string();
1778 auto outStringP = Teuchos::rcp(
new std::ostringstream());
1779 Teuchos::RCP<Teuchos::FancyOStream> outp =
1780 Teuchos::getFancyOStream(outStringP);
1781 Teuchos::FancyOStream& out = *outp;
1783 auto comm = this->getComm();
1784 const int myRank = comm->getRank();
1785 const int numProcs = comm->getSize();
1786 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1787 Teuchos::OSTab tab1(out);
1789 const LO numEnt =
static_cast<LO
>(this->getLocalNumElements());
1790 out <<
"My number of entries: " << numEnt << endl
1791 <<
"My minimum global index: " << this->getMinGlobalIndex() << endl
1792 <<
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
1794 if (vl == Teuchos::VERB_EXTREME) {
1795 out <<
"My global indices: [";
1796 const LO minLclInd = this->getMinLocalIndex();
1797 for (LO k = 0; k < numEnt; ++k) {
1798 out << minLclInd + this->getGlobalElement(k);
1799 if (k + 1 < numEnt) {
1807 return outStringP->str();
1810template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1813 const Teuchos::EVerbosityLevel
verbLevel)
const {
1815 using Teuchos::TypeNameTraits;
1816 using Teuchos::VERB_DEFAULT;
1817 using Teuchos::VERB_HIGH;
1818 using Teuchos::VERB_LOW;
1819 using Teuchos::VERB_NONE;
1822 const Teuchos::EVerbosityLevel
vl =
1832 auto comm = this->getComm();
1833 if (comm.is_null()) {
1836 const int myRank = comm->getRank();
1837 const int numProcs = comm->getSize();
1846 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
1852 tab0 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1853 out <<
"\"Tpetra::Map\":" <<
endl;
1854 tab1 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1856 out <<
"Template parameters:" <<
endl;
1864 out <<
"Label: \"" << label <<
"\"" <<
endl;
1866 out <<
"Global number of entries: " << getGlobalNumElements() <<
endl
1867 <<
"Minimum global index: " << getMinAllGlobalIndex() <<
endl
1868 <<
"Maximum global index: " << getMaxAllGlobalIndex() <<
endl
1869 <<
"Index base: " << getIndexBase() <<
endl
1871 <<
"Uniform: " << (isUniform() ?
"true" :
"false") <<
endl
1872 <<
"Contiguous: " << (isContiguous() ?
"true" :
"false") <<
endl
1873 <<
"Distributed: " << (isDistributed() ?
"true" :
"false") <<
endl;
1878 const std::string
lclStr = this->localDescribeToString(
vl);
1883template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1884Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1902 return Teuchos::null;
1903 }
else if (
newComm->getSize() == 1) {
1916 newMap->indexBase_ = this->indexBase_;
1917 newMap->numGlobalElements_ = this->numLocalElements_;
1918 newMap->numLocalElements_ = this->numLocalElements_;
1919 newMap->minMyGID_ = this->minMyGID_;
1920 newMap->maxMyGID_ = this->maxMyGID_;
1921 newMap->minAllGID_ = this->minMyGID_;
1922 newMap->maxAllGID_ = this->maxMyGID_;
1923 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1924 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1925 newMap->haveGlobalConstants_ = this->haveGlobalConstants_;
1928 newMap->uniform_ = this->uniform_;
1929 newMap->contiguous_ = this->contiguous_;
1932 newMap->distributed_ =
false;
1933 newMap->lgMap_ = this->lgMap_;
1934 newMap->lgMapHost_ = this->lgMapHost_;
1935 newMap->glMap_ = this->glMap_;
1936 newMap->glMapHost_ = this->glMapHost_;
1956 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
1972 auto lgMap = this->getMyGlobalIndices();
1974 typename std::decay<
decltype(
lgMap.extent(0))>::type;
1976 static_cast<size_type
>(this->getLocalNumElements());
1977 using Teuchos::TypeNameTraits;
1979 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
1983 <<
this->getLocalNumElements() <<
". The latter, upon being "
1984 "cast to size_type = "
1987 <<
lclNumInds <<
". Please report this bug to the Tpetra "
1990 Teuchos::ArrayView<const GO>
lgMap = this->getLocalElementList();
1993 const GO
indexBase = this->getIndexBase();
2000template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2001Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
2005 using Teuchos::Comm;
2006 using Teuchos::null;
2007 using Teuchos::outArg;
2010 using Teuchos::REDUCE_MIN;
2011 using Teuchos::reduceAll;
2018 const int color = (numLocalElements_ == 0) ? 0 : 1;
2035 map->indexBase_ = indexBase_;
2036 map->numGlobalElements_ = numGlobalElements_;
2037 map->numLocalElements_ = numLocalElements_;
2038 map->minMyGID_ = minMyGID_;
2039 map->maxMyGID_ = maxMyGID_;
2040 map->minAllGID_ = minAllGID_;
2041 map->maxAllGID_ = maxAllGID_;
2042 map->firstContiguousGID_ = firstContiguousGID_;
2043 map->lastContiguousGID_ = lastContiguousGID_;
2044 map->haveGlobalConstants_ = haveGlobalConstants_;
2048 map->uniform_ = uniform_;
2049 map->contiguous_ = contiguous_;
2064 if (!distributed_ ||
newComm->getSize() == 1) {
2065 map->distributed_ =
false;
2066 if (
newComm->getSize() == 1) {
2067 map->minAllGID_ =
map->minMyGID_;
2068 map->maxAllGID_ =
map->maxMyGID_;
2069 map->haveGlobalConstants_ =
true;
2072 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2078 map->lgMap_ = lgMap_;
2079 map->lgMapHost_ = lgMapHost_;
2080 map->glMap_ = glMap_;
2081 map->glMapHost_ = glMapHost_;
2098template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2101 directory_.is_null(), std::logic_error,
2102 "Tpetra::Map::setupDirectory: "
2103 "The Directory is null. "
2104 "Please report this bug to the Tpetra developers.");
2108 if (!directory_->initialized()) {
2110 if (isDistributed() && !isUniform() && !isContiguous())
2111 computeGlobalConstants();
2112 directory_->initialize(*
this);
2116template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2120 const Teuchos::ArrayView<int>&
PIDs,
2121 const Teuchos::ArrayView<LocalOrdinal>&
LIDs)
const {
2124 using Tpetra::Details::OrdinalTraits;
2125 using size_type = Teuchos::ArrayView<int>::size_type;
2129 std::unique_ptr<std::string>
prefix;
2132 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2133 std::ostringstream
os;
2137 std::cerr <<
os.str();
2146 if (getGlobalNumElements() == 0) {
2147 if (
GIDs.size() == 0) {
2149 std::ostringstream
os;
2150 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2151 std::cerr <<
os.str();
2156 std::ostringstream
os;
2157 os << *
prefix <<
"Done: Map is empty on all processes, "
2158 "so all output PIDs & LIDs are invalid (-1)."
2160 std::cerr <<
os.str();
2162 for (size_type
k = 0;
k <
PIDs.size(); ++
k) {
2165 for (size_type
k = 0;
k <
LIDs.size(); ++
k) {
2177 std::ostringstream
os;
2179 std::cerr <<
os.str();
2183 std::ostringstream
os;
2184 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2185 std::cerr <<
os.str();
2188 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs,
LIDs);
2190 std::ostringstream
os;
2191 os << *
prefix <<
"Done; getDirectoryEntries returned "
2198 std::cerr <<
os.str();
2203template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2207 const Teuchos::ArrayView<int>&
PIDs)
const {
2213 std::unique_ptr<std::string>
prefix;
2216 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2217 std::ostringstream
os;
2221 std::cerr <<
os.str();
2224 if (getGlobalNumElements() == 0) {
2225 if (
GIDs.size() == 0) {
2227 std::ostringstream
os;
2228 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2229 std::cerr <<
os.str();
2234 std::ostringstream
os;
2235 os << *
prefix <<
"Done: Map is empty on all processes, "
2236 "so all output PIDs are invalid (-1)."
2238 std::cerr <<
os.str();
2240 for (Teuchos::ArrayView<int>::size_type
k = 0;
k <
PIDs.size(); ++
k) {
2241 PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2252 std::ostringstream
os;
2254 std::cerr <<
os.str();
2258 std::ostringstream
os;
2259 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2260 std::cerr <<
os.str();
2263 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs);
2265 std::ostringstream
os;
2266 os << *
prefix <<
"Done; getDirectoryEntries returned "
2271 std::cerr <<
os.str();
2276template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2278 using exec_space =
typename Node::device_type::execution_space;
2279 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2285 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2298template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2299Teuchos::RCP<const Teuchos::Comm<int>>
2304template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2309 using Teuchos::outArg;
2310 using Teuchos::REDUCE_MIN;
2311 using Teuchos::reduceAll;
2314 std::unique_ptr<std::string>
prefix;
2317 comm_.getRawPtr(),
"Map",
"checkIsDist");
2318 std::ostringstream
os;
2320 std::cerr <<
os.str();
2323 bool global =
false;
2324 if (comm_->getSize() > 1) {
2328 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2341 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2342 if (allLocalRep != 1) {
2352 std::ostringstream os;
2353 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2355 std::cerr << os.str();
2362template <
class LocalOrdinal,
class GlobalOrdinal>
2363Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2365 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2366 typedef LocalOrdinal LO;
2367 typedef GlobalOrdinal GO;
2368 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2369 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2372template <
class LocalOrdinal,
class GlobalOrdinal>
2373Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2375 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2376 typedef LocalOrdinal LO;
2377 typedef GlobalOrdinal GO;
2378 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2379 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2382template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2383Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2385 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2388 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2390 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2393template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2394Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2396 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2400 const GlobalOrdinal indexBase = 0;
2403 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2406template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2407Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2409 const size_t localNumElements,
2410 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2413 const GlobalOrdinal indexBase = 0;
2415 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2418template <
class LocalOrdinal,
class GlobalOrdinal>
2419Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2421 const size_t localNumElements,
2422 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2423 typedef LocalOrdinal LO;
2424 typedef GlobalOrdinal GO;
2430template <
class LocalOrdinal,
class GlobalOrdinal>
2431Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2433 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2434 typedef LocalOrdinal LO;
2435 typedef GlobalOrdinal GO;
2441template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2442Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2444 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2448 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2452 const GlobalOrdinal indexBase = 0;
2454 return rcp(
new map_type(INV, elementList, indexBase, comm));
2457template <
class LO,
class GO,
class NT>
2458Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2460 using Details::verbosePrintArray;
2463 using Teuchos::Array;
2464 using Teuchos::ArrayView;
2470 const bool verbose = Details::Behavior::verbose(
"Map");
2471 std::unique_ptr<std::string> prefix;
2473 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2474 prefix = Details::createPrefix(
2475 comm.getRawPtr(),
"createOneToOne(Map)");
2476 std::ostringstream os;
2477 os << *prefix <<
"Start" << endl;
2480 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2481 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2482 const int myRank = M->getComm()->getRank();
2488 if (!M->isDistributed()) {
2495 const GST numGlobalEntries = M->getGlobalNumElements();
2496 if (M->isContiguous()) {
2497 const size_t numLocalEntries =
2498 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2500 std::ostringstream os;
2501 os << *prefix <<
"Input is locally replicated & contiguous; "
2503 << numLocalEntries << endl;
2507 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2508 M->getIndexBase(), M->getComm()));
2510 std::ostringstream os;
2511 os << *prefix <<
"Done" << endl;
2517 std::ostringstream os;
2518 os << *prefix <<
"Input is locally replicated & noncontiguous"
2522 ArrayView<const GO> myGids =
2523 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2525 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2528 std::ostringstream os;
2529 os << *prefix <<
"Done" << endl;
2534 }
else if (M->isContiguous()) {
2536 std::ostringstream os;
2537 os << *prefix <<
"Input is distributed & contiguous" << endl;
2545 std::ostringstream os;
2546 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2550 const size_t numMyElems = M->getLocalNumElements();
2551 ArrayView<const GO> myElems = M->getLocalElementList();
2552 Array<int> owner_procs_vec(numMyElems);
2555 std::ostringstream os;
2556 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2561 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2563 std::ostringstream os;
2564 os << *prefix <<
"getDirectoryEntries result: ";
2570 Array<GO> myOwned_vec(numMyElems);
2571 size_t numMyOwnedElems = 0;
2572 for (
size_t i = 0; i < numMyElems; ++i) {
2573 const GO GID = myElems[i];
2574 const int owner = owner_procs_vec[i];
2576 if (myRank == owner) {
2577 myOwned_vec[numMyOwnedElems++] = GID;
2580 myOwned_vec.resize(numMyOwnedElems);
2583 std::ostringstream os;
2584 os << *prefix <<
"Create Map: ";
2589 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2590 M->getIndexBase(), M->getComm()));
2592 std::ostringstream os;
2593 os << *prefix <<
"Done" << endl;
2600template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2601Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2604 using Details::Behavior;
2605 using Details::verbosePrintArray;
2608 using Teuchos::Array;
2609 using Teuchos::ArrayView;
2612 using Teuchos::toString;
2613 using LO = LocalOrdinal;
2614 using GO = GlobalOrdinal;
2617 const bool verbose = Behavior::verbose(
"Map");
2618 std::unique_ptr<std::string> prefix;
2620 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2621 prefix = Details::createPrefix(
2622 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2623 std::ostringstream os;
2624 os << *prefix <<
"Start" << endl;
2627 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2634 std::ostringstream os;
2635 os << *prefix <<
"Initialize Directory" << endl;
2638 directory.initialize(*M, tie_break);
2640 std::ostringstream os;
2641 os << *prefix <<
"Done initializing Directory" << endl;
2644 size_t numMyElems = M->getLocalNumElements();
2645 ArrayView<const GO> myElems = M->getLocalElementList();
2646 Array<int> owner_procs_vec(numMyElems);
2648 std::ostringstream os;
2649 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2654 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2656 std::ostringstream os;
2657 os << *prefix <<
"getDirectoryEntries result: ";
2663 const int myRank = M->getComm()->getRank();
2664 Array<GO> myOwned_vec(numMyElems);
2665 size_t numMyOwnedElems = 0;
2666 for (
size_t i = 0; i < numMyElems; ++i) {
2667 const GO GID = myElems[i];
2668 const int owner = owner_procs_vec[i];
2669 if (myRank == owner) {
2670 myOwned_vec[numMyOwnedElems++] = GID;
2673 myOwned_vec.resize(numMyOwnedElems);
2678 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2680 std::ostringstream os;
2681 os << *prefix <<
"Create Map: ";
2686 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2689 std::ostringstream os;
2690 os << *prefix <<
"Done" << endl;
2698template <
class p
ids_view_type>
2701 pids_view_type pids;
2703 SortToFit(
int _myRank, pids_view_type _pids)
2708 bool operator()(
size_t i,
size_t j)
const {
2709 if (pids(i) == myRank) {
2710 if (pids(j) == myRank)
2715 if (pids(j) == myRank)
2725template <
class LO,
class GO,
class NT>
2726Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2728 Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
constM =
M;
2738 const pid_type myRank =
M->getComm()->getRank();
2739 const size_t numMyElems =
M->getLocalNumElements();
2741 Kokkos::View<pid_type*, typename NT::memory_space> pids(
"pids",
numMyElems);
2743 auto gids_vec =
M->getLocalElementList();
2746 Kokkos::View<pid_type*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
pids_h(
pids_vec.data(),
pids_vec.size());
2747 Kokkos::deep_copy(pids,
pids_h);
2750 auto gids =
M->getMyGlobalIndicesDevice();
2752 auto policy = Kokkos::RangePolicy<size_t, typename NT::execution_space>(0,
numMyElems);
2754 Kokkos::View<size_t*, typename NT::memory_space> idx(Kokkos::ViewAllocateWithoutInitializing(
"idx"),
numMyElems);
2755 Kokkos::parallel_for(
2758 Tpetra::Details::SortToFit
cmp(myRank, pids);
2759 Kokkos::sort(
typename NT::execution_space(), idx,
cmp);
2761 Kokkos::View<GO*, typename NT::memory_space>
new_gids(Kokkos::ViewAllocateWithoutInitializing(
"new_gids"),
numMyElems);
2762 Kokkos::parallel_for(
2784#define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2786 template class Map<LO, GO, NODE>; \
2788 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2789 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2790 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2792 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2793 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2794 const size_t localNumElements, \
2795 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2797 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2798 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2799 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2801 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2802 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2803 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2805 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2806 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2808 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2809 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2810 const Tpetra::Details::TieBreak<LO, GO>& tie_break); \
2812 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2813 createOneToOneAndMakeOverlappingMapFitted(Teuchos::RCP<const Map<LO, GO, NODE>>& M);
2816#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2817 template Teuchos::RCP<const Map<LO, GO>> \
2818 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2820 template Teuchos::RCP<const Map<LO, GO>> \
2821 createContigMap<LO, GO>(global_size_t, size_t, \
2822 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2824 template Teuchos::RCP<const Map<LO, GO>> \
2825 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2826 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2828 template Teuchos::RCP<const Map<LO, GO>> \
2829 createUniformContigMap<LO, GO>(const global_size_t, \
2830 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::iallreduce.
Declaration of Tpetra::Details::initializeKokkos.
Declaration of Tpetra::Details::printOnce.
Declaration of the Tpetra::Map class and related nonmember constructors.
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.
::Tpetra::Details::FixedHashTable< global_ordinal_type, local_ordinal_type, device_type > global_to_local_table_type
Type of a mapping from global IDs to local IDs.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
Node node_type
Legacy typedef that will go away at some point.
Kokkos::View< const global_ordinal_type *, Kokkos::LayoutLeft, device_type > lgMap_
A mapping from local IDs to global IDs.
Map()
Default constructor (that does nothing).
GlobalOrdinal global_ordinal_type
The type of global indices.
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.
global_to_local_table_type glMap_
A mapping from global IDs to local IDs.
local_map_type getLocalMap() const
Get the LocalMap for Kokkos-Kernels.
global_indices_array_type getMyGlobalIndices() const
Return a view of the global indices owned by this process.
void computeGlobalConstants() const
Compute global constants for the map. This method needs to be called collectively over all processes ...
typename Node::device_type device_type
This class' Kokkos::Device specialization.
Implementation details of Tpetra.
Nonmember function that computes a residual Computes R = B - A * X.
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(int *argc, char ***argv, int myRank)
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.
Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > createOneToOneAndMakeOverlappingMapFitted(Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &M)
Creates a one-to-one version of the given Map where each GID lives on only one process....
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...