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 ArrayView<const GO> lhsElts = getLocalElementList ();
1466 return std::equal (lhsElts.begin (), lhsElts.end (), rhsElts.begin ());
1472 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1485 auto lmap2 = this->getLocalMap();
1487 auto numLocalElements1 = lmap1.getLocalNumElements();
1488 auto numLocalElements2 = lmap2.getLocalNumElements();
1490 if (numLocalElements1 > numLocalElements2) {
1495 if (lmap1.isContiguous () && lmap2.isContiguous ()) {
1497 return ((lmap1.getMinGlobalIndex () == lmap2.getMinGlobalIndex ()) &&
1498 (lmap1.getMaxGlobalIndex () <= lmap2.getMaxGlobalIndex ()));
1501 if (lmap1.getMinGlobalIndex () < lmap2.getMinGlobalIndex () ||
1502 lmap1.getMaxGlobalIndex () > lmap2.getMaxGlobalIndex ()) {
1510 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1514 Kokkos::parallel_reduce(
1516 range_type(0, numLocalElements1),
1517 KOKKOS_LAMBDA (
const LO i, LO& diff) {
1518 diff += (lmap1.getGlobalElement(i) != lmap2.getGlobalElement(i));
1521 return (numDiff == 0);
1524 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1529 using Teuchos::outArg;
1530 using Teuchos::REDUCE_MIN;
1531 using Teuchos::reduceAll;
1541 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1564 else if (isContiguous () && isUniform () &&
1585 const int isSame_lcl = locallySameAs (map) ? 1 : 0;
1589 reduceAll<int, int> (*comm_, REDUCE_MIN, isSame_lcl, outArg (isSame_gbl));
1590 return isSame_gbl == 1;
1594 template <
class LO,
class GO,
class DT>
1597 FillLgMap (
const Kokkos::View<GO*, DT>& lgMap,
1598 const GO startGid) :
1599 lgMap_ (lgMap), startGid_ (startGid)
1601 Kokkos::RangePolicy<LO, typename DT::execution_space>
1602 range (static_cast<LO> (0), static_cast<LO> (lgMap.size ()));
1603 Kokkos::parallel_for (range, *
this);
1606 KOKKOS_INLINE_FUNCTION
void operator () (
const LO& lid)
const {
1607 lgMap_(lid) = startGid_ +
static_cast<GO
> (lid);
1611 const Kokkos::View<GO*, DT> lgMap_;
1618 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1619 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_type
1625 using const_lg_view_type = decltype(lgMap_);
1626 using lg_view_type =
typename const_lg_view_type::non_const_type;
1630 std::unique_ptr<std::string> prefix;
1633 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1634 std::ostringstream os;
1635 os << *prefix <<
"Start" << endl;
1636 std::cerr << os.str();
1642 const bool needToCreateLocalToGlobalMapping =
1643 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1645 if (needToCreateLocalToGlobalMapping) {
1647 std::ostringstream os;
1648 os << *prefix <<
"Need to create lgMap" << endl;
1649 std::cerr << os.str();
1654 TEUCHOS_TEST_FOR_EXCEPTION
1655 (! isContiguous(), std::logic_error,
1656 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1657 "mapping (lgMap_) should have been set up already for a "
1658 "noncontiguous Map. Please report this bug to the Tpetra "
1661 const LO numElts =
static_cast<LO
> (getLocalNumElements ());
1663 using Kokkos::view_alloc;
1664 using Kokkos::WithoutInitializing;
1665 lg_view_type lgMap (
"lgMap", numElts);
1667 std::ostringstream os;
1668 os << *prefix <<
"Fill lgMap" << endl;
1669 std::cerr << os.str();
1671 FillLgMap<LO, GO, device_type> fillIt (lgMap, minMyGID_);
1674 std::ostringstream os;
1675 os << *prefix <<
"Copy lgMap to lgMapHost" << endl;
1676 std::cerr << os.str();
1679 auto lgMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
1686 exec_instance.fence();
1690 lgMapHost_ = lgMapHost;
1697 std::ostringstream os;
1698 os << *prefix <<
"Done" << endl;
1699 std::cerr << os.str();
1705 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1706 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_device_type
1712 using const_lg_view_type = decltype(lgMap_);
1713 using lg_view_type =
typename const_lg_view_type::non_const_type;
1717 std::unique_ptr<std::string> prefix;
1720 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1721 std::ostringstream os;
1722 os << *prefix <<
"Start" << endl;
1723 std::cerr << os.str();
1729 const bool needToCreateLocalToGlobalMapping =
1730 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1732 if (needToCreateLocalToGlobalMapping) {
1734 std::ostringstream os;
1735 os << *prefix <<
"Need to create lgMap" << endl;
1736 std::cerr << os.str();
1741 TEUCHOS_TEST_FOR_EXCEPTION
1742 (! isContiguous(), std::logic_error,
1743 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1744 "mapping (lgMap_) should have been set up already for a "
1745 "noncontiguous Map. Please report this bug to the Tpetra "
1748 const LO numElts =
static_cast<LO
> (getLocalNumElements ());
1750 using Kokkos::view_alloc;
1751 using Kokkos::WithoutInitializing;
1752 lg_view_type lgMap (
"lgMap", numElts);
1754 std::ostringstream os;
1755 os << *prefix <<
"Fill lgMap" << endl;
1756 std::cerr << os.str();
1758 FillLgMap<LO, GO, device_type> fillIt (lgMap, minMyGID_);
1765 std::ostringstream os;
1766 os << *prefix <<
"Done" << endl;
1767 std::cerr << os.str();
1774 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1775 Teuchos::ArrayView<const GlobalOrdinal>
1783 (void) this->getMyGlobalIndices ();
1787 const GO* lgMapHostRawPtr = lgMapHost_.data ();
1791 return Teuchos::ArrayView<const GO>(
1793 lgMapHost_.extent (0),
1794 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1797 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1799 return distributed_;
1802 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1804 using Teuchos::TypeNameTraits;
1805 std::ostringstream os;
1807 os <<
"Tpetra::Map: {"
1808 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name ()
1809 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name ()
1810 <<
", NodeType: " << TypeNameTraits<Node>::name ();
1811 if (this->getObjectLabel () !=
"") {
1812 os <<
", Label: \"" << this->getObjectLabel () <<
"\"";
1814 os <<
", Global number of entries: " << getGlobalNumElements ()
1815 <<
", Number of processes: " << getComm ()->getSize ()
1816 <<
", Uniform: " << (isUniform () ?
"true" :
"false")
1817 <<
", Contiguous: " << (isContiguous () ?
"true" :
"false")
1818 <<
", Distributed: " << (isDistributed () ?
"true" :
"false")
1827 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1832 using LO = local_ordinal_type;
1836 if (vl < Teuchos::VERB_HIGH) {
1837 return std::string ();
1839 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
1840 Teuchos::RCP<Teuchos::FancyOStream> outp =
1841 Teuchos::getFancyOStream (outStringP);
1842 Teuchos::FancyOStream& out = *outp;
1844 auto comm = this->getComm ();
1845 const int myRank = comm->getRank ();
1846 const int numProcs = comm->getSize ();
1847 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1848 Teuchos::OSTab tab1 (out);
1850 const LO numEnt =
static_cast<LO
> (this->getLocalNumElements ());
1851 out <<
"My number of entries: " << numEnt << endl
1852 <<
"My minimum global index: " << this->getMinGlobalIndex () << endl
1853 <<
"My maximum global index: " << this->getMaxGlobalIndex () << endl;
1855 if (vl == Teuchos::VERB_EXTREME) {
1856 out <<
"My global indices: [";
1857 const LO minLclInd = this->getMinLocalIndex ();
1858 for (LO k = 0; k < numEnt; ++k) {
1859 out << minLclInd + this->getGlobalElement (k);
1860 if (k + 1 < numEnt) {
1868 return outStringP->str ();
1871 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1875 const Teuchos::EVerbosityLevel verbLevel)
const
1877 using Teuchos::TypeNameTraits;
1878 using Teuchos::VERB_DEFAULT;
1879 using Teuchos::VERB_NONE;
1880 using Teuchos::VERB_LOW;
1881 using Teuchos::VERB_HIGH;
1885 const Teuchos::EVerbosityLevel vl =
1886 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1888 if (vl == VERB_NONE) {
1895 auto comm = this->getComm ();
1896 if (comm.is_null ()) {
1899 const int myRank = comm->getRank ();
1900 const int numProcs = comm->getSize ();
1909 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1915 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
1916 out <<
"\"Tpetra::Map\":" << endl;
1917 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
1919 out <<
"Template parameters:" << endl;
1920 Teuchos::OSTab tab2 (out);
1921 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name () << endl
1922 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name () << endl
1923 <<
"Node: " << TypeNameTraits<Node>::name () << endl;
1925 const std::string label = this->getObjectLabel ();
1927 out <<
"Label: \"" << label <<
"\"" << endl;
1929 out <<
"Global number of entries: " << getGlobalNumElements () << endl
1930 <<
"Minimum global index: " << getMinAllGlobalIndex () << endl
1931 <<
"Maximum global index: " << getMaxAllGlobalIndex () << endl
1932 <<
"Index base: " << getIndexBase () << endl
1933 <<
"Number of processes: " << numProcs << endl
1934 <<
"Uniform: " << (isUniform () ?
"true" :
"false") << endl
1935 <<
"Contiguous: " << (isContiguous () ?
"true" :
"false") << endl
1936 <<
"Distributed: " << (isDistributed () ?
"true" :
"false") << endl;
1940 if (vl >= VERB_HIGH) {
1941 const std::string lclStr = this->localDescribeToString (vl);
1946 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1947 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1965 if (newComm.is_null () || newComm->getSize () < 1) {
1966 return Teuchos::null;
1968 else if (newComm->getSize () == 1) {
1975 RCP<map_type> newMap (
new map_type ());
1977 newMap->comm_ = newComm;
1981 newMap->indexBase_ = this->indexBase_;
1982 newMap->numGlobalElements_ = this->numLocalElements_;
1983 newMap->numLocalElements_ = this->numLocalElements_;
1984 newMap->minMyGID_ = this->minMyGID_;
1985 newMap->maxMyGID_ = this->maxMyGID_;
1986 newMap->minAllGID_ = this->minMyGID_;
1987 newMap->maxAllGID_ = this->maxMyGID_;
1988 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1989 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1992 newMap->uniform_ = this->uniform_;
1993 newMap->contiguous_ = this->contiguous_;
1996 newMap->distributed_ =
false;
1997 newMap->lgMap_ = this->lgMap_;
1998 newMap->lgMapHost_ = this->lgMapHost_;
1999 newMap->glMap_ = this->glMap_;
2000 newMap->glMapHost_ = this->glMapHost_;
2021 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2037 auto lgMap = this->getMyGlobalIndices ();
2039 typename std::decay<decltype (lgMap.extent (0)) >::type;
2040 const size_type lclNumInds =
2041 static_cast<size_type
> (this->getLocalNumElements ());
2042 using Teuchos::TypeNameTraits;
2043 TEUCHOS_TEST_FOR_EXCEPTION
2044 (lgMap.extent (0) != lclNumInds, std::logic_error,
2045 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
2046 "has length " << lgMap.extent (0) <<
" (of type " <<
2047 TypeNameTraits<size_type>::name () <<
") != this->getLocalNumElements()"
2048 " = " << this->getLocalNumElements () <<
". The latter, upon being "
2049 "cast to size_type = " << TypeNameTraits<size_type>::name () <<
", "
2050 "becomes " << lclNumInds <<
". Please report this bug to the Tpetra "
2053 Teuchos::ArrayView<const GO> lgMap = this->getLocalElementList ();
2056 const GO indexBase = this->getIndexBase ();
2058 auto lgMap_device = Kokkos::create_mirror_view_and_copy(
device_type(), lgMap);
2059 return rcp (
new map_type (RECOMPUTE, lgMap_device, indexBase, newComm));
2063 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2064 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
2068 using Teuchos::Comm;
2069 using Teuchos::null;
2070 using Teuchos::outArg;
2073 using Teuchos::REDUCE_MIN;
2074 using Teuchos::reduceAll;
2081 const int color = (numLocalElements_ == 0) ? 0 : 1;
2086 RCP<const Comm<int> > newComm = comm_->split (color, 0);
2092 if (newComm.is_null ()) {
2095 RCP<Map> map = rcp (
new Map ());
2097 map->comm_ = newComm;
2098 map->indexBase_ = indexBase_;
2099 map->numGlobalElements_ = numGlobalElements_;
2100 map->numLocalElements_ = numLocalElements_;
2101 map->minMyGID_ = minMyGID_;
2102 map->maxMyGID_ = maxMyGID_;
2103 map->minAllGID_ = minAllGID_;
2104 map->maxAllGID_ = maxAllGID_;
2105 map->firstContiguousGID_= firstContiguousGID_;
2106 map->lastContiguousGID_ = lastContiguousGID_;
2110 map->uniform_ = uniform_;
2111 map->contiguous_ = contiguous_;
2126 if (! distributed_ || newComm->getSize () == 1) {
2127 map->distributed_ =
false;
2129 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2130 int allProcsOwnAllGids = 0;
2131 reduceAll<int, int> (*newComm, REDUCE_MIN, iOwnAllGids, outArg (allProcsOwnAllGids));
2132 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
2135 map->lgMap_ = lgMap_;
2136 map->lgMapHost_ = lgMapHost_;
2137 map->glMap_ = glMap_;
2138 map->glMapHost_ = glMapHost_;
2155 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2159 TEUCHOS_TEST_FOR_EXCEPTION(
2160 directory_.is_null (), std::logic_error,
"Tpetra::Map::setupDirectory: "
2161 "The Directory is null. "
2162 "Please report this bug to the Tpetra developers.");
2166 if (! directory_->initialized ()) {
2167 directory_->initialize (*
this);
2171 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2175 const Teuchos::ArrayView<int>& PIDs,
2176 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const
2178 using Tpetra::Details::OrdinalTraits;
2181 using size_type = Teuchos::ArrayView<int>::size_type;
2184 const size_t maxNumToPrint = verbose ?
2186 std::unique_ptr<std::string> prefix;
2189 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2190 std::ostringstream os;
2191 os << *prefix <<
"Start: ";
2194 std::cerr << os.str();
2203 if (getGlobalNumElements () == 0) {
2204 if (GIDs.size () == 0) {
2206 std::ostringstream os;
2207 os << *prefix <<
"Done; both Map & input are empty" << endl;
2208 std::cerr << os.str();
2214 std::ostringstream os;
2215 os << *prefix <<
"Done: Map is empty on all processes, "
2216 "so all output PIDs & LIDs are invalid (-1)." << endl;
2217 std::cerr << os.str();
2219 for (size_type k = 0; k < PIDs.size (); ++k) {
2220 PIDs[k] = OrdinalTraits<int>::invalid ();
2222 for (size_type k = 0; k < LIDs.size (); ++k) {
2223 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid ();
2234 std::ostringstream os;
2235 os << *prefix <<
"Call setupDirectory" << endl;
2236 std::cerr << os.str();
2240 std::ostringstream os;
2241 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2242 std::cerr << os.str();
2245 directory_->getDirectoryEntries (*
this, GIDs, PIDs, LIDs);
2247 std::ostringstream os;
2248 os << *prefix <<
"Done; getDirectoryEntries returned "
2249 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2255 std::cerr << os.str();
2260 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2264 const Teuchos::ArrayView<int> & PIDs)
const
2270 const size_t maxNumToPrint = verbose ?
2272 std::unique_ptr<std::string> prefix;
2275 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2276 std::ostringstream os;
2277 os << *prefix <<
"Start: ";
2280 std::cerr << os.str();
2283 if (getGlobalNumElements () == 0) {
2284 if (GIDs.size () == 0) {
2286 std::ostringstream os;
2287 os << *prefix <<
"Done; both Map & input are empty" << endl;
2288 std::cerr << os.str();
2294 std::ostringstream os;
2295 os << *prefix <<
"Done: Map is empty on all processes, "
2296 "so all output PIDs are invalid (-1)." << endl;
2297 std::cerr << os.str();
2299 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size (); ++k) {
2300 PIDs[k] = Tpetra::Details::OrdinalTraits<int>::invalid ();
2311 std::ostringstream os;
2312 os << *prefix <<
"Call setupDirectory" << endl;
2313 std::cerr << os.str();
2317 std::ostringstream os;
2318 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2319 std::cerr << os.str();
2322 directory_->getDirectoryEntries(*
this, GIDs, PIDs);
2324 std::ostringstream os;
2325 os << *prefix <<
"Done; getDirectoryEntries returned "
2326 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2330 std::cerr << os.str();
2335 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2338 using exec_space =
typename Node::device_type::execution_space;
2339 if(lgMap_.extent(0) != lgMapHost_.extent(0)) {
2345 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace (), lgMap_);
2350 exec_space().fence();
2351 lgMapHost_ = lgMap_host;
2354 glMapHost_ = global_to_local_table_host_type(glMap_);
2359 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2360 Teuchos::RCP<const Teuchos::Comm<int> >
2365 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2371 using Teuchos::outArg;
2372 using Teuchos::REDUCE_MIN;
2373 using Teuchos::reduceAll;
2377 std::unique_ptr<std::string> prefix;
2380 comm_.getRawPtr(),
"Map",
"checkIsDist");
2381 std::ostringstream os;
2382 os << *prefix <<
"Start" << endl;
2383 std::cerr << os.str();
2386 bool global =
false;
2387 if (comm_->getSize () > 1) {
2391 if (numGlobalElements_ == as<global_size_t> (numLocalElements_)) {
2404 reduceAll<int, int> (*comm_, REDUCE_MIN, localRep, outArg (allLocalRep));
2405 if (allLocalRep != 1) {
2415 std::ostringstream os;
2416 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2418 std::cerr << os.str();
2425 template <
class LocalOrdinal,
class GlobalOrdinal>
2426 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2428 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2430 typedef LocalOrdinal LO;
2431 typedef GlobalOrdinal GO;
2432 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2433 return createLocalMapWithNode<LO, GO, NT> (numElements, comm);
2436 template <
class LocalOrdinal,
class GlobalOrdinal>
2437 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2439 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2441 typedef LocalOrdinal LO;
2442 typedef GlobalOrdinal GO;
2443 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2444 return createUniformContigMapWithNode<LO, GO, NT> (numElements, comm);
2447 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2448 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2450 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2455 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2457 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed));
2460 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2461 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2463 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2469 const GlobalOrdinal indexBase = 0;
2472 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated));
2475 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2476 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2478 const size_t localNumElements,
2479 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2484 const GlobalOrdinal indexBase = 0;
2486 return rcp (
new map_type (numElements, localNumElements, indexBase, comm));
2489 template <
class LocalOrdinal,
class GlobalOrdinal>
2490 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2492 const size_t localNumElements,
2493 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2495 typedef LocalOrdinal LO;
2496 typedef GlobalOrdinal GO;
2499 return Tpetra::createContigMapWithNode<LO, GO, NT> (numElements, localNumElements, comm);
2502 template <
class LocalOrdinal,
class GlobalOrdinal>
2503 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2505 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2507 typedef LocalOrdinal LO;
2508 typedef GlobalOrdinal GO;
2511 return Tpetra::createNonContigMapWithNode<LO, GO, NT> (elementList, comm);
2514 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2515 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2517 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2523 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2527 const GlobalOrdinal indexBase = 0;
2529 return rcp (
new map_type (INV, elementList, indexBase, comm));
2532 template<
class LO,
class GO,
class NT>
2533 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >
2537 using Teuchos::Array;
2538 using Teuchos::ArrayView;
2546 const bool verbose = Details::Behavior::verbose(
"Map");
2547 std::unique_ptr<std::string> prefix;
2549 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2550 prefix = Details::createPrefix(
2551 comm.getRawPtr(),
"createOneToOne(Map)");
2552 std::ostringstream os;
2553 os << *prefix <<
"Start" << endl;
2556 const size_t maxNumToPrint = verbose ?
2557 Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2558 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2559 const int myRank = M->getComm ()->getRank ();
2565 if (! M->isDistributed ()) {
2572 const GST numGlobalEntries = M->getGlobalNumElements ();
2573 if (M->isContiguous()) {
2574 const size_t numLocalEntries =
2575 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2577 std::ostringstream os;
2578 os << *prefix <<
"Input is locally replicated & contiguous; "
2579 "numLocalEntries=" << numLocalEntries << endl;
2583 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2584 M->getIndexBase(), M->getComm()));
2586 std::ostringstream os;
2587 os << *prefix <<
"Done" << endl;
2594 std::ostringstream os;
2595 os << *prefix <<
"Input is locally replicated & noncontiguous"
2599 ArrayView<const GO> myGids =
2600 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2602 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2605 std::ostringstream os;
2606 os << *prefix <<
"Done" << endl;
2612 else if (M->isContiguous ()) {
2614 std::ostringstream os;
2615 os << *prefix <<
"Input is distributed & contiguous" << endl;
2624 std::ostringstream os;
2625 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2629 const size_t numMyElems = M->getLocalNumElements ();
2630 ArrayView<const GO> myElems = M->getLocalElementList ();
2631 Array<int> owner_procs_vec (numMyElems);
2634 std::ostringstream os;
2635 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2642 std::ostringstream os;
2643 os << *prefix <<
"getDirectoryEntries result: ";
2649 Array<GO> myOwned_vec (numMyElems);
2650 size_t numMyOwnedElems = 0;
2651 for (
size_t i = 0; i < numMyElems; ++i) {
2652 const GO GID = myElems[i];
2653 const int owner = owner_procs_vec[i];
2655 if (myRank == owner) {
2656 myOwned_vec[numMyOwnedElems++] = GID;
2659 myOwned_vec.resize (numMyOwnedElems);
2662 std::ostringstream os;
2663 os << *prefix <<
"Create Map: ";
2668 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2669 M->getIndexBase(), M->getComm()));
2671 std::ostringstream os;
2672 os << *prefix <<
"Done" << endl;
2679 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2680 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2684 using Details::Behavior;
2686 using Teuchos::Array;
2687 using Teuchos::ArrayView;
2690 using Teuchos::toString;
2693 using LO = LocalOrdinal;
2694 using GO = GlobalOrdinal;
2697 const bool verbose = Behavior::verbose(
"Map");
2698 std::unique_ptr<std::string> prefix;
2700 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2701 prefix = Details::createPrefix(
2702 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2703 std::ostringstream os;
2704 os << *prefix <<
"Start" << endl;
2707 const size_t maxNumToPrint = verbose ?
2708 Behavior::verbosePrintCountThreshold() : size_t(0);
2715 std::ostringstream os;
2716 os << *prefix <<
"Initialize Directory" << endl;
2721 std::ostringstream os;
2722 os << *prefix <<
"Done initializing Directory" << endl;
2725 size_t numMyElems = M->getLocalNumElements ();
2726 ArrayView<const GO> myElems = M->getLocalElementList ();
2727 Array<int> owner_procs_vec (numMyElems);
2729 std::ostringstream os;
2730 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2737 std::ostringstream os;
2738 os << *prefix <<
"getDirectoryEntries result: ";
2744 const int myRank = M->getComm()->getRank();
2745 Array<GO> myOwned_vec (numMyElems);
2746 size_t numMyOwnedElems = 0;
2747 for (
size_t i = 0; i < numMyElems; ++i) {
2748 const GO GID = myElems[i];
2749 const int owner = owner_procs_vec[i];
2750 if (myRank == owner) {
2751 myOwned_vec[numMyOwnedElems++] = GID;
2754 myOwned_vec.resize (numMyOwnedElems);
2759 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
2761 std::ostringstream os;
2762 os << *prefix <<
"Create Map: ";
2767 RCP<const map_type> retMap
2768 (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2771 std::ostringstream os;
2772 os << *prefix <<
"Done" << endl;
2786 #define TPETRA_MAP_INSTANT(LO,GO,NODE) \
2788 template class Map< LO , GO , NODE >; \
2790 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2791 createLocalMapWithNode<LO,GO,NODE> (const size_t numElements, \
2792 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2794 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2795 createContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2796 const size_t localNumElements, \
2797 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2799 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2800 createNonContigMapWithNode(const Teuchos::ArrayView<const GO> &elementList, \
2801 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); \
2803 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2804 createUniformContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2805 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2807 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2808 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M); \
2810 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2811 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M, \
2812 const Tpetra::Details::TieBreak<LO,GO>& tie_break); \
2816 #define TPETRA_MAP_INSTANT_DEFAULTNODE(LO,GO) \
2817 template Teuchos::RCP< const Map<LO,GO> > \
2818 createLocalMap<LO,GO>( const size_t, const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2820 template Teuchos::RCP< const Map<LO,GO> > \
2821 createContigMap<LO,GO>( global_size_t, size_t, \
2822 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2824 template Teuchos::RCP< const Map<LO,GO> > \
2825 createNonContigMap(const Teuchos::ArrayView<const GO> &, \
2826 const Teuchos::RCP<const Teuchos::Comm<int> > &); \
2828 template Teuchos::RCP< const Map<LO,GO> > \
2829 createUniformContigMap<LO,GO>( const global_size_t, \
2830 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2832 #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).