15#ifndef TPETRA_MAP_DEF_HPP
16#define TPETRA_MAP_DEF_HPP
23#include "Teuchos_as.hpp"
24#include "Teuchos_TypeNameTraits.hpp"
25#include "Teuchos_CommHelpers.hpp"
27#include "Tpetra_Directory.hpp"
29#include "Tpetra_Details_FixedHashTable.hpp"
34#include "Tpetra_Details_mpiIsInitialized.hpp"
42inline void checkMapInputArray(
const char ctorName[],
43 const void* indexList,
44 const size_t indexListSize,
45 const Teuchos::Comm<int>*
const comm) {
46 using Tpetra::Details::Behavior;
48 const bool debug = Behavior::debug(
"Map");
51 using Teuchos::outArg;
52 using Teuchos::REDUCE_MIN;
53 using Teuchos::reduceAll;
55 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
56 const bool verbose = Behavior::verbose(
"Map");
57 std::ostringstream lclErrStrm;
60 if (indexListSize != 0 && indexList ==
nullptr) {
63 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
65 << indexListSize <<
" != 0." << endl;
69 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
70 if (gblSuccess != 1) {
71 std::ostringstream gblErrStrm;
72 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
" detected a problem with the input array "
73 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
80 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
85template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
86void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
87 using LO = LocalOrdinal;
88 using GO = GlobalOrdinal;
89 using exec_space =
typename ViewType::device_type::execution_space;
90 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
91 const LO numLocalElements = entryList.extent(0);
95 typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
101 Kokkos::parallel_reduce(
102 range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
103 GO entry_0 = entryList[0];
104 GO entry_i = entryList[i];
107 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
108 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
109 l_firstCont = entry_0;
111 if (entry_i - entry_0 != i && l_lastCont.val >= i) {
113 l_lastCont.val = i - 1;
114 l_lastCont.loc = entryList[i - 1];
115 }
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
118 l_lastCont.loc = entry_i;
121 Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
124 lastContiguousGID_val = myMinLoc.loc;
125 lastContiguousGID_loc = myMinLoc.val;
130template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
133 : comm_(new Teuchos::SerialComm<int>())
135 , numGlobalElements_(0)
136 , numLocalElements_(0)
137 , minMyGID_(
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid())
138 , maxMyGID_(
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid())
139 , minAllGID_(
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid())
140 , maxAllGID_(
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid())
141 , firstContiguousGID_(
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid())
142 , lastContiguousGID_(
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid())
146 , distributed_(false)
148 directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
153template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
157 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
161 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
164 using Teuchos::broadcast;
165 using Teuchos::outArg;
166 using Teuchos::REDUCE_MAX;
167 using Teuchos::REDUCE_MIN;
168 using Teuchos::reduceAll;
169 using Teuchos::typeName;
172 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
173 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
175 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
179 std::unique_ptr<std::string> prefix;
182 comm_.getRawPtr(),
"Map", funcName);
183 std::ostringstream os;
184 os << *prefix <<
"Start" << endl;
185 std::cerr << os.str();
193 GST proc0NumGlobalElements = numGlobalElements;
194 broadcast(*comm_, 0, outArg(proc0NumGlobalElements));
195 GST minNumGlobalElements = numGlobalElements;
196 GST maxNumGlobalElements = numGlobalElements;
197 reduceAll(*comm, REDUCE_MIN, numGlobalElements,
198 outArg(minNumGlobalElements));
199 reduceAll(*comm, REDUCE_MAX, numGlobalElements,
200 outArg(maxNumGlobalElements));
201 TEUCHOS_TEST_FOR_EXCEPTION(minNumGlobalElements != maxNumGlobalElements ||
202 numGlobalElements != minNumGlobalElements,
203 std::invalid_argument, exPfx <<
"All processes must "
204 "provide the same number of global elements. Process 0 set "
206 << proc0NumGlobalElements <<
". The "
208 << comm->getRank() <<
" set "
210 << numGlobalElements <<
". The min "
211 "and max values over all processes are "
212 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements <<
".");
214 GO proc0IndexBase = indexBase;
215 broadcast<int, GO>(*comm_, 0, outArg(proc0IndexBase));
216 GO minIndexBase = indexBase;
217 GO maxIndexBase = indexBase;
218 reduceAll(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
219 reduceAll(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
220 TEUCHOS_TEST_FOR_EXCEPTION(minIndexBase != maxIndexBase || indexBase != minIndexBase,
221 std::invalid_argument, exPfx <<
"All processes must "
222 "provide the same indexBase argument. Process 0 set "
224 << proc0IndexBase <<
". The calling process " << comm->getRank() <<
" set indexBase=" << indexBase <<
". The min and max values over all processes are " << minIndexBase <<
" resp. " << maxIndexBase <<
".");
244 TEUCHOS_TEST_FOR_EXCEPTION(
245 (numGlobalElements < 1 && numGlobalElements != 0),
246 std::invalid_argument, exPfx <<
"numGlobalElements (= " << numGlobalElements <<
") must be nonnegative.");
248 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements == GSTI, std::invalid_argument, exPfx <<
"You provided numGlobalElements = Teuchos::OrdinalTraits<"
249 "Tpetra::global_size_t>::invalid(). This version of the "
250 "constructor requires a valid value of numGlobalElements. "
251 "You probably mistook this constructor for the \"contiguous "
252 "nonuniform\" constructor, which can compute the global "
253 "number of elements for you if you set numGlobalElements to "
254 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
256 size_t numLocalElements = 0;
257 if (lOrG == GloballyDistributed) {
272 const GST numProcs =
static_cast<GST
>(comm_->getSize());
273 const GST myRank =
static_cast<GST
>(comm_->getRank());
274 const GST quotient = numGlobalElements / numProcs;
275 const GST remainder = numGlobalElements - quotient * numProcs;
278 if (myRank < remainder) {
279 numLocalElements =
static_cast<size_t>(1) +
static_cast<size_t>(quotient);
282 startIndex = as<GO>(myRank) * as<GO>(numLocalElements);
284 numLocalElements = as<size_t>(quotient);
285 startIndex = as<GO>(myRank) * as<GO>(numLocalElements) +
289 minMyGID_ = indexBase + startIndex;
290 maxMyGID_ = indexBase + startIndex + numLocalElements - 1;
291 minAllGID_ = indexBase;
292 maxAllGID_ = indexBase + numGlobalElements - 1;
293 distributed_ = (numProcs > 1);
295 numLocalElements = as<size_t>(numGlobalElements);
296 minMyGID_ = indexBase;
297 maxMyGID_ = indexBase + numGlobalElements - 1;
298 distributed_ =
false;
301 minAllGID_ = indexBase;
302 maxAllGID_ = indexBase + numGlobalElements - 1;
303 indexBase_ = indexBase;
304 numGlobalElements_ = numGlobalElements;
305 numLocalElements_ = numLocalElements;
306 firstContiguousGID_ = minMyGID_;
307 lastContiguousGID_ = maxMyGID_;
314 std::ostringstream os;
315 os << *prefix <<
"Done" << endl;
316 std::cerr << os.str();
320template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
323 const size_t numLocalElements,
325 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
328 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
331 using Teuchos::broadcast;
332 using Teuchos::outArg;
333 using Teuchos::REDUCE_MAX;
334 using Teuchos::REDUCE_MIN;
335 using Teuchos::REDUCE_SUM;
336 using Teuchos::reduceAll;
340 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
341 const char funcName[] =
342 "Map(gblNumInds,lclNumInds,indexBase,comm)";
344 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
345 const char suffix[] =
346 ". Please report this bug to the Tpetra developers.";
350 std::unique_ptr<std::string> prefix;
353 comm_.getRawPtr(),
"Map", funcName);
354 std::ostringstream os;
355 os << *prefix <<
"Start" << endl;
356 std::cerr << os.str();
363 GST debugGlobalSum{};
365 debugGlobalSum = initialNonuniformDebugCheck(exPfx,
366 numGlobalElements, numLocalElements, indexBase, comm);
381 scan<int, GO>(*comm, REDUCE_SUM, numLocalElements, outArg(scanResult));
382 const GO myOffset = scanResult - numLocalElements;
384 if (numGlobalElements != GSTI) {
385 numGlobalElements_ = numGlobalElements;
391 const int numProcs = comm->getSize();
392 GST globalSum = scanResult;
394 broadcast(*comm, numProcs - 1, outArg(globalSum));
396 numGlobalElements_ = globalSum;
400 TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx <<
"globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum << suffix);
403 numLocalElements_ = numLocalElements;
404 indexBase_ = indexBase;
405 minAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
406 maxAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
407 minMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
408 maxMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
409 firstContiguousGID_ = minMyGID_;
410 lastContiguousGID_ = maxMyGID_;
412 distributed_ = checkIsDist();
418 std::ostringstream os;
419 os << *prefix <<
"Done" << endl;
420 std::cerr << os.str();
424template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
428 const char errorMessagePrefix[],
430 const size_t numLocalElements,
432 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const {
438 using Teuchos::broadcast;
439 using Teuchos::outArg;
441 using Teuchos::REDUCE_MAX;
442 using Teuchos::REDUCE_MIN;
443 using Teuchos::REDUCE_SUM;
444 using Teuchos::reduceAll;
445 using GO = global_ordinal_type;
447 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
457 GST debugGlobalSum = 0;
458 reduceAll<int, GST>(*comm, REDUCE_SUM,
static_cast<GST
>(numLocalElements),
459 outArg(debugGlobalSum));
463 GST proc0NumGlobalElements = numGlobalElements;
464 broadcast<int, GST>(*comm_, 0, outArg(proc0NumGlobalElements));
465 GST minNumGlobalElements = numGlobalElements;
466 GST maxNumGlobalElements = numGlobalElements;
467 reduceAll<int, GST>(*comm, REDUCE_MIN, numGlobalElements,
468 outArg(minNumGlobalElements));
469 reduceAll<int, GST>(*comm, REDUCE_MAX, numGlobalElements,
470 outArg(maxNumGlobalElements));
471 TEUCHOS_TEST_FOR_EXCEPTION(minNumGlobalElements != maxNumGlobalElements ||
472 numGlobalElements != minNumGlobalElements,
473 std::invalid_argument, errorMessagePrefix <<
"All processes "
474 "must provide the same number of global elements, even if "
476 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
477 "(which signals that the Map should compute the global "
478 "number of elements). Process 0 set numGlobalElements"
480 << proc0NumGlobalElements <<
". The calling process " << comm->getRank() <<
" set numGlobalElements=" << numGlobalElements <<
". The min and max values over all "
482 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements <<
".");
484 GO proc0IndexBase = indexBase;
485 broadcast<int, GO>(*comm_, 0, outArg(proc0IndexBase));
486 GO minIndexBase = indexBase;
487 GO maxIndexBase = indexBase;
488 reduceAll<int, GO>(*comm, REDUCE_MIN, indexBase, outArg(minIndexBase));
489 reduceAll<int, GO>(*comm, REDUCE_MAX, indexBase, outArg(maxIndexBase));
490 TEUCHOS_TEST_FOR_EXCEPTION(minIndexBase != maxIndexBase || indexBase != minIndexBase,
491 std::invalid_argument, errorMessagePrefix <<
"All processes must provide the same indexBase argument. "
492 "Process 0 set indexBase = "
493 << proc0IndexBase <<
". The "
495 << comm->getRank() <<
" set indexBase=" << indexBase <<
". The min and max values over all "
497 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
501 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalElements != GSTI &&
502 debugGlobalSum != numGlobalElements,
503 std::invalid_argument,
504 errorMessagePrefix <<
"The sum of each process' number of "
505 "indices over all processes, "
506 << debugGlobalSum <<
", != "
507 <<
"numGlobalElements=" << numGlobalElements <<
". If you "
508 "would like this constructor to compute numGlobalElements "
509 "for you, you may set numGlobalElements="
510 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
511 "on input. Please note that this is NOT necessarily -1.");
513 return debugGlobalSum;
516template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
519 const char errorMessagePrefix[],
524 Kokkos::MemoryUnmanaged>& entryList_host,
526 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
527 Tpetra::Details::ProfilingRegion pr(
"Map::initWithNonownedHostIndexList()");
529 using Kokkos::LayoutLeft;
530 using Kokkos::subview;
532 using Kokkos::view_alloc;
533 using Kokkos::WithoutInitializing;
535 using Teuchos::broadcast;
536 using Teuchos::outArg;
538 using Teuchos::REDUCE_MAX;
539 using Teuchos::REDUCE_MIN;
540 using Teuchos::REDUCE_SUM;
541 using Teuchos::reduceAll;
545 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
547 TEUCHOS_TEST_FOR_EXCEPTION(!Kokkos::is_initialized(), std::runtime_error,
548 errorMessagePrefix <<
"The Kokkos execution space "
549 << Teuchos::TypeNameTraits<execution_space>::name()
550 <<
" has not been initialized. "
551 "Please initialize it before creating a Map.")
564 const
size_t numLocalElements(entryList_host.size());
566 initialNonuniformDebugCheck(errorMessagePrefix, numGlobalElements,
567 numLocalElements, indexBase, comm);
577 if (numGlobalElements != GSTI) {
578 numGlobalElements_ = numGlobalElements;
580 reduceAll(*comm, REDUCE_SUM,
581 static_cast<GST
>(numLocalElements),
582 outArg(numGlobalElements_));
608 numLocalElements_ = numLocalElements;
609 indexBase_ = indexBase;
611 minMyGID_ = indexBase_;
612 maxMyGID_ = indexBase_;
622 if (numLocalElements_ > 0) {
626 typename decltype(lgMap_)::non_const_type lgMap(view_alloc(
"lgMap", WithoutInitializing), numLocalElements_);
628 Kokkos::create_mirror_view(Kokkos::HostSpace(), lgMap);
636 firstContiguousGID_ = entryList_host[0];
637 lastContiguousGID_ = firstContiguousGID_ + 1;
645 lgMap_host[0] = firstContiguousGID_;
647 for (; i < numLocalElements_; ++i) {
648 const GO curGid = entryList_host[i];
649 const LO curLid = as<LO>(i);
651 if (lastContiguousGID_ != curGid)
break;
657 lgMap_host[curLid] = curGid;
658 ++lastContiguousGID_;
660 --lastContiguousGID_;
666 minMyGID_ = firstContiguousGID_;
667 maxMyGID_ = lastContiguousGID_;
671 LO firstNonContiguous_loc = i;
673 const std::pair<size_t, size_t> ncRange(i, entryList_host.extent(0));
674 auto nonContigGids_host = subview(entryList_host, ncRange);
675 TEUCHOS_TEST_FOR_EXCEPTION(
static_cast<size_t>(nonContigGids_host.extent(0)) !=
676 static_cast<size_t>(entryList_host.extent(0) - i),
678 "Tpetra::Map noncontiguous constructor: "
679 "nonContigGids_host.extent(0) = "
680 << nonContigGids_host.extent(0)
681 <<
" != entryList_host.extent(0) - i = "
682 << (entryList_host.extent(0) - i) <<
" = "
683 << entryList_host.extent(0) <<
" - " << i
684 <<
". Please report this bug to the Tpetra developers.");
688 View<GO*, LayoutLeft, device_type>
689 nonContigGids(view_alloc(
"nonContigGids", WithoutInitializing),
690 nonContigGids_host.size());
693 Kokkos::deep_copy(
execution_space(), nonContigGids, nonContigGids_host);
694 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
696 glMap_ = global_to_local_table_type(nonContigGids,
697 firstNonContiguous_loc);
699 glMapHost_ = global_to_local_table_host_type(glMap_);
707 for (; i < numLocalElements_; ++i) {
708 const GO curGid = entryList_host[i];
709 const LO curLid =
static_cast<LO
>(i);
710 lgMap_host[curLid] = curGid;
714 if (curGid < minMyGID_) {
717 if (curGid > maxMyGID_) {
729 lgMapHost_ = lgMap_host;
732 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
733 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
737 firstContiguousGID_ = indexBase_ + 1;
738 lastContiguousGID_ = indexBase_;
763 if (std::numeric_limits<GO>::is_signed) {
766 (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
769 minMaxInput[0] = -minMyGID_;
770 minMaxInput[1] = maxMyGID_;
771 minMaxInput[2] = localDist;
777 reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
778 minAllGID_ = -minMaxOutput[0];
779 maxAllGID_ = minMaxOutput[1];
780 const GO globalDist = minMaxOutput[2];
781 distributed_ = (comm_->getSize() > 1 && globalDist == 1);
784 reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
785 reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
786 distributed_ = checkIsDist();
791 TEUCHOS_TEST_FOR_EXCEPTION(
792 minAllGID_ < indexBase_,
793 std::invalid_argument,
794 "Tpetra::Map constructor (noncontiguous): "
795 "Minimum global ID = "
796 << minAllGID_ <<
" over all process(es) is "
797 "less than the given indexBase = "
798 << indexBase_ <<
".");
804template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
807 const GlobalOrdinal indexList[],
808 const LocalOrdinal indexListSize,
809 const GlobalOrdinal indexBase,
810 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
813 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
815 const char funcName[] =
816 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
819 std::unique_ptr<std::string> prefix;
822 comm_.getRawPtr(),
"Map", funcName);
823 std::ostringstream os;
824 os << *prefix <<
"Start" << endl;
825 std::cerr << os.str();
830 Impl::checkMapInputArray(
"(GST, const GO[], LO, GO, comm)",
831 indexList,
static_cast<size_t>(indexListSize),
836 const GlobalOrdinal*
const indsRaw = indexListSize == 0 ? NULL : indexList;
837 Kokkos::View<
const GlobalOrdinal*,
840 Kokkos::MemoryUnmanaged>
841 inds(indsRaw, indexListSize);
842 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
845 std::ostringstream os;
846 os << *prefix <<
"Done" << endl;
847 std::cerr << os.str();
851template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
854 const Teuchos::ArrayView<const GlobalOrdinal>& entryList,
855 const GlobalOrdinal indexBase,
856 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
859 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
861 const char* funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
864 std::unique_ptr<std::string> prefix;
867 comm_.getRawPtr(),
"Map", funcName);
868 std::ostringstream os;
869 os << *prefix <<
"Start" << endl;
870 std::cerr << os.str();
875 const size_t numLclInds =
static_cast<size_t>(entryList.size());
876 Impl::checkMapInputArray(
"(GST, ArrayView, GO, comm)",
877 entryList.getRawPtr(), numLclInds,
882 const GlobalOrdinal*
const indsRaw =
883 numLclInds == 0 ? NULL : entryList.getRawPtr();
884 Kokkos::View<
const GlobalOrdinal*,
887 Kokkos::MemoryUnmanaged>
888 inds(indsRaw, numLclInds);
889 initWithNonownedHostIndexList(funcName, numGlobalElements, inds,
892 std::ostringstream os;
893 os << *prefix <<
"Done" << endl;
894 std::cerr << os.str();
898template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
901 const Kokkos::View<const GlobalOrdinal*, device_type>& entryList,
902 const GlobalOrdinal indexBase,
903 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
906 , directory_(new
Directory<LocalOrdinal, GlobalOrdinal, Node>()) {
907 using Kokkos::LayoutLeft;
908 using Kokkos::subview;
910 using Kokkos::view_alloc;
911 using Kokkos::WithoutInitializing;
914 using Teuchos::ArrayView;
916 using Teuchos::broadcast;
917 using Teuchos::outArg;
919 using Teuchos::REDUCE_MAX;
920 using Teuchos::REDUCE_MIN;
921 using Teuchos::REDUCE_SUM;
922 using Teuchos::reduceAll;
923 using Teuchos::typeName;
927 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
928 const char funcName[] =
929 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
932 std::unique_ptr<std::string> prefix;
935 comm_.getRawPtr(),
"Map", funcName);
936 std::ostringstream os;
937 os << *prefix <<
"Start" << endl;
938 std::cerr << os.str();
943 Impl::checkMapInputArray(
"(GST, Kokkos::View, GO, comm)",
945 static_cast<size_t>(entryList.extent(0)),
959 const size_t numLocalElements(entryList.size());
961 initialNonuniformDebugCheck(funcName, numGlobalElements,
962 numLocalElements, indexBase, comm);
972 if (numGlobalElements != GSTI) {
973 numGlobalElements_ = numGlobalElements;
975 reduceAll(*comm, REDUCE_SUM,
976 static_cast<GST
>(numLocalElements),
977 outArg(numGlobalElements_));
1003 numLocalElements_ = numLocalElements;
1004 indexBase_ = indexBase;
1006 minMyGID_ = indexBase_;
1007 maxMyGID_ = indexBase_;
1017 if (numLocalElements_ > 0) {
1021 typename decltype(lgMap_)::non_const_type lgMap(view_alloc(
"lgMap2", WithoutInitializing), numLocalElements_);
1025 Kokkos::deep_copy(
typename device_type::execution_space(), lgMap, entryList);
1026 LO lastContiguousGID_loc;
1027 Impl::computeConstantsOnDevice(entryList, minMyGID_, maxMyGID_, firstContiguousGID_, lastContiguousGID_, lastContiguousGID_loc);
1028 LO firstNonContiguous_loc = lastContiguousGID_loc + 1;
1029 auto nonContigGids = Kokkos::subview(entryList, std::pair<size_t, size_t>(firstNonContiguous_loc, entryList.extent(0)));
1032 glMap_ = global_to_local_table_type(nonContigGids,
1033 firstNonContiguous_loc);
1039 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1040 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1044 firstContiguousGID_ = indexBase_ + 1;
1045 lastContiguousGID_ = indexBase_;
1070 if (std::numeric_limits<GO>::is_signed) {
1072 const GO localDist =
1073 (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
1076 minMaxInput[0] = -minMyGID_;
1077 minMaxInput[1] = maxMyGID_;
1078 minMaxInput[2] = localDist;
1081 minMaxOutput[0] = 0;
1082 minMaxOutput[1] = 0;
1083 minMaxOutput[2] = 0;
1084 reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1085 minAllGID_ = -minMaxOutput[0];
1086 maxAllGID_ = minMaxOutput[1];
1087 const GO globalDist = minMaxOutput[2];
1088 distributed_ = (comm_->getSize() > 1 && globalDist == 1);
1091 reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
1092 reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
1093 distributed_ = checkIsDist();
1096 contiguous_ =
false;
1098 TEUCHOS_TEST_FOR_EXCEPTION(
1099 minAllGID_ < indexBase_,
1100 std::invalid_argument,
1101 "Tpetra::Map constructor (noncontiguous): "
1102 "Minimum global ID = "
1103 << minAllGID_ <<
" over all process(es) is "
1104 "less than the given indexBase = "
1105 << indexBase_ <<
".");
1111 std::ostringstream os;
1112 os << *prefix <<
"Done" << endl;
1113 std::cerr << os.str();
1117template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1119 if (!Kokkos::is_initialized()) {
1120 std::ostringstream os;
1121 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1122 "Kokkos::finalize() has been called. This is user error! There are "
1123 "two likely causes: "
1125 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1127 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1128 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1129 "or Tpetra::finalize()."
1132 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1135 this->getComm().getRawPtr());
1141 Teuchos::RCP<const Teuchos::Comm<int>> comm = this->
getComm();
1142 if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
1143 mpiIsInitialized() && mpiIsFinalized()) {
1149 std::ostringstream os;
1150 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1151 "MPI_Finalize() has been called. This is user error! There are "
1152 "two likely causes: "
1154 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1156 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1157 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1158 "Tpetra::finalize()."
1161 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1171template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1173 TEUCHOS_TEST_FOR_EXCEPTION(
1174 getComm().is_null(), std::logic_error,
1175 "Tpetra::Map::isOneToOne: "
1176 "getComm() returns null. Please report this bug to the Tpetra "
1181 return directory_->isOneToOne(*
this);
1184template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1191 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1194 }
else if (globalIndex >= firstContiguousGID_ &&
1195 globalIndex <= lastContiguousGID_) {
1196 return static_cast<LocalOrdinal
>(globalIndex - firstContiguousGID_);
1202 return glMapHost_.get(globalIndex);
1206template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1211 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
1221 return lgMapHost_[localIndex];
1225template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1226bool Map<LocalOrdinal, GlobalOrdinal, Node>::getGlobalElements(
1228 auto const minGI = getMinGlobalIndex();
1229 auto const minLI = getMinLocalIndex();
1230 auto const maxLI = getMaxLocalIndex();
1231 if (isContiguous()) {
1232 for (
size_t i = 0; i < numEntries; i++) {
1233 auto lclInd = localIndices[i];
1234 if (lclInd < minLI || lclInd > maxLI) {
1237 globalIndices[i] = minGI + lclInd;
1245 for (
size_t i = 0; i < numEntries; i++) {
1246 auto lclInd = localIndices[i];
1247 if (lclInd < minLI || lclInd > maxLI) {
1250 globalIndices[i] = lgMapHost_[lclInd];
1256template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1266template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1270 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1273template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1278template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1283template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1289 firstContiguousGID_, lastContiguousGID_,
1293template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1296 using Teuchos::outArg;
1297 using Teuchos::REDUCE_MIN;
1298 using Teuchos::reduceAll;
1323 lgMap_.extent(0) != 0 && map.lgMap_.extent(0) != 0 &&
1324 lgMap_.data() == map.lgMap_.data()) {
1338 TEUCHOS_TEST_FOR_EXCEPTION(
1340 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1341 "checked that this condition is true above, but it's false here. "
1342 "Please report this bug to the Tpetra developers.");
1345 const int locallyCompat =
1348 int globallyCompat = 0;
1349 reduceAll<int, int>(*comm_, REDUCE_MIN, locallyCompat, outArg(globallyCompat));
1350 return (globallyCompat == 1);
1353template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1356 using Teuchos::ArrayView;
1358 using size_type =
typename ArrayView<const GO>::size_type;
1382 TEUCHOS_TEST_FOR_EXCEPTION(
1384 "Tpetra::Map::locallySameAs: BUG");
1387 const size_type numRhsElts = rhsElts.size();
1388 for (size_type k = 0; k < numRhsElts; ++k) {
1389 const GO curLhsGid = minLhsGid +
static_cast<GO
>(k);
1390 if (curLhsGid != rhsElts[k]) {
1397 TEUCHOS_TEST_FOR_EXCEPTION(
1399 "Tpetra::Map::locallySameAs: BUG");
1402 const size_type numLhsElts = lhsElts.size();
1403 for (size_type k = 0; k < numLhsElts; ++k) {
1404 const GO curRhsGid = minRhsGid +
static_cast<GO
>(k);
1405 if (curRhsGid != lhsElts[k]) {
1410 }
else if (this->lgMap_.data() == map.lgMap_.data()) {
1418 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1423 LocalOrdinal numMismatchedElements = 0;
1424 Kokkos::parallel_reduce(
1425 "Tpetra::Map::locallySameAs",
1427 KOKKOS_LAMBDA(
const LocalOrdinal lid, LocalOrdinal& numMismatches) {
1428 if (lhsLclMap.getGlobalElement(lid) != rhsLclMap.getGlobalElement(lid))
1431 numMismatchedElements);
1433 return (numMismatchedElements == 0);
1439template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1452 auto numLocalElements1 = lmap1.getLocalNumElements();
1453 auto numLocalElements2 = lmap2.getLocalNumElements();
1455 if (numLocalElements1 > numLocalElements2) {
1460 if (lmap1.isContiguous() && lmap2.isContiguous()) {
1462 return ((lmap1.getMinGlobalIndex() == lmap2.getMinGlobalIndex()) &&
1463 (lmap1.getMaxGlobalIndex() <= lmap2.getMaxGlobalIndex()));
1466 if (lmap1.getMinGlobalIndex() < lmap2.getMinGlobalIndex() ||
1467 lmap1.getMaxGlobalIndex() > lmap2.getMaxGlobalIndex()) {
1475 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1479 Kokkos::parallel_reduce(
1481 range_type(0, numLocalElements1),
1482 KOKKOS_LAMBDA(
const LO i, LO& diff) {
1483 diff += (lmap1.getGlobalElement(i) != lmap2.getGlobalElement(i));
1487 return (numDiff == 0);
1490template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1493 using Teuchos::outArg;
1494 using Teuchos::REDUCE_MIN;
1495 using Teuchos::reduceAll;
1548 reduceAll<int, int>(*comm_, REDUCE_MIN, isSame_lcl, outArg(isSame_gbl));
1549 return isSame_gbl == 1;
1553template <
class LO,
class GO,
class DT>
1556 FillLgMap(
const Kokkos::View<GO*, DT>& lgMap,
1559 , startGid_(startGid) {
1560 Kokkos::RangePolicy<LO, typename DT::execution_space>
1561 range(
static_cast<LO
>(0),
static_cast<LO
>(lgMap.size()));
1562 Kokkos::parallel_for(range, *
this);
1565 KOKKOS_INLINE_FUNCTION
void operator()(
const LO& lid)
const {
1566 lgMap_(lid) = startGid_ +
static_cast<GO
>(lid);
1570 const Kokkos::View<GO*, DT> lgMap_;
1576template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1577typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
1582 using const_lg_view_type =
decltype(lgMap_);
1583 using lg_view_type =
typename const_lg_view_type::non_const_type;
1587 std::unique_ptr<std::string> prefix;
1590 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1591 std::ostringstream os;
1592 os << *prefix <<
"Start" << endl;
1593 std::cerr << os.str();
1599 const bool needToCreateLocalToGlobalMapping =
1600 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1602 if (needToCreateLocalToGlobalMapping) {
1604 std::ostringstream os;
1605 os << *prefix <<
"Need to create lgMap" << endl;
1606 std::cerr << os.str();
1611 TEUCHOS_TEST_FOR_EXCEPTION(!
isContiguous(), std::logic_error,
1612 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1613 "mapping (lgMap_) should have been set up already for a "
1614 "noncontiguous Map. Please report this bug to the Tpetra "
1619 using Kokkos::view_alloc;
1620 using Kokkos::WithoutInitializing;
1621 lg_view_type lgMap(
"lgMap3", numElts);
1623 std::ostringstream os;
1624 os << *prefix <<
"Fill lgMap" << endl;
1625 std::cerr << os.str();
1627 FillLgMap<LO, GO, device_type> fillIt(lgMap, minMyGID_);
1630 std::ostringstream os;
1631 os << *prefix <<
"Copy lgMap to lgMapHost" << endl;
1632 std::cerr << os.str();
1635 auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(), lgMap);
1638 Kokkos::deep_copy(exec_instance, lgMapHost, lgMap);
1642 exec_instance.fence();
1646 lgMapHost_ = lgMapHost;
1652 std::ostringstream os;
1653 os << *prefix <<
"Done" << endl;
1654 std::cerr << os.str();
1659template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1660typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
1665 using const_lg_view_type =
decltype(lgMap_);
1666 using lg_view_type =
typename const_lg_view_type::non_const_type;
1670 std::unique_ptr<std::string> prefix;
1673 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1674 std::ostringstream os;
1675 os << *prefix <<
"Start" << endl;
1676 std::cerr << os.str();
1682 const bool needToCreateLocalToGlobalMapping =
1683 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1685 if (needToCreateLocalToGlobalMapping) {
1687 std::ostringstream os;
1688 os << *prefix <<
"Need to create lgMap" << endl;
1689 std::cerr << os.str();
1694 TEUCHOS_TEST_FOR_EXCEPTION(!
isContiguous(), std::logic_error,
1695 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1696 "mapping (lgMap_) should have been set up already for a "
1697 "noncontiguous Map. Please report this bug to the Tpetra "
1702 using Kokkos::view_alloc;
1703 using Kokkos::WithoutInitializing;
1704 lg_view_type lgMap(
"lgMap4", numElts);
1706 std::ostringstream os;
1707 os << *prefix <<
"Fill lgMap" << endl;
1708 std::cerr << os.str();
1710 FillLgMap<LO, GO, device_type> fillIt(lgMap, minMyGID_);
1717 std::ostringstream os;
1718 os << *prefix <<
"Done" << endl;
1719 std::cerr << os.str();
1724template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1725Teuchos::ArrayView<const GlobalOrdinal>
1736 const GO* lgMapHostRawPtr = lgMapHost_.data();
1740 return Teuchos::ArrayView<const GO>(
1742 lgMapHost_.extent(0),
1743 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1746template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1748 return distributed_;
1751template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1753 using Teuchos::TypeNameTraits;
1754 std::ostringstream os;
1756 os <<
"Tpetra::Map: {"
1757 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name()
1758 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name()
1759 <<
", NodeType: " << TypeNameTraits<Node>::name();
1760 if (this->getObjectLabel() !=
"") {
1761 os <<
", Label: \"" << this->getObjectLabel() <<
"\"";
1764 <<
", Number of processes: " <<
getComm()->getSize()
1765 <<
", Uniform: " << (
isUniform() ?
"true" :
"false")
1766 <<
", Contiguous: " << (
isContiguous() ?
"true" :
"false")
1767 <<
", Distributed: " << (
isDistributed() ?
"true" :
"false")
1776template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1784 if (vl < Teuchos::VERB_HIGH) {
1785 return std::string();
1787 auto outStringP = Teuchos::rcp(
new std::ostringstream());
1788 Teuchos::RCP<Teuchos::FancyOStream> outp =
1789 Teuchos::getFancyOStream(outStringP);
1790 Teuchos::FancyOStream& out = *outp;
1792 auto comm = this->getComm();
1793 const int myRank = comm->getRank();
1794 const int numProcs = comm->getSize();
1795 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1796 Teuchos::OSTab tab1(out);
1798 const LO numEnt =
static_cast<LO
>(this->getLocalNumElements());
1799 out <<
"My number of entries: " << numEnt << endl
1800 <<
"My minimum global index: " << this->getMinGlobalIndex() << endl
1801 <<
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
1803 if (vl == Teuchos::VERB_EXTREME) {
1804 out <<
"My global indices: [";
1805 const LO minLclInd = this->getMinLocalIndex();
1806 for (LO k = 0; k < numEnt; ++k) {
1807 out << minLclInd + this->getGlobalElement(k);
1808 if (k + 1 < numEnt) {
1816 return outStringP->str();
1819template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1821 describe(Teuchos::FancyOStream& out,
1822 const Teuchos::EVerbosityLevel verbLevel)
const {
1824 using Teuchos::TypeNameTraits;
1825 using Teuchos::VERB_DEFAULT;
1826 using Teuchos::VERB_HIGH;
1827 using Teuchos::VERB_LOW;
1828 using Teuchos::VERB_NONE;
1831 const Teuchos::EVerbosityLevel vl =
1832 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1834 if (vl == VERB_NONE) {
1842 if (comm.is_null()) {
1845 const int myRank = comm->getRank();
1846 const int numProcs = comm->getSize();
1855 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1861 tab0 = Teuchos::rcp(
new Teuchos::OSTab(out));
1862 out <<
"\"Tpetra::Map\":" << endl;
1863 tab1 = Teuchos::rcp(
new Teuchos::OSTab(out));
1865 out <<
"Template parameters:" << endl;
1866 Teuchos::OSTab tab2(out);
1867 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name() << endl
1868 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name() << endl
1869 <<
"Node: " << TypeNameTraits<Node>::name() << endl;
1871 const std::string label = this->getObjectLabel();
1873 out <<
"Label: \"" << label <<
"\"" << endl;
1879 <<
"Number of processes: " << numProcs << endl
1880 <<
"Uniform: " << (
isUniform() ?
"true" :
"false") << endl
1881 <<
"Contiguous: " << (
isContiguous() ?
"true" :
"false") << endl
1882 <<
"Distributed: " << (
isDistributed() ?
"true" :
"false") << endl;
1886 if (vl >= VERB_HIGH) {
1887 const std::string lclStr = this->localDescribeToString(vl);
1892template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1893Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1910 if (newComm.is_null() || newComm->getSize() < 1) {
1911 return Teuchos::null;
1912 }
else if (newComm->getSize() == 1) {
1919 RCP<map_type> newMap(
new map_type());
1921 newMap->comm_ = newComm;
1925 newMap->indexBase_ = this->indexBase_;
1926 newMap->numGlobalElements_ = this->numLocalElements_;
1927 newMap->numLocalElements_ = this->numLocalElements_;
1928 newMap->minMyGID_ = this->minMyGID_;
1929 newMap->maxMyGID_ = this->maxMyGID_;
1930 newMap->minAllGID_ = this->minMyGID_;
1931 newMap->maxAllGID_ = this->maxMyGID_;
1932 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1933 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1936 newMap->uniform_ = this->uniform_;
1937 newMap->contiguous_ = this->contiguous_;
1940 newMap->distributed_ =
false;
1941 newMap->lgMap_ = this->lgMap_;
1942 newMap->lgMapHost_ = this->lgMapHost_;
1943 newMap->glMap_ = this->glMap_;
1944 newMap->glMapHost_ = this->glMapHost_;
1964 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
1982 typename std::decay<
decltype(lgMap.extent(0))>::type;
1983 const size_type lclNumInds =
1985 using Teuchos::TypeNameTraits;
1986 TEUCHOS_TEST_FOR_EXCEPTION(lgMap.extent(0) != lclNumInds, std::logic_error,
1987 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
1989 << lgMap.extent(0) <<
" (of type " << TypeNameTraits<size_type>::name() <<
") != this->getLocalNumElements()"
1991 << this->getLocalNumElements() <<
". The latter, upon being "
1992 "cast to size_type = "
1993 << TypeNameTraits<size_type>::name() <<
", "
1995 << lclNumInds <<
". Please report this bug to the Tpetra "
2003 auto lgMap_device = Kokkos::create_mirror_view_and_copy(
device_type(), lgMap);
2004 return rcp(
new map_type(RECOMPUTE, lgMap_device, indexBase, newComm));
2008template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2009Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
2012 using Teuchos::Comm;
2013 using Teuchos::null;
2014 using Teuchos::outArg;
2017 using Teuchos::REDUCE_MIN;
2018 using Teuchos::reduceAll;
2025 const int color = (numLocalElements_ == 0) ? 0 : 1;
2030 RCP<const Comm<int>> newComm = comm_->split(color, 0);
2036 if (newComm.is_null()) {
2039 RCP<Map> map = rcp(
new Map());
2041 map->comm_ = newComm;
2042 map->indexBase_ = indexBase_;
2043 map->numGlobalElements_ = numGlobalElements_;
2044 map->numLocalElements_ = numLocalElements_;
2045 map->minMyGID_ = minMyGID_;
2046 map->maxMyGID_ = maxMyGID_;
2047 map->minAllGID_ = minAllGID_;
2048 map->maxAllGID_ = maxAllGID_;
2049 map->firstContiguousGID_ = firstContiguousGID_;
2050 map->lastContiguousGID_ = lastContiguousGID_;
2054 map->uniform_ = uniform_;
2055 map->contiguous_ = contiguous_;
2070 if (!distributed_ || newComm->getSize() == 1) {
2071 map->distributed_ =
false;
2073 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2074 int allProcsOwnAllGids = 0;
2075 reduceAll<int, int>(*newComm, REDUCE_MIN, iOwnAllGids, outArg(allProcsOwnAllGids));
2076 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
2079 map->lgMap_ = lgMap_;
2080 map->lgMapHost_ = lgMapHost_;
2081 map->glMap_ = glMap_;
2082 map->glMapHost_ = glMapHost_;
2099template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2100void Map<LocalOrdinal, GlobalOrdinal, Node>::setupDirectory()
const {
2101 TEUCHOS_TEST_FOR_EXCEPTION(
2102 directory_.is_null(), std::logic_error,
2103 "Tpetra::Map::setupDirectory: "
2104 "The Directory is null. "
2105 "Please report this bug to the Tpetra developers.");
2109 if (!directory_->initialized()) {
2110 directory_->initialize(*
this);
2114template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2118 const Teuchos::ArrayView<int>& PIDs,
2119 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const {
2122 using Tpetra::Details::OrdinalTraits;
2123 using size_type = Teuchos::ArrayView<int>::size_type;
2127 std::unique_ptr<std::string> prefix;
2130 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2131 std::ostringstream os;
2132 os << *prefix <<
"Start: ";
2133 verbosePrintArray(os, GIDs,
"GIDs", maxNumToPrint);
2135 std::cerr << os.str();
2145 if (GIDs.size() == 0) {
2147 std::ostringstream os;
2148 os << *prefix <<
"Done; both Map & input are empty" << endl;
2149 std::cerr << os.str();
2154 std::ostringstream os;
2155 os << *prefix <<
"Done: Map is empty on all processes, "
2156 "so all output PIDs & LIDs are invalid (-1)."
2158 std::cerr << os.str();
2160 for (size_type k = 0; k < PIDs.size(); ++k) {
2161 PIDs[k] = OrdinalTraits<int>::invalid();
2163 for (size_type k = 0; k < LIDs.size(); ++k) {
2164 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid();
2175 std::ostringstream os;
2176 os << *prefix <<
"Call setupDirectory" << endl;
2177 std::cerr << os.str();
2181 std::ostringstream os;
2182 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2183 std::cerr << os.str();
2186 directory_->getDirectoryEntries(*
this, GIDs, PIDs, LIDs);
2188 std::ostringstream os;
2189 os << *prefix <<
"Done; getDirectoryEntries returned "
2190 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2192 verbosePrintArray(os, PIDs,
"PIDs", maxNumToPrint);
2194 verbosePrintArray(os, LIDs,
"LIDs", maxNumToPrint);
2196 std::cerr << os.str();
2201template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2205 const Teuchos::ArrayView<int>& PIDs)
const {
2211 std::unique_ptr<std::string> prefix;
2214 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2215 std::ostringstream os;
2216 os << *prefix <<
"Start: ";
2217 verbosePrintArray(os, GIDs,
"GIDs", maxNumToPrint);
2219 std::cerr << os.str();
2223 if (GIDs.size() == 0) {
2225 std::ostringstream os;
2226 os << *prefix <<
"Done; both Map & input are empty" << endl;
2227 std::cerr << os.str();
2232 std::ostringstream os;
2233 os << *prefix <<
"Done: Map is empty on all processes, "
2234 "so all output PIDs are invalid (-1)."
2236 std::cerr << os.str();
2238 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size(); ++k) {
2239 PIDs[k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2250 std::ostringstream os;
2251 os << *prefix <<
"Call setupDirectory" << endl;
2252 std::cerr << os.str();
2256 std::ostringstream os;
2257 os << *prefix <<
"Call directory_->getDirectoryEntries" << endl;
2258 std::cerr << os.str();
2261 directory_->getDirectoryEntries(*
this, GIDs, PIDs);
2263 std::ostringstream os;
2264 os << *prefix <<
"Done; getDirectoryEntries returned "
2265 << (retVal ==
IDNotPresent ?
"IDNotPresent" :
"AllIDsPresent")
2267 verbosePrintArray(os, PIDs,
"PIDs", maxNumToPrint);
2269 std::cerr << os.str();
2274template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2276 using exec_space =
typename Node::device_type::execution_space;
2277 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2283 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2287 Kokkos::deep_copy(exec_space(), lgMap_host, lgMap_);
2288 exec_space().fence();
2289 lgMapHost_ = lgMap_host;
2292 glMapHost_ = global_to_local_table_host_type(glMap_);
2296template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2297Teuchos::RCP<const Teuchos::Comm<int>>
2302template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2307 using Teuchos::outArg;
2308 using Teuchos::REDUCE_MIN;
2309 using Teuchos::reduceAll;
2312 std::unique_ptr<std::string> prefix;
2315 comm_.getRawPtr(),
"Map",
"checkIsDist");
2316 std::ostringstream os;
2317 os << *prefix <<
"Start" << endl;
2318 std::cerr << os.str();
2321 bool global =
false;
2322 if (comm_->getSize() > 1) {
2326 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2339 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2340 if (allLocalRep != 1) {
2350 std::ostringstream os;
2351 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2353 std::cerr << os.str();
2360template <
class LocalOrdinal,
class GlobalOrdinal>
2361Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2363 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2364 typedef LocalOrdinal LO;
2365 typedef GlobalOrdinal GO;
2366 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2367 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2370template <
class LocalOrdinal,
class GlobalOrdinal>
2371Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2373 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2374 typedef LocalOrdinal LO;
2375 typedef GlobalOrdinal GO;
2376 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2377 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2380template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2381Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2383 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2386 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2388 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2391template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2392Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2394 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2398 const GlobalOrdinal indexBase = 0;
2401 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2404template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2405Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2407 const size_t localNumElements,
2408 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2411 const GlobalOrdinal indexBase = 0;
2413 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2416template <
class LocalOrdinal,
class GlobalOrdinal>
2417Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2419 const size_t localNumElements,
2420 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2421 typedef LocalOrdinal LO;
2422 typedef GlobalOrdinal GO;
2428template <
class LocalOrdinal,
class GlobalOrdinal>
2429Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2431 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2432 typedef LocalOrdinal LO;
2433 typedef GlobalOrdinal GO;
2439template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2440Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2442 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2446 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2450 const GlobalOrdinal indexBase = 0;
2452 return rcp(
new map_type(INV, elementList, indexBase, comm));
2455template <
class LO,
class GO,
class NT>
2456Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2458 using Details::verbosePrintArray;
2461 using Teuchos::Array;
2462 using Teuchos::ArrayView;
2468 const bool verbose = Details::Behavior::verbose(
"Map");
2469 std::unique_ptr<std::string> prefix;
2471 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2472 prefix = Details::createPrefix(
2473 comm.getRawPtr(),
"createOneToOne(Map)");
2474 std::ostringstream os;
2475 os << *prefix <<
"Start" << endl;
2478 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2479 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2480 const int myRank = M->getComm()->getRank();
2486 if (!M->isDistributed()) {
2493 const GST numGlobalEntries = M->getGlobalNumElements();
2494 if (M->isContiguous()) {
2495 const size_t numLocalEntries =
2496 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2498 std::ostringstream os;
2499 os << *prefix <<
"Input is locally replicated & contiguous; "
2501 << numLocalEntries << endl;
2505 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2506 M->getIndexBase(), M->getComm()));
2508 std::ostringstream os;
2509 os << *prefix <<
"Done" << endl;
2515 std::ostringstream os;
2516 os << *prefix <<
"Input is locally replicated & noncontiguous"
2520 ArrayView<const GO> myGids =
2521 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2523 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2526 std::ostringstream os;
2527 os << *prefix <<
"Done" << endl;
2532 }
else if (M->isContiguous()) {
2534 std::ostringstream os;
2535 os << *prefix <<
"Input is distributed & contiguous" << endl;
2543 std::ostringstream os;
2544 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2548 const size_t numMyElems = M->getLocalNumElements();
2549 ArrayView<const GO> myElems = M->getLocalElementList();
2550 Array<int> owner_procs_vec(numMyElems);
2553 std::ostringstream os;
2554 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2561 std::ostringstream os;
2562 os << *prefix <<
"getDirectoryEntries result: ";
2568 Array<GO> myOwned_vec(numMyElems);
2569 size_t numMyOwnedElems = 0;
2570 for (
size_t i = 0; i < numMyElems; ++i) {
2571 const GO GID = myElems[i];
2572 const int owner = owner_procs_vec[i];
2574 if (myRank == owner) {
2575 myOwned_vec[numMyOwnedElems++] = GID;
2578 myOwned_vec.resize(numMyOwnedElems);
2581 std::ostringstream os;
2582 os << *prefix <<
"Create Map: ";
2587 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2588 M->getIndexBase(), M->getComm()));
2590 std::ostringstream os;
2591 os << *prefix <<
"Done" << endl;
2598template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2599Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2602 using Details::Behavior;
2603 using Details::verbosePrintArray;
2606 using Teuchos::Array;
2607 using Teuchos::ArrayView;
2610 using Teuchos::toString;
2611 using LO = LocalOrdinal;
2612 using GO = GlobalOrdinal;
2615 const bool verbose = Behavior::verbose(
"Map");
2616 std::unique_ptr<std::string> prefix;
2618 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2619 prefix = Details::createPrefix(
2620 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2621 std::ostringstream os;
2622 os << *prefix <<
"Start" << endl;
2625 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2632 std::ostringstream os;
2633 os << *prefix <<
"Initialize Directory" << endl;
2638 std::ostringstream os;
2639 os << *prefix <<
"Done initializing Directory" << endl;
2642 size_t numMyElems = M->getLocalNumElements();
2643 ArrayView<const GO> myElems = M->getLocalElementList();
2644 Array<int> owner_procs_vec(numMyElems);
2646 std::ostringstream os;
2647 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2654 std::ostringstream os;
2655 os << *prefix <<
"getDirectoryEntries result: ";
2661 const int myRank = M->getComm()->getRank();
2662 Array<GO> myOwned_vec(numMyElems);
2663 size_t numMyOwnedElems = 0;
2664 for (
size_t i = 0; i < numMyElems; ++i) {
2665 const GO GID = myElems[i];
2666 const int owner = owner_procs_vec[i];
2667 if (myRank == owner) {
2668 myOwned_vec[numMyOwnedElems++] = GID;
2671 myOwned_vec.resize(numMyOwnedElems);
2676 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2678 std::ostringstream os;
2679 os << *prefix <<
"Create Map: ";
2684 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2687 std::ostringstream os;
2688 os << *prefix <<
"Done" << endl;
2702#define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2704 template class Map<LO, GO, NODE>; \
2706 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2707 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2708 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2710 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2711 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2712 const size_t localNumElements, \
2713 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2715 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2716 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2717 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2719 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2720 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2721 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2723 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2724 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2726 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2727 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2728 const Tpetra::Details::TieBreak<LO, GO>& tie_break);
2731#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2732 template Teuchos::RCP<const Map<LO, GO>> \
2733 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2735 template Teuchos::RCP<const Map<LO, GO>> \
2736 createContigMap<LO, GO>(global_size_t, size_t, \
2737 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2739 template Teuchos::RCP<const Map<LO, GO>> \
2740 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2741 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2743 template Teuchos::RCP<const Map<LO, GO>> \
2744 createUniformContigMap<LO, GO>(const global_size_t, \
2745 const Teuchos::RCP<const Teuchos::Comm<int>>&);
Functions for initializing and finalizing Tpetra.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
Declaration of a function that prints strings from each process.
Declaration of Tpetra::Details::initializeKokkos.
Declaration of Tpetra::Details::printOnce.
Stand-alone utility functions and macros.
static void reject_unrecognized_env_vars()
Search the environment for TPETRA_ variables and reject unrecognized ones.
static bool debug()
Whether Tpetra is in debug mode.
static bool verbose()
Whether Tpetra is in verbose mode.
static size_t verbosePrintCountThreshold()
Number of entries below which arrays, lists, etc. will be printed in debug mode.
Interface for breaking ties in ownership.
Implement mapping from global ID to process ID and local ID.
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.
void initialize(const map_type &map)
Initialize the Directory with its Map.
A parallel distribution of indices over processes.
::Tpetra::Details::LocalMap< local_ordinal_type, global_ordinal_type, device_type > local_map_type
Type of the "local" Map.
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
bool isOneToOne() const
Whether the Map is one to one.
std::string description() const
Implementation of Teuchos::Describable.
Teuchos::ArrayView< const global_ordinal_type > getLocalElementList() const
Return a NONOWNING view of the global indices owned by this process.
global_ordinal_type getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
Node node_type
Legacy typedef that will go away at some point.
Map()
Default constructor (that does nothing).
GlobalOrdinal global_ordinal_type
The type of global indices.
Map(const global_size_t numGlobalElements, const global_ordinal_type indexBase, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const LocalGlobal lg=GloballyDistributed)
Constructor with contiguous uniform distribution.
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.
bool isNodeLocalElement(local_ordinal_type localIndex) const
Whether the given local index is valid for this Map on the calling process.
bool isUniform() const
Whether the range of global indices is uniform.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
typename device_type::execution_space execution_space
The Kokkos execution space.
LocalOrdinal local_ordinal_type
The type of local indices.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > removeEmptyProcesses() const
Advanced methods.
void lazyPushToHost() const
Push the device data to host, if needed.
global_ordinal_type getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
bool isCompatible(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is compatible with this Map.
global_ordinal_type getIndexBase() const
The index base for this 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?
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.
virtual ~Map()
Destructor (virtual for memory safety of derived classes).
global_indices_array_device_type getMyGlobalIndicesDevice() const
Return a view of the global indices owned by this process on the Map's device.
global_ordinal_type getMinGlobalIndex() const
The minimum global index owned by the calling process.
local_ordinal_type getLocalElement(global_ordinal_type globalIndex) const
The local index corresponding to the given global index.
Teuchos::RCP< const Map< local_ordinal_type, global_ordinal_type, Node > > replaceCommWithSubset(const Teuchos::RCP< const Teuchos::Comm< int > > &newComm) const
Replace this Map's communicator with a subset communicator.
global_ordinal_type getMaxGlobalIndex() const
The maximum global index owned by the calling process.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
bool isContiguous() const
True if this Map is distributed contiguously, else false.
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.
bool isNodeGlobalElement(global_ordinal_type globalIndex) const
Whether the given global index is owned by this Map on the calling process.
bool isSameAs(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is identical to this Map.
local_ordinal_type getMinLocalIndex() const
The minimum local index.
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
local_map_type getLocalMap() const
Get the LocalMap for Kokkos-Kernels.
global_indices_array_type getMyGlobalIndices() const
Return a view of the global indices owned by this process.
local_ordinal_type getMaxLocalIndex() const
The maximum local index on the calling process.
typename Node::device_type device_type
This class' Kokkos::Device specialization.
Implementation details of Tpetra.
void verbosePrintArray(std::ostream &out, const ArrayType &x, const char name[], const size_t maxNumToPrint)
Print min(x.size(), maxNumToPrint) entries of x.
void printOnce(std::ostream &out, const std::string &s, const Teuchos::Comm< int > *comm)
Print on one process of the given communicator, or at least try to do so (if MPI is not initialized).
bool teuchosCommIsAnMpiComm(const Teuchos::Comm< int > &)
Is the given Comm a Teuchos::MpiComm<int> instance?
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
bool mpiIsInitialized()
Has MPI_Init been called (on this process)?
bool congruent(const Teuchos::Comm< int > &comm1, const Teuchos::Comm< int > &comm2)
Whether the two communicators are congruent.
void initializeKokkos()
Initialize Kokkos, using command-line arguments (if any) given to Teuchos::GlobalMPISession.
bool mpiIsFinalized()
Has MPI_Finalize been called (on this process)?
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,...
Namespace for new Tpetra features that are not ready for public release, but are ready for evaluation...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
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.
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.
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.
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.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
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...
size_t global_size_t
Global size_t object.
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,...
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.
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 ...
LocalGlobal
Enum for local versus global allocation of Map entries.
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...