45 #ifndef TPETRA_MAP_DEF_HPP
46 #define TPETRA_MAP_DEF_HPP
48 #include "Tpetra_Directory.hpp"
51 #include "Tpetra_Details_FixedHashTable.hpp"
56 #include "Teuchos_as.hpp"
57 #include "Teuchos_TypeNameTraits.hpp"
58 #include "Teuchos_CommHelpers.hpp"
59 #include "Tpetra_Details_mpiIsInitialized.hpp"
69 template<
class ExecutionSpace>
71 checkMapInputArray (
const char ctorName[],
72 const void* indexList,
73 const size_t indexListSize,
74 const ExecutionSpace& execSpace,
75 const Teuchos::Comm<int>*
const comm)
79 const bool debug = Behavior::debug(
"Map");
82 using Teuchos::outArg;
83 using Teuchos::REDUCE_MIN;
84 using Teuchos::reduceAll;
87 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
88 const bool verbose = Behavior::verbose(
"Map");
89 std::ostringstream lclErrStrm;
92 if (indexListSize != 0 && indexList ==
nullptr) {
95 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
96 "but indexListSize=" << indexListSize <<
" != 0." << endl;
100 if (indexListSize != 0 && indexList !=
nullptr &&
104 using ::Tpetra::Details::memorySpaceName;
106 const std::string execSpaceName =
107 Teuchos::TypeNameTraits<ExecutionSpace>::name ();
108 lclErrStrm <<
"Proc " << myRank <<
": Input array is not "
109 "accessible from the required execution space " <<
110 execSpaceName <<
". As far as I can tell, array lives "
111 "in memory space " << memSpaceName <<
"." << endl;
116 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
117 if (gblSuccess != 1) {
118 std::ostringstream gblErrStrm;
119 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
120 " detected a problem with the input array "
121 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
122 "of global indices." << endl;
124 using ::Tpetra::Details::gathervPrint;
127 TEUCHOS_TEST_FOR_EXCEPTION
128 (
true, std::invalid_argument, gblErrStrm.str ());
136 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 comm_ (new Teuchos::SerialComm<int> ()),
141 numGlobalElements_ (0),
142 numLocalElements_ (0),
143 minMyGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
144 maxMyGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
145 minAllGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
146 maxAllGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
147 firstContiguousGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
148 lastContiguousGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
151 distributed_ (false),
152 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
158 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
162 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
166 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
169 using Teuchos::broadcast;
170 using Teuchos::outArg;
171 using Teuchos::reduceAll;
172 using Teuchos::REDUCE_MIN;
173 using Teuchos::REDUCE_MAX;
174 using Teuchos::typeName;
178 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
179 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
181 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
185 std::unique_ptr<std::string> prefix;
188 comm_.getRawPtr(),
"Map", funcName);
189 std::ostringstream os;
190 os << *prefix <<
"Start" << endl;
191 std::cerr << os.str();
198 GST proc0NumGlobalElements = numGlobalElements;
199 broadcast(*comm_, 0, outArg(proc0NumGlobalElements));
200 GST minNumGlobalElements = numGlobalElements;
201 GST maxNumGlobalElements = numGlobalElements;
202 reduceAll(*comm, REDUCE_MIN, numGlobalElements,
203 outArg(minNumGlobalElements));
204 reduceAll(*comm, REDUCE_MAX, numGlobalElements,
205 outArg(maxNumGlobalElements));
206 TEUCHOS_TEST_FOR_EXCEPTION
207 (minNumGlobalElements != maxNumGlobalElements ||
208 numGlobalElements != minNumGlobalElements,
209 std::invalid_argument, exPfx <<
"All processes must "
210 "provide the same number of global elements. Process 0 set "
211 "numGlobalElements="<< proc0NumGlobalElements <<
". The "
212 "calling process " << comm->getRank() <<
" set "
213 "numGlobalElements=" << numGlobalElements <<
". The min "
214 "and max values over all processes are "
215 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements
218 GO proc0IndexBase = indexBase;
219 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
220 GO minIndexBase = indexBase;
221 GO maxIndexBase = indexBase;
222 reduceAll(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
223 reduceAll(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
224 TEUCHOS_TEST_FOR_EXCEPTION
225 (minIndexBase != maxIndexBase || indexBase != minIndexBase,
226 std::invalid_argument, exPfx <<
"All processes must "
227 "provide the same indexBase argument. Process 0 set "
228 "indexBase=" << proc0IndexBase <<
". The calling process "
229 << comm->getRank() <<
" set indexBase=" << indexBase
230 <<
". The min and max values over all processes are "
231 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
251 TEUCHOS_TEST_FOR_EXCEPTION(
252 (numGlobalElements < 1 && numGlobalElements != 0),
253 std::invalid_argument, exPfx <<
"numGlobalElements (= "
254 << numGlobalElements <<
") must be nonnegative.");
256 TEUCHOS_TEST_FOR_EXCEPTION
257 (numGlobalElements == GSTI, std::invalid_argument, exPfx <<
258 "You provided numGlobalElements = Teuchos::OrdinalTraits<"
259 "Tpetra::global_size_t>::invalid(). This version of the "
260 "constructor requires a valid value of numGlobalElements. "
261 "You probably mistook this constructor for the \"contiguous "
262 "nonuniform\" constructor, which can compute the global "
263 "number of elements for you if you set numGlobalElements to "
264 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
266 size_t numLocalElements = 0;
267 if (lOrG == GloballyDistributed) {
282 const GST numProcs =
static_cast<GST
> (comm_->getSize ());
283 const GST myRank =
static_cast<GST
> (comm_->getRank ());
284 const GST quotient = numGlobalElements / numProcs;
285 const GST remainder = numGlobalElements - quotient * numProcs;
288 if (myRank < remainder) {
289 numLocalElements =
static_cast<size_t> (1) + static_cast<size_t> (quotient);
292 startIndex = as<GO> (myRank) * as<GO> (numLocalElements);
294 numLocalElements = as<size_t> (quotient);
295 startIndex = as<GO> (myRank) * as<GO> (numLocalElements) +
299 minMyGID_ = indexBase + startIndex;
300 maxMyGID_ = indexBase + startIndex + numLocalElements - 1;
301 minAllGID_ = indexBase;
302 maxAllGID_ = indexBase + numGlobalElements - 1;
303 distributed_ = (numProcs > 1);
306 numLocalElements = as<size_t> (numGlobalElements);
307 minMyGID_ = indexBase;
308 maxMyGID_ = indexBase + numGlobalElements - 1;
309 distributed_ =
false;
312 minAllGID_ = indexBase;
313 maxAllGID_ = indexBase + numGlobalElements - 1;
314 indexBase_ = indexBase;
315 numGlobalElements_ = numGlobalElements;
316 numLocalElements_ = numLocalElements;
317 firstContiguousGID_ = minMyGID_;
318 lastContiguousGID_ = maxMyGID_;
325 std::ostringstream os;
326 os << *prefix <<
"Done" << endl;
327 std::cerr << os.str();
332 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
335 const size_t numLocalElements,
337 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm) :
340 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
343 using Teuchos::broadcast;
344 using Teuchos::outArg;
345 using Teuchos::reduceAll;
346 using Teuchos::REDUCE_MIN;
347 using Teuchos::REDUCE_MAX;
348 using Teuchos::REDUCE_SUM;
353 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
354 const char funcName[] =
355 "Map(gblNumInds,lclNumInds,indexBase,comm)";
357 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
358 const char suffix[] =
359 ". Please report this bug to the Tpetra developers.";
363 std::unique_ptr<std::string> prefix;
366 comm_.getRawPtr(),
"Map", funcName);
367 std::ostringstream os;
368 os << *prefix <<
"Start" << endl;
369 std::cerr << os.str();
375 GST debugGlobalSum {};
377 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
378 numGlobalElements, numLocalElements, indexBase, comm);
393 scan<int, GO> (*comm, REDUCE_SUM, numLocalElements, outArg (scanResult));
394 const GO myOffset = scanResult - numLocalElements;
396 if (numGlobalElements != GSTI) {
397 numGlobalElements_ = numGlobalElements;
404 const int numProcs = comm->getSize ();
405 GST globalSum = scanResult;
407 broadcast (*comm, numProcs - 1, outArg (globalSum));
409 numGlobalElements_ = globalSum;
413 TEUCHOS_TEST_FOR_EXCEPTION
414 (globalSum != debugGlobalSum, std::logic_error, exPfx <<
415 "globalSum = " << globalSum <<
" != debugGlobalSum = " <<
416 debugGlobalSum << suffix);
419 numLocalElements_ = numLocalElements;
420 indexBase_ = indexBase;
421 minAllGID_ = (numGlobalElements_ == 0) ?
422 std::numeric_limits<GO>::max () :
424 maxAllGID_ = (numGlobalElements_ == 0) ?
425 std::numeric_limits<GO>::lowest () :
426 indexBase + GO(numGlobalElements_) - GO(1);
427 minMyGID_ = (numLocalElements_ == 0) ?
428 std::numeric_limits<GO>::max () :
429 indexBase + GO(myOffset);
430 maxMyGID_ = (numLocalElements_ == 0) ?
431 std::numeric_limits<GO>::lowest () :
432 indexBase + myOffset + GO(numLocalElements) - GO(1);
433 firstContiguousGID_ = minMyGID_;
434 lastContiguousGID_ = maxMyGID_;
436 distributed_ = checkIsDist ();
442 std::ostringstream os;
443 os << *prefix <<
"Done" << endl;
444 std::cerr << os.str();
448 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
452 const char errorMessagePrefix[],
454 const size_t numLocalElements,
455 const global_ordinal_type indexBase,
456 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const
463 using Teuchos::broadcast;
464 using Teuchos::outArg;
466 using Teuchos::REDUCE_MAX;
467 using Teuchos::REDUCE_MIN;
468 using Teuchos::REDUCE_SUM;
469 using Teuchos::reduceAll;
470 using GO = global_ordinal_type;
472 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
482 GST debugGlobalSum = 0;
483 reduceAll<int, GST> (*comm, REDUCE_SUM,
static_cast<GST
> (numLocalElements),
484 outArg (debugGlobalSum));
488 GST proc0NumGlobalElements = numGlobalElements;
489 broadcast<int, GST> (*comm_, 0, outArg (proc0NumGlobalElements));
490 GST minNumGlobalElements = numGlobalElements;
491 GST maxNumGlobalElements = numGlobalElements;
492 reduceAll<int, GST> (*comm, REDUCE_MIN, numGlobalElements,
493 outArg (minNumGlobalElements));
494 reduceAll<int, GST> (*comm, REDUCE_MAX, numGlobalElements,
495 outArg (maxNumGlobalElements));
496 TEUCHOS_TEST_FOR_EXCEPTION
497 (minNumGlobalElements != maxNumGlobalElements ||
498 numGlobalElements != minNumGlobalElements,
499 std::invalid_argument, errorMessagePrefix <<
"All processes "
500 "must provide the same number of global elements, even if "
502 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
503 "(which signals that the Map should compute the global "
504 "number of elements). Process 0 set numGlobalElements"
505 "=" << proc0NumGlobalElements <<
". The calling process "
506 << comm->getRank() <<
" set numGlobalElements=" <<
507 numGlobalElements <<
". The min and max values over all "
508 "processes are " << minNumGlobalElements <<
" resp. " <<
509 maxNumGlobalElements <<
".");
511 GO proc0IndexBase = indexBase;
512 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
513 GO minIndexBase = indexBase;
514 GO maxIndexBase = indexBase;
515 reduceAll<int, GO> (*comm, REDUCE_MIN, indexBase, outArg (minIndexBase));
516 reduceAll<int, GO> (*comm, REDUCE_MAX, indexBase, outArg (maxIndexBase));
517 TEUCHOS_TEST_FOR_EXCEPTION
518 (minIndexBase != maxIndexBase || indexBase != minIndexBase,
519 std::invalid_argument, errorMessagePrefix <<
520 "All processes must provide the same indexBase argument. "
521 "Process 0 set indexBase = " << proc0IndexBase <<
". The "
522 "calling process " << comm->getRank() <<
" set indexBase="
523 << indexBase <<
". The min and max values over all "
524 "processes are " << minIndexBase <<
" resp. " << maxIndexBase
529 TEUCHOS_TEST_FOR_EXCEPTION
530 (numGlobalElements != GSTI &&
531 debugGlobalSum != numGlobalElements, std::invalid_argument,
532 errorMessagePrefix <<
"The sum of each process' number of "
533 "indices over all processes, " << debugGlobalSum <<
", != "
534 <<
"numGlobalElements=" << numGlobalElements <<
". If you "
535 "would like this constructor to compute numGlobalElements "
536 "for you, you may set numGlobalElements="
537 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
538 "on input. Please note that this is NOT necessarily -1.");
540 return debugGlobalSum;
543 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
545 Map<LocalOrdinal,GlobalOrdinal,Node>::
546 initWithNonownedHostIndexList(
547 const char errorMessagePrefix[],
549 const Kokkos::View<
const global_ordinal_type*,
552 Kokkos::MemoryUnmanaged>& entryList_host,
553 const global_ordinal_type indexBase,
554 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
556 using Kokkos::LayoutLeft;
557 using Kokkos::subview;
559 using Kokkos::view_alloc;
560 using Kokkos::WithoutInitializing;
562 using Teuchos::broadcast;
563 using Teuchos::outArg;
565 using Teuchos::REDUCE_MAX;
566 using Teuchos::REDUCE_MIN;
567 using Teuchos::REDUCE_SUM;
568 using Teuchos::reduceAll;
570 using GO = global_ordinal_type;
572 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
575 TEUCHOS_TEST_FOR_EXCEPTION
576 (! Kokkos::is_initialized (), std::runtime_error,
577 errorMessagePrefix <<
"The Kokkos execution space "
578 << Teuchos::TypeNameTraits<execution_space>::name()
579 <<
" has not been initialized. "
580 "Please initialize it before creating a Map.")
593 const
size_t numLocalElements(entryList_host.size());
595 initialNonuniformDebugCheck(errorMessagePrefix, numGlobalElements,
596 numLocalElements, indexBase, comm);
606 if (numGlobalElements != GSTI) {
607 numGlobalElements_ = numGlobalElements;
610 reduceAll(*comm, REDUCE_SUM,
611 static_cast<GST>(numLocalElements),
612 outArg(numGlobalElements_));
638 numLocalElements_ = numLocalElements;
639 indexBase_ = indexBase;
641 minMyGID_ = indexBase_;
642 maxMyGID_ = indexBase_;
652 if (numLocalElements_ > 0) {
656 typename decltype (lgMap_)::non_const_type lgMap
657 (view_alloc (
"lgMap", WithoutInitializing), numLocalElements_);
659 Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
667 firstContiguousGID_ = entryList_host[0];
668 lastContiguousGID_ = firstContiguousGID_+1;
676 lgMap_host[0] = firstContiguousGID_;
678 for ( ; i < numLocalElements_; ++i) {
679 const GO curGid = entryList_host[i];
680 const LO curLid = as<LO> (i);
682 if (lastContiguousGID_ != curGid)
break;
688 lgMap_host[curLid] = curGid;
689 ++lastContiguousGID_;
691 --lastContiguousGID_;
696 minMyGID_ = firstContiguousGID_;
697 maxMyGID_ = lastContiguousGID_;
702 const std::pair<size_t, size_t> ncRange (i, entryList_host.extent (0));
703 auto nonContigGids_host = subview (entryList_host, ncRange);
704 TEUCHOS_TEST_FOR_EXCEPTION
705 (static_cast<size_t> (nonContigGids_host.extent (0)) !=
706 static_cast<size_t> (entryList_host.extent (0) - i),
707 std::logic_error,
"Tpetra::Map noncontiguous constructor: "
708 "nonContigGids_host.extent(0) = "
709 << nonContigGids_host.extent (0)
710 <<
" != entryList_host.extent(0) - i = "
711 << (entryList_host.extent (0) - i) <<
" = "
712 << entryList_host.extent (0) <<
" - " << i
713 <<
". Please report this bug to the Tpetra developers.");
717 View<GO*, LayoutLeft, device_type>
718 nonContigGids (view_alloc (
"nonContigGids", WithoutInitializing),
719 nonContigGids_host.size ());
722 glMap_ = global_to_local_table_type (nonContigGids,
725 static_cast<LO> (i));
733 for ( ; i < numLocalElements_; ++i) {
734 const GO curGid = entryList_host[i];
735 const LO curLid =
static_cast<LO
> (i);
736 lgMap_host[curLid] = curGid;
740 if (curGid < minMyGID_) {
743 if (curGid > maxMyGID_) {
754 lgMapHost_ = lgMap_host;
757 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
758 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
762 firstContiguousGID_ = indexBase_+1;
763 lastContiguousGID_ = indexBase_;
788 if (std::numeric_limits<GO>::is_signed) {
791 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
794 minMaxInput[0] = -minMyGID_;
795 minMaxInput[1] = maxMyGID_;
796 minMaxInput[2] = localDist;
802 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
803 minAllGID_ = -minMaxOutput[0];
804 maxAllGID_ = minMaxOutput[1];
805 const GO globalDist = minMaxOutput[2];
806 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
810 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
811 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
812 distributed_ = checkIsDist ();
817 TEUCHOS_TEST_FOR_EXCEPTION(
818 minAllGID_ < indexBase_,
819 std::invalid_argument,
820 "Tpetra::Map constructor (noncontiguous): "
821 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
822 "less than the given indexBase = " << indexBase_ <<
".");
828 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
831 const GlobalOrdinal indexList[],
832 const LocalOrdinal indexListSize,
833 const GlobalOrdinal indexBase,
834 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
837 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
840 const char funcName[] =
841 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
844 std::unique_ptr<std::string> prefix;
847 comm_.getRawPtr(),
"Map", funcName);
848 std::ostringstream os;
849 os << *prefix <<
"Start" << endl;
850 std::cerr << os.str();
853 checkMapInputArray (
"(GST, const GO[], LO, GO, comm)",
854 indexList, static_cast<size_t> (indexListSize),
855 Kokkos::DefaultHostExecutionSpace (),
860 const GlobalOrdinal*
const indsRaw = indexListSize == 0 ? NULL : indexList;
861 Kokkos::View<
const GlobalOrdinal*,
864 Kokkos::MemoryUnmanaged> inds (indsRaw, indexListSize);
865 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
868 std::ostringstream os;
869 os << *prefix <<
"Done" << endl;
870 std::cerr << os.str();
874 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
877 const Teuchos::ArrayView<const GlobalOrdinal>& entryList,
878 const GlobalOrdinal indexBase,
879 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
882 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
885 const char funcName[] =
886 "Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
889 std::unique_ptr<std::string> prefix;
892 comm_.getRawPtr(),
"Map", funcName);
893 std::ostringstream os;
894 os << *prefix <<
"Start" << endl;
895 std::cerr << os.str();
898 const size_t numLclInds =
static_cast<size_t> (entryList.size ());
899 checkMapInputArray (
"(GST, ArrayView, GO, comm)",
900 entryList.getRawPtr (), numLclInds,
901 Kokkos::DefaultHostExecutionSpace (),
906 const GlobalOrdinal*
const indsRaw =
907 numLclInds == 0 ? NULL : entryList.getRawPtr ();
908 Kokkos::View<
const GlobalOrdinal*,
911 Kokkos::MemoryUnmanaged> inds (indsRaw, numLclInds);
912 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
915 std::ostringstream os;
916 os << *prefix <<
"Done" << endl;
917 std::cerr << os.str();
921 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
924 const Kokkos::View<const GlobalOrdinal*, device_type>& entryList,
925 const GlobalOrdinal indexBase,
926 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
929 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
931 using Kokkos::LayoutLeft;
932 using Kokkos::subview;
934 using Kokkos::view_alloc;
935 using Kokkos::WithoutInitializing;
937 using Teuchos::ArrayView;
939 using Teuchos::broadcast;
940 using Teuchos::outArg;
942 using Teuchos::REDUCE_MAX;
943 using Teuchos::REDUCE_MIN;
944 using Teuchos::REDUCE_SUM;
945 using Teuchos::reduceAll;
946 using Teuchos::typeName;
951 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
952 const char funcName[] =
953 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
956 std::unique_ptr<std::string> prefix;
959 comm_.getRawPtr(),
"Map", funcName);
960 std::ostringstream os;
961 os << *prefix <<
"Start" << endl;
962 std::cerr << os.str();
965 checkMapInputArray (
"(GST, Kokkos::View, GO, comm)",
967 static_cast<size_t> (entryList.extent (0)),
981 const size_t numLocalElements(entryList.size());
983 initialNonuniformDebugCheck(funcName, numGlobalElements,
984 numLocalElements, indexBase, comm);
994 if (numGlobalElements != GSTI) {
995 numGlobalElements_ = numGlobalElements;
998 reduceAll(*comm, REDUCE_SUM,
999 static_cast<GST>(numLocalElements),
1000 outArg(numGlobalElements_));
1026 numLocalElements_ = numLocalElements;
1027 indexBase_ = indexBase;
1029 minMyGID_ = indexBase_;
1030 maxMyGID_ = indexBase_;
1040 if (numLocalElements_ > 0) {
1044 typename decltype (lgMap_)::non_const_type lgMap
1045 (view_alloc (
"lgMap", WithoutInitializing), numLocalElements_);
1047 Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
1049 using array_layout =
1050 typename View<const GO*, device_type>::array_layout;
1051 View<GO*, array_layout, Kokkos::HostSpace> entryList_host
1052 (view_alloc (
"entryList_host", WithoutInitializing),
1053 entryList.extent(0));
1056 firstContiguousGID_ = entryList_host[0];
1057 lastContiguousGID_ = firstContiguousGID_+1;
1065 lgMap_host[0] = firstContiguousGID_;
1067 for ( ; i < numLocalElements_; ++i) {
1068 const GO curGid = entryList_host[i];
1069 const LO curLid = as<LO> (i);
1071 if (lastContiguousGID_ != curGid)
break;
1077 lgMap_host[curLid] = curGid;
1078 ++lastContiguousGID_;
1080 --lastContiguousGID_;
1085 minMyGID_ = firstContiguousGID_;
1086 maxMyGID_ = lastContiguousGID_;
1091 const std::pair<size_t, size_t> ncRange (i, entryList.extent (0));
1092 auto nonContigGids = subview (entryList, ncRange);
1093 TEUCHOS_TEST_FOR_EXCEPTION
1094 (static_cast<size_t> (nonContigGids.extent (0)) !=
1095 static_cast<size_t> (entryList.extent (0) - i),
1096 std::logic_error,
"Tpetra::Map noncontiguous constructor: "
1097 "nonContigGids.extent(0) = "
1098 << nonContigGids.extent (0)
1099 <<
" != entryList.extent(0) - i = "
1100 << (entryList.extent (0) - i) <<
" = "
1101 << entryList.extent (0) <<
" - " << i
1102 <<
". Please report this bug to the Tpetra developers.");
1105 firstContiguousGID_,
1107 static_cast<LO> (i));
1115 for ( ; i < numLocalElements_; ++i) {
1116 const GO curGid = entryList_host[i];
1117 const LO curLid =
static_cast<LO
> (i);
1118 lgMap_host[curLid] = curGid;
1122 if (curGid < minMyGID_) {
1125 if (curGid > maxMyGID_) {
1136 lgMapHost_ = lgMap_host;
1139 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1140 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1144 firstContiguousGID_ = indexBase_+1;
1145 lastContiguousGID_ = indexBase_;
1170 if (std::numeric_limits<GO>::is_signed) {
1172 const GO localDist =
1173 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
1176 minMaxInput[0] = -minMyGID_;
1177 minMaxInput[1] = maxMyGID_;
1178 minMaxInput[2] = localDist;
1181 minMaxOutput[0] = 0;
1182 minMaxOutput[1] = 0;
1183 minMaxOutput[2] = 0;
1184 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1185 minAllGID_ = -minMaxOutput[0];
1186 maxAllGID_ = minMaxOutput[1];
1187 const GO globalDist = minMaxOutput[2];
1188 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
1192 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
1193 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
1194 distributed_ = checkIsDist ();
1197 contiguous_ =
false;
1199 TEUCHOS_TEST_FOR_EXCEPTION(
1200 minAllGID_ < indexBase_,
1201 std::invalid_argument,
1202 "Tpetra::Map constructor (noncontiguous): "
1203 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
1204 "less than the given indexBase = " << indexBase_ <<
".");
1210 std::ostringstream os;
1211 os << *prefix <<
"Done" << endl;
1212 std::cerr << os.str();
1217 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1220 if (! Kokkos::is_initialized ()) {
1221 std::ostringstream os;
1222 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1223 "Kokkos::finalize() has been called. This is user error! There are "
1224 "two likely causes: " << std::endl <<
1225 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1227 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1228 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1229 "or Tpetra::finalize()." << std::endl << std::endl <<
1230 "Don't do either of these! Please refer to GitHib Issue #2372."
1232 ::Tpetra::Details::printOnce (std::cerr, os.str (),
1233 this->getComm ().getRawPtr ());
1236 using ::Tpetra::Details::mpiIsInitialized;
1237 using ::Tpetra::Details::mpiIsFinalized;
1238 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1240 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getComm ();
1241 if (! comm.is_null () && teuchosCommIsAnMpiComm (*comm) &&
1242 mpiIsInitialized () && mpiIsFinalized ()) {
1248 std::ostringstream os;
1249 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1250 "MPI_Finalize() has been called. This is user error! There are "
1251 "two likely causes: " << std::endl <<
1252 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1254 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1255 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1256 "Tpetra::finalize()." << std::endl << std::endl <<
1257 "Don't do either of these! Please refer to GitHib Issue #2372."
1259 ::Tpetra::Details::printOnce (std::cerr, os.str (), comm.getRawPtr ());
1267 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1271 TEUCHOS_TEST_FOR_EXCEPTION(
1272 getComm ().is_null (), std::logic_error,
"Tpetra::Map::isOneToOne: "
1273 "getComm() returns null. Please report this bug to the Tpetra "
1278 return directory_->isOneToOne (*
this);
1281 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1286 if (isContiguous ()) {
1287 if (globalIndex < getMinGlobalIndex () ||
1288 globalIndex > getMaxGlobalIndex ()) {
1289 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1291 return static_cast<LocalOrdinal
> (globalIndex - getMinGlobalIndex ());
1293 else if (globalIndex >= firstContiguousGID_ &&
1294 globalIndex <= lastContiguousGID_) {
1295 return static_cast<LocalOrdinal
> (globalIndex - firstContiguousGID_);
1300 return glMap_.get (globalIndex);
1304 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1309 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1310 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ();
1312 if (isContiguous ()) {
1313 return getMinGlobalIndex () + localIndex;
1320 return lgMapHost_[localIndex];
1324 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1329 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1336 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1340 return this->getLocalElement (globalIndex) !=
1341 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1344 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1349 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1355 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1361 getMinGlobalIndex (), getMaxGlobalIndex (),
1362 firstContiguousGID_, lastContiguousGID_,
1363 getNodeNumElements (), isContiguous ());
1366 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1371 using Teuchos::outArg;
1372 using Teuchos::REDUCE_MIN;
1373 using Teuchos::reduceAll;
1383 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1394 else if (isContiguous () && isUniform () &&
1402 lgMap_.extent (0) != 0 && map.lgMap_.extent (0) != 0 &&
1403 lgMap_.data () == map.lgMap_.data ()) {
1417 TEUCHOS_TEST_FOR_EXCEPTION(
1419 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1420 "checked that this condition is true above, but it's false here. "
1421 "Please report this bug to the Tpetra developers.");
1424 const int locallyCompat =
1427 int globallyCompat = 0;
1428 reduceAll<int, int> (*comm_, REDUCE_MIN, locallyCompat, outArg (globallyCompat));
1429 return (globallyCompat == 1);
1432 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1437 using Teuchos::ArrayView;
1439 using size_type =
typename ArrayView<const GO>::size_type;
1462 if (isContiguous ()) {
1467 TEUCHOS_TEST_FOR_EXCEPTION(
1468 ! this->isContiguous () || map.
isContiguous (), std::logic_error,
1469 "Tpetra::Map::locallySameAs: BUG");
1471 const GO minLhsGid = this->getMinGlobalIndex ();
1472 const size_type numRhsElts = rhsElts.size ();
1473 for (size_type k = 0; k < numRhsElts; ++k) {
1474 const GO curLhsGid = minLhsGid +
static_cast<GO
> (k);
1475 if (curLhsGid != rhsElts[k]) {
1483 TEUCHOS_TEST_FOR_EXCEPTION(
1484 this->isContiguous () || ! map.
isContiguous (), std::logic_error,
1485 "Tpetra::Map::locallySameAs: BUG");
1486 ArrayView<const GO> lhsElts = this->getNodeElementList ();
1488 const size_type numLhsElts = lhsElts.size ();
1489 for (size_type k = 0; k < numLhsElts; ++k) {
1490 const GO curRhsGid = minRhsGid +
static_cast<GO
> (k);
1491 if (curRhsGid != lhsElts[k]) {
1497 else if (this->lgMap_.data () == map.lgMap_.data ()) {
1507 ArrayView<const GO> lhsElts = getNodeElementList ();
1513 return std::equal (lhsElts.begin (), lhsElts.end (), rhsElts.begin ());
1519 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1529 auto lmap2 = this->getLocalMap();
1531 auto numLocalElements1 = lmap1.getNodeNumElements();
1532 auto numLocalElements2 = lmap2.getNodeNumElements();
1534 if (numLocalElements1 > numLocalElements2) {
1539 if (lmap1.isContiguous () && lmap2.isContiguous ()) {
1541 return ((lmap1.getMinGlobalIndex () == lmap2.getMinGlobalIndex ()) &&
1542 (lmap1.getMaxGlobalIndex () <= lmap2.getMaxGlobalIndex ()));
1545 if (lmap1.getMinGlobalIndex () < lmap2.getMinGlobalIndex () ||
1546 lmap1.getMaxGlobalIndex () > lmap2.getMaxGlobalIndex ()) {
1554 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1558 Kokkos::parallel_reduce(
1560 range_type(0, numLocalElements1),
1561 KOKKOS_LAMBDA (
const LO i, LO& diff) {
1562 diff += (lmap1.getGlobalElement(i) != lmap2.getGlobalElement(i));
1565 return (numDiff == 0);
1568 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1573 using Teuchos::outArg;
1574 using Teuchos::REDUCE_MIN;
1575 using Teuchos::reduceAll;
1585 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1608 else if (isContiguous () && isUniform () &&
1629 const int isSame_lcl = locallySameAs (map) ? 1 : 0;
1633 reduceAll<int, int> (*comm_, REDUCE_MIN, isSame_lcl, outArg (isSame_gbl));
1634 return isSame_gbl == 1;
1638 template <
class LO,
class GO,
class DT>
1641 FillLgMap (
const Kokkos::View<GO*, DT>& lgMap,
1642 const GO startGid) :
1643 lgMap_ (lgMap), startGid_ (startGid)
1645 Kokkos::RangePolicy<LO, typename DT::execution_space>
1646 range (static_cast<LO> (0), static_cast<LO> (lgMap.size ()));
1647 Kokkos::parallel_for (range, *
this);
1650 KOKKOS_INLINE_FUNCTION
void operator () (
const LO& lid)
const {
1651 lgMap_(lid) = startGid_ +
static_cast<GO
> (lid);
1655 const Kokkos::View<GO*, DT> lgMap_;
1662 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1663 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_type
1670 using const_lg_view_type = decltype(lgMap_);
1671 using lg_view_type =
typename const_lg_view_type::non_const_type;
1675 std::unique_ptr<std::string> prefix;
1678 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1679 std::ostringstream os;
1680 os << *prefix <<
"Start" << endl;
1681 std::cerr << os.str();
1687 const bool needToCreateLocalToGlobalMapping =
1688 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1690 if (needToCreateLocalToGlobalMapping) {
1692 std::ostringstream os;
1693 os << *prefix <<
"Need to create lgMap" << endl;
1694 std::cerr << os.str();
1699 TEUCHOS_TEST_FOR_EXCEPTION
1700 (! isContiguous(), std::logic_error,
1701 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1702 "mapping (lgMap_) should have been set up already for a "
1703 "noncontiguous Map. Please report this bug to the Tpetra "
1706 const LO numElts =
static_cast<LO
> (getNodeNumElements ());
1708 using Kokkos::view_alloc;
1709 using Kokkos::WithoutInitializing;
1710 lg_view_type lgMap (
"lgMap", numElts);
1712 std::ostringstream os;
1713 os << *prefix <<
"Fill lgMap" << endl;
1714 std::cerr << os.str();
1716 FillLgMap<LO, GO, DT> fillIt (lgMap, minMyGID_);
1719 std::ostringstream os;
1720 os << *prefix <<
"Copy lgMap to lgMapHost" << endl;
1721 std::cerr << os.str();
1727 Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
1732 lgMapHost_ = lgMapHost;
1736 std::ostringstream os;
1737 os << *prefix <<
"Done" << endl;
1738 std::cerr << os.str();
1743 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1744 Teuchos::ArrayView<const GlobalOrdinal>
1752 (void) this->getMyGlobalIndices ();
1755 const GO* lgMapHostRawPtr = lgMapHost_.data ();
1759 return Teuchos::ArrayView<const GO>(
1761 lgMapHost_.extent (0),
1762 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1765 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1767 return distributed_;
1770 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1772 using Teuchos::TypeNameTraits;
1773 std::ostringstream os;
1775 os <<
"Tpetra::Map: {"
1776 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name ()
1777 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name ()
1778 <<
", NodeType: " << TypeNameTraits<Node>::name ();
1779 if (this->getObjectLabel () !=
"") {
1780 os <<
", Label: \"" << this->getObjectLabel () <<
"\"";
1782 os <<
", Global number of entries: " << getGlobalNumElements ()
1783 <<
", Number of processes: " << getComm ()->getSize ()
1784 <<
", Uniform: " << (isUniform () ?
"true" :
"false")
1785 <<
", Contiguous: " << (isContiguous () ?
"true" :
"false")
1786 <<
", Distributed: " << (isDistributed () ?
"true" :
"false")
1795 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1800 using LO = local_ordinal_type;
1804 if (vl < Teuchos::VERB_HIGH) {
1805 return std::string ();
1807 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
1808 Teuchos::RCP<Teuchos::FancyOStream> outp =
1809 Teuchos::getFancyOStream (outStringP);
1810 Teuchos::FancyOStream& out = *outp;
1812 auto comm = this->getComm ();
1813 const int myRank = comm->getRank ();
1814 const int numProcs = comm->getSize ();
1815 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1816 Teuchos::OSTab tab1 (out);
1818 const LO numEnt =
static_cast<LO
> (this->getNodeNumElements ());
1819 out <<
"My number of entries: " << numEnt << endl
1820 <<
"My minimum global index: " << this->getMinGlobalIndex () << endl
1821 <<
"My maximum global index: " << this->getMaxGlobalIndex () << endl;
1823 if (vl == Teuchos::VERB_EXTREME) {
1824 out <<
"My global indices: [";
1825 const LO minLclInd = this->getMinLocalIndex ();
1826 for (LO k = 0; k < numEnt; ++k) {
1827 out << minLclInd + this->getGlobalElement (k);
1828 if (k + 1 < numEnt) {
1836 return outStringP->str ();
1839 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1843 const Teuchos::EVerbosityLevel verbLevel)
const
1845 using Teuchos::TypeNameTraits;
1846 using Teuchos::VERB_DEFAULT;
1847 using Teuchos::VERB_NONE;
1848 using Teuchos::VERB_LOW;
1849 using Teuchos::VERB_HIGH;
1853 const Teuchos::EVerbosityLevel vl =
1854 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1856 if (vl == VERB_NONE) {
1863 auto comm = this->getComm ();
1864 if (comm.is_null ()) {
1867 const int myRank = comm->getRank ();
1868 const int numProcs = comm->getSize ();
1877 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1883 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
1884 out <<
"\"Tpetra::Map\":" << endl;
1885 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
1887 out <<
"Template parameters:" << endl;
1888 Teuchos::OSTab tab2 (out);
1889 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name () << endl
1890 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name () << endl
1891 <<
"Node: " << TypeNameTraits<Node>::name () << endl;
1893 const std::string label = this->getObjectLabel ();
1895 out <<
"Label: \"" << label <<
"\"" << endl;
1897 out <<
"Global number of entries: " << getGlobalNumElements () << endl
1898 <<
"Minimum global index: " << getMinAllGlobalIndex () << endl
1899 <<
"Maximum global index: " << getMaxAllGlobalIndex () << endl
1900 <<
"Index base: " << getIndexBase () << endl
1901 <<
"Number of processes: " << numProcs << endl
1902 <<
"Uniform: " << (isUniform () ?
"true" :
"false") << endl
1903 <<
"Contiguous: " << (isContiguous () ?
"true" :
"false") << endl
1904 <<
"Distributed: " << (isDistributed () ?
"true" :
"false") << endl;
1908 if (vl >= VERB_HIGH) {
1909 const std::string lclStr = this->localDescribeToString (vl);
1914 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1915 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1933 if (newComm.is_null () || newComm->getSize () < 1) {
1934 return Teuchos::null;
1936 else if (newComm->getSize () == 1) {
1941 RCP<map_type> newMap (
new map_type ());
1943 newMap->comm_ = newComm;
1947 newMap->indexBase_ = this->indexBase_;
1948 newMap->numGlobalElements_ = this->numLocalElements_;
1949 newMap->numLocalElements_ = this->numLocalElements_;
1950 newMap->minMyGID_ = this->minMyGID_;
1951 newMap->maxMyGID_ = this->maxMyGID_;
1952 newMap->minAllGID_ = this->minMyGID_;
1953 newMap->maxAllGID_ = this->maxMyGID_;
1954 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1955 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1958 newMap->uniform_ = this->uniform_;
1959 newMap->contiguous_ = this->contiguous_;
1962 newMap->distributed_ =
false;
1963 newMap->lgMap_ = this->lgMap_;
1964 newMap->lgMapHost_ = this->lgMapHost_;
1965 newMap->glMap_ = this->glMap_;
1986 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2002 auto lgMap = this->getMyGlobalIndices ();
2004 typename std::decay<decltype (lgMap.extent (0)) >::type;
2005 const size_type lclNumInds =
2006 static_cast<size_type
> (this->getNodeNumElements ());
2007 using Teuchos::TypeNameTraits;
2008 TEUCHOS_TEST_FOR_EXCEPTION
2009 (lgMap.extent (0) != lclNumInds, std::logic_error,
2010 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
2011 "has length " << lgMap.extent (0) <<
" (of type " <<
2012 TypeNameTraits<size_type>::name () <<
") != this->getNodeNumElements()"
2013 " = " << this->getNodeNumElements () <<
". The latter, upon being "
2014 "cast to size_type = " << TypeNameTraits<size_type>::name () <<
", "
2015 "becomes " << lclNumInds <<
". Please report this bug to the Tpetra "
2018 Teuchos::ArrayView<const GO> lgMap = this->getNodeElementList ();
2021 const GO indexBase = this->getIndexBase ();
2022 return rcp (
new map_type (RECOMPUTE, lgMap, indexBase, newComm));
2026 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2027 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
2031 using Teuchos::Comm;
2032 using Teuchos::null;
2033 using Teuchos::outArg;
2036 using Teuchos::REDUCE_MIN;
2037 using Teuchos::reduceAll;
2044 const int color = (numLocalElements_ == 0) ? 0 : 1;
2049 RCP<const Comm<int> > newComm = comm_->split (color, 0);
2055 if (newComm.is_null ()) {
2060 RCP<Map> map = rcp (
new Map ());
2062 map->comm_ = newComm;
2063 map->indexBase_ = indexBase_;
2064 map->numGlobalElements_ = numGlobalElements_;
2065 map->numLocalElements_ = numLocalElements_;
2066 map->minMyGID_ = minMyGID_;
2067 map->maxMyGID_ = maxMyGID_;
2068 map->minAllGID_ = minAllGID_;
2069 map->maxAllGID_ = maxAllGID_;
2070 map->firstContiguousGID_= firstContiguousGID_;
2071 map->lastContiguousGID_ = lastContiguousGID_;
2075 map->uniform_ = uniform_;
2076 map->contiguous_ = contiguous_;
2091 if (! distributed_ || newComm->getSize () == 1) {
2092 map->distributed_ =
false;
2094 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2095 int allProcsOwnAllGids = 0;
2096 reduceAll<int, int> (*newComm, REDUCE_MIN, iOwnAllGids, outArg (allProcsOwnAllGids));
2097 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
2100 map->lgMap_ = lgMap_;
2101 map->lgMapHost_ = lgMapHost_;
2102 map->glMap_ = glMap_;
2119 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2123 TEUCHOS_TEST_FOR_EXCEPTION(
2124 directory_.is_null (), std::logic_error,
"Tpetra::Map::setupDirectory: "
2125 "The Directory is null. "
2126 "Please report this bug to the Tpetra developers.");
2130 if (! directory_->initialized ()) {
2131 directory_->initialize (*
this);
2135 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2139 const Teuchos::ArrayView<int>& PIDs,
2140 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const
2142 using Tpetra::Details::OrdinalTraits;
2145 using size_type = Teuchos::ArrayView<int>::size_type;
2148 const size_t maxNumToPrint = verbose ?
2150 std::unique_ptr<std::string> prefix;
2153 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2154 std::ostringstream os;
2155 os << *prefix <<
"Start: ";
2158 std::cerr << os.str();
2167 if (getGlobalNumElements () == 0) {
2168 if (GIDs.size () == 0) {
2170 std::ostringstream os;
2171 os << *prefix <<
"Done; both Map & input are empty" << endl;
2172 std::cerr << os.str();
2178 std::ostringstream os;
2179 os << *prefix <<
"Done: Map is empty on all processes, "
2180 "so all output PIDs & LIDs are invalid (-1)." << endl;
2181 std::cerr << os.str();
2183 for (size_type k = 0; k < PIDs.size (); ++k) {
2184 PIDs[k] = OrdinalTraits<int>::invalid ();
2186 for (size_type k = 0; k < LIDs.size (); ++k) {
2187 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid ();
2198 std::ostringstream os;
2199 os << *prefix <<
"Call setupDirectory" << endl;
2200 std::cerr << os.str();
2204 std::ostringstream os;
2205 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2206 std::cerr << os.str();
2209 directory_->getDirectoryEntries (*
this, GIDs, PIDs, LIDs);
2211 std::ostringstream os;
2212 os << *prefix <<
"Done; getDirectoryEntries returned "
2213 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2219 std::cerr << os.str();
2224 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2228 const Teuchos::ArrayView<int> & PIDs)
const
2234 const size_t maxNumToPrint = verbose ?
2236 std::unique_ptr<std::string> prefix;
2239 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2240 std::ostringstream os;
2241 os << *prefix <<
"Start: ";
2244 std::cerr << os.str();
2247 if (getGlobalNumElements () == 0) {
2248 if (GIDs.size () == 0) {
2250 std::ostringstream os;
2251 os << *prefix <<
"Done; both Map & input are empty" << endl;
2252 std::cerr << os.str();
2258 std::ostringstream os;
2259 os << *prefix <<
"Done: Map is empty on all processes, "
2260 "so all output PIDs are invalid (-1)." << endl;
2261 std::cerr << os.str();
2263 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size (); ++k) {
2264 PIDs[k] = Tpetra::Details::OrdinalTraits<int>::invalid ();
2275 std::ostringstream os;
2276 os << *prefix <<
"Call setupDirectory" << endl;
2277 std::cerr << os.str();
2281 std::ostringstream os;
2282 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2283 std::cerr << os.str();
2286 directory_->getDirectoryEntries(*
this, GIDs, PIDs);
2288 std::ostringstream os;
2289 os << *prefix <<
"Done; getDirectoryEntries returned "
2290 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2294 std::cerr << os.str();
2299 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2300 Teuchos::RCP<const Teuchos::Comm<int> >
2305 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2311 using Teuchos::outArg;
2312 using Teuchos::REDUCE_MIN;
2313 using Teuchos::reduceAll;
2317 std::unique_ptr<std::string> prefix;
2320 comm_.getRawPtr(),
"Map",
"checkIsDist");
2321 std::ostringstream os;
2322 os << *prefix <<
"Start" << endl;
2323 std::cerr << os.str();
2326 bool global =
false;
2327 if (comm_->getSize () > 1) {
2331 if (numGlobalElements_ == as<global_size_t> (numLocalElements_)) {
2344 reduceAll<int, int> (*comm_, REDUCE_MIN, localRep, outArg (allLocalRep));
2345 if (allLocalRep != 1) {
2355 std::ostringstream os;
2356 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2358 std::cerr << os.str();
2365 template <
class LocalOrdinal,
class GlobalOrdinal>
2366 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2368 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2370 typedef LocalOrdinal LO;
2371 typedef GlobalOrdinal GO;
2372 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2373 return createLocalMapWithNode<LO, GO, NT> (numElements, comm);
2376 template <
class LocalOrdinal,
class GlobalOrdinal>
2377 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2379 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2381 typedef LocalOrdinal LO;
2382 typedef GlobalOrdinal GO;
2383 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2384 return createUniformContigMapWithNode<LO, GO, NT> (numElements, comm);
2387 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2388 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2390 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2395 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2397 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed));
2400 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2401 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2403 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2409 const GlobalOrdinal indexBase = 0;
2412 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated));
2415 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2416 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2418 const size_t localNumElements,
2419 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2424 const GlobalOrdinal indexBase = 0;
2426 return rcp (
new map_type (numElements, localNumElements, indexBase, comm));
2429 template <
class LocalOrdinal,
class GlobalOrdinal>
2430 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2432 const size_t localNumElements,
2433 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2435 typedef LocalOrdinal LO;
2436 typedef GlobalOrdinal GO;
2439 return Tpetra::createContigMapWithNode<LO, GO, NT> (numElements, localNumElements, comm);
2442 template <
class LocalOrdinal,
class GlobalOrdinal>
2443 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2445 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2447 typedef LocalOrdinal LO;
2448 typedef GlobalOrdinal GO;
2451 return Tpetra::createNonContigMapWithNode<LO, GO, NT> (elementList, 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
2463 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2467 const GlobalOrdinal indexBase = 0;
2469 return rcp (
new map_type (INV, elementList, indexBase, comm));
2472 template<
class LO,
class GO,
class NT>
2473 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >
2477 using Teuchos::Array;
2478 using Teuchos::ArrayView;
2486 const bool verbose = Details::Behavior::verbose(
"Map");
2487 std::unique_ptr<std::string> prefix;
2489 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2490 prefix = Details::createPrefix(
2491 comm.getRawPtr(),
"createOneToOne(Map)");
2492 std::ostringstream os;
2493 os << *prefix <<
"Start" << endl;
2496 const size_t maxNumToPrint = verbose ?
2497 Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2498 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2499 const int myRank = M->getComm ()->getRank ();
2505 if (! M->isDistributed ()) {
2512 const GST numGlobalEntries = M->getGlobalNumElements ();
2513 if (M->isContiguous()) {
2514 const size_t numLocalEntries =
2515 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2517 std::ostringstream os;
2518 os << *prefix <<
"Input is locally replicated & contiguous; "
2519 "numLocalEntries=" << numLocalEntries << endl;
2523 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2524 M->getIndexBase(), M->getComm()));
2526 std::ostringstream os;
2527 os << *prefix <<
"Done" << endl;
2534 std::ostringstream os;
2535 os << *prefix <<
"Input is locally replicated & noncontiguous"
2539 ArrayView<const GO> myGids =
2540 (myRank == 0) ? M->getNodeElementList() : Teuchos::null;
2542 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2545 std::ostringstream os;
2546 os << *prefix <<
"Done" << endl;
2552 else if (M->isContiguous ()) {
2554 std::ostringstream os;
2555 os << *prefix <<
"Input is distributed & contiguous" << endl;
2564 std::ostringstream os;
2565 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2569 const size_t numMyElems = M->getNodeNumElements ();
2570 ArrayView<const GO> myElems = M->getNodeElementList ();
2571 Array<int> owner_procs_vec (numMyElems);
2574 std::ostringstream os;
2575 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2582 std::ostringstream os;
2583 os << *prefix <<
"getDirectoryEntries result: ";
2589 Array<GO> myOwned_vec (numMyElems);
2590 size_t numMyOwnedElems = 0;
2591 for (
size_t i = 0; i < numMyElems; ++i) {
2592 const GO GID = myElems[i];
2593 const int owner = owner_procs_vec[i];
2595 if (myRank == owner) {
2596 myOwned_vec[numMyOwnedElems++] = GID;
2599 myOwned_vec.resize (numMyOwnedElems);
2602 std::ostringstream os;
2603 os << *prefix <<
"Create Map: ";
2608 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2609 M->getIndexBase(), M->getComm()));
2611 std::ostringstream os;
2612 os << *prefix <<
"Done" << endl;
2619 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2620 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2624 using Details::Behavior;
2626 using Teuchos::Array;
2627 using Teuchos::ArrayView;
2630 using Teuchos::toString;
2633 using LO = LocalOrdinal;
2634 using GO = GlobalOrdinal;
2637 const bool verbose = Behavior::verbose(
"Map");
2638 std::unique_ptr<std::string> prefix;
2640 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2641 prefix = Details::createPrefix(
2642 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2643 std::ostringstream os;
2644 os << *prefix <<
"Start" << endl;
2647 const size_t maxNumToPrint = verbose ?
2648 Behavior::verbosePrintCountThreshold() : size_t(0);
2655 std::ostringstream os;
2656 os << *prefix <<
"Initialize Directory" << endl;
2661 std::ostringstream os;
2662 os << *prefix <<
"Done initializing Directory" << endl;
2665 size_t numMyElems = M->getNodeNumElements ();
2666 ArrayView<const GO> myElems = M->getNodeElementList ();
2667 Array<int> owner_procs_vec (numMyElems);
2669 std::ostringstream os;
2670 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2677 std::ostringstream os;
2678 os << *prefix <<
"getDirectoryEntries result: ";
2684 const int myRank = M->getComm()->getRank();
2685 Array<GO> myOwned_vec (numMyElems);
2686 size_t numMyOwnedElems = 0;
2687 for (
size_t i = 0; i < numMyElems; ++i) {
2688 const GO GID = myElems[i];
2689 const int owner = owner_procs_vec[i];
2690 if (myRank == owner) {
2691 myOwned_vec[numMyOwnedElems++] = GID;
2694 myOwned_vec.resize (numMyOwnedElems);
2699 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
2701 std::ostringstream os;
2702 os << *prefix <<
"Create Map: ";
2707 RCP<const map_type> retMap
2708 (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2711 std::ostringstream os;
2712 os << *prefix <<
"Done" << endl;
2726 #define TPETRA_MAP_INSTANT(LO,GO,NODE) \
2728 template class Map< LO , GO , NODE >; \
2730 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2731 createLocalMapWithNode<LO,GO,NODE> (const size_t numElements, \
2732 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2734 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2735 createContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2736 const size_t localNumElements, \
2737 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2739 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2740 createNonContigMapWithNode(const Teuchos::ArrayView<const GO> &elementList, \
2741 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); \
2743 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2744 createUniformContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2745 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2747 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2748 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M); \
2750 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2751 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M, \
2752 const Tpetra::Details::TieBreak<LO,GO>& tie_break); \
2756 #define TPETRA_MAP_INSTANT_DEFAULTNODE(LO,GO) \
2757 template Teuchos::RCP< const Map<LO,GO> > \
2758 createLocalMap<LO,GO>( const size_t, const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2760 template Teuchos::RCP< const Map<LO,GO> > \
2761 createContigMap<LO,GO>( global_size_t, size_t, \
2762 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2764 template Teuchos::RCP< const Map<LO,GO> > \
2765 createNonContigMap(const Teuchos::ArrayView<const GO> &, \
2766 const Teuchos::RCP<const Teuchos::Comm<int> > &); \
2768 template Teuchos::RCP< const Map<LO,GO> > \
2769 createUniformContigMap<LO,GO>( const global_size_t, \
2770 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2772 #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.
std::string memorySpaceName(const void *ptr)
Return the Kokkos memory space name (without "Kokkos::") corresponding to the given nonnull pointer...
global_indices_array_type getMyGlobalIndices() const
Return a view of the global indices owned by this process.
Declaration of functions for checking whether a given pointer is accessible from a given Kokkos execu...
bool isContiguous() const
True if this Map is distributed contiguously, else false.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
Declaration of a function that prints strings from each 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...
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.
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.
bool pointerAccessibleFromExecutionSpace(const void *ptr, const ExecutionSpace &space)
Is the given nonnull ptr accessible from the given execution space?
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.
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 local Map for Kokkos kernels.
Teuchos::ArrayView< const global_ordinal_type > getNodeElementList() const
Return a NONOWNING view of the global indices owned by this process.
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...
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
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).