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 "Kokkos_Sort.hpp"
29#include "Tpetra_Directory.hpp"
32#include "Tpetra_Details_FixedHashTable.hpp"
38#include "Tpetra_Details_mpiIsInitialized.hpp"
46inline void checkMapInputArray(
const char ctorName[],
47 const void* indexList,
48 const size_t indexListSize,
49 const Teuchos::Comm<int>*
const comm) {
52 const bool debug = Behavior::debug(
"Map");
55 using Teuchos::outArg;
56 using Teuchos::REDUCE_MIN;
57 using Teuchos::reduceAll;
59 const int myRank = comm ==
nullptr ? 0 : comm->getRank();
60 const bool verbose = Behavior::verbose(
"Map");
61 std::ostringstream lclErrStrm;
64 if (indexListSize != 0 && indexList ==
nullptr) {
67 lclErrStrm <<
"Proc " << myRank <<
": indexList is null, "
69 << indexListSize <<
" != 0." << endl;
73 reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
74 if (gblSuccess != 1) {
75 std::ostringstream gblErrStrm;
76 gblErrStrm <<
"Tpetra::Map constructor " << ctorName <<
" detected a problem with the input array "
77 "(raw array, Teuchos::ArrayView, or Kokkos::View) "
81 using ::Tpetra::Details::gathervPrint;
84 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
89template <
class LocalOrdinal,
class GlobalOrdinal,
class ViewType>
90void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
91 using LO = LocalOrdinal;
92 using GO = GlobalOrdinal;
93 using exec_space =
typename ViewType::device_type::execution_space;
94 using range_policy = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
95 const LO numLocalElements = entryList.extent(0);
99 typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
100 minloc_type myMinLoc;
105 Kokkos::parallel_reduce(
106 range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
107 GO entry_0 = entryList[0];
108 GO entry_i = entryList[i];
111 l_myMin = (l_myMin < entry_i) ? l_myMin : entry_i;
112 l_myMax = (l_myMax > entry_i) ? l_myMax : entry_i;
113 l_firstCont = entry_0;
115 if (entry_i - entry_0 != i && l_lastCont.val >= i) {
117 l_lastCont.val = i - 1;
118 l_lastCont.loc = entryList[i - 1];
119 }
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
122 l_lastCont.loc = entry_i;
125 Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
128 lastContiguousGID_val = myMinLoc.loc;
129 lastContiguousGID_loc = myMinLoc.val;
134template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
139 , numGlobalElements_(0)
140 , numLocalElements_(0)
150 , distributed_(
false)
151 , haveGlobalConstants_(
true)
158template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
162 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
169 using Teuchos::broadcast;
170 using Teuchos::outArg;
171 using Teuchos::REDUCE_MAX;
172 using Teuchos::REDUCE_MIN;
173 using Teuchos::reduceAll;
174 using Teuchos::typeName;
177 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
178 const char funcName[] =
"Map(gblNumInds,indexBase,comm,LG)";
180 "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
184 std::unique_ptr<std::string>
prefix;
187 comm_.getRawPtr(),
"Map",
funcName);
188 std::ostringstream
os;
190 std::cerr <<
os.str();
208 std::invalid_argument,
exPfx <<
"All processes must "
209 "provide the same number of global elements. Process 0 set "
213 << comm->getRank() <<
" set "
216 "and max values over all processes are "
226 std::invalid_argument,
exPfx <<
"All processes must "
227 "provide the same indexBase argument. Process 0 set "
251 std::invalid_argument,
exPfx <<
"numGlobalElements (= " <<
numGlobalElements <<
") must be nonnegative.");
254 "Tpetra::global_size_t>::invalid(). This version of the "
255 "constructor requires a valid value of numGlobalElements. "
256 "You probably mistook this constructor for the \"contiguous "
257 "nonuniform\" constructor, which can compute the global "
258 "number of elements for you if you set numGlobalElements to "
259 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
262 if (
lOrG == GloballyDistributed) {
278 const GST myRank =
static_cast<GST>(comm_->getRank());
303 distributed_ =
false;
306 minAllGID_ = indexBase;
307 maxAllGID_ = indexBase + numGlobalElements - 1;
308 indexBase_ = indexBase;
309 numGlobalElements_ = numGlobalElements;
310 numLocalElements_ = numLocalElements;
311 firstContiguousGID_ = minMyGID_;
312 lastContiguousGID_ = maxMyGID_;
314 haveGlobalConstants_ =
true;
320 std::ostringstream os;
321 os << *prefix <<
"Done" << endl;
322 std::cerr << os.str();
326template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
331 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
337 using Teuchos::broadcast;
338 using Teuchos::outArg;
339 using Teuchos::REDUCE_MAX;
340 using Teuchos::REDUCE_MIN;
341 using Teuchos::REDUCE_SUM;
342 using Teuchos::reduceAll;
346 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
348 "Map(gblNumInds,lclNumInds,indexBase,comm)";
350 "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
352 ". Please report this bug to the Tpetra developers.";
356 std::unique_ptr<std::string>
prefix;
359 comm_.getRawPtr(),
"Map",
funcName);
360 std::ostringstream
os;
362 std::cerr <<
os.str();
397 const int numProcs = comm->getSize();
402 numGlobalElements_ = globalSum;
406 TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx <<
"globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum << suffix);
409 numLocalElements_ = numLocalElements;
410 indexBase_ = indexBase;
411 minAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
412 maxAllGID_ = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
413 minMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
414 maxMyGID_ = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
415 firstContiguousGID_ = minMyGID_;
416 lastContiguousGID_ = maxMyGID_;
418 distributed_ = (comm->getSize() > 1);
419 haveGlobalConstants_ =
true;
425 std::ostringstream os;
426 os << *prefix <<
"Done" << endl;
427 std::cerr << os.str();
431template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
433Map<LocalOrdinal, GlobalOrdinal, Node>::
434 initialNonuniformDebugCheck(
435 const char errorMessagePrefix[],
437 const size_t numLocalElements,
438 const global_ordinal_type indexBase,
439 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
const {
445 using Teuchos::broadcast;
446 using Teuchos::outArg;
448 using Teuchos::REDUCE_MAX;
449 using Teuchos::REDUCE_MIN;
450 using Teuchos::REDUCE_SUM;
451 using Teuchos::reduceAll;
452 using GO = global_ordinal_type;
454 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
481 "must provide the same number of global elements, even if "
483 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
484 "(which signals that the Map should compute the global "
485 "number of elements). Process 0 set numGlobalElements"
498 std::invalid_argument,
errorMessagePrefix <<
"All processes must provide the same indexBase argument. "
499 "Process 0 set indexBase = "
502 << comm->getRank() <<
" set indexBase=" <<
indexBase <<
". The min and max values over all "
510 std::invalid_argument,
512 "indices over all processes, "
515 "would like this constructor to compute numGlobalElements "
516 "for you, you may set numGlobalElements="
517 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() "
518 "on input. Please note that this is NOT necessarily -1.");
523template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
524void Map<LocalOrdinal, GlobalOrdinal, Node>::
525 initWithNonownedHostIndexList(
526 const char errorMessagePrefix[],
528 const Kokkos::View<
const global_ordinal_type*,
531 Kokkos::MemoryUnmanaged>& entryList_host,
532 const global_ordinal_type indexBase,
533 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
534 const Teuchos::RCP<Teuchos::ParameterList>& params) {
537 using Kokkos::LayoutLeft;
538 using Kokkos::subview;
540 using Kokkos::view_alloc;
541 using Kokkos::WithoutInitializing;
543 using Teuchos::broadcast;
544 using Teuchos::outArg;
546 using Teuchos::REDUCE_MAX;
547 using Teuchos::REDUCE_MIN;
548 using Teuchos::REDUCE_SUM;
549 using Teuchos::reduceAll;
553 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
557 << Teuchos::TypeNameTraits<execution_space>::name()
558 <<
" has not been initialized. "
559 "Please initialize it before creating a Map.")
618 numLocalElements_ = numLocalElements;
619 indexBase_ = indexBase;
621 minMyGID_ = indexBase_;
622 maxMyGID_ = indexBase_;
632 if (numLocalElements_ > 0) {
637 typename decltype(lgMap_)::non_const_type lgMap(view_alloc(
"lgMap", WithoutInitializing), numLocalElements_);
639 Kokkos::create_mirror_view(Kokkos::HostSpace(), lgMap);
647 firstContiguousGID_ = entryList_host[0];
648 lastContiguousGID_ = firstContiguousGID_ + 1;
656 lgMap_host[0] = firstContiguousGID_;
658 for (;
i < numLocalElements_; ++
i) {
662 if (lastContiguousGID_ !=
curGid)
break;
669 ++lastContiguousGID_;
671 --lastContiguousGID_;
677 minMyGID_ = firstContiguousGID_;
678 maxMyGID_ = lastContiguousGID_;
689 "Tpetra::Map noncontiguous constructor: "
690 "nonContigGids_host.extent(0) = "
692 <<
" != entryList_host.extent(0) - i = "
695 <<
". Please report this bug to the Tpetra developers.");
705 Kokkos::fence(
"Map::initWithNonownedHostIndexList");
718 for (;
i < numLocalElements_; ++
i) {
720 const LO
curLid =
static_cast<LO
>(
i);
728 if (curGid > maxMyGID_) {
735 Kokkos::deep_copy(execution_space(), lgMap, lgMap_host);
743 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
744 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
748 firstContiguousGID_ = indexBase_ + 1;
749 lastContiguousGID_ = indexBase_;
755 if (req) req->wait();
757 const bool callComputeGlobalConstants = params.get() ==
nullptr ||
758 params->get(
"compute global constants",
true);
760 if (callComputeGlobalConstants)
761 computeGlobalConstants();
763 distributed_ = params->get(
"distributed",
true) && (comm->getSize() > 1);
769template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
775 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
776 const Teuchos::RCP<Teuchos::ParameterList>&
params)
782 "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
785 std::unique_ptr<std::string>
prefix;
788 comm_.getRawPtr(),
"Map",
funcName);
789 std::ostringstream
os;
791 std::cerr <<
os.str();
796 Impl::checkMapInputArray(
"(GST, const GO[], LO, GO, comm)",
806 Kokkos::MemoryUnmanaged>
811 std::ostringstream
os;
813 std::cerr <<
os.str();
817template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
820 const Teuchos::ArrayView<const GlobalOrdinal>&
entryList,
822 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
823 const Teuchos::RCP<Teuchos::ParameterList>&
params)
828 const char*
funcName =
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
831 std::unique_ptr<std::string>
prefix;
834 comm_.getRawPtr(),
"Map",
funcName);
835 std::ostringstream
os;
837 std::cerr <<
os.str();
843 Impl::checkMapInputArray(
"(GST, ArrayView, GO, comm)",
854 Kokkos::MemoryUnmanaged>
859 std::ostringstream
os;
861 std::cerr <<
os.str();
865template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
868 const Kokkos::View<const GlobalOrdinal*, device_type>&
entryList,
870 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
871 const Teuchos::RCP<Teuchos::ParameterList>&
params)
875 using Kokkos::LayoutLeft;
876 using Kokkos::subview;
878 using Kokkos::view_alloc;
879 using Kokkos::WithoutInitializing;
882 using Teuchos::ArrayView;
884 using Teuchos::broadcast;
885 using Teuchos::outArg;
887 using Teuchos::REDUCE_MAX;
888 using Teuchos::REDUCE_MIN;
889 using Teuchos::REDUCE_SUM;
890 using Teuchos::reduceAll;
891 using Teuchos::typeName;
894 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
896 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
899 std::unique_ptr<std::string>
prefix;
902 comm_.getRawPtr(),
"Map",
funcName);
903 std::ostringstream
os;
905 std::cerr <<
os.str();
910 Impl::checkMapInputArray(
"(GST, Kokkos::View, GO, comm)",
912 static_cast<size_t>(
entryList.extent(0)),
939 std::shared_ptr<Details::CommRequest>
req;
975 minMyGID_ = indexBase_;
976 maxMyGID_ = indexBase_;
986 if (numLocalElements_ > 0) {
994 Kokkos::deep_copy(
typename device_type::execution_space(),
lgMap,
entryList);
1008 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1009 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1013 firstContiguousGID_ = indexBase_ + 1;
1014 lastContiguousGID_ = indexBase_;
1018 if (req) req->wait();
1020 const bool callComputeGlobalConstants = params.get() ==
nullptr ||
1021 params->get(
"compute global constants",
true);
1023 if (callComputeGlobalConstants)
1026 distributed_ = params->get(
"distributed",
true) && (comm->getSize() > 1);
1028 contiguous_ =
false;
1036 std::cerr <<
os.str();
1040template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1045 if (haveGlobalConstants_)
1071 Kokkos::View<GO*, Kokkos::HostSpace>
minMaxInput(Kokkos::ViewAllocateWithoutInitializing(
"minMaxInput"), 3);
1072 Kokkos::View<GO*, Kokkos::HostSpace>
minMaxOutput(Kokkos::ViewAllocateWithoutInitializing(
"minMaxOutput"), 3);
1074 minMaxInput[0] = std::numeric_limits<GO>::max() - minMyGID_;
1076 minMaxInput[2] = std::numeric_limits<GO>::max() -
static_cast<GO
>(numLocalElements_);
1080 minAllGID_ = std::numeric_limits<GO>::max() -
minMaxOutput[0];
1086 haveGlobalConstants_ =
true;
1089 minAllGID_ < indexBase_,
1090 std::invalid_argument,
1091 "Tpetra::Map constructor (noncontiguous): "
1092 "Minimum global ID = "
1093 << minAllGID_ <<
" over all process(es) is "
1094 "less than the given indexBase = "
1095 << indexBase_ <<
".");
1098template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1100 if (!Kokkos::is_initialized()) {
1101 std::ostringstream
os;
1102 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1103 "Kokkos::finalize() has been called. This is user error! There are "
1104 "two likely causes: "
1106 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1108 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1109 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1110 "or Tpetra::finalize()."
1113 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1116 this->getComm().getRawPtr());
1118 using ::Tpetra::Details::mpiIsFinalized;
1119 using ::Tpetra::Details::mpiIsInitialized;
1120 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1122 Teuchos::RCP<const Teuchos::Comm<int>> comm = this->getComm();
1123 if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
1124 mpiIsInitialized() && mpiIsFinalized()) {
1130 std::ostringstream
os;
1131 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1132 "MPI_Finalize() has been called. This is user error! There are "
1133 "two likely causes: "
1135 <<
" 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1137 <<
" 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1138 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1139 "Tpetra::finalize()."
1142 <<
"Don't do either of these! Please refer to GitHib Issue #2372."
1152template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1155 getComm().
is_null(), std::logic_error,
1156 "Tpetra::Map::isOneToOne: "
1157 "getComm() returns null. Please report this bug to the Tpetra "
1162 return directory_->isOneToOne(*
this);
1165template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1169 if (isContiguous()) {
1172 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1187template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1192 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
1194 if (isContiguous()) {
1206template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1209 auto const minGI = getMinGlobalIndex();
1210 auto const minLI = getMinLocalIndex();
1211 auto const maxLI = getMaxLocalIndex();
1212 if (isContiguous()) {
1213 for (
size_t i = 0;
i < numEntries;
i++) {
1226 for (
size_t i = 0; i < numEntries; i++) {
1227 auto lclInd = localIndices[i];
1228 if (lclInd < minLI || lclInd > maxLI) {
1231 globalIndices[i] = lgMapHost_[lclInd];
1237template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1247template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1251 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
1254template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1259template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1264template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1269 getMinGlobalIndex(), getMaxGlobalIndex(),
1270 firstContiguousGID_, lastContiguousGID_,
1271 getLocalNumElements(), isContiguous());
1274template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1277 using Teuchos::outArg;
1278 using Teuchos::REDUCE_MIN;
1279 using Teuchos::reduceAll;
1288 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1293 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1297 }
else if (isContiguous() && isUniform() &&
1298 map.isContiguous() &&
map.isUniform()) {
1303 }
else if (!isContiguous() && !
map.isContiguous() &&
1304 lgMap_.extent(0) != 0 &&
map.lgMap_.extent(0) != 0 &&
1305 lgMap_.data() ==
map.lgMap_.data()) {
1320 getGlobalNumElements() !=
map.getGlobalNumElements(), std::logic_error,
1321 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1322 "checked that this condition is true above, but it's false here. "
1323 "Please report this bug to the Tpetra developers.");
1327 (getLocalNumElements() ==
map.getLocalNumElements()) ? 1 : 0;
1334template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1337 using Teuchos::ArrayView;
1353 }
else if (getLocalNumElements() !=
map.getLocalNumElements()) {
1355 }
else if (getMinGlobalIndex() !=
map.getMinGlobalIndex() ||
1356 getMaxGlobalIndex() !=
map.getMaxGlobalIndex()) {
1359 if (isContiguous()) {
1360 if (
map.isContiguous()) {
1364 !this->isContiguous() ||
map.isContiguous(), std::logic_error,
1365 "Tpetra::Map::locallySameAs: BUG");
1367 const GO
minLhsGid = this->getMinGlobalIndex();
1377 }
else if (
map.isContiguous()) {
1379 this->isContiguous() || !
map.isContiguous(), std::logic_error,
1380 "Tpetra::Map::locallySameAs: BUG");
1391 }
else if (this->lgMap_.data() ==
map.lgMap_.data()) {
1394 return this->getLocalNumElements() ==
map.getLocalNumElements();
1396 if (this->getLocalNumElements() !=
map.getLocalNumElements()) {
1399 using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
1405 Kokkos::parallel_reduce(
1406 "Tpetra::Map::locallySameAs",
1407 range_type(0, this->getLocalNumElements()),
1420template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1431 auto lmap2 = this->getLocalMap();
1441 if (
lmap1.isContiguous() &&
lmap2.isContiguous()) {
1443 return ((
lmap1.getMinGlobalIndex() ==
lmap2.getMinGlobalIndex()) &&
1444 (
lmap1.getMaxGlobalIndex() <=
lmap2.getMaxGlobalIndex()));
1447 if (
lmap1.getMinGlobalIndex() <
lmap2.getMinGlobalIndex() ||
1448 lmap1.getMaxGlobalIndex() >
lmap2.getMaxGlobalIndex()) {
1456 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1460 Kokkos::parallel_reduce(
1471template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1474 using Teuchos::outArg;
1475 using Teuchos::REDUCE_MIN;
1476 using Teuchos::reduceAll;
1485 }
else if (getComm()->getSize() !=
map.getComm()->getSize()) {
1490 }
else if (getGlobalNumElements() !=
map.getGlobalNumElements()) {
1494 }
else if (haveGlobalConstants() &&
map.haveGlobalConstants() && (getMinAllGlobalIndex() !=
map.getMinAllGlobalIndex() || getMaxAllGlobalIndex() !=
map.getMaxAllGlobalIndex() || getIndexBase() !=
map.getIndexBase())) {
1498 }
else if (haveGlobalConstants() &&
map.haveGlobalConstants() && (isDistributed() !=
map.isDistributed())) {
1502 }
else if (isContiguous() && isUniform() &&
1503 map.isContiguous() &&
map.isUniform()) {
1532template <
class LO,
class GO,
class DT>
1535 FillLgMap(
const Kokkos::View<GO*, DT>&
lgMap,
1539 Kokkos::RangePolicy<LO, typename DT::execution_space>
1540 range(
static_cast<LO
>(0),
static_cast<LO
>(
lgMap.size()));
1541 Kokkos::parallel_for(
range, *
this);
1544 KOKKOS_INLINE_FUNCTION
void operator()(
const LO& lid)
const {
1545 lgMap_(lid) = startGid_ +
static_cast<GO
>(lid);
1549 const Kokkos::View<GO*, DT> lgMap_;
1555template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1556typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
1562 using lg_view_type =
typename const_lg_view_type::non_const_type;
1566 std::unique_ptr<std::string>
prefix;
1569 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1570 std::ostringstream
os;
1572 std::cerr <<
os.str();
1579 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1583 std::ostringstream
os;
1585 std::cerr <<
os.str();
1591 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1592 "mapping (lgMap_) should have been set up already for a "
1593 "noncontiguous Map. Please report this bug to the Tpetra "
1596 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1598 using Kokkos::view_alloc;
1599 using Kokkos::WithoutInitializing;
1602 std::ostringstream
os;
1604 std::cerr <<
os.str();
1609 std::ostringstream
os;
1611 std::cerr <<
os.str();
1614 auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(),
lgMap);
1631 std::ostringstream
os;
1633 std::cerr <<
os.str();
1638template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1639typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
1645 using lg_view_type =
typename const_lg_view_type::non_const_type;
1649 std::unique_ptr<std::string>
prefix;
1652 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1653 std::ostringstream
os;
1655 std::cerr <<
os.str();
1662 lgMap_.extent(0) == 0 && numLocalElements_ > 0;
1666 std::ostringstream
os;
1668 std::cerr <<
os.str();
1674 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1675 "mapping (lgMap_) should have been set up already for a "
1676 "noncontiguous Map. Please report this bug to the Tpetra "
1679 const LO
numElts =
static_cast<LO
>(getLocalNumElements());
1681 using Kokkos::view_alloc;
1682 using Kokkos::WithoutInitializing;
1685 std::ostringstream
os;
1687 std::cerr <<
os.str();
1696 std::ostringstream
os;
1698 std::cerr <<
os.str();
1703template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1704Teuchos::ArrayView<const GlobalOrdinal>
1711 (
void)this->getMyGlobalIndices();
1719 return Teuchos::ArrayView<const GO>(
1721 lgMapHost_.extent(0),
1722 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1725template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1727 return distributed_;
1730template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1732 using Teuchos::TypeNameTraits;
1733 std::ostringstream
os;
1735 os <<
"Tpetra::Map: {"
1742 os <<
", Global number of entries: " << getGlobalNumElements()
1743 <<
", Number of processes: " << getComm()->getSize()
1744 <<
", Uniform: " << (isUniform() ?
"true" :
"false")
1745 <<
", Contiguous: " << (isContiguous() ?
"true" :
"false")
1746 <<
", Distributed: " << (isDistributed() ?
"true" :
"false")
1755template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1759 using LO = local_ordinal_type;
1763 if (
vl < Teuchos::VERB_HIGH) {
1764 return std::string();
1766 auto outStringP = Teuchos::rcp(
new std::ostringstream());
1767 Teuchos::RCP<Teuchos::FancyOStream> outp =
1768 Teuchos::getFancyOStream(outStringP);
1769 Teuchos::FancyOStream& out = *outp;
1771 auto comm = this->getComm();
1772 const int myRank = comm->getRank();
1773 const int numProcs = comm->getSize();
1774 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1775 Teuchos::OSTab tab1(out);
1777 const LO numEnt =
static_cast<LO
>(this->getLocalNumElements());
1778 out <<
"My number of entries: " << numEnt << endl
1779 <<
"My minimum global index: " << this->getMinGlobalIndex() << endl
1780 <<
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
1782 if (vl == Teuchos::VERB_EXTREME) {
1783 out <<
"My global indices: [";
1784 const LO minLclInd = this->getMinLocalIndex();
1785 for (LO k = 0; k < numEnt; ++k) {
1786 out << minLclInd + this->getGlobalElement(k);
1787 if (k + 1 < numEnt) {
1795 return outStringP->str();
1798template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1801 const Teuchos::EVerbosityLevel
verbLevel)
const {
1803 using Teuchos::TypeNameTraits;
1804 using Teuchos::VERB_DEFAULT;
1805 using Teuchos::VERB_HIGH;
1806 using Teuchos::VERB_LOW;
1807 using Teuchos::VERB_NONE;
1810 const Teuchos::EVerbosityLevel
vl =
1820 auto comm = this->getComm();
1821 if (comm.is_null()) {
1824 const int myRank = comm->getRank();
1825 const int numProcs = comm->getSize();
1834 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
1840 tab0 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1841 out <<
"\"Tpetra::Map\":" <<
endl;
1842 tab1 = Teuchos::rcp(
new Teuchos::OSTab(
out));
1844 out <<
"Template parameters:" <<
endl;
1852 out <<
"Label: \"" << label <<
"\"" <<
endl;
1854 out <<
"Global number of entries: " << getGlobalNumElements() <<
endl
1855 <<
"Minimum global index: " << getMinAllGlobalIndex() <<
endl
1856 <<
"Maximum global index: " << getMaxAllGlobalIndex() <<
endl
1857 <<
"Index base: " << getIndexBase() <<
endl
1859 <<
"Uniform: " << (isUniform() ?
"true" :
"false") <<
endl
1860 <<
"Contiguous: " << (isContiguous() ?
"true" :
"false") <<
endl
1861 <<
"Distributed: " << (isDistributed() ?
"true" :
"false") <<
endl;
1866 const std::string
lclStr = this->localDescribeToString(
vl);
1871template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1872Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1890 return Teuchos::null;
1891 }
else if (
newComm->getSize() == 1) {
1904 newMap->indexBase_ = this->indexBase_;
1905 newMap->numGlobalElements_ = this->numLocalElements_;
1906 newMap->numLocalElements_ = this->numLocalElements_;
1907 newMap->minMyGID_ = this->minMyGID_;
1908 newMap->maxMyGID_ = this->maxMyGID_;
1909 newMap->minAllGID_ = this->minMyGID_;
1910 newMap->maxAllGID_ = this->maxMyGID_;
1911 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1912 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1913 newMap->haveGlobalConstants_ = this->haveGlobalConstants_;
1916 newMap->uniform_ = this->uniform_;
1917 newMap->contiguous_ = this->contiguous_;
1920 newMap->distributed_ =
false;
1921 newMap->lgMap_ = this->lgMap_;
1922 newMap->lgMapHost_ = this->lgMapHost_;
1923 newMap->glMap_ = this->glMap_;
1924 newMap->glMapHost_ = this->glMapHost_;
1944 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
1960 auto lgMap = this->getMyGlobalIndices();
1962 typename std::decay<
decltype(
lgMap.extent(0))>::type;
1964 static_cast<size_type
>(this->getLocalNumElements());
1965 using Teuchos::TypeNameTraits;
1967 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
1971 <<
this->getLocalNumElements() <<
". The latter, upon being "
1972 "cast to size_type = "
1975 <<
lclNumInds <<
". Please report this bug to the Tpetra "
1978 Teuchos::ArrayView<const GO>
lgMap = this->getLocalElementList();
1981 const GO
indexBase = this->getIndexBase();
1988template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1989Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
1992 using Teuchos::Comm;
1993 using Teuchos::null;
1994 using Teuchos::outArg;
1997 using Teuchos::REDUCE_MIN;
1998 using Teuchos::reduceAll;
2005 const int color = (numLocalElements_ == 0) ? 0 : 1;
2015 TEUCHOS_TEST_FOR_EXCEPTION(!haveGlobalConstants(), std::logic_error,
"\"Map::removeEmptyProcesses\" called, but global constants have not been computed with \"Map::computeGlobalConstants\".");
2024 map->indexBase_ = indexBase_;
2025 map->numGlobalElements_ = numGlobalElements_;
2026 map->numLocalElements_ = numLocalElements_;
2027 map->minMyGID_ = minMyGID_;
2028 map->maxMyGID_ = maxMyGID_;
2029 map->minAllGID_ = minAllGID_;
2030 map->maxAllGID_ = maxAllGID_;
2031 map->firstContiguousGID_ = firstContiguousGID_;
2032 map->lastContiguousGID_ = lastContiguousGID_;
2033 map->haveGlobalConstants_ = haveGlobalConstants_;
2037 map->uniform_ = uniform_;
2038 map->contiguous_ = contiguous_;
2053 if (!distributed_ ||
newComm->getSize() == 1) {
2054 map->distributed_ =
false;
2056 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2062 map->lgMap_ = lgMap_;
2063 map->lgMapHost_ = lgMapHost_;
2064 map->glMap_ = glMap_;
2065 map->glMapHost_ = glMapHost_;
2082template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2085 directory_.is_null(), std::logic_error,
2086 "Tpetra::Map::setupDirectory: "
2087 "The Directory is null. "
2088 "Please report this bug to the Tpetra developers.");
2092 if (!directory_->initialized()) {
2093 directory_->initialize(*
this);
2097template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2101 const Teuchos::ArrayView<int>&
PIDs,
2102 const Teuchos::ArrayView<LocalOrdinal>&
LIDs)
const {
2105 using Tpetra::Details::OrdinalTraits;
2106 using size_type = Teuchos::ArrayView<int>::size_type;
2110 std::unique_ptr<std::string>
prefix;
2113 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2114 std::ostringstream
os;
2118 std::cerr <<
os.str();
2127 if (getGlobalNumElements() == 0) {
2128 if (
GIDs.size() == 0) {
2130 std::ostringstream
os;
2131 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2132 std::cerr <<
os.str();
2137 std::ostringstream
os;
2138 os << *
prefix <<
"Done: Map is empty on all processes, "
2139 "so all output PIDs & LIDs are invalid (-1)."
2141 std::cerr <<
os.str();
2143 for (size_type
k = 0;
k <
PIDs.size(); ++
k) {
2146 for (size_type
k = 0;
k <
LIDs.size(); ++
k) {
2158 std::ostringstream
os;
2160 std::cerr <<
os.str();
2164 std::ostringstream
os;
2165 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2166 std::cerr <<
os.str();
2169 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs,
LIDs);
2171 std::ostringstream
os;
2172 os << *
prefix <<
"Done; getDirectoryEntries returned "
2179 std::cerr <<
os.str();
2184template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2188 const Teuchos::ArrayView<int>&
PIDs)
const {
2194 std::unique_ptr<std::string>
prefix;
2197 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2198 std::ostringstream
os;
2202 std::cerr <<
os.str();
2205 if (getGlobalNumElements() == 0) {
2206 if (
GIDs.size() == 0) {
2208 std::ostringstream
os;
2209 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2210 std::cerr <<
os.str();
2215 std::ostringstream
os;
2216 os << *
prefix <<
"Done: Map is empty on all processes, "
2217 "so all output PIDs are invalid (-1)."
2219 std::cerr <<
os.str();
2221 for (Teuchos::ArrayView<int>::size_type
k = 0;
k <
PIDs.size(); ++
k) {
2222 PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2233 std::ostringstream
os;
2235 std::cerr <<
os.str();
2239 std::ostringstream
os;
2240 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2241 std::cerr <<
os.str();
2244 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs);
2246 std::ostringstream
os;
2247 os << *
prefix <<
"Done; getDirectoryEntries returned "
2252 std::cerr <<
os.str();
2257template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2259 using exec_space =
typename Node::device_type::execution_space;
2260 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2266 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2279template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2280Teuchos::RCP<const Teuchos::Comm<int>>
2285template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2290 using Teuchos::outArg;
2291 using Teuchos::REDUCE_MIN;
2292 using Teuchos::reduceAll;
2295 std::unique_ptr<std::string>
prefix;
2298 comm_.getRawPtr(),
"Map",
"checkIsDist");
2299 std::ostringstream
os;
2301 std::cerr <<
os.str();
2304 bool global =
false;
2305 if (comm_->getSize() > 1) {
2309 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2322 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2323 if (allLocalRep != 1) {
2333 std::ostringstream os;
2334 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2336 std::cerr << os.str();
2343template <
class LocalOrdinal,
class GlobalOrdinal>
2344Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2346 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2347 typedef LocalOrdinal LO;
2348 typedef GlobalOrdinal GO;
2349 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2350 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2353template <
class LocalOrdinal,
class GlobalOrdinal>
2354Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2356 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2357 typedef LocalOrdinal LO;
2358 typedef GlobalOrdinal GO;
2359 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2360 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2363template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2364Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2366 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2369 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2371 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2374template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2375Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2377 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2381 const GlobalOrdinal indexBase = 0;
2384 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2387template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2388Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2390 const size_t localNumElements,
2391 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2394 const GlobalOrdinal indexBase = 0;
2396 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2399template <
class LocalOrdinal,
class GlobalOrdinal>
2400Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2402 const size_t localNumElements,
2403 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2404 typedef LocalOrdinal LO;
2405 typedef GlobalOrdinal GO;
2411template <
class LocalOrdinal,
class GlobalOrdinal>
2412Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2414 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2415 typedef LocalOrdinal LO;
2416 typedef GlobalOrdinal GO;
2422template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2423Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2425 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2429 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2433 const GlobalOrdinal indexBase = 0;
2435 return rcp(
new map_type(INV, elementList, indexBase, comm));
2438template <
class LO,
class GO,
class NT>
2439Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2441 using Details::verbosePrintArray;
2444 using Teuchos::Array;
2445 using Teuchos::ArrayView;
2451 const bool verbose = Details::Behavior::verbose(
"Map");
2452 std::unique_ptr<std::string> prefix;
2454 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2455 prefix = Details::createPrefix(
2456 comm.getRawPtr(),
"createOneToOne(Map)");
2457 std::ostringstream os;
2458 os << *prefix <<
"Start" << endl;
2461 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2462 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2463 const int myRank = M->getComm()->getRank();
2469 if (!M->isDistributed()) {
2476 const GST numGlobalEntries = M->getGlobalNumElements();
2477 if (M->isContiguous()) {
2478 const size_t numLocalEntries =
2479 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2481 std::ostringstream os;
2482 os << *prefix <<
"Input is locally replicated & contiguous; "
2484 << numLocalEntries << endl;
2488 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2489 M->getIndexBase(), M->getComm()));
2491 std::ostringstream os;
2492 os << *prefix <<
"Done" << endl;
2498 std::ostringstream os;
2499 os << *prefix <<
"Input is locally replicated & noncontiguous"
2503 ArrayView<const GO> myGids =
2504 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2506 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2509 std::ostringstream os;
2510 os << *prefix <<
"Done" << endl;
2515 }
else if (M->isContiguous()) {
2517 std::ostringstream os;
2518 os << *prefix <<
"Input is distributed & contiguous" << endl;
2526 std::ostringstream os;
2527 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2531 const size_t numMyElems = M->getLocalNumElements();
2532 ArrayView<const GO> myElems = M->getLocalElementList();
2533 Array<int> owner_procs_vec(numMyElems);
2536 std::ostringstream os;
2537 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2542 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2544 std::ostringstream os;
2545 os << *prefix <<
"getDirectoryEntries result: ";
2551 Array<GO> myOwned_vec(numMyElems);
2552 size_t numMyOwnedElems = 0;
2553 for (
size_t i = 0; i < numMyElems; ++i) {
2554 const GO GID = myElems[i];
2555 const int owner = owner_procs_vec[i];
2557 if (myRank == owner) {
2558 myOwned_vec[numMyOwnedElems++] = GID;
2561 myOwned_vec.resize(numMyOwnedElems);
2564 std::ostringstream os;
2565 os << *prefix <<
"Create Map: ";
2570 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2571 M->getIndexBase(), M->getComm()));
2573 std::ostringstream os;
2574 os << *prefix <<
"Done" << endl;
2581template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2582Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2585 using Details::Behavior;
2586 using Details::verbosePrintArray;
2589 using Teuchos::Array;
2590 using Teuchos::ArrayView;
2593 using Teuchos::toString;
2594 using LO = LocalOrdinal;
2595 using GO = GlobalOrdinal;
2598 const bool verbose = Behavior::verbose(
"Map");
2599 std::unique_ptr<std::string> prefix;
2601 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2602 prefix = Details::createPrefix(
2603 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2604 std::ostringstream os;
2605 os << *prefix <<
"Start" << endl;
2608 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2615 std::ostringstream os;
2616 os << *prefix <<
"Initialize Directory" << endl;
2619 directory.initialize(*M, tie_break);
2621 std::ostringstream os;
2622 os << *prefix <<
"Done initializing Directory" << endl;
2625 size_t numMyElems = M->getLocalNumElements();
2626 ArrayView<const GO> myElems = M->getLocalElementList();
2627 Array<int> owner_procs_vec(numMyElems);
2629 std::ostringstream os;
2630 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2635 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2637 std::ostringstream os;
2638 os << *prefix <<
"getDirectoryEntries result: ";
2644 const int myRank = M->getComm()->getRank();
2645 Array<GO> myOwned_vec(numMyElems);
2646 size_t numMyOwnedElems = 0;
2647 for (
size_t i = 0; i < numMyElems; ++i) {
2648 const GO GID = myElems[i];
2649 const int owner = owner_procs_vec[i];
2650 if (myRank == owner) {
2651 myOwned_vec[numMyOwnedElems++] = GID;
2654 myOwned_vec.resize(numMyOwnedElems);
2659 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2661 std::ostringstream os;
2662 os << *prefix <<
"Create Map: ";
2667 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2670 std::ostringstream os;
2671 os << *prefix <<
"Done" << endl;
2679template <
class p
ids_view_type>
2682 pids_view_type pids;
2684 SortToFit(
int _myRank, pids_view_type _pids)
2689 bool operator()(
size_t i,
size_t j)
const {
2690 if (pids(i) == myRank) {
2691 if (pids(j) == myRank)
2696 if (pids(j) == myRank)
2706template <
class LO,
class GO,
class NT>
2707Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2709 Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
constM =
M;
2719 const pid_type myRank =
M->getComm()->getRank();
2720 const size_t numMyElems =
M->getLocalNumElements();
2722 Kokkos::View<pid_type*, typename NT::memory_space> pids(
"pids",
numMyElems);
2724 auto gids_vec =
M->getLocalElementList();
2727 Kokkos::View<pid_type*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
pids_h(
pids_vec.data(),
pids_vec.size());
2728 Kokkos::deep_copy(pids,
pids_h);
2731 auto gids =
M->getMyGlobalIndicesDevice();
2733 auto policy = Kokkos::RangePolicy<size_t, typename NT::execution_space>(0,
numMyElems);
2735 Kokkos::View<size_t*, typename NT::memory_space> idx(Kokkos::ViewAllocateWithoutInitializing(
"idx"),
numMyElems);
2736 Kokkos::parallel_for(
2739 Tpetra::Details::SortToFit
cmp(myRank, pids);
2740 Kokkos::sort(
typename NT::execution_space(), idx,
cmp);
2742 Kokkos::View<GO*, typename NT::memory_space>
new_gids(Kokkos::ViewAllocateWithoutInitializing(
"new_gids"),
numMyElems);
2743 Kokkos::parallel_for(
2765#define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2767 template class Map<LO, GO, NODE>; \
2769 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2770 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2771 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2773 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2774 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2775 const size_t localNumElements, \
2776 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2778 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2779 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2780 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2782 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2783 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2784 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2786 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2787 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2789 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2790 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2791 const Tpetra::Details::TieBreak<LO, GO>& tie_break); \
2793 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2794 createOneToOneAndMakeOverlappingMapFitted(Teuchos::RCP<const Map<LO, GO, NODE>>& M);
2797#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2798 template Teuchos::RCP<const Map<LO, GO>> \
2799 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2801 template Teuchos::RCP<const Map<LO, GO>> \
2802 createContigMap<LO, GO>(global_size_t, size_t, \
2803 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2805 template Teuchos::RCP<const Map<LO, GO>> \
2806 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2807 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2809 template Teuchos::RCP<const Map<LO, GO>> \
2810 createUniformContigMap<LO, GO>(const global_size_t, \
2811 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::iallreduce.
Declaration of Tpetra::Details::initializeKokkos.
Declaration of Tpetra::Details::printOnce.
Declaration of the Tpetra::Map class and related nonmember constructors.
Stand-alone utility functions and macros.
Struct that holds views of the contents of a CrsMatrix.
Description of Tpetra's behavior.
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.
"Local" part of Map suitable for Kokkos kernels.
Interface for breaking ties in ownership.
Implement mapping from global ID to process ID and local ID.
A parallel distribution of indices over processes.
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.
::Tpetra::Details::FixedHashTable< global_ordinal_type, local_ordinal_type, device_type > global_to_local_table_type
Type of a mapping from global IDs to local IDs.
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.
Kokkos::View< const global_ordinal_type *, Kokkos::LayoutLeft, device_type > lgMap_
A mapping from local IDs to global IDs.
Map()
Default constructor (that does nothing).
GlobalOrdinal global_ordinal_type
The type of global indices.
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.
LO 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.
bool isCompatible(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is compatible with 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.
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.
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.
void computeGlobalConstants()
Compute global constants for the map. This method needs to be called collectively over all processes ...
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.
global_to_local_table_type glMap_
A mapping from global IDs to local IDs.
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.
typename Node::device_type device_type
This class' Kokkos::Device specialization.
Implementation details of Tpetra.
Nonmember function that computes a residual Computes R = B - A * X.
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).
std::unique_ptr< std::string > createPrefix(const int myRank, const char prefix[])
Create string prefix for each line of verbose output.
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.
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 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.
Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > createOneToOneAndMakeOverlappingMapFitted(Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &M)
Creates a one-to-one version of the given Map where each GID lives on only one process....
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...