15#ifndef TPETRA_MAP_DEF_HPP 
   16#define TPETRA_MAP_DEF_HPP 
   23#include "Teuchos_as.hpp" 
   24#include "Teuchos_TypeNameTraits.hpp" 
   25#include "Teuchos_CommHelpers.hpp" 
   27#include "Tpetra_Directory.hpp"   
   29#include "Tpetra_Details_FixedHashTable.hpp" 
   34#include "Tpetra_Details_mpiIsInitialized.hpp" 
   41void checkMapInputArray(
const char ctorName[],
 
   42                        const void* indexList,
 
   43                        const size_t indexListSize,
 
   44                        const Teuchos::Comm<int>* 
const comm) {
 
   47  const bool debug = Behavior::debug(
"Map");
 
   50    using Teuchos::outArg;
 
   51    using Teuchos::REDUCE_MIN;
 
   52    using Teuchos::reduceAll;
 
   54    const int myRank   = comm == 
nullptr ? 0 : comm->getRank();
 
   55    const bool verbose = Behavior::verbose(
"Map");
 
   56    std::ostringstream lclErrStrm;
 
   59    if (indexListSize != 0 && indexList == 
nullptr) {
 
   62        lclErrStrm << 
"Proc " << myRank << 
": indexList is null, " 
   64                   << indexListSize << 
" != 0." << endl;
 
   68    reduceAll(*comm, REDUCE_MIN, lclSuccess, outArg(gblSuccess));
 
   69    if (gblSuccess != 1) {
 
   70      std::ostringstream gblErrStrm;
 
   71      gblErrStrm << 
"Tpetra::Map constructor " << ctorName << 
" detected a problem with the input array " 
   72                                                              "(raw array, Teuchos::ArrayView, or Kokkos::View) " 
   76        using ::Tpetra::Details::gathervPrint;
 
   79      TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument, gblErrStrm.str());
 
   84template <
class LocalOrdinal, 
class GlobalOrdinal, 
class ViewType>
 
   85void computeConstantsOnDevice(
const ViewType& entryList, GlobalOrdinal& minMyGID, GlobalOrdinal& maxMyGID, GlobalOrdinal& firstContiguousGID, GlobalOrdinal& lastContiguousGID_val, LocalOrdinal& lastContiguousGID_loc) {
 
   86  using LO                  = LocalOrdinal;
 
   87  using GO                  = GlobalOrdinal;
 
   88  using exec_space          = 
typename ViewType::device_type::execution_space;
 
   89  using range_policy        = Kokkos::RangePolicy<exec_space, Kokkos::IndexType<LO>>;
 
   90  const LO numLocalElements = entryList.extent(0);
 
   94  typedef typename Kokkos::MinLoc<LO, GO>::value_type minloc_type;
 
  100  Kokkos::parallel_reduce(
 
  101      range_policy(0, numLocalElements), KOKKOS_LAMBDA(
const LO& i, GO& l_myMin, GO& l_myMax, GO& l_firstCont, minloc_type& l_lastCont) {
 
  102        GO entry_0 = entryList[0];
 
  103        GO entry_i = entryList[i];
 
  106        l_myMin     = (l_myMin < entry_i) ? l_myMin : entry_i;
 
  107        l_myMax     = (l_myMax > entry_i) ? l_myMax : entry_i;
 
  108        l_firstCont = entry_0;
 
  110        if (entry_i - entry_0 != i && l_lastCont.val >= i) {
 
  112          l_lastCont.val = i - 1;
 
  113          l_lastCont.loc = entryList[i - 1];
 
  114        } 
else if (i == numLocalElements - 1 && i < l_lastCont.val) {
 
  117          l_lastCont.loc = entry_i;
 
  120      Kokkos::Min<GO>(minMyGID), Kokkos::Max<GO>(maxMyGID), Kokkos::Min<GO>(firstContiguousGID), Kokkos::MinLoc<LO, GO>(myMinLoc));
 
  123  lastContiguousGID_val = myMinLoc.loc;
 
  124  lastContiguousGID_loc = myMinLoc.val;
 
  131template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  136  , numGlobalElements_(0)
 
  137  , numLocalElements_(0)
 
  147  , distributed_(
false)
 
 
  154template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  158        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm,
 
  165  using Teuchos::broadcast;
 
  166  using Teuchos::outArg;
 
  167  using Teuchos::REDUCE_MAX;
 
  168  using Teuchos::REDUCE_MIN;
 
  169  using Teuchos::reduceAll;
 
  170  using Teuchos::typeName;
 
  173  const GST GSTI        = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
  174  const char funcName[] = 
"Map(gblNumInds,indexBase,comm,LG)";
 
  176      "Tpetra::Map::Map(gblNumInds,indexBase,comm,LG): ";
 
  180  std::unique_ptr<std::string> 
prefix;
 
  183        comm_.getRawPtr(), 
"Map", 
funcName);
 
  184    std::ostringstream 
os;
 
  186    std::cerr << 
os.str();
 
  204                               std::invalid_argument, 
exPfx << 
"All processes must " 
  205                                                               "provide the same number of global elements.  Process 0 set " 
  209                                                            << comm->getRank() << 
" set " 
  212                                                                                    "and max values over all processes are " 
  222                               std::invalid_argument, 
exPfx << 
"All processes must " 
  223                                                               "provide the same indexBase argument.  Process 0 set " 
  247      std::invalid_argument, 
exPfx << 
"numGlobalElements (= " << 
numGlobalElements << 
") must be nonnegative.");
 
  250                                                                                        "Tpetra::global_size_t>::invalid().  This version of the " 
  251                                                                                        "constructor requires a valid value of numGlobalElements.  " 
  252                                                                                        "You probably mistook this constructor for the \"contiguous " 
  253                                                                                        "nonuniform\" constructor, which can compute the global " 
  254                                                                                        "number of elements for you if you set numGlobalElements to " 
  255                                                                                        "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid().");
 
  258  if (
lOrG == GloballyDistributed) {
 
  299    distributed_     = 
false;
 
  302  minAllGID_          = indexBase;
 
  303  maxAllGID_          = indexBase + numGlobalElements - 1;
 
  304  indexBase_          = indexBase;
 
  305  numGlobalElements_  = numGlobalElements;
 
  306  numLocalElements_   = numLocalElements;
 
  307  firstContiguousGID_ = minMyGID_;
 
  308  lastContiguousGID_  = maxMyGID_;
 
  315    std::ostringstream os;
 
  316    os << *prefix << 
"Done" << endl;
 
  317    std::cerr << os.str();
 
 
 
  321template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  326        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
 
  332  using Teuchos::broadcast;
 
  333  using Teuchos::outArg;
 
  334  using Teuchos::REDUCE_MAX;
 
  335  using Teuchos::REDUCE_MIN;
 
  336  using Teuchos::REDUCE_SUM;
 
  337  using Teuchos::reduceAll;
 
  341  const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
  343      "Map(gblNumInds,lclNumInds,indexBase,comm)";
 
  345      "Tpetra::Map::Map(gblNumInds,lclNumInds,indexBase,comm): ";
 
  347      ".  Please report this bug to the Tpetra developers.";
 
  351  std::unique_ptr<std::string> 
prefix;
 
  354        comm_.getRawPtr(), 
"Map", 
funcName);
 
  355    std::ostringstream 
os;
 
  357    std::cerr << 
os.str();
 
  366    debugGlobalSum = initialNonuniformDebugCheck(exPfx,
 
  367                                                 numGlobalElements, numLocalElements, indexBase, comm);
 
  392    const int numProcs = comm->getSize();
 
  397    numGlobalElements_ = globalSum;
 
  401      TEUCHOS_TEST_FOR_EXCEPTION(globalSum != debugGlobalSum, std::logic_error, exPfx << 
"globalSum = " << globalSum << 
" != debugGlobalSum = " << debugGlobalSum << suffix);
 
  404  numLocalElements_   = numLocalElements;
 
  405  indexBase_          = indexBase;
 
  406  minAllGID_          = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase;
 
  407  maxAllGID_          = (numGlobalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + GO(numGlobalElements_) - GO(1);
 
  408  minMyGID_           = (numLocalElements_ == 0) ? std::numeric_limits<GO>::max() : indexBase + GO(myOffset);
 
  409  maxMyGID_           = (numLocalElements_ == 0) ? std::numeric_limits<GO>::lowest() : indexBase + myOffset + GO(numLocalElements) - GO(1);
 
  410  firstContiguousGID_ = minMyGID_;
 
  411  lastContiguousGID_  = maxMyGID_;
 
  413  distributed_        = checkIsDist();
 
  419    std::ostringstream os;
 
  420    os << *prefix << 
"Done" << endl;
 
  421    std::cerr << os.str();
 
  425template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  433        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
 const {
 
  439  using Teuchos::broadcast;
 
  440  using Teuchos::outArg;
 
  442  using Teuchos::REDUCE_MAX;
 
  443  using Teuchos::REDUCE_MIN;
 
  444  using Teuchos::REDUCE_SUM;
 
  445  using Teuchos::reduceAll;
 
  448  const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
  475                                                                            "must provide the same number of global elements, even if " 
  477                                                                            "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() " 
  478                                                                            "(which signals that the Map should compute the global " 
  479                                                                            "number of elements).  Process 0 set numGlobalElements" 
  492                               std::invalid_argument, 
errorMessagePrefix << 
"All processes must provide the same indexBase argument.  " 
  493                                                                            "Process 0 set indexBase = " 
  496                                                                         << comm->getRank() << 
" set indexBase=" << 
indexBase << 
".  The min and max values over all " 
  504                               std::invalid_argument,
 
  506                                                     "indices over all processes, " 
  509                                                                                                  "would like this constructor to compute numGlobalElements " 
  510                                                                                                  "for you, you may set numGlobalElements=" 
  511                                                                                                  "Teuchos::OrdinalTraits<Tpetra::global_size_t>::invalid() " 
  512                                                                                                  "on input.  Please note that this is NOT necessarily -1.");
 
  517template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  527        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
  530  using Kokkos::LayoutLeft;
 
  531  using Kokkos::subview;
 
  533  using Kokkos::view_alloc;
 
  534  using Kokkos::WithoutInitializing;
 
  536  using Teuchos::broadcast;
 
  537  using Teuchos::outArg;
 
  539  using Teuchos::REDUCE_MAX;
 
  540  using Teuchos::REDUCE_MIN;
 
  541  using Teuchos::REDUCE_SUM;
 
  542  using Teuchos::reduceAll;
 
  546  const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
  550                                                << Teuchos::TypeNameTraits<execution_space>::name()
 
  551                                                << 
" has not been initialized.  " 
  552                                                   "Please initialize it before creating a Map.")
 
  583              outArg(numGlobalElements_));
 
  612  minMyGID_ = indexBase_;
 
  613  maxMyGID_ = indexBase_;
 
  623  if (numLocalElements_ > 0) {
 
  629        Kokkos::create_mirror_view(Kokkos::HostSpace(), 
lgMap);
 
  638    lastContiguousGID_  = firstContiguousGID_ + 1;
 
  648    for (; 
i < numLocalElements_; ++
i) {
 
  652      if (lastContiguousGID_ != 
curGid) 
break;
 
  659      ++lastContiguousGID_;
 
  661    --lastContiguousGID_;
 
  667    minMyGID_ = firstContiguousGID_;
 
  668    maxMyGID_ = lastContiguousGID_;
 
  679                                 "Tpetra::Map noncontiguous constructor: " 
  680                                 "nonContigGids_host.extent(0) = " 
  682                                     << 
" != entryList_host.extent(0) - i = " 
  685                                     << 
".  Please report this bug to the Tpetra developers.");
 
  695      Kokkos::fence(
"Map::initWithNonownedHostIndexList");  
 
  708    for (; 
i < numLocalElements_; ++
i) {
 
  710      const LO 
curLid    = 
static_cast<LO
>(
i);
 
  733    minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
 
  734    maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
 
  738    firstContiguousGID_ = indexBase_ + 1;
 
  739    lastContiguousGID_  = indexBase_;
 
  764  if (std::numeric_limits<GO>::is_signed) {
 
  767        (
as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
 
  782    distributed_        = (comm_->getSize() > 1 && 
globalDist == 1);
 
  787    distributed_ = checkIsDist();
 
  793      minAllGID_ < indexBase_,
 
  794      std::invalid_argument,
 
  795      "Tpetra::Map constructor (noncontiguous): " 
  796      "Minimum global ID = " 
  797          << minAllGID_ << 
" over all process(es) is " 
  798                           "less than the given indexBase = " 
  799          << indexBase_ << 
".");
 
  805template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  811        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
 
  817      "Map(gblNumInds,indexList,indexListSize,indexBase,comm)";
 
  819  const bool verbose = Details::Behavior::verbose(
"Map");
 
  820  std::unique_ptr<std::string> 
prefix;
 
  822    prefix = Details::createPrefix(
 
  823        comm_.getRawPtr(), 
"Map", 
funcName);
 
  824    std::ostringstream 
os;
 
  826    std::cerr << 
os.str();
 
  841               Kokkos::MemoryUnmanaged>
 
  846    std::ostringstream 
os;
 
  848    std::cerr << 
os.str();
 
  852template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  855        const Teuchos::ArrayView<const GlobalOrdinal>& 
entryList,
 
  857        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
 
  862  const char* 
funcName = 
"Map(gblNumInds,entryList(Teuchos::ArrayView),indexBase,comm)";
 
  864  const bool verbose = Details::Behavior::verbose(
"Map");
 
  865  std::unique_ptr<std::string> 
prefix;
 
  867    prefix = Details::createPrefix(
 
  868        comm_.getRawPtr(), 
"Map", 
funcName);
 
  869    std::ostringstream 
os;
 
  871    std::cerr << 
os.str();
 
  888               Kokkos::MemoryUnmanaged>
 
  893    std::ostringstream 
os;
 
  895    std::cerr << 
os.str();
 
  899template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
  902        const Kokkos::View<const GlobalOrdinal*, device_type>& 
entryList,
 
  904        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm)
 
  908  using Kokkos::LayoutLeft;
 
  909  using Kokkos::subview;
 
  911  using Kokkos::view_alloc;
 
  912  using Kokkos::WithoutInitializing;
 
  915  using Teuchos::ArrayView;
 
  917  using Teuchos::broadcast;
 
  918  using Teuchos::outArg;
 
  920  using Teuchos::REDUCE_MAX;
 
  921  using Teuchos::REDUCE_MIN;
 
  922  using Teuchos::REDUCE_SUM;
 
  923  using Teuchos::reduceAll;
 
  924  using Teuchos::typeName;
 
  928  const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
  930      "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
 
  933  std::unique_ptr<std::string> 
prefix;
 
  936        comm_.getRawPtr(), 
"Map", 
funcName);
 
  937    std::ostringstream 
os;
 
  939    std::cerr << 
os.str();
 
  946                     static_cast<size_t>(
entryList.extent(0)),
 
  978              outArg(numGlobalElements_));
 
 1007  minMyGID_ = indexBase_;
 
 1008  maxMyGID_ = indexBase_;
 
 1018  if (numLocalElements_ > 0) {
 
 1026    Kokkos::deep_copy(
typename device_type::execution_space(), 
lgMap, 
entryList);
 
 1040    minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
 
 1041    maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
 
 1045    firstContiguousGID_ = indexBase_ + 1;
 
 1046    lastContiguousGID_  = indexBase_;
 
 1071  if (std::numeric_limits<GO>::is_signed) {
 
 1073    const GO localDist =
 
 1074        (as<GST>(numLocalElements_) < numGlobalElements_) ? 1 : 0;
 
 1077    minMaxInput[0] = -minMyGID_;
 
 1078    minMaxInput[1] = maxMyGID_;
 
 1079    minMaxInput[2] = localDist;
 
 1082    minMaxOutput[0] = 0;
 
 1083    minMaxOutput[1] = 0;
 
 1084    minMaxOutput[2] = 0;
 
 1085    reduceAll<int, GO>(*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
 
 1086    minAllGID_          = -minMaxOutput[0];
 
 1087    maxAllGID_          = minMaxOutput[1];
 
 1088    const GO globalDist = minMaxOutput[2];
 
 1089    distributed_        = (comm_->getSize() > 1 && globalDist == 1);
 
 1092    reduceAll<int, GO>(*comm_, REDUCE_MIN, minMyGID_, outArg(minAllGID_));
 
 1093    reduceAll<int, GO>(*comm_, REDUCE_MAX, maxMyGID_, outArg(maxAllGID_));
 
 1094    distributed_ = checkIsDist();
 
 1097  contiguous_ = 
false;  
 
 1099  TEUCHOS_TEST_FOR_EXCEPTION(
 
 1100      minAllGID_ < indexBase_,
 
 1101      std::invalid_argument,
 
 1102      "Tpetra::Map constructor (noncontiguous): " 
 1103      "Minimum global ID = " 
 1104          << minAllGID_ << 
" over all process(es) is " 
 1105                           "less than the given indexBase = " 
 1106          << indexBase_ << 
".");
 
 1112    std::ostringstream 
os;
 
 1114    std::cerr << 
os.str();
 
 1118template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1120  if (!Kokkos::is_initialized()) {
 
 1121    std::ostringstream 
os;
 
 1122    os << 
"WARNING: Tpetra::Map destructor (~Map()) is being called after " 
 1123          "Kokkos::finalize() has been called.  This is user error!  There are " 
 1124          "two likely causes: " 
 1126       << 
"  1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)" 
 1128       << 
"  2. You declare and construct a Tpetra::Map (or RCP or shared_ptr " 
 1129          "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() " 
 1130          "or Tpetra::finalize()." 
 1133       << 
"Don't do either of these!  Please refer to GitHib Issue #2372." 
 1136                                 this->getComm().getRawPtr());
 
 1138    using ::Tpetra::Details::mpiIsFinalized;
 
 1139    using ::Tpetra::Details::mpiIsInitialized;
 
 1140    using ::Tpetra::Details::teuchosCommIsAnMpiComm;
 
 1142    Teuchos::RCP<const Teuchos::Comm<int>> comm = this->getComm();
 
 1143    if (!comm.is_null() && teuchosCommIsAnMpiComm(*comm) &&
 
 1144        mpiIsInitialized() && mpiIsFinalized()) {
 
 1150      std::ostringstream 
os;
 
 1151      os << 
"WARNING: Tpetra::Map destructor (~Map()) is being called after " 
 1152            "MPI_Finalize() has been called.  This is user error!  There are " 
 1153            "two likely causes: " 
 1155         << 
"  1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)" 
 1157         << 
"  2. You declare and construct a Tpetra::Map (or RCP or shared_ptr " 
 1158            "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or " 
 1159            "Tpetra::finalize()." 
 1162         << 
"Don't do either of these!  Please refer to GitHib Issue #2372." 
 
 1172template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1175      getComm().
is_null(), std::logic_error,
 
 1176      "Tpetra::Map::isOneToOne: " 
 1177      "getComm() returns null.  Please report this bug to the Tpetra " 
 1182  return directory_->isOneToOne(*
this);
 
 
 1185template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1189  if (isContiguous()) {
 
 1192      return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
 
 
 1207template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1212    return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid();
 
 1214  if (isContiguous()) {
 
 
 1226template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1236template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1240         Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid();
 
 
 1243template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1248template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1253template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1258                        getMinGlobalIndex(), getMaxGlobalIndex(),
 
 1259                        firstContiguousGID_, lastContiguousGID_,
 
 1260                        getLocalNumElements(), isContiguous());
 
 
 1263template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1266  using Teuchos::outArg;
 
 1267  using Teuchos::REDUCE_MIN;
 
 1268  using Teuchos::reduceAll;
 
 1277  } 
else if (getComm()->getSize() != 
map.getComm()->getSize()) {
 
 1282  } 
else if (getGlobalNumElements() != 
map.getGlobalNumElements()) {
 
 1286  } 
else if (isContiguous() && isUniform() &&
 
 1287             map.isContiguous() && 
map.isUniform()) {
 
 1292  } 
else if (!isContiguous() && !
map.isContiguous() &&
 
 1293             lgMap_.extent(0) != 0 && 
map.lgMap_.extent(0) != 0 &&
 
 1294             lgMap_.data() == 
map.lgMap_.data()) {
 
 1309      getGlobalNumElements() != 
map.getGlobalNumElements(), std::logic_error,
 
 1310      "Tpetra::Map::isCompatible: There's a bug in this method.  We've already " 
 1311      "checked that this condition is true above, but it's false here.  " 
 1312      "Please report this bug to the Tpetra developers.");
 
 1316      (getLocalNumElements() == 
map.getLocalNumElements()) ? 1 : 0;
 
 
 1323template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1326  using Teuchos::ArrayView;
 
 1342  } 
else if (getLocalNumElements() != 
map.getLocalNumElements()) {
 
 1344  } 
else if (getMinGlobalIndex() != 
map.getMinGlobalIndex() ||
 
 1345             getMaxGlobalIndex() != 
map.getMaxGlobalIndex()) {
 
 1348    if (isContiguous()) {
 
 1349      if (
map.isContiguous()) {
 
 1353            !this->isContiguous() || 
map.isContiguous(), std::logic_error,
 
 1354            "Tpetra::Map::locallySameAs: BUG");
 
 1356        const GO 
minLhsGid          = this->getMinGlobalIndex();
 
 1366    } 
else if (
map.isContiguous()) {  
 
 1368          this->isContiguous() || !
map.isContiguous(), std::logic_error,
 
 1369          "Tpetra::Map::locallySameAs: BUG");
 
 1380    } 
else if (this->lgMap_.data() == 
map.lgMap_.data()) {
 
 1383      return this->getLocalNumElements() == 
map.getLocalNumElements();
 
 1385      if (this->getLocalNumElements() != 
map.getLocalNumElements()) {
 
 1388        using range_type = Kokkos::RangePolicy<LocalOrdinal, typename node_type::execution_space>;
 
 1394        Kokkos::parallel_reduce(
 
 1395            "Tpetra::Map::locallySameAs",
 
 1396            range_type(0, this->getLocalNumElements()),
 
 
 1409template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1420  auto lmap2 = this->getLocalMap();
 
 1430  if (
lmap1.isContiguous() && 
lmap2.isContiguous()) {
 
 1432    return ((
lmap1.getMinGlobalIndex() == 
lmap2.getMinGlobalIndex()) &&
 
 1433            (
lmap1.getMaxGlobalIndex() <= 
lmap2.getMaxGlobalIndex()));
 
 1436  if (
lmap1.getMinGlobalIndex() < 
lmap2.getMinGlobalIndex() ||
 
 1437      lmap1.getMaxGlobalIndex() > 
lmap2.getMaxGlobalIndex()) {
 
 1445      Kokkos::RangePolicy<LO, typename node_type::execution_space>;
 
 1449  Kokkos::parallel_reduce(
 
 
 1460template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1463  using Teuchos::outArg;
 
 1464  using Teuchos::REDUCE_MIN;
 
 1465  using Teuchos::reduceAll;
 
 1474  } 
else if (getComm()->getSize() != 
map.getComm()->getSize()) {
 
 1479  } 
else if (getGlobalNumElements() != 
map.getGlobalNumElements()) {
 
 1483  } 
else if (getMinAllGlobalIndex() != 
map.getMinAllGlobalIndex() ||
 
 1484             getMaxAllGlobalIndex() != 
map.getMaxAllGlobalIndex() ||
 
 1485             getIndexBase() != 
map.getIndexBase()) {
 
 1489  } 
else if (isDistributed() != 
map.isDistributed()) {
 
 1493  } 
else if (isContiguous() && isUniform() &&
 
 1494             map.isContiguous() && 
map.isUniform()) {
 
 
 1523template <
class LO, 
class GO, 
class DT>
 
 1526  FillLgMap(
const Kokkos::View<GO*, DT>& 
lgMap,
 
 1530    Kokkos::RangePolicy<LO, typename DT::execution_space>
 
 1531        range(
static_cast<LO
>(0), 
static_cast<LO
>(
lgMap.size()));
 
 1532    Kokkos::parallel_for(
range, *
this);
 
 1535  KOKKOS_INLINE_FUNCTION 
void operator()(
const LO& lid)
 const {
 
 1536    lgMap_(lid) = startGid_ + 
static_cast<GO
>(lid);
 
 1540  const Kokkos::View<GO*, DT> lgMap_;
 
 1546template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1547typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_type
 
 1553  using lg_view_type       = 
typename const_lg_view_type::non_const_type;
 
 1557  std::unique_ptr<std::string> 
prefix;
 
 1560        comm_.getRawPtr(), 
"Map", 
"getMyGlobalIndices");
 
 1561    std::ostringstream 
os;
 
 1563    std::cerr << 
os.str();
 
 1570      lgMap_.extent(0) == 0 && numLocalElements_ > 0;
 
 1574      std::ostringstream 
os;
 
 1576      std::cerr << 
os.str();
 
 1582                                 "Tpetra::Map::getMyGlobalIndices: The local-to-global " 
 1583                                 "mapping (lgMap_) should have been set up already for a " 
 1584                                 "noncontiguous Map.  Please report this bug to the Tpetra " 
 1587    const LO 
numElts = 
static_cast<LO
>(getLocalNumElements());
 
 1589    using Kokkos::view_alloc;
 
 1590    using Kokkos::WithoutInitializing;
 
 1593      std::ostringstream 
os;
 
 1595      std::cerr << 
os.str();
 
 1600      std::ostringstream 
os;
 
 1602      std::cerr << 
os.str();
 
 1605    auto lgMapHost = Kokkos::create_mirror_view(Kokkos::HostSpace(), 
lgMap);
 
 1622    std::ostringstream 
os;
 
 1624    std::cerr << 
os.str();
 
 
 1629template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1630typename Map<LocalOrdinal, GlobalOrdinal, Node>::global_indices_array_device_type
 
 1636  using lg_view_type       = 
typename const_lg_view_type::non_const_type;
 
 1640  std::unique_ptr<std::string> 
prefix;
 
 1643        comm_.getRawPtr(), 
"Map", 
"getMyGlobalIndicesDevice");
 
 1644    std::ostringstream 
os;
 
 1646    std::cerr << 
os.str();
 
 1653      lgMap_.extent(0) == 0 && numLocalElements_ > 0;
 
 1657      std::ostringstream 
os;
 
 1659      std::cerr << 
os.str();
 
 1665                                 "Tpetra::Map::getMyGlobalIndices: The local-to-global " 
 1666                                 "mapping (lgMap_) should have been set up already for a " 
 1667                                 "noncontiguous Map.  Please report this bug to the Tpetra " 
 1670    const LO 
numElts = 
static_cast<LO
>(getLocalNumElements());
 
 1672    using Kokkos::view_alloc;
 
 1673    using Kokkos::WithoutInitializing;
 
 1676      std::ostringstream 
os;
 
 1678      std::cerr << 
os.str();
 
 1687    std::ostringstream 
os;
 
 1689    std::cerr << 
os.str();
 
 
 1694template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1695Teuchos::ArrayView<const GlobalOrdinal>
 
 1702  (
void)this->getMyGlobalIndices();
 
 1710  return Teuchos::ArrayView<const GO>(
 
 1712      lgMapHost_.extent(0),
 
 1713      Teuchos::RCP_DISABLE_NODE_LOOKUP);
 
 
 1716template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1718  return distributed_;
 
 
 1721template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1723  using Teuchos::TypeNameTraits;
 
 1724  std::ostringstream 
os;
 
 1726  os << 
"Tpetra::Map: {" 
 1733  os << 
", Global number of entries: " << getGlobalNumElements()
 
 1734     << 
", Number of processes: " << getComm()->getSize()
 
 1735     << 
", Uniform: " << (isUniform() ? 
"true" : 
"false")
 
 1736     << 
", Contiguous: " << (isContiguous() ? 
"true" : 
"false")
 
 1737     << 
", Distributed: " << (isDistributed() ? 
"true" : 
"false")
 
 
 1746template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1750  using LO = local_ordinal_type;
 
 1754  if (
vl < Teuchos::VERB_HIGH) {
 
 1755    return std::string();
 
 1757  auto outStringP = Teuchos::rcp(
new std::ostringstream());
 
 1758  Teuchos::RCP<Teuchos::FancyOStream> outp =
 
 1759      Teuchos::getFancyOStream(outStringP);
 
 1760  Teuchos::FancyOStream& out = *outp;
 
 1762  auto comm          = this->getComm();
 
 1763  const int myRank   = comm->getRank();
 
 1764  const int numProcs = comm->getSize();
 
 1765  out << 
"Process " << myRank << 
" of " << numProcs << 
":" << endl;
 
 1766  Teuchos::OSTab tab1(out);
 
 1768  const LO numEnt = 
static_cast<LO
>(this->getLocalNumElements());
 
 1769  out << 
"My number of entries: " << numEnt << endl
 
 1770      << 
"My minimum global index: " << this->getMinGlobalIndex() << endl
 
 1771      << 
"My maximum global index: " << this->getMaxGlobalIndex() << endl;
 
 1773  if (vl == Teuchos::VERB_EXTREME) {
 
 1774    out << 
"My global indices: [";
 
 1775    const LO minLclInd = this->getMinLocalIndex();
 
 1776    for (LO k = 0; k < numEnt; ++k) {
 
 1777      out << minLclInd + this->getGlobalElement(k);
 
 1778      if (k + 1 < numEnt) {
 
 1786  return outStringP->str();
 
 1789template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1792             const Teuchos::EVerbosityLevel 
verbLevel)
 const {
 
 1794  using Teuchos::TypeNameTraits;
 
 1795  using Teuchos::VERB_DEFAULT;
 
 1796  using Teuchos::VERB_HIGH;
 
 1797  using Teuchos::VERB_LOW;
 
 1798  using Teuchos::VERB_NONE;
 
 1801  const Teuchos::EVerbosityLevel 
vl =
 
 1811  auto comm = this->getComm();
 
 1812  if (comm.is_null()) {
 
 1815  const int myRank   = comm->getRank();
 
 1816  const int numProcs = comm->getSize();
 
 1825  Teuchos::RCP<Teuchos::OSTab> 
tab0, 
tab1;
 
 1831    tab0 = Teuchos::rcp(
new Teuchos::OSTab(
out));
 
 1832    out << 
"\"Tpetra::Map\":" << 
endl;
 
 1833    tab1 = Teuchos::rcp(
new Teuchos::OSTab(
out));
 
 1835      out << 
"Template parameters:" << 
endl;
 
 1843      out << 
"Label: \"" << label << 
"\"" << 
endl;
 
 1845    out << 
"Global number of entries: " << getGlobalNumElements() << 
endl 
 1846        << 
"Minimum global index: " << getMinAllGlobalIndex() << 
endl 
 1847        << 
"Maximum global index: " << getMaxAllGlobalIndex() << 
endl 
 1848        << 
"Index base: " << getIndexBase() << 
endl 
 1850        << 
"Uniform: " << (isUniform() ? 
"true" : 
"false") << 
endl 
 1851        << 
"Contiguous: " << (isContiguous() ? 
"true" : 
"false") << 
endl 
 1852        << 
"Distributed: " << (isDistributed() ? 
"true" : 
"false") << 
endl;
 
 1857    const std::string 
lclStr = this->localDescribeToString(
vl);
 
 
 1862template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1863Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 1881    return Teuchos::null;  
 
 1882  } 
else if (
newComm->getSize() == 1) {
 
 1895    newMap->indexBase_          = this->indexBase_;
 
 1896    newMap->numGlobalElements_  = this->numLocalElements_;
 
 1897    newMap->numLocalElements_   = this->numLocalElements_;
 
 1898    newMap->minMyGID_           = this->minMyGID_;
 
 1899    newMap->maxMyGID_           = this->maxMyGID_;
 
 1900    newMap->minAllGID_          = this->minMyGID_;
 
 1901    newMap->maxAllGID_          = this->maxMyGID_;
 
 1902    newMap->firstContiguousGID_ = this->firstContiguousGID_;
 
 1903    newMap->lastContiguousGID_  = this->lastContiguousGID_;
 
 1906    newMap->uniform_    = this->uniform_;
 
 1907    newMap->contiguous_ = this->contiguous_;
 
 1910    newMap->distributed_ = 
false;
 
 1911    newMap->lgMap_       = this->lgMap_;
 
 1912    newMap->lgMapHost_   = this->lgMapHost_;
 
 1913    newMap->glMap_       = this->glMap_;
 
 1914    newMap->glMapHost_   = this->glMapHost_;
 
 1934    const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
 1950    auto lgMap = this->getMyGlobalIndices();
 
 1952        typename std::decay<
decltype(
lgMap.extent(0))>::type;
 
 1954        static_cast<size_type
>(this->getLocalNumElements());
 
 1955    using Teuchos::TypeNameTraits;
 
 1957                               "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() " 
 1961                                   << 
this->getLocalNumElements() << 
".  The latter, upon being " 
 1962                                                                     "cast to size_type = " 
 1965                                   << 
lclNumInds << 
".  Please report this bug to the Tpetra " 
 1968    Teuchos::ArrayView<const GO> 
lgMap = this->getLocalElementList();
 
 1971    const GO 
indexBase = this->getIndexBase();
 
 
 1978template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 1979Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 1982  using Teuchos::Comm;
 
 1983  using Teuchos::null;
 
 1984  using Teuchos::outArg;
 
 1987  using Teuchos::REDUCE_MIN;
 
 1988  using Teuchos::reduceAll;
 
 1995  const int color = (numLocalElements_ == 0) ? 0 : 1;
 
 2012    map->indexBase_          = indexBase_;
 
 2013    map->numGlobalElements_  = numGlobalElements_;
 
 2014    map->numLocalElements_   = numLocalElements_;
 
 2015    map->minMyGID_           = minMyGID_;
 
 2016    map->maxMyGID_           = maxMyGID_;
 
 2017    map->minAllGID_          = minAllGID_;
 
 2018    map->maxAllGID_          = maxAllGID_;
 
 2019    map->firstContiguousGID_ = firstContiguousGID_;
 
 2020    map->lastContiguousGID_  = lastContiguousGID_;
 
 2024    map->uniform_    = uniform_;
 
 2025    map->contiguous_ = contiguous_;
 
 2040    if (!distributed_ || 
newComm->getSize() == 1) {
 
 2041      map->distributed_ = 
false;
 
 2043      const int iOwnAllGids  = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
 
 2049    map->lgMap_     = lgMap_;
 
 2050    map->lgMapHost_ = lgMapHost_;
 
 2051    map->glMap_     = glMap_;
 
 2052    map->glMapHost_ = glMapHost_;
 
 
 2069template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2072      directory_.is_null(), std::logic_error,
 
 2073      "Tpetra::Map::setupDirectory: " 
 2074      "The Directory is null.  " 
 2075      "Please report this bug to the Tpetra developers.");
 
 2079  if (!directory_->initialized()) {
 
 2080    directory_->initialize(*
this);
 
 2084template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2088                       const Teuchos::ArrayView<int>& 
PIDs,
 
 2089                       const Teuchos::ArrayView<LocalOrdinal>& 
LIDs)
 const {
 
 2092  using Tpetra::Details::OrdinalTraits;
 
 2093  using size_type = Teuchos::ArrayView<int>::size_type;
 
 2097  std::unique_ptr<std::string> 
prefix;
 
 2100                                   "Map", 
"getRemoteIndexList(GIDs,PIDs,LIDs)");
 
 2101    std::ostringstream 
os;
 
 2105    std::cerr << 
os.str();
 
 2114  if (getGlobalNumElements() == 0) {
 
 2115    if (
GIDs.size() == 0) {
 
 2117        std::ostringstream 
os;
 
 2118        os << *
prefix << 
"Done; both Map & input are empty" << 
endl;
 
 2119        std::cerr << 
os.str();
 
 2124        std::ostringstream 
os;
 
 2125        os << *
prefix << 
"Done: Map is empty on all processes, " 
 2126                         "so all output PIDs & LIDs are invalid (-1)." 
 2128        std::cerr << 
os.str();
 
 2130      for (size_type 
k = 0; 
k < 
PIDs.size(); ++
k) {
 
 2133      for (size_type 
k = 0; 
k < 
LIDs.size(); ++
k) {
 
 2145    std::ostringstream 
os;
 
 2147    std::cerr << 
os.str();
 
 2151    std::ostringstream 
os;
 
 2152    os << *
prefix << 
"Call directory_->getDirectoryEntries" << 
endl;
 
 2153    std::cerr << 
os.str();
 
 2156      directory_->getDirectoryEntries(*
this, 
GIDs, 
PIDs, 
LIDs);
 
 2158    std::ostringstream 
os;
 
 2159    os << *
prefix << 
"Done; getDirectoryEntries returned " 
 2166    std::cerr << 
os.str();
 
 
 2171template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2175                       const Teuchos::ArrayView<int>& 
PIDs)
 const {
 
 2181  std::unique_ptr<std::string> 
prefix;
 
 2184                                   "Map", 
"getRemoteIndexList(GIDs,PIDs)");
 
 2185    std::ostringstream 
os;
 
 2189    std::cerr << 
os.str();
 
 2192  if (getGlobalNumElements() == 0) {
 
 2193    if (
GIDs.size() == 0) {
 
 2195        std::ostringstream 
os;
 
 2196        os << *
prefix << 
"Done; both Map & input are empty" << 
endl;
 
 2197        std::cerr << 
os.str();
 
 2202        std::ostringstream 
os;
 
 2203        os << *
prefix << 
"Done: Map is empty on all processes, " 
 2204                         "so all output PIDs are invalid (-1)." 
 2206        std::cerr << 
os.str();
 
 2208      for (Teuchos::ArrayView<int>::size_type 
k = 0; 
k < 
PIDs.size(); ++
k) {
 
 2209        PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid();
 
 2220    std::ostringstream 
os;
 
 2222    std::cerr << 
os.str();
 
 2226    std::ostringstream 
os;
 
 2227    os << *
prefix << 
"Call directory_->getDirectoryEntries" << 
endl;
 
 2228    std::cerr << 
os.str();
 
 2231      directory_->getDirectoryEntries(*
this, 
GIDs, 
PIDs);
 
 2233    std::ostringstream 
os;
 
 2234    os << *
prefix << 
"Done; getDirectoryEntries returned " 
 2239    std::cerr << 
os.str();
 
 
 2244template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2246  using exec_space = 
typename Node::device_type::execution_space;
 
 2247  if (lgMap_.extent(0) != lgMapHost_.extent(0)) {
 
 2253    auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace(), lgMap_);
 
 
 
 2266template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2267Teuchos::RCP<const Teuchos::Comm<int>>
 
 2272template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2277  using Teuchos::outArg;
 
 2278  using Teuchos::REDUCE_MIN;
 
 2279  using Teuchos::reduceAll;
 
 2282  std::unique_ptr<std::string> 
prefix;
 
 2285        comm_.getRawPtr(), 
"Map", 
"checkIsDist");
 
 2286    std::ostringstream 
os;
 
 2288    std::cerr << 
os.str();
 
 2291  bool global = 
false;
 
 2292  if (comm_->getSize() > 1) {
 
 2296    if (numGlobalElements_ == as<global_size_t>(numLocalElements_)) {
 
 2309    reduceAll<int, int>(*comm_, REDUCE_MIN, localRep, outArg(allLocalRep));
 
 2310    if (allLocalRep != 1) {
 
 2320    std::ostringstream os;
 
 2321    os << *prefix << 
"Done; global=" << (global ? 
"true" : 
"false")
 
 2323    std::cerr << os.str();
 
 2330template <
class LocalOrdinal, 
class GlobalOrdinal>
 
 2331Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
 
 2333                       const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2334  typedef LocalOrdinal LO;
 
 2335  typedef GlobalOrdinal GO;
 
 2336  using NT = typename ::Tpetra::Map<LO, GO>::node_type;
 
 2337  return createLocalMapWithNode<LO, GO, NT>(numElements, comm);
 
 2340template <
class LocalOrdinal, 
class GlobalOrdinal>
 
 2341Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
 
 2343                               const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2344  typedef LocalOrdinal LO;
 
 2345  typedef GlobalOrdinal GO;
 
 2346  using NT = typename ::Tpetra::Map<LO, GO>::node_type;
 
 2347  return createUniformContigMapWithNode<LO, GO, NT>(numElements, comm);
 
 2350template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2351Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 2353                                       const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2356  const GlobalOrdinal indexBase = 
static_cast<GlobalOrdinal
>(0);
 
 2358  return rcp(
new map_type(numElements, indexBase, comm, GloballyDistributed));
 
 2361template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2362Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 2364                               const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2368  const GlobalOrdinal indexBase     = 0;
 
 2371  return rcp(
new map_type(globalNumElts, indexBase, comm, LocallyReplicated));
 
 2374template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2375Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 2377                                const size_t localNumElements,
 
 2378                                const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2381  const GlobalOrdinal indexBase = 0;
 
 2383  return rcp(
new map_type(numElements, localNumElements, indexBase, comm));
 
 2386template <
class LocalOrdinal, 
class GlobalOrdinal>
 
 2387Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
 
 2389                        const size_t localNumElements,
 
 2390                        const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2391  typedef LocalOrdinal LO;
 
 2392  typedef GlobalOrdinal GO;
 
 2398template <
class LocalOrdinal, 
class GlobalOrdinal>
 
 2399Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal>>
 
 2401                           const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2402  typedef LocalOrdinal LO;
 
 2403  typedef GlobalOrdinal GO;
 
 2409template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2410Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 2412                                   const Teuchos::RCP<
const Teuchos::Comm<int>>& comm) {
 
 2416  const GST INV  = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
 2420  const GlobalOrdinal indexBase = 0;
 
 2422  return rcp(
new map_type(INV, elementList, indexBase, comm));
 
 2425template <
class LO, 
class GO, 
class NT>
 
 2426Teuchos::RCP<const Tpetra::Map<LO, GO, NT>>
 
 2428  using Details::verbosePrintArray;
 
 2431  using Teuchos::Array;
 
 2432  using Teuchos::ArrayView;
 
 2438  const bool verbose = Details::Behavior::verbose(
"Map");
 
 2439  std::unique_ptr<std::string> prefix;
 
 2441    auto comm = M.is_null() ? Teuchos::null : M->getComm();
 
 2442    prefix    = Details::createPrefix(
 
 2443           comm.getRawPtr(), 
"createOneToOne(Map)");
 
 2444    std::ostringstream os;
 
 2445    os << *prefix << 
"Start" << endl;
 
 2448  const size_t maxNumToPrint = verbose ? Details::Behavior::verbosePrintCountThreshold() : size_t(0);
 
 2449  const GST GINV             = Tpetra::Details::OrdinalTraits<GST>::invalid();
 
 2450  const int myRank           = M->getComm()->getRank();
 
 2456  if (!M->isDistributed()) {
 
 2463    const GST numGlobalEntries = M->getGlobalNumElements();
 
 2464    if (M->isContiguous()) {
 
 2465      const size_t numLocalEntries =
 
 2466          (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
 
 2468        std::ostringstream os;
 
 2469        os << *prefix << 
"Input is locally replicated & contiguous; " 
 2471           << numLocalEntries << endl;
 
 2475          rcp(
new map_type(numGlobalEntries, numLocalEntries,
 
 2476                           M->getIndexBase(), M->getComm()));
 
 2478        std::ostringstream os;
 
 2479        os << *prefix << 
"Done" << endl;
 
 2485        std::ostringstream os;
 
 2486        os << *prefix << 
"Input is locally replicated & noncontiguous" 
 2490      ArrayView<const GO> myGids =
 
 2491          (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
 
 2493          rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
 
 2496        std::ostringstream os;
 
 2497        os << *prefix << 
"Done" << endl;
 
 2502  } 
else if (M->isContiguous()) {
 
 2504      std::ostringstream os;
 
 2505      os << *prefix << 
"Input is distributed & contiguous" << endl;
 
 2513      std::ostringstream os;
 
 2514      os << *prefix << 
"Input is distributed & noncontiguous" << endl;
 
 2518    const size_t numMyElems     = M->getLocalNumElements();
 
 2519    ArrayView<const GO> myElems = M->getLocalElementList();
 
 2520    Array<int> owner_procs_vec(numMyElems);
 
 2523      std::ostringstream os;
 
 2524      os << *prefix << 
"Call Directory::getDirectoryEntries: ";
 
 2529    directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
 
 2531      std::ostringstream os;
 
 2532      os << *prefix << 
"getDirectoryEntries result: ";
 
 2538    Array<GO> myOwned_vec(numMyElems);
 
 2539    size_t numMyOwnedElems = 0;
 
 2540    for (
size_t i = 0; i < numMyElems; ++i) {
 
 2541      const GO GID    = myElems[i];
 
 2542      const int owner = owner_procs_vec[i];
 
 2544      if (myRank == owner) {
 
 2545        myOwned_vec[numMyOwnedElems++] = GID;
 
 2548    myOwned_vec.resize(numMyOwnedElems);
 
 2551      std::ostringstream os;
 
 2552      os << *prefix << 
"Create Map: ";
 
 2557    auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
 
 2558                                   M->getIndexBase(), M->getComm()));
 
 2560      std::ostringstream os;
 
 2561      os << *prefix << 
"Done" << endl;
 
 2568template <
class LocalOrdinal, 
class GlobalOrdinal, 
class Node>
 
 2569Teuchos::RCP<const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
 
 2572  using Details::Behavior;
 
 2573  using Details::verbosePrintArray;
 
 2576  using Teuchos::Array;
 
 2577  using Teuchos::ArrayView;
 
 2580  using Teuchos::toString;
 
 2581  using LO       = LocalOrdinal;
 
 2582  using GO       = GlobalOrdinal;
 
 2585  const bool verbose = Behavior::verbose(
"Map");
 
 2586  std::unique_ptr<std::string> prefix;
 
 2588    auto comm = M.is_null() ? Teuchos::null : M->getComm();
 
 2589    prefix    = Details::createPrefix(
 
 2590           comm.getRawPtr(), 
"createOneToOne(Map,TieBreak)");
 
 2591    std::ostringstream os;
 
 2592    os << *prefix << 
"Start" << endl;
 
 2595  const size_t maxNumToPrint = verbose ? Behavior::verbosePrintCountThreshold() : size_t(0);
 
 2602    std::ostringstream os;
 
 2603    os << *prefix << 
"Initialize Directory" << endl;
 
 2606  directory.initialize(*M, tie_break);
 
 2608    std::ostringstream os;
 
 2609    os << *prefix << 
"Done initializing Directory" << endl;
 
 2612  size_t numMyElems           = M->getLocalNumElements();
 
 2613  ArrayView<const GO> myElems = M->getLocalElementList();
 
 2614  Array<int> owner_procs_vec(numMyElems);
 
 2616    std::ostringstream os;
 
 2617    os << *prefix << 
"Call Directory::getDirectoryEntries: ";
 
 2622  directory.getDirectoryEntries(*M, myElems, owner_procs_vec());
 
 2624    std::ostringstream os;
 
 2625    os << *prefix << 
"getDirectoryEntries result: ";
 
 2631  const int myRank = M->getComm()->getRank();
 
 2632  Array<GO> myOwned_vec(numMyElems);
 
 2633  size_t numMyOwnedElems = 0;
 
 2634  for (
size_t i = 0; i < numMyElems; ++i) {
 
 2635    const GO GID    = myElems[i];
 
 2636    const int owner = owner_procs_vec[i];
 
 2637    if (myRank == owner) {
 
 2638      myOwned_vec[numMyOwnedElems++] = GID;
 
 2641  myOwned_vec.resize(numMyOwnedElems);
 
 2646      Tpetra::Details::OrdinalTraits<global_size_t>::invalid();
 
 2648    std::ostringstream os;
 
 2649    os << *prefix << 
"Create Map: ";
 
 2654  RCP<const map_type> retMap(
new map_type(GINV, myOwned_vec(), M->getIndexBase(),
 
 2657    std::ostringstream os;
 
 2658    os << *prefix << 
"Done" << endl;
 
 2672#define TPETRA_MAP_INSTANT(LO, GO, NODE)                                                            \ 
 2674  template class Map<LO, GO, NODE>;                                                                 \ 
 2676  template Teuchos::RCP<const Map<LO, GO, NODE>>                                                    \ 
 2677  createLocalMapWithNode<LO, GO, NODE>(const size_t numElements,                                    \ 
 2678                                       const Teuchos::RCP<const Teuchos::Comm<int>>& comm);         \ 
 2680  template Teuchos::RCP<const Map<LO, GO, NODE>>                                                    \ 
 2681  createContigMapWithNode<LO, GO, NODE>(const global_size_t numElements,                            \ 
 2682                                        const size_t localNumElements,                              \ 
 2683                                        const Teuchos::RCP<const Teuchos::Comm<int>>& comm);        \ 
 2685  template Teuchos::RCP<const Map<LO, GO, NODE>>                                                    \ 
 2686  createNonContigMapWithNode(const Teuchos::ArrayView<const GO>& elementList,                       \ 
 2687                             const Teuchos::RCP<const Teuchos::Comm<int>>& comm);                   \ 
 2689  template Teuchos::RCP<const Map<LO, GO, NODE>>                                                    \ 
 2690  createUniformContigMapWithNode<LO, GO, NODE>(const global_size_t numElements,                     \ 
 2691                                               const Teuchos::RCP<const Teuchos::Comm<int>>& comm); \ 
 2693  template Teuchos::RCP<const Map<LO, GO, NODE>>                                                    \ 
 2694  createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M);                                   \ 
 2696  template Teuchos::RCP<const Map<LO, GO, NODE>>                                                    \ 
 2697  createOneToOne(const Teuchos::RCP<const Map<LO, GO, NODE>>& M,                                    \ 
 2698                 const Tpetra::Details::TieBreak<LO, GO>& tie_break); 
 
 2701#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO, GO)                                         \ 
 2702  template Teuchos::RCP<const Map<LO, GO>>                                             \ 
 2703  createLocalMap<LO, GO>(const size_t, const Teuchos::RCP<const Teuchos::Comm<int>>&); \ 
 2705  template Teuchos::RCP<const Map<LO, GO>>                                             \ 
 2706  createContigMap<LO, GO>(global_size_t, size_t,                                       \ 
 2707                          const Teuchos::RCP<const Teuchos::Comm<int>>&);              \ 
 2709  template Teuchos::RCP<const Map<LO, GO>>                                             \ 
 2710  createNonContigMap(const Teuchos::ArrayView<const GO>&,                              \ 
 2711                     const Teuchos::RCP<const Teuchos::Comm<int>>&);                   \ 
 2713  template Teuchos::RCP<const Map<LO, GO>>                                             \ 
 2714  createUniformContigMap<LO, GO>(const global_size_t,                                  \ 
 2715                                 const Teuchos::RCP<const Teuchos::Comm<int>>&); 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
Functions for initializing and finalizing Tpetra.
 
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
 
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
 
Declaration of a function that prints strings from each process.
 
Declaration of Tpetra::Details::initializeKokkos.
 
Declaration of Tpetra::Details::printOnce.
 
Stand-alone utility functions and macros.
 
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.
 
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
 
Node node_type
Legacy typedef that will go away at some point.
 
Map()
Default constructor (that does nothing).
 
GlobalOrdinal global_ordinal_type
The type of global indices.
 
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.
 
bool isNodeGlobalElement(global_ordinal_type globalIndex) const
Whether the given global index is owned by this Map on the calling process.
 
bool isSameAs(const Map< local_ordinal_type, global_ordinal_type, Node > &map) const
True if and only if map is identical to this Map.
 
local_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.
 
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.
 
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...