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"
42 checkMapInputArray (
const char ctorName[],
43 const void* indexList,
44 const size_t indexListSize,
45 const Teuchos::Comm<int>*
const comm)
49 const bool debug = Behavior::debug(
"Map");
51 using Teuchos::outArg;
52 using Teuchos::REDUCE_MIN;
53 using Teuchos::reduceAll;
56 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
57 const bool verbose = Behavior::verbose(
"Map");
58 std::ostringstream lclErrStrm;
61 if (indexListSize != 0 && indexList ==
nullptr) {
64 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
65 "but indexListSize=" << indexListSize <<
" != 0." << endl;
69 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
70 if (gblSuccess != 1) {
71 std::ostringstream gblErrStrm;
72 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
73 " detected a problem with the input array "
74 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
75 "of global indices." << endl;
77 using ::Tpetra::Details::gathervPrint;
80 TEUCHOS_TEST_FOR_EXCEPTION
81 (
true, std::invalid_argument, gblErrStrm.str ());
89 template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
90 void 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(range_policy(0,numLocalElements),KOKKOS_LAMBDA(
const LO & i, GO &l_myMin, GO&l_myMax, GO& l_firstCont, minloc_type & l_lastCont){
106 GO entry_0 = entryList[0];
107 GO entry_i = entryList[i];
110 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
111 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
112 l_firstCont = entry_0;
114 if(entry_i - entry_0 != i && l_lastCont.val >= i) {
116 l_lastCont.val = i-1;
117 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;
137 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
140 comm_ (new Teuchos::SerialComm<int> ()),
142 numGlobalElements_ (0),
143 numLocalElements_ (0),
144 minMyGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
145 maxMyGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
146 minAllGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
147 maxAllGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
148 firstContiguousGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
149 lastContiguousGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
152 distributed_ (false),
153 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
160 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
168 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
171 using Teuchos::broadcast;
172 using Teuchos::outArg;
173 using Teuchos::reduceAll;
174 using Teuchos::REDUCE_MIN;
175 using Teuchos::REDUCE_MAX;
176 using Teuchos::typeName;
180 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
181 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
183 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
187 std::unique_ptr<std::string> prefix;
190 comm_.getRawPtr(),
"Map", funcName);
191 std::ostringstream os;
192 os << *prefix <<
"Start" << endl;
193 std::cerr << os.str();
201 GST proc0NumGlobalElements = numGlobalElements;
202 broadcast(*comm_, 0, outArg(proc0NumGlobalElements));
203 GST minNumGlobalElements = numGlobalElements;
204 GST maxNumGlobalElements = numGlobalElements;
205 reduceAll(*comm, REDUCE_MIN, numGlobalElements,
206 outArg(minNumGlobalElements));
207 reduceAll(*comm, REDUCE_MAX, numGlobalElements,
208 outArg(maxNumGlobalElements));
209 TEUCHOS_TEST_FOR_EXCEPTION
210 (minNumGlobalElements != maxNumGlobalElements ||
211 numGlobalElements != minNumGlobalElements,
212 std::invalid_argument, exPfx <<
"All processes must "
213 "provide the same number of global elements. Process 0 set "
214 "numGlobalElements="<< proc0NumGlobalElements <<
". The "
215 "calling process " << comm->getRank() <<
" set "
216 "numGlobalElements=" << numGlobalElements <<
". The min "
217 "and max values over all processes are "
218 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements
221 GO proc0IndexBase = indexBase;
222 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
223 GO minIndexBase = indexBase;
224 GO maxIndexBase = indexBase;
225 reduceAll(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
226 reduceAll(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
227 TEUCHOS_TEST_FOR_EXCEPTION
228 (minIndexBase != maxIndexBase || indexBase != minIndexBase,
229 std::invalid_argument, exPfx <<
"All processes must "
230 "provide the same indexBase argument. Process 0 set "
231 "indexBase=" << proc0IndexBase <<
". The calling process "
232 << comm->getRank() <<
" set indexBase=" << indexBase
233 <<
". The min and max values over all processes are "
234 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
254 TEUCHOS_TEST_FOR_EXCEPTION(
255 (numGlobalElements < 1 && numGlobalElements != 0),
256 std::invalid_argument, exPfx <<
"numGlobalElements (= "
257 << numGlobalElements <<
") must be nonnegative.");
259 TEUCHOS_TEST_FOR_EXCEPTION
260 (numGlobalElements == GSTI, std::invalid_argument, exPfx <<
261 "You provided numGlobalElements = Teuchos::OrdinalTraits<"
262 "Tpetra::global_size_t>::invalid(). This version of the "
263 "constructor requires a valid value of numGlobalElements. "
264 "You probably mistook this constructor for the \"contiguous "
265 "nonuniform\" constructor, which can compute the global "
266 "number of elements for you if you set numGlobalElements to "
267 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
269 size_t numLocalElements = 0;
270 if (lOrG == GloballyDistributed) {
285 const GST numProcs =
static_cast<GST
> (comm_->getSize ());
286 const GST myRank =
static_cast<GST
> (comm_->getRank ());
287 const GST quotient = numGlobalElements / numProcs;
288 const GST remainder = numGlobalElements - quotient * numProcs;
291 if (myRank < remainder) {
292 numLocalElements =
static_cast<size_t> (1) + static_cast<size_t> (quotient);
295 startIndex = as<GO> (myRank) * as<GO> (numLocalElements);
297 numLocalElements = as<size_t> (quotient);
298 startIndex = as<GO> (myRank) * as<GO> (numLocalElements) +
302 minMyGID_ = indexBase + startIndex;
303 maxMyGID_ = indexBase + startIndex + numLocalElements - 1;
304 minAllGID_ = indexBase;
305 maxAllGID_ = indexBase + numGlobalElements - 1;
306 distributed_ = (numProcs > 1);
309 numLocalElements = as<size_t> (numGlobalElements);
310 minMyGID_ = indexBase;
311 maxMyGID_ = indexBase + numGlobalElements - 1;
312 distributed_ =
false;
315 minAllGID_ = indexBase;
316 maxAllGID_ = indexBase + numGlobalElements - 1;
317 indexBase_ = indexBase;
318 numGlobalElements_ = numGlobalElements;
319 numLocalElements_ = numLocalElements;
320 firstContiguousGID_ = minMyGID_;
321 lastContiguousGID_ = maxMyGID_;
328 std::ostringstream os;
329 os << *prefix <<
"Done" << endl;
330 std::cerr << os.str();
335 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
338 const size_t numLocalElements,
340 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm) :
343 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
346 using Teuchos::broadcast;
347 using Teuchos::outArg;
348 using Teuchos::reduceAll;
349 using Teuchos::REDUCE_MIN;
350 using Teuchos::REDUCE_MAX;
351 using Teuchos::REDUCE_SUM;
356 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
357 const char funcName[] =
358 "Map(gblNumInds,lclNumInds,indexBase,comm)";
360 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
361 const char suffix[] =
362 ". Please report this bug to the Tpetra developers.";
366 std::unique_ptr<std::string> prefix;
369 comm_.getRawPtr(),
"Map", funcName);
370 std::ostringstream os;
371 os << *prefix <<
"Start" << endl;
372 std::cerr << os.str();
379 GST debugGlobalSum {};
381 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
382 numGlobalElements, numLocalElements, indexBase, comm);
397 scan<int, GO> (*comm, REDUCE_SUM, numLocalElements, outArg (scanResult));
398 const GO myOffset = scanResult - numLocalElements;
400 if (numGlobalElements != GSTI) {
401 numGlobalElements_ = numGlobalElements;
408 const int numProcs = comm->getSize ();
409 GST globalSum = scanResult;
411 broadcast (*comm, numProcs - 1, outArg (globalSum));
413 numGlobalElements_ = globalSum;
417 TEUCHOS_TEST_FOR_EXCEPTION
418 (globalSum != debugGlobalSum, std::logic_error, exPfx <<
419 "globalSum = " << globalSum <<
" != debugGlobalSum = " <<
420 debugGlobalSum << suffix);
423 numLocalElements_ = numLocalElements;
424 indexBase_ = indexBase;
425 minAllGID_ = (numGlobalElements_ == 0) ?
426 std::numeric_limits<GO>::max () :
428 maxAllGID_ = (numGlobalElements_ == 0) ?
429 std::numeric_limits<GO>::lowest () :
430 indexBase + GO(numGlobalElements_) - GO(1);
431 minMyGID_ = (numLocalElements_ == 0) ?
432 std::numeric_limits<GO>::max () :
433 indexBase + GO(myOffset);
434 maxMyGID_ = (numLocalElements_ == 0) ?
435 std::numeric_limits<GO>::lowest () :
436 indexBase + myOffset + GO(numLocalElements) - GO(1);
437 firstContiguousGID_ = minMyGID_;
438 lastContiguousGID_ = maxMyGID_;
440 distributed_ = checkIsDist ();
446 std::ostringstream os;
447 os << *prefix <<
"Done" << endl;
448 std::cerr << os.str();
452 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
456 const char errorMessagePrefix[],
458 const size_t numLocalElements,
459 const global_ordinal_type indexBase,
460 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const
467 using Teuchos::broadcast;
468 using Teuchos::outArg;
470 using Teuchos::REDUCE_MAX;
471 using Teuchos::REDUCE_MIN;
472 using Teuchos::REDUCE_SUM;
473 using Teuchos::reduceAll;
474 using GO = global_ordinal_type;
476 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
486 GST debugGlobalSum = 0;
487 reduceAll<int, GST> (*comm, REDUCE_SUM,
static_cast<GST
> (numLocalElements),
488 outArg (debugGlobalSum));
492 GST proc0NumGlobalElements = numGlobalElements;
493 broadcast<int, GST> (*comm_, 0, outArg (proc0NumGlobalElements));
494 GST minNumGlobalElements = numGlobalElements;
495 GST maxNumGlobalElements = numGlobalElements;
496 reduceAll<int, GST> (*comm, REDUCE_MIN, numGlobalElements,
497 outArg (minNumGlobalElements));
498 reduceAll<int, GST> (*comm, REDUCE_MAX, numGlobalElements,
499 outArg (maxNumGlobalElements));
500 TEUCHOS_TEST_FOR_EXCEPTION
501 (minNumGlobalElements != maxNumGlobalElements ||
502 numGlobalElements != minNumGlobalElements,
503 std::invalid_argument, errorMessagePrefix <<
"All processes "
504 "must provide the same number of global elements, even if "
506 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
507 "(which signals that the Map should compute the global "
508 "number of elements). Process 0 set numGlobalElements"
509 "=" << proc0NumGlobalElements <<
". The calling process "
510 << comm->getRank() <<
" set numGlobalElements=" <<
511 numGlobalElements <<
". The min and max values over all "
512 "processes are " << minNumGlobalElements <<
" resp. " <<
513 maxNumGlobalElements <<
".");
515 GO proc0IndexBase = indexBase;
516 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
517 GO minIndexBase = indexBase;
518 GO maxIndexBase = indexBase;
519 reduceAll<int, GO> (*comm, REDUCE_MIN, indexBase, outArg (minIndexBase));
520 reduceAll<int, GO> (*comm, REDUCE_MAX, indexBase, outArg (maxIndexBase));
521 TEUCHOS_TEST_FOR_EXCEPTION
522 (minIndexBase != maxIndexBase || indexBase != minIndexBase,
523 std::invalid_argument, errorMessagePrefix <<
524 "All processes must provide the same indexBase argument. "
525 "Process 0 set indexBase = " << proc0IndexBase <<
". The "
526 "calling process " << comm->getRank() <<
" set indexBase="
527 << indexBase <<
". The min and max values over all "
528 "processes are " << minIndexBase <<
" resp. " << maxIndexBase
533 TEUCHOS_TEST_FOR_EXCEPTION
534 (numGlobalElements != GSTI &&
535 debugGlobalSum != numGlobalElements, std::invalid_argument,
536 errorMessagePrefix <<
"The sum of each process' number of "
537 "indices over all processes, " << debugGlobalSum <<
", != "
538 <<
"numGlobalElements=" << numGlobalElements <<
". If you "
539 "would like this constructor to compute numGlobalElements "
540 "for you, you may set numGlobalElements="
541 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
542 "on input. Please note that this is NOT necessarily -1.");
544 return debugGlobalSum;
547 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
549 Map<LocalOrdinal,GlobalOrdinal,Node>::
550 initWithNonownedHostIndexList(
551 const char errorMessagePrefix[],
553 const Kokkos::View<
const global_ordinal_type*,
556 Kokkos::MemoryUnmanaged>& entryList_host,
557 const global_ordinal_type indexBase,
558 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
562 using Kokkos::LayoutLeft;
563 using Kokkos::subview;
565 using Kokkos::view_alloc;
566 using Kokkos::WithoutInitializing;
568 using Teuchos::broadcast;
569 using Teuchos::outArg;
571 using Teuchos::REDUCE_MAX;
572 using Teuchos::REDUCE_MIN;
573 using Teuchos::REDUCE_SUM;
574 using Teuchos::reduceAll;
576 using GO = global_ordinal_type;
578 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
580 TEUCHOS_TEST_FOR_EXCEPTION
581 (! Kokkos::is_initialized (), std::runtime_error,
582 errorMessagePrefix <<
"The Kokkos execution space "
583 << Teuchos::TypeNameTraits<execution_space>::name()
584 <<
" has not been initialized. "
585 "Please initialize it before creating a Map.")
598 const
size_t numLocalElements(entryList_host.size());
600 initialNonuniformDebugCheck(errorMessagePrefix, numGlobalElements,
601 numLocalElements, indexBase, comm);
611 if (numGlobalElements != GSTI) {
612 numGlobalElements_ = numGlobalElements;
615 reduceAll(*comm, REDUCE_SUM,
616 static_cast<GST>(numLocalElements),
617 outArg(numGlobalElements_));
643 numLocalElements_ = numLocalElements;
644 indexBase_ = indexBase;
646 minMyGID_ = indexBase_;
647 maxMyGID_ = indexBase_;
657 if (numLocalElements_ > 0) {
661 typename decltype (lgMap_)::non_const_type lgMap
662 (view_alloc (
"lgMap", WithoutInitializing), numLocalElements_);
664 Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
672 firstContiguousGID_ = entryList_host[0];
673 lastContiguousGID_ = firstContiguousGID_+1;
681 lgMap_host[0] = firstContiguousGID_;
683 for ( ; i < numLocalElements_; ++i) {
684 const GO curGid = entryList_host[i];
685 const LO curLid = as<LO> (i);
687 if (lastContiguousGID_ != curGid)
break;
693 lgMap_host[curLid] = curGid;
694 ++lastContiguousGID_;
696 --lastContiguousGID_;
702 minMyGID_ = firstContiguousGID_;
703 maxMyGID_ = lastContiguousGID_;
707 LO firstNonContiguous_loc=i;
710 const std::pair<size_t, size_t> ncRange (i, entryList_host.extent (0));
711 auto nonContigGids_host = subview (entryList_host, ncRange);
712 TEUCHOS_TEST_FOR_EXCEPTION
713 (static_cast<size_t> (nonContigGids_host.extent (0)) !=
714 static_cast<size_t> (entryList_host.extent (0) - i),
715 std::logic_error,
"Tpetra::Map noncontiguous constructor: "
716 "nonContigGids_host.extent(0) = "
717 << nonContigGids_host.extent (0)
718 <<
" != entryList_host.extent(0) - i = "
719 << (entryList_host.extent (0) - i) <<
" = "
720 << entryList_host.extent (0) <<
" - " << i
721 <<
". Please report this bug to the Tpetra developers.");
725 View<GO*, LayoutLeft, device_type>
726 nonContigGids (view_alloc (
"nonContigGids", WithoutInitializing),
727 nonContigGids_host.size ());
732 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
734 glMap_ = global_to_local_table_type(nonContigGids,
735 firstNonContiguous_loc);
737 glMapHost_ = global_to_local_table_host_type(glMap_);
745 for ( ; i < numLocalElements_; ++i) {
746 const GO curGid = entryList_host[i];
747 const LO curLid =
static_cast<LO
> (i);
748 lgMap_host[curLid] = curGid;
752 if (curGid < minMyGID_) {
755 if (curGid > maxMyGID_) {
767 lgMapHost_ = lgMap_host;
772 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
773 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
777 firstContiguousGID_ = indexBase_+1;
778 lastContiguousGID_ = indexBase_;
807 if (std::numeric_limits<GO>::is_signed) {
810 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
813 minMaxInput[0] = -minMyGID_;
814 minMaxInput[1] = maxMyGID_;
815 minMaxInput[2] = localDist;
821 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
822 minAllGID_ = -minMaxOutput[0];
823 maxAllGID_ = minMaxOutput[1];
824 const GO globalDist = minMaxOutput[2];
825 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
829 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
830 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
831 distributed_ = checkIsDist ();
836 TEUCHOS_TEST_FOR_EXCEPTION(
837 minAllGID_ < indexBase_,
838 std::invalid_argument,
839 "Tpetra::Map constructor (noncontiguous): "
840 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
841 "less than the given indexBase = " << indexBase_ <<
".");
847 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
850 const GlobalOrdinal indexList[],
851 const LocalOrdinal indexListSize,
852 const GlobalOrdinal indexBase,
853 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
856 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
859 const char funcName[] =
860 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
863 std::unique_ptr<std::string> prefix;
866 comm_.getRawPtr(),
"Map", funcName);
867 std::ostringstream os;
868 os << *prefix <<
"Start" << endl;
869 std::cerr << os.str();
874 checkMapInputArray (
"(GST, const GO[], LO, GO, comm)",
875 indexList, static_cast<size_t> (indexListSize),
880 const GlobalOrdinal*
const indsRaw = indexListSize == 0 ? NULL : indexList;
881 Kokkos::View<
const GlobalOrdinal*,
884 Kokkos::MemoryUnmanaged> inds (indsRaw, indexListSize);
885 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
888 std::ostringstream os;
889 os << *prefix <<
"Done" << endl;
890 std::cerr << os.str();
894 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
897 const Teuchos::ArrayView<const GlobalOrdinal>& entryList,
898 const GlobalOrdinal indexBase,
899 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
902 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
905 const char* funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
908 std::unique_ptr<std::string> prefix;
911 comm_.getRawPtr(),
"Map", funcName);
912 std::ostringstream os;
913 os << *prefix <<
"Start" << endl;
914 std::cerr << os.str();
919 const size_t numLclInds =
static_cast<size_t> (entryList.size ());
920 checkMapInputArray (
"(GST, ArrayView, GO, comm)",
921 entryList.getRawPtr (), numLclInds,
926 const GlobalOrdinal*
const indsRaw =
927 numLclInds == 0 ? NULL : entryList.getRawPtr ();
928 Kokkos::View<
const GlobalOrdinal*,
931 Kokkos::MemoryUnmanaged> inds (indsRaw, numLclInds);
932 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
935 std::ostringstream os;
936 os << *prefix <<
"Done" << endl;
937 std::cerr << os.str();
942 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
945 const Kokkos::View<const GlobalOrdinal*, device_type>& entryList,
946 const GlobalOrdinal indexBase,
947 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
950 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
952 using Kokkos::LayoutLeft;
953 using Kokkos::subview;
955 using Kokkos::view_alloc;
956 using Kokkos::WithoutInitializing;
958 using Teuchos::ArrayView;
960 using Teuchos::broadcast;
961 using Teuchos::outArg;
963 using Teuchos::REDUCE_MAX;
964 using Teuchos::REDUCE_MIN;
965 using Teuchos::REDUCE_SUM;
966 using Teuchos::reduceAll;
967 using Teuchos::typeName;
972 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
973 const char funcName[] =
974 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
977 std::unique_ptr<std::string> prefix;
980 comm_.getRawPtr(),
"Map", funcName);
981 std::ostringstream os;
982 os << *prefix <<
"Start" << endl;
983 std::cerr << os.str();
988 checkMapInputArray (
"(GST, Kokkos::View, GO, comm)",
990 static_cast<size_t> (entryList.extent (0)),
1004 const size_t numLocalElements(entryList.size());
1006 initialNonuniformDebugCheck(funcName, numGlobalElements,
1007 numLocalElements, indexBase, comm);
1017 if (numGlobalElements != GSTI) {
1018 numGlobalElements_ = numGlobalElements;
1021 reduceAll(*comm, REDUCE_SUM,
1022 static_cast<GST>(numLocalElements),
1023 outArg(numGlobalElements_));
1050 numLocalElements_ = numLocalElements;
1051 indexBase_ = indexBase;
1053 minMyGID_ = indexBase_;
1054 maxMyGID_ = indexBase_;
1064 if (numLocalElements_ > 0) {
1068 typename decltype (lgMap_)::non_const_type lgMap
1069 (view_alloc (
"lgMap", WithoutInitializing), numLocalElements_);
1074 LO lastContiguousGID_loc;
1075 computeConstantsOnDevice(entryList,minMyGID_,maxMyGID_,firstContiguousGID_,lastContiguousGID_,lastContiguousGID_loc);
1076 LO firstNonContiguous_loc = lastContiguousGID_loc+1;
1077 auto nonContigGids = Kokkos::subview(entryList,std::pair<size_t,size_t>(firstNonContiguous_loc,entryList.extent(0)));
1081 firstNonContiguous_loc);
1088 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1089 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1093 firstContiguousGID_ = indexBase_+1;
1094 lastContiguousGID_ = indexBase_;
1120 if (std::numeric_limits<GO>::is_signed) {
1122 const GO localDist =
1123 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
1126 minMaxInput[0] = -minMyGID_;
1127 minMaxInput[1] = maxMyGID_;
1128 minMaxInput[2] = localDist;
1131 minMaxOutput[0] = 0;
1132 minMaxOutput[1] = 0;
1133 minMaxOutput[2] = 0;
1134 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1135 minAllGID_ = -minMaxOutput[0];
1136 maxAllGID_ = minMaxOutput[1];
1137 const GO globalDist = minMaxOutput[2];
1138 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
1142 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
1143 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
1144 distributed_ = checkIsDist ();
1147 contiguous_ =
false;
1149 TEUCHOS_TEST_FOR_EXCEPTION(
1150 minAllGID_ < indexBase_,
1151 std::invalid_argument,
1152 "Tpetra::Map constructor (noncontiguous): "
1153 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
1154 "less than the given indexBase = " << indexBase_ <<
".");
1160 std::ostringstream os;
1161 os << *prefix <<
"Done" << endl;
1162 std::cerr << os.str();
1167 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1170 if (! Kokkos::is_initialized ()) {
1171 std::ostringstream os;
1172 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1173 "Kokkos::finalize() has been called. This is user error! There are "
1174 "two likely causes: " << std::endl <<
1175 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1177 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1178 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1179 "or Tpetra::finalize()." << std::endl << std::endl <<
1180 "Don't do either of these! Please refer to GitHib Issue #2372."
1182 ::Tpetra::Details::printOnce (std::cerr, os.str (),
1183 this->getComm ().getRawPtr ());
1186 using ::Tpetra::Details::mpiIsInitialized;
1187 using ::Tpetra::Details::mpiIsFinalized;
1188 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1190 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getComm ();
1191 if (! comm.is_null () && teuchosCommIsAnMpiComm (*comm) &&
1192 mpiIsInitialized () && mpiIsFinalized ()) {
1198 std::ostringstream os;
1199 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1200 "MPI_Finalize() has been called. This is user error! There are "
1201 "two likely causes: " << std::endl <<
1202 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1204 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1205 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1206 "Tpetra::finalize()." << std::endl << std::endl <<
1207 "Don't do either of these! Please refer to GitHib Issue #2372."
1209 ::Tpetra::Details::printOnce (std::cerr, os.str (), comm.getRawPtr ());
1217 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1221 TEUCHOS_TEST_FOR_EXCEPTION(
1222 getComm ().is_null (), std::logic_error,
"Tpetra::Map::isOneToOne: "
1223 "getComm() returns null. Please report this bug to the Tpetra "
1228 return directory_->isOneToOne (*
this);
1231 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1236 if (isContiguous ()) {
1237 if (globalIndex < getMinGlobalIndex () ||
1238 globalIndex > getMaxGlobalIndex ()) {
1239 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1241 return static_cast<LocalOrdinal
> (globalIndex - getMinGlobalIndex ());
1243 else if (globalIndex >= firstContiguousGID_ &&
1244 globalIndex <= lastContiguousGID_) {
1245 return static_cast<LocalOrdinal
> (globalIndex - firstContiguousGID_);
1252 return glMapHost_.get (globalIndex);
1256 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1261 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1262 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ();
1264 if (isContiguous ()) {
1265 return getMinGlobalIndex () + localIndex;
1273 return lgMapHost_[localIndex];
1277 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1282 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1289 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1293 return this->getLocalElement (globalIndex) !=
1294 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1297 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1302 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1308 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1314 getMinGlobalIndex (), getMaxGlobalIndex (),
1315 firstContiguousGID_, lastContiguousGID_,
1316 getLocalNumElements (), isContiguous ());
1319 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1324 using Teuchos::outArg;
1325 using Teuchos::REDUCE_MIN;
1326 using Teuchos::reduceAll;
1336 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1347 else if (isContiguous () && isUniform () &&
1355 lgMap_.extent (0) != 0 && map.lgMap_.extent (0) != 0 &&
1356 lgMap_.data () == map.lgMap_.data ()) {
1370 TEUCHOS_TEST_FOR_EXCEPTION(
1372 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1373 "checked that this condition is true above, but it's false here. "
1374 "Please report this bug to the Tpetra developers.");
1377 const int locallyCompat =
1380 int globallyCompat = 0;
1381 reduceAll<int, int> (*comm_, REDUCE_MIN, locallyCompat, outArg (globallyCompat));
1382 return (globallyCompat == 1);
1385 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1390 using Teuchos::ArrayView;
1392 using size_type =
typename ArrayView<const GO>::size_type;
1415 if (isContiguous ()) {
1420 TEUCHOS_TEST_FOR_EXCEPTION(
1421 ! this->isContiguous () || map.
isContiguous (), std::logic_error,
1422 "Tpetra::Map::locallySameAs: BUG");
1424 const GO minLhsGid = this->getMinGlobalIndex ();
1425 const size_type numRhsElts = rhsElts.size ();
1426 for (size_type k = 0; k < numRhsElts; ++k) {
1427 const GO curLhsGid = minLhsGid +
static_cast<GO
> (k);
1428 if (curLhsGid != rhsElts[k]) {
1436 TEUCHOS_TEST_FOR_EXCEPTION(
1437 this->isContiguous () || ! map.
isContiguous (), std::logic_error,
1438 "Tpetra::Map::locallySameAs: BUG");
1439 ArrayView<const GO> lhsElts = this->getLocalElementList ();
1441 const size_type numLhsElts = lhsElts.size ();
1442 for (size_type k = 0; k < numLhsElts; ++k) {
1443 const GO curRhsGid = minRhsGid +
static_cast<GO
> (k);
1444 if (curRhsGid != lhsElts[k]) {
1450 else if (this->lgMap_.data () == map.lgMap_.data ()) {
1460 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1462 auto lhsLclMap = getLocalMap();
1465 LocalOrdinal numMismatchedElements = 0;
1466 Kokkos::parallel_reduce(
"Tpetra::Map::locallySameAs",
1467 range_type(0, this->getLocalNumElements()),
1468 KOKKOS_LAMBDA(
const LocalOrdinal lid, LocalOrdinal& numMismatches) {
1469 if (lhsLclMap.getGlobalElement(lid) != rhsLclMap.getGlobalElement(lid))
1471 }, numMismatchedElements);
1473 return (numMismatchedElements == 0);
1479 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1492 auto lmap2 = this->getLocalMap();
1494 auto numLocalElements1 = lmap1.getLocalNumElements();
1495 auto numLocalElements2 = lmap2.getLocalNumElements();
1497 if (numLocalElements1 > numLocalElements2) {
1502 if (lmap1.isContiguous () && lmap2.isContiguous ()) {
1504 return ((lmap1.getMinGlobalIndex () == lmap2.getMinGlobalIndex ()) &&
1505 (lmap1.getMaxGlobalIndex () <= lmap2.getMaxGlobalIndex ()));
1508 if (lmap1.getMinGlobalIndex () < lmap2.getMinGlobalIndex () ||
1509 lmap1.getMaxGlobalIndex () > lmap2.getMaxGlobalIndex ()) {
1517 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1521 Kokkos::parallel_reduce(
1523 range_type(0, numLocalElements1),
1524 KOKKOS_LAMBDA (
const LO i, LO& diff) {
1525 diff += (lmap1.getGlobalElement(i) != lmap2.getGlobalElement(i));
1528 return (numDiff == 0);
1531 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1536 using Teuchos::outArg;
1537 using Teuchos::REDUCE_MIN;
1538 using Teuchos::reduceAll;
1548 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1571 else if (isContiguous () && isUniform () &&
1592 const int isSame_lcl = locallySameAs (map) ? 1 : 0;
1596 reduceAll<int, int> (*comm_, REDUCE_MIN, isSame_lcl, outArg (isSame_gbl));
1597 return isSame_gbl == 1;
1601 template <
class LO,
class GO,
class DT>
1604 FillLgMap (
const Kokkos::View<GO*, DT>& lgMap,
1605 const GO startGid) :
1606 lgMap_ (lgMap), startGid_ (startGid)
1608 Kokkos::RangePolicy<LO, typename DT::execution_space>
1609 range (static_cast<LO> (0), static_cast<LO> (lgMap.size ()));
1610 Kokkos::parallel_for (range, *
this);
1613 KOKKOS_INLINE_FUNCTION
void operator () (
const LO& lid)
const {
1614 lgMap_(lid) = startGid_ +
static_cast<GO
> (lid);
1618 const Kokkos::View<GO*, DT> lgMap_;
1625 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1626 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_type
1632 using const_lg_view_type = decltype(lgMap_);
1633 using lg_view_type =
typename const_lg_view_type::non_const_type;
1637 std::unique_ptr<std::string> prefix;
1640 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1641 std::ostringstream os;
1642 os << *prefix <<
"Start" << endl;
1643 std::cerr << os.str();
1649 const bool needToCreateLocalToGlobalMapping =
1650 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1652 if (needToCreateLocalToGlobalMapping) {
1654 std::ostringstream os;
1655 os << *prefix <<
"Need to create lgMap" << endl;
1656 std::cerr << os.str();
1661 TEUCHOS_TEST_FOR_EXCEPTION
1662 (! isContiguous(), std::logic_error,
1663 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1664 "mapping (lgMap_) should have been set up already for a "
1665 "noncontiguous Map. Please report this bug to the Tpetra "
1668 const LO numElts =
static_cast<LO
> (getLocalNumElements ());
1670 using Kokkos::view_alloc;
1671 using Kokkos::WithoutInitializing;
1672 lg_view_type lgMap (
"lgMap", numElts);
1674 std::ostringstream os;
1675 os << *prefix <<
"Fill lgMap" << endl;
1676 std::cerr << os.str();
1678 FillLgMap<LO, GO, device_type> fillIt (lgMap, minMyGID_);
1681 std::ostringstream os;
1682 os << *prefix <<
"Copy lgMap to lgMapHost" << endl;
1683 std::cerr << os.str();
1686 auto lgMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
1693 exec_instance.fence();
1697 lgMapHost_ = lgMapHost;
1704 std::ostringstream os;
1705 os << *prefix <<
"Done" << endl;
1706 std::cerr << os.str();
1712 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1713 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_device_type
1719 using const_lg_view_type = decltype(lgMap_);
1720 using lg_view_type =
typename const_lg_view_type::non_const_type;
1724 std::unique_ptr<std::string> prefix;
1727 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1728 std::ostringstream os;
1729 os << *prefix <<
"Start" << endl;
1730 std::cerr << os.str();
1736 const bool needToCreateLocalToGlobalMapping =
1737 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1739 if (needToCreateLocalToGlobalMapping) {
1741 std::ostringstream os;
1742 os << *prefix <<
"Need to create lgMap" << endl;
1743 std::cerr << os.str();
1748 TEUCHOS_TEST_FOR_EXCEPTION
1749 (! isContiguous(), std::logic_error,
1750 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1751 "mapping (lgMap_) should have been set up already for a "
1752 "noncontiguous Map. Please report this bug to the Tpetra "
1755 const LO numElts =
static_cast<LO
> (getLocalNumElements ());
1757 using Kokkos::view_alloc;
1758 using Kokkos::WithoutInitializing;
1759 lg_view_type lgMap (
"lgMap", numElts);
1761 std::ostringstream os;
1762 os << *prefix <<
"Fill lgMap" << endl;
1763 std::cerr << os.str();
1765 FillLgMap<LO, GO, device_type> fillIt (lgMap, minMyGID_);
1772 std::ostringstream os;
1773 os << *prefix <<
"Done" << endl;
1774 std::cerr << os.str();
1781 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1782 Teuchos::ArrayView<const GlobalOrdinal>
1790 (void) this->getMyGlobalIndices ();
1794 const GO* lgMapHostRawPtr = lgMapHost_.data ();
1798 return Teuchos::ArrayView<const GO>(
1800 lgMapHost_.extent (0),
1801 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1804 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1806 return distributed_;
1809 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1811 using Teuchos::TypeNameTraits;
1812 std::ostringstream os;
1814 os <<
"Tpetra::Map: {"
1815 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name ()
1816 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name ()
1817 <<
", NodeType: " << TypeNameTraits<Node>::name ();
1818 if (this->getObjectLabel () !=
"") {
1819 os <<
", Label: \"" << this->getObjectLabel () <<
"\"";
1821 os <<
", Global number of entries: " << getGlobalNumElements ()
1822 <<
", Number of processes: " << getComm ()->getSize ()
1823 <<
", Uniform: " << (isUniform () ?
"true" :
"false")
1824 <<
", Contiguous: " << (isContiguous () ?
"true" :
"false")
1825 <<
", Distributed: " << (isDistributed () ?
"true" :
"false")
1834 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1839 using LO = local_ordinal_type;
1843 if (vl < Teuchos::VERB_HIGH) {
1844 return std::string ();
1846 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
1847 Teuchos::RCP<Teuchos::FancyOStream> outp =
1848 Teuchos::getFancyOStream (outStringP);
1849 Teuchos::FancyOStream& out = *outp;
1851 auto comm = this->getComm ();
1852 const int myRank = comm->getRank ();
1853 const int numProcs = comm->getSize ();
1854 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1855 Teuchos::OSTab tab1 (out);
1857 const LO numEnt =
static_cast<LO
> (this->getLocalNumElements ());
1858 out <<
"My number of entries: " << numEnt << endl
1859 <<
"My minimum global index: " << this->getMinGlobalIndex () << endl
1860 <<
"My maximum global index: " << this->getMaxGlobalIndex () << endl;
1862 if (vl == Teuchos::VERB_EXTREME) {
1863 out <<
"My global indices: [";
1864 const LO minLclInd = this->getMinLocalIndex ();
1865 for (LO k = 0; k < numEnt; ++k) {
1866 out << minLclInd + this->getGlobalElement (k);
1867 if (k + 1 < numEnt) {
1875 return outStringP->str ();
1878 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1882 const Teuchos::EVerbosityLevel verbLevel)
const
1884 using Teuchos::TypeNameTraits;
1885 using Teuchos::VERB_DEFAULT;
1886 using Teuchos::VERB_NONE;
1887 using Teuchos::VERB_LOW;
1888 using Teuchos::VERB_HIGH;
1892 const Teuchos::EVerbosityLevel vl =
1893 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1895 if (vl == VERB_NONE) {
1902 auto comm = this->getComm ();
1903 if (comm.is_null ()) {
1906 const int myRank = comm->getRank ();
1907 const int numProcs = comm->getSize ();
1916 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1922 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
1923 out <<
"\"Tpetra::Map\":" << endl;
1924 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
1926 out <<
"Template parameters:" << endl;
1927 Teuchos::OSTab tab2 (out);
1928 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name () << endl
1929 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name () << endl
1930 <<
"Node: " << TypeNameTraits<Node>::name () << endl;
1932 const std::string label = this->getObjectLabel ();
1934 out <<
"Label: \"" << label <<
"\"" << endl;
1936 out <<
"Global number of entries: " << getGlobalNumElements () << endl
1937 <<
"Minimum global index: " << getMinAllGlobalIndex () << endl
1938 <<
"Maximum global index: " << getMaxAllGlobalIndex () << endl
1939 <<
"Index base: " << getIndexBase () << endl
1940 <<
"Number of processes: " << numProcs << endl
1941 <<
"Uniform: " << (isUniform () ?
"true" :
"false") << endl
1942 <<
"Contiguous: " << (isContiguous () ?
"true" :
"false") << endl
1943 <<
"Distributed: " << (isDistributed () ?
"true" :
"false") << endl;
1947 if (vl >= VERB_HIGH) {
1948 const std::string lclStr = this->localDescribeToString (vl);
1953 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1954 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1972 if (newComm.is_null () || newComm->getSize () < 1) {
1973 return Teuchos::null;
1975 else if (newComm->getSize () == 1) {
1982 RCP<map_type> newMap (
new map_type ());
1984 newMap->comm_ = newComm;
1988 newMap->indexBase_ = this->indexBase_;
1989 newMap->numGlobalElements_ = this->numLocalElements_;
1990 newMap->numLocalElements_ = this->numLocalElements_;
1991 newMap->minMyGID_ = this->minMyGID_;
1992 newMap->maxMyGID_ = this->maxMyGID_;
1993 newMap->minAllGID_ = this->minMyGID_;
1994 newMap->maxAllGID_ = this->maxMyGID_;
1995 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1996 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1999 newMap->uniform_ = this->uniform_;
2000 newMap->contiguous_ = this->contiguous_;
2003 newMap->distributed_ =
false;
2004 newMap->lgMap_ = this->lgMap_;
2005 newMap->lgMapHost_ = this->lgMapHost_;
2006 newMap->glMap_ = this->glMap_;
2007 newMap->glMapHost_ = this->glMapHost_;
2028 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2044 auto lgMap = this->getMyGlobalIndices ();
2046 typename std::decay<decltype (lgMap.extent (0)) >::type;
2047 const size_type lclNumInds =
2048 static_cast<size_type
> (this->getLocalNumElements ());
2049 using Teuchos::TypeNameTraits;
2050 TEUCHOS_TEST_FOR_EXCEPTION
2051 (lgMap.extent (0) != lclNumInds, std::logic_error,
2052 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
2053 "has length " << lgMap.extent (0) <<
" (of type " <<
2054 TypeNameTraits<size_type>::name () <<
") != this->getLocalNumElements()"
2055 " = " << this->getLocalNumElements () <<
". The latter, upon being "
2056 "cast to size_type = " << TypeNameTraits<size_type>::name () <<
", "
2057 "becomes " << lclNumInds <<
". Please report this bug to the Tpetra "
2060 Teuchos::ArrayView<const GO> lgMap = this->getLocalElementList ();
2063 const GO indexBase = this->getIndexBase ();
2065 auto lgMap_device = Kokkos::create_mirror_view_and_copy(
device_type(), lgMap);
2066 return rcp (
new map_type (RECOMPUTE, lgMap_device, indexBase, newComm));
2070 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2071 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
2075 using Teuchos::Comm;
2076 using Teuchos::null;
2077 using Teuchos::outArg;
2080 using Teuchos::REDUCE_MIN;
2081 using Teuchos::reduceAll;
2088 const int color = (numLocalElements_ == 0) ? 0 : 1;
2093 RCP<const Comm<int> > newComm = comm_->split (color, 0);
2099 if (newComm.is_null ()) {
2102 RCP<Map> map = rcp (
new Map ());
2104 map->comm_ = newComm;
2105 map->indexBase_ = indexBase_;
2106 map->numGlobalElements_ = numGlobalElements_;
2107 map->numLocalElements_ = numLocalElements_;
2108 map->minMyGID_ = minMyGID_;
2109 map->maxMyGID_ = maxMyGID_;
2110 map->minAllGID_ = minAllGID_;
2111 map->maxAllGID_ = maxAllGID_;
2112 map->firstContiguousGID_= firstContiguousGID_;
2113 map->lastContiguousGID_ = lastContiguousGID_;
2117 map->uniform_ = uniform_;
2118 map->contiguous_ = contiguous_;
2133 if (! distributed_ || newComm->getSize () == 1) {
2134 map->distributed_ =
false;
2136 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2137 int allProcsOwnAllGids = 0;
2138 reduceAll<int, int> (*newComm, REDUCE_MIN, iOwnAllGids, outArg (allProcsOwnAllGids));
2139 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
2142 map->lgMap_ = lgMap_;
2143 map->lgMapHost_ = lgMapHost_;
2144 map->glMap_ = glMap_;
2145 map->glMapHost_ = glMapHost_;
2162 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2166 TEUCHOS_TEST_FOR_EXCEPTION(
2167 directory_.is_null (), std::logic_error,
"Tpetra::Map::setupDirectory: "
2168 "The Directory is null. "
2169 "Please report this bug to the Tpetra developers.");
2173 if (! directory_->initialized ()) {
2174 directory_->initialize (*
this);
2178 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2182 const Teuchos::ArrayView<int>& PIDs,
2183 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const
2185 using Tpetra::Details::OrdinalTraits;
2188 using size_type = Teuchos::ArrayView<int>::size_type;
2191 const size_t maxNumToPrint = verbose ?
2193 std::unique_ptr<std::string> prefix;
2196 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2197 std::ostringstream os;
2198 os << *prefix <<
"Start: ";
2201 std::cerr << os.str();
2210 if (getGlobalNumElements () == 0) {
2211 if (GIDs.size () == 0) {
2213 std::ostringstream os;
2214 os << *prefix <<
"Done; both Map & input are empty" << endl;
2215 std::cerr << os.str();
2221 std::ostringstream os;
2222 os << *prefix <<
"Done: Map is empty on all processes, "
2223 "so all output PIDs & LIDs are invalid (-1)." << endl;
2224 std::cerr << os.str();
2226 for (size_type k = 0; k < PIDs.size (); ++k) {
2227 PIDs[k] = OrdinalTraits<int>::invalid ();
2229 for (size_type k = 0; k < LIDs.size (); ++k) {
2230 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid ();
2241 std::ostringstream os;
2242 os << *prefix <<
"Call setupDirectory" << endl;
2243 std::cerr << os.str();
2247 std::ostringstream os;
2248 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2249 std::cerr << os.str();
2252 directory_->getDirectoryEntries (*
this, GIDs, PIDs, LIDs);
2254 std::ostringstream os;
2255 os << *prefix <<
"Done; getDirectoryEntries returned "
2256 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2262 std::cerr << os.str();
2267 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2271 const Teuchos::ArrayView<int> & PIDs)
const
2277 const size_t maxNumToPrint = verbose ?
2279 std::unique_ptr<std::string> prefix;
2282 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2283 std::ostringstream os;
2284 os << *prefix <<
"Start: ";
2287 std::cerr << os.str();
2290 if (getGlobalNumElements () == 0) {
2291 if (GIDs.size () == 0) {
2293 std::ostringstream os;
2294 os << *prefix <<
"Done; both Map & input are empty" << endl;
2295 std::cerr << os.str();
2301 std::ostringstream os;
2302 os << *prefix <<
"Done: Map is empty on all processes, "
2303 "so all output PIDs are invalid (-1)." << endl;
2304 std::cerr << os.str();
2306 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size (); ++k) {
2307 PIDs[k] = Tpetra::Details::OrdinalTraits<int>::invalid ();
2318 std::ostringstream os;
2319 os << *prefix <<
"Call setupDirectory" << endl;
2320 std::cerr << os.str();
2324 std::ostringstream os;
2325 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2326 std::cerr << os.str();
2329 directory_->getDirectoryEntries(*
this, GIDs, PIDs);
2331 std::ostringstream os;
2332 os << *prefix <<
"Done; getDirectoryEntries returned "
2333 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2337 std::cerr << os.str();
2342 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2345 using exec_space =
typename Node::device_type::execution_space;
2346 if(lgMap_.extent(0) != lgMapHost_.extent(0)) {
2352 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace (), lgMap_);
2357 exec_space().fence();
2358 lgMapHost_ = lgMap_host;
2361 glMapHost_ = global_to_local_table_host_type(glMap_);
2366 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2367 Teuchos::RCP<const Teuchos::Comm<int> >
2372 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2378 using Teuchos::outArg;
2379 using Teuchos::REDUCE_MIN;
2380 using Teuchos::reduceAll;
2384 std::unique_ptr<std::string> prefix;
2387 comm_.getRawPtr(),
"Map",
"checkIsDist");
2388 std::ostringstream os;
2389 os << *prefix <<
"Start" << endl;
2390 std::cerr << os.str();
2393 bool global =
false;
2394 if (comm_->getSize () > 1) {
2398 if (numGlobalElements_ == as<global_size_t> (numLocalElements_)) {
2411 reduceAll<int, int> (*comm_, REDUCE_MIN, localRep, outArg (allLocalRep));
2412 if (allLocalRep != 1) {
2422 std::ostringstream os;
2423 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2425 std::cerr << os.str();
2432 template <
class LocalOrdinal,
class GlobalOrdinal>
2433 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2435 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2437 typedef LocalOrdinal LO;
2438 typedef GlobalOrdinal GO;
2439 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2440 return createLocalMapWithNode<LO, GO, NT> (numElements, comm);
2443 template <
class LocalOrdinal,
class GlobalOrdinal>
2444 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2446 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2448 typedef LocalOrdinal LO;
2449 typedef GlobalOrdinal GO;
2450 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2451 return createUniformContigMapWithNode<LO, GO, NT> (numElements, comm);
2454 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2455 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2457 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2462 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2464 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed));
2467 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2468 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2470 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2476 const GlobalOrdinal indexBase = 0;
2479 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated));
2482 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2483 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2485 const size_t localNumElements,
2486 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2491 const GlobalOrdinal indexBase = 0;
2493 return rcp (
new map_type (numElements, localNumElements, indexBase, comm));
2496 template <
class LocalOrdinal,
class GlobalOrdinal>
2497 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2499 const size_t localNumElements,
2500 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2502 typedef LocalOrdinal LO;
2503 typedef GlobalOrdinal GO;
2506 return Tpetra::createContigMapWithNode<LO, GO, NT> (numElements, localNumElements, comm);
2509 template <
class LocalOrdinal,
class GlobalOrdinal>
2510 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2512 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2514 typedef LocalOrdinal LO;
2515 typedef GlobalOrdinal GO;
2518 return Tpetra::createNonContigMapWithNode<LO, GO, NT> (elementList, comm);
2521 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2522 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2524 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2530 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2534 const GlobalOrdinal indexBase = 0;
2536 return rcp (
new map_type (INV, elementList, indexBase, comm));
2539 template<
class LO,
class GO,
class NT>
2540 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >
2544 using Teuchos::Array;
2545 using Teuchos::ArrayView;
2553 const bool verbose = Details::Behavior::verbose(
"Map");
2554 std::unique_ptr<std::string> prefix;
2556 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2557 prefix = Details::createPrefix(
2558 comm.getRawPtr(),
"createOneToOne(Map)");
2559 std::ostringstream os;
2560 os << *prefix <<
"Start" << endl;
2563 const size_t maxNumToPrint = verbose ?
2564 Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2565 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2566 const int myRank = M->getComm ()->getRank ();
2572 if (! M->isDistributed ()) {
2579 const GST numGlobalEntries = M->getGlobalNumElements ();
2580 if (M->isContiguous()) {
2581 const size_t numLocalEntries =
2582 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2584 std::ostringstream os;
2585 os << *prefix <<
"Input is locally replicated & contiguous; "
2586 "numLocalEntries=" << numLocalEntries << endl;
2590 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2591 M->getIndexBase(), M->getComm()));
2593 std::ostringstream os;
2594 os << *prefix <<
"Done" << endl;
2601 std::ostringstream os;
2602 os << *prefix <<
"Input is locally replicated & noncontiguous"
2606 ArrayView<const GO> myGids =
2607 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2609 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2612 std::ostringstream os;
2613 os << *prefix <<
"Done" << endl;
2619 else if (M->isContiguous ()) {
2621 std::ostringstream os;
2622 os << *prefix <<
"Input is distributed & contiguous" << endl;
2631 std::ostringstream os;
2632 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2636 const size_t numMyElems = M->getLocalNumElements ();
2637 ArrayView<const GO> myElems = M->getLocalElementList ();
2638 Array<int> owner_procs_vec (numMyElems);
2641 std::ostringstream os;
2642 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2649 std::ostringstream os;
2650 os << *prefix <<
"getDirectoryEntries result: ";
2656 Array<GO> myOwned_vec (numMyElems);
2657 size_t numMyOwnedElems = 0;
2658 for (
size_t i = 0; i < numMyElems; ++i) {
2659 const GO GID = myElems[i];
2660 const int owner = owner_procs_vec[i];
2662 if (myRank == owner) {
2663 myOwned_vec[numMyOwnedElems++] = GID;
2666 myOwned_vec.resize (numMyOwnedElems);
2669 std::ostringstream os;
2670 os << *prefix <<
"Create Map: ";
2675 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2676 M->getIndexBase(), M->getComm()));
2678 std::ostringstream os;
2679 os << *prefix <<
"Done" << endl;
2686 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2687 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2691 using Details::Behavior;
2693 using Teuchos::Array;
2694 using Teuchos::ArrayView;
2697 using Teuchos::toString;
2700 using LO = LocalOrdinal;
2701 using GO = GlobalOrdinal;
2704 const bool verbose = Behavior::verbose(
"Map");
2705 std::unique_ptr<std::string> prefix;
2707 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2708 prefix = Details::createPrefix(
2709 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2710 std::ostringstream os;
2711 os << *prefix <<
"Start" << endl;
2714 const size_t maxNumToPrint = verbose ?
2715 Behavior::verbosePrintCountThreshold() : size_t(0);
2722 std::ostringstream os;
2723 os << *prefix <<
"Initialize Directory" << endl;
2728 std::ostringstream os;
2729 os << *prefix <<
"Done initializing Directory" << endl;
2732 size_t numMyElems = M->getLocalNumElements ();
2733 ArrayView<const GO> myElems = M->getLocalElementList ();
2734 Array<int> owner_procs_vec (numMyElems);
2736 std::ostringstream os;
2737 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2744 std::ostringstream os;
2745 os << *prefix <<
"getDirectoryEntries result: ";
2751 const int myRank = M->getComm()->getRank();
2752 Array<GO> myOwned_vec (numMyElems);
2753 size_t numMyOwnedElems = 0;
2754 for (
size_t i = 0; i < numMyElems; ++i) {
2755 const GO GID = myElems[i];
2756 const int owner = owner_procs_vec[i];
2757 if (myRank == owner) {
2758 myOwned_vec[numMyOwnedElems++] = GID;
2761 myOwned_vec.resize (numMyOwnedElems);
2766 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
2768 std::ostringstream os;
2769 os << *prefix <<
"Create Map: ";
2774 RCP<const map_type> retMap
2775 (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2778 std::ostringstream os;
2779 os << *prefix <<
"Done" << endl;
2793 #define TPETRA_MAP_INSTANT(LO,GO,NODE) \
2795 template class Map< LO , GO , NODE >; \
2797 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2798 createLocalMapWithNode<LO,GO,NODE> (const size_t numElements, \
2799 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2801 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2802 createContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2803 const size_t localNumElements, \
2804 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2806 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2807 createNonContigMapWithNode(const Teuchos::ArrayView<const GO> &elementList, \
2808 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); \
2810 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2811 createUniformContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2812 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2814 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2815 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M); \
2817 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2818 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M, \
2819 const Tpetra::Details::TieBreak<LO,GO>& tie_break); \
2823 #define TPETRA_MAP_INSTANT_DEFAULTNODE(LO,GO) \
2824 template Teuchos::RCP< const Map<LO,GO> > \
2825 createLocalMap<LO,GO>( const size_t, const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2827 template Teuchos::RCP< const Map<LO,GO> > \
2828 createContigMap<LO,GO>( global_size_t, size_t, \
2829 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2831 template Teuchos::RCP< const Map<LO,GO> > \
2832 createNonContigMap(const Teuchos::ArrayView<const GO> &, \
2833 const Teuchos::RCP<const Teuchos::Comm<int> > &); \
2835 template Teuchos::RCP< const Map<LO,GO> > \
2836 createUniformContigMap<LO,GO>( const global_size_t, \
2837 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2839 #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.
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.
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.
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...
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, 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.
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.
bool isNodeLocalElement(local_ordinal_type localIndex) const
Whether the given local index is valid for this Map on the calling process.
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.
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 > > 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...
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 > > 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< 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.
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.
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...
A parallel distribution of indices over processes.
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.
bool locallySameAs(const Map< local_ordinal_type, global_ordinal_type, node_type > &map) const
Is this Map locally the same as the input Map?
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.
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.
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.
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.
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.
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 ...
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).