47 #ifndef TPETRA_MAP_DEF_HPP 48 #define TPETRA_MAP_DEF_HPP 50 #include "Tpetra_Directory.hpp" 51 #include "Tpetra_Details_FixedHashTable.hpp" 52 #include "Tpetra_Details_gathervPrint.hpp" 54 #include "Teuchos_as.hpp" 58 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
61 comm_ (new
Teuchos::SerialComm<int> ()),
62 node_ (defaultArgNode<Node> ()),
64 numGlobalElements_ (0),
65 numLocalElements_ (0),
66 minMyGID_ (
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
67 maxMyGID_ (
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
68 minAllGID_ (
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
69 maxAllGID_ (
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
70 firstContiguousGID_ (
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
71 lastContiguousGID_ (
Tpetra::
Details::OrdinalTraits<GlobalOrdinal>::invalid ()),
75 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
78 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 GlobalOrdinal indexBase,
82 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
84 const Teuchos::RCP<Node> &node) :
88 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
91 using Teuchos::broadcast;
92 using Teuchos::outArg;
93 using Teuchos::reduceAll;
94 using Teuchos::REDUCE_MIN;
95 using Teuchos::REDUCE_MAX;
96 using Teuchos::typeName;
97 typedef GlobalOrdinal GO;
102 TEUCHOS_TEST_FOR_EXCEPTION
103 (! execution_space::is_initialized (), std::runtime_error,
104 "Tpetra::Map constructor: The Kokkos execution space has not been " 105 "initialized. Please initialize it before creating a Map.")
107 #ifdef HAVE_TPETRA_DEBUG 111 GST proc0NumGlobalElements = numGlobalElements;
112 broadcast<int, GST> (*comm_, 0, outArg (proc0NumGlobalElements));
113 GST minNumGlobalElements = numGlobalElements;
114 GST maxNumGlobalElements = numGlobalElements;
115 reduceAll<int, GST> (*comm, REDUCE_MIN, numGlobalElements, outArg (minNumGlobalElements));
116 reduceAll<int, GST> (*comm, REDUCE_MAX, numGlobalElements, outArg (maxNumGlobalElements));
117 TEUCHOS_TEST_FOR_EXCEPTION(
118 minNumGlobalElements != maxNumGlobalElements || numGlobalElements != minNumGlobalElements,
119 std::invalid_argument,
120 "Tpetra::Map constructor: All processes must provide the same number " 121 "of global elements. Process 0 set numGlobalElements = " 122 << proc0NumGlobalElements <<
". The calling process " 123 << comm->getRank () <<
" set numGlobalElements = " << numGlobalElements
124 <<
". The min and max values over all processes are " 125 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements <<
".");
127 GO proc0IndexBase = indexBase;
128 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
129 GO minIndexBase = indexBase;
130 GO maxIndexBase = indexBase;
131 reduceAll<int, GO> (*comm, REDUCE_MIN, indexBase, outArg (minIndexBase));
132 reduceAll<int, GO> (*comm, REDUCE_MAX, indexBase, outArg (maxIndexBase));
133 TEUCHOS_TEST_FOR_EXCEPTION(
134 minIndexBase != maxIndexBase || indexBase != minIndexBase,
135 std::invalid_argument,
136 "Tpetra::Map constructor: " 137 "All processes must provide the same indexBase argument. " 138 "Process 0 set indexBase = " << proc0IndexBase <<
". The calling " 139 "process " << comm->getRank () <<
" set indexBase = " << indexBase
140 <<
". The min and max values over all processes are " 141 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
143 #endif // HAVE_TPETRA_DEBUG 162 TEUCHOS_TEST_FOR_EXCEPTION(
163 (numGlobalElements < 1 && numGlobalElements != 0),
164 std::invalid_argument,
165 "Tpetra::Map constructor: numGlobalElements (= " 166 << numGlobalElements <<
") must be nonnegative.");
168 TEUCHOS_TEST_FOR_EXCEPTION(
169 numGlobalElements == GSTI, std::invalid_argument,
170 "Tpetra::Map constructor: You provided numGlobalElements = Teuchos::" 171 "OrdinalTraits<Tpetra::global_size_t>::invalid(). This version of the " 172 "constructor requires a valid value of numGlobalElements. You " 173 "probably mistook this constructor for the \"contiguous nonuniform\" " 174 "constructor, which can compute the global number of elements for you " 175 "if you set numGlobalElements to that value.");
177 size_t numLocalElements = 0;
178 if (lOrG == GloballyDistributed) {
193 const GST numProcs =
static_cast<GST
> (comm_->getSize ());
194 const GST myRank =
static_cast<GST
> (comm_->getRank ());
195 const GST quotient = numGlobalElements / numProcs;
196 const GST remainder = numGlobalElements - quotient * numProcs;
199 if (myRank < remainder) {
200 numLocalElements =
static_cast<size_t> (1) + static_cast<size_t> (quotient);
203 startIndex = as<GO> (myRank) * as<GO> (numLocalElements);
205 numLocalElements = as<size_t> (quotient);
206 startIndex = as<GO> (myRank) * as<GO> (numLocalElements) +
210 minMyGID_ = indexBase + startIndex;
211 maxMyGID_ = indexBase + startIndex + numLocalElements - 1;
212 minAllGID_ = indexBase;
213 maxAllGID_ = indexBase + numGlobalElements - 1;
214 distributed_ = (numProcs > 1);
217 numLocalElements = as<size_t> (numGlobalElements);
218 minMyGID_ = indexBase;
219 maxMyGID_ = indexBase + numGlobalElements - 1;
220 distributed_ =
false;
223 minAllGID_ = indexBase;
224 maxAllGID_ = indexBase + numGlobalElements - 1;
225 indexBase_ = indexBase;
226 numGlobalElements_ = numGlobalElements;
227 numLocalElements_ = numLocalElements;
228 firstContiguousGID_ = minMyGID_;
229 lastContiguousGID_ = maxMyGID_;
236 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
239 size_t numLocalElements,
240 GlobalOrdinal indexBase,
241 const Teuchos::RCP<
const Teuchos::Comm<int> > &comm,
242 const Teuchos::RCP<Node> &node) :
246 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
249 using Teuchos::broadcast;
250 using Teuchos::outArg;
251 using Teuchos::reduceAll;
252 using Teuchos::REDUCE_MIN;
253 using Teuchos::REDUCE_MAX;
254 using Teuchos::REDUCE_SUM;
256 typedef GlobalOrdinal GO;
261 TEUCHOS_TEST_FOR_EXCEPTION
262 (! execution_space::is_initialized (), std::runtime_error,
263 "Tpetra::Map constructor: The Kokkos execution space has not been " 264 "initialized. Please initialize it before creating a Map.")
266 #ifdef HAVE_TPETRA_DEBUG 269 const GST debugGlobalSum =
270 initialNonuniformDebugCheck (numGlobalElements, numLocalElements,
272 #endif // HAVE_TPETRA_DEBUG 286 scan<int, GO> (*comm, REDUCE_SUM, numLocalElements, outArg (scanResult));
287 const GO myOffset = scanResult - numLocalElements;
289 if (numGlobalElements != GSTI) {
290 numGlobalElements_ = numGlobalElements;
296 const int numProcs = comm->getSize ();
297 GST globalSum = scanResult;
299 broadcast (*comm, numProcs - 1, outArg (globalSum));
301 numGlobalElements_ = globalSum;
303 #ifdef HAVE_TPETRA_DEBUG 305 TEUCHOS_TEST_FOR_EXCEPTION(
306 globalSum != debugGlobalSum, std::logic_error,
307 "Tpetra::Map constructor (contiguous nonuniform): " 308 "globalSum = " << globalSum <<
" != debugGlobalSum = " << debugGlobalSum
309 <<
". Please report this bug to the Tpetra developers.");
310 #endif // HAVE_TPETRA_DEBUG 312 numLocalElements_ = numLocalElements;
313 indexBase_ = indexBase;
314 minAllGID_ = indexBase;
316 maxAllGID_ = indexBase + numGlobalElements_ - 1;
317 minMyGID_ = indexBase + myOffset;
318 maxMyGID_ = indexBase + myOffset + numLocalElements - 1;
319 firstContiguousGID_ = minMyGID_;
320 lastContiguousGID_ = maxMyGID_;
322 distributed_ = checkIsDist ();
328 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
332 const size_t numLocalElements,
333 const GlobalOrdinal indexBase,
334 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
const 336 #ifdef HAVE_TPETRA_DEBUG 337 using Teuchos::broadcast;
338 using Teuchos::outArg;
340 using Teuchos::REDUCE_MAX;
341 using Teuchos::REDUCE_MIN;
342 using Teuchos::REDUCE_SUM;
343 using Teuchos::reduceAll;
344 typedef GlobalOrdinal GO;
356 GST debugGlobalSum = 0;
357 reduceAll<int, GST> (*comm, REDUCE_SUM,
static_cast<GST
> (numLocalElements),
358 outArg (debugGlobalSum));
362 GST proc0NumGlobalElements = numGlobalElements;
363 broadcast<int, GST> (*comm_, 0, outArg (proc0NumGlobalElements));
364 GST minNumGlobalElements = numGlobalElements;
365 GST maxNumGlobalElements = numGlobalElements;
366 reduceAll<int, GST> (*comm, REDUCE_MIN, numGlobalElements,
367 outArg (minNumGlobalElements));
368 reduceAll<int, GST> (*comm, REDUCE_MAX, numGlobalElements,
369 outArg (maxNumGlobalElements));
370 TEUCHOS_TEST_FOR_EXCEPTION(
371 minNumGlobalElements != maxNumGlobalElements ||
372 numGlobalElements != minNumGlobalElements,
373 std::invalid_argument,
374 "Tpetra::Map constructor: All processes must provide the same number " 375 "of global elements. This is true even if that argument is Teuchos::" 376 "OrdinalTraits<global_size_t>::invalid() to signal that the Map should " 377 "compute the global number of elements. Process 0 set numGlobalElements" 378 " = " << proc0NumGlobalElements <<
". The calling process " 379 << comm->getRank () <<
" set numGlobalElements = " << numGlobalElements
380 <<
". The min and max values over all processes are " 381 << minNumGlobalElements <<
" resp. " << maxNumGlobalElements <<
".");
383 GO proc0IndexBase = indexBase;
384 broadcast<int, GO> (*comm_, 0, outArg (proc0IndexBase));
385 GO minIndexBase = indexBase;
386 GO maxIndexBase = indexBase;
387 reduceAll<int, GO> (*comm, REDUCE_MIN, indexBase, outArg (minIndexBase));
388 reduceAll<int, GO> (*comm, REDUCE_MAX, indexBase, outArg (maxIndexBase));
389 TEUCHOS_TEST_FOR_EXCEPTION(
390 minIndexBase != maxIndexBase || indexBase != minIndexBase,
391 std::invalid_argument,
392 "Tpetra::Map constructor: " 393 "All processes must provide the same indexBase argument. " 394 "Process 0 set indexBase = " << proc0IndexBase <<
". The calling " 395 "process " << comm->getRank () <<
" set indexBase = " << indexBase
396 <<
". The min and max values over all processes are " 397 << minIndexBase <<
" resp. " << maxIndexBase <<
".");
401 TEUCHOS_TEST_FOR_EXCEPTION
402 (numGlobalElements != GSTI && debugGlobalSum != numGlobalElements,
403 std::invalid_argument,
"Tpetra::Map constructor: The sum of each " 404 "process' number of indices over all processes, " << debugGlobalSum
405 <<
" != numGlobalElements = " << numGlobalElements <<
". If you " 406 "would like this constructor to compute numGlobalElements for you, " 407 "you may set numGlobalElements = " 408 "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() on input. " 409 "Please note that this is NOT necessarily -1.");
412 return debugGlobalSum;
414 return static_cast<global_size_t
> (0);
415 #endif // HAVE_TPETRA_DEBUG 418 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
420 Map<LocalOrdinal,GlobalOrdinal,Node>::
421 initWithNonownedHostIndexList (
const global_size_t numGlobalElements,
422 const Kokkos::View<
const GlobalOrdinal*,
425 Kokkos::MemoryUnmanaged>& entryList_host,
426 const GlobalOrdinal indexBase,
427 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
429 using Kokkos::LayoutLeft;
430 using Kokkos::subview;
433 using Teuchos::broadcast;
434 using Teuchos::outArg;
436 using Teuchos::REDUCE_MAX;
437 using Teuchos::REDUCE_MIN;
438 using Teuchos::REDUCE_SUM;
439 using Teuchos::reduceAll;
440 typedef LocalOrdinal LO;
441 typedef GlobalOrdinal GO;
446 TEUCHOS_TEST_FOR_EXCEPTION
447 (! execution_space::is_initialized (), std::runtime_error,
448 "Tpetra::Map constructor: The Kokkos execution space has not been " 449 "initialized. Please initialize it before creating a Map.")
462 const
size_t numLocalElements = static_cast<
size_t> (entryList_host.size ());
464 initialNonuniformDebugCheck (numGlobalElements, numLocalElements,
475 if (numGlobalElements != GSTI) {
476 numGlobalElements_ = numGlobalElements;
479 reduceAll<int, GST> (*comm, REDUCE_SUM,
480 static_cast<GST
> (numLocalElements),
481 outArg (numGlobalElements_));
507 numLocalElements_ = numLocalElements;
508 indexBase_ = indexBase;
510 minMyGID_ = indexBase_;
511 maxMyGID_ = indexBase_;
521 if (numLocalElements_ > 0) {
525 View<GO*, LayoutLeft, device_type> lgMap (
"lgMap", numLocalElements_);
526 auto lgMap_host = Kokkos::create_mirror_view (lgMap);
533 firstContiguousGID_ = entryList_host[0];
534 lastContiguousGID_ = firstContiguousGID_+1;
542 lgMap_host[0] = firstContiguousGID_;
544 for ( ; i < numLocalElements_; ++i) {
545 const GO curGid = entryList_host[i];
546 const LO curLid = as<LO> (i);
548 if (lastContiguousGID_ != curGid)
break;
554 lgMap_host[curLid] = curGid;
555 ++lastContiguousGID_;
557 --lastContiguousGID_;
562 minMyGID_ = firstContiguousGID_;
563 maxMyGID_ = lastContiguousGID_;
568 const std::pair<size_t, size_t> ncRange (i, entryList_host.dimension_0 ());
569 auto nonContigGids_host = subview (entryList_host, ncRange);
570 TEUCHOS_TEST_FOR_EXCEPTION
571 (static_cast<size_t> (nonContigGids_host.dimension_0 ()) !=
572 static_cast<size_t> (entryList_host.dimension_0 () - i),
573 std::logic_error,
"Tpetra::Map noncontiguous constructor: " 574 "nonContigGids_host.dimension_0() = " 575 << nonContigGids_host.dimension_0 ()
576 <<
" != entryList_host.dimension_0() - i = " 577 << (entryList_host.dimension_0 () - i) <<
" = " 578 << entryList_host.dimension_0 () <<
" - " << i
579 <<
". Please report this bug to the Tpetra developers.");
583 View<GO*, LayoutLeft, device_type>
584 nonContigGids (
"nonContigGids", nonContigGids_host.size ());
587 glMap_ = global_to_local_table_type (nonContigGids,
590 static_cast<LO> (i));
598 for ( ; i < numLocalElements_; ++i) {
599 const GO curGid = entryList_host[i];
600 const LO curLid = as<LO> (i);
601 lgMap_host[curLid] = curGid;
605 if (curGid < minMyGID_) {
608 if (curGid > maxMyGID_) {
619 lgMapHost_ = lgMap_host;
625 firstContiguousGID_ = indexBase_+1;
626 lastContiguousGID_ = indexBase_;
651 if (std::numeric_limits<GO>::is_signed) {
654 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
657 minMaxInput[0] = -minMyGID_;
658 minMaxInput[1] = maxMyGID_;
659 minMaxInput[2] = localDist;
665 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
666 minAllGID_ = -minMaxOutput[0];
667 maxAllGID_ = minMaxOutput[1];
668 const GO globalDist = minMaxOutput[2];
669 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
673 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
674 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
675 distributed_ = checkIsDist ();
680 TEUCHOS_TEST_FOR_EXCEPTION(
681 minAllGID_ < indexBase_,
682 std::invalid_argument,
683 "Tpetra::Map constructor (noncontiguous): " 684 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is " 685 "less than the given indexBase = " << indexBase_ <<
".");
691 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
692 Map<LocalOrdinal,GlobalOrdinal,Node>::
694 const GlobalOrdinal indexList[],
695 const LocalOrdinal indexListSize,
696 const GlobalOrdinal indexBase,
697 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
699 node_ (defaultArgNode<Node> ()),
701 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
704 TEUCHOS_TEST_FOR_EXCEPTION
705 (! execution_space::is_initialized (), std::runtime_error,
706 "Tpetra::Map constructor: The Kokkos execution space has not been " 707 "initialized. Please initialize it before creating a Map.")
712 const GlobalOrdinal*
const indsRaw = indexListSize == 0 ? NULL : indexList;
713 Kokkos::View<
const GlobalOrdinal*,
716 Kokkos::MemoryUnmanaged> inds (indsRaw, indexListSize);
717 initWithNonownedHostIndexList (numGlobalElements, inds, indexBase, comm);
720 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
723 const Teuchos::ArrayView<const GlobalOrdinal>& entryList,
724 const GlobalOrdinal indexBase,
725 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
726 const Teuchos::RCP<Node>& node) :
730 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
733 TEUCHOS_TEST_FOR_EXCEPTION
734 (! execution_space::is_initialized (), std::runtime_error,
735 "Tpetra::Map constructor: The Kokkos execution space has not been " 736 "initialized. Please initialize it before creating a Map.")
738 const size_t numLclInds =
static_cast<size_t> (entryList.size ());
743 const GlobalOrdinal*
const indsRaw =
744 numLclInds == 0 ? NULL : entryList.getRawPtr ();
745 Kokkos::View<
const GlobalOrdinal*,
748 Kokkos::MemoryUnmanaged> inds (indsRaw, numLclInds);
749 initWithNonownedHostIndexList (numGlobalElements, inds, indexBase, comm);
752 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
755 const Kokkos::View<const GlobalOrdinal*, device_type>& entryList,
756 const GlobalOrdinal indexBase,
757 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm) :
759 node_ (defaultArgNode<Node> ()),
761 directory_ (new
Directory<LocalOrdinal, GlobalOrdinal, Node> ())
763 using Kokkos::LayoutLeft;
764 using Kokkos::subview;
767 using Teuchos::ArrayView;
769 using Teuchos::broadcast;
770 using Teuchos::outArg;
772 using Teuchos::REDUCE_MAX;
773 using Teuchos::REDUCE_MIN;
774 using Teuchos::REDUCE_SUM;
775 using Teuchos::reduceAll;
776 using Teuchos::typeName;
777 typedef LocalOrdinal LO;
778 typedef GlobalOrdinal GO;
783 TEUCHOS_TEST_FOR_EXCEPTION
784 (! execution_space::is_initialized (), std::runtime_error,
785 "Tpetra::Map constructor: The Kokkos execution space has not been " 786 "initialized. Please initialize it before creating a Map.")
799 const size_t numLocalElements =
static_cast<size_t> (entryList.size ());
801 initialNonuniformDebugCheck (numGlobalElements, numLocalElements,
812 if (numGlobalElements != GSTI) {
813 numGlobalElements_ = numGlobalElements;
816 reduceAll<int, GST> (*comm, REDUCE_SUM,
817 static_cast<GST
> (numLocalElements),
818 outArg (numGlobalElements_));
844 numLocalElements_ = numLocalElements;
845 indexBase_ = indexBase;
847 minMyGID_ = indexBase_;
848 maxMyGID_ = indexBase_;
858 if (numLocalElements_ > 0) {
862 View<GO*, LayoutLeft, device_type> lgMap (
"lgMap", numLocalElements_);
863 auto lgMap_host = Kokkos::create_mirror_view (lgMap);
867 auto entryList_host = Kokkos::create_mirror_view (entryList);
870 firstContiguousGID_ = entryList_host[0];
871 lastContiguousGID_ = firstContiguousGID_+1;
879 lgMap_host[0] = firstContiguousGID_;
881 for ( ; i < numLocalElements_; ++i) {
882 const GO curGid = entryList_host[i];
883 const LO curLid = as<LO> (i);
885 if (lastContiguousGID_ != curGid)
break;
891 lgMap_host[curLid] = curGid;
892 ++lastContiguousGID_;
894 --lastContiguousGID_;
899 minMyGID_ = firstContiguousGID_;
900 maxMyGID_ = lastContiguousGID_;
905 const std::pair<size_t, size_t> ncRange (i, entryList.dimension_0 ());
906 auto nonContigGids = subview (entryList, ncRange);
907 TEUCHOS_TEST_FOR_EXCEPTION
908 (static_cast<size_t> (nonContigGids.dimension_0 ()) !=
909 static_cast<size_t> (entryList.dimension_0 () - i),
910 std::logic_error,
"Tpetra::Map noncontiguous constructor: " 911 "nonContigGids.dimension_0() = " 912 << nonContigGids.dimension_0 ()
913 <<
" != entryList.dimension_0() - i = " 914 << (entryList.dimension_0 () - i) <<
" = " 915 << entryList.dimension_0 () <<
" - " << i
916 <<
". Please report this bug to the Tpetra developers.");
921 static_cast<LO> (i));
929 for ( ; i < numLocalElements_; ++i) {
930 const GO curGid = entryList_host[i];
931 const LO curLid =
static_cast<LO
> (i);
932 lgMap_host[curLid] = curGid;
936 if (curGid < minMyGID_) {
939 if (curGid > maxMyGID_) {
950 lgMapHost_ = lgMap_host;
956 firstContiguousGID_ = indexBase_+1;
957 lastContiguousGID_ = indexBase_;
982 if (std::numeric_limits<GO>::is_signed) {
985 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
988 minMaxInput[0] = -minMyGID_;
989 minMaxInput[1] = maxMyGID_;
990 minMaxInput[2] = localDist;
996 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
997 minAllGID_ = -minMaxOutput[0];
998 maxAllGID_ = minMaxOutput[1];
999 const GO globalDist = minMaxOutput[2];
1000 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
1004 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
1005 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
1006 distributed_ = checkIsDist ();
1009 contiguous_ =
false;
1011 TEUCHOS_TEST_FOR_EXCEPTION(
1012 minAllGID_ < indexBase_,
1013 std::invalid_argument,
1014 "Tpetra::Map constructor (noncontiguous): " 1015 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is " 1016 "less than the given indexBase = " << indexBase_ <<
".");
1023 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1028 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1032 TEUCHOS_TEST_FOR_EXCEPTION(
1033 getComm ().is_null (), std::logic_error,
"Tpetra::Map::isOneToOne: " 1034 "getComm() returns null. Please report this bug to the Tpetra " 1039 return directory_->isOneToOne (*
this);
1043 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1048 if (isContiguous ()) {
1049 if (globalIndex < getMinGlobalIndex () ||
1050 globalIndex > getMaxGlobalIndex ()) {
1053 return static_cast<LocalOrdinal
> (globalIndex - getMinGlobalIndex ());
1055 else if (globalIndex >= firstContiguousGID_ &&
1056 globalIndex <= lastContiguousGID_) {
1057 return static_cast<LocalOrdinal
> (globalIndex - firstContiguousGID_);
1062 return glMap_.get (globalIndex);
1066 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1071 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1074 if (isContiguous ()) {
1075 return getMinGlobalIndex () + localIndex;
1082 return lgMapHost_[localIndex];
1086 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1091 if (localIndex < getMinLocalIndex () || localIndex > getMaxLocalIndex ()) {
1098 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1102 return this->getLocalElement (globalIndex) !=
1106 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1111 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1117 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1123 getMinGlobalIndex (), getMaxGlobalIndex (),
1124 firstContiguousGID_, lastContiguousGID_,
1125 getNodeNumElements (), isContiguous ());
1128 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1133 using Teuchos::outArg;
1134 using Teuchos::REDUCE_MIN;
1135 using Teuchos::reduceAll;
1145 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1156 else if (isContiguous () && isUniform () &&
1164 lgMap_.dimension_0 () != 0 && map.lgMap_.dimension_0 () != 0 &&
1165 lgMap_.ptr_on_device () == map.lgMap_.ptr_on_device ()) {
1179 TEUCHOS_TEST_FOR_EXCEPTION(
1181 "Tpetra::Map::isCompatible: There's a bug in this method. We've already " 1182 "checked that this condition is true above, but it's false here. " 1183 "Please report this bug to the Tpetra developers.");
1186 const int locallyCompat =
1189 int globallyCompat = 0;
1190 reduceAll<int, int> (*comm_, REDUCE_MIN, locallyCompat, outArg (globallyCompat));
1191 return (globallyCompat == 1);
1194 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1199 using Teuchos::ArrayView;
1200 typedef GlobalOrdinal GO;
1201 typedef typename ArrayView<const GO>::size_type size_type;
1224 if (isContiguous ()) {
1229 TEUCHOS_TEST_FOR_EXCEPTION(
1230 ! this->isContiguous () || map.
isContiguous (), std::logic_error,
1231 "Tpetra::Map::locallySameAs: BUG");
1233 const GO minLhsGid = this->getMinGlobalIndex ();
1234 const size_type numRhsElts = rhsElts.size ();
1235 for (size_type k = 0; k < numRhsElts; ++k) {
1236 const GO curLhsGid = minLhsGid +
static_cast<GO
> (k);
1237 if (curLhsGid != rhsElts[k]) {
1245 TEUCHOS_TEST_FOR_EXCEPTION(
1246 this->isContiguous () || ! map.
isContiguous (), std::logic_error,
1247 "Tpetra::Map::locallySameAs: BUG");
1248 ArrayView<const GO> lhsElts = this->getNodeElementList ();
1250 const size_type numLhsElts = lhsElts.size ();
1251 for (size_type k = 0; k < numLhsElts; ++k) {
1252 const GO curRhsGid = minRhsGid +
static_cast<GO
> (k);
1253 if (curRhsGid != lhsElts[k]) {
1259 else if (this->lgMap_.ptr_on_device () == map.lgMap_.ptr_on_device ()) {
1269 ArrayView<const GO> lhsElts = getNodeElementList ();
1275 return std::equal (lhsElts.begin (), lhsElts.end (), rhsElts.begin ());
1281 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1286 using Teuchos::outArg;
1287 using Teuchos::REDUCE_MIN;
1288 using Teuchos::reduceAll;
1298 else if (getComm ()->getSize () != map.
getComm ()->getSize ()) {
1321 else if (isContiguous () && isUniform () &&
1336 if (! Details::congruent (*comm_, * (map.
getComm ()))) {
1342 const int isSame_lcl = locallySameAs (map) ? 1 : 0;
1346 reduceAll<int, int> (*comm_, REDUCE_MIN, isSame_lcl, outArg (isSame_gbl));
1347 return isSame_gbl == 1;
1351 template <
class LO,
class GO,
class DT>
1354 FillLgMap (
const Kokkos::View<GO*, DT>& lgMap,
1355 const GO startGid) :
1356 lgMap_ (lgMap), startGid_ (startGid)
1358 Kokkos::RangePolicy<LO, typename DT::execution_space>
1359 range (static_cast<LO> (0), static_cast<LO> (lgMap.size ()));
1360 Kokkos::parallel_for (range, *
this);
1363 KOKKOS_INLINE_FUNCTION
void operator () (
const LO& lid)
const {
1364 lgMap_(lid) = startGid_ +
static_cast<GO
> (lid);
1368 const Kokkos::View<GO*, DT> lgMap_;
1375 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1376 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_type
1379 typedef LocalOrdinal LO;
1380 typedef GlobalOrdinal GO;
1383 typedef decltype (lgMap_) const_lg_view_type;
1384 typedef typename const_lg_view_type::non_const_type lg_view_type;
1389 const bool needToCreateLocalToGlobalMapping =
1390 lgMap_.dimension_0 () == 0 && numLocalElements_ > 0;
1392 if (needToCreateLocalToGlobalMapping) {
1393 #ifdef HAVE_TEUCHOS_DEBUG 1396 TEUCHOS_TEST_FOR_EXCEPTION( ! isContiguous(), std::logic_error,
1397 "Tpetra::Map::getNodeElementList: The local-to-global mapping (lgMap_) " 1398 "should have been set up already for a noncontiguous Map. Please report" 1399 " this bug to the Tpetra team.");
1400 #endif // HAVE_TEUCHOS_DEBUG 1402 const LO numElts =
static_cast<LO
> (getNodeNumElements ());
1404 lg_view_type lgMap (
"lgMap", numElts);
1405 FillLgMap<LO, GO, DT> fillIt (lgMap, minMyGID_);
1407 auto lgMapHost = Kokkos::create_mirror_view (lgMap);
1412 lgMapHost_ = lgMapHost;
1418 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1419 Teuchos::ArrayView<const GlobalOrdinal>
1422 typedef GlobalOrdinal GO;
1427 (void) this->getMyGlobalIndices ();
1430 const GO* lgMapHostRawPtr = lgMapHost_.ptr_on_device ();
1434 return Teuchos::ArrayView<const GO> (lgMapHostRawPtr,
1435 lgMapHost_.dimension_0 (),
1436 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1439 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1441 return distributed_;
1444 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1446 using Teuchos::TypeNameTraits;
1447 std::ostringstream os;
1449 os <<
"Tpetra::Map: {" 1450 <<
"LocalOrdinalType: " << TypeNameTraits<LocalOrdinal>::name ()
1451 <<
", GlobalOrdinalType: " << TypeNameTraits<GlobalOrdinal>::name ()
1452 <<
", NodeType: " << TypeNameTraits<Node>::name ();
1453 if (this->getObjectLabel () !=
"") {
1454 os <<
", Label: \"" << this->getObjectLabel () <<
"\"";
1456 os <<
", Global number of entries: " << getGlobalNumElements ()
1457 <<
", Number of processes: " << getComm ()->getSize ()
1458 <<
", Uniform: " << (isUniform () ?
"true" :
"false")
1459 <<
", Contiguous: " << (isContiguous () ?
"true" :
"false")
1460 <<
", Distributed: " << (isDistributed () ?
"true" :
"false")
1469 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1474 typedef LocalOrdinal LO;
1478 if (vl < Teuchos::VERB_HIGH) {
1479 return std::string ();
1481 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
1482 Teuchos::RCP<Teuchos::FancyOStream> outp =
1483 Teuchos::getFancyOStream (outStringP);
1484 Teuchos::FancyOStream& out = *outp;
1486 auto comm = this->getComm ();
1487 const int myRank = comm->getRank ();
1488 const int numProcs = comm->getSize ();
1489 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1490 Teuchos::OSTab tab1 (out);
1492 const LO numEnt =
static_cast<LO
> (this->getNodeNumElements ());
1493 out <<
"My number of entries: " << numEnt << endl
1494 <<
"My minimum global index: " << this->getMinGlobalIndex () << endl
1495 <<
"My maximum global index: " << this->getMaxGlobalIndex () << endl;
1497 if (vl == Teuchos::VERB_EXTREME) {
1498 out <<
"My global indices: [";
1499 const LO minLclInd = this->getMinLocalIndex ();
1500 for (LO k = 0; k < numEnt; ++k) {
1501 out << minLclInd + this->getGlobalElement (k);
1502 if (k + 1 < numEnt) {
1510 return outStringP->str ();
1513 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1515 Map<LocalOrdinal,GlobalOrdinal,Node>::
1516 describe (Teuchos::FancyOStream &out,
1517 const Teuchos::EVerbosityLevel verbLevel)
const 1519 using Teuchos::TypeNameTraits;
1520 using Teuchos::VERB_DEFAULT;
1521 using Teuchos::VERB_NONE;
1522 using Teuchos::VERB_LOW;
1523 using Teuchos::VERB_HIGH;
1525 typedef LocalOrdinal LO;
1526 typedef GlobalOrdinal GO;
1527 const Teuchos::EVerbosityLevel vl =
1528 (verbLevel == VERB_DEFAULT) ? VERB_LOW : verbLevel;
1530 if (vl == VERB_NONE) {
1537 auto comm = this->getComm ();
1538 if (comm.is_null ()) {
1541 const int myRank = comm->getRank ();
1542 const int numProcs = comm->getSize ();
1551 Teuchos::RCP<Teuchos::OSTab> tab0, tab1;
1557 tab0 = Teuchos::rcp (
new Teuchos::OSTab (out));
1558 out <<
"\"Tpetra::Map\":" << endl;
1559 tab1 = Teuchos::rcp (
new Teuchos::OSTab (out));
1561 out <<
"Template parameters:" << endl;
1562 Teuchos::OSTab tab2 (out);
1563 out <<
"LocalOrdinal: " << TypeNameTraits<LO>::name () << endl
1564 <<
"GlobalOrdinal: " << TypeNameTraits<GO>::name () << endl
1565 <<
"Node: " << TypeNameTraits<Node>::name () << endl;
1567 const std::string label = this->getObjectLabel ();
1569 out <<
"Label: \"" << label <<
"\"" << endl;
1571 out <<
"Global number of entries: " << getGlobalNumElements () << endl
1572 <<
"Minimum global index: " << getMinAllGlobalIndex () << endl
1573 <<
"Maximum global index: " << getMaxAllGlobalIndex () << endl
1574 <<
"Index base: " << getIndexBase () << endl
1575 <<
"Number of processes: " << numProcs << endl
1576 <<
"Uniform: " << (isUniform () ?
"true" :
"false") << endl
1577 <<
"Contiguous: " << (isContiguous () ?
"true" :
"false") << endl
1578 <<
"Distributed: " << (isDistributed () ?
"true" :
"false") << endl;
1582 if (vl >= VERB_HIGH) {
1583 const std::string lclStr = this->localDescribeToString (vl);
1588 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1589 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1596 typedef LocalOrdinal LO;
1597 typedef GlobalOrdinal GO;
1607 if (newComm.is_null () || newComm->getSize () < 1) {
1608 return Teuchos::null;
1610 else if (newComm->getSize () == 1) {
1615 RCP<map_type> newMap (
new map_type ());
1617 newMap->comm_ = newComm;
1618 newMap->node_ = this->node_;
1622 newMap->indexBase_ = this->indexBase_;
1623 newMap->numGlobalElements_ = this->numLocalElements_;
1624 newMap->numLocalElements_ = this->numLocalElements_;
1625 newMap->minMyGID_ = this->minMyGID_;
1626 newMap->maxMyGID_ = this->maxMyGID_;
1627 newMap->minAllGID_ = this->minMyGID_;
1628 newMap->maxAllGID_ = this->maxMyGID_;
1629 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1630 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1633 newMap->uniform_ = this->uniform_;
1634 newMap->contiguous_ = this->contiguous_;
1637 newMap->distributed_ =
false;
1638 newMap->lgMap_ = this->lgMap_;
1639 newMap->lgMapHost_ = this->lgMapHost_;
1640 newMap->glMap_ = this->glMap_;
1677 auto lgMap = this->getMyGlobalIndices ();
1678 typedef typename std::decay<decltype (lgMap.dimension_0 ()) >::type size_type;
1679 const size_type lclNumInds =
1680 static_cast<size_type
> (this->getNodeNumElements ());
1681 using Teuchos::TypeNameTraits;
1682 TEUCHOS_TEST_FOR_EXCEPTION
1683 (lgMap.dimension_0 () != lclNumInds, std::logic_error,
1684 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() " 1685 "has length " << lgMap.dimension_0 () <<
" (of type " <<
1686 TypeNameTraits<size_type>::name () <<
") != this->getNodeNumElements()" 1687 " = " << this->getNodeNumElements () <<
". The latter, upon being " 1688 "cast to size_type = " << TypeNameTraits<size_type>::name () <<
", " 1689 "becomes " << lclNumInds <<
". Please report this bug to the Tpetra " 1692 Teuchos::ArrayView<const GO> lgMap = this->getNodeElementList ();
1695 const GO indexBase = this->getIndexBase ();
1696 return rcp (
new map_type (RECOMPUTE, lgMap, indexBase, newComm));
1700 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1701 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1705 using Teuchos::Comm;
1706 using Teuchos::null;
1707 using Teuchos::outArg;
1710 using Teuchos::REDUCE_MIN;
1711 using Teuchos::reduceAll;
1718 const int color = (numLocalElements_ == 0) ? 0 : 1;
1723 RCP<const Comm<int> > newComm = comm_->split (color, 0);
1729 if (newComm.is_null ()) {
1734 RCP<Map> map = rcp (
new Map ());
1736 map->comm_ = newComm;
1737 map->indexBase_ = indexBase_;
1738 map->numGlobalElements_ = numGlobalElements_;
1739 map->numLocalElements_ = numLocalElements_;
1740 map->minMyGID_ = minMyGID_;
1741 map->maxMyGID_ = maxMyGID_;
1742 map->minAllGID_ = minAllGID_;
1743 map->maxAllGID_ = maxAllGID_;
1744 map->firstContiguousGID_= firstContiguousGID_;
1745 map->lastContiguousGID_ = lastContiguousGID_;
1749 map->uniform_ = uniform_;
1750 map->contiguous_ = contiguous_;
1765 if (! distributed_ || newComm->getSize () == 1) {
1766 map->distributed_ =
false;
1768 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
1769 int allProcsOwnAllGids = 0;
1770 reduceAll<int, int> (*newComm, REDUCE_MIN, iOwnAllGids, outArg (allProcsOwnAllGids));
1771 map->distributed_ = (allProcsOwnAllGids == 1) ?
false :
true;
1774 map->lgMap_ = lgMap_;
1775 map->lgMapHost_ = lgMapHost_;
1776 map->glMap_ = glMap_;
1794 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1798 TEUCHOS_TEST_FOR_EXCEPTION(
1799 directory_.is_null (), std::logic_error,
"Tpetra::Map::setupDirectory: " 1800 "The Directory is null. " 1801 "Please report this bug to the Tpetra developers.");
1805 if (! directory_->initialized ()) {
1806 directory_->initialize (*
this);
1810 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1812 Map<LocalOrdinal,GlobalOrdinal,Node>::
1813 getRemoteIndexList (
const Teuchos::ArrayView<const GlobalOrdinal>& GIDs,
1814 const Teuchos::ArrayView<int>& PIDs,
1815 const Teuchos::ArrayView<LocalOrdinal>& LIDs)
const 1818 typedef Teuchos::ArrayView<int>::size_type size_type;
1826 if (getGlobalNumElements () == 0) {
1827 if (GIDs.size () == 0) {
1830 for (size_type k = 0; k < PIDs.size (); ++k) {
1831 PIDs[k] = OrdinalTraits<int>::invalid ();
1833 for (size_type k = 0; k < LIDs.size (); ++k) {
1834 LIDs[k] = OrdinalTraits<LocalOrdinal>::invalid ();
1844 return directory_->getDirectoryEntries (*
this, GIDs, PIDs, LIDs);
1847 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1851 const Teuchos::ArrayView<int> & PIDs)
const 1853 if (getGlobalNumElements () == 0) {
1854 if (GIDs.size () == 0) {
1858 for (Teuchos::ArrayView<int>::size_type k = 0; k < PIDs.size (); ++k) {
1869 return directory_->getDirectoryEntries (*
this, GIDs, PIDs);
1872 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1873 Teuchos::RCP<const Teuchos::Comm<int> >
1878 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1884 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1887 using Teuchos::outArg;
1888 using Teuchos::REDUCE_MIN;
1889 using Teuchos::reduceAll;
1891 bool global =
false;
1892 if (comm_->getSize () > 1) {
1896 if (numGlobalElements_ == as<global_size_t> (numLocalElements_)) {
1909 reduceAll<int, int> (*comm_, REDUCE_MIN, localRep, outArg (allLocalRep));
1910 if (allLocalRep != 1) {
1923 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1928 using Teuchos::ArrayView;
1929 typedef GlobalOrdinal GO;
1930 typedef typename ArrayView<const GO>::size_type size_type;
1933 if (&map1 == &map2) {
1944 const size_type numInds_map1 =
1954 if (numInds_map1 > inds_map2.size ()) {
1962 for (size_type k = 0; k < numInds_map1; ++k) {
1963 const GO inds_map1_k =
static_cast<GO
> (k) + minInd_map1;
1964 if (inds_map1_k != inds_map2[k]) {
1974 if (numInds_map1 > inds_map2.size ()) {
1981 for (size_type k = 0; k < numInds_map1; ++k) {
1982 if (inds_map1[k] != inds_map2[k]) {
1996 template <
class LocalOrdinal,
class GlobalOrdinal>
1997 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal> >
1999 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2001 typedef LocalOrdinal LO;
2002 typedef GlobalOrdinal GO;
2003 typedef typename ::Tpetra::Map<LO, GO>::node_type NT;
2004 return createLocalMapWithNode<LO, GO, NT> (numElements, comm);
2007 template <
class LocalOrdinal,
class GlobalOrdinal>
2008 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal> >
2010 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2012 typedef LocalOrdinal LO;
2013 typedef GlobalOrdinal GO;
2014 typedef typename ::Tpetra::Map<LO, GO>::node_type NT;
2015 return createUniformContigMapWithNode<LO, GO, NT> (numElements, comm);
2018 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2019 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2021 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
2022 const Teuchos::RCP<Node>& node)
2026 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2028 if (node.is_null ()) {
2029 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed));
2032 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed, node));
2036 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2037 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2039 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
2040 const Teuchos::RCP<Node>& node)
2045 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2048 if (node.is_null ()) {
2049 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated));
2052 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated, node));
2056 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2057 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2059 const size_t localNumElements,
2060 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
2061 const Teuchos::RCP<Node>& node)
2065 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2067 return rcp (
new map_type (numElements, localNumElements, indexBase, comm, node));
2070 template <
class LocalOrdinal,
class GlobalOrdinal>
2071 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal> >
2073 const size_t localNumElements,
2074 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2076 typedef LocalOrdinal LO;
2077 typedef GlobalOrdinal GO;
2080 return Tpetra::createContigMapWithNode<LO, GO, NT> (numElements, localNumElements, comm);
2084 template <
class LocalOrdinal,
class GlobalOrdinal>
2085 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal> >
2087 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2089 typedef LocalOrdinal LO;
2090 typedef GlobalOrdinal GO;
2093 return Tpetra::createNonContigMapWithNode<LO, GO, NT> (elementList, comm);
2097 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2098 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2100 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
2101 const Teuchos::RCP<Node>& node)
2110 const GlobalOrdinal indexBase = 0;
2112 if (node.is_null ()) {
2113 return rcp (
new map_type (INV, elementList, indexBase, comm));
2116 return rcp (
new map_type (INV, elementList, indexBase, comm, node));
2120 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2121 Teuchos::RCP< const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2124 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm,
2125 const Teuchos::RCP<Node>& node)
2127 Teuchos::RCP< Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> > map;
2128 int sumOfWeights, elemsLeft, localNumElements;
2129 const int numImages = comm->getSize();
2130 const int myImageID = comm->getRank();
2131 Teuchos::reduceAll<int>(*comm,Teuchos::REDUCE_SUM,myWeight,Teuchos::outArg(sumOfWeights));
2132 const double myShare = ((double)myWeight) / ((double)sumOfWeights);
2133 localNumElements = (int)std::floor( myShare * ((
double)numElements) );
2135 Teuchos::reduceAll<int>(*comm,Teuchos::REDUCE_SUM,localNumElements,Teuchos::outArg(elemsLeft));
2136 elemsLeft = numElements - elemsLeft;
2139 TEUCHOS_TEST_FOR_EXCEPT(elemsLeft < -numImages || numImages < elemsLeft);
2140 if (elemsLeft < 0) {
2142 if (myImageID >= numImages-elemsLeft) --localNumElements;
2144 else if (elemsLeft > 0) {
2146 if (myImageID < elemsLeft) ++localNumElements;
2149 return createContigMapWithNode<LocalOrdinal,GlobalOrdinal,Node>(numElements,localNumElements,comm,node);
2153 template<
class LO,
class GO,
class NT>
2154 Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >
2157 using Teuchos::Array;
2158 using Teuchos::ArrayView;
2164 const int myRank = M->getComm ()->getRank ();
2170 if (! M->isDistributed ()) {
2177 const GST numGlobalEntries = M->getGlobalNumElements ();
2178 if (M->isContiguous ()) {
2179 const size_t numLocalEntries =
2180 (myRank == 0) ? as<size_t> (numGlobalEntries) :
static_cast<size_t> (0);
2181 return rcp (
new map_type (numGlobalEntries, numLocalEntries,
2182 M->getIndexBase (), M->getComm (),
2186 ArrayView<const GO> myGids =
2187 (myRank == 0) ? M->getNodeElementList () : Teuchos::null;
2188 return rcp (
new map_type (GINV, myGids (), M->getIndexBase (),
2189 M->getComm (), M->getNode ()));
2193 else if (M->isContiguous ()) {
2200 const size_t numMyElems = M->getNodeNumElements ();
2201 ArrayView<const GO> myElems = M->getNodeElementList ();
2202 Array<int> owner_procs_vec (numMyElems);
2206 Array<GO> myOwned_vec (numMyElems);
2207 size_t numMyOwnedElems = 0;
2208 for (
size_t i = 0; i < numMyElems; ++i) {
2209 const GO GID = myElems[i];
2210 const int owner = owner_procs_vec[i];
2212 if (myRank == owner) {
2213 myOwned_vec[numMyOwnedElems++] = GID;
2216 myOwned_vec.resize (numMyOwnedElems);
2218 return rcp (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2219 M->getComm (), M->getNode ()));
2223 template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2224 Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2228 using Teuchos::Array;
2229 using Teuchos::ArrayView;
2231 typedef LocalOrdinal LO;
2232 typedef GlobalOrdinal GO;
2234 int myID = M->
getComm()->getRank();
2243 size_t numMyElems = M->getNodeNumElements ();
2244 ArrayView<const GO> myElems = M->getNodeElementList ();
2245 Array<int> owner_procs_vec (numMyElems);
2249 Array<GO> myOwned_vec (numMyElems);
2250 size_t numMyOwnedElems = 0;
2251 for (
size_t i = 0; i < numMyElems; ++i) {
2252 GO GID = myElems[i];
2253 int owner = owner_procs_vec[i];
2255 if (myID == owner) {
2256 myOwned_vec[numMyOwnedElems++] = GID;
2259 myOwned_vec.resize (numMyOwnedElems);
2265 return rcp (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2266 M->getComm (), M->getNode ()));
2276 #define TPETRA_MAP_INSTANT(LO,GO,NODE) \ 2278 template class Map< LO , GO , NODE >; \ 2280 template Teuchos::RCP< const Map<LO,GO,NODE> > \ 2281 createLocalMapWithNode<LO,GO,NODE> (const size_t numElements, \ 2282 const Teuchos::RCP< const Teuchos::Comm< int > >& comm, \ 2283 const Teuchos::RCP< NODE >& node); \ 2285 template Teuchos::RCP< const Map<LO,GO,NODE> > \ 2286 createContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \ 2287 const size_t localNumElements, \ 2288 const Teuchos::RCP< const Teuchos::Comm< int > >& comm, \ 2289 const Teuchos::RCP< NODE > &node); \ 2291 template Teuchos::RCP< const Map<LO,GO,NODE> > \ 2292 createNonContigMapWithNode(const Teuchos::ArrayView<const GO> &elementList, \ 2293 const Teuchos::RCP<const Teuchos::Comm<int> > &comm, \ 2294 const Teuchos::RCP<NODE> &node); \ 2296 template Teuchos::RCP< const Map<LO,GO,NODE> > \ 2297 createUniformContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \ 2298 const Teuchos::RCP< const Teuchos::Comm< int > >& comm, \ 2299 const Teuchos::RCP< NODE > &node); \ 2301 template Teuchos::RCP< const Map<LO,GO,NODE> > \ 2302 createWeightedContigMapWithNode<LO,GO,NODE> (const int thisNodeWeight, \ 2303 const global_size_t numElements, \ 2304 const Teuchos::RCP< const Teuchos::Comm< int > >& comm, \ 2305 const Teuchos::RCP< NODE >& node); \ 2307 template Teuchos::RCP<const Map<LO,GO,NODE> > \ 2308 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M); \ 2310 template Teuchos::RCP<const Map<LO,GO,NODE> > \ 2311 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M, \ 2312 const Tpetra::Details::TieBreak<LO,GO>& tie_break); \ 2315 Details::isLocallyFitted (const Tpetra::Map<LO, GO, NODE>& map1, \ 2316 const Tpetra::Map<LO, GO, NODE>& map2); 2320 #define TPETRA_MAP_INSTANT_DEFAULTNODE(LO,GO) \ 2321 template Teuchos::RCP< const Map<LO,GO> > \ 2322 createLocalMap<LO,GO>( const size_t, const Teuchos::RCP< const Teuchos::Comm< int > > &); \ 2324 template Teuchos::RCP< const Map<LO,GO> > \ 2325 createContigMap<LO,GO>( global_size_t, size_t, \ 2326 const Teuchos::RCP< const Teuchos::Comm< int > > &); \ 2328 template Teuchos::RCP< const Map<LO,GO> > \ 2329 createNonContigMap(const Teuchos::ArrayView<const GO> &, \ 2330 const Teuchos::RCP<const Teuchos::Comm<int> > &); \ 2332 template Teuchos::RCP< const Map<LO,GO> > \ 2333 createUniformContigMap<LO,GO>( const global_size_t, \ 2334 const Teuchos::RCP< const Teuchos::Comm< int > > &); \ 2336 #endif // TPETRA_MAP_DEF_HPP Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createUniformContigMapWithNode(const global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=Teuchos::null)
Non-member constructor for a uniformly distributed, contiguous Map with a user-specified Kokkos Node...
Interface for breaking ties in ownership.
GlobalOrdinal getMaxAllGlobalIndex() const
The maximum global index over all processes in the communicator.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
GlobalOrdinal getMinAllGlobalIndex() const
The minimum global index over all processes in the communicator.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createLocalMapWithNode(const size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=Teuchos::null)
Nonmember constructor for a locally replicated Map with a specified Kokkos Node.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createWeightedContigMapWithNode(const int thisNodeWeight, const global_size_t numElements, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=Teuchos::null)
Non-member constructor for a contiguous Map with user-defined weights and a user-specified Kokkos Nod...
bool isContiguous() const
True if this Map is distributed contiguously, else false.
void deep_copy(MultiVector< DS, DL, DG, DN, dstClassic > &dst, const MultiVector< SS, SL, SG, SN, srcClassic > &src)
Copy the contents of the MultiVector src into dst.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
LookupStatus getDirectoryEntries(const map_type &map, const Teuchos::ArrayView< const GlobalOrdinal > &globalIDs, const Teuchos::ArrayView< int > &nodeIDs) const
Given a global ID list, return the list of their owning process IDs.
"Local" part of Map suitable for Kokkos kernels.
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
Implementation details of Tpetra.
void gathervPrint(std::ostream &out, const std::string &s, const Teuchos::Comm< int > &comm)
On Process 0 in the given communicator, print strings from each process in that communicator, in rank order.
size_t global_size_t
Global size_t object.
Traits class for "invalid" (flag) values of integer types that Tpetra uses as local ordinals or globa...
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createOneToOne(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &M)
Creates a one-to-one version of the given Map where each GID is owned by only one process...
bool isDistributed() const
Whether this Map is globally distributed or locally replicated.
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, const Teuchos::RCP< Node > &node=defaultArgNode< Node >())
Non-member constructor for a (potentially) non-uniformly distributed, contiguous Map with a user-spec...
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...
GlobalOrdinal getIndexBase() const
The index base for this Map.
node_type ::device_type device_type
The Kokkos device type over which to allocate Views and perform work.
Teuchos::ArrayView< const GlobalOrdinal > getNodeElementList() const
Return a NONOWNING view of the global indices owned by this process.
GlobalOrdinal getMinGlobalIndex() const
The minimum global index owned by the calling process.
Node node_type
The type of the Kokkos Node.
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 with the default...
bool isLocallyFitted(const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map1, const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &map2)
Is map1 locally fitted to map2?
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.
Describes a parallel distribution of objects over processes.
Implement mapping from global ID to process ID and local ID.
Stand-alone utility functions and macros.
void initialize(const map_type &map)
Initialize the Directory with its Map.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal > > createNonContigMap(const Teuchos::ArrayView< const GlobalOrdinal > &elementList, const Teuchos::RCP< const Teuchos::Comm< int > > &comm)
Non-member constructor for a non-contiguous Map with the default Kokkos Node.
LocalGlobal
Enum for local versus global allocation of Map entries.
bool isUniform() const
Whether the range of global indices is uniform.
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > createNonContigMapWithNode(const Teuchos::ArrayView< const GlobalOrdinal > &elementList, const Teuchos::RCP< const Teuchos::Comm< int > > &comm, const Teuchos::RCP< Node > &node=Teuchos::null)
Non-member constructor for a non-contiguous Map with a user-specified Kokkos Node.
GlobalOrdinal getMaxGlobalIndex() const
The maximum global index owned by the calling process.
Map()
Default constructor (that does nothing).