62 #include "Tpetra_Map.hpp"
63 #include "Tpetra_Import.hpp"
66 #include "Teuchos_FancyOStream.hpp"
78 template<
class MapType>
81 using local_ordinal_type =
typename MapType::local_ordinal_type;
82 using global_ordinal_type =
typename MapType::global_ordinal_type;
83 using node_type =
typename MapType::node_type;
87 static Teuchos::RCP<const map_type>
88 makeOptColMap (std::ostream& errStream,
94 using ::Tpetra::Details::Behavior;
96 using Teuchos::ArrayView;
97 using Teuchos::FancyOStream;
98 using Teuchos::getFancyOStream;
101 using Teuchos::rcpFromRef;
103 using LO = local_ordinal_type;
104 using GO = global_ordinal_type;
105 const char prefix[] =
"Tpetra::Details::makeOptimizedColMap: ";
107 RCP<const Teuchos::Comm<int> > comm = colMap.
getComm ();
108 std::ostream& err = errStream;
112 RCP<FancyOStream> outPtr = getFancyOStream (rcpFromRef (std::cerr));
113 TEUCHOS_TEST_FOR_EXCEPTION
114 (outPtr.is_null (), std::logic_error,
115 "outPtr is null; this should never happen!");
116 FancyOStream& out = *outPtr;
117 Teuchos::OSTab tab1 (out);
119 std::unique_ptr<std::string> verboseHeader;
121 std::ostringstream os;
122 const int myRank = comm->getRank ();
123 os <<
"Proc " << myRank <<
": ";
124 verboseHeader = std::unique_ptr<std::string> (
new std::string (os.str ()));
127 std::ostringstream os;
128 os << *verboseHeader <<
"Tpetra::Details::makeOptimizedColMap" << endl;
133 std::ostringstream os;
134 os << *verboseHeader <<
"Domain Map GIDs: [";
136 for (LO lid = 0; lid < domMapLclNumInds; ++lid) {
139 if (lid + LO (1) < domMapLclNumInds) {
150 std::ostringstream os;
151 os << *verboseHeader <<
"Column Map GIDs: [";
152 for (LO lid = 0; lid < colMapLclNumInds; ++lid) {
155 if (lid + LO (1) < colMapLclNumInds) {
165 LO numRemoteGids = 0;
166 for (LO colMapLid = 0; colMapLid < colMapLclNumInds; ++colMapLid) {
177 std::ostringstream os;
178 os << *verboseHeader <<
"- numOwnedGids: " << numOwnedGids << endl
179 << *verboseHeader <<
"- numRemoteGids: " << numRemoteGids << endl;
185 Array<GO> allGids (numOwnedGids + numRemoteGids);
186 ArrayView<GO> ownedGids = allGids.view (0, numOwnedGids);
187 ArrayView<GO> remoteGids = allGids.view (numOwnedGids, numRemoteGids);
196 for (LO colMapLid = 0; colMapLid < colMapLclNumInds; ++colMapLid) {
199 ownedGids[ownedPos++] = colMapGid;
202 remoteGids[remotePos++] = colMapGid;
211 if (ownedPos != numOwnedGids) {
213 err << prefix <<
"On Process " << comm->getRank () <<
", ownedPos = "
214 << ownedPos <<
" != numOwnedGids = " << numOwnedGids << endl;
215 for (LO colMapLid = ownedPos; colMapLid < numOwnedGids; ++colMapLid) {
216 ownedGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid ();
219 if (remotePos != numRemoteGids) {
221 err << prefix <<
"On Process " << comm->getRank () <<
", remotePos = "
222 << remotePos <<
" != numRemoteGids = " << numRemoteGids << endl;
223 for (LO colMapLid = remotePos; colMapLid < numRemoteGids; ++colMapLid) {
224 remoteGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid ();
232 Array<int> remotePids (numRemoteGids, -1);
242 const bool getRemoteIndexListFailed = (lookupStatus ==
IDNotPresent);
243 if (getRemoteIndexListFailed) {
245 err << prefix <<
"On Process " << comm->getRank () <<
", some indices "
246 "in the input colMap (the original column Map) are not in domMap (the "
247 "domain Map). Either these indices or the domain Map is invalid. "
248 "Likely cause: For a nonsquare matrix, you must give the domain and "
249 "range Maps as input to fillComplete." << endl;
254 for (LO k = 0; k < numRemoteGids; ++k) {
255 bool foundInvalidPid =
false;
256 if (remotePids[k] == -1) {
257 foundInvalidPid =
true;
260 if (foundInvalidPid) {
262 err << prefix <<
"On Process " << comm->getRank () <<
", "
263 "getRemoteIndexList returned -1 for the process ranks of "
264 "one or more GIDs on this process." << endl;
269 std::ostringstream os;
270 os << *verboseHeader <<
"- Before sort2:" << endl
271 << *verboseHeader <<
"-- ownedGids: " << Teuchos::toString (ownedGids) << endl
272 << *verboseHeader <<
"-- remoteGids: " << Teuchos::toString (remoteGids) << endl
273 << *verboseHeader <<
"-- allGids: " << Teuchos::toString (allGids ()) << endl;
277 sort2 (remotePids.begin (), remotePids.end (), remoteGids.begin ());
279 std::ostringstream os;
280 os << *verboseHeader <<
"- After sort2:" << endl
281 << *verboseHeader <<
"-- ownedGids: " << Teuchos::toString (ownedGids) << endl
282 << *verboseHeader <<
"-- remoteGids: " << Teuchos::toString (remoteGids) << endl
283 << *verboseHeader <<
"-- allGids: " << Teuchos::toString (allGids ()) << endl;
292 std::ostringstream os;
293 os << *verboseHeader <<
"Tpetra::Details::makeOptimizedColMap: Done" << endl;
329 static std::pair<Teuchos::RCP<const map_type>,
330 Teuchos::RCP<import_type> >
343 RCP<const map_type> newColMap =
344 makeOptColMap (errStream, lclErr, domMap, colMap, oldImport);
353 return std::make_pair (newColMap, imp);
381 template<
class MapType>
382 Teuchos::RCP<const MapType>
385 const MapType& domMap,
386 const MapType& colMap,
388 typename MapType::local_ordinal_type,
389 typename MapType::global_ordinal_type,
390 typename MapType::node_type>* oldImport =
nullptr)
393 typename MapType::local_ordinal_type,
394 typename MapType::global_ordinal_type,
395 typename MapType::node_type>;
397 auto mapPtr = impl_type::makeOptColMap (errStream, lclErr,
398 domMap, colMap, oldImport);
458 template<
class MapType>
459 std::pair<Teuchos::RCP<const MapType>,
460 Teuchos::RCP<typename OptColMap<MapType>::import_type> >
463 const MapType& domMap,
464 const MapType& colMap,
467 using local_ordinal_type =
typename MapType::local_ordinal_type;
468 using global_ordinal_type =
typename MapType::global_ordinal_type;
469 using node_type =
typename MapType::node_type;
473 auto mapAndImp = impl_type::makeOptColMapAndImport (errStream, lclErr, domMap, colMap, oldImport);
474 return std::make_pair (mapAndImp.first, mapAndImp.second);
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is owned by this Map on the calling process.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
GlobalOrdinal getIndexBase() const
The index base for this Map.
Teuchos::RCP< const Teuchos::Comm< int > > getComm() const
Accessors for the Teuchos::Comm and Kokkos Node objects.
Implementation detail of makeOptimizedColMap, and makeOptimizedColMapAndImport.
std::pair< Teuchos::RCP< const MapType >, Teuchos::RCP< typename OptColMap< MapType >::import_type > > makeOptimizedColMapAndImport(std::ostream &errStream, bool &lclErr, const MapType &domMap, const MapType &colMap, const typename OptColMap< MapType >::import_type *oldImport=nullptr)
Return an optimized reordering of the given column Map. Optionally, recompute an Import from the inpu...
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
static bool verbose()
Whether Tpetra is in verbose mode.
LookupStatus getRemoteIndexList(const Teuchos::ArrayView< const GlobalOrdinal > &GIDList, const Teuchos::ArrayView< int > &nodeIDList, const Teuchos::ArrayView< LocalOrdinal > &LIDList) const
Return the process ranks and corresponding local indices for the given global indices.
void sort2(const IT1 &first1, const IT1 &last1, const IT2 &first2)
Sort the first array, and apply the resulting permutation to the second array.
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
A parallel distribution of indices over processes.
Stand-alone utility functions and macros.
Teuchos::RCP< const MapType > makeOptimizedColMap(std::ostream &errStream, bool &lclErr, const MapType &domMap, const MapType &colMap, const Tpetra::Import< typename MapType::local_ordinal_type, typename MapType::global_ordinal_type, typename MapType::node_type > *oldImport=nullptr)
Return an optimized reordering of the given column Map.
static std::pair< Teuchos::RCP< const map_type >, Teuchos::RCP< import_type > > makeOptColMapAndImport(std::ostream &errStream, bool &lclErr, const map_type &domMap, const map_type &colMap, const import_type *oldImport)
Return an optimized reordering of the given column Map. Optionally, recompute an Import from the inpu...
global_size_t getGlobalNumElements() const
The number of elements in this Map.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.