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>>
1993 using Teuchos::Comm;
1994 using Teuchos::null;
1995 using Teuchos::outArg;
1998 using Teuchos::REDUCE_MIN;
1999 using Teuchos::reduceAll;
2006 const int color = (numLocalElements_ == 0) ? 0 : 1;
2016 TEUCHOS_TEST_FOR_EXCEPTION(!haveGlobalConstants(), std::logic_error,
"\"Map::removeEmptyProcesses\" called, but global constants have not been computed with \"Map::computeGlobalConstants\".");
2025 map->indexBase_ = indexBase_;
2026 map->numGlobalElements_ = numGlobalElements_;
2027 map->numLocalElements_ = numLocalElements_;
2028 map->minMyGID_ = minMyGID_;
2029 map->maxMyGID_ = maxMyGID_;
2030 map->minAllGID_ = minAllGID_;
2031 map->maxAllGID_ = maxAllGID_;
2032 map->firstContiguousGID_ = firstContiguousGID_;
2033 map->lastContiguousGID_ = lastContiguousGID_;
2034 map->haveGlobalConstants_ = haveGlobalConstants_;
2038 map->uniform_ = uniform_;
2039 map->contiguous_ = contiguous_;
2054 if (!distributed_ ||
newComm->getSize() == 1) {
2055 map->distributed_ =
false;
2057 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2063 map->lgMap_ = lgMap_;
2064 map->lgMapHost_ = lgMapHost_;
2065 map->glMap_ = glMap_;
2066 map->glMapHost_ = glMapHost_;
2083template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2086 directory_.is_null(), std::logic_error,
2087 "Tpetra::Map::setupDirectory: "
2088 "The Directory is null. "
2089 "Please report this bug to the Tpetra developers.");
2093 if (!directory_->initialized()) {
2094 directory_->initialize(*
this);
2098template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2102 const Teuchos::ArrayView<int>&
PIDs,
2103 const Teuchos::ArrayView<LocalOrdinal>&
LIDs)
const {
2106 using Tpetra::Details::OrdinalTraits;
2107 using size_type = Teuchos::ArrayView<int>::size_type;
2111 std::unique_ptr<std::string>
prefix;
2114 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2115 std::ostringstream
os;
2119 std::cerr <<
os.str();
2128 if (getGlobalNumElements() == 0) {
2129 if (
GIDs.size() == 0) {
2131 std::ostringstream
os;
2132 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2133 std::cerr <<
os.str();
2138 std::ostringstream
os;
2139 os << *
prefix <<
"Done: Map is empty on all processes, "
2140 "so all output PIDs & LIDs are invalid (-1)."
2142 std::cerr <<
os.str();
2144 for (size_type
k = 0;
k <
PIDs.size(); ++
k) {
2147 for (size_type
k = 0;
k <
LIDs.size(); ++
k) {
2159 std::ostringstream
os;
2161 std::cerr <<
os.str();
2165 std::ostringstream
os;
2166 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2167 std::cerr <<
os.str();
2170 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs,
LIDs);
2172 std::ostringstream
os;
2173 os << *
prefix <<
"Done; getDirectoryEntries returned "
2180 std::cerr <<
os.str();
2185template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2189 const Teuchos::ArrayView<int>&
PIDs)
const {
2195 std::unique_ptr<std::string>
prefix;
2198 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2199 std::ostringstream
os;
2203 std::cerr <<
os.str();
2206 if (getGlobalNumElements() == 0) {
2207 if (
GIDs.size() == 0) {
2209 std::ostringstream
os;
2210 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2211 std::cerr <<
os.str();
2216 std::ostringstream
os;
2217 os << *
prefix <<
"Done: Map is empty on all processes, "
2218 "so all output PIDs are invalid (-1)."
2220 std::cerr <<
os.str();
2222 for (Teuchos::ArrayView<int>::size_type
k = 0;
k <
PIDs.size(); ++
k) {
2223 PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid();
2234 std::ostringstream
os;
2236 std::cerr <<
os.str();
2240 std::ostringstream
os;
2241 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2242 std::cerr <<
os.str();
2245 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs);
2247 std::ostringstream
os;
2248 os << *
prefix <<
"Done; getDirectoryEntries returned "
2253 std::cerr <<
os.str();
2258template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2260 using exec_space =
typename Node::device_type::execution_space;
2261 if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
2267 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
2280template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2281Teuchos::RCP<const Teuchos::Comm<int>>
2286template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2291 using Teuchos::outArg;
2292 using Teuchos::REDUCE_MIN;
2293 using Teuchos::reduceAll;
2296 std::unique_ptr<std::string>
prefix;
2299 comm_.getRawPtr(),
"Map",
"checkIsDist");
2300 std::ostringstream
os;
2302 std::cerr <<
os.str();
2305 bool global =
false;
2306 if (comm_->getSize() > 1) {
2310 if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
2323 reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
2324 if (allLocalRep != 1) {
2334 std::ostringstream os;
2335 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2337 std::cerr << os.str();
2344template <
class LocalOrdinal,
class GlobalOrdinal>
2345Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2347 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2348 typedef LocalOrdinal LO;
2349 typedef GlobalOrdinal GO;
2350 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2351 return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
2354template <
class LocalOrdinal,
class GlobalOrdinal>
2355Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2357 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2358 typedef LocalOrdinal LO;
2359 typedef GlobalOrdinal GO;
2360 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2361 return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
2364template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2365Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2367 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2370 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
>(0);
2372 return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
2375template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2376Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2378 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2382 const GlobalOrdinal indexBase = 0;
2385 return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
2388template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2389Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2391 const size_t localNumElements,
2392 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2395 const GlobalOrdinal indexBase = 0;
2397 return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
2400template <
class LocalOrdinal,
class GlobalOrdinal>
2401Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2403 const size_t localNumElements,
2404 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2405 typedef LocalOrdinal LO;
2406 typedef GlobalOrdinal GO;
2412template <
class LocalOrdinal,
class GlobalOrdinal>
2413Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
2415 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2416 typedef LocalOrdinal LO;
2417 typedef GlobalOrdinal GO;
2423template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2424Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2426 const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
2430 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2434 const GlobalOrdinal indexBase = 0;
2436 return rcp(
new map_type(INV, elementList, indexBase, comm));
2439template <
class LO,
class GO,
class NT>
2440Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2442 using Details::verbosePrintArray;
2445 using Teuchos::Array;
2446 using Teuchos::ArrayView;
2452 const bool verbose = Details::Behavior::verbose(
"Map");
2453 std::unique_ptr<std::string> prefix;
2455 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2456 prefix = Details::createPrefix(
2457 comm.getRawPtr(),
"createOneToOne(Map)");
2458 std::ostringstream os;
2459 os << *prefix <<
"Start" << endl;
2462 const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2463 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid();
2464 const int myRank = M->getComm()->getRank();
2470 if (!M->isDistributed()) {
2477 const GST numGlobalEntries = M->getGlobalNumElements();
2478 if (M->isContiguous()) {
2479 const size_t numLocalEntries =
2480 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2482 std::ostringstream os;
2483 os << *prefix <<
"Input is locally replicated & contiguous; "
2485 << numLocalEntries << endl;
2489 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2490 M->getIndexBase(), M->getComm()));
2492 std::ostringstream os;
2493 os << *prefix <<
"Done" << endl;
2499 std::ostringstream os;
2500 os << *prefix <<
"Input is locally replicated & noncontiguous"
2504 ArrayView<const GO> myGids =
2505 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2507 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2510 std::ostringstream os;
2511 os << *prefix <<
"Done" << endl;
2516 }
else if (M->isContiguous()) {
2518 std::ostringstream os;
2519 os << *prefix <<
"Input is distributed & contiguous" << endl;
2527 std::ostringstream os;
2528 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2532 const size_t numMyElems = M->getLocalNumElements();
2533 ArrayView<const GO> myElems = M->getLocalElementList();
2534 Array<int> owner_procs_vec(numMyElems);
2537 std::ostringstream os;
2538 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2543 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2545 std::ostringstream os;
2546 os << *prefix <<
"getDirectoryEntries result: ";
2552 Array<GO> myOwned_vec(numMyElems);
2553 size_t numMyOwnedElems = 0;
2554 for (
size_t i = 0; i < numMyElems; ++i) {
2555 const GO GID = myElems[i];
2556 const int owner = owner_procs_vec[i];
2558 if (myRank == owner) {
2559 myOwned_vec[numMyOwnedElems++] = GID;
2562 myOwned_vec.resize(numMyOwnedElems);
2565 std::ostringstream os;
2566 os << *prefix <<
"Create Map: ";
2571 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2572 M->getIndexBase(), M->getComm()));
2574 std::ostringstream os;
2575 os << *prefix <<
"Done" << endl;
2582template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2583Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
2586 using Details::Behavior;
2587 using Details::verbosePrintArray;
2590 using Teuchos::Array;
2591 using Teuchos::ArrayView;
2594 using Teuchos::toString;
2595 using LO = LocalOrdinal;
2596 using GO = GlobalOrdinal;
2599 const bool verbose = Behavior::verbose(
"Map");
2600 std::unique_ptr<std::string> prefix;
2602 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2603 prefix = Details::createPrefix(
2604 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2605 std::ostringstream os;
2606 os << *prefix <<
"Start" << endl;
2609 const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
2616 std::ostringstream os;
2617 os << *prefix <<
"Initialize Directory" << endl;
2620 directory.initialize(*M, tie_break);
2622 std::ostringstream os;
2623 os << *prefix <<
"Done initializing Directory" << endl;
2626 size_t numMyElems = M->getLocalNumElements();
2627 ArrayView<const GO> myElems = M->getLocalElementList();
2628 Array<int> owner_procs_vec(numMyElems);
2630 std::ostringstream os;
2631 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2636 directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
2638 std::ostringstream os;
2639 os << *prefix <<
"getDirectoryEntries result: ";
2645 const int myRank = M->getComm()->getRank();
2646 Array<GO> myOwned_vec(numMyElems);
2647 size_t numMyOwnedElems = 0;
2648 for (
size_t i = 0; i < numMyElems; ++i) {
2649 const GO GID = myElems[i];
2650 const int owner = owner_procs_vec[i];
2651 if (myRank == owner) {
2652 myOwned_vec[numMyOwnedElems++] = GID;
2655 myOwned_vec.resize(numMyOwnedElems);
2660 Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
2662 std::ostringstream os;
2663 os << *prefix <<
"Create Map: ";
2668 RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
2671 std::ostringstream os;
2672 os << *prefix <<
"Done" << endl;
2680template <
class p
ids_view_type>
2683 pids_view_type pids;
2685 SortToFit(
int _myRank, pids_view_type _pids)
2690 bool operator()(
size_t i,
size_t j)
const {
2691 if (pids(i) == myRank) {
2692 if (pids(j) == myRank)
2697 if (pids(j) == myRank)
2707template <
class LO,
class GO,
class NT>
2708Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
2710 Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
constM =
M;
2720 const pid_type myRank =
M->getComm()->getRank();
2721 const size_t numMyElems =
M->getLocalNumElements();
2723 Kokkos::View<pid_type*, typename NT::memory_space> pids(
"pids",
numMyElems);
2725 auto gids_vec =
M->getLocalElementList();
2728 Kokkos::View<pid_type*, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>>
pids_h(
pids_vec.data(),
pids_vec.size());
2729 Kokkos::deep_copy(pids,
pids_h);
2732 auto gids =
M->getMyGlobalIndicesDevice();
2734 auto policy = Kokkos::RangePolicy<size_t, typename NT::execution_space>(0,
numMyElems);
2736 Kokkos::View<size_t*, typename NT::memory_space> idx(Kokkos::ViewAllocateWithoutInitializing(
"idx"),
numMyElems);
2737 Kokkos::parallel_for(
2740 Tpetra::Details::SortToFit
cmp(myRank, pids);
2741 Kokkos::sort(
typename NT::execution_space(), idx,
cmp);
2743 Kokkos::View<GO*, typename NT::memory_space>
new_gids(Kokkos::ViewAllocateWithoutInitializing(
"new_gids"),
numMyElems);
2744 Kokkos::parallel_for(
2766#define TPETRA_MAP_INSTANT(LO, GO, NODE) \
2768 template class Map<LO, GO, NODE>; \
2770 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2771 createLocalMapWithNode<LO, GO, NODE>(const size_t numElements, \
2772 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2774 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2775 createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2776 const size_t localNumElements, \
2777 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2779 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2780 createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList, \
2781 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2783 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2784 createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements, \
2785 const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \
2787 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2788 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M); \
2790 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2791 createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M, \
2792 const Tpetra::Details::TieBreak<LO, GO>& tie_break); \
2794 template Teuchos::RCP<const Map<LO, GO, NODE>> \
2795 createOneToOneAndMakeOverlappingMapFitted(Teuchos::RCP<const Map<LO, GO, NODE>>& M);
2798#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO) \
2799 template Teuchos::RCP<const Map<LO, GO>> \
2800 createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2802 template Teuchos::RCP<const Map<LO, GO>> \
2803 createContigMap<LO, GO>(global_size_t, size_t, \
2804 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2806 template Teuchos::RCP<const Map<LO, GO>> \
2807 createNonContigMap(const Teuchos::ArrayView<const GO>&, \
2808 const Teuchos::RCP<const Teuchos::Comm<int>>&); \
2810 template Teuchos::RCP<const Map<LO, GO>> \
2811 createUniformContigMap<LO, GO>(const global_size_t, \
2812 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...