952 using Kokkos::LayoutLeft;
953 using Kokkos::subview;
955 using Kokkos::view_alloc;
956 using Kokkos::WithoutInitializing;
958 using Teuchos::ArrayView;
960 using Teuchos::broadcast;
961 using Teuchos::outArg;
963 using Teuchos::REDUCE_MAX;
964 using Teuchos::REDUCE_MIN;
965 using Teuchos::REDUCE_SUM;
966 using Teuchos::reduceAll;
967 using Teuchos::typeName;
972 const GST GSTI = Tpetra::Details::OrdinalTraits<GST>::invalid ();
974 "Map(gblNumInds,entryList(Kokkos::View),indexBase,comm)";
976 const bool verbose = Details::Behavior::verbose(
"Map");
977 std::unique_ptr<std::string>
prefix;
979 prefix = Details::createPrefix(
980 comm_.getRawPtr(),
"Map",
funcName);
981 std::ostringstream
os;
983 std::cerr <<
os.str();
990 static_cast<size_t> (
entryList.extent (0)),
1023 outArg(numGlobalElements_));
1053 minMyGID_ = indexBase_;
1054 maxMyGID_ = indexBase_;
1064 if (numLocalElements_ > 0) {
1068 typename decltype (lgMap_)::non_const_type
lgMap
1073 Kokkos::deep_copy(
typename device_type::execution_space(),
lgMap,
entryList);
1088 minMyGID_ = std::numeric_limits<GlobalOrdinal>::max();
1089 maxMyGID_ = std::numeric_limits<GlobalOrdinal>::lowest();
1093 firstContiguousGID_ = indexBase_+1;
1094 lastContiguousGID_ = indexBase_;
1120 if (std::numeric_limits<GO>::is_signed) {
1122 const GO localDist =
1123 (as<GST> (numLocalElements_) < numGlobalElements_) ? 1 : 0;
1126 minMaxInput[0] = -minMyGID_;
1127 minMaxInput[1] = maxMyGID_;
1128 minMaxInput[2] = localDist;
1131 minMaxOutput[0] = 0;
1132 minMaxOutput[1] = 0;
1133 minMaxOutput[2] = 0;
1134 reduceAll<int, GO> (*comm, REDUCE_MAX, 3, minMaxInput, minMaxOutput);
1135 minAllGID_ = -minMaxOutput[0];
1136 maxAllGID_ = minMaxOutput[1];
1137 const GO globalDist = minMaxOutput[2];
1138 distributed_ = (comm_->getSize () > 1 && globalDist == 1);
1142 reduceAll<int, GO> (*comm_, REDUCE_MIN, minMyGID_, outArg (minAllGID_));
1143 reduceAll<int, GO> (*comm_, REDUCE_MAX, maxMyGID_, outArg (maxAllGID_));
1144 distributed_ = checkIsDist ();
1147 contiguous_ =
false;
1149 TEUCHOS_TEST_FOR_EXCEPTION(
1150 minAllGID_ < indexBase_,
1151 std::invalid_argument,
1152 "Tpetra::Map constructor (noncontiguous): "
1153 "Minimum global ID = " << minAllGID_ <<
" over all process(es) is "
1154 "less than the given indexBase = " << indexBase_ <<
".");
1160 std::ostringstream os;
1161 os << *prefix <<
"Done" << endl;
1162 std::cerr << os.str();
1167 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1170 if (! Kokkos::is_initialized ()) {
1171 std::ostringstream
os;
1172 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1173 "Kokkos::finalize() has been called. This is user error! There are "
1174 "two likely causes: " << std::endl <<
1175 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1177 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1178 "of a Tpetra::Map) at the same scope in main() as Kokkos::finalize() "
1179 "or Tpetra::finalize()." << std::endl << std::endl <<
1180 "Don't do either of these! Please refer to GitHib Issue #2372."
1183 this->getComm ().getRawPtr ());
1186 using ::Tpetra::Details::mpiIsInitialized;
1187 using ::Tpetra::Details::mpiIsFinalized;
1188 using ::Tpetra::Details::teuchosCommIsAnMpiComm;
1190 Teuchos::RCP<const Teuchos::Comm<int> > comm = this->getComm ();
1191 if (! comm.is_null () && teuchosCommIsAnMpiComm (*comm) &&
1192 mpiIsInitialized () && mpiIsFinalized ()) {
1198 std::ostringstream
os;
1199 os <<
"WARNING: Tpetra::Map destructor (~Map()) is being called after "
1200 "MPI_Finalize() has been called. This is user error! There are "
1201 "two likely causes: " << std::endl <<
1202 " 1. You have a static Tpetra::Map (or RCP or shared_ptr of a Map)"
1204 " 2. You declare and construct a Tpetra::Map (or RCP or shared_ptr "
1205 "of a Tpetra::Map) at the same scope in main() as MPI_finalize() or "
1206 "Tpetra::finalize()." << std::endl << std::endl <<
1207 "Don't do either of these! Please refer to GitHib Issue #2372."
1217 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1222 getComm ().
is_null (), std::logic_error,
"Tpetra::Map::isOneToOne: "
1223 "getComm() returns null. Please report this bug to the Tpetra "
1228 return directory_->isOneToOne (*
this);
1231 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1236 if (isContiguous ()) {
1239 return Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1256 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1262 return Tpetra::Details::OrdinalTraits<GlobalOrdinal>::invalid ();
1264 if (isContiguous ()) {
1277 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1289 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1294 Tpetra::Details::OrdinalTraits<LocalOrdinal>::invalid ();
1297 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1302 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1308 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1314 getMinGlobalIndex (), getMaxGlobalIndex (),
1315 firstContiguousGID_, lastContiguousGID_,
1316 getLocalNumElements (), isContiguous ());
1319 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1324 using Teuchos::outArg;
1325 using Teuchos::REDUCE_MIN;
1326 using Teuchos::reduceAll;
1336 else if (getComm ()->getSize () !=
map.getComm ()->getSize ()) {
1342 else if (getGlobalNumElements () !=
map.getGlobalNumElements ()) {
1347 else if (isContiguous () && isUniform () &&
1348 map.isContiguous () &&
map.isUniform ()) {
1354 else if (! isContiguous () && !
map.isContiguous () &&
1355 lgMap_.extent (0) != 0 &&
map.lgMap_.extent (0) != 0 &&
1356 lgMap_.data () ==
map.lgMap_.data ()) {
1371 getGlobalNumElements () !=
map.getGlobalNumElements (), std::logic_error,
1372 "Tpetra::Map::isCompatible: There's a bug in this method. We've already "
1373 "checked that this condition is true above, but it's false here. "
1374 "Please report this bug to the Tpetra developers.");
1378 (getLocalNumElements () ==
map.getLocalNumElements ()) ? 1 : 0;
1385 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1390 using Teuchos::ArrayView;
1407 else if (getLocalNumElements () !=
map.getLocalNumElements ()) {
1410 else if (getMinGlobalIndex () !=
map.getMinGlobalIndex () ||
1411 getMaxGlobalIndex () !=
map.getMaxGlobalIndex ()) {
1415 if (isContiguous ()) {
1416 if (
map.isContiguous ()) {
1421 ! this->isContiguous () ||
map.isContiguous (), std::logic_error,
1422 "Tpetra::Map::locallySameAs: BUG");
1424 const GO
minLhsGid = this->getMinGlobalIndex ();
1435 else if (
map.isContiguous ()) {
1437 this->isContiguous () || !
map.isContiguous (), std::logic_error,
1438 "Tpetra::Map::locallySameAs: BUG");
1450 else if (this->lgMap_.data () ==
map.lgMap_.data ()) {
1453 return this->getLocalNumElements () ==
map.getLocalNumElements ();
1456 if (this->getLocalNumElements () !=
map.getLocalNumElements ()) {
1472 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1485 auto lmap2 = this->getLocalMap();
1495 if (
lmap1.isContiguous () &&
lmap2.isContiguous ()) {
1497 return ((
lmap1.getMinGlobalIndex () ==
lmap2.getMinGlobalIndex ()) &&
1498 (
lmap1.getMaxGlobalIndex () <=
lmap2.getMaxGlobalIndex ()));
1501 if (
lmap1.getMinGlobalIndex () <
lmap2.getMinGlobalIndex () ||
1502 lmap1.getMaxGlobalIndex () >
lmap2.getMaxGlobalIndex ()) {
1510 Kokkos::RangePolicy<LO, typename node_type::execution_space>;
1514 Kokkos::parallel_reduce(
1524 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1529 using Teuchos::outArg;
1530 using Teuchos::REDUCE_MIN;
1531 using Teuchos::reduceAll;
1541 else if (getComm ()->getSize () !=
map.getComm ()->getSize ()) {
1547 else if (getGlobalNumElements () !=
map.getGlobalNumElements ()) {
1552 else if (getMinAllGlobalIndex () !=
map.getMinAllGlobalIndex () ||
1553 getMaxAllGlobalIndex () !=
map.getMaxAllGlobalIndex () ||
1554 getIndexBase () !=
map.getIndexBase ()) {
1559 else if (isDistributed () !=
map.isDistributed ()) {
1564 else if (isContiguous () && isUniform () &&
1565 map.isContiguous () &&
map.isUniform ()) {
1594 template <
class LO,
class GO,
class DT>
1597 FillLgMap (
const Kokkos::View<GO*, DT>&
lgMap,
1601 Kokkos::RangePolicy<LO, typename DT::execution_space>
1602 range (
static_cast<LO
> (0),
static_cast<LO
> (
lgMap.size ()));
1603 Kokkos::parallel_for (
range, *
this);
1606 KOKKOS_INLINE_FUNCTION
void operator () (
const LO& lid)
const {
1607 lgMap_(lid) = startGid_ +
static_cast<GO
> (lid);
1611 const Kokkos::View<GO*, DT> lgMap_;
1618 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1619 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_type
1626 using lg_view_type =
typename const_lg_view_type::non_const_type;
1627 const bool debug = Details::Behavior::debug(
"Map");
1628 const bool verbose = Details::Behavior::verbose(
"Map");
1630 std::unique_ptr<std::string>
prefix;
1632 prefix = Details::createPrefix(
1633 comm_.getRawPtr(),
"Map",
"getMyGlobalIndices");
1634 std::ostringstream
os;
1636 std::cerr <<
os.str();
1643 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1647 std::ostringstream
os;
1649 std::cerr <<
os.str();
1655 (! isContiguous(), std::logic_error,
1656 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1657 "mapping (lgMap_) should have been set up already for a "
1658 "noncontiguous Map. Please report this bug to the Tpetra "
1661 const LO
numElts =
static_cast<LO
> (getLocalNumElements ());
1663 using Kokkos::view_alloc;
1664 using Kokkos::WithoutInitializing;
1667 std::ostringstream
os;
1669 std::cerr <<
os.str();
1674 std::ostringstream
os;
1676 std::cerr <<
os.str();
1679 auto lgMapHost = Kokkos::create_mirror_view (Kokkos::HostSpace (),
lgMap);
1697 std::ostringstream
os;
1699 std::cerr <<
os.str();
1705 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1706 typename Map<LocalOrdinal,GlobalOrdinal,Node>::global_indices_array_device_type
1713 using lg_view_type =
typename const_lg_view_type::non_const_type;
1714 const bool debug = Details::Behavior::debug(
"Map");
1715 const bool verbose = Details::Behavior::verbose(
"Map");
1717 std::unique_ptr<std::string>
prefix;
1719 prefix = Details::createPrefix(
1720 comm_.getRawPtr(),
"Map",
"getMyGlobalIndicesDevice");
1721 std::ostringstream
os;
1723 std::cerr <<
os.str();
1730 lgMap_.extent (0) == 0 && numLocalElements_ > 0;
1734 std::ostringstream
os;
1736 std::cerr <<
os.str();
1742 (! isContiguous(), std::logic_error,
1743 "Tpetra::Map::getMyGlobalIndices: The local-to-global "
1744 "mapping (lgMap_) should have been set up already for a "
1745 "noncontiguous Map. Please report this bug to the Tpetra "
1748 const LO
numElts =
static_cast<LO
> (getLocalNumElements ());
1750 using Kokkos::view_alloc;
1751 using Kokkos::WithoutInitializing;
1754 std::ostringstream
os;
1756 std::cerr <<
os.str();
1765 std::ostringstream
os;
1767 std::cerr <<
os.str();
1774 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1775 Teuchos::ArrayView<const GlobalOrdinal>
1783 (
void) this->getMyGlobalIndices ();
1791 return Teuchos::ArrayView<const GO>(
1793 lgMapHost_.extent (0),
1794 Teuchos::RCP_DISABLE_NODE_LOOKUP);
1797 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1799 return distributed_;
1802 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1804 using Teuchos::TypeNameTraits;
1805 std::ostringstream
os;
1807 os <<
"Tpetra::Map: {"
1814 os <<
", Global number of entries: " << getGlobalNumElements ()
1815 <<
", Number of processes: " << getComm ()->getSize ()
1816 <<
", Uniform: " << (isUniform () ?
"true" :
"false")
1817 <<
", Contiguous: " << (isContiguous () ?
"true" :
"false")
1818 <<
", Distributed: " << (isDistributed () ?
"true" :
"false")
1827 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1832 using LO = local_ordinal_type;
1836 if (
vl < Teuchos::VERB_HIGH) {
1837 return std::string ();
1839 auto outStringP = Teuchos::rcp (
new std::ostringstream ());
1840 Teuchos::RCP<Teuchos::FancyOStream> outp =
1841 Teuchos::getFancyOStream (outStringP);
1842 Teuchos::FancyOStream& out = *outp;
1844 auto comm = this->getComm ();
1845 const int myRank = comm->getRank ();
1846 const int numProcs = comm->getSize ();
1847 out <<
"Process " << myRank <<
" of " << numProcs <<
":" << endl;
1848 Teuchos::OSTab tab1 (out);
1850 const LO numEnt =
static_cast<LO
> (this->getLocalNumElements ());
1851 out <<
"My number of entries: " << numEnt << endl
1852 <<
"My minimum global index: " << this->getMinGlobalIndex () << endl
1853 <<
"My maximum global index: " << this->getMaxGlobalIndex () << endl;
1855 if (vl == Teuchos::VERB_EXTREME) {
1856 out <<
"My global indices: [";
1857 const LO minLclInd = this->getMinLocalIndex ();
1858 for (LO k = 0; k < numEnt; ++k) {
1859 out << minLclInd + this->getGlobalElement (k);
1860 if (k + 1 < numEnt) {
1868 return outStringP->str ();
1871 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1875 const Teuchos::EVerbosityLevel
verbLevel)
const
1877 using Teuchos::TypeNameTraits;
1878 using Teuchos::VERB_DEFAULT;
1879 using Teuchos::VERB_NONE;
1880 using Teuchos::VERB_LOW;
1881 using Teuchos::VERB_HIGH;
1885 const Teuchos::EVerbosityLevel
vl =
1895 auto comm = this->getComm ();
1896 if (comm.is_null ()) {
1899 const int myRank = comm->getRank ();
1900 const int numProcs = comm->getSize ();
1909 Teuchos::RCP<Teuchos::OSTab>
tab0,
tab1;
1915 tab0 = Teuchos::rcp (
new Teuchos::OSTab (
out));
1916 out <<
"\"Tpetra::Map\":" <<
endl;
1917 tab1 = Teuchos::rcp (
new Teuchos::OSTab (
out));
1919 out <<
"Template parameters:" <<
endl;
1927 out <<
"Label: \"" << label <<
"\"" <<
endl;
1929 out <<
"Global number of entries: " << getGlobalNumElements () <<
endl
1930 <<
"Minimum global index: " << getMinAllGlobalIndex () <<
endl
1931 <<
"Maximum global index: " << getMaxAllGlobalIndex () <<
endl
1932 <<
"Index base: " << getIndexBase () <<
endl
1934 <<
"Uniform: " << (isUniform () ?
"true" :
"false") <<
endl
1935 <<
"Contiguous: " << (isContiguous () ?
"true" :
"false") <<
endl
1936 <<
"Distributed: " << (isDistributed () ?
"true" :
"false") <<
endl;
1941 const std::string
lclStr = this->localDescribeToString (
vl);
1946 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
1947 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
1966 return Teuchos::null;
1968 else if (
newComm->getSize () == 1) {
1981 newMap->indexBase_ = this->indexBase_;
1982 newMap->numGlobalElements_ = this->numLocalElements_;
1983 newMap->numLocalElements_ = this->numLocalElements_;
1984 newMap->minMyGID_ = this->minMyGID_;
1985 newMap->maxMyGID_ = this->maxMyGID_;
1986 newMap->minAllGID_ = this->minMyGID_;
1987 newMap->maxAllGID_ = this->maxMyGID_;
1988 newMap->firstContiguousGID_ = this->firstContiguousGID_;
1989 newMap->lastContiguousGID_ = this->lastContiguousGID_;
1992 newMap->uniform_ = this->uniform_;
1993 newMap->contiguous_ = this->contiguous_;
1996 newMap->distributed_ =
false;
1997 newMap->lgMap_ = this->lgMap_;
1998 newMap->lgMapHost_ = this->lgMapHost_;
1999 newMap->glMap_ = this->glMap_;
2000 newMap->glMapHost_ = this->glMapHost_;
2021 const GST RECOMPUTE = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2037 auto lgMap = this->getMyGlobalIndices ();
2039 typename std::decay<
decltype (
lgMap.extent (0)) >::type;
2041 static_cast<size_type
> (this->getLocalNumElements ());
2042 using Teuchos::TypeNameTraits;
2045 "Tpetra::Map::replaceCommWithSubset: Result of getMyGlobalIndices() "
2046 "has length " <<
lgMap.extent (0) <<
" (of type " <<
2048 " = " <<
this->getLocalNumElements () <<
". The latter, upon being "
2050 "becomes " <<
lclNumInds <<
". Please report this bug to the Tpetra "
2053 Teuchos::ArrayView<const GO>
lgMap = this->getLocalElementList ();
2056 const GO
indexBase = this->getIndexBase ();
2063 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2064 Teuchos::RCP<const Map<LocalOrdinal, GlobalOrdinal, Node> >
2068 using Teuchos::Comm;
2069 using Teuchos::null;
2070 using Teuchos::outArg;
2073 using Teuchos::REDUCE_MIN;
2074 using Teuchos::reduceAll;
2081 const int color = (numLocalElements_ == 0) ? 0 : 1;
2098 map->indexBase_ = indexBase_;
2099 map->numGlobalElements_ = numGlobalElements_;
2100 map->numLocalElements_ = numLocalElements_;
2101 map->minMyGID_ = minMyGID_;
2102 map->maxMyGID_ = maxMyGID_;
2103 map->minAllGID_ = minAllGID_;
2104 map->maxAllGID_ = maxAllGID_;
2105 map->firstContiguousGID_= firstContiguousGID_;
2106 map->lastContiguousGID_ = lastContiguousGID_;
2110 map->uniform_ = uniform_;
2111 map->contiguous_ = contiguous_;
2126 if (! distributed_ ||
newComm->getSize () == 1) {
2127 map->distributed_ =
false;
2129 const int iOwnAllGids = (numLocalElements_ == numGlobalElements_) ? 1 : 0;
2135 map->lgMap_ = lgMap_;
2136 map->lgMapHost_ = lgMapHost_;
2137 map->glMap_ = glMap_;
2138 map->glMapHost_ = glMapHost_;
2155 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2160 directory_.is_null (), std::logic_error,
"Tpetra::Map::setupDirectory: "
2161 "The Directory is null. "
2162 "Please report this bug to the Tpetra developers.");
2166 if (! directory_->initialized ()) {
2167 directory_->initialize (*
this);
2171 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2175 const Teuchos::ArrayView<int>&
PIDs,
2176 const Teuchos::ArrayView<LocalOrdinal>&
LIDs)
const
2178 using Tpetra::Details::OrdinalTraits;
2179 using Details::verbosePrintArray;
2181 using size_type = Teuchos::ArrayView<int>::size_type;
2183 const bool verbose = Details::Behavior::verbose(
"Map");
2185 Details::Behavior::verbosePrintCountThreshold() :
size_t(0);
2186 std::unique_ptr<std::string>
prefix;
2188 prefix = Details::createPrefix(comm_.getRawPtr(),
2189 "Map",
"getRemoteIndexList(GIDs,PIDs,LIDs)");
2190 std::ostringstream
os;
2194 std::cerr <<
os.str();
2203 if (getGlobalNumElements () == 0) {
2204 if (
GIDs.size () == 0) {
2206 std::ostringstream
os;
2207 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2208 std::cerr <<
os.str();
2214 std::ostringstream
os;
2215 os << *
prefix <<
"Done: Map is empty on all processes, "
2216 "so all output PIDs & LIDs are invalid (-1)." <<
endl;
2217 std::cerr <<
os.str();
2219 for (size_type
k = 0;
k <
PIDs.size (); ++
k) {
2222 for (size_type
k = 0;
k <
LIDs.size (); ++
k) {
2234 std::ostringstream
os;
2236 std::cerr <<
os.str();
2240 std::ostringstream
os;
2241 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2242 std::cerr <<
os.str();
2245 directory_->getDirectoryEntries (*
this,
GIDs,
PIDs,
LIDs);
2247 std::ostringstream
os;
2248 os << *
prefix <<
"Done; getDirectoryEntries returned "
2255 std::cerr <<
os.str();
2260 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2264 const Teuchos::ArrayView<int> &
PIDs)
const
2266 using Details::verbosePrintArray;
2269 const bool verbose = Details::Behavior::verbose(
"Map");
2271 Details::Behavior::verbosePrintCountThreshold() :
size_t(0);
2272 std::unique_ptr<std::string>
prefix;
2274 prefix = Details::createPrefix(comm_.getRawPtr(),
2275 "Map",
"getRemoteIndexList(GIDs,PIDs)");
2276 std::ostringstream
os;
2280 std::cerr <<
os.str();
2283 if (getGlobalNumElements () == 0) {
2284 if (
GIDs.size () == 0) {
2286 std::ostringstream
os;
2287 os << *
prefix <<
"Done; both Map & input are empty" <<
endl;
2288 std::cerr <<
os.str();
2294 std::ostringstream
os;
2295 os << *
prefix <<
"Done: Map is empty on all processes, "
2296 "so all output PIDs are invalid (-1)." <<
endl;
2297 std::cerr <<
os.str();
2299 for (Teuchos::ArrayView<int>::size_type
k = 0;
k <
PIDs.size (); ++
k) {
2300 PIDs[
k] = Tpetra::Details::OrdinalTraits<int>::invalid ();
2311 std::ostringstream
os;
2313 std::cerr <<
os.str();
2317 std::ostringstream
os;
2318 os << *
prefix <<
"Call directory_->getDirectoryEntries" <<
endl;
2319 std::cerr <<
os.str();
2322 directory_->getDirectoryEntries(*
this,
GIDs,
PIDs);
2324 std::ostringstream
os;
2325 os << *
prefix <<
"Done; getDirectoryEntries returned "
2330 std::cerr <<
os.str();
2335 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2338 using exec_space =
typename Node::device_type::execution_space;
2339 if(lgMap_.extent(0) != lgMapHost_.extent(0)) {
2345 auto lgMap_host = Kokkos::create_mirror(Kokkos::HostSpace (), lgMap_);
2354 glMapHost_ = global_to_local_table_host_type(glMap_);
2359 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2360 Teuchos::RCP<const Teuchos::Comm<int> >
2365 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2371 using Teuchos::outArg;
2372 using Teuchos::REDUCE_MIN;
2373 using Teuchos::reduceAll;
2376 const bool verbose = Details::Behavior::verbose(
"Map");
2377 std::unique_ptr<std::string>
prefix;
2379 prefix = Details::createPrefix(
2380 comm_.getRawPtr(),
"Map",
"checkIsDist");
2381 std::ostringstream
os;
2383 std::cerr <<
os.str();
2386 bool global =
false;
2387 if (comm_->getSize () > 1) {
2391 if (numGlobalElements_ == as<global_size_t> (numLocalElements_)) {
2404 reduceAll<int, int> (*comm_, REDUCE_MIN, localRep, outArg (allLocalRep));
2405 if (allLocalRep != 1) {
2415 std::ostringstream os;
2416 os << *prefix <<
"Done; global=" << (global ?
"true" :
"false")
2418 std::cerr << os.str();
2425template <
class LocalOrdinal,
class GlobalOrdinal>
2426Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2428 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2430 typedef LocalOrdinal LO;
2431 typedef GlobalOrdinal GO;
2432 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2433 return createLocalMapWithNode<LO, GO, NT> (numElements, comm);
2436template <
class LocalOrdinal,
class GlobalOrdinal>
2437Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2439 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2441 typedef LocalOrdinal LO;
2442 typedef GlobalOrdinal GO;
2443 using NT = typename ::Tpetra::Map<LO, GO>::node_type;
2444 return createUniformContigMapWithNode<LO, GO, NT> (numElements, comm);
2447template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2448Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2450 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2455 const GlobalOrdinal indexBase =
static_cast<GlobalOrdinal
> (0);
2457 return rcp (
new map_type (numElements, indexBase, comm, GloballyDistributed));
2460template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2461Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2463 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2469 const GlobalOrdinal indexBase = 0;
2472 return rcp (
new map_type (globalNumElts, indexBase, comm, LocallyReplicated));
2475template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2476Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2478 const size_t localNumElements,
2479 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2484 const GlobalOrdinal indexBase = 0;
2486 return rcp (
new map_type (numElements, localNumElements, indexBase, comm));
2489template <
class LocalOrdinal,
class GlobalOrdinal>
2490Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2492 const size_t localNumElements,
2493 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2495 typedef LocalOrdinal LO;
2496 typedef GlobalOrdinal GO;
2502template <
class LocalOrdinal,
class GlobalOrdinal>
2503Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal> >
2505 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm)
2507 typedef LocalOrdinal LO;
2508 typedef GlobalOrdinal GO;
2514template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2515Teuchos::RCP< const Tpetra::Map<LocalOrdinal, GlobalOrdinal, Node> >
2517 const Teuchos::RCP<
const Teuchos::Comm<int> >& comm
2523 const GST INV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2527 const GlobalOrdinal indexBase = 0;
2529 return rcp (
new map_type (INV, elementList, indexBase, comm));
2532template<
class LO,
class GO,
class NT>
2533Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >
2536 using Details::verbosePrintArray;
2537 using Teuchos::Array;
2538 using Teuchos::ArrayView;
2546 const bool verbose = Details::Behavior::verbose(
"Map");
2547 std::unique_ptr<std::string> prefix;
2549 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2550 prefix = Details::createPrefix(
2551 comm.getRawPtr(),
"createOneToOne(Map)");
2552 std::ostringstream os;
2553 os << *prefix <<
"Start" << endl;
2556 const size_t maxNumToPrint = verbose ?
2557 Details::Behavior::verbosePrintCountThreshold() : size_t(0);
2558 const GST GINV = Tpetra::Details::OrdinalTraits<GST>::invalid ();
2559 const int myRank = M->getComm ()->getRank ();
2565 if (! M->isDistributed ()) {
2572 const GST numGlobalEntries = M->getGlobalNumElements ();
2573 if (M->isContiguous()) {
2574 const size_t numLocalEntries =
2575 (myRank == 0) ? as<size_t>(numGlobalEntries) : size_t(0);
2577 std::ostringstream os;
2578 os << *prefix <<
"Input is locally replicated & contiguous; "
2579 "numLocalEntries=" << numLocalEntries << endl;
2583 rcp(
new map_type(numGlobalEntries, numLocalEntries,
2584 M->getIndexBase(), M->getComm()));
2586 std::ostringstream os;
2587 os << *prefix <<
"Done" << endl;
2594 std::ostringstream os;
2595 os << *prefix <<
"Input is locally replicated & noncontiguous"
2599 ArrayView<const GO> myGids =
2600 (myRank == 0) ? M->getLocalElementList() : Teuchos::null;
2602 rcp(
new map_type(GINV, myGids(), M->getIndexBase(),
2605 std::ostringstream os;
2606 os << *prefix <<
"Done" << endl;
2612 else if (M->isContiguous ()) {
2614 std::ostringstream os;
2615 os << *prefix <<
"Input is distributed & contiguous" << endl;
2624 std::ostringstream os;
2625 os << *prefix <<
"Input is distributed & noncontiguous" << endl;
2629 const size_t numMyElems = M->getLocalNumElements ();
2630 ArrayView<const GO> myElems = M->getLocalElementList ();
2631 Array<int> owner_procs_vec (numMyElems);
2634 std::ostringstream os;
2635 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2640 directory.getDirectoryEntries (*M, myElems, owner_procs_vec ());
2642 std::ostringstream os;
2643 os << *prefix <<
"getDirectoryEntries result: ";
2649 Array<GO> myOwned_vec (numMyElems);
2650 size_t numMyOwnedElems = 0;
2651 for (
size_t i = 0; i < numMyElems; ++i) {
2652 const GO GID = myElems[i];
2653 const int owner = owner_procs_vec[i];
2655 if (myRank == owner) {
2656 myOwned_vec[numMyOwnedElems++] = GID;
2659 myOwned_vec.resize (numMyOwnedElems);
2662 std::ostringstream os;
2663 os << *prefix <<
"Create Map: ";
2668 auto retMap = rcp(
new map_type(GINV, myOwned_vec(),
2669 M->getIndexBase(), M->getComm()));
2671 std::ostringstream os;
2672 os << *prefix <<
"Done" << endl;
2679template<
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2680Teuchos::RCP<const Tpetra::Map<LocalOrdinal,GlobalOrdinal,Node> >
2684 using Details::Behavior;
2685 using Details::verbosePrintArray;
2686 using Teuchos::Array;
2687 using Teuchos::ArrayView;
2690 using Teuchos::toString;
2693 using LO = LocalOrdinal;
2694 using GO = GlobalOrdinal;
2697 const bool verbose = Behavior::verbose(
"Map");
2698 std::unique_ptr<std::string> prefix;
2700 auto comm = M.is_null() ? Teuchos::null : M->getComm();
2701 prefix = Details::createPrefix(
2702 comm.getRawPtr(),
"createOneToOne(Map,TieBreak)");
2703 std::ostringstream os;
2704 os << *prefix <<
"Start" << endl;
2707 const size_t maxNumToPrint = verbose ?
2708 Behavior::verbosePrintCountThreshold() : size_t(0);
2715 std::ostringstream os;
2716 os << *prefix <<
"Initialize Directory" << endl;
2719 directory.initialize (*M, tie_break);
2721 std::ostringstream os;
2722 os << *prefix <<
"Done initializing Directory" << endl;
2725 size_t numMyElems = M->getLocalNumElements ();
2726 ArrayView<const GO> myElems = M->getLocalElementList ();
2727 Array<int> owner_procs_vec (numMyElems);
2729 std::ostringstream os;
2730 os << *prefix <<
"Call Directory::getDirectoryEntries: ";
2735 directory.getDirectoryEntries (*M, myElems, owner_procs_vec ());
2737 std::ostringstream os;
2738 os << *prefix <<
"getDirectoryEntries result: ";
2744 const int myRank = M->getComm()->getRank();
2745 Array<GO> myOwned_vec (numMyElems);
2746 size_t numMyOwnedElems = 0;
2747 for (
size_t i = 0; i < numMyElems; ++i) {
2748 const GO GID = myElems[i];
2749 const int owner = owner_procs_vec[i];
2750 if (myRank == owner) {
2751 myOwned_vec[numMyOwnedElems++] = GID;
2754 myOwned_vec.resize (numMyOwnedElems);
2759 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
2761 std::ostringstream os;
2762 os << *prefix <<
"Create Map: ";
2767 RCP<const map_type> retMap
2768 (
new map_type (GINV, myOwned_vec (), M->getIndexBase (),
2771 std::ostringstream os;
2772 os << *prefix <<
"Done" << endl;
2786#define TPETRA_MAP_INSTANT(LO,GO,NODE) \
2788 template class Map< LO , GO , NODE >; \
2790 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2791 createLocalMapWithNode<LO,GO,NODE> (const size_t numElements, \
2792 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2794 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2795 createContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2796 const size_t localNumElements, \
2797 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2799 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2800 createNonContigMapWithNode(const Teuchos::ArrayView<const GO> &elementList, \
2801 const Teuchos::RCP<const Teuchos::Comm<int> > &comm); \
2803 template Teuchos::RCP< const Map<LO,GO,NODE> > \
2804 createUniformContigMapWithNode<LO,GO,NODE> (const global_size_t numElements, \
2805 const Teuchos::RCP< const Teuchos::Comm< int > >& comm); \
2807 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2808 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M); \
2810 template Teuchos::RCP<const Map<LO,GO,NODE> > \
2811 createOneToOne (const Teuchos::RCP<const Map<LO,GO,NODE> >& M, \
2812 const Tpetra::Details::TieBreak<LO,GO>& tie_break); \
2816#define TPETRA_MAP_INSTANT_DEFAULTNODE(LO,GO) \
2817 template Teuchos::RCP< const Map<LO,GO> > \
2818 createLocalMap<LO,GO>( const size_t, const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2820 template Teuchos::RCP< const Map<LO,GO> > \
2821 createContigMap<LO,GO>( global_size_t, size_t, \
2822 const Teuchos::RCP< const Teuchos::Comm< int > > &); \
2824 template Teuchos::RCP< const Map<LO,GO> > \
2825 createNonContigMap(const Teuchos::ArrayView<const GO> &, \
2826 const Teuchos::RCP<const Teuchos::Comm<int> > &); \
2828 template Teuchos::RCP< const Map<LO,GO> > \
2829 createUniformContigMap<LO,GO>( const global_size_t, \
2830 const Teuchos::RCP< const Teuchos::Comm< int > > &); \