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,
60 using ::Tpetra::Details::Behavior;
62 using Teuchos::ArrayView;
63 using Teuchos::FancyOStream;
64 using Teuchos::getFancyOStream;
67 using Teuchos::rcpFromRef;
69 using LO = local_ordinal_type;
70 using GO = global_ordinal_type;
71 const char prefix[] =
"Tpetra::Details::makeOptimizedColMap: ";
73 RCP<const Teuchos::Comm<int> > comm = colMap.
getComm ();
74 std::ostream& err = errStream;
78 RCP<FancyOStream> outPtr = getFancyOStream (rcpFromRef (std::cerr));
79 TEUCHOS_TEST_FOR_EXCEPTION
80 (outPtr.is_null (), std::logic_error,
81 "outPtr is null; this should never happen!");
82 FancyOStream& out = *outPtr;
83 Teuchos::OSTab tab1 (out);
85 std::unique_ptr<std::string> verboseHeader;
87 std::ostringstream os;
88 const int myRank = comm->getRank ();
89 os <<
"Proc " << myRank <<
": ";
90 verboseHeader = std::unique_ptr<std::string> (
new std::string (os.str ()));
93 std::ostringstream os;
94 os << *verboseHeader <<
"Tpetra::Details::makeOptimizedColMap" << endl;
99 std::ostringstream os;
100 os << *verboseHeader <<
"Domain Map GIDs: [";
102 for (LO lid = 0; lid < domMapLclNumInds; ++lid) {
105 if (lid + LO (1) < domMapLclNumInds) {
116 std::ostringstream os;
117 os << *verboseHeader <<
"Column Map GIDs: [";
118 for (LO lid = 0; lid < colMapLclNumInds; ++lid) {
121 if (lid + LO (1) < colMapLclNumInds) {
131 LO numRemoteGids = 0;
132 for (LO colMapLid = 0; colMapLid < colMapLclNumInds; ++colMapLid) {
143 std::ostringstream os;
144 os << *verboseHeader <<
"- numOwnedGids: " << numOwnedGids << endl
145 << *verboseHeader <<
"- numRemoteGids: " << numRemoteGids << endl;
151 Array<GO> allGids (numOwnedGids + numRemoteGids);
152 ArrayView<GO> ownedGids = allGids.view (0, numOwnedGids);
153 ArrayView<GO> remoteGids = allGids.view (numOwnedGids, numRemoteGids);
162 for (LO colMapLid = 0; colMapLid < colMapLclNumInds; ++colMapLid) {
165 ownedGids[ownedPos++] = colMapGid;
168 remoteGids[remotePos++] = colMapGid;
177 if (ownedPos != numOwnedGids) {
179 err << prefix <<
"On Process " << comm->getRank () <<
", ownedPos = "
180 << ownedPos <<
" != numOwnedGids = " << numOwnedGids << endl;
181 for (LO colMapLid = ownedPos; colMapLid < numOwnedGids; ++colMapLid) {
182 ownedGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid ();
185 if (remotePos != numRemoteGids) {
187 err << prefix <<
"On Process " << comm->getRank () <<
", remotePos = "
188 << remotePos <<
" != numRemoteGids = " << numRemoteGids << endl;
189 for (LO colMapLid = remotePos; colMapLid < numRemoteGids; ++colMapLid) {
190 remoteGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid ();
198 Array<int> remotePids (numRemoteGids, -1);
208 const bool getRemoteIndexListFailed = (lookupStatus ==
IDNotPresent);
209 if (getRemoteIndexListFailed) {
211 err << prefix <<
"On Process " << comm->getRank () <<
", some indices "
212 "in the input colMap (the original column Map) are not in domMap (the "
213 "domain Map). Either these indices or the domain Map is invalid. "
214 "Likely cause: For a nonsquare matrix, you must give the domain and "
215 "range Maps as input to fillComplete." << endl;
220 for (LO k = 0; k < numRemoteGids; ++k) {
221 bool foundInvalidPid =
false;
222 if (remotePids[k] == -1) {
223 foundInvalidPid =
true;
226 if (foundInvalidPid) {
228 err << prefix <<
"On Process " << comm->getRank () <<
", "
229 "getRemoteIndexList returned -1 for the process ranks of "
230 "one or more GIDs on this process." << endl;
235 std::ostringstream os;
236 os << *verboseHeader <<
"- Before sort2:" << endl
237 << *verboseHeader <<
"-- ownedGids: " << Teuchos::toString (ownedGids) << endl
238 << *verboseHeader <<
"-- remoteGids: " << Teuchos::toString (remoteGids) << endl
239 << *verboseHeader <<
"-- allGids: " << Teuchos::toString (allGids ()) << endl;
243 sort2 (remotePids.begin (), remotePids.end (), remoteGids.begin (),
true);
245 std::ostringstream os;
246 os << *verboseHeader <<
"- After sort2:" << endl
247 << *verboseHeader <<
"-- ownedGids: " << Teuchos::toString (ownedGids) << endl
248 << *verboseHeader <<
"-- remoteGids: " << Teuchos::toString (remoteGids) << endl
249 << *verboseHeader <<
"-- allGids: " << Teuchos::toString (allGids ()) << endl;
258 std::ostringstream os;
259 os << *verboseHeader <<
"Tpetra::Details::makeOptimizedColMap: Done" << endl;
295 static std::pair<Teuchos::RCP<const map_type>,
296 Teuchos::RCP<import_type> >
309 RCP<const map_type> newColMap =
310 makeOptColMap (errStream, lclErr, domMap, colMap, oldImport);
319 return std::make_pair (newColMap, imp);
347 template<
class MapType>
348 Teuchos::RCP<const MapType>
351 const MapType& domMap,
352 const MapType& colMap,
354 typename MapType::local_ordinal_type,
355 typename MapType::global_ordinal_type,
356 typename MapType::node_type>* oldImport =
nullptr)
359 typename MapType::local_ordinal_type,
360 typename MapType::global_ordinal_type,
361 typename MapType::node_type>;
363 auto mapPtr = impl_type::makeOptColMap (errStream, lclErr,
364 domMap, colMap, oldImport);
424 template<
class MapType>
425 std::pair<Teuchos::RCP<const MapType>,
426 Teuchos::RCP<typename OptColMap<MapType>::import_type> >
429 const MapType& domMap,
430 const MapType& colMap,
433 using local_ordinal_type =
typename MapType::local_ordinal_type;
434 using global_ordinal_type =
typename MapType::global_ordinal_type;
435 using node_type =
typename MapType::node_type;
439 auto mapAndImp = impl_type::makeOptColMapAndImport (errStream, lclErr, domMap, colMap, oldImport);
440 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.