45 #ifndef TPETRA_CRSGRAPH_DEF_HPP 46 #define TPETRA_CRSGRAPH_DEF_HPP 48 #include <Kokkos_NodeTrace.hpp> 49 #include "Tpetra_Distributor.hpp" 50 #include <Teuchos_Assert.hpp> 51 #include <Teuchos_NullIteratorTraits.hpp> 58 #ifdef DOXYGEN_USE_ONLY 59 #include "Tpetra_CrsGraph_decl.hpp" 66 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
67 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
69 size_t maxNumEntriesPerRow,
72 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
77 , numAllocForAllRows_(maxNumEntriesPerRow)
78 , indicesAreAllocated_(false)
79 , indicesAreLocal_(false)
80 , indicesAreGlobal_(false)
81 , fillComplete_(false)
82 , indicesAreSorted_ (true)
83 , noRedundancies_ (true)
84 , haveLocalConstants_ (false)
85 , haveGlobalConstants_ (false)
91 std::invalid_argument,
"The allocation hint must be a valid size_t value, " 92 "which in this case means it must not be Teuchos::OrdinalTraits<size_t>::" 100 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
104 size_t maxNumEntriesPerRow,
107 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
114 , indicesAreAllocated_(false)
115 , indicesAreLocal_(false)
116 , indicesAreGlobal_(false)
117 , fillComplete_(false)
127 std::invalid_argument,
"The allocation hint must be a valid size_t value, " 128 "which in this case means it must not be Teuchos::OrdinalTraits<size_t>::" 131 checkInternalState();
136 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
142 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
149 , indicesAreAllocated_(false)
150 , indicesAreLocal_(false)
151 , indicesAreGlobal_(false)
152 , fillComplete_(false)
160 const char tfecfFuncName[] =
"CrsGraph(rowMap,NumEntriesPerRowToAlloc)";
163 ": NumEntriesPerRowToAlloc must have as many entries as specified by rowMap for this node.");
165 const size_t curRowCount = NumEntriesPerRowToAlloc[r];
167 std::invalid_argument,
"NumEntriesPerRowToAlloc[" << r <<
"] specifies " 168 "an invalid number of entries (Teuchos::OrdinalTraits<size_t>::" 172 checkInternalState();
178 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
185 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
193 , indicesAreAllocated_(false)
194 , indicesAreLocal_(false)
195 , indicesAreGlobal_(false)
196 , fillComplete_(false)
204 const char tfecfFuncName[] =
"CrsGraph(rowMap,colMap,NumEntriesPerRowToAlloc)";
207 ": NumEntriesPerRowToAlloc must have as many entries as specified by rowMap for this node.");
209 const size_t curRowCount = NumEntriesPerRowToAlloc[r];
211 std::invalid_argument,
"NumEntriesPerRowToAlloc[" << r <<
"] specifies " 212 "an invalid number of entries (Teuchos::OrdinalTraits<size_t>::" 216 checkInternalState();
222 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
229 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
236 , indicesAreAllocated_(true)
237 , indicesAreLocal_(true)
238 , indicesAreGlobal_(false)
239 , fillComplete_(false)
249 checkInternalState();
254 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
258 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
279 params->set (
"Import", *importSublist,
"How the Import performs communication.");
285 params->set (
"Export", *importSublist,
"How the Export performs communication.");
290 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
296 params->validateParametersAndSetDefaults (*validParams);
300 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
303 return rowMap_->getGlobalNumElements();
306 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
309 const char tfecfFuncName[] =
"getGlobalNumCols()";
312 ": requires domain map, which requires that fillComplete() has been " 317 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
320 return rowMap_->getNodeNumElements();
323 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
326 const char tfecfFuncName[] =
"getNodeNumCols()";
328 hasColMap() ==
false, std::runtime_error,
329 ": requires column map. This requires either that a custom column Map " 330 "was given to the constructor, or that fillComplete() has been called.");
331 return colMap_->getNodeNumElements();
334 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
337 return nodeNumDiags_;
340 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
343 return globalNumDiags_;
346 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
353 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
360 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
367 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
374 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
381 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
388 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
395 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
401 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
405 #ifdef HAVE_TPETRA_DEBUG 406 const char tfecfFuncName[] =
"isStorageOptimized()";
408 ": Violated stated post-conditions. Please contact Tpetra team.");
413 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
419 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
422 return globalNumEntries_;
425 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
428 return nodeNumEntries_;
431 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
434 return globalMaxNumRowEntries_;
437 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
440 return nodeMaxNumRowEntries_;
443 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
446 return fillComplete_;
449 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
452 return !fillComplete_;
455 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
461 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
467 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
470 return indicesAreLocal_;
473 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
476 return indicesAreGlobal_;
479 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
482 return nodeNumAllocated_;
485 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
492 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
495 return rowMap_->getIndexBase();
498 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
501 return indicesAreAllocated_;
516 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
525 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
533 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
551 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
559 const char tfecfFuncName[] =
"allocateIndices()";
562 ": The graph is locally indexed, but Tpetra code is calling this method " 563 "with lg=GlobalIndices. Please report this bug to the Tpetra developers.");
566 ": The graph is globally indexed, but Tpetra code is calling this method " 567 "with lg=LocalIndices. Please report this bug to the Tpetra developers.");
569 indicesAreAllocated(), std::logic_error,
": The graph's indices are " 570 "already allocated, but Tpetra code is calling allocateIndices() again. " 571 "Please report this bug to the Tpetra developers.");
574 indicesAreLocal_ = (lg == LocalIndices);
575 indicesAreGlobal_ = (lg == GlobalIndices);
576 nodeNumAllocated_ = 0;
597 if (lg == LocalIndices) {
598 lclInds1D_ = LocalMatOps::template allocStorage<LocalOrdinal>(
getRowMap()->getNode(), rowPtrs_() );
601 gblInds1D_ = LocalMatOps::template allocStorage<GlobalOrdinal>(
getRowMap()->getNode(), rowPtrs_() );
603 nodeNumAllocated_ = rowPtrs_[numRows];
611 if (lg == LocalIndices) {
612 lclInds2D_ = arcp< Array<LocalOrdinal> >(numRows);
613 nodeNumAllocated_ = 0;
614 for (
size_t i=0; i < numRows; ++i) {
616 nodeNumAllocated_ += howmany;
617 if (howmany > 0)
lclInds2D_[i].resize(howmany);
621 gblInds2D_ = arcp< Array<GlobalOrdinal> >(numRows);
622 nodeNumAllocated_ = 0;
623 for (
size_t i=0; i < numRows; ++i) {
625 nodeNumAllocated_ += howmany;
626 if (howmany > 0)
gblInds2D_[i].resize(howmany);
637 indicesAreAllocated_ =
true;
638 checkInternalState();
644 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
648 const char tfecfFuncName[] =
"allocateValues()";
650 indicesAreAllocated() ==
false,
651 std::runtime_error,
": graph indices must be allocated before values." 655 std::runtime_error,
": graph indices must be allocated in a static profile." 658 values1D = LocalMatOps::template allocStorage<T>(
getRowMap()->getNode(), rowPtrs_() );
665 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
670 const char tfecfFuncName[] =
"allocateValues2D()";
672 indicesAreAllocated() ==
false,
673 std::runtime_error,
": graph indices must be allocated before values." 677 std::runtime_error,
": graph indices must be allocated in a dynamic profile." 683 for (
size_t r = 0; r < numRows; ++r) {
689 for (
size_t r = 0; r < numRows; ++r) {
699 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
700 template <ELocalGlobal lg,
class T>
707 #ifdef HAVE_TPETRA_DEBUG 712 TEUCHOS_TEST_FOR_EXCEPT( newAllocSize == 0 );
713 TEUCHOS_TEST_FOR_EXCEPT( ! indicesAreAllocated() );
716 if (lg == LocalIndices) {
717 lclInds2D_[rowinfo.localRow].resize (newAllocSize);
720 gblInds2D_[rowinfo.localRow].resize (newAllocSize);
722 rowVals.
resize (newAllocSize);
723 nodeNumAllocated_ += (newAllocSize - rowinfo.allocSize);
724 rowinfo.allocSize = newAllocSize;
731 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
737 if (rowinfo.allocSize > 0) {
739 view =
lclInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
741 else if (!
lclInds2D_[rowinfo.localRow].empty()) {
751 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
757 if (rowinfo.allocSize > 0) {
759 view =
lclInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
761 else if (!
lclInds2D_[rowinfo.localRow].empty()) {
771 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
777 if (rowinfo.allocSize > 0) {
779 view =
gblInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
781 else if (!
gblInds2D_[rowinfo.localRow].empty()) {
791 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
797 if (rowinfo.allocSize > 0) {
799 view =
gblInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
801 else if (!
gblInds2D_[rowinfo.localRow].empty()) {
811 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
814 #ifdef HAVE_TPETRA_DEBUG 815 const char tfecfFuncName[] =
"getRowInfo()";
817 rowMap_->isNodeLocalElement (myRow) ==
false,
819 ": The given (local) row index myRow = " << myRow
820 <<
" does not belong to the graph's row Map. " 821 "This probably indicates a bug in Tpetra::CrsGraph or Tpetra::CrsMatrix. " 822 "Please report this to the Tpetra developers.");
824 hasRowInfo() ==
false, std::logic_error,
825 ": Late catch! Graph does not have row info anymore. " 826 "Error should have been caught earlier. Please contact Tpetra team.");
827 #endif // HAVE_TPETRA_DEBUG 830 ret.localRow = myRow;
831 if (nodeNumAllocated_ != 0 && nodeNumAllocated_ != STINV) {
836 ret.offset1D = rowPtrs_[myRow];
837 ret.allocSize = rowPtrs_[myRow+1] - rowPtrs_[myRow];
839 ret.numEntries = ret.allocSize;
846 ret.offset1D = STINV;
856 else if (nodeNumAllocated_ == 0) {
860 ret.offset1D = STINV;
862 else if (indicesAreAllocated () ==
false) {
871 ret.offset1D = STINV;
883 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
897 std::string msg =
typeName(*
this) +
": Object cannot be allocated with stated template arguments: size assumptions are not valid.";
907 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
908 template <ELocalGlobal lg>
914 size_t numFiltered = 0;
915 #ifdef HAVE_TPETRA_DEBUG 916 size_t numFiltered_debug = 0;
918 if (lg == GlobalIndices) {
921 cptr = ginds.
begin();
922 while (cptr != ginds.
end()) {
925 #ifdef HAVE_TPETRA_DEBUG 931 numFiltered = fend - ginds.
begin();
933 else if (lg == LocalIndices) {
936 cptr = linds.
begin();
937 while (cptr != linds.
end()) {
940 #ifdef HAVE_TPETRA_DEBUG 946 numFiltered = fend - linds.
begin();
948 #ifdef HAVE_TPETRA_DEBUG 957 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
964 size_t numFiltered = 0;
967 #ifdef HAVE_TPETRA_DEBUG 968 size_t numFiltered_debug = 0;
972 while (cptr != ginds.
end()) {
975 *fvalsend++ = *valscptr;
976 #ifdef HAVE_TPETRA_DEBUG 983 numFiltered = fend - ginds.
begin();
984 #ifdef HAVE_TPETRA_DEBUG 987 const size_t numFilteredActual =
988 Teuchos::as<size_t> (fvalsend - vals.
begin ());
997 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1005 size_t numFiltered = 0;
1008 #ifdef HAVE_TPETRA_DEBUG 1009 size_t numFiltered_debug = 0;
1013 while (cptr != linds.
end()) {
1016 *fvalsend++ = *valscptr;
1017 #ifdef HAVE_TPETRA_DEBUG 1018 ++numFiltered_debug;
1024 numFiltered = fend - linds.
begin();
1025 #ifdef HAVE_TPETRA_DEBUG 1028 const size_t numFilteredActual =
1029 Teuchos::as<size_t> (fvalsend - vals.
begin ());
1038 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1042 const SLocalGlobalViews &newInds,
1043 const ELocalGlobal lg,
1044 const ELocalGlobal I)
1046 #ifdef HAVE_TPETRA_DEBUG 1048 lg != GlobalIndices && lg != LocalIndices, std::invalid_argument,
1049 "Tpetra::CrsGraph::insertIndices: lg must be either GlobalIndices or " 1051 #endif // HAVE_TPETRA_DEBUG 1052 size_t numNewInds = 0;
1053 if (lg == GlobalIndices) {
1055 numNewInds = new_ginds.
size();
1056 if (I == GlobalIndices) {
1058 std::copy(new_ginds.
begin(), new_ginds.
end(), gind_view.
begin()+rowinfo.numEntries);
1060 else if (I == LocalIndices) {
1065 while (in != stop) {
1066 *out++ =
colMap_->getLocalElement (*in++);
1070 else if (lg == LocalIndices) {
1072 numNewInds = new_linds.
size();
1073 if (I == LocalIndices) {
1075 std::copy(new_linds.
begin(), new_linds.
end(), lind_view.
begin()+rowinfo.numEntries);
1077 else if (I == GlobalIndices) {
1079 "insertIndices: the case where the input indices are local and the " 1080 "indices to write are global (lg=LocalIndices, I=GlobalIndices) is " 1081 "not implemented, because it does not make sense." << std::endl <<
1082 "If you have correct local column indices, that means the graph has " 1083 "a column Map. In that case, you should be storing local indices.");
1087 nodeNumEntries_ += numNewInds;
1094 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1099 const char* tfecfFuncName (
"insertGlobalIndicesImpl");
1101 RowInfo rowInfo = getRowInfo(myRow);
1102 const size_t numNewInds = indices.
size();
1103 const size_t newNumEntries = rowInfo.numEntries + numNewInds;
1104 if (newNumEntries > rowInfo.allocSize) {
1107 ": new indices exceed statically allocated graph structure.");
1110 size_t newAllocSize = 2*rowInfo.allocSize;
1111 if (newAllocSize < newNumEntries)
1112 newAllocSize = newNumEntries;
1114 nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
1119 std::copy(indices.
begin(), indices.
end(),
1122 std::copy(indices.
begin(), indices.
end(),
1123 gblInds2D_[myRow].begin()+rowInfo.numEntries);
1125 nodeNumEntries_ += numNewInds;
1128 #ifdef HAVE_TPETRA_DEBUG 1132 chkNewNumEntries != newNumEntries, std::logic_error,
1133 ": Internal logic error. Please contact Tpetra team.");
1140 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1145 const char* tfecfFuncName (
"insertLocallIndicesImpl");
1147 RowInfo rowInfo = getRowInfo(myRow);
1148 const size_t numNewInds = indices.
size();
1149 const size_t newNumEntries = rowInfo.numEntries + numNewInds;
1150 if (newNumEntries > rowInfo.allocSize) {
1153 ": new indices exceed statically allocated graph structure.");
1156 size_t newAllocSize = 2*rowInfo.allocSize;
1157 if (newAllocSize < newNumEntries)
1158 newAllocSize = newNumEntries;
1160 nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
1165 std::copy(indices.
begin(), indices.
end(),
1168 std::copy(indices.
begin(), indices.
end(),
1169 lclInds2D_[myRow].begin()+rowInfo.numEntries);
1171 nodeNumEntries_ += numNewInds;
1173 #ifdef HAVE_TPETRA_DEBUG 1177 chkNewNumEntries != newNumEntries, std::logic_error,
1178 ": Internal logic error. Please contact Tpetra team.");
1185 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1186 template <
class Scalar>
1189 const SLocalGlobalViews& newInds,
1192 const ELocalGlobal lg,
1193 const ELocalGlobal I)
1195 const size_t numNewInds =
insertIndices (rowInfo, newInds, lg, I);
1197 newRowVals.
begin ();
1198 std::copy (newRowValsBegin, newRowValsBegin + numNewInds,
1199 oldRowVals.
begin () + rowInfo.numEntries);
1204 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1205 template <
class Scalar,
class BinaryFunction>
1212 BinaryFunction f)
const 1215 const size_t numElts = Teuchos::as<size_t> (inds.
size ());
1222 for (
size_t j = 0; j < numElts; ++j) {
1223 const size_t k =
findLocalIndex (rowInfo, inds[j], colInds, hint);
1225 rowVals[k] = f( rowVals[k], newVals[j] );
1234 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1235 template <
class Scalar,
class BinaryFunction>
1242 BinaryFunction f)
const 1245 const size_t numElts = Teuchos::as<size_t> (inds.
size ());
1248 for (
size_t j = 0; j < numElts; ++j) {
1251 rowVals[k] = f( rowVals[k], newVals[j] );
1261 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1264 if (rowinfo.numEntries > 0) {
1266 std::sort(inds_view.
begin(), inds_view.
begin() + rowinfo.numEntries);
1274 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1275 template <
class Scalar>
1278 if (rowinfo.numEntries > 0) {
1287 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1290 const char tfecfFuncName[] =
"mergRowIndices()";
1293 ": The graph is already storage optimized, so we shouldn't be merging any indices." 1294 " Please report this bug to the Tpetra developers.");
1297 beg = inds_view.
begin();
1298 end = inds_view.
begin() + rowinfo.numEntries;
1299 newend = std::unique(beg,end);
1300 const size_t mergedEntries = newend - beg;
1301 #ifdef HAVE_TPETRA_DEBUG 1306 nodeNumEntries_ -= (rowinfo.numEntries - mergedEntries);
1313 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1314 template<
class Scalar>
1318 const char tfecfFuncName[] =
"mergeRowIndicesAndValues";
1321 "method if the graph's storage has already been optimized." << std::endl
1322 <<
"Please report this bug to the Tpetra developers.");
1325 Iter rowValueIter = rowValues.
begin ();
1330 beg = inds_view.
begin();
1331 end = inds_view.
begin() + rowinfo.numEntries;
1335 Iter vcur = rowValueIter + 1;
1336 Iter vend = rowValueIter;
1338 while (cur != end) {
1339 if (*cur != *newend) {
1356 const size_t mergedEntries = newend - beg;
1357 #ifdef HAVE_TPETRA_DEBUG 1363 ": Merge was incorrect; it eliminated entries from the graph. " 1364 << std::endl <<
"Please report this bug to the Tpetra developers.");
1365 #endif // HAVE_TPETRA_DEBUG 1367 nodeNumEntries_ -= (rowinfo.numEntries - mergedEntries);
1373 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1392 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1404 template <
class LocalOrdinal,
1405 class GlobalOrdinal,
1418 if (hint < rowinfo.numEntries && colInds[hint] == ind) {
1426 IT beg = colInds.
begin ();
1427 IT end = beg + rowinfo.numEntries;
1428 IT ptr = beg + rowinfo.numEntries;
1433 std::pair<IT,IT> p = std::equal_range (beg, end, ind);
1434 if (p.first == p.second) {
1443 ptr = std::find (beg, end, ind);
1450 return Teuchos::as<size_t> (ptr - beg);
1460 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1470 if (hint < rowinfo.numEntries && indices[hint] == ind) {
1474 IT beg = indices.
begin ();
1475 IT end = indices.
begin () + rowinfo.numEntries;
1477 const std::pair<IT,IT> p = std::equal_range (beg, end, ind);
1478 if (p.first == p.second) {
1481 return p.first - beg;
1485 const IT loc = std::find (beg, end, ind);
1497 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1509 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1512 #ifdef HAVE_TPETRA_DEBUG 1515 std::string err =
typeName(*
this) +
"::checkInternalState(): Likely internal logic error. Please contact Tpetra team.";
1536 std::logic_error, err );
1540 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreAllocated() ==
false && (nodeNumAllocated_ != STI || nodeNumEntries_ != 0), std::logic_error, err );
1548 std::logic_error, err );
1551 std::logic_error, err );
1558 std::logic_error, err );
1566 TEUCHOS_TEST_FOR_EXCEPTION( (indicesAreLocal_ ==
true || indicesAreGlobal_ ==
true) && indicesAreAllocated_ ==
false, std::logic_error, err );
1575 std::logic_error, err );
1578 std::logic_error, err );
1584 if (indicesAreAllocated()) {
1585 size_t actualNumAllocated = 0;
1599 else if (rowPtrs_ != null) {
1621 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1624 const LocalOrdinal lrow =
rowMap_->getLocalElement(globalRow);
1628 RowInfo rowinfo = getRowInfo(lrow);
1629 ret = rowinfo.numEntries;
1637 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1641 if (hasRowInfo() &&
rowMap_->isNodeLocalElement(localRow)) {
1642 RowInfo rowinfo = getRowInfo(localRow);
1643 ret = rowinfo.numEntries;
1651 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1654 const LocalOrdinal lrow =
rowMap_->getLocalElement(globalRow);
1658 RowInfo rowinfo = getRowInfo(lrow);
1659 ret = rowinfo.allocSize;
1667 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1671 if (hasRowInfo() &&
rowMap_->isNodeLocalElement(localRow)) {
1672 RowInfo rowinfo = getRowInfo(localRow);
1673 ret = rowinfo.allocSize;
1681 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1690 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1699 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1707 const char tfecfFuncName[] =
"getLocalRowCopy(localRow,...)";
1710 ": localRow (== " << localRow <<
") is not valid on this node.");
1712 const RowInfo rowinfo = getRowInfo(localRow);
1713 NumIndices = rowinfo.numEntries;
1714 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC((
size_t)indices.
size() < NumIndices, std::runtime_error,
1715 ": specified storage (size==" << indices.
size()
1716 <<
") is not large enough to hold all entries for this row (NumIndices == " << NumIndices <<
").");
1719 std::copy( lview.
begin(), lview.
begin() + NumIndices, indices.
begin());
1723 for (
size_t j=0; j < NumIndices; ++j) {
1724 indices[j] =
colMap_->getLocalElement(gview[j]);
1728 #ifdef HAVE_TPETRA_DEBUG 1730 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( indicesAreAllocated() ==
true, std::logic_error,
": Internal logic error. Please contact Tpetra team.");
1740 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1744 const LocalOrdinal lrow =
rowMap_->getLocalElement(globalRow);
1745 const char tfecfFuncName[] =
"getGlobalRowCopy(globalRow,...)";
1747 ": globalRow (== " << globalRow <<
") does not belong to this node.");
1749 const RowInfo rowinfo = getRowInfo((
size_t)lrow);
1750 NumIndices = rowinfo.numEntries;
1752 ": specified storage (size==" << indices.
size()
1753 <<
") is not large enough to hold all entries for this row (NumIndices == " << NumIndices <<
").");
1756 for (
size_t j=0; j < NumIndices; ++j) {
1757 indices[j] =
colMap_->getGlobalElement(lview[j]);
1762 std::copy(gview.
begin(), gview.
begin() + NumIndices, indices.
begin());
1770 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1773 const char tfecfFuncName[] =
"getLocalRowView()";
1777 if (
rowMap_->isNodeLocalElement(localRow) ==
true) {
1778 const RowInfo rowinfo = getRowInfo(localRow);
1779 if (rowinfo.numEntries > 0) {
1780 indices = getLocalView(rowinfo);
1781 indices = indices(0,rowinfo.numEntries);
1784 #ifdef HAVE_TPETRA_DEBUG 1793 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1797 const char tfecfFuncName[] =
"getGlobalRowView()";
1800 ": The graph is locally indexed, so we cannot return a view with global " 1801 "column indices. Use getGlobalRowCopy() instead.");
1804 hasRowInfo() ==
false, std::runtime_error,
1805 ": graph row information was deleted at fillComplete().");
1809 const LocalOrdinal localRow =
rowMap_->getLocalElement (globalRow);
1812 const RowInfo rowInfo = getRowInfo (as<size_t> (localRow));
1813 if (rowInfo.numEntries > 0) {
1814 indices = (getGlobalView (rowInfo)) (0, rowInfo.numEntries);
1817 #ifdef HAVE_TPETRA_DEBUG 1822 ": Violated stated post-conditions:" 1823 <<
" indices.size () = " << indices.
size () << endl
1824 <<
" as<size_t> (indices.size ()) = " << as<size_t> (indices.
size ())
1825 << endl <<
" getNumEntriesInGlobalRow (globalRow = " << globalRow
1827 <<
"Please report this bug to the Tpetra developers.");
1828 #endif // HAVE_TPETRA_DEBUG 1834 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1841 typedef LocalOrdinal LO;
1842 const char tfecfFuncName[] =
"insertLocalIndices";
1846 ": requires that fill is active.");
1849 ": graph indices are global; use insertGlobalIndices().");
1851 hasColMap() ==
false, std::runtime_error,
1852 ": cannot insert local indices without a column map.");
1854 rowMap_->isNodeLocalElement(localRow) ==
false, std::runtime_error,
1855 ": row does not belong to this node.");
1857 hasRowInfo() ==
false, std::runtime_error,
1858 ": graph row information was deleted at fillComplete().");
1859 if (! indicesAreAllocated ()) {
1860 allocateIndices (LocalIndices);
1863 #ifdef HAVE_TPETRA_DEBUG 1876 bool allInColMap =
true;
1877 for (size_type k = 0; k < indices.
size (); ++k) {
1879 allInColMap =
false;
1883 if (! allInColMap) {
1884 std::ostringstream os;
1885 os <<
"Tpetra::CrsMatrix::insertLocalIndices: You attempted to insert " 1886 "entries in owned row " << localRow <<
", at the following column " 1887 "indices: " <<
toString (indices) <<
"." << endl;
1888 os <<
"Of those, the following indices are not in the column Map on " 1889 "this process: " <<
toString (badColInds) <<
"." << endl <<
"Since " 1890 "the graph has a column Map already, it is invalid to insert entries " 1891 "at those locations.";
1895 #endif // HAVE_TPETRA_DEBUG 1897 insertLocalIndicesImpl (localRow, indices);
1899 #ifdef HAVE_TPETRA_DEBUG 1900 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1903 ": Violated stated post-conditions. Please contact Tpetra team.");
1910 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1916 typedef LocalOrdinal LO;
1917 const char tfecfFuncName[] =
"insertLocalIndicesFiltered";
1921 ": requires that fill is active.");
1924 ": graph indices are global; use insertGlobalIndices().");
1926 hasColMap() ==
false, std::runtime_error,
1927 ": cannot insert local indices without a column map.");
1929 rowMap_->isNodeLocalElement(localRow) ==
false, std::runtime_error,
1930 ": row does not belong to this node.");
1932 hasRowInfo() ==
false, std::runtime_error,
1933 ": graph row information was deleted at fillComplete().");
1934 if (indicesAreAllocated() ==
false) {
1935 allocateIndices(LocalIndices);
1941 SLocalGlobalViews inds_view;
1942 SLocalGlobalNCViews inds_ncview;
1943 inds_ncview.linds = filtered_indices();
1944 const size_t numFilteredEntries =
1945 filterIndices<LocalIndices>(inds_ncview);
1946 inds_view.linds = filtered_indices (0, numFilteredEntries);
1947 insertLocalIndicesImpl(localRow, inds_view.linds);
1950 insertLocalIndicesImpl(localRow, indices);
1952 #ifdef HAVE_TPETRA_DEBUG 1953 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1956 ": Violated stated post-conditions. Please contact Tpetra team.");
1963 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1969 typedef LocalOrdinal LO;
1970 typedef GlobalOrdinal GO;
1972 const char tfecfFuncName[] =
"insertGlobalIndices";
1976 ": graph indices are local; use insertLocalIndices().");
1978 hasRowInfo() ==
false, std::runtime_error,
1979 ": graph row information was deleted at fillComplete().");
1986 ": You are not allowed to call this method if fill is not active. " 1987 "If fillComplete has been called, you must first call resumeFill " 1988 "before you may insert indices.");
1989 if (! indicesAreAllocated ()) {
1990 allocateIndices (GlobalIndices);
1992 const LO myRow =
rowMap_->getLocalElement (grow);
1994 #ifdef HAVE_TPETRA_DEBUG 2003 bool allInColMap =
true;
2004 for (size_type k = 0; k < indices.
size (); ++k) {
2006 allInColMap =
false;
2010 if (! allInColMap) {
2011 std::ostringstream os;
2012 os <<
"Tpetra::CrsGraph::insertGlobalIndices: You attempted to insert " 2013 "entries in owned row " << grow <<
", at the following column " 2014 "indices: " <<
toString (indices) <<
"." << endl;
2015 os <<
"Of those, the following indices are not in the column Map on " 2016 "this process: " <<
toString (badColInds) <<
"." << endl <<
"Since " 2017 "the matrix has a column Map already, it is invalid to insert " 2018 "entries at those locations.";
2022 #endif // HAVE_TPETRA_DEBUG 2023 insertGlobalIndicesImpl (myRow, indices);
2026 const size_type numIndices = indices.
size ();
2030 std::deque<GO>& nonlocalRow =
nonlocals_[grow];
2031 for (size_type k = 0; k < numIndices; ++k) {
2032 nonlocalRow.push_back (indices[k]);
2035 #ifdef HAVE_TPETRA_DEBUG 2039 ": Violated stated post-conditions. Please contact Tpetra team.");
2046 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2052 typedef LocalOrdinal LO;
2053 typedef GlobalOrdinal GO;
2054 const char tfecfFuncName[] =
"insertGlobalIndicesFiltered";
2058 ": graph indices are local; use insertLocalIndices().");
2060 hasRowInfo() ==
false, std::runtime_error,
2061 ": graph row information was deleted at fillComplete().");
2068 ": You are not allowed to call this method if fill is not active. " 2069 "If fillComplete has been called, you must first call resumeFill " 2070 "before you may insert indices.");
2071 if (indicesAreAllocated() ==
false) {
2072 allocateIndices (GlobalIndices);
2074 const LO myRow =
rowMap_->getLocalElement (grow);
2079 SLocalGlobalViews inds_view;
2080 SLocalGlobalNCViews inds_ncview;
2081 inds_ncview.ginds = filtered_indices();
2082 const size_t numFilteredEntries =
2083 filterIndices<GlobalIndices> (inds_ncview);
2084 inds_view.ginds = filtered_indices (0, numFilteredEntries);
2085 insertGlobalIndicesImpl(myRow, inds_view.ginds);
2088 insertGlobalIndicesImpl(myRow, indices);
2093 const size_type numIndices = indices.
size ();
2094 for (size_type k = 0; k < numIndices; ++k) {
2098 #ifdef HAVE_TPETRA_DEBUG 2102 ": Violated stated post-conditions. Please contact Tpetra team.");
2108 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2111 const char tfecfFuncName[] =
"removeLocalIndices()";
2116 if (indicesAreAllocated() ==
false) {
2117 allocateIndices(LocalIndices);
2120 clearGlobalConstants();
2126 #ifdef HAVE_TPETRA_DEBUG 2128 ": Violated stated post-conditions. Please contact Tpetra team.");
2134 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2137 const char tfecfFuncName[] =
"setAllIndices()";
2141 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
lclInds2D_ != Teuchos::null ||
gblInds2D_ != Teuchos::null, std::runtime_error,
": cannot have 2D data structures allocated.");
2143 indicesAreAllocated_ =
true;
2144 indicesAreLocal_ =
true;
2147 rowPtrs_ = rowPointers;
2148 nodeNumEntries_ = nodeNumAllocated_ = rowPtrs_[
getNodeNumRows()];
2149 checkInternalState();
2155 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2161 using Teuchos::gatherAll;
2164 using Teuchos::outArg;
2165 using Teuchos::REDUCE_MAX;
2168 using Teuchos::waitAll;
2171 using std::make_pair;
2173 typedef GlobalOrdinal GO;
2174 typedef typename std::map<GO, std::deque<GO> >::const_iterator NLITER;
2177 const char tfecfFuncName[] =
"globalAssemble";
2180 const int numImages = comm->getSize();
2181 const int myImageID = comm->getRank();
2182 #ifdef HAVE_TPETRA_DEBUG 2183 Teuchos::barrier (*comm);
2184 #endif // HAVE_TPETRA_DEBUG 2187 ": requires that fill is active.");
2190 size_t MyNonlocals =
nonlocals_.size(), MaxGlobalNonlocals;
2191 reduceAll (*comm, REDUCE_MAX, MyNonlocals, outArg (MaxGlobalNonlocals));
2192 if (MaxGlobalNonlocals == 0) {
2204 std::map<GO, int> NLR2Id;
2211 std::set<GO> setOfRows;
2213 setOfRows.
insert(iter->first);
2216 NLRs.
resize(setOfRows.size());
2217 std::copy(setOfRows.begin(), setOfRows.end(), NLRs.
begin());
2225 reduceAll<int, int> (*comm, REDUCE_MAX, lclerror, outArg (gblerror));
2226 if (gblerror != 0) {
2227 const int myRank = comm->getRank ();
2228 std::ostringstream os;
2229 os <<
"On one or more processes in the communicator, " 2230 <<
"there were insertions into rows of the graph that do not " 2231 <<
"exist in the row Map on any process in the communicator." 2232 << endl <<
"This process " << myRank <<
" is " 2233 << (lclerror == 0 ?
"not " :
"") <<
"one of those offending " 2234 <<
"processes." << endl;
2235 if (lclerror != 0) {
2240 for (size_type k = 0; k < NLRs.
size (); ++k) {
2241 if (NLRIds[k] == -1) {
2242 invalidNonlocalRows.
push_back (NLRs[k]);
2245 const size_type numInvalid = invalidNonlocalRows.
size ();
2246 os <<
"On this process, " << numInvalid <<
" nonlocal row" 2247 << (numInvalid != 1 ?
"s " :
" ") <<
" were inserted that are " 2248 <<
"not in the row Map on any process." << endl;
2250 if (numInvalid <= 100) {
2251 os <<
"Offending row indices: " 2252 <<
toString (invalidNonlocalRows ()) << endl;
2256 gblerror != 0, std::runtime_error,
2257 ": nonlocal entries correspond to invalid rows." 2258 << endl << os.str ());
2269 for (nlr = NLRs.
begin(),
id = NLRIds.begin();
2270 nlr != NLRs.
end(); ++nlr, ++id) {
2272 localNeighbors[*id] = 1;
2274 IdsAndRows.
push_back(make_pair(*
id,*nlr));
2276 for (
int j=0; j<numImages; ++j) {
2277 if (localNeighbors[j]) {
2282 std::sort(IdsAndRows.
begin(),IdsAndRows.
end());
2286 numImages * numImages, globalNeighbors.
values());
2298 for (
int j=0; j<numImages; ++j) {
2299 if (globalNeighbors(myImageID,j)) {
2303 const size_t numRecvs = recvIDs.
size();
2310 size_t numSends = 0;
2311 for (
typename Array<pair<int, GO> >::const_iterator IdAndRow = IdsAndRows.
begin();
2312 IdAndRow != IdsAndRows.
end(); ++IdAndRow) {
2313 int id = IdAndRow->first;
2314 GO row = IdAndRow->second;
2316 if (sendIDs[numSends] !=
id) {
2319 std::logic_error,
": internal logic error. Contact Tpetra team.");
2322 for (
typename deque<GO>::const_iterator j =
nonlocals_[row].begin(); j !=
nonlocals_[row].end(); ++j)
2324 IJSendBuffer.
push_back( pair<GlobalOrdinal,GlobalOrdinal>(row,*j) );
2325 sendSizes[numSends]++;
2328 if (IdsAndRows.
size() > 0) {
2346 for (
size_t s = 0; s < numSends ; ++s) {
2349 requests.
push_back (isend<int, size_t> (*comm,
2350 rcp (&sendSizes[s],
false),
2355 for (
size_t r = 0; r < numRecvs; ++r) {
2358 requests.
push_back (ireceive (*comm,
rcp (&recvSizes[r],
false), recvIDs[r]));
2361 if (! requests.
empty()) {
2362 waitAll (*comm, requests());
2364 #ifdef HAVE_TPETRA_DEBUG 2365 Teuchos::barrier (*comm);
2366 #endif // HAVE_TPETRA_DEBUG 2378 for (
size_t s=0; s<numSends; ++s) {
2379 sendBuffers[s] = IJSendBuffer(cur,sendSizes[s]);
2380 cur += sendSizes[s];
2384 for (
size_t s=0; s < numSends ; ++s)
2389 arcp (sendBuffers[s].getRawPtr(), 0, sendBuffers[s].size(),
false);
2390 requests.
push_back (isend<
int, pair<GO,GO> > (*comm, tmpSendBuf, sendIDs[s]));
2394 size_t totalRecvSize = std::accumulate (recvSizes.
begin(), recvSizes.
end(), 0);
2400 for (
size_t r=0; r<numRecvs; ++r) {
2401 recvBuffers[r] = IJRecvBuffer(cur,recvSizes[r]);
2402 cur += recvSizes[r];
2406 for (
size_t r = 0; r < numRecvs; ++r) {
2410 arcp (recvBuffers[r].getRawPtr(), 0, recvBuffers[r].size(),
false);
2411 requests.
push_back (ireceive (*comm, tmpRecvBuf, recvIDs[r]));
2414 if (! requests.
empty()) {
2415 waitAll (*comm, requests());
2417 #ifdef HAVE_TPETRA_DEBUG 2418 Teuchos::barrier (*comm);
2419 #endif // HAVE_TPETRA_DEBUG 2429 for (
typename Array<pair<GO,GO> >::const_iterator ij = IJRecvBuffer.
begin();
2430 ij != IJRecvBuffer.end(); ++ij)
2434 checkInternalState();
2440 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2445 const char tfecfFuncName[] =
"resumeFill";
2447 ": Sorry, you cannot resume fill of the CrsGraph, since the graph's row " 2448 "information was deleted in fillComplete().");
2450 #ifdef HAVE_TPETRA_DEBUG 2451 Teuchos::barrier( *
rowMap_->getComm() );
2452 #endif // HAVE_TPETRA_DEBUG 2453 clearGlobalConstants();
2461 fillComplete_ =
false;
2462 #ifdef HAVE_TPETRA_DEBUG 2465 "::resumeFill(): At end of method, either fill is not active or fill is " 2466 "complete. This violates stated post-conditions. Please report this bug " 2467 "to the Tpetra developers.");
2468 #endif // HAVE_TPETRA_DEBUG 2474 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2483 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2490 #ifdef HAVE_TPETRA_DEBUG 2491 rowMap_->getComm ()->barrier ();
2492 #endif // HAVE_TPETRA_DEBUG 2493 const char tfecfFuncName[] =
"fillComplete()";
2495 std::runtime_error,
": Graph fill state must be active (isFillActive() " 2496 "must be true) before calling fillComplete().");
2498 const int numProcs =
getComm ()->getSize ();
2501 if (! indicesAreAllocated()) {
2503 allocateIndices( GlobalIndices );
2508 bool assertNoNonlocalInserts =
false;
2510 assertNoNonlocalInserts =
2511 params->
get<
bool> (
"No Nonlocal Changes", assertNoNonlocalInserts);
2515 const bool mayNeedGlobalAssemble = ! assertNoNonlocalInserts && numProcs > 1;
2516 if (mayNeedGlobalAssemble) {
2523 numProcs > 1 &&
nonlocals_.size() > 0, std::runtime_error,
2524 ":" << std::endl <<
"The graph's communicator contains only one " 2525 "process, but there are nonlocal entries. " << std::endl <<
2526 "This probably means that invalid entries were added to the graph.");
2544 computeGlobalConstants();
2546 fillLocalGraph(params);
2548 fillComplete_ =
true;
2549 #ifdef HAVE_TPETRA_DEBUG 2553 checkInternalState();
2559 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2566 #ifdef HAVE_TPETRA_DEBUG 2567 rowMap_->getComm ()->barrier ();
2568 #endif // HAVE_TPETRA_DEBUG 2569 const char tfecfFuncName[] =
"expertStaticFillComplete()";
2571 std::runtime_error,
": fillComplete cannot have already been called and a ColMap is required.");
2574 std::runtime_error,
": a matrix will getNodeNumRows()>0 requires rowptr to be set.");
2577 std::runtime_error,
": requires a non-null domainMap & rangeMap.");
2580 std::runtime_error,
": requires StaticProfile.");
2586 nodeNumEntries_ = nodeNumAllocated_ = rowPtrs_[
getNodeNumRows()];
2591 indicesAreAllocated_ =
true;
2594 indicesAreLocal_ =
true;
2595 indicesAreGlobal_ =
false;
2607 if(importer != Teuchos::null) {
2609 std::invalid_argument,
": importer does not match matrix maps.");
2613 if(exporter != Teuchos::null) {
2615 std::invalid_argument,
": exporter does not match matrix maps.");
2621 computeGlobalConstants();
2624 fillLocalGraph(params);
2625 fillComplete_ =
true;
2627 #ifdef HAVE_TPETRA_DEBUG 2630 checkInternalState();
2637 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2643 bool requestOptimizedStorage =
true;
2644 if (params != null && params->
get(
"Optimize Storage",
true) ==
false) requestOptimizedStorage =
false;
2648 inds = LocalMatOps::template allocStorage<LocalOrdinal>(
getRowMap()->getNode(), ptrs() );
2649 for (
size_t row=0; row < numRows; ++row) {
2656 if (nodeNumEntries_ != nodeNumAllocated_) {
2658 inds = LocalMatOps::template allocStorage<LocalOrdinal>(
getRowMap()->getNode(), ptrs() );
2659 for (
size_t row=0; row < numRows; ++row) {
2670 if ( requestOptimizedStorage ) {
2676 nodeNumAllocated_ = nodeNumEntries_;
2681 if (params == null) lclparams = parameterList();
2682 else lclparams = sublist(params,
"Local Graph");
2684 lclGraph_->setStructure(ptrs,inds);
2692 LocalMatOps::finalizeGraph(uplo,diag,*lclGraph_,params);
2698 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2701 const char tfecfFuncName[] =
"replaceDomainMapAndImporter()";
2703 if( (newImporter==Teuchos::null &&
colMap_!=Teuchos::null &&
colMap_->isSameAs(*newDomainMap)) ||
2704 (newImporter!=Teuchos::null &&
colMap_!=Teuchos::null &&
colMap_->isSameAs(*newImporter->getTargetMap()) && newDomainMap->isSameAs(*newImporter->getSourceMap()))) {
2717 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2727 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2737 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2741 using Teuchos::outArg;
2743 typedef LocalOrdinal LO;
2744 typedef GlobalOrdinal GO;
2747 #ifdef HAVE_TPETRA_DEBUG 2749 "CrsGraph::computeGlobalConstants: At this point, the graph should have " 2750 "a column Map, but it does not. Please report this bug to the Tpetra " 2752 #endif // HAVE_TPETRA_DEBUG 2770 nodeMaxNumRowEntries_ = 0;
2787 if (indicesAreAllocated () && nodeNumAllocated_ > 0) {
2789 for (
size_t localRow = 0; localRow < numLocalRows; ++localRow) {
2793 RowInfo rowInfo = getRowInfo (localRow);
2796 beg = rview.
begin();
2797 end = beg + rowInfo.numEntries;
2799 for (cur = beg; cur != end; ++cur) {
2801 if (rlcid == *cur) ++nodeNumDiags_;
2808 const size_t smallestCol = as<size_t> (*beg);
2809 const size_t largestCol = as<size_t> (*(end - 1));
2811 if (smallestCol < localRow) {
2814 if (localRow < largestCol) {
2819 nodeMaxNumRowEntries_ = std::max (nodeMaxNumRowEntries_, rowInfo.numEntries);
2842 lcl[0] = as<GST> (nodeNumEntries_);
2843 lcl[1] = as<GST> (nodeNumDiags_);
2844 reduceAll<int,GST> (*
getComm (), Teuchos::REDUCE_SUM,
2846 globalNumEntries_ = gbl[0];
2847 globalNumDiags_ = gbl[1];
2848 reduceAll<int,GST> (*
getComm (), Teuchos::REDUCE_MAX,
2849 as<GST> (nodeMaxNumRowEntries_),
2850 outArg (globalMaxNumRowEntries_));
2858 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2861 typedef LocalOrdinal LO;
2862 typedef GlobalOrdinal GO;
2867 const char tfecfFuncName[] =
"makeIndicesLocal()";
2870 ": inconsistent index state. Indices must be either local on all " 2871 "processes, or global on all processes.");
2883 if (nodeNumAllocated_ &&
sizeof (LO) ==
sizeof (GO)) {
2887 lclInds1D_ = LocalMatOps::template allocStorage<LO> (
getRowMap ()->getNode (), rowPtrs_ ());
2890 const size_t offset = rowPtrs_[r];
2892 for (
size_t j = 0; j < numentry; ++j) {
2894 const LO lid =
colMap_->getLocalElement (gid);
2896 #ifdef HAVE_TPETRA_DEBUG 2900 ": In local row r=" << r <<
", global column " << gid <<
" is " 2901 "not in the column Map. This should never happen. Please " 2902 "report this bug to the Tpetra developers.");
2903 #endif // HAVE_TPETRA_DEBUG 2915 const GO*
const ginds =
gblInds2D_[r].getRawPtr ();
2919 LO*
const linds =
lclInds2D_[r].getRawPtr ();
2920 for (
size_t j = 0; j < numentry; ++j) {
2922 LO lid =
colMap_->getLocalElement (gid);
2924 #ifdef HAVE_TPETRA_DEBUG 2928 ": Global column ginds[j=" << j <<
"]=" << ginds[j]
2929 <<
" of local row r=" << r <<
" is not in the column Map. " 2930 "This should never happen. Please report this bug to the " 2931 "Tpetra developers.");
2932 #endif // HAVE_TPETRA_DEBUG 2939 indicesAreLocal_ =
true;
2940 indicesAreGlobal_ =
false;
2941 checkInternalState();
2947 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3023 int myIndices[2] = {0,0};
3024 if (indicesAreLocal_) myIndices[0] = 1;
3025 if (indicesAreGlobal_) myIndices[1] = 1;
3027 Teuchos::reduceAll<int, int> (* (
getComm()), Teuchos::REDUCE_MAX,
3028 2, myIndices, allIndices);
3031 indicesAreLocal_ = (allIndices[0]==1);
3032 indicesAreGlobal_ = (allIndices[1]==1);
3038 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3044 RowInfo rowInfo = getRowInfo(row);
3055 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3059 using Teuchos::REDUCE_MAX;
3061 typedef LocalOrdinal LO;
3062 typedef GlobalOrdinal GO;
3063 const char tfecfFuncName[] =
"makeColMap";
3074 ": The graph is locally indexed. Calling makeColMap() to make the " 3075 "column Map requires that the graph be globally indexed.");
3111 size_t numLocalColGIDs = 0, numRemoteColGIDs = 0;
3116 std::set<GO> RemoteGIDSet;
3118 for (
size_t r = 0; r < myNumRows; ++r) {
3119 RowInfo rowinfo = getRowInfo (r);
3120 if (rowinfo.numEntries > 0) {
3125 rowGids = rowGids (0, rowinfo.numEntries);
3127 for (
size_t k = 0; k < rowinfo.numEntries; ++k) {
3128 const GO gid = rowGids[k];
3129 const LO lid =
domainMap_->getLocalElement (gid);
3131 const char alreadyFound = GIDisLocal[lid];
3132 if (alreadyFound == 0) {
3133 GIDisLocal[lid] = 1;
3138 const bool notAlreadyFound = RemoteGIDSet.
insert (gid).second;
3139 if (notAlreadyFound) {
3176 if (
domainMap_->getComm ()->getSize () == 1) {
3178 numRemoteColGIDs != 0, std::runtime_error,
3179 ": " << numRemoteColGIDs <<
" column " 3180 << (numRemoteColGIDs != 1 ?
"indices are" :
"index is")
3181 <<
" not in the domain Map." << endl
3182 <<
"Either these indices are invalid or the domain Map is invalid." 3183 << endl <<
"Remember that nonsquare matrices, or matrices where the " 3184 "row and range Maps are different, require calling the version of " 3185 "fillComplete that takes the domain and range Maps as input.");
3186 if (numLocalColGIDs ==
domainMap_->getNodeNumElements()) {
3188 checkInternalState ();
3197 myColumns.
resize (numLocalColGIDs + numRemoteColGIDs);
3199 ArrayView<GO> LocalColGIDs = myColumns (0, numLocalColGIDs);
3200 ArrayView<GO> RemoteColGIDs = myColumns (numLocalColGIDs, numRemoteColGIDs);
3203 std::copy (RemoteGIDSet.
begin(), RemoteGIDSet.
end(), RemoteColGIDs.
begin());
3206 Array<int> RemoteImageIDs (numRemoteColGIDs);
3210 domainMap_->getRemoteIndexList (RemoteColGIDs, RemoteImageIDs ());
3211 #ifdef HAVE_TPETRA_DEBUG 3219 const int missingID_lcl = (stat ==
IDNotPresent ? 1 : 0);
3220 int missingID_gbl = 0;
3221 reduceAll<int, int> (*
getComm (), REDUCE_MAX, missingID_lcl,
3222 outArg (missingID_gbl));
3224 missingID_gbl == 1, std::runtime_error,
3225 ": Some column indices are not in the domain Map." << endl
3226 <<
"Either these column indices are invalid or the domain Map is " 3227 "invalid." << endl <<
"Likely cause: For a nonsquare matrix, you " 3228 "must give the domain and range Maps as input to fillComplete.");
3231 #endif // HAVE_TPETRA_DEBUG 3236 sort2 (RemoteImageIDs.begin(), RemoteImageIDs.end(), RemoteColGIDs.
begin());
3253 const size_t numDomainElts =
domainMap_->getNodeNumElements ();
3254 if (numLocalColGIDs == numDomainElts) {
3258 std::copy (domainElts.begin(), domainElts.end(), LocalColGIDs.
begin());
3263 size_t numLocalCount = 0;
3264 for (
size_t i = 0; i < numDomainElts; ++i) {
3265 if (GIDisLocal[i]) {
3266 LocalColGIDs[numLocalCount++] = domainElts[i];
3270 numLocalCount != numLocalColGIDs, std::logic_error,
3271 ": numLocalCount = " << numLocalCount <<
" != numLocalColGIDs = " 3272 << numLocalColGIDs <<
". This should never happen. Please report " 3273 "this bug to the Tpetra developers.");
3319 const GO indexBase =
domainMap_->getIndexBase ();
3323 checkInternalState ();
3328 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3335 RowInfo rowInfo = getRowInfo(row);
3344 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3352 "CrsGraph: It's not allowed to call makeImportExport() unless the graph " 3353 "has a column Map.");
3366 if (params.
is_null () || ! params->isSublist (
"Import")) {
3380 if (params.
is_null () || ! params->isSublist (
"Export")) {
3392 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3396 std::ostringstream oss;
3397 oss << DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>::description();
3399 oss <<
"{status = fill complete" 3406 oss <<
"{status = fill not complete" 3414 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3420 const char tfecfFuncName[] =
"describe()";
3432 const int myImageID = comm->getRank(),
3433 numImages = comm->getSize();
3438 width = std::max<size_t>(width,Teuchos::as<size_t>(11)) + 2;
3448 if (myImageID == 0) out << this->
description() << std::endl;
3451 out <<
"Global number of diagonals = " << globalNumDiags_ << std::endl;
3452 out <<
"Global max number of row entries = " << globalMaxNumRowEntries_ << std::endl;
3456 if (myImageID == 0) out <<
"\nRow map: " << std::endl;
3459 if (myImageID == 0) out <<
"\nColumn map: " << std::endl;
3463 if (myImageID == 0) out <<
"\nDomain map: " << std::endl;
3467 if (myImageID == 0) out <<
"\nRange map: " << std::endl;
3473 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
3474 if (myImageID == imageCtr) {
3475 out <<
"Node ID = " << imageCtr << std::endl
3476 <<
"Node number of entries = " << nodeNumEntries_ << std::endl
3477 <<
"Node number of diagonals = " << nodeNumDiags_ << std::endl
3478 <<
"Node max number of entries = " << nodeMaxNumRowEntries_ << std::endl;
3479 if (indicesAreAllocated()) {
3480 out <<
"Node number of allocated entries = " << nodeNumAllocated_ << std::endl;
3483 out <<
"Indices are not allocated." << std::endl;
3494 for (
int imageCtr = 0; imageCtr < numImages; ++imageCtr) {
3495 if (myImageID == imageCtr) {
3496 out << std::setw(width) <<
"Node ID" 3497 << std::setw(width) <<
"Global Row" 3498 << std::setw(width) <<
"Num Entries";
3504 RowInfo rowinfo = getRowInfo(r);
3505 GlobalOrdinal gid =
rowMap_->getGlobalElement(r);
3506 out << std::setw(width) << myImageID
3507 << std::setw(width) << gid
3508 << std::setw(width) << rowinfo.numEntries;
3512 for (
size_t j=0; j < rowinfo.numEntries; ++j) out << rowview[j] <<
" ";
3516 for (
size_t j=0; j < rowinfo.numEntries; ++j) out <<
colMap_->getGlobalElement(rowview[j]) <<
" ";
3531 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3545 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3555 const char tfecfFuncName[] =
"copyAndPermute";
3557 const this_type& src_graph =
dynamic_cast<const this_type&
> (source);
3560 permuteToLIDs.
size() != permuteFromLIDs.
size(), std::runtime_error,
3561 ": permuteToLIDs and permuteFromLIDs must have the same size.");
3562 const bool src_filled = src_graph.isFillComplete ();
3564 const map_type& srcRowMap = * (src_graph.getRowMap ());
3568 LocalOrdinal myid = 0;
3569 for (
size_t i = 0; i < numSameIDs; ++i, ++myid) {
3572 size_t row_length = src_graph.getNumEntriesInGlobalRow (gid);
3573 row_copy.
resize (row_length);
3574 size_t check_row_length = 0;
3575 src_graph.getGlobalRowCopy (gid, row_copy (), check_row_length);
3580 src_graph.getGlobalRowView (gid,row);
3585 for (LocalOrdinal i=0; i<permuteToLIDs.
size(); ++i) {
3589 size_t row_length = src_graph.getNumEntriesInGlobalRow (srcgid);
3590 row_copy.
resize (row_length);
3591 size_t check_row_length = 0;
3592 src_graph.getGlobalRowCopy (srcgid, row_copy (), check_row_length);
3597 src_graph.getGlobalRowView (srcgid, row);
3604 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3611 size_t& constantNumPackets,
3615 const char tfecfFuncName[] =
"packAndPrepare";
3617 exportLIDs.
size() != numPacketsPerLID.
size(), std::runtime_error,
3618 ": exportLIDs and numPacketsPerLID must have the same size.");
3620 const this_type& src_graph =
dynamic_cast<const this_type&
> (source);
3627 ": The target CrsGraph of an Import or Export must not be fillComplete.");
3629 constantNumPackets = 0;
3631 size_t totalNumPackets = 0;
3633 for (LocalOrdinal i=0; i<exportLIDs.
size(); ++i) {
3634 GlobalOrdinal GID = src_graph.getMap()->getGlobalElement(exportLIDs[i]);
3635 size_t row_length = src_graph.getNumEntriesInGlobalRow(GID);
3636 numPacketsPerLID[i] = row_length;
3637 totalNumPackets += row_length;
3640 exports.
resize(totalNumPackets);
3643 size_t exportsOffset = 0;
3644 for (LocalOrdinal i=0; i<exportLIDs.
size(); ++i) {
3645 GlobalOrdinal GID = src_graph.getMap()->getGlobalElement(exportLIDs[i]);
3646 size_t row_length = src_graph.getNumEntriesInGlobalRow(GID);
3648 size_t check_row_length = 0;
3649 src_graph.getGlobalRowCopy(GID, row(), check_row_length);
3651 row_iter = row.
begin(), row_end = row.
end();
3653 for (; row_iter != row_end; ++row_iter, ++j) {
3654 exports[exportsOffset+j] = *row_iter;
3656 exportsOffset += row.
size();
3661 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3667 size_t constantNumPackets,
3688 const char tfecfFuncName[] =
"unpackAndCombine";
3690 importLIDs.
size() != numPacketsPerLID.
size(), std::runtime_error,
3691 ": importLIDs and numPacketsPerLID must have the same size.");
3694 ": Import or Export operations are not allowed on the destination " 3695 "CrsGraph if it is fill complete.");
3696 size_t importsOffset = 0;
3699 iter_type impLIDiter = importLIDs.
begin();
3700 iter_type impLIDend = importLIDs.
end();
3702 for (
size_t i = 0; impLIDiter != impLIDend; ++impLIDiter, ++i) {
3703 LocalOrdinal row_length = numPacketsPerLID[i];
3706 importsOffset += row_length;
3711 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3717 using Teuchos::null;
3732 (newMap.is_null ()) ? null : newMap->getComm ();
3742 domainMap =
domainMap_->replaceCommWithSubset (newComm);
3753 rangeMap =
rangeMap_->replaceCommWithSubset (newComm);
3757 colMap =
colMap_->replaceCommWithSubset (newComm);
3771 rangeMap != rowMap &&
3773 if (params.
is_null () || ! params->isSublist (
"Export")) {
3774 exporter =
rcp (
new export_type (rowMap, rangeMap));
3778 exporter =
rcp (
new export_type (rowMap, rangeMap, exportSublist));
3783 domainMap != colMap &&
3785 if (params.
is_null () || ! params->isSublist (
"Import")) {
3786 importer =
rcp (
new import_type (domainMap, colMap));
3789 importer =
rcp (
new import_type (domainMap, colMap, importSublist));
3805 this->
map_ = rowMap;
3820 #define TPETRA_CRSGRAPH_INSTANT(LO,GO,NODE) \ 3822 template class CrsGraph< LO , GO , NODE >; \ 3825 #endif // TPETRA_CRSGRAPH_DEF_HPP ScalarType * values() const
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this graph.
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
RCP< const ParameterList > getValidParameters() const
Default parameter list suitable for validation.
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void reserve(size_type n)
size_t findLocalIndex(RowInfo rowinfo, LocalOrdinal ind, size_t hint=0) const
Find the column offset corresponding to the given (local) column index.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &Indices) const
Extract a const, non-persisting view of global indices in a specified row of the graph.
bool isLowerTriangular() const
Whether the graph is locally lower triangular.
RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > getExporter() const
Returns the exporter associated with this graph.
ProfileType getProfileType() const
Returns true if the graph was allocated with static data structures.
size_t getNodeNumRows() const
Returns the number of graph rows owned on the calling node.
int shapeUninitialized(OrdinalType numRows, OrdinalType numCols)
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > rangeMap_
The Map describing the range of the (matrix corresponding to the) graph.
bool haveGlobalConstants_
Whether all processes have computed global constants.
bool hasColMap() const
Whether the graph has a column Map.
ArrayRCP< const size_t > numAllocPerRow_
The maximum number of entries to allow in each locally owned row, per row.
bool isUpperTriangular() const
Whether the graph is locally upper triangular.
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &indices, size_t &NumIndices) const
Extract a list of elements in a specified local row of the graph. Put into storage allocated by calli...
void insertGlobalIndicesFiltered(const GlobalOrdinal localRow, const ArrayView< const GlobalOrdinal > &indices)
Like insertGlobalIndices(), but with column Map filtering.
void transformLocalValues(RowInfo rowInfo, const Teuchos::ArrayView< Scalar > &rowVals, const Teuchos::ArrayView< const LocalOrdinal > &inds, const Teuchos::ArrayView< const Scalar > &newVals, BinaryFunction f) const
Transform the given values using local indices.
void sortRowIndices(RowInfo rowinfo)
Sort the column indices in the given row.
void setParameterList(const RCP< ParameterList > ¶ms)
Set the given list of parameters (must be nonnull).
ArrayRCP< LocalOrdinal > lclInds1D_
lclInds1D_ are the indices for all rows
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > domainMap_
The Map describing the domain of the (matrix corresponding to the) graph.
#define TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(throw_exception_test, Exception, msg)
void replaceDomainMapAndImporter(const Teuchos::RCP< const map_type > &newDomainMap, Teuchos::RCP< const Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replace the current domain Map and Import with the given parameters.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
Print the object with some verbosity level to an FancyOStream object.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::map< GlobalOrdinal, std::deque< GlobalOrdinal > > nonlocals_
Nonlocal data given to insertGlobalValues or sumIntoGlobalValues.
const_pointer const_iterator
GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this graph.
size_t getNodeNumEntries() const
Returns the local number of entries in the graph.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices) const
Extract a const, non-persisting view of local indices in a specified row of the graph.
ArrayRCP< size_t > numRowEntries_
The number of local entries in each locally owned row.
void insertGlobalIndices(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices)
Insert global indices into the graph.
RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > exporter_
The Export from the row Map to the range Map.
bool isSorted() const
Indicates whether the graph indices in all rows are known to be sorted.
bool isStorageOptimized() const
Returns true if storage has been optimized.
global_size_t getGlobalNumRows() const
Returns the number of global rows in the graph.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRowMap() const
Returns the Map that describes the row distribution in this graph.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
ArrayRCP< const LocalOrdinal > getNodePackedIndices() const
Get an ArrayRCP of the packed column-indices.
size_t getGlobalMaxNumRowEntries() const
Maximum number of entries in all rows over all processes.
bool isNodeLocalElement(LocalOrdinal localIndex) const
Whether the given local index is valid for this Map on this process.
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
Remove processes owning zero rows from the Maps and their communicator.
void makeColMap()
Make the column Map.
void setDomainRangeMaps(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap)
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > colMap_
The Map describing the distribution of columns of the graph.
size_t getNodeAllocationSize() const
Returns the total number of indices allocated for the graph, across all rows on this node...
ArrayRCP< GlobalOrdinal > gblInds1D_
gblInds1D_ are the indices for all rows
global_size_t getGlobalNumCols() const
Returns the number of global columns in the graph.
void mergeRowIndicesAndValues(RowInfo rowinfo, const Teuchos::ArrayView< Scalar > &rowValues)
Merge duplicate row indices in the given row, along with their corresponding values.
virtual void packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< GlobalOrdinal > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)
Perform any packing or preparation required for communication.
const RCP< const Comm< int > > & getComm() const
Returns the communicator.
void resize(const size_type n, const T &val=T())
size_t global_size_t
Global size_t object.
void fillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< ParameterList > ¶ms=null)
Signal that data entry is complete, specifying domain and range maps.
RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > getImporter() const
Returns the importer associated with this graph.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
ProfileType pftype_
Whether the graph was allocated with static or dynamic profile.
bool noRedundancies_
Whether the graph's indices are non-redundant (merged) in each row, on this process.
virtual void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const GlobalOrdinal > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode CM)
Perform any unpacking and combining after communication.
size_t getNumAllocatedEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of allocated entries for this node in the specified global row ...
void mergeAllIndices()
Merge duplicate row indices in all of the rows.
size_t findGlobalIndex(RowInfo rowinfo, GlobalOrdinal ind, size_t hint=0) const
Find the column offset corresponding to the given (global) column index.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, size_t &NumIndices) const
Extract a list of elements in a specified global row of the graph. Put into pre-allocated storage...
Sets up and executes a communication plan for a Tpetra DistObject.
GlobalOrdinal getGlobalElement(LocalOrdinal localIndex) const
The global index corresponding to the given local index.
CombineMode
Tpetra::Combine Mode enumerable type.
size_t getNodeMaxNumRowEntries() const
Maximum number of entries in all rows owned by the calling process.
size_t getNumAllocatedEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of allocated entries on this node in the specified local row...
void setLocallyModified()
Report that we made a local modification to its structure.
const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getMap() const
The Map describing the parallel distribution of this object.
TEUCHOSCORE_LIB_DLL_EXPORT std::string toString(const EVerbosityLevel verbLevel)
void setMyParamList(const RCP< ParameterList > ¶mList)
bool isMerged() const
Whether duplicate column indices in each row have been merged.
virtual void copyAndPermute(const SrcDistObject &source, size_t numSameIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteToLIDs, const Teuchos::ArrayView< const LocalOrdinal > &permuteFromLIDs)
Perform copies and permutations that are local to this process.
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > rowMap_
The Map describing the distribution of rows of the graph.
Abstract base class for objects that can be the source of an Import or Export operation.
bool lowerTriangular_
Whether the graph is locally lower triangular.
void resize(size_type new_size, const value_type &x=value_type())
ArrayRCP< Array< LocalOrdinal > > lclInds2D_
lclInds2D_[r] are the indices for row r.
RCP< ParameterList > getNonconstParameterList()
size_t numAllocForAllRows_
The maximum number of entries to allow in each locally owned row.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the Map associated with the domain of this graph.
std::vector< T >::const_iterator const_iterator
RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > importer_
The Import from the domain Map to the column Map.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getColMap() const
Returns the Map that describes the column distribution in this graph.
void insertLocalIndices(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices)
Insert local indices into the graph.
void transformGlobalValues(RowInfo rowInfo, const Teuchos::ArrayView< Scalar > &rowVals, const Teuchos::ArrayView< const GlobalOrdinal > &inds, const Teuchos::ArrayView< const Scalar > &newVals, BinaryFunction f) const
Transform the given values using global indices.
RCP< CommRequest< Ordinal > > ireceive(const ArrayRCP< Packet > &recvBuffer, const int sourceRank, const int tag, const Comm< Ordinal > &comm)
std::string description() const
Return a simple one-line description of this object.
LocalOrdinal getLocalElement(GlobalOrdinal globalIndex) const
The local index corresponding to the given global index.
void push_back(const value_type &x)
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 distributed graph accessed by rows (adjacency lists) and stored sparsely.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
void computeIndexState()
Set collectively whether the graph uses global or local indices.
Describes a parallel distribution of objects over processes.
void resumeFill(const RCP< ParameterList > ¶ms=null)
bool isSameAs(const Map< LocalOrdinal, GlobalOrdinal, Node > &map) const
True if and only if map is identical to this Map.
bool upperTriangular_
Whether the graph is locally upper triangular.
TypeTo as(const TypeFrom &t)
bool isGloballyIndexed() const
If graph indices are in the global range, this function returns true. Otherwise, this function return...
ArrayRCP< const size_t > getNodeRowPtrs() const
Get an ArrayRCP of the row-offsets.
void mergeRowIndices(RowInfo rowinfo)
Merge duplicate row indices in the given row.
void expertStaticFillComplete(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const RCP< const Import< LocalOrdinal, GlobalOrdinal, Node > > &importer=Teuchos::null, const RCP< const Export< LocalOrdinal, GlobalOrdinal, Node > > &exporter=Teuchos::null, const RCP< ParameterList > ¶ms=Teuchos::null)
Perform a fillComplete on a graph that already has data, via setAllIndices().
void insertLocalIndicesFiltered(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &indices)
Like insertLocalIndices(), but with column Map filtering.
size_t insertIndices(const RowInfo &rowInfo, const SLocalGlobalViews &newInds, const ELocalGlobal lg, const ELocalGlobal I)
Insert indices into the given row.
bool isFillComplete() const
Returns true if fillComplete() has been called and the graph is in compute mode.
void sortRowIndicesAndValues(RowInfo rowinfo, ArrayView< Scalar > values)
Sort the column indices and their values in the given row.
RCP< Node > getNode() const
Returns the underlying node.
void sortAllIndices()
Sort the column indices in all the rows.
bool indicesAreSorted_
Whether the graph's indices are sorted in each row, on this process.
RCP< CommRequest< Ordinal > > isend(const ArrayRCP< const Packet > &sendBuffer, const int destRank, const int tag, const Comm< Ordinal > &comm)
bool isLocallyIndexed() const
If graph indices are in the local range, this function returns true. Otherwise, this function returns...
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
void globalAssemble()
Communicate non-local contributions to other processes.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in the graph.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
Returns the Map associated with the domain of this graph.
bool haveLocalConstants_
Whether this process has computed local constants.
virtual ~CrsGraph()
Destructor.
Base class for distributed Tpetra objects that support data redistribution.
iterator insert(iterator position, const value_type &x)
void removeLocalIndices(LocalOrdinal localRow)
Remove all graph indices from the specified local row.
bool isFillActive() const
Returns true if resumeFill() has been called and the graph is in edit mode.
ArrayRCP< Array< GlobalOrdinal > > gblInds2D_
gblInds2D_[r] are the indices for row r.
void insertIndicesAndValues(const RowInfo &rowInfo, const SLocalGlobalViews &newInds, const ArrayView< Scalar > &oldRowVals, const ArrayView< const Scalar > &newRowVals, const ELocalGlobal lg, const ELocalGlobal I)
Insert indices and their values into the given row.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
std::string toString(const T &t)
std::string typeName(const T &t)
Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > map_
The Map over which this object is distributed.
void setAllIndices(const ArrayRCP< size_t > &rowPointers, const ArrayRCP< LocalOrdinal > &columnIndices)
Set the graph's data directly, using 1-D storage.