28 #include "Tpetra_Map.hpp"
29 #include "Tpetra_Import.hpp"
32 #include "Teuchos_FancyOStream.hpp"
44 template <
class MapType>
47 using local_ordinal_type =
typename MapType::local_ordinal_type;
48 using global_ordinal_type =
typename MapType::global_ordinal_type;
49 using node_type =
typename MapType::node_type;
53 static Teuchos::RCP<const map_type>
54 makeOptColMap(std::ostream& errStream,
61 using Teuchos::ArrayView;
62 using Teuchos::FancyOStream;
63 using Teuchos::getFancyOStream;
66 using Teuchos::rcpFromRef;
67 using ::Tpetra::Details::Behavior;
68 using LO = local_ordinal_type;
69 using GO = global_ordinal_type;
70 const char prefix[] =
"Tpetra::Details::makeOptimizedColMap: ";
72 RCP<const Teuchos::Comm<int> > comm = colMap.
getComm();
73 std::ostream& err = errStream;
77 RCP<FancyOStream> outPtr = getFancyOStream(rcpFromRef(std::cerr));
78 TEUCHOS_TEST_FOR_EXCEPTION(outPtr.is_null(), std::logic_error,
79 "outPtr is null; this should never happen!");
80 FancyOStream& out = *outPtr;
81 Teuchos::OSTab tab1(out);
83 std::unique_ptr<std::string> verboseHeader;
85 std::ostringstream os;
86 const int myRank = comm->getRank();
87 os <<
"Proc " << myRank <<
": ";
88 verboseHeader = std::unique_ptr<std::string>(
new std::string(os.str()));
91 std::ostringstream os;
92 os << *verboseHeader <<
"Tpetra::Details::makeOptimizedColMap" << endl;
97 std::ostringstream os;
98 os << *verboseHeader <<
"Domain Map GIDs: [";
100 for (LO lid = 0; lid < domMapLclNumInds; ++lid) {
103 if (lid + LO(1) < domMapLclNumInds) {
114 std::ostringstream os;
115 os << *verboseHeader <<
"Column Map GIDs: [";
116 for (LO lid = 0; lid < colMapLclNumInds; ++lid) {
119 if (lid + LO(1) < colMapLclNumInds) {
129 LO numRemoteGids = 0;
130 for (LO colMapLid = 0; colMapLid < colMapLclNumInds; ++colMapLid) {
140 std::ostringstream os;
141 os << *verboseHeader <<
"- numOwnedGids: " << numOwnedGids << endl
142 << *verboseHeader <<
"- numRemoteGids: " << numRemoteGids << endl;
148 Array<GO> allGids(numOwnedGids + numRemoteGids);
149 ArrayView<GO> ownedGids = allGids.view(0, numOwnedGids);
150 ArrayView<GO> remoteGids = allGids.view(numOwnedGids, numRemoteGids);
159 for (LO colMapLid = 0; colMapLid < colMapLclNumInds; ++colMapLid) {
162 ownedGids[ownedPos++] = colMapGid;
164 remoteGids[remotePos++] = colMapGid;
173 if (ownedPos != numOwnedGids) {
175 err << prefix <<
"On Process " << comm->getRank() <<
", ownedPos = "
176 << ownedPos <<
" != numOwnedGids = " << numOwnedGids << endl;
177 for (LO colMapLid = ownedPos; colMapLid < numOwnedGids; ++colMapLid) {
178 ownedGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid();
181 if (remotePos != numRemoteGids) {
183 err << prefix <<
"On Process " << comm->getRank() <<
", remotePos = "
184 << remotePos <<
" != numRemoteGids = " << numRemoteGids << endl;
185 for (LO colMapLid = remotePos; colMapLid < numRemoteGids; ++colMapLid) {
186 remoteGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid();
194 Array<int> remotePids(numRemoteGids, -1);
204 const bool getRemoteIndexListFailed = (lookupStatus ==
IDNotPresent);
205 if (getRemoteIndexListFailed) {
207 err << prefix <<
"On Process " << comm->getRank() <<
", some indices "
208 "in the input colMap (the original column Map) are not in domMap (the "
209 "domain Map). Either these indices or the domain Map is invalid. "
210 "Likely cause: For a nonsquare matrix, you must give the domain and "
211 "range Maps as input to fillComplete."
217 for (LO k = 0; k < numRemoteGids; ++k) {
218 bool foundInvalidPid =
false;
219 if (remotePids[k] == -1) {
220 foundInvalidPid =
true;
223 if (foundInvalidPid) {
225 err << prefix <<
"On Process " << comm->getRank() <<
", "
226 "getRemoteIndexList returned -1 for the process ranks of "
227 "one or more GIDs on this process."
233 std::ostringstream os;
234 os << *verboseHeader <<
"- Before sort2:" << endl
235 << *verboseHeader <<
"-- ownedGids: " << Teuchos::toString(ownedGids) << endl
236 << *verboseHeader <<
"-- remoteGids: " << Teuchos::toString(remoteGids) << endl
237 << *verboseHeader <<
"-- allGids: " << Teuchos::toString(allGids()) << endl;
241 sort2(remotePids.begin(), remotePids.end(), remoteGids.begin(),
true);
243 std::ostringstream os;
244 os << *verboseHeader <<
"- After sort2:" << endl
245 << *verboseHeader <<
"-- ownedGids: " << Teuchos::toString(ownedGids) << endl
246 << *verboseHeader <<
"-- remoteGids: " << Teuchos::toString(remoteGids) << endl
247 << *verboseHeader <<
"-- allGids: " << Teuchos::toString(allGids()) << endl;
256 std::ostringstream os;
257 os << *verboseHeader <<
"Tpetra::Details::makeOptimizedColMap: Done" << endl;
293 static std::pair<Teuchos::RCP<const map_type>,
294 Teuchos::RCP<import_type> >
306 RCP<const map_type> newColMap =
307 makeOptColMap(errStream, lclErr, domMap, colMap, oldImport);
316 return std::make_pair(newColMap, imp);
344 template <
class MapType>
345 Teuchos::RCP<const MapType>
348 const MapType& domMap,
349 const MapType& colMap,
351 typename MapType::local_ordinal_type,
352 typename MapType::global_ordinal_type,
353 typename MapType::node_type>* oldImport =
nullptr) {
355 typename MapType::local_ordinal_type,
356 typename MapType::global_ordinal_type,
357 typename MapType::node_type>;
359 auto mapPtr = impl_type::makeOptColMap(errStream, lclErr,
360 domMap, colMap, oldImport);
420 template <
class MapType>
421 std::pair<Teuchos::RCP<const MapType>,
422 Teuchos::RCP<typename OptColMap<MapType>::import_type> >
425 const MapType& domMap,
426 const MapType& colMap,
428 using local_ordinal_type =
typename MapType::local_ordinal_type;
429 using global_ordinal_type =
typename MapType::global_ordinal_type;
430 using node_type =
typename MapType::node_type;
434 auto mapAndImp = impl_type::makeOptColMapAndImport(errStream, lclErr, domMap, colMap, oldImport);
435 return std::make_pair(mapAndImp.first, mapAndImp.second);
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
size_t getLocalNumElements() const
The number of elements belonging to the calling process.
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...
global_ordinal_type getIndexBase() const
The index base for this Map.
global_ordinal_type getGlobalElement(local_ordinal_type localIndex) const
The global index corresponding to the given local index.
void sort2(const IT1 &first1, const IT1 &last1, const IT2 &first2, const bool stableSort=false)
Sort the first array, and apply the resulting permutation to the second array.
bool isNodeGlobalElement(global_ordinal_type globalIndex) const
Whether the given global index is owned by this Map on the calling process.
static bool verbose()
Whether Tpetra is in verbose mode.
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...
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.
global_size_t getGlobalNumElements() const
The number of elements in this Map.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.