45 #ifndef TPETRA_MAP_DEF_HPP
46 #define TPETRA_MAP_DEF_HPP
53 #include "Teuchos_as.hpp"
54 #include "Teuchos_TypeNameTraits.hpp"
55 #include "Teuchos_CommHelpers.hpp"
57 #include "Tpetra_Directory.hpp"
59 #include "Tpetra_Details_FixedHashTable.hpp"
64 #include "Tpetra_Details_mpiIsInitialized.hpp"
72 checkMapInputArray (
const char ctorName[],
73 const void* indexList,
74 const size_t indexListSize,
75 const Teuchos::Comm<int>*
const comm)
79 const bool debug = Behavior::debug(
"Map");
81 using Teuchos::outArg;
82 using Teuchos::REDUCE_MIN;
83 using Teuchos::reduceAll;
86 const int myRank = comm ==
nullptr ? 0 : comm->getRank ();
87 const bool verbose = Behavior::verbose(
"Map");
88 std::ostringstream lclErrStrm;
91 if (indexListSize != 0 && indexList ==
nullptr) {
94 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
95 "but indexListSize=" << indexListSize <<
" != 0." << endl;
99 reduceAll (*comm, REDUCE_MIN, lclSuccess, outArg (gblSuccess));
100 if (gblSuccess != 1) {
101 std::ostringstream gblErrStrm;
102 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
103 " detected a problem with the input array "
104 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
105 "of global indices." << endl;
107 using ::Tpetra::Details::gathervPrint;
110 TEUCHOS_TEST_FOR_EXCEPTION
111 (
true, std::invalid_argument, gblErrStrm.str ());
119 template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
120 void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal & minMyGID, GlobalOrdinal & maxMyGID, GlobalOrdinal &firstContiguousGID, GlobalOrdinal &lastContiguousGID_val, LocalOrdinal &lastContiguousGID_loc) {
121 using LO = LocalOrdinal;
122 using GO = GlobalOrdinal;
123 using exec_space =
typename ViewType::device_type::execution_space;
124 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO> >;
125 const LO numLocalElements = entryList.extent(0);
129 typedef typename Kokkos::MinLoc<LO,GO>::value_type minloc_type;
130 minloc_type myMinLoc;
135 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){
136 GO entry_0 = entryList[0];
137 GO entry_i = entryList[i];
140 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
141 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
142 l_firstCont = entry_0;
144 if(entry_i - entry_0 != i && l_lastCont.val >= i) {
146 l_lastCont.val = i-1;
147 l_lastCont.loc = entryList[i-1];
149 else if (i == numLocalElements-1 && i < l_lastCont.val) {
152 l_lastCont.loc = entry_i;
155 },Kokkos::Min<GO>(minMyGID),Kokkos::Max<GO>(maxMyGID),Kokkos::Min<GO>(firstContiguousGID),Kokkos::MinLoc<LO,GO>(myMinLoc));
158 lastContiguousGID_val = myMinLoc.loc;
159 lastContiguousGID_loc = myMinLoc.val;
167 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
170 comm_ (new Teuchos::SerialComm<int> ()),
172 numGlobalElements_ (0),
173 numLocalElements_ (0),
174 minMyGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
175 maxMyGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
176 minAllGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
177 maxAllGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
178 firstContiguousGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
179 lastContiguousGID_ (Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
182 distributed_ (false),
183 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
190 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
194 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
198 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
201 using Teuchos::broadcast;
202 using Teuchos::outArg;
203 using Teuchos::reduceAll;
204 using Teuchos::REDUCE_MIN;
205 using Teuchos::REDUCE_MAX;
206 using Teuchos::typeName;
210 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
211 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
213 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
217 std::unique_ptr<std::string> prefix;
220 comm_.getRawPtr(),
"Map", funcName);
221 std::ostringstream os;
222 os << *prefix <<
"Start" << endl;
223 std::cerr << os.str();
231 GST proc0NumGlobalElements = numGlobalElements;
232 broadcast(*comm_, 0, outArg(proc0NumGlobalElements));
233 GST minNumGlobalElements = numGlobalElements;
234 GST maxNumGlobalElements = numGlobalElements;
235 reduceAll(*comm, REDUCE_MIN, numGlobalElements,
236 outArg(minNumGlobalElements));
237 reduceAll(*comm, REDUCE_MAX, numGlobalElements,
238 outArg(maxNumGlobalElements));
239 TEUCHOS_TEST_FOR_EXCEPTION
240 (minNumGlobalElements != maxNumGlobalElements ||
241 numGlobalElements != minNumGlobalElements,
242 std::invalid_argument, exPfx <<
"All processes must "
243 "provide the same number of global elements. Process 0 set "
244 "numGlobalElements="<< proc0NumGlobalElements <<
". The "
245 "calling process " << comm->getRank() <<
" set "
246 "numGlobalElements=" << numGlobalElements <<
". The min "
247 "and max values over all processes are "
248 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements
251 GO proc0IndexBase = indexBase;
252 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
253 GO minIndexBase = indexBase;
254 GO maxIndexBase = indexBase;
255 reduceAll(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
256 reduceAll(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
257 TEUCHOS_TEST_FOR_EXCEPTION
258 (minIndexBase != maxIndexBase || indexBase != minIndexBase,
259 std::invalid_argument, exPfx <<
"All processes must "
260 "provide the same indexBase argument. Process 0 set "
261 "indexBase=" << proc0IndexBase <<
". The calling process "
262 << comm->getRank() <<
" set indexBase=" << indexBase
263 <<
". The min and max values over all processes are "
264 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
284 TEUCHOS_TEST_FOR_EXCEPTION(
285 (numGlobalElements < 1 && numGlobalElements != 0),
286 std::invalid_argument, exPfx <<
"numGlobalElements (= "
287 << numGlobalElements <<
") must be nonnegative.");
289 TEUCHOS_TEST_FOR_EXCEPTION
290 (numGlobalElements == GSTI, std::invalid_argument, exPfx <<
291 "You provided numGlobalElements = Teuchos::OrdinalTraits<"
292 "Tpetra::global_size_t>::invalid(). This version of the "
293 "constructor requires a valid value of numGlobalElements. "
294 "You probably mistook this constructor for the \"contiguous "
295 "nonuniform\" constructor, which can compute the global "
296 "number of elements for you if you set numGlobalElements to "
297 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
299 size_t numLocalElements = 0;
300 if (lOrG == GloballyDistributed) {
315 const GST numProcs =
static_cast<GST
> (comm_->getSize ());
316 const GST myRank =
static_cast<GST
> (comm_->getRank ());
317 const GST quotient = numGlobalElements / numProcs;
318 const GST remainder = numGlobalElements - quotient * numProcs;
321 if (myRank < remainder) {
322 numLocalElements =
static_cast<size_t> (1) + static_cast<size_t> (quotient);
325 startIndex = as<GO> (myRank) * as<GO> (numLocalElements);
327 numLocalElements = as<size_t> (quotient);
328 startIndex = as<GO> (myRank) * as<GO> (numLocalElements) +
332 minMyGID_ = indexBase + startIndex;
333 maxMyGID_ = indexBase + startIndex + numLocalElements - 1;
334 minAllGID_ = indexBase;
335 maxAllGID_ = indexBase + numGlobalElements - 1;
336 distributed_ = (numProcs > 1);
339 numLocalElements = as<size_t> (numGlobalElements);
340 minMyGID_ = indexBase;
341 maxMyGID_ = indexBase + numGlobalElements - 1;
342 distributed_ =
false;
345 minAllGID_ = indexBase;
346 maxAllGID_ = indexBase + numGlobalElements - 1;
347 indexBase_ = indexBase;
348 numGlobalElements_ = numGlobalElements;
349 numLocalElements_ = numLocalElements;
350 firstContiguousGID_ = minMyGID_;
351 lastContiguousGID_ = maxMyGID_;
358 std::ostringstream os;
359 os << *prefix <<
"Done" << endl;
360 std::cerr << os.str();
365 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
368 const size_t numLocalElements,
370 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm) :
373 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
376 using Teuchos::broadcast;
377 using Teuchos::outArg;
378 using Teuchos::reduceAll;
379 using Teuchos::REDUCE_MIN;
380 using Teuchos::REDUCE_MAX;
381 using Teuchos::REDUCE_SUM;
386 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
387 const char funcName[] =
388 "Map(gblNumInds,lclNumInds,indexBase,comm)";
390 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
391 const char suffix[] =
392 ". Please report this bug to the Tpetra developers.";
396 std::unique_ptr<std::string> prefix;
399 comm_.getRawPtr(),
"Map", funcName);
400 std::ostringstream os;
401 os << *prefix <<
"Start" << endl;
402 std::cerr << os.str();
409 GST debugGlobalSum {};
411 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
412 numGlobalElements, numLocalElements, indexBase, comm);
427 scan<int, GO> (*comm, REDUCE_SUM, numLocalElements, outArg (scanResult));
428 const GO myOffset = scanResult - numLocalElements;
430 if (numGlobalElements != GSTI) {
431 numGlobalElements_ = numGlobalElements;
438 const int numProcs = comm->getSize ();
439 GST globalSum = scanResult;
441 broadcast (*comm, numProcs - 1, outArg (globalSum));
443 numGlobalElements_ = globalSum;
447 TEUCHOS_TEST_FOR_EXCEPTION
448 (globalSum != debugGlobalSum, std::logic_error, exPfx <<
449 "globalSum = " << globalSum <<
" != debugGlobalSum = " <<
450 debugGlobalSum << suffix);
453 numLocalElements_ = numLocalElements;
454 indexBase_ = indexBase;
455 minAllGID_ = (numGlobalElements_ == 0) ?
456 std::numeric_limits<GO>::max () :
458 maxAllGID_ = (numGlobalElements_ == 0) ?
459 std::numeric_limits<GO>::lowest () :
460 indexBase + GO(numGlobalElements_) - GO(1);
461 minMyGID_ = (numLocalElements_ == 0) ?
462 std::numeric_limits<GO>::max () :
463 indexBase + GO(myOffset);
464 maxMyGID_ = (numLocalElements_ == 0) ?
465 std::numeric_limits<GO>::lowest () :
466 indexBase + myOffset + GO(numLocalElements) - GO(1);
467 firstContiguousGID_ = minMyGID_;
468 lastContiguousGID_ = maxMyGID_;
470 distributed_ = checkIsDist ();
476 std::ostringstream os;
477 os << *prefix <<
"Done" << endl;
478 std::cerr << os.str();
482 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
486 const char errorMessagePrefix[],
488 const size_t numLocalElements,
489 const global_ordinal_type indexBase,
490 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const
497 using Teuchos::broadcast;
498 using Teuchos::outArg;
500 using Teuchos::REDUCE_MAX;
501 using Teuchos::REDUCE_MIN;
502 using Teuchos::REDUCE_SUM;
503 using Teuchos::reduceAll;
504 using GO = global_ordinal_type;
506 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
516 GST debugGlobalSum = 0;
517 reduceAll<int, GST> (*comm, REDUCE_SUM,
static_cast<GST
> (numLocalElements),
518 outArg (debugGlobalSum));
522 GST proc0NumGlobalElements = numGlobalElements;
523 broadcast<int, GST> (*comm_, 0, outArg (proc0NumGlobalElements));
524 GST minNumGlobalElements = numGlobalElements;
525 GST maxNumGlobalElements = numGlobalElements;
526 reduceAll<int, GST> (*comm, REDUCE_MIN, numGlobalElements,
527 outArg (minNumGlobalElements));
528 reduceAll<int, GST> (*comm, REDUCE_MAX, numGlobalElements,
529 outArg (maxNumGlobalElements));
530 TEUCHOS_TEST_FOR_EXCEPTION
531 (minNumGlobalElements != maxNumGlobalElements ||
532 numGlobalElements != minNumGlobalElements,
533 std::invalid_argument, errorMessagePrefix <<
"All processes "
534 "must provide the same number of global elements, even if "
536 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
537 "(which signals that the Map should compute the global "
538 "number of elements). Process 0 set numGlobalElements"
539 "=" << proc0NumGlobalElements <<
". The calling process "
540 << comm->getRank() <<
" set numGlobalElements=" <<
541 numGlobalElements <<
". The min and max values over all "
542 "processes are " << minNumGlobalElements <<
" resp. " <<
543 maxNumGlobalElements <<
".");
545 GO proc0IndexBase = indexBase;
546 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
547 GO minIndexBase = indexBase;
548 GO maxIndexBase = indexBase;
549 reduceAll<int, GO> (*comm, REDUCE_MIN, indexBase, outArg (minIndexBase));
550 reduceAll<int, GO> (*comm, REDUCE_MAX, indexBase, outArg (maxIndexBase));
551 TEUCHOS_TEST_FOR_EXCEPTION
552 (minIndexBase != maxIndexBase || indexBase != minIndexBase,
553 std::invalid_argument, errorMessagePrefix <<
554 "All processes must provide the same indexBase argument. "
555 "Process 0 set indexBase = " << proc0IndexBase <<
". The "
556 "calling process " << comm->getRank() <<
" set indexBase="
557 << indexBase <<
". The min and max values over all "
558 "processes are " << minIndexBase <<
" resp. " << maxIndexBase
563 TEUCHOS_TEST_FOR_EXCEPTION
564 (numGlobalElements != GSTI &&
565 debugGlobalSum != numGlobalElements, std::invalid_argument,
566 errorMessagePrefix <<
"The sum of each process' number of "
567 "indices over all processes, " << debugGlobalSum <<
", != "
568 <<
"numGlobalElements=" << numGlobalElements <<
". If you "
569 "would like this constructor to compute numGlobalElements "
570 "for you, you may set numGlobalElements="
571 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
572 "on input. Please note that this is NOT necessarily -1.");
574 return debugGlobalSum;
577 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
579 Map<LocalOrdinal,GlobalOrdinal,Node>::
580 initWithNonownedHostIndexList(
581 const char errorMessagePrefix[],
583 const Kokkos::View<
const global_ordinal_type*,
586 Kokkos::MemoryUnmanaged>& entryList_host,
587 const global_ordinal_type indexBase,
588 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
592 using Kokkos::LayoutLeft;
593 using Kokkos::subview;
595 using Kokkos::view_alloc;
596 using Kokkos::WithoutInitializing;
598 using Teuchos::broadcast;
599 using Teuchos::outArg;
601 using Teuchos::REDUCE_MAX;
602 using Teuchos::REDUCE_MIN;
603 using Teuchos::REDUCE_SUM;
604 using Teuchos::reduceAll;
606 using GO = global_ordinal_type;
608 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
610 TEUCHOS_TEST_FOR_EXCEPTION
611 (! Kokkos::is_initialized (), std::runtime_error,
612 errorMessagePrefix <<
"The Kokkos execution space "
613 << Teuchos::TypeNameTraits<execution_space>::name()
614 <<
" has not been initialized. "
615 "Please initialize it before creating a Map.")
628 const
size_t numLocalElements(entryList_host.size());
630 initialNonuniformDebugCheck(errorMessagePrefix, numGlobalElements,
631 numLocalElements, indexBase, comm);
641 if (numGlobalElements != GSTI) {
642 numGlobalElements_ = numGlobalElements;
645 reduceAll(*comm, REDUCE_SUM,
646 static_cast<GST>(numLocalElements),
647 outArg(numGlobalElements_));
673 numLocalElements_ = numLocalElements;
674 indexBase_ = indexBase;
676 minMyGID_ = indexBase_;
677 maxMyGID_ = indexBase_;
687 if (numLocalElements_ > 0) {
691 typename decltype (lgMap_)::non_const_type lgMap
692 (view_alloc (
"lgMap", WithoutInitializing), numLocalElements_);
694 Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
702 firstContiguousGID_ = entryList_host[0];
703 lastContiguousGID_ = firstContiguousGID_+1;
711 lgMap_host[0] = firstContiguousGID_;
713 for ( ; i < numLocalElements_; ++i) {
714 const GO curGid = entryList_host[i];
715 const LO curLid = as<LO> (i);
717 if (lastContiguousGID_ != curGid)
break;
723 lgMap_host[curLid] = curGid;
724 ++lastContiguousGID_;
726 --lastContiguousGID_;
732 minMyGID_ = firstContiguousGID_;
733 maxMyGID_ = lastContiguousGID_;
737 LO firstNonContiguous_loc=i;
740 const std::pair<size_t, size_t> ncRange (i, entryList_host.extent (0));
741 auto nonContigGids_host = subview (entryList_host, ncRange);
742 TEUCHOS_TEST_FOR_EXCEPTION
743 (static_cast<size_t> (nonContigGids_host.extent (0)) !=
744 static_cast<size_t> (entryList_host.extent (0) - i),
745 std::logic_error,
"Tpetra::Map noncontiguous constructor: "
746 "nonContigGids_host.extent(0) = "
747 << nonContigGids_host.extent (0)
748 <<
" != entryList_host.extent(0) - i = "
749 << (entryList_host.extent (0) - i) <<
" = "
750 << entryList_host.extent (0) <<
" - " << i
751 <<
". Please report this bug to the Tpetra developers.");
755 View<GO*, LayoutLeft, device_type>
756 nonContigGids (view_alloc (
"nonContigGids", WithoutInitializing),
757 nonContigGids_host.size ());
762 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
764 glMap_ = global_to_local_table_type(nonContigGids,
765 firstNonContiguous_loc);
767 glMapHost_ = global_to_local_table_host_type(glMap_);
775 for ( ; i < numLocalElements_; ++i) {
776 const GO curGid = entryList_host[i];
777 const LO curLid =
static_cast<LO
> (i);
778 lgMap_host[curLid] = curGid;
782 if (curGid < minMyGID_) {
785 if (curGid > maxMyGID_) {
797 lgMapHost_ = lgMap_host;
802 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
803 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
807 firstContiguousGID_ = indexBase_+1;
808 lastContiguousGID_ = indexBase_;
837 if (std::numeric_limits<GO>::is_signed) {
840 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
843 minMaxInput[0] = -minMyGID_;
844 minMaxInput[1] = maxMyGID_;
845 minMaxInput[2] = localDist;
851 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
852 minAllGID_ = -minMaxOutput[0];
853 maxAllGID_ = minMaxOutput[1];
854 const GO globalDist = minMaxOutput[2];
855 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
859 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
860 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
861 distributed_ = checkIsDist ();
866 TEUCHOS_TEST_FOR_EXCEPTION(
867 minAllGID_ < indexBase_,
868 std::invalid_argument,
869 "Tpetra::Map constructor (noncontiguous): "
870 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
871 "less than the given indexBase = " << indexBase_ <<
".");
877 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
880 const GlobalOrdinal indexList[],
881 const LocalOrdinal indexListSize,
882 const GlobalOrdinal indexBase,
883 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
886 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
889 const char funcName[] =
890 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
893 std::unique_ptr<std::string> prefix;
896 comm_.getRawPtr(),
"Map", funcName);
897 std::ostringstream os;
898 os << *prefix <<
"Start" << endl;
899 std::cerr << os.str();
904 checkMapInputArray (
"(GST, const GO[], LO, GO, comm)",
905 indexList, static_cast<size_t> (indexListSize),
910 const GlobalOrdinal*
const indsRaw = indexListSize == 0 ? NULL : indexList;
911 Kokkos::View<
const GlobalOrdinal*,
914 Kokkos::MemoryUnmanaged> inds (indsRaw, indexListSize);
915 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
918 std::ostringstream os;
919 os << *prefix <<
"Done" << endl;
920 std::cerr << os.str();
924 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
927 const Teuchos::ArrayView<const GlobalOrdinal>& entryList,
928 const GlobalOrdinal indexBase,
929 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
932 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
935 const char* funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
938 std::unique_ptr<std::string> prefix;
941 comm_.getRawPtr(),
"Map", funcName);
942 std::ostringstream os;
943 os << *prefix <<
"Start" << endl;
944 std::cerr << os.str();
949 const size_t numLclInds =
static_cast<size_t> (entryList.size ());
950 checkMapInputArray (
"(GST, ArrayView, GO, comm)",
951 entryList.getRawPtr (), numLclInds,
956 const GlobalOrdinal*
const indsRaw =
957 numLclInds == 0 ? NULL : entryList.getRawPtr ();
958 Kokkos::View<
const GlobalOrdinal*,
961 Kokkos::MemoryUnmanaged> inds (indsRaw, numLclInds);
962 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
965 std::ostringstream os;
966 os << *prefix <<
"Done" << endl;
967 std::cerr << os.str();
972 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
975 const Kokkos::View<const GlobalOrdinal*, device_type>& entryList,
976 const GlobalOrdinal indexBase,
977 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
980 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
982 using Kokkos::LayoutLeft;
983 using Kokkos::subview;
985 using Kokkos::view_alloc;
986 using Kokkos::WithoutInitializing;
988 using Teuchos::ArrayView;
990 using Teuchos::broadcast;
991 using Teuchos::outArg;
993 using Teuchos::REDUCE_MAX;
994 using Teuchos::REDUCE_MIN;
995 using Teuchos::REDUCE_SUM;
996 using Teuchos::reduceAll;
997 using Teuchos::typeName;
1002 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
1003 const char funcName[] =
1004 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
1007 std::unique_ptr<std::string> prefix;
1010 comm_.getRawPtr(),
"Map", funcName);
1011 std::ostringstream os;
1012 os << *prefix <<
"Start" << endl;
1013 std::cerr << os.str();
1018 checkMapInputArray (
"(GST, Kokkos::View, GO, comm)",
1020 static_cast<size_t> (entryList.extent (0)),
1034 const size_t numLocalElements(entryList.size());
1036 initialNonuniformDebugCheck(funcName, numGlobalElements,
1037 numLocalElements, indexBase, comm);
1047 if (numGlobalElements != GSTI) {
1048 numGlobalElements_ = numGlobalElements;
1051 reduceAll(*comm, REDUCE_SUM,
1052 static_cast<GST>(numLocalElements),
1053 outArg(numGlobalElements_));
1080 numLocalElements_ = numLocalElements;
1081 indexBase_ = indexBase;
1083 minMyGID_ = indexBase_;
1084 maxMyGID_ = indexBase_;
1094 if (numLocalElements_ > 0) {
1098 typename decltype (lgMap_)::non_const_type lgMap
1099 (view_alloc (
"lgMap", WithoutInitializing), numLocalElements_);
1104 LO lastContiguousGID_loc;
1105 computeConstantsOnDevice(entryList,minMyGID_,maxMyGID_,firstContiguousGID_,lastContiguousGID_,lastContiguousGID_loc);
1106 LO firstNonContiguous_loc = lastContiguousGID_loc+1;
1107 auto nonContigGids = Kokkos::subview(entryList,std::pair<size_t,size_t>(firstNonContiguous_loc,entryList.extent(0)));
1111 firstNonContiguous_loc);
1118 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1119 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1123 firstContiguousGID_ = indexBase_+1;
1124 lastContiguousGID_ = indexBase_;
1150 if (std::numeric_limits<GO>::is_signed) {
1152 const GO localDist =
1153 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
1156 minMaxInput[0] = -minMyGID_;
1157 minMaxInput[1] = maxMyGID_;
1158 minMaxInput[2] = localDist;
1161 minMaxOutput[0] = 0;
1162 minMaxOutput[1] = 0;
1163 minMaxOutput[2] = 0;
1164 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1165 minAllGID_ = -minMaxOutput[0];
1166 maxAllGID_ = minMaxOutput[1];
1167 const GO globalDist = minMaxOutput[2];
1168 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
1172 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
1173 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
1174 distributed_ = checkIsDist ();
1177 contiguous_ =
false;
1179 TEUCHOS_TEST_FOR_EXCEPTION(
1180 minAllGID_ < indexBase_,
1181 std::invalid_argument,
1182 "Tpetra::Map constructor (noncontiguous): "
1183 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
1184 "less than the given indexBase = " << indexBase_ <<
".");
1190 std::ostringstream os;
1191 os << *prefix <<
"Done" << endl;
1192 std::cerr << os.str();
1197 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1200 if (! Kokkos::is_initialized ()) {
1201 std::ostringstream os;
1202 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1203 "Kokkos::finalize() has been called. This is user error! There are "
1204 "two likely causes: " << std::endl <<
1205 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1207 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1208 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1209 "or Tpetra::finalize()." << std::endl << std::endl <<
1210 "Don't do either of these! Please refer to GitHib Issue #2372."
1212 ::Tpetra::Details::printOnce (std::cerr, os.str (),
1213 this->getComm ().getRawPtr ());
1216 using ::Tpetra::Details::mpiIsInitialized;
1217 using ::Tpetra::Details::mpiIsFinalized;
1218 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1220 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getComm ();
1221 if (! comm.is_null () && teuchosCommIsAnMpiComm (*comm) &&
1222 mpiIsInitialized () && mpiIsFinalized ()) {
1228 std::ostringstream os;
1229 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1230 "MPI_Finalize() has been called. This is user error! There are "
1231 "two likely causes: " << std::endl <<
1232 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1234 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1235 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1236 "Tpetra::finalize()." << std::endl << std::endl <<
1237 "Don't do either of these! Please refer to GitHib Issue #2372."
1239 ::Tpetra::Details::printOnce (std::cerr, os.str (), comm.getRawPtr ());
1247 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1251 TEUCHOS_TEST_FOR_EXCEPTION(
1252 getComm ().is_null (), std::logic_error,
"Tpetra::Map::isOneToOne: "
1253 "getComm() returns null. Please report this bug to the Tpetra "
1258 return directory_->isOneToOne (*
this);
1261 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1266 if (isContiguous ()) {
1267 if (globalIndex < getMinGlobalIndex () ||
1268 globalIndex > getMaxGlobalIndex ()) {
1269 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1271 return static_cast<LocalOrdinal
> (globalIndex - getMinGlobalIndex ());
1273 else if (globalIndex >= firstContiguousGID_ &&
1274 globalIndex <= lastContiguousGID_) {
1275 return static_cast<LocalOrdinal
> (globalIndex - firstContiguousGID_);
1282 return glMapHost_.get (globalIndex);
1286 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1291 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1292 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ();
1294 if (isContiguous ()) {
1295 return getMinGlobalIndex () + localIndex;
1303 return lgMapHost_[localIndex];
1307 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1312 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1319 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1323 return this->getLocalElement (globalIndex) !=
1324 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1327 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1332 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1338 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1344 getMinGlobalIndex (), getMaxGlobalIndex (),
1345 firstContiguousGID_, lastContiguousGID_,
1346 getLocalNumElements (), isContiguous ());
1349 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1354 using Teuchos::outArg;
1355 using Teuchos::REDUCE_MIN;
1356 using Teuchos::reduceAll;
1366 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1377 else if (isContiguous () && isUniform () &&
1385 lgMap_.extent (0) != 0 && map.lgMap_.extent (0) != 0 &&
1386 lgMap_.data () == map.lgMap_.data ()) {
1400 TEUCHOS_TEST_FOR_EXCEPTION(
1402 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1403 "checked that this condition is true above, but it's false here. "
1404 "Please report this bug to the Tpetra developers.");
1407 const int locallyCompat =
1410 int globallyCompat = 0;
1411 reduceAll<int, int> (*comm_, REDUCE_MIN, locallyCompat, outArg (globallyCompat));
1412 return (globallyCompat == 1);
1415 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1420 using Teuchos::ArrayView;
1422 using size_type =
typename ArrayView<const GO>::size_type;
1445 if (isContiguous ()) {
1450 TEUCHOS_TEST_FOR_EXCEPTION(
1451 ! this->isContiguous () || map.
isContiguous (), std::logic_error,
1452 "Tpetra::Map::locallySameAs: BUG");
1454 const GO minLhsGid = this->getMinGlobalIndex ();
1455 const size_type numRhsElts = rhsElts.size ();
1456 for (size_type k = 0; k < numRhsElts; ++k) {
1457 const GO curLhsGid = minLhsGid +
static_cast<GO
> (k);
1458 if (curLhsGid != rhsElts[k]) {
1466 TEUCHOS_TEST_FOR_EXCEPTION(
1467 this->isContiguous () || ! map.
isContiguous (), std::logic_error,
1468 "Tpetra::Map::locallySameAs: BUG");
1469 ArrayView<const GO> lhsElts = this->getLocalElementList ();
1471 const size_type numLhsElts = lhsElts.size ();
1472 for (size_type k = 0; k < numLhsElts; ++k) {
1473 const GO curRhsGid = minRhsGid +
static_cast<GO
> (k);
1474 if (curRhsGid != lhsElts[k]) {
1480 else if (this->lgMap_.data () == map.lgMap_.data ()) {
1490 ArrayView<const GO> lhsElts = getLocalElementList ();
1496 return std::equal (lhsElts.begin (), lhsElts.end (), rhsElts.begin ());
1502 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1515 auto lmap2 = this->getLocalMap();
1517 auto numLocalElements1 = lmap1.getLocalNumElements();
1518 auto numLocalElements2 = lmap2.getLocalNumElements();
1520 if (numLocalElements1 > numLocalElements2) {
1525 if (lmap1.isContiguous () && lmap2.isContiguous ()) {
1527 return ((lmap1.getMinGlobalIndex () == lmap2.getMinGlobalIndex ()) &&
1528 (lmap1.getMaxGlobalIndex () <= lmap2.getMaxGlobalIndex ()));
1531 if (lmap1.getMinGlobalIndex () < lmap2.getMinGlobalIndex () ||
1532 lmap1.getMaxGlobalIndex () > lmap2.getMaxGlobalIndex ()) {
1540 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1544 Kokkos::parallel_reduce(
1546 range_type(0, numLocalElements1),
1547 KOKKOS_LAMBDA (
const LO i, LO& diff) {
1548 diff += (lmap1.getGlobalElement(i) != lmap2.getGlobalElement(i));
1551 return (numDiff == 0);
1554 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1559 using Teuchos::outArg;
1560 using Teuchos::REDUCE_MIN;
1561 using Teuchos::reduceAll;
1571 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1594 else if (isContiguous () && isUniform () &&
1615 const int isSame_lcl = locallySameAs (map) ? 1 : 0;
1619 reduceAll<int, int> (*comm_, REDUCE_MIN, isSame_lcl, outArg (isSame_gbl));
1620 return isSame_gbl == 1;
1624 template <
class LO,
class GO,
class DT>
1627 FillLgMap (
const Kokkos::View<GO*, DT>& lgMap,
1628 const GO startGid) :
1629 lgMap_ (lgMap), startGid_ (startGid)
1631 Kokkos::RangePolicy<LO, typename DT::execution_space>
1632 range (static_cast<LO> (0), static_cast<LO> (lgMap.size ()));
1633 Kokkos::parallel_for (range, *
this);
1636 KOKKOS_INLINE_FUNCTION
void operator () (
const LO& lid)
const {
1637 lgMap_(lid) = startGid_ +
static_cast<GO
> (lid);
1641 const Kokkos::View<GO*, DT> lgMap_;
1648 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1649 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_type
1655 using const_lg_view_type = decltype(lgMap_);
1656 using lg_view_type =
typename const_lg_view_type::non_const_type;
1660 std::unique_ptr<std::string> prefix;
1663 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1664 std::ostringstream os;
1665 os << *prefix <<
"Start" << endl;
1666 std::cerr << os.str();
1672 const bool needToCreateLocalToGlobalMapping =
1673 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1675 if (needToCreateLocalToGlobalMapping) {
1677 std::ostringstream os;
1678 os << *prefix <<
"Need to create lgMap" << endl;
1679 std::cerr << os.str();
1684 TEUCHOS_TEST_FOR_EXCEPTION
1685 (! isContiguous(), std::logic_error,
1686 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1687 "mapping (lgMap_) should have been set up already for a "
1688 "noncontiguous Map. Please report this bug to the Tpetra "
1691 const LO numElts =
static_cast<LO
> (getLocalNumElements ());
1693 using Kokkos::view_alloc;
1694 using Kokkos::WithoutInitializing;
1695 lg_view_type lgMap (
"lgMap", numElts);
1697 std::ostringstream os;
1698 os << *prefix <<
"Fill lgMap" << endl;
1699 std::cerr << os.str();
1701 FillLgMap<LO, GO, device_type> fillIt (lgMap, minMyGID_);
1704 std::ostringstream os;
1705 os << *prefix <<
"Copy lgMap to lgMapHost" << endl;
1706 std::cerr << os.str();
1709 auto lgMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (), lgMap);
1716 exec_instance.fence();
1720 lgMapHost_ = lgMapHost;
1727 std::ostringstream os;
1728 os << *prefix <<
"Done" << endl;
1729 std::cerr << os.str();
1735 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1736 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_device_type
1742 using const_lg_view_type = decltype(lgMap_);
1743 using lg_view_type =
typename const_lg_view_type::non_const_type;
1747 std::unique_ptr<std::string> prefix;
1750 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1751 std::ostringstream os;
1752 os << *prefix <<
"Start" << endl;
1753 std::cerr << os.str();
1759 const bool needToCreateLocalToGlobalMapping =
1760 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1762 if (needToCreateLocalToGlobalMapping) {
1764 std::ostringstream os;
1765 os << *prefix <<
"Need to create lgMap" << endl;
1766 std::cerr << os.str();
1771 TEUCHOS_TEST_FOR_EXCEPTION
1772 (! isContiguous(), std::logic_error,
1773 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1774 "mapping (lgMap_) should have been set up already for a "
1775 "noncontiguous Map. Please report this bug to the Tpetra "
1778 const LO numElts =
static_cast<LO
> (getLocalNumElements ());
1780 using Kokkos::view_alloc;
1781 using Kokkos::WithoutInitializing;
1782 lg_view_type lgMap (
"lgMap", numElts);
1784 std::ostringstream os;
1785 os << *prefix <<
"Fill lgMap" << endl;
1786 std::cerr << os.str();
1788 FillLgMap<LO, GO, device_type> fillIt (lgMap, minMyGID_);
1795 std::ostringstream os;
1796 os << *prefix <<
"Done" << endl;
1797 std::cerr << os.str();
1804 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1805 Teuchos::ArrayView<const GlobalOrdinal>
1813 (void) this->getMyGlobalIndices ();
1817 const GO* lgMapHostRawPtr = lgMapHost_.data ();
1821 return Teuchos::ArrayView<const GO>(
1823 lgMapHost_.extent (0),
1824 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1827 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1829 return distributed_;
1832 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1834 using Teuchos::TypeNameTraits;
1835 std::ostringstream os;
1837 os <<
"Tpetra::Map: {"
1838 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name ()
1839 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name ()
1840 <<
", NodeType: " << TypeNameTraits<Node>::name ();
1841 if (this->getObjectLabel () !=
"") {
1842 os <<
", Label: \"" << this->getObjectLabel () <<
"\"";
1844 os <<
", Global number of entries: " << getGlobalNumElements ()
1845 <<
", Number of processes: " << getComm ()->getSize ()
1846 <<
", Uniform: " << (isUniform () ?
"true" :
"false")
1847 <<
", Contiguous: " << (isContiguous () ?
"true" :
"false")
1848 <<
", Distributed: " << (isDistributed () ?
"true" :
"false")
1857 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1862 using LO = local_ordinal_type;
1866 if (vl < Teuchos::VERB_HIGH) {
1867 return std::string ();
1869 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
1870 Teuchos::RCP<Teuchos::FancyOStream> outp =
1871 Teuchos::getFancyOStream (outStringP);
1872 Teuchos::FancyOStream& out = *outp;
1874 auto comm = this->getComm ();
1875 const int myRank = comm->getRank ();
1876 const int numProcs = comm->getSize ();
1877 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1878 Teuchos::OSTab tab1 (out);
1880 const LO numEnt =
static_cast<LO
> (this->getLocalNumElements ());
1881 out <<
"My number of entries: " << numEnt << endl
1882 <<
"My minimum global index: " << this->getMinGlobalIndex () << endl
1883 <<
"My maximum global index: " << this->getMaxGlobalIndex () << endl;
1885 if (vl == Teuchos::VERB_EXTREME) {
1886 out <<
"My global indices: [";
1887 const LO minLclInd = this->getMinLocalIndex ();
1888 for (LO k = 0; k < numEnt; ++k) {
1889 out << minLclInd + this->getGlobalElement (k);
1890 if (k + 1 < numEnt) {
1898 return outStringP->str ();
1901 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1905 const Teuchos::EVerbosityLevel verbLevel)
const
1907 using Teuchos::TypeNameTraits;
1908 using Teuchos::VERB_DEFAULT;
1909 using Teuchos::VERB_NONE;
1910 using Teuchos::VERB_LOW;
1911 using Teuchos::VERB_HIGH;
1915 const Teuchos::EVerbosityLevel vl =
1916 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1918 if (vl == VERB_NONE) {
1925 auto comm = this->getComm ();
1926 if (comm.is_null ()) {
1929 const int myRank = comm->getRank ();
1930 const int numProcs = comm->getSize ();
1939 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1945 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
1946 out <<
"\"Tpetra::Map\":" << endl;
1947 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
1949 out <<
"Template parameters:" << endl;
1950 Teuchos::OSTab tab2 (out);
1951 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name () << endl
1952 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name () << endl
1953 <<
"Node: " << TypeNameTraits<Node>::name () << endl;
1955 const std::string label = this->getObjectLabel ();
1957 out <<
"Label: \"" << label <<
"\"" << endl;
1959 out <<
"Global number of entries: " << getGlobalNumElements () << endl
1960 <<
"Minimum global index: " << getMinAllGlobalIndex () << endl
1961 <<
"Maximum global index: " << getMaxAllGlobalIndex () << endl
1962 <<
"Index base: " << getIndexBase () << endl
1963 <<
"Number of processes: " << numProcs << endl
1964 <<
"Uniform: " << (isUniform () ?
"true" :
"false") << endl
1965 <<
"Contiguous: " << (isContiguous () ?
"true" :
"false") << endl
1966 <<
"Distributed: " << (isDistributed () ?
"true" :
"false") << endl;
1970 if (vl >= VERB_HIGH) {
1971 const std::string lclStr = this->localDescribeToString (vl);
1976 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1977 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1995 if (newComm.is_null () || newComm->getSize () < 1) {
1996 return Teuchos::null;
1998 else if (newComm->getSize () == 1) {
2005 RCP<map_type> newMap (
new map_type ());
2007 newMap->comm_ = newComm;
2011 newMap->indexBase_ = this->indexBase_;
2012 newMap->numGlobalElements_ = this->numLocalElements_;
2013 newMap->numLocalElements_ = this->numLocalElements_;
2014 newMap->minMyGID_ = this->minMyGID_;
2015 newMap->maxMyGID_ = this->maxMyGID_;
2016 newMap->minAllGID_ = this->minMyGID_;
2017 newMap->maxAllGID_ = this->maxMyGID_;
2018 newMap->firstContiguousGID_ = this->firstContiguousGID_;
2019 newMap->lastContiguousGID_ = this->lastContiguousGID_;
2022 newMap->uniform_ = this->uniform_;
2023 newMap->contiguous_ = this->contiguous_;
2026 newMap->distributed_ =
false;
2027 newMap->lgMap_ = this->lgMap_;
2028 newMap->lgMapHost_ = this->lgMapHost_;
2029 newMap->glMap_ = this->glMap_;
2030 newMap->glMapHost_ = this->glMapHost_;
2051 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2067 auto lgMap = this->getMyGlobalIndices ();
2069 typename std::decay<decltype (lgMap.extent (0)) >::type;
2070 const size_type lclNumInds =
2071 static_cast<size_type
> (this->getLocalNumElements ());
2072 using Teuchos::TypeNameTraits;
2073 TEUCHOS_TEST_FOR_EXCEPTION
2074 (lgMap.extent (0) != lclNumInds, std::logic_error,
2075 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
2076 "has length " << lgMap.extent (0) <<
" (of type " <<
2077 TypeNameTraits<size_type>::name () <<
") != this->getLocalNumElements()"
2078 " = " << this->getLocalNumElements () <<
". The latter, upon being "
2079 "cast to size_type = " << TypeNameTraits<size_type>::name () <<
", "
2080 "becomes " << lclNumInds <<
". Please report this bug to the Tpetra "
2083 Teuchos::ArrayView<const GO> lgMap = this->getLocalElementList ();
2086 const GO indexBase = this->getIndexBase ();
2088 auto lgMap_device = Kokkos::create_mirror_view_and_copy(
device_type(), lgMap);
2089 return rcp (
new map_type (RECOMPUTE, lgMap_device, indexBase, newComm));
2093 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2094 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
2098 using Teuchos::Comm;
2099 using Teuchos::null;
2100 using Teuchos::outArg;
2103 using Teuchos::REDUCE_MIN;
2104 using Teuchos::reduceAll;
2111 const int color = (numLocalElements_ == 0) ? 0 : 1;
2116 RCP<const Comm<int> > newComm = comm_->split (color, 0);
2122 if (newComm.is_null ()) {
2125 RCP<Map> map = rcp (
new Map ());
2127 map->comm_ = newComm;
2128 map->indexBase_ = indexBase_;
2129 map->numGlobalElements_ = numGlobalElements_;
2130 map->numLocalElements_ = numLocalElements_;
2131 map->minMyGID_ = minMyGID_;
2132 map->maxMyGID_ = maxMyGID_;
2133 map->minAllGID_ = minAllGID_;
2134 map->maxAllGID_ = maxAllGID_;
2135 map->firstContiguousGID_= firstContiguousGID_;
2136 map->lastContiguousGID_ = lastContiguousGID_;
2140 map->uniform_ = uniform_;
2141 map->contiguous_ = contiguous_;
2156 if (! distributed_ || newComm->getSize () == 1) {
2157 map->distributed_ =
false;
2159 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2160 int allProcsOwnAllGids = 0;
2161 reduceAll<int, int> (*newComm, REDUCE_MIN, iOwnAllGids, outArg (allProcsOwnAllGids));
2162 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
2165 map->lgMap_ = lgMap_;
2166 map->lgMapHost_ = lgMapHost_;
2167 map->glMap_ = glMap_;
2168 map->glMapHost_ = glMapHost_;
2185 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2189 TEUCHOS_TEST_FOR_EXCEPTION(
2190 directory_.is_null (), std::logic_error,
"Tpetra::Map::setupDirectory: "
2191 "The Directory is null. "
2192 "Please report this bug to the Tpetra developers.");
2196 if (! directory_->initialized ()) {
2197 directory_->initialize (*
this);
2201 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2205 const Teuchos::ArrayView<int>& PIDs,
2206 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const
2208 using Tpetra::Details::OrdinalTraits;
2211 using size_type = Teuchos::ArrayView<int>::size_type;
2214 const size_t maxNumToPrint = verbose ?
2216 std::unique_ptr<std::string> prefix;
2219 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2220 std::ostringstream os;
2221 os << *prefix <<
"Start: ";
2224 std::cerr << os.str();
2233 if (getGlobalNumElements () == 0) {
2234 if (GIDs.size () == 0) {
2236 std::ostringstream os;
2237 os << *prefix <<
"Done; both Map & input are empty" << endl;
2238 std::cerr << os.str();
2244 std::ostringstream os;
2245 os << *prefix <<
"Done: Map is empty on all processes, "
2246 "so all output PIDs & LIDs are invalid (-1)." << endl;
2247 std::cerr << os.str();
2249 for (size_type k = 0; k < PIDs.size (); ++k) {
2250 PIDs[k] = OrdinalTraits<int>::invalid ();
2252 for (size_type k = 0; k < LIDs.size (); ++k) {
2253 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid ();
2264 std::ostringstream os;
2265 os << *prefix <<
"Call setupDirectory" << endl;
2266 std::cerr << os.str();
2270 std::ostringstream os;
2271 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2272 std::cerr << os.str();
2275 directory_->getDirectoryEntries (*
this, GIDs, PIDs, LIDs);
2277 std::ostringstream os;
2278 os << *prefix <<
"Done; getDirectoryEntries returned "
2279 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2285 std::cerr << os.str();
2290 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2294 const Teuchos::ArrayView<int> & PIDs)
const
2300 const size_t maxNumToPrint = verbose ?
2302 std::unique_ptr<std::string> prefix;
2305 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2306 std::ostringstream os;
2307 os << *prefix <<
"Start: ";
2310 std::cerr << os.str();
2313 if (getGlobalNumElements () == 0) {
2314 if (GIDs.size () == 0) {
2316 std::ostringstream os;
2317 os << *prefix <<
"Done; both Map & input are empty" << endl;
2318 std::cerr << os.str();
2324 std::ostringstream os;
2325 os << *prefix <<
"Done: Map is empty on all processes, "
2326 "so all output PIDs are invalid (-1)." << endl;
2327 std::cerr << os.str();
2329 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size (); ++k) {
2330 PIDs[k] = Tpetra::Details::OrdinalTraits<int>::invalid ();
2341 std::ostringstream os;
2342 os << *prefix <<
"Call setupDirectory" << endl;
2343 std::cerr << os.str();
2347 std::ostringstream os;
2348 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2349 std::cerr << os.str();
2352 directory_->getDirectoryEntries(*
this, GIDs, PIDs);
2354 std::ostringstream os;
2355 os << *prefix <<
"Done; getDirectoryEntries returned "
2356 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2360 std::cerr << os.str();
2365 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2368 using exec_space =
typename Node::device_type::execution_space;
2369 if(lgMap_.extent(0) != lgMapHost_.extent(0)) {
2375 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace (), lgMap_);
2380 exec_space().fence();
2381 lgMapHost_ = lgMap_host;
2384 glMapHost_ = global_to_local_table_host_type(glMap_);
2389 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2390 Teuchos::RCP<const Teuchos::Comm<int> >
2395 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2401 using Teuchos::outArg;
2402 using Teuchos::REDUCE_MIN;
2403 using Teuchos::reduceAll;
2407 std::unique_ptr<std::string> prefix;
2410 comm_.getRawPtr(),
"Map",
"checkIsDist");
2411 std::ostringstream os;
2412 os << *prefix <<
"Start" << endl;
2413 std::cerr << os.str();
2416 bool global =
false;
2417 if (comm_->getSize () > 1) {
2421 if (numGlobalElements_ == as<global_size_t> (numLocalElements_)) {
2434 reduceAll<int, int> (*comm_, REDUCE_MIN, localRep, outArg (allLocalRep));
2435 if (allLocalRep != 1) {
2445 std::ostringstream os;
2446 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2448 std::cerr << os.str();
2455 template <
class LocalOrdinal,
class GlobalOrdinal>
2456 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2458 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2460 typedef LocalOrdinal LO;
2461 typedef GlobalOrdinal GO;
2462 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2463 return createLocalMapWithNode<LO, GO, NT> (numElements, comm);
2466 template <
class LocalOrdinal,
class GlobalOrdinal>
2467 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2469 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2471 typedef LocalOrdinal LO;
2472 typedef GlobalOrdinal GO;
2473 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2474 return createUniformContigMapWithNode<LO, GO, NT> (numElements, comm);
2477 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2478 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2480 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2485 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2487 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed));
2490 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2491 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2493 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2499 const GlobalOrdinal indexBase = 0;
2502 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated));
2505 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2506 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2508 const size_t localNumElements,
2509 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2514 const GlobalOrdinal indexBase = 0;
2516 return rcp (
new map_type (numElements, localNumElements, indexBase, comm));
2519 template <
class LocalOrdinal,
class GlobalOrdinal>
2520 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2522 const size_t localNumElements,
2523 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2525 typedef LocalOrdinal LO;
2526 typedef GlobalOrdinal GO;
2529 return Tpetra::createContigMapWithNode<LO, GO, NT> (numElements, localNumElements, comm);
2532 template <
class LocalOrdinal,
class GlobalOrdinal>
2533 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2535 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2537 typedef LocalOrdinal LO;
2538 typedef GlobalOrdinal GO;
2541 return Tpetra::createNonContigMapWithNode<LO, GO, NT> (elementList, comm);
2544 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2545 Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2547 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2553 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2557 const GlobalOrdinal indexBase = 0;
2559 return rcp (
new map_type (INV, elementList, indexBase, comm));
2562 template<
class LO,
class GO,
class NT>
2563 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >
2567 using Teuchos::Array;
2568 using Teuchos::ArrayView;
2576 const bool verbose = Details::Behavior::verbose(
"Map");
2577 std::unique_ptr<std::string> prefix;
2579 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2580 prefix = Details::createPrefix(
2581 comm.getRawPtr(),
"createOneToOne(Map)");
2582 std::ostringstream os;
2583 os << *prefix <<
"Start" << endl;
2586 const size_t maxNumToPrint = verbose ?
2587 Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2588 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2589 const int myRank = M->getComm ()->getRank ();
2595 if (! M->isDistributed ()) {
2602 const GST numGlobalEntries = M->getGlobalNumElements ();
2603 if (M->isContiguous()) {
2604 const size_t numLocalEntries =
2605 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2607 std::ostringstream os;
2608 os << *prefix <<
"Input is locally replicated & contiguous; "
2609 "numLocalEntries=" << numLocalEntries << endl;
2613 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2614 M->getIndexBase(), M->getComm()));
2616 std::ostringstream os;
2617 os << *prefix <<
"Done" << endl;
2624 std::ostringstream os;
2625 os << *prefix <<
"Input is locally replicated & noncontiguous"
2629 ArrayView<const GO> myGids =
2630 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2632 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2635 std::ostringstream os;
2636 os << *prefix <<
"Done" << endl;
2642 else if (M->isContiguous ()) {
2644 std::ostringstream os;
2645 os << *prefix <<
"Input is distributed & contiguous" << endl;
2654 std::ostringstream os;
2655 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2659 const size_t numMyElems = M->getLocalNumElements ();
2660 ArrayView<const GO> myElems = M->getLocalElementList ();
2661 Array<int> owner_procs_vec (numMyElems);
2664 std::ostringstream os;
2665 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2672 std::ostringstream os;
2673 os << *prefix <<
"getDirectoryEntries result: ";
2679 Array<GO> myOwned_vec (numMyElems);
2680 size_t numMyOwnedElems = 0;
2681 for (
size_t i = 0; i < numMyElems; ++i) {
2682 const GO GID = myElems[i];
2683 const int owner = owner_procs_vec[i];
2685 if (myRank == owner) {
2686 myOwned_vec[numMyOwnedElems++] = GID;
2689 myOwned_vec.resize (numMyOwnedElems);
2692 std::ostringstream os;
2693 os << *prefix <<
"Create Map: ";
2698 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2699 M->getIndexBase(), M->getComm()));
2701 std::ostringstream os;
2702 os << *prefix <<
"Done" << endl;
2709 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2710 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2714 using Details::Behavior;
2716 using Teuchos::Array;
2717 using Teuchos::ArrayView;
2720 using Teuchos::toString;
2723 using LO = LocalOrdinal;
2724 using GO = GlobalOrdinal;
2727 const bool verbose = Behavior::verbose(
"Map");
2728 std::unique_ptr<std::string> prefix;
2730 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2731 prefix = Details::createPrefix(
2732 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2733 std::ostringstream os;
2734 os << *prefix <<
"Start" << endl;
2737 const size_t maxNumToPrint = verbose ?
2738 Behavior::verbosePrintCountThreshold() : size_t(0);
2745 std::ostringstream os;
2746 os << *prefix <<
"Initialize Directory" << endl;
2751 std::ostringstream os;
2752 os << *prefix <<
"Done initializing Directory" << endl;
2755 size_t numMyElems = M->getLocalNumElements ();
2756 ArrayView<const GO> myElems = M->getLocalElementList ();
2757 Array<int> owner_procs_vec (numMyElems);
2759 std::ostringstream os;
2760 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2767 std::ostringstream os;
2768 os << *prefix <<
"getDirectoryEntries result: ";
2774 const int myRank = M->getComm()->getRank();
2775 Array<GO> myOwned_vec (numMyElems);
2776 size_t numMyOwnedElems = 0;
2777 for (
size_t i = 0; i < numMyElems; ++i) {
2778 const GO GID = myElems[i];
2779 const int owner = owner_procs_vec[i];
2780 if (myRank == owner) {
2781 myOwned_vec[numMyOwnedElems++] = GID;
2784 myOwned_vec.resize (numMyOwnedElems);
2789 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
2791 std::ostringstream os;
2792 os << *prefix <<
"Create Map: ";
2797 RCP<const map_type> retMap
2798 (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2801 std::ostringstream os;
2802 os << *prefix <<
"Done" << endl;
2816 #define TPETRA_MAP_INSTANT(LO,GO,NODE) \
2818 template class Map< LO , GO , NODE >; \
2820 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2821 createLocalMapWithNode<LO,GO,NODE> (const size_t numElements, \
2822 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2824 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2825 createContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2826 const size_t localNumElements, \
2827 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2829 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2830 createNonContigMapWithNode(const Teuchos::ArrayView<const GO> &elementList, \
2831 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); \
2833 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2834 createUniformContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2835 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2837 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2838 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M); \
2840 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2841 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M, \
2842 const Tpetra::Details::TieBreak<LO,GO>& tie_break); \
2846 #define TPETRA_MAP_INSTANT_DEFAULTNODE(LO,GO) \
2847 template Teuchos::RCP< const Map<LO,GO> > \
2848 createLocalMap<LO,GO>( const size_t, const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2850 template Teuchos::RCP< const Map<LO,GO> > \
2851 createContigMap<LO,GO>( global_size_t, size_t, \
2852 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2854 template Teuchos::RCP< const Map<LO,GO> > \
2855 createNonContigMap(const Teuchos::ArrayView<const GO> &, \
2856 const Teuchos::RCP<const Teuchos::Comm<int> > &); \
2858 template Teuchos::RCP< const Map<LO,GO> > \
2859 createUniformContigMap<LO,GO>( const global_size_t, \
2860 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2862 #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 local Map 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).