62 #include <Tpetra_Map.hpp> 63 #include <Tpetra_Import.hpp> 75 template<
class MapType>
78 typedef MapType map_type;
79 typedef typename MapType::local_ordinal_type local_ordinal_type;
80 typedef typename MapType::global_ordinal_type global_ordinal_type;
81 typedef typename MapType::node_type node_type;
82 typedef Import<local_ordinal_type,
120 static std::pair<map_type, Teuchos::RCP<import_type> >
123 const map_type& domMap,
124 const map_type& colMap,
126 const bool makeImport)
128 using Teuchos::Array;
129 using Teuchos::ArrayView;
133 typedef local_ordinal_type LO;
134 typedef global_ordinal_type GO;
135 const char prefix[] =
"Tpetra::makeOptimizedColMapAndImport: ";
136 std::ostream& err = errStream;
140 RCP<const Teuchos::Comm<int> > comm = colMap.getComm ();
141 const LO colMapMinLid = colMap.getMinLocalIndex ();
142 const LO colMapMaxLid = colMap.getMaxLocalIndex ();
150 LO numRemoteGids = 0;
151 if (colMap.getNodeNumElements () != 0) {
152 for (LO colMapLid = colMapMinLid; colMapLid <= colMapMaxLid; ++colMapLid) {
153 const GO colMapGid = colMap.getGlobalElement (colMapLid);
154 if (domMap.isNodeLocalElement (colMapGid)) {
164 Array<GO> allGids (numOwnedGids + numRemoteGids);
165 ArrayView<GO> ownedGids = allGids.view (0, numOwnedGids);
166 ArrayView<GO> remoteGids = allGids.view (numOwnedGids, numRemoteGids);
175 if (colMap.getNodeNumElements () != 0) {
176 for (LO colMapLid = colMapMinLid; colMapLid <= colMapMaxLid; ++colMapLid) {
177 const GO colMapGid = colMap.getGlobalElement (colMapLid);
178 if (domMap.isNodeLocalElement (colMapGid)) {
179 ownedGids[ownedPos++] = colMapGid;
181 remoteGids[remotePos++] = colMapGid;
191 if (ownedPos != numOwnedGids) {
193 err << prefix <<
"On Process " << comm->getRank () <<
", ownedPos = " 194 << ownedPos <<
" != numOwnedGids = " << numOwnedGids << endl;
195 for (LO colMapLid = ownedPos; colMapLid < numOwnedGids; ++colMapLid) {
196 ownedGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid ();
199 if (remotePos != numRemoteGids) {
201 err << prefix <<
"On Process " << comm->getRank () <<
", remotePos = " 202 << remotePos <<
" != numRemoteGids = " << numRemoteGids << endl;
203 for (LO colMapLid = remotePos; colMapLid < numRemoteGids; ++colMapLid) {
204 remoteGids[colMapLid] = Teuchos::OrdinalTraits<GO>::invalid ();
212 Array<int> remotePids (numRemoteGids, -1);
213 Array<LO> remoteLids;
215 remoteLids.resize (numRemoteGids);
216 std::fill (remoteLids.begin (), remoteLids.end (),
217 Teuchos::OrdinalTraits<LO>::invalid ());
221 lookupStatus = domMap.getRemoteIndexList (remoteGids, remotePids (),
224 lookupStatus = domMap.getRemoteIndexList (remoteGids, remotePids ());
233 const bool getRemoteIndexListFailed = (lookupStatus ==
IDNotPresent);
234 if (getRemoteIndexListFailed) {
236 err << prefix <<
"On Process " << comm->getRank () <<
", some indices " 237 "in the input colMap (the original column Map) are not in domMap (the " 238 "domain Map). Either these indices or the domain Map is invalid. " 239 "Likely cause: For a nonsquare matrix, you must give the domain and " 240 "range Maps as input to fillComplete." << endl;
245 for (LO k = 0; k < numRemoteGids; ++k) {
246 bool foundInvalidPid =
false;
247 if (remotePids[k] == -1) {
248 foundInvalidPid =
true;
251 if (foundInvalidPid) {
253 err << prefix <<
"On Process " << comm->getRank () <<
", " 254 "getRemoteIndexList returned -1 for the process ranks of " 255 "one or more GIDs on this process." << endl;
263 sort2 (remotePids.begin (), remotePids.end (), remoteGids.begin ());
266 sort3 (remotePids.begin (), remotePids.end (),
268 remoteLids.begin ());
271 MapType newColMap (colMap.getGlobalNumElements (), allGids (),
272 colMap.getIndexBase (), comm, colMap.getNode ());
274 RCP<import_type> imp;
276 imp = rcp (
new import_type (rcp (
new map_type (domMap)),
277 rcp (
new map_type (newColMap))));
285 return std::make_pair (newColMap, imp);
308 template<
class MapType>
312 const MapType& domMap,
313 const MapType& colMap)
315 typedef typename MapType::local_ordinal_type LO;
316 typedef typename MapType::global_ordinal_type GO;
317 typedef typename MapType::node_type NT;
318 typedef ::Tpetra::Import<LO, GO, NT> import_type;
320 const bool makeImport =
false;
321 std::pair<MapType, Teuchos::RCP<import_type> > ret =
381 template<
class MapType>
382 std::pair<MapType, Teuchos::RCP<typename OptColMap<MapType>::import_type> >
385 const MapType& domMap,
386 const MapType& colMap,
388 const bool makeImport)
391 oldImport, makeImport);
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void sort3(const IT1 &first1, const IT1 &last1, const IT2 &first2, const IT3 &first3)
Sort the first array, and apply the same permutation to the second and third arrays.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
MapType makeOptimizedColMap(std::ostream &errStream, bool &lclErr, const MapType &domMap, const MapType &colMap)
Return an optimized reordering of the given column Map.
static std::pair< map_type, Teuchos::RCP< import_type > > make(std::ostream &errStream, bool &lclErr, const map_type &domMap, const map_type &colMap, const import_type *oldImport, const bool makeImport)
Return an optimized reordering of the given column Map. Optionally, recompute an Import from the inpu...
Implementation details of Tpetra.
Implementation detail of makeOptimizedColMap, and makeOptimizedColMapAndImport.
void sort2(const IT1 &first1, const IT1 &last1, const IT2 &first2)
Sort the first array, and apply the resulting permutation to the second array.
Stand-alone utility functions and macros.
std::pair< 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, const bool makeImport)
Return an optimized reordering of the given column Map. Optionally, recompute an Import from the inpu...