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"
41 void checkMapInputArray(
const char ctorName[],
42 const void* indexList,
43 const size_t indexListSize,
44 const Teuchos::Comm<int>*
const comm) {
47 const bool debug = Behavior::debug(
"Map");
50 using Teuchos::outArg;
51 using Teuchos::REDUCE_MIN;
52 using Teuchos::reduceAll;
54 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
55 const bool verbose = Behavior::verbose(
"Map");
56 std::ostringstream lclErrStrm;
59 if (indexListSize != 0 && indexList ==
nullptr) {
62 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
64 << indexListSize <<
" != 0." << endl;
68 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
69 if (gblSuccess != 1) {
70 std::ostringstream gblErrStrm;
71 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
" detected a problem with the input array "
72 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
76 using ::Tpetra::Details::gathervPrint;
79 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
84 template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
85 void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
86 using LO = LocalOrdinal;
87 using GO = GlobalOrdinal;
88 using exec_space =
typename ViewType::device_type::execution_space;
89 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
90 const LO numLocalElements = entryList.extent(0);
94 typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
100 Kokkos::parallel_reduce(
101 range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
102 GO entry_0 = entryList[0];
103 GO entry_i = entryList[i];
106 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
107 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
108 l_firstCont = entry_0;
110 if (entry_i - entry_0 != i && l_lastCont.val >= i) {
112 l_lastCont.val = i - 1;
113 l_lastCont.loc = entryList[i - 1];
114 }
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
117 l_lastCont.loc = entry_i;
120 Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
123 lastContiguousGID_val = myMinLoc.loc;
124 lastContiguousGID_loc = myMinLoc.val;
131 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
134 : comm_(new Teuchos::SerialComm<int>())
136 , numGlobalElements_(0)
137 , numLocalElements_(0)
138 , minMyGID_(Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid())
139 , maxMyGID_(Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid())
140 , minAllGID_(Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid())
141 , maxAllGID_(Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid())
142 , firstContiguousGID_(Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid())
143 , lastContiguousGID_(Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid())
147 , distributed_(false)
149 directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
154 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
158 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
162 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
165 using Teuchos::broadcast;
166 using Teuchos::outArg;
167 using Teuchos::REDUCE_MAX;
168 using Teuchos::REDUCE_MIN;
169 using Teuchos::reduceAll;
170 using Teuchos::typeName;
173 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
174 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
176 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
180 std::unique_ptr<std::string> prefix;
183 comm_.getRawPtr(),
"Map", funcName);
184 std::ostringstream os;
185 os << *prefix <<
"Start" << endl;
186 std::cerr << os.str();
194 GST proc0NumGlobalElements = numGlobalElements;
195 broadcast(*comm_, 0, outArg(proc0NumGlobalElements));
196 GST minNumGlobalElements = numGlobalElements;
197 GST maxNumGlobalElements = numGlobalElements;
198 reduceAll(*comm, REDUCE_MIN, numGlobalElements,
199 outArg(minNumGlobalElements));
200 reduceAll(*comm, REDUCE_MAX, numGlobalElements,
201 outArg(maxNumGlobalElements));
202 TEUCHOS_TEST_FOR_EXCEPTION(minNumGlobalElements != maxNumGlobalElements ||
203 numGlobalElements != minNumGlobalElements,
204 std::invalid_argument, exPfx <<
"All processes must "
205 "provide the same number of global elements. Process 0 set "
207 << proc0NumGlobalElements <<
". The "
209 << comm->getRank() <<
" set "
211 << numGlobalElements <<
". The min "
212 "and max values over all processes are "
213 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements <<
".");
215 GO proc0IndexBase = indexBase;
216 broadcast<int, GO>(*comm_, 0, outArg(proc0IndexBase));
217 GO minIndexBase = indexBase;
218 GO maxIndexBase = indexBase;
219 reduceAll(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
220 reduceAll(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
221 TEUCHOS_TEST_FOR_EXCEPTION(minIndexBase != maxIndexBase || indexBase != minIndexBase,
222 std::invalid_argument, exPfx <<
"All processes must "
223 "provide the same indexBase argument. Process 0 set "
225 << proc0IndexBase <<
". The calling process " << comm->getRank() <<
" set indexBase=" << indexBase <<
". The min and max values over all processes are " << minIndexBase <<
" resp. " << maxIndexBase <<
".");
245 TEUCHOS_TEST_FOR_EXCEPTION(
246 (numGlobalElements < 1 && numGlobalElements != 0),
247 std::invalid_argument, exPfx <<
"numGlobalElements (= " << numGlobalElements <<
") must be nonnegative.");
249 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements == GSTI, std::invalid_argument, exPfx <<
"You provided numGlobalElements = Teuchos::OrdinalTraits<"
250 "Tpetra::global_size_t>::invalid(). This version of the "
251 "constructor requires a valid value of numGlobalElements. "
252 "You probably mistook this constructor for the \"contiguous "
253 "nonuniform\" constructor, which can compute the global "
254 "number of elements for you if you set numGlobalElements to "
255 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
257 size_t numLocalElements = 0;
258 if (lOrG == GloballyDistributed) {
273 const GST numProcs =
static_cast<GST
>(comm_->getSize());
274 const GST myRank =
static_cast<GST
>(comm_->getRank());
275 const GST quotient = numGlobalElements / numProcs;
276 const GST remainder = numGlobalElements - quotient * numProcs;
279 if (myRank < remainder) {
280 numLocalElements =
static_cast<size_t>(1) + static_cast<size_t>(quotient);
283 startIndex = as<GO>(myRank) * as<GO>(numLocalElements);
285 numLocalElements = as<size_t>(quotient);
286 startIndex = as<GO>(myRank) * as<GO>(numLocalElements) +
290 minMyGID_ = indexBase + startIndex;
291 maxMyGID_ = indexBase + startIndex + numLocalElements - 1;
292 minAllGID_ = indexBase;
293 maxAllGID_ = indexBase + numGlobalElements - 1;
294 distributed_ = (numProcs > 1);
296 numLocalElements = as<size_t>(numGlobalElements);
297 minMyGID_ = indexBase;
298 maxMyGID_ = indexBase + numGlobalElements - 1;
299 distributed_ =
false;
302 minAllGID_ = indexBase;
303 maxAllGID_ = indexBase + numGlobalElements - 1;
304 indexBase_ = indexBase;
305 numGlobalElements_ = numGlobalElements;
306 numLocalElements_ = numLocalElements;
307 firstContiguousGID_ = minMyGID_;
308 lastContiguousGID_ = maxMyGID_;
315 std::ostringstream os;
316 os << *prefix <<
"Done" << endl;
317 std::cerr << os.str();
321 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
324 const size_t numLocalElements,
326 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
329 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
332 using Teuchos::broadcast;
333 using Teuchos::outArg;
334 using Teuchos::REDUCE_MAX;
335 using Teuchos::REDUCE_MIN;
336 using Teuchos::REDUCE_SUM;
337 using Teuchos::reduceAll;
341 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
342 const char funcName[] =
343 "Map(gblNumInds,lclNumInds,indexBase,comm)";
345 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
346 const char suffix[] =
347 ". Please report this bug to the Tpetra developers.";
351 std::unique_ptr<std::string> prefix;
354 comm_.getRawPtr(),
"Map", funcName);
355 std::ostringstream os;
356 os << *prefix <<
"Start" << endl;
357 std::cerr << os.str();
364 GST debugGlobalSum{};
366 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
367 numGlobalElements, numLocalElements, indexBase, comm);
382 scan<int, GO>(*comm, REDUCE_SUM, numLocalElements, outArg(scanResult));
383 const GO myOffset = scanResult - numLocalElements;
385 if (numGlobalElements != GSTI) {
386 numGlobalElements_ = numGlobalElements;
392 const int numProcs = comm->getSize();
393 GST globalSum = scanResult;
395 broadcast(*comm, numProcs - 1, outArg(globalSum));
397 numGlobalElements_ = globalSum;
401 TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx <<
"globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum << suffix);
404 numLocalElements_ = numLocalElements;
405 indexBase_ = indexBase;
406 minAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
407 maxAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
408 minMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
409 maxMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
410 firstContiguousGID_ = minMyGID_;
411 lastContiguousGID_ = maxMyGID_;
413 distributed_ = checkIsDist();
419 std::ostringstream os;
420 os << *prefix <<
"Done" << endl;
421 std::cerr << os.str();
425 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
429 const char errorMessagePrefix[],
431 const size_t numLocalElements,
432 const global_ordinal_type indexBase,
433 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const {
439 using Teuchos::broadcast;
440 using Teuchos::outArg;
442 using Teuchos::REDUCE_MAX;
443 using Teuchos::REDUCE_MIN;
444 using Teuchos::REDUCE_SUM;
445 using Teuchos::reduceAll;
446 using GO = global_ordinal_type;
448 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
458 GST debugGlobalSum = 0;
459 reduceAll<int, GST>(*comm, REDUCE_SUM,
static_cast<GST
>(numLocalElements),
460 outArg(debugGlobalSum));
464 GST proc0NumGlobalElements = numGlobalElements;
465 broadcast<int, GST>(*comm_, 0, outArg(proc0NumGlobalElements));
466 GST minNumGlobalElements = numGlobalElements;
467 GST maxNumGlobalElements = numGlobalElements;
468 reduceAll<int, GST>(*comm, REDUCE_MIN, numGlobalElements,
469 outArg(minNumGlobalElements));
470 reduceAll<int, GST>(*comm, REDUCE_MAX, numGlobalElements,
471 outArg(maxNumGlobalElements));
472 TEUCHOS_TEST_FOR_EXCEPTION(minNumGlobalElements != maxNumGlobalElements ||
473 numGlobalElements != minNumGlobalElements,
474 std::invalid_argument, errorMessagePrefix <<
"All processes "
475 "must provide the same number of global elements, even if "
477 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
478 "(which signals that the Map should compute the global "
479 "number of elements). Process 0 set numGlobalElements"
481 << proc0NumGlobalElements <<
". The calling process " << comm->getRank() <<
" set numGlobalElements=" << numGlobalElements <<
". The min and max values over all "
483 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements <<
".");
485 GO proc0IndexBase = indexBase;
486 broadcast<int, GO>(*comm_, 0, outArg(proc0IndexBase));
487 GO minIndexBase = indexBase;
488 GO maxIndexBase = indexBase;
489 reduceAll<int, GO>(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
490 reduceAll<int, GO>(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
491 TEUCHOS_TEST_FOR_EXCEPTION(minIndexBase != maxIndexBase || indexBase != minIndexBase,
492 std::invalid_argument, errorMessagePrefix <<
"All processes must provide the same indexBase argument. "
493 "Process 0 set indexBase = "
494 << proc0IndexBase <<
". The "
496 << comm->getRank() <<
" set indexBase=" << indexBase <<
". The min and max values over all "
498 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
502 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements != GSTI &&
503 debugGlobalSum != numGlobalElements,
504 std::invalid_argument,
505 errorMessagePrefix <<
"The sum of each process' number of "
506 "indices over all processes, "
507 << debugGlobalSum <<
", != "
508 <<
"numGlobalElements=" << numGlobalElements <<
". If you "
509 "would like this constructor to compute numGlobalElements "
510 "for you, you may set numGlobalElements="
511 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
512 "on input. Please note that this is NOT necessarily -1.");
514 return debugGlobalSum;
517 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
518 void Map<LocalOrdinal, GlobalOrdinal, Node>::
519 initWithNonownedHostIndexList(
520 const char errorMessagePrefix[],
522 const Kokkos::View<
const global_ordinal_type*,
525 Kokkos::MemoryUnmanaged>& entryList_host,
526 const global_ordinal_type indexBase,
527 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
530 using Kokkos::LayoutLeft;
531 using Kokkos::subview;
533 using Kokkos::view_alloc;
534 using Kokkos::WithoutInitializing;
536 using Teuchos::broadcast;
537 using Teuchos::outArg;
539 using Teuchos::REDUCE_MAX;
540 using Teuchos::REDUCE_MIN;
541 using Teuchos::REDUCE_SUM;
542 using Teuchos::reduceAll;
544 using GO = global_ordinal_type;
546 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
548 TEUCHOS_TEST_FOR_EXCEPTION(!Kokkos::is_initialized(), std::runtime_error,
549 errorMessagePrefix <<
"The Kokkos execution space "
550 << Teuchos::TypeNameTraits<execution_space>::name()
551 <<
" has not been initialized. "
552 "Please initialize it before creating a Map.")
565 const
size_t numLocalElements(entryList_host.size());
567 initialNonuniformDebugCheck(errorMessagePrefix, numGlobalElements,
568 numLocalElements, indexBase, comm);
578 if (numGlobalElements != GSTI) {
579 numGlobalElements_ = numGlobalElements;
581 reduceAll(*comm, REDUCE_SUM,
582 static_cast<GST>(numLocalElements),
583 outArg(numGlobalElements_));
609 numLocalElements_ = numLocalElements;
610 indexBase_ = indexBase;
612 minMyGID_ = indexBase_;
613 maxMyGID_ = indexBase_;
623 if (numLocalElements_ > 0) {
627 typename decltype(lgMap_)::non_const_type lgMap(view_alloc(
"lgMap", WithoutInitializing), numLocalElements_);
629 Kokkos::create_mirror_view(Kokkos::HostSpace(), lgMap);
637 firstContiguousGID_ = entryList_host[0];
638 lastContiguousGID_ = firstContiguousGID_ + 1;
646 lgMap_host[0] = firstContiguousGID_;
648 for (; i < numLocalElements_; ++i) {
649 const GO curGid = entryList_host[i];
650 const LO curLid = as<LO>(i);
652 if (lastContiguousGID_ != curGid)
break;
658 lgMap_host[curLid] = curGid;
659 ++lastContiguousGID_;
661 --lastContiguousGID_;
667 minMyGID_ = firstContiguousGID_;
668 maxMyGID_ = lastContiguousGID_;
672 LO firstNonContiguous_loc = i;
674 const std::pair<size_t, size_t> ncRange(i, entryList_host.extent(0));
675 auto nonContigGids_host = subview(entryList_host, ncRange);
676 TEUCHOS_TEST_FOR_EXCEPTION(static_cast<size_t>(nonContigGids_host.extent(0)) !=
677 static_cast<size_t>(entryList_host.extent(0) - i),
679 "Tpetra::Map noncontiguous constructor: "
680 "nonContigGids_host.extent(0) = "
681 << nonContigGids_host.extent(0)
682 <<
" != entryList_host.extent(0) - i = "
683 << (entryList_host.extent(0) - i) <<
" = "
684 << entryList_host.extent(0) <<
" - " << i
685 <<
". Please report this bug to the Tpetra developers.");
689 View<GO*, LayoutLeft, device_type>
690 nonContigGids(view_alloc(
"nonContigGids", WithoutInitializing),
691 nonContigGids_host.size());
695 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
697 glMap_ = global_to_local_table_type(nonContigGids,
698 firstNonContiguous_loc);
700 glMapHost_ = global_to_local_table_host_type(glMap_);
708 for (; i < numLocalElements_; ++i) {
709 const GO curGid = entryList_host[i];
710 const LO curLid =
static_cast<LO
>(i);
711 lgMap_host[curLid] = curGid;
715 if (curGid < minMyGID_) {
718 if (curGid > maxMyGID_) {
730 lgMapHost_ = lgMap_host;
733 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
734 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
738 firstContiguousGID_ = indexBase_ + 1;
739 lastContiguousGID_ = indexBase_;
764 if (std::numeric_limits<GO>::is_signed) {
767 (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
770 minMaxInput[0] = -minMyGID_;
771 minMaxInput[1] = maxMyGID_;
772 minMaxInput[2] = localDist;
778 reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
779 minAllGID_ = -minMaxOutput[0];
780 maxAllGID_ = minMaxOutput[1];
781 const GO globalDist = minMaxOutput[2];
782 distributed_ = (comm_->getSize() > 1 && globalDist == 1);
785 reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
786 reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
787 distributed_ = checkIsDist();
792 TEUCHOS_TEST_FOR_EXCEPTION(
793 minAllGID_ < indexBase_,
794 std::invalid_argument,
795 "Tpetra::Map constructor (noncontiguous): "
796 "Minimum global ID = "
797 << minAllGID_ <<
" over all process(es) is "
798 "less than the given indexBase = "
799 << indexBase_ <<
".");
805 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
808 const GlobalOrdinal indexList[],
809 const LocalOrdinal indexListSize,
810 const GlobalOrdinal indexBase,
811 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
814 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
816 const char funcName[] =
817 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
820 std::unique_ptr<std::string> prefix;
823 comm_.getRawPtr(),
"Map", funcName);
824 std::ostringstream os;
825 os << *prefix <<
"Start" << endl;
826 std::cerr << os.str();
831 checkMapInputArray(
"(GST, const GO[], LO, GO, comm)",
832 indexList, static_cast<size_t>(indexListSize),
837 const GlobalOrdinal*
const indsRaw = indexListSize == 0 ? NULL : indexList;
838 Kokkos::View<
const GlobalOrdinal*,
841 Kokkos::MemoryUnmanaged>
842 inds(indsRaw, indexListSize);
843 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
846 std::ostringstream os;
847 os << *prefix <<
"Done" << endl;
848 std::cerr << os.str();
852 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
855 const Teuchos::ArrayView<const GlobalOrdinal>& entryList,
856 const GlobalOrdinal indexBase,
857 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
860 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
862 const char* funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
865 std::unique_ptr<std::string> prefix;
868 comm_.getRawPtr(),
"Map", funcName);
869 std::ostringstream os;
870 os << *prefix <<
"Start" << endl;
871 std::cerr << os.str();
876 const size_t numLclInds =
static_cast<size_t>(entryList.size());
877 checkMapInputArray(
"(GST, ArrayView, GO, comm)",
878 entryList.getRawPtr(), numLclInds,
883 const GlobalOrdinal*
const indsRaw =
884 numLclInds == 0 ? NULL : entryList.getRawPtr();
885 Kokkos::View<
const GlobalOrdinal*,
888 Kokkos::MemoryUnmanaged>
889 inds(indsRaw, numLclInds);
890 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
893 std::ostringstream os;
894 os << *prefix <<
"Done" << endl;
895 std::cerr << os.str();
899 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
902 const Kokkos::View<const GlobalOrdinal*, device_type>& entryList,
903 const GlobalOrdinal indexBase,
904 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
907 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
908 using Kokkos::LayoutLeft;
909 using Kokkos::subview;
911 using Kokkos::view_alloc;
912 using Kokkos::WithoutInitializing;
915 using Teuchos::ArrayView;
917 using Teuchos::broadcast;
918 using Teuchos::outArg;
920 using Teuchos::REDUCE_MAX;
921 using Teuchos::REDUCE_MIN;
922 using Teuchos::REDUCE_SUM;
923 using Teuchos::reduceAll;
924 using Teuchos::typeName;
928 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
929 const char funcName[] =
930 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
933 std::unique_ptr<std::string> prefix;
936 comm_.getRawPtr(),
"Map", funcName);
937 std::ostringstream os;
938 os << *prefix <<
"Start" << endl;
939 std::cerr << os.str();
944 checkMapInputArray(
"(GST, Kokkos::View, GO, comm)",
946 static_cast<size_t>(entryList.extent(0)),
960 const size_t numLocalElements(entryList.size());
962 initialNonuniformDebugCheck(funcName, numGlobalElements,
963 numLocalElements, indexBase, comm);
973 if (numGlobalElements != GSTI) {
974 numGlobalElements_ = numGlobalElements;
976 reduceAll(*comm, REDUCE_SUM,
977 static_cast<GST>(numLocalElements),
978 outArg(numGlobalElements_));
1004 numLocalElements_ = numLocalElements;
1005 indexBase_ = indexBase;
1007 minMyGID_ = indexBase_;
1008 maxMyGID_ = indexBase_;
1018 if (numLocalElements_ > 0) {
1022 typename decltype(lgMap_)::non_const_type lgMap(view_alloc(
"lgMap", WithoutInitializing), numLocalElements_);
1027 LO lastContiguousGID_loc;
1028 computeConstantsOnDevice(entryList, minMyGID_, maxMyGID_, firstContiguousGID_, lastContiguousGID_, lastContiguousGID_loc);
1029 LO firstNonContiguous_loc = lastContiguousGID_loc + 1;
1030 auto nonContigGids = Kokkos::subview(entryList, std::pair<size_t, size_t>(firstNonContiguous_loc, entryList.extent(0)));
1034 firstNonContiguous_loc);
1040 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1041 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1045 firstContiguousGID_ = indexBase_ + 1;
1046 lastContiguousGID_ = indexBase_;
1071 if (std::numeric_limits<GO>::is_signed) {
1073 const GO localDist =
1074 (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
1077 minMaxInput[0] = -minMyGID_;
1078 minMaxInput[1] = maxMyGID_;
1079 minMaxInput[2] = localDist;
1082 minMaxOutput[0] = 0;
1083 minMaxOutput[1] = 0;
1084 minMaxOutput[2] = 0;
1085 reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1086 minAllGID_ = -minMaxOutput[0];
1087 maxAllGID_ = minMaxOutput[1];
1088 const GO globalDist = minMaxOutput[2];
1089 distributed_ = (comm_->getSize() > 1 && globalDist == 1);
1092 reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
1093 reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
1094 distributed_ = checkIsDist();
1097 contiguous_ =
false;
1099 TEUCHOS_TEST_FOR_EXCEPTION(
1100 minAllGID_ < indexBase_,
1101 std::invalid_argument,
1102 "Tpetra::Map constructor (noncontiguous): "
1103 "Minimum global ID = "
1104 << minAllGID_ <<
" over all process(es) is "
1105 "less than the given indexBase = "
1106 << indexBase_ <<
".");
1112 std::ostringstream os;
1113 os << *prefix <<
"Done" << endl;
1114 std::cerr << os.str();
1118 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1120 if (!Kokkos::is_initialized()) {
1121 std::ostringstream os;
1122 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1123 "Kokkos::finalize() has been called. This is user error! There are "
1124 "two likely causes: "
1126 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1128 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1129 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1130 "or Tpetra::finalize()."
1133 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1135 ::Tpetra::Details::printOnce(std::cerr, os.str(),
1136 this->getComm().getRawPtr());
1138 using ::Tpetra::Details::mpiIsFinalized;
1139 using ::Tpetra::Details::mpiIsInitialized;
1140 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1142 Teuchos::RCP<const Teuchos::Comm<int>> comm = this->getComm();
1143 if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
1144 mpiIsInitialized() && mpiIsFinalized()) {
1150 std::ostringstream os;
1151 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1152 "MPI_Finalize() has been called. This is user error! There are "
1153 "two likely causes: "
1155 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1157 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1158 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1159 "Tpetra::finalize()."
1162 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1164 ::Tpetra::Details::printOnce(std::cerr, os.str(), comm.getRawPtr());
1172 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1174 TEUCHOS_TEST_FOR_EXCEPTION(
1175 getComm().is_null(), std::logic_error,
1176 "Tpetra::Map::isOneToOne: "
1177 "getComm() returns null. Please report this bug to the Tpetra "
1182 return directory_->isOneToOne(*
this);
1185 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1189 if (isContiguous()) {
1190 if (globalIndex < getMinGlobalIndex() ||
1191 globalIndex > getMaxGlobalIndex()) {
1192 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1194 return static_cast<LocalOrdinal
>(globalIndex - getMinGlobalIndex());
1195 }
else if (globalIndex >= firstContiguousGID_ &&
1196 globalIndex <= lastContiguousGID_) {
1197 return static_cast<LocalOrdinal
>(globalIndex - firstContiguousGID_);
1203 return glMapHost_.get(globalIndex);
1207 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1211 if (localIndex < getMinLocalIndex() || localIndex > getMaxLocalIndex()) {
1212 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
1214 if (isContiguous()) {
1215 return getMinGlobalIndex() + localIndex;
1222 return lgMapHost_[localIndex];
1226 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1229 if (localIndex < getMinLocalIndex() || localIndex > getMaxLocalIndex()) {
1236 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1239 return this->getLocalElement(globalIndex) !=
1240 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1243 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1248 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1253 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1258 getMinGlobalIndex(), getMaxGlobalIndex(),
1259 firstContiguousGID_, lastContiguousGID_,
1260 getLocalNumElements(), isContiguous());
1263 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1266 using Teuchos::outArg;
1267 using Teuchos::REDUCE_MIN;
1268 using Teuchos::reduceAll;
1277 }
else if (getComm()->getSize() != map.
getComm()->getSize()) {
1286 }
else if (isContiguous() && isUniform() &&
1293 lgMap_.extent(0) != 0 && map.lgMap_.extent(0) != 0 &&
1294 lgMap_.data() == map.lgMap_.data()) {
1308 TEUCHOS_TEST_FOR_EXCEPTION(
1310 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1311 "checked that this condition is true above, but it's false here. "
1312 "Please report this bug to the Tpetra developers.");
1315 const int locallyCompat =
1318 int globallyCompat = 0;
1319 reduceAll<int, int>(*comm_, REDUCE_MIN, locallyCompat, outArg(globallyCompat));
1320 return (globallyCompat == 1);
1323 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1326 using Teuchos::ArrayView;
1328 using size_type =
typename ArrayView<const GO>::size_type;
1348 if (isContiguous()) {
1352 TEUCHOS_TEST_FOR_EXCEPTION(
1353 !this->isContiguous() || map.
isContiguous(), std::logic_error,
1354 "Tpetra::Map::locallySameAs: BUG");
1356 const GO minLhsGid = this->getMinGlobalIndex();
1357 const size_type numRhsElts = rhsElts.size();
1358 for (size_type k = 0; k < numRhsElts; ++k) {
1359 const GO curLhsGid = minLhsGid +
static_cast<GO
>(k);
1360 if (curLhsGid != rhsElts[k]) {
1367 TEUCHOS_TEST_FOR_EXCEPTION(
1368 this->isContiguous() || !map.
isContiguous(), std::logic_error,
1369 "Tpetra::Map::locallySameAs: BUG");
1370 ArrayView<const GO> lhsElts = this->getLocalElementList();
1372 const size_type numLhsElts = lhsElts.size();
1373 for (size_type k = 0; k < numLhsElts; ++k) {
1374 const GO curRhsGid = minRhsGid +
static_cast<GO
>(k);
1375 if (curRhsGid != lhsElts[k]) {
1380 }
else if (this->lgMap_.data() == map.lgMap_.data()) {
1388 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1390 auto lhsLclMap = getLocalMap();
1393 LocalOrdinal numMismatchedElements = 0;
1394 Kokkos::parallel_reduce(
1395 "Tpetra::Map::locallySameAs",
1396 range_type(0, this->getLocalNumElements()),
1397 KOKKOS_LAMBDA(
const LocalOrdinal lid, LocalOrdinal& numMismatches) {
1398 if (lhsLclMap.getGlobalElement(lid) != rhsLclMap.getGlobalElement(lid))
1401 numMismatchedElements);
1403 return (numMismatchedElements == 0);
1409 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1420 auto lmap2 = this->getLocalMap();
1422 auto numLocalElements1 = lmap1.getLocalNumElements();
1423 auto numLocalElements2 = lmap2.getLocalNumElements();
1425 if (numLocalElements1 > numLocalElements2) {
1430 if (lmap1.isContiguous() && lmap2.isContiguous()) {
1432 return ((lmap1.getMinGlobalIndex() == lmap2.getMinGlobalIndex()) &&
1433 (lmap1.getMaxGlobalIndex() <= lmap2.getMaxGlobalIndex()));
1436 if (lmap1.getMinGlobalIndex() < lmap2.getMinGlobalIndex() ||
1437 lmap1.getMaxGlobalIndex() > lmap2.getMaxGlobalIndex()) {
1445 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1449 Kokkos::parallel_reduce(
1451 range_type(0, numLocalElements1),
1452 KOKKOS_LAMBDA(
const LO i, LO& diff) {
1453 diff += (lmap1.getGlobalElement(i) != lmap2.getGlobalElement(i));
1457 return (numDiff == 0);
1460 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1463 using Teuchos::outArg;
1464 using Teuchos::REDUCE_MIN;
1465 using Teuchos::reduceAll;
1474 }
else if (getComm()->getSize() != map.
getComm()->getSize()) {
1493 }
else if (isContiguous() && isUniform() &&
1514 const int isSame_lcl = locallySameAs(map) ? 1 : 0;
1518 reduceAll<int, int>(*comm_, REDUCE_MIN, isSame_lcl, outArg(isSame_gbl));
1519 return isSame_gbl == 1;
1523 template <
class LO,
class GO,
class DT>
1526 FillLgMap(
const Kokkos::View<GO*, DT>& lgMap,
1529 , startGid_(startGid) {
1530 Kokkos::RangePolicy<LO, typename DT::execution_space>
1531 range(static_cast<LO>(0), static_cast<LO>(lgMap.size()));
1532 Kokkos::parallel_for(range, *
this);
1535 KOKKOS_INLINE_FUNCTION
void operator()(
const LO& lid)
const {
1536 lgMap_(lid) = startGid_ +
static_cast<GO
>(lid);
1540 const Kokkos::View<GO*, DT> lgMap_;
1546 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1547 typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
1552 using const_lg_view_type = decltype(lgMap_);
1553 using lg_view_type =
typename const_lg_view_type::non_const_type;
1557 std::unique_ptr<std::string> prefix;
1560 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1561 std::ostringstream os;
1562 os << *prefix <<
"Start" << endl;
1563 std::cerr << os.str();
1569 const bool needToCreateLocalToGlobalMapping =
1570 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1572 if (needToCreateLocalToGlobalMapping) {
1574 std::ostringstream os;
1575 os << *prefix <<
"Need to create lgMap" << endl;
1576 std::cerr << os.str();
1581 TEUCHOS_TEST_FOR_EXCEPTION(!isContiguous(), std::logic_error,
1582 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1583 "mapping (lgMap_) should have been set up already for a "
1584 "noncontiguous Map. Please report this bug to the Tpetra "
1587 const LO numElts =
static_cast<LO
>(getLocalNumElements());
1589 using Kokkos::view_alloc;
1590 using Kokkos::WithoutInitializing;
1591 lg_view_type lgMap(
"lgMap", numElts);
1593 std::ostringstream os;
1594 os << *prefix <<
"Fill lgMap" << endl;
1595 std::cerr << os.str();
1597 FillLgMap<LO, GO, device_type> fillIt(lgMap, minMyGID_);
1600 std::ostringstream os;
1601 os << *prefix <<
"Copy lgMap to lgMapHost" << endl;
1602 std::cerr << os.str();
1605 auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(), lgMap);
1612 exec_instance.fence();
1616 lgMapHost_ = lgMapHost;
1622 std::ostringstream os;
1623 os << *prefix <<
"Done" << endl;
1624 std::cerr << os.str();
1629 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1630 typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
1635 using const_lg_view_type = decltype(lgMap_);
1636 using lg_view_type =
typename const_lg_view_type::non_const_type;
1640 std::unique_ptr<std::string> prefix;
1643 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1644 std::ostringstream os;
1645 os << *prefix <<
"Start" << endl;
1646 std::cerr << os.str();
1652 const bool needToCreateLocalToGlobalMapping =
1653 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1655 if (needToCreateLocalToGlobalMapping) {
1657 std::ostringstream os;
1658 os << *prefix <<
"Need to create lgMap" << endl;
1659 std::cerr << os.str();
1664 TEUCHOS_TEST_FOR_EXCEPTION(!isContiguous(), std::logic_error,
1665 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1666 "mapping (lgMap_) should have been set up already for a "
1667 "noncontiguous Map. Please report this bug to the Tpetra "
1670 const LO numElts =
static_cast<LO
>(getLocalNumElements());
1672 using Kokkos::view_alloc;
1673 using Kokkos::WithoutInitializing;
1674 lg_view_type lgMap(
"lgMap", numElts);
1676 std::ostringstream os;
1677 os << *prefix <<
"Fill lgMap" << endl;
1678 std::cerr << os.str();
1680 FillLgMap<LO, GO, device_type> fillIt(lgMap, minMyGID_);
1687 std::ostringstream os;
1688 os << *prefix <<
"Done" << endl;
1689 std::cerr << os.str();
1694 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1695 Teuchos::ArrayView<const GlobalOrdinal>
1702 (void)this->getMyGlobalIndices();
1706 const GO* lgMapHostRawPtr = lgMapHost_.data();
1710 return Teuchos::ArrayView<const GO>(
1712 lgMapHost_.extent(0),
1713 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1716 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1718 return distributed_;
1721 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1723 using Teuchos::TypeNameTraits;
1724 std::ostringstream os;
1726 os <<
"Tpetra::Map: {"
1727 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name()
1728 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name()
1729 <<
", NodeType: " << TypeNameTraits<Node>::name();
1730 if (this->getObjectLabel() !=
"") {
1731 os <<
", Label: \"" << this->getObjectLabel() <<
"\"";
1733 os <<
", Global number of entries: " << getGlobalNumElements()
1734 <<
", Number of processes: " << getComm()->getSize()
1735 <<
", Uniform: " << (isUniform() ?
"true" :
"false")
1736 <<
", Contiguous: " << (isContiguous() ?
"true" :
"false")
1737 <<
", Distributed: " << (isDistributed() ?
"true" :
"false")
1746 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1750 using LO = local_ordinal_type;
1754 if (vl < Teuchos::VERB_HIGH) {
1755 return std::string();
1757 auto outStringP = Teuchos::rcp(
new std::ostringstream());
1758 Teuchos::RCP<Teuchos::FancyOStream> outp =
1759 Teuchos::getFancyOStream(outStringP);
1760 Teuchos::FancyOStream& out = *outp;
1762 auto comm = this->getComm();
1763 const int myRank = comm->getRank();
1764 const int numProcs = comm->getSize();
1765 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1766 Teuchos::OSTab tab1(out);
1768 const LO numEnt =
static_cast<LO
>(this->getLocalNumElements());
1769 out <<
"My number of entries: " << numEnt << endl
1770 <<
"My minimum global index: " << this->getMinGlobalIndex() << endl
1771 <<
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
1773 if (vl == Teuchos::VERB_EXTREME) {
1774 out <<
"My global indices: [";
1775 const LO minLclInd = this->getMinLocalIndex();
1776 for (LO k = 0; k < numEnt; ++k) {
1777 out << minLclInd + this->getGlobalElement(k);
1778 if (k + 1 < numEnt) {
1786 return outStringP->str();
1789 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1792 const Teuchos::EVerbosityLevel verbLevel)
const {
1794 using Teuchos::TypeNameTraits;
1795 using Teuchos::VERB_DEFAULT;
1796 using Teuchos::VERB_HIGH;
1797 using Teuchos::VERB_LOW;
1798 using Teuchos::VERB_NONE;
1801 const Teuchos::EVerbosityLevel vl =
1802 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1804 if (vl == VERB_NONE) {
1811 auto comm = this->getComm();
1812 if (comm.is_null()) {
1815 const int myRank = comm->getRank();
1816 const int numProcs = comm->getSize();
1825 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1831 tab0 = Teuchos::rcp(
new Teuchos::OSTab(out));
1832 out <<
"\"Tpetra::Map\":" << endl;
1833 tab1 = Teuchos::rcp(
new Teuchos::OSTab(out));
1835 out <<
"Template parameters:" << endl;
1836 Teuchos::OSTab tab2(out);
1837 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name() << endl
1838 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name() << endl
1839 <<
"Node: " << TypeNameTraits<Node>::name() << endl;
1841 const std::string label = this->getObjectLabel();
1843 out <<
"Label: \"" << label <<
"\"" << endl;
1845 out <<
"Global number of entries: " << getGlobalNumElements() << endl
1846 <<
"Minimum global index: " << getMinAllGlobalIndex() << endl
1847 <<
"Maximum global index: " << getMaxAllGlobalIndex() << endl
1848 <<
"Index base: " << getIndexBase() << endl
1849 <<
"Number of processes: " << numProcs << endl
1850 <<
"Uniform: " << (isUniform() ?
"true" :
"false") << endl
1851 <<
"Contiguous: " << (isContiguous() ?
"true" :
"false") << endl
1852 <<
"Distributed: " << (isDistributed() ?
"true" :
"false") << endl;
1856 if (vl >= VERB_HIGH) {
1857 const std::string lclStr = this->localDescribeToString(vl);
1862 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1863 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1880 if (newComm.is_null() || newComm->getSize() < 1) {
1881 return Teuchos::null;
1882 }
else if (newComm->getSize() == 1) {
1889 RCP<map_type> newMap(
new map_type());
1891 newMap->comm_ = newComm;
1895 newMap->indexBase_ = this->indexBase_;
1896 newMap->numGlobalElements_ = this->numLocalElements_;
1897 newMap->numLocalElements_ = this->numLocalElements_;
1898 newMap->minMyGID_ = this->minMyGID_;
1899 newMap->maxMyGID_ = this->maxMyGID_;
1900 newMap->minAllGID_ = this->minMyGID_;
1901 newMap->maxAllGID_ = this->maxMyGID_;
1902 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1903 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1906 newMap->uniform_ = this->uniform_;
1907 newMap->contiguous_ = this->contiguous_;
1910 newMap->distributed_ =
false;
1911 newMap->lgMap_ = this->lgMap_;
1912 newMap->lgMapHost_ = this->lgMapHost_;
1913 newMap->glMap_ = this->glMap_;
1914 newMap->glMapHost_ = this->glMapHost_;
1934 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
1950 auto lgMap = this->getMyGlobalIndices();
1952 typename std::decay<decltype(lgMap.extent(0))>::type;
1953 const size_type lclNumInds =
1954 static_cast<size_type
>(this->getLocalNumElements());
1955 using Teuchos::TypeNameTraits;
1956 TEUCHOS_TEST_FOR_EXCEPTION(lgMap.extent(0) != lclNumInds, std::logic_error,
1957 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
1959 << lgMap.extent(0) <<
" (of type " << TypeNameTraits<size_type>::name() <<
") != this->getLocalNumElements()"
1961 << this->getLocalNumElements() <<
". The latter, upon being "
1962 "cast to size_type = "
1963 << TypeNameTraits<size_type>::name() <<
", "
1965 << lclNumInds <<
". Please report this bug to the Tpetra "
1968 Teuchos::ArrayView<const GO> lgMap = this->getLocalElementList();
1971 const GO indexBase = this->getIndexBase();
1973 auto lgMap_device = Kokkos::create_mirror_view_and_copy(
device_type(), lgMap);
1974 return rcp(
new map_type(RECOMPUTE, lgMap_device, indexBase, newComm));
1978 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1979 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1982 using Teuchos::Comm;
1983 using Teuchos::null;
1984 using Teuchos::outArg;
1987 using Teuchos::REDUCE_MIN;
1988 using Teuchos::reduceAll;
1995 const int color = (numLocalElements_ == 0) ? 0 : 1;
2000 RCP<const Comm<int>> newComm = comm_->split(color, 0);
2006 if (newComm.is_null()) {
2009 RCP<Map> map = rcp(
new Map());
2011 map->comm_ = newComm;
2012 map->indexBase_ = indexBase_;
2013 map->numGlobalElements_ = numGlobalElements_;
2014 map->numLocalElements_ = numLocalElements_;
2015 map->minMyGID_ = minMyGID_;
2016 map->maxMyGID_ = maxMyGID_;
2017 map->minAllGID_ = minAllGID_;
2018 map->maxAllGID_ = maxAllGID_;
2019 map->firstContiguousGID_ = firstContiguousGID_;
2020 map->lastContiguousGID_ = lastContiguousGID_;
2024 map->uniform_ = uniform_;
2025 map->contiguous_ = contiguous_;
2040 if (!distributed_ || newComm->getSize() == 1) {
2041 map->distributed_ =
false;
2043 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2044 int allProcsOwnAllGids = 0;
2045 reduceAll<int, int>(*newComm, REDUCE_MIN, iOwnAllGids, outArg(allProcsOwnAllGids));
2046 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
2049 map->lgMap_ = lgMap_;
2050 map->lgMapHost_ = lgMapHost_;
2051 map->glMap_ = glMap_;
2052 map->glMapHost_ = glMapHost_;
2069 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2071 TEUCHOS_TEST_FOR_EXCEPTION(
2072 directory_.is_null(), std::logic_error,
2073 "Tpetra::Map::setupDirectory: "
2074 "The Directory is null. "
2075 "Please report this bug to the Tpetra developers.");
2079 if (!directory_->initialized()) {
2080 directory_->initialize(*
this);
2084 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2088 const Teuchos::ArrayView<int>& PIDs,
2089 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const {
2092 using Tpetra::Details::OrdinalTraits;
2093 using size_type = Teuchos::ArrayView<int>::size_type;
2097 std::unique_ptr<std::string> prefix;
2100 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2101 std::ostringstream os;
2102 os << *prefix <<
"Start: ";
2105 std::cerr << os.str();
2114 if (getGlobalNumElements() == 0) {
2115 if (GIDs.size() == 0) {
2117 std::ostringstream os;
2118 os << *prefix <<
"Done; both Map & input are empty" << endl;
2119 std::cerr << os.str();
2124 std::ostringstream os;
2125 os << *prefix <<
"Done: Map is empty on all processes, "
2126 "so all output PIDs & LIDs are invalid (-1)."
2128 std::cerr << os.str();
2130 for (size_type k = 0; k < PIDs.size(); ++k) {
2131 PIDs[k] = OrdinalTraits<int>::invalid();
2133 for (size_type k = 0; k < LIDs.size(); ++k) {
2134 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid();
2145 std::ostringstream os;
2146 os << *prefix <<
"Call setupDirectory" << endl;
2147 std::cerr << os.str();
2151 std::ostringstream os;
2152 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2153 std::cerr << os.str();
2156 directory_->getDirectoryEntries(*
this, GIDs, PIDs, LIDs);
2158 std::ostringstream os;
2159 os << *prefix <<
"Done; getDirectoryEntries returned "
2160 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2166 std::cerr << os.str();
2171 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2175 const Teuchos::ArrayView<int>& PIDs)
const {
2181 std::unique_ptr<std::string> prefix;
2184 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2185 std::ostringstream os;
2186 os << *prefix <<
"Start: ";
2189 std::cerr << os.str();
2192 if (getGlobalNumElements() == 0) {
2193 if (GIDs.size() == 0) {
2195 std::ostringstream os;
2196 os << *prefix <<
"Done; both Map & input are empty" << endl;
2197 std::cerr << os.str();
2202 std::ostringstream os;
2203 os << *prefix <<
"Done: Map is empty on all processes, "
2204 "so all output PIDs are invalid (-1)."
2206 std::cerr << os.str();
2208 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size(); ++k) {
2209 PIDs[k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2220 std::ostringstream os;
2221 os << *prefix <<
"Call setupDirectory" << endl;
2222 std::cerr << os.str();
2226 std::ostringstream os;
2227 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2228 std::cerr << os.str();
2231 directory_->getDirectoryEntries(*
this, GIDs, PIDs);
2233 std::ostringstream os;
2234 os << *prefix <<
"Done; getDirectoryEntries returned "
2235 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2239 std::cerr << os.str();
2244 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2246 using exec_space =
typename Node::device_type::execution_space;
2247 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2253 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2258 exec_space().fence();
2259 lgMapHost_ = lgMap_host;
2262 glMapHost_ = global_to_local_table_host_type(glMap_);
2266 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2267 Teuchos::RCP<const Teuchos::Comm<int>>
2272 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2277 using Teuchos::outArg;
2278 using Teuchos::REDUCE_MIN;
2279 using Teuchos::reduceAll;
2282 std::unique_ptr<std::string> prefix;
2285 comm_.getRawPtr(),
"Map",
"checkIsDist");
2286 std::ostringstream os;
2287 os << *prefix <<
"Start" << endl;
2288 std::cerr << os.str();
2291 bool global =
false;
2292 if (comm_->getSize() > 1) {
2296 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2309 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2310 if (allLocalRep != 1) {
2320 std::ostringstream os;
2321 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2323 std::cerr << os.str();
2330 template <
class LocalOrdinal,
class GlobalOrdinal>
2331 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2333 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2334 typedef LocalOrdinal LO;
2335 typedef GlobalOrdinal GO;
2336 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2337 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2340 template <
class LocalOrdinal,
class GlobalOrdinal>
2341 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2343 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2344 typedef LocalOrdinal LO;
2345 typedef GlobalOrdinal GO;
2346 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2347 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2350 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2351 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2353 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2356 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2358 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2361 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2362 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2364 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2368 const GlobalOrdinal indexBase = 0;
2371 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2374 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2375 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2377 const size_t localNumElements,
2378 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2381 const GlobalOrdinal indexBase = 0;
2383 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2386 template <
class LocalOrdinal,
class GlobalOrdinal>
2387 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2389 const size_t localNumElements,
2390 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2391 typedef LocalOrdinal LO;
2392 typedef GlobalOrdinal GO;
2395 return Tpetra::createContigMapWithNode<LO, GO, NT>(numElements, localNumElements, comm);
2398 template <
class LocalOrdinal,
class GlobalOrdinal>
2399 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2401 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2402 typedef LocalOrdinal LO;
2403 typedef GlobalOrdinal GO;
2406 return Tpetra::createNonContigMapWithNode<LO, GO, NT>(elementList, comm);
2409 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2410 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2412 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2416 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2420 const GlobalOrdinal indexBase = 0;
2422 return rcp(
new map_type(INV, elementList, indexBase, comm));
2425 template <
class LO,
class GO,
class NT>
2426 Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2431 using Teuchos::Array;
2432 using Teuchos::ArrayView;
2438 const bool verbose = Details::Behavior::verbose(
"Map");
2439 std::unique_ptr<std::string> prefix;
2441 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2442 prefix = Details::createPrefix(
2443 comm.getRawPtr(),
"createOneToOne(Map)");
2444 std::ostringstream os;
2445 os << *prefix <<
"Start" << endl;
2448 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2449 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2450 const int myRank = M->getComm()->getRank();
2456 if (!M->isDistributed()) {
2463 const GST numGlobalEntries = M->getGlobalNumElements();
2464 if (M->isContiguous()) {
2465 const size_t numLocalEntries =
2466 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2468 std::ostringstream os;
2469 os << *prefix <<
"Input is locally replicated & contiguous; "
2471 << numLocalEntries << endl;
2475 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2476 M->getIndexBase(), M->getComm()));
2478 std::ostringstream os;
2479 os << *prefix <<
"Done" << endl;
2485 std::ostringstream os;
2486 os << *prefix <<
"Input is locally replicated & noncontiguous"
2490 ArrayView<const GO> myGids =
2491 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2493 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2496 std::ostringstream os;
2497 os << *prefix <<
"Done" << endl;
2502 }
else if (M->isContiguous()) {
2504 std::ostringstream os;
2505 os << *prefix <<
"Input is distributed & contiguous" << endl;
2513 std::ostringstream os;
2514 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2518 const size_t numMyElems = M->getLocalNumElements();
2519 ArrayView<const GO> myElems = M->getLocalElementList();
2520 Array<int> owner_procs_vec(numMyElems);
2523 std::ostringstream os;
2524 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2531 std::ostringstream os;
2532 os << *prefix <<
"getDirectoryEntries result: ";
2538 Array<GO> myOwned_vec(numMyElems);
2539 size_t numMyOwnedElems = 0;
2540 for (
size_t i = 0; i < numMyElems; ++i) {
2541 const GO GID = myElems[i];
2542 const int owner = owner_procs_vec[i];
2544 if (myRank == owner) {
2545 myOwned_vec[numMyOwnedElems++] = GID;
2548 myOwned_vec.resize(numMyOwnedElems);
2551 std::ostringstream os;
2552 os << *prefix <<
"Create Map: ";
2557 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2558 M->getIndexBase(), M->getComm()));
2560 std::ostringstream os;
2561 os << *prefix <<
"Done" << endl;
2568 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2569 Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2572 using Details::Behavior;
2576 using Teuchos::Array;
2577 using Teuchos::ArrayView;
2580 using Teuchos::toString;
2581 using LO = LocalOrdinal;
2582 using GO = GlobalOrdinal;
2585 const bool verbose = Behavior::verbose(
"Map");
2586 std::unique_ptr<std::string> prefix;
2588 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2589 prefix = Details::createPrefix(
2590 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2591 std::ostringstream os;
2592 os << *prefix <<
"Start" << endl;
2595 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2602 std::ostringstream os;
2603 os << *prefix <<
"Initialize Directory" << endl;
2608 std::ostringstream os;
2609 os << *prefix <<
"Done initializing Directory" << endl;
2612 size_t numMyElems = M->getLocalNumElements();
2613 ArrayView<const GO> myElems = M->getLocalElementList();
2614 Array<int> owner_procs_vec(numMyElems);
2616 std::ostringstream os;
2617 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2624 std::ostringstream os;
2625 os << *prefix <<
"getDirectoryEntries result: ";
2631 const int myRank = M->getComm()->getRank();
2632 Array<GO> myOwned_vec(numMyElems);
2633 size_t numMyOwnedElems = 0;
2634 for (
size_t i = 0; i < numMyElems; ++i) {
2635 const GO GID = myElems[i];
2636 const int owner = owner_procs_vec[i];
2637 if (myRank == owner) {
2638 myOwned_vec[numMyOwnedElems++] = GID;
2641 myOwned_vec.resize(numMyOwnedElems);
2646 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2648 std::ostringstream os;
2649 os << *prefix <<
"Create Map: ";
2654 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2657 std::ostringstream os;
2658 os << *prefix <<
"Done" << endl;
2672 #define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2674 template class Map<LO, GO, NODE>; \
2676 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2677 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2678 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2680 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2681 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2682 const size_t localNumElements, \
2683 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2685 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2686 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2687 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2689 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2690 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2691 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2693 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2694 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2696 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2697 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2698 const Tpetra::Details::TieBreak<LO, GO>& tie_break);
2701 #define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2702 template Teuchos::RCP<const Map<LO, GO>> \
2703 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2705 template Teuchos::RCP<const Map<LO, GO>> \
2706 createContigMap<LO, GO>(global_size_t, size_t, \
2707 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2709 template Teuchos::RCP<const Map<LO, GO>> \
2710 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2711 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2713 template Teuchos::RCP<const Map<LO, GO>> \
2714 createUniformContigMap<LO, GO>(const global_size_t, \
2715 const Teuchos::RCP<const Teuchos::Comm<int>>&);
2717 #endif // TPETRA_MAP_DEF_HPP
Interface for breaking ties in ownership.
bool congruent(const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
Whether the two communicators are congruent.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createNonContigMap(const Teuchos::ArrayView< const GlobalOrdinal > &elementList, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Nonmember constructor for a non-contiguous Map using the default Kokkos::Device type.
global_ordinal_type getMaxGlobalIndex() const
The maximum global index owned by the calling process.
LocalOrdinal local_ordinal_type
The type of local indices.
virtual ~Map()
Destructor (virtual for memory safety of derived classes).
GlobalOrdinal global_ordinal_type
The type of global indices.
bool isSameAs(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is identical to this Map.
Declaration of Tpetra::Details::printOnce.
global_indices_array_type getMyGlobalIndices() const
Return a view of the global indices owned by this process.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
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.
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
Declaration of a function that prints strings from each process.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
bool isLocallyFitted(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is locally fitted to this Map.
bool isUniform() const
Whether the range of global indices is uniform.
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map's device.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > removeEmptyProcesses() const
Advanced methods.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
static bool debug()
Whether Tpetra is in debug mode.
static void reject_unrecognized_env_vars()
Search the environment for TPETRA_ variables and reject unrecognized ones.
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x.
int local_ordinal_type
Default value of Scalar template parameter.
"Local" part of Map suitable for Kokkos kernels.
Declaration of Tpetra::Details::initializeKokkos.
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, in rank order.
Teuchos::ArrayView< const global_ordinal_type > getLocalElementList() const
Return a NONOWNING view of the global indices owned by this process.
void initializeKokkos()
Initialize Kokkos, using command-line arguments (if any) given to Teuchos::GlobalMPISession.
size_t global_size_t
Global size_t object.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
bool isCompatible(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is compatible with this Map.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createContigMap(const global_size_t numElements, const size_t localNumElements, const Teuchos::RCP< const Teuchos::Comm< int >> &comm)
Non-member constructor for a (potentially) non-uniformly distributed, contiguous Map using the defaul...
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int >> &newComm) const
Replace this Map's communicator with a subset communicator.
global_ordinal_type getIndexBase() const
The index base for this Map.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
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.
bool isNodeLocalElement(local_ordinal_type localIndex) const
Whether the given local index is valid for this Map on the calling process.
Functions for initializing and finalizing Tpetra.
bool isNodeGlobalElement(global_ordinal_type globalIndex) const
Whether the given global index is owned by this Map on the calling process.
static bool verbose()
Whether Tpetra is in verbose mode.
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, possibly nondefault Kokkos Node type.
LookupStatus getDirectoryEntries(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs) const
Given a global ID list, return the list of their owning process IDs.
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...
local_map_type getLocalMap() const
Get the LocalMap for Kokkos-Kernels.
global_ordinal_type getMinGlobalIndex() const
The minimum global index owned by the calling process.
typename device_type::execution_space execution_space
The Kokkos execution space.
A parallel distribution of indices over processes.
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 ...
global_ordinal_type getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
local_ordinal_type getLocalElement(global_ordinal_type globalIndex) const
The local index corresponding to the given global index.
Implement mapping from global ID to process ID and local ID.
Stand-alone utility functions and macros.
bool isOneToOne() const
Whether the Map is one to one.
void initialize(const map_type &map)
Initialize the Directory with its Map.
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...
bool locallySameAs(const Map< local_ordinal_type, global_ordinal_type, node_type > &map) const
Is this Map locally the same as the input Map?
static size_t verbosePrintCountThreshold()
Number of entries below which arrays, lists, etc. will be printed in debug mode.
typename Node::device_type device_type
This class' Kokkos::Device specialization.
LocalGlobal
Enum for local versus global allocation of Map entries.
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.
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...
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.
Node node_type
Legacy typedef that will go away at some point.
global_ordinal_type getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
Description of Tpetra's behavior.
std::string description() const
Implementation of Teuchos::Describable.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Map()
Default constructor (that does nothing).