1 #ifndef TPETRA_DETAILS_MAKECOLMAP_DEF_HPP 2 #define TPETRA_DETAILS_MAKECOLMAP_DEF_HPP 56 #include "Tpetra_RowGraph.hpp" 64 template <
class LO,
class GO,
class NT>
69 const bool sortEachProcsGids,
70 std::ostream* errStrm)
73 using Teuchos::ArrayView;
76 typedef ::Tpetra::Map<LO, GO, NT> map_type;
77 const char prefix[] =
"Tpetra::Details::makeColMap: ";
87 if (domMap.is_null () || domMap->getComm ().is_null ()) {
88 colMap = Teuchos::null;
101 if (colMap.is_null () || ! graph.
hasColMap ()) {
103 if (errStrm != NULL) {
104 *errStrm << prefix <<
"The graph is locally indexed on the calling " 105 "process, but has no column Map (either getColMap() returns null, " 106 "or hasColMap() returns false)." << endl;
118 if (colMap->isContiguous ()) {
120 const LO numCurGids =
static_cast<LO
> (colMap->getNodeNumElements ());
121 myColumns.resize (numCurGids);
122 const GO myFirstGblInd = colMap->getMinGlobalIndex ();
123 for (LO k = 0; k < numCurGids; ++k) {
124 myColumns[k] = myFirstGblInd +
static_cast<GO
> (k);
128 ArrayView<const GO> curGids = graph.
getColMap ()->getNodeElementList ();
130 const LO numCurGids =
static_cast<LO
> (curGids.size ());
131 myColumns.resize (numCurGids);
132 for (LO k = 0; k < numCurGids; ++k) {
133 myColumns[k] = curGids[k];
162 const LO LINV = Tpetra::Details::OrdinalTraits<LO>::invalid ();
163 size_t numLocalColGIDs = 0;
164 size_t numRemoteColGIDs = 0;
168 std::vector<bool> GIDisLocal (domMap->getNodeNumElements (),
false);
169 std::set<GO> RemoteGIDSet;
172 std::vector<GO> RemoteGIDUnorderedVector;
177 for (LO lclRow = 0; lclRow < lclNumRows; ++lclRow) {
179 Teuchos::ArrayView<const GO> rowGids;
182 const LO numEnt =
static_cast<LO
> (rowGids.size ());
184 for (LO k = 0; k < numEnt; ++k) {
185 const GO gid = rowGids[k];
186 const LO lid = domMap->getLocalElement (gid);
188 const bool alreadyFound = GIDisLocal[lid];
189 if (! alreadyFound) {
190 GIDisLocal[lid] =
true;
195 const bool notAlreadyFound = RemoteGIDSet.insert (gid).second;
196 if (notAlreadyFound) {
197 if (! sortEachProcsGids) {
204 RemoteGIDUnorderedVector.push_back (gid);
243 if (domMap->getComm ()->getSize () == 1) {
244 if (numRemoteColGIDs != 0) {
246 if (errStrm != NULL) {
247 *errStrm << prefix <<
"The domain Map only has one process, but " 248 << numRemoteColGIDs <<
" column " 249 << (numRemoteColGIDs != 1 ?
"indices are" :
"index is")
250 <<
" not in the domain Map. Either these indices are " 251 "invalid or the domain Map is invalid. Remember that nonsquare " 252 "matrices, or matrices where the row and range Maps differ, " 253 "require calling the version of fillComplete that takes the " 254 "domain and range Maps as input." << endl;
257 if (numLocalColGIDs == domMap->getNodeNumElements ()) {
267 myColumns.resize (numLocalColGIDs + numRemoteColGIDs);
269 ArrayView<GO> LocalColGIDs = myColumns (0, numLocalColGIDs);
270 ArrayView<GO> remoteColGIDs = myColumns (numLocalColGIDs, numRemoteColGIDs);
273 if (sortEachProcsGids) {
275 std::copy (RemoteGIDSet.begin(), RemoteGIDSet.end(),
276 remoteColGIDs.begin());
280 std::copy (RemoteGIDUnorderedVector.begin(),
281 RemoteGIDUnorderedVector.end(), remoteColGIDs.begin());
285 Array<int> remotePIDs (numRemoteColGIDs);
289 domMap->getRemoteIndexList (remoteColGIDs, remotePIDs ());
299 if (errStrm != NULL) {
300 *errStrm << prefix <<
"Some column indices are not in the domain Map." 301 "Either these column indices are invalid or the domain Map is " 302 "invalid. Likely cause: For a nonsquare matrix, you must give the " 303 "domain and range Maps as input to fillComplete." << endl;
322 sort2 (remotePIDs.begin(), remotePIDs.end(), remoteColGIDs.begin());
334 const size_t numDomainElts = domMap->getNodeNumElements ();
335 if (numLocalColGIDs == numDomainElts) {
339 if (domMap->isContiguous ()) {
344 GO curColMapGid = domMap->getMinGlobalIndex ();
345 for (
size_t k = 0; k < numLocalColGIDs; ++k, ++curColMapGid) {
346 LocalColGIDs[k] = curColMapGid;
350 ArrayView<const GO> domainElts = domMap->getNodeElementList ();
351 std::copy (domainElts.begin(), domainElts.end(), LocalColGIDs.begin());
357 size_t numLocalCount = 0;
358 if (domMap->isContiguous ()) {
363 GO curColMapGid = domMap->getMinGlobalIndex ();
364 for (
size_t i = 0; i < numDomainElts; ++i, ++curColMapGid) {
366 LocalColGIDs[numLocalCount++] = curColMapGid;
371 ArrayView<const GO> domainElts = domMap->getNodeElementList ();
372 for (
size_t i = 0; i < numDomainElts; ++i) {
374 LocalColGIDs[numLocalCount++] = domainElts[i];
378 if (numLocalCount != numLocalColGIDs) {
379 if (errStrm != NULL) {
380 *errStrm << prefix <<
"numLocalCount = " << numLocalCount
381 <<
" != numLocalColGIDs = " << numLocalColGIDs
382 <<
". This should never happen. " 383 "Please report this bug to the Tpetra developers." << endl;
441 Tpetra::Details::OrdinalTraits<global_size_t>::invalid ();
446 const GO indexBase = domMap->getIndexBase ();
447 colMap = rcp (
new map_type (INV, myColumns, indexBase, domMap->getComm ()));
459 #define TPETRA_DETAILS_MAKECOLMAP_INSTANT(LO,GO,NT) template int makeColMap (Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, const Teuchos::RCP<const Tpetra::Map<LO, GO, NT> >&, const RowGraph<LO, GO, NT>&, const bool, std::ostream*); 461 #endif // TPETRA_DETAILS_MAKECOLMAP_DEF_HPP virtual bool hasColMap() const =0
Indicates whether the graph has a well-defined column map.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
An abstract interface for graphs accessed by rows.
LookupStatus
Return status of Map remote index lookup (getRemoteIndexList()).
int makeColMap(Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &colMap, const Teuchos::RCP< const Tpetra::Map< LO, GO, NT > > &domMap, const RowGraph< LO, GO, NT > &graph, const bool sortEachProcsGids=true, std::ostream *errStrm=NULL)
Make the graph's column Map.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getColMap() const =0
The Map that describes this graph's distribution of columns over processes.
virtual void getGlobalRowView(const GlobalOrdinal gblRow, Teuchos::ArrayView< const GlobalOrdinal > &gblColInds) const
Get a const, non-persisting view of the given global row's global column indices, as a Teuchos::Array...
size_t getNodeNumElements() const
The number of elements belonging to the calling process.
Implementation details of Tpetra.
size_t global_size_t
Global size_t object.
virtual Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > getRowMap() const =0
The Map that describes this graph's distribution of rows over processes.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
virtual bool isGloballyIndexed() const =0
If graph indices are in the global range, this function returns true. Otherwise, this function return...
void sort2(const IT1 &first1, const IT1 &last1, const IT2 &first2)
Sort the first array, and apply the resulting permutation to the second array.
A parallel distribution of indices over processes.
Stand-alone utility functions and macros.
virtual bool isLocallyIndexed() const =0
If graph indices are in the local range, this function returns true. Otherwise, this function returns...