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>
52 #include <Teuchos_as.hpp>
56 #include <Teuchos_SerialDenseMatrix.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,
71 const RCP<ParameterList>& params)
72 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
75 , nodeNumAllocated_(OrdinalTraits<size_t>::invalid())
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)
88 typedef Teuchos::OrdinalTraits<size_t> OTST;
90 TEUCHOS_TEST_FOR_EXCEPTION(maxNumEntriesPerRow == OTST::invalid(),
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,
106 const RCP<ParameterList>& params)
107 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
111 , nodeNumAllocated_(OrdinalTraits<size_t>::invalid())
113 , numAllocForAllRows_(maxNumEntriesPerRow)
114 , indicesAreAllocated_(false)
115 , indicesAreLocal_(false)
116 , indicesAreGlobal_(false)
117 , fillComplete_(false)
118 , indicesAreSorted_(true)
119 , noRedundancies_(true)
120 , haveLocalConstants_ (false)
121 , haveGlobalConstants_ (false)
124 typedef Teuchos::OrdinalTraits<size_t> OTST;
126 TEUCHOS_TEST_FOR_EXCEPTION(maxNumEntriesPerRow == OTST::invalid(),
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>
139 const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc,
141 const RCP<ParameterList>& params)
142 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
145 , nodeNumAllocated_(OrdinalTraits<size_t>::invalid())
147 , numAllocPerRow_(NumEntriesPerRowToAlloc)
148 , numAllocForAllRows_(0)
149 , indicesAreAllocated_(false)
150 , indicesAreLocal_(false)
151 , indicesAreGlobal_(false)
152 , fillComplete_(false)
153 , indicesAreSorted_(true)
154 , noRedundancies_(true)
155 , haveLocalConstants_ (false)
156 , haveGlobalConstants_ (false)
159 typedef Teuchos::OrdinalTraits<size_t> OTST;
160 const char tfecfFuncName[] =
"CrsGraph(rowMap,NumEntriesPerRowToAlloc)";
162 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC((
size_t)NumEntriesPerRowToAlloc.size() !=
getNodeNumRows(), std::invalid_argument,
163 ": NumEntriesPerRowToAlloc must have as many entries as specified by rowMap for this node.");
165 const size_t curRowCount = NumEntriesPerRowToAlloc[r];
166 TEUCHOS_TEST_FOR_EXCEPTION(curRowCount == OTST::invalid(),
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>
182 const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc,
184 const RCP<ParameterList>& params)
185 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
189 , nodeNumAllocated_(OrdinalTraits<size_t>::invalid())
191 , numAllocPerRow_(NumEntriesPerRowToAlloc)
192 , numAllocForAllRows_(0)
193 , indicesAreAllocated_(false)
194 , indicesAreLocal_(false)
195 , indicesAreGlobal_(false)
196 , fillComplete_(false)
197 , indicesAreSorted_(true)
198 , noRedundancies_(true)
199 , haveLocalConstants_ (false)
200 , haveGlobalConstants_ (false)
203 typedef Teuchos::OrdinalTraits<size_t> OTST;
204 const char tfecfFuncName[] =
"CrsGraph(rowMap,colMap,NumEntriesPerRowToAlloc)";
206 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC((
size_t)NumEntriesPerRowToAlloc.size() !=
getNodeNumRows(), std::invalid_argument,
207 ": NumEntriesPerRowToAlloc must have as many entries as specified by rowMap for this node.");
209 const size_t curRowCount = NumEntriesPerRowToAlloc[r];
210 TEUCHOS_TEST_FOR_EXCEPTION(curRowCount == OTST::invalid(),
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>
226 const ArrayRCP<size_t> & rowPointers,
227 const ArrayRCP<LocalOrdinal> & columnIndices,
228 const RCP<ParameterList>& params)
229 :
DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>(rowMap)
233 , nodeNumAllocated_(OrdinalTraits<size_t>::invalid())
235 , numAllocForAllRows_(0)
236 , indicesAreAllocated_(true)
237 , indicesAreLocal_(true)
238 , indicesAreGlobal_(false)
239 , fillComplete_(false)
240 , indicesAreSorted_(true)
241 , noRedundancies_(true)
242 , haveLocalConstants_ (false)
243 , haveGlobalConstants_ (false)
247 globalNumEntries_ = globalNumDiags_ = globalMaxNumRowEntries_ = OrdinalTraits<global_size_t>::invalid();
249 checkInternalState();
254 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
258 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
259 RCP<const ParameterList>
263 RCP<ParameterList> params = parameterList (
"Tpetra::CrsGraph");
266 RCP<ParameterList> importSublist = parameterList (
"Import");
278 Distributor distributor (rowMap_->getComm(), importSublist);
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>
295 RCP<const ParameterList> validParams = getValidParameters ();
296 params->validateParametersAndSetDefaults (*validParams);
297 this->setMyParamList (params);
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()";
310 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
311 isFillComplete() ==
false, std::runtime_error,
312 ": requires domain map, which requires that fillComplete() has been "
314 return getDomainMap()->getGlobalNumElements();
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()";
327 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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>
350 return rowMap_->getNode();
353 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
354 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
360 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
361 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
367 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
368 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
374 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
375 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
381 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
382 RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> >
388 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
389 RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> >
395 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
398 return (colMap_ != null);
401 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
404 bool isOpt = indicesAreAllocated_ && (numRowEntries_ == null) && (getNodeNumRows() > 0);
405 #ifdef HAVE_TPETRA_DEBUG
406 const char tfecfFuncName[] =
"isStorageOptimized()";
407 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( (isOpt ==
true) && (getProfileType() ==
DynamicProfile), std::logic_error,
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>
458 return upperTriangular_;
461 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
464 return lowerTriangular_;
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>
486 const RCP<const Comm<int> > &
489 return rowMap_->getComm();
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>
519 return indicesAreSorted_;
525 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
528 return noRedundancies_;
533 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
541 indicesAreSorted_ =
false;
542 noRedundancies_ =
false;
546 haveLocalConstants_ =
false;
551 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
559 const char tfecfFuncName[] =
"allocateIndices()";
560 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
561 isLocallyIndexed() && lg==GlobalIndices, std::logic_error,
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.");
564 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
565 isGloballyIndexed() && lg==LocalIndices, std::logic_error,
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.");
568 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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.");
573 const size_t numRows = getNodeNumRows();
574 indicesAreLocal_ = (lg == LocalIndices);
575 indicesAreGlobal_ = (lg == GlobalIndices);
576 nodeNumAllocated_ = 0;
577 if (numAllocPerRow_ == null && getNodeNumRows() > 0) {
580 ArrayRCP<size_t> tmpnumallocperrow = arcp<size_t>(numRows);
581 std::fill(tmpnumallocperrow.begin(), tmpnumallocperrow.end(), numAllocForAllRows_);
582 numAllocPerRow_ = tmpnumallocperrow;
596 rowPtrs_ = LocalMatOps::allocRowPtrs( getRowMap()->getNode(), numAllocPerRow_() );
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];
609 typename ArrayRCP<const size_t>::iterator numalloc = numAllocPerRow_.begin();
610 size_t howmany = numAllocForAllRows_;
611 if (lg == LocalIndices) {
612 lclInds2D_ = arcp< Array<LocalOrdinal> >(numRows);
613 nodeNumAllocated_ = 0;
614 for (
size_t i=0; i < numRows; ++i) {
615 if (numAllocPerRow_ != null) howmany = *numalloc++;
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) {
624 if (numAllocPerRow_ != null) howmany = *numalloc++;
625 nodeNumAllocated_ += howmany;
626 if (howmany > 0) gblInds2D_[i].resize(howmany);
631 numRowEntries_ = arcp<size_t>(numRows);
632 std::fill( numRowEntries_.begin(), numRowEntries_.end(), 0 );
635 numAllocForAllRows_ = 0;
636 numAllocPerRow_ = null;
637 indicesAreAllocated_ =
true;
638 checkInternalState();
644 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
646 ArrayRCP<T> CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::allocateValues1D()
const
648 const char tfecfFuncName[] =
"allocateValues()";
649 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
650 indicesAreAllocated() ==
false,
651 std::runtime_error,
": graph indices must be allocated before values."
653 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
655 std::runtime_error,
": graph indices must be allocated in a static profile."
657 ArrayRCP<T> values1D;
658 values1D = LocalMatOps::template allocStorage<T>( getRowMap()->getNode(), rowPtrs_() );
665 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
668 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::allocateValues2D()
const
670 const char tfecfFuncName[] =
"allocateValues2D()";
671 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
672 indicesAreAllocated() ==
false,
673 std::runtime_error,
": graph indices must be allocated before values."
675 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
677 std::runtime_error,
": graph indices must be allocated in a dynamic profile."
679 ArrayRCP<Array<T> > values2D;
680 values2D = arcp<Array<T> > (getNodeNumRows ());
681 if (lclInds2D_ != null) {
682 const size_t numRows = lclInds2D_.size ();
683 for (
size_t r = 0; r < numRows; ++r) {
684 values2D[r].resize (lclInds2D_[r].size ());
687 else if (gblInds2D_ != null) {
688 const size_t numRows = gblInds2D_.size ();
689 for (
size_t r = 0; r < numRows; ++r) {
690 values2D[r].resize (gblInds2D_[r].size ());
699 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
700 template <ELocalGlobal lg,
class T>
702 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
703 updateAllocAndValues (RowInfo rowinfo,
707 #ifdef HAVE_TPETRA_DEBUG
708 TEUCHOS_TEST_FOR_EXCEPT( ! rowMap_->isNodeLocalElement(rowinfo.localRow) );
709 TEUCHOS_TEST_FOR_EXCEPT( newAllocSize < rowinfo.allocSize );
710 TEUCHOS_TEST_FOR_EXCEPT( (lg == LocalIndices && ! isLocallyIndexed()) ||
711 (lg == GlobalIndices && ! isGloballyIndexed()) );
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>
732 ArrayView<const LocalOrdinal>
733 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
734 getLocalView (RowInfo rowinfo)
const
736 ArrayView<const LocalOrdinal> view;
737 if (rowinfo.allocSize > 0) {
738 if (lclInds1D_ != null) {
739 view = lclInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
741 else if (!lclInds2D_[rowinfo.localRow].empty()) {
742 view = lclInds2D_[rowinfo.localRow] ();
751 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
752 ArrayView<LocalOrdinal>
753 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
754 getLocalViewNonConst (RowInfo rowinfo)
756 ArrayView<LocalOrdinal> view;
757 if (rowinfo.allocSize > 0) {
758 if (lclInds1D_ != null) {
759 view = lclInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
761 else if (! lclInds2D_[rowinfo.localRow].empty()) {
762 view = lclInds2D_[rowinfo.localRow] ();
771 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
772 ArrayView<const GlobalOrdinal>
773 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
774 getGlobalView (RowInfo rowinfo)
const
776 ArrayView<const GlobalOrdinal> view;
777 if (rowinfo.allocSize > 0) {
778 if (gblInds1D_ != null) {
779 view = gblInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
781 else if (! gblInds2D_[rowinfo.localRow].empty()) {
782 view = gblInds2D_[rowinfo.localRow] ();
791 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
792 ArrayView<GlobalOrdinal>
793 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
794 getGlobalViewNonConst (RowInfo rowinfo)
796 ArrayView<GlobalOrdinal> view;
797 if (rowinfo.allocSize > 0) {
798 if (gblInds1D_ != null) {
799 view = gblInds1D_ (rowinfo.offset1D, rowinfo.allocSize);
801 else if (!gblInds2D_[rowinfo.localRow].empty()) {
802 view = gblInds2D_[rowinfo.localRow] ();
811 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
812 RowInfo CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::getRowInfo(
size_t myRow)
const
814 #ifdef HAVE_TPETRA_DEBUG
815 const char tfecfFuncName[] =
"getRowInfo()";
816 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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.");
823 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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
828 const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid ();
830 ret.localRow = myRow;
831 if (nodeNumAllocated_ != 0 && nodeNumAllocated_ != STINV) {
836 ret.offset1D = rowPtrs_[myRow];
837 ret.allocSize = rowPtrs_[myRow+1] - rowPtrs_[myRow];
838 if (numRowEntries_ == null) {
839 ret.numEntries = ret.allocSize;
842 ret.numEntries = numRowEntries_[myRow];
846 ret.offset1D = STINV;
847 if (isLocallyIndexed ()) {
848 ret.allocSize = lclInds2D_[myRow].size();
851 ret.allocSize = gblInds2D_[myRow].size();
853 ret.numEntries = numRowEntries_[myRow];
856 else if (nodeNumAllocated_ == 0) {
860 ret.offset1D = STINV;
862 else if (indicesAreAllocated () ==
false) {
864 if (numAllocPerRow_ == null) {
865 ret.allocSize = numAllocForAllRows_;
868 ret.allocSize = numAllocPerRow_[myRow];
871 ret.offset1D = STINV;
875 TEUCHOS_TEST_FOR_EXCEPT(
true);
883 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
884 void CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::staticAssertions()
const
894 Teuchos::CompileTimeAssert<sizeof(GlobalOrdinal) < sizeof(LocalOrdinal)> cta_size1; (void)cta_size1;
895 Teuchos::CompileTimeAssert<sizeof(global_size_t) < sizeof(size_t) > cta_size2; (void)cta_size2;
897 std::string msg = typeName(*
this) +
": Object cannot be allocated with stated template arguments: size assumptions are not valid.";
898 TEUCHOS_TEST_FOR_EXCEPTION( (
size_t)OrdinalTraits<LocalOrdinal>::max() > OrdinalTraits<size_t>::max(), std::runtime_error, msg);
899 TEUCHOS_TEST_FOR_EXCEPTION( (
global_size_t)OrdinalTraits<LocalOrdinal>::max() > (
global_size_t)OrdinalTraits<GlobalOrdinal>::max(), std::runtime_error, msg);
900 TEUCHOS_TEST_FOR_EXCEPTION( (
size_t)OrdinalTraits<GlobalOrdinal>::max() > OrdinalTraits<global_size_t>::max(), std::runtime_error, msg);
901 TEUCHOS_TEST_FOR_EXCEPTION( OrdinalTraits<size_t>::max() > OrdinalTraits<global_size_t>::max(), std::runtime_error, msg);
907 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
908 template <ELocalGlobal lg>
909 size_t CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::filterIndices(
const SLocalGlobalNCViews &inds)
const
911 const Map<LocalOrdinal,GlobalOrdinal,Node> &cmap = *colMap_;
912 Teuchos::CompileTimeAssert<lg != GlobalIndices && lg != LocalIndices> cta_lg;
914 size_t numFiltered = 0;
915 #ifdef HAVE_TPETRA_DEBUG
916 size_t numFiltered_debug = 0;
918 if (lg == GlobalIndices) {
919 ArrayView<GlobalOrdinal> ginds = inds.ginds;
920 typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin(),
921 cptr = ginds.begin();
922 while (cptr != ginds.end()) {
923 if (cmap.isNodeGlobalElement(*cptr)) {
925 #ifdef HAVE_TPETRA_DEBUG
931 numFiltered = fend - ginds.begin();
933 else if (lg == LocalIndices) {
934 ArrayView<LocalOrdinal> linds = inds.linds;
935 typename ArrayView<LocalOrdinal>::iterator fend = linds.begin(),
936 cptr = linds.begin();
937 while (cptr != linds.end()) {
938 if (cmap.isNodeLocalElement(*cptr)) {
940 #ifdef HAVE_TPETRA_DEBUG
946 numFiltered = fend - linds.begin();
948 #ifdef HAVE_TPETRA_DEBUG
949 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
957 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
959 size_t CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
960 filterGlobalIndicesAndValues (
const ArrayView<GlobalOrdinal>& ginds,
961 const ArrayView<T>& vals)
const
963 const Map<LocalOrdinal,GlobalOrdinal,Node>& cmap = *colMap_;
964 size_t numFiltered = 0;
965 typename ArrayView<T>::iterator fvalsend = vals.begin();
966 typename ArrayView<T>::iterator valscptr = vals.begin();
967 #ifdef HAVE_TPETRA_DEBUG
968 size_t numFiltered_debug = 0;
970 typename ArrayView<GlobalOrdinal>::iterator fend = ginds.begin();
971 typename ArrayView<GlobalOrdinal>::iterator cptr = ginds.begin();
972 while (cptr != ginds.end()) {
973 if (cmap.isNodeGlobalElement (*cptr)) {
975 *fvalsend++ = *valscptr;
976 #ifdef HAVE_TPETRA_DEBUG
983 numFiltered = fend - ginds.begin();
984 #ifdef HAVE_TPETRA_DEBUG
985 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
986 TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
987 const size_t numFilteredActual =
988 Teuchos::as<size_t> (fvalsend - vals.begin ());
989 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
997 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1000 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
1001 filterLocalIndicesAndValues (
const ArrayView<LocalOrdinal>& linds,
1002 const ArrayView<T>& vals)
const
1004 const Map<LocalOrdinal,GlobalOrdinal,Node>& cmap = *colMap_;
1005 size_t numFiltered = 0;
1006 typename ArrayView<T>::iterator fvalsend = vals.begin();
1007 typename ArrayView<T>::iterator valscptr = vals.begin();
1008 #ifdef HAVE_TPETRA_DEBUG
1009 size_t numFiltered_debug = 0;
1011 typename ArrayView<LocalOrdinal>::iterator fend = linds.begin();
1012 typename ArrayView<LocalOrdinal>::iterator cptr = linds.begin();
1013 while (cptr != linds.end()) {
1014 if (cmap.isNodeLocalElement (*cptr)) {
1016 *fvalsend++ = *valscptr;
1017 #ifdef HAVE_TPETRA_DEBUG
1018 ++numFiltered_debug;
1024 numFiltered = fend - linds.begin();
1025 #ifdef HAVE_TPETRA_DEBUG
1026 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFiltered_debug );
1027 TEUCHOS_TEST_FOR_EXCEPT( valscptr != vals.end() );
1028 const size_t numFilteredActual =
1029 Teuchos::as<size_t> (fvalsend - vals.begin ());
1030 TEUCHOS_TEST_FOR_EXCEPT( numFiltered != numFilteredActual );
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
1047 TEUCHOS_TEST_FOR_EXCEPTION(
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) {
1054 ArrayView<const GlobalOrdinal> new_ginds = newInds.ginds;
1055 numNewInds = new_ginds.size();
1056 if (I == GlobalIndices) {
1057 ArrayView<GlobalOrdinal> gind_view = getGlobalViewNonConst(rowinfo);
1058 std::copy(new_ginds.begin(), new_ginds.end(), gind_view.begin()+rowinfo.numEntries);
1060 else if (I == LocalIndices) {
1061 ArrayView<LocalOrdinal> lind_view = getLocalViewNonConst(rowinfo);
1062 typename ArrayView<const GlobalOrdinal>::iterator in = new_ginds.begin();
1063 const typename ArrayView<const GlobalOrdinal>::iterator stop = new_ginds.end();
1064 typename ArrayView<LocalOrdinal>::iterator out = lind_view.begin()+rowinfo.numEntries;
1065 while (in != stop) {
1066 *out++ = colMap_->getLocalElement (*in++);
1070 else if (lg == LocalIndices) {
1071 ArrayView<const LocalOrdinal> new_linds = newInds.linds;
1072 numNewInds = new_linds.size();
1073 if (I == LocalIndices) {
1074 ArrayView<LocalOrdinal> lind_view = getLocalViewNonConst(rowinfo);
1075 std::copy(new_linds.begin(), new_linds.end(), lind_view.begin()+rowinfo.numEntries);
1077 else if (I == GlobalIndices) {
1078 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Tpetra::CrsGraph::"
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.");
1086 numRowEntries_[rowinfo.localRow] += numNewInds;
1087 nodeNumEntries_ += numNewInds;
1088 setLocallyModified ();
1094 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1097 const ArrayView<const GlobalOrdinal> &indices)
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) {
1105 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1107 ": new indices exceed statically allocated graph structure.");
1110 size_t newAllocSize = 2*rowInfo.allocSize;
1111 if (newAllocSize < newNumEntries)
1112 newAllocSize = newNumEntries;
1113 gblInds2D_[myRow].resize(newAllocSize);
1114 nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
1118 if (gblInds1D_ != null)
1119 std::copy(indices.begin(), indices.end(),
1120 gblInds1D_.begin()+rowInfo.offset1D+rowInfo.numEntries);
1122 std::copy(indices.begin(), indices.end(),
1123 gblInds2D_[myRow].begin()+rowInfo.numEntries);
1124 numRowEntries_[myRow] += numNewInds;
1125 nodeNumEntries_ += numNewInds;
1126 setLocallyModified ();
1128 #ifdef HAVE_TPETRA_DEBUG
1130 const size_t chkNewNumEntries = getNumEntriesInLocalRow (myRow);
1131 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1132 chkNewNumEntries != newNumEntries, std::logic_error,
1133 ": Internal logic error. Please contact Tpetra team.");
1140 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1141 void CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::
1142 insertLocalIndicesImpl (
const LocalOrdinal myRow,
1143 const ArrayView<const LocalOrdinal> &indices)
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) {
1151 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1153 ": new indices exceed statically allocated graph structure.");
1156 size_t newAllocSize = 2*rowInfo.allocSize;
1157 if (newAllocSize < newNumEntries)
1158 newAllocSize = newNumEntries;
1159 lclInds2D_[myRow].resize(newAllocSize);
1160 nodeNumAllocated_ += (newAllocSize - rowInfo.allocSize);
1164 if (lclInds1D_ != null)
1165 std::copy(indices.begin(), indices.end(),
1166 lclInds1D_.begin()+rowInfo.offset1D+rowInfo.numEntries);
1168 std::copy(indices.begin(), indices.end(),
1169 lclInds2D_[myRow].begin()+rowInfo.numEntries);
1170 numRowEntries_[myRow] += numNewInds;
1171 nodeNumEntries_ += numNewInds;
1172 setLocallyModified ();
1173 #ifdef HAVE_TPETRA_DEBUG
1175 const size_t chkNewNumEntries = getNumEntriesInLocalRow (myRow);
1176 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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,
1190 const ArrayView<Scalar>& oldRowVals,
1191 const ArrayView<const Scalar>& newRowVals,
1192 const ELocalGlobal lg,
1193 const ELocalGlobal I)
1195 const size_t numNewInds = insertIndices (rowInfo, newInds, lg, I);
1196 typename ArrayView<const Scalar>::const_iterator newRowValsBegin =
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>
1209 const Teuchos::ArrayView<Scalar>& rowVals,
1210 const Teuchos::ArrayView<const LocalOrdinal>& inds,
1211 const Teuchos::ArrayView<const Scalar>& newVals,
1212 BinaryFunction f)
const
1214 const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid();
1215 const size_t numElts = Teuchos::as<size_t> (inds.size ());
1220 ArrayView<const LocalOrdinal> colInds = getLocalView (rowInfo);
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>
1239 const Teuchos::ArrayView<Scalar>& rowVals,
1240 const Teuchos::ArrayView<const GlobalOrdinal>& inds,
1241 const Teuchos::ArrayView<const Scalar>& newVals,
1242 BinaryFunction f)
const
1244 const size_t STINV = Teuchos::OrdinalTraits<size_t>::invalid();
1245 const size_t numElts = Teuchos::as<size_t> (inds.size ());
1248 for (
size_t j = 0; j < numElts; ++j) {
1249 const size_t k = findGlobalIndex (rowInfo, inds[j], hint);
1251 rowVals[k] = f( rowVals[k], newVals[j] );
1261 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1264 if (rowinfo.numEntries > 0) {
1265 ArrayView<LocalOrdinal> inds_view = getLocalViewNonConst(rowinfo);
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) {
1279 ArrayView<LocalOrdinal> inds_view = getLocalViewNonConst(rowinfo);
1280 sort2(inds_view.begin(), inds_view.begin()+rowinfo.numEntries, values.begin());
1287 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1290 const char tfecfFuncName[] =
"mergRowIndices()";
1291 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1292 isStorageOptimized() ==
true, std::logic_error,
1293 ": The graph is already storage optimized, so we shouldn't be merging any indices."
1294 " Please report this bug to the Tpetra developers.");
1295 ArrayView<LocalOrdinal> inds_view = getLocalViewNonConst(rowinfo);
1296 typename ArrayView<LocalOrdinal>::iterator beg, end, newend;
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
1303 TEUCHOS_TEST_FOR_EXCEPT( isStorageOptimized() && mergedEntries != rowinfo.numEntries );
1305 numRowEntries_[rowinfo.localRow] = mergedEntries;
1306 nodeNumEntries_ -= (rowinfo.numEntries - mergedEntries);
1313 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1314 template<
class Scalar>
1318 const char tfecfFuncName[] =
"mergeRowIndicesAndValues";
1319 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1320 isStorageOptimized(), std::logic_error,
": It is invalid to call this "
1321 "method if the graph's storage has already been optimized." << std::endl
1322 <<
"Please report this bug to the Tpetra developers.");
1324 typedef typename ArrayView<Scalar>::iterator Iter;
1325 Iter rowValueIter = rowValues.begin ();
1326 ArrayView<LocalOrdinal> inds_view = getLocalViewNonConst (rowinfo);
1327 typename ArrayView<LocalOrdinal>::iterator beg, end, newend;
1330 beg = inds_view.begin();
1331 end = inds_view.begin() + rowinfo.numEntries;
1334 typename ArrayView<LocalOrdinal>::iterator cur = beg + 1;
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
1360 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1361 isStorageOptimized() && mergedEntries != rowinfo.numEntries,
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
1366 numRowEntries_[rowinfo.localRow] = mergedEntries;
1367 nodeNumEntries_ -= (rowinfo.numEntries - mergedEntries);
1373 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1379 if (domainMap_ != domainMap) {
1380 domainMap_ = domainMap;
1383 if (rangeMap_ != rangeMap) {
1384 rangeMap_ = rangeMap;
1392 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1397 ArrayView<const LocalOrdinal> colInds = getLocalView (rowinfo);
1398 return this->findLocalIndex (rowinfo, ind, colInds, hint);
1404 template <
class LocalOrdinal,
1405 class GlobalOrdinal,
1412 ArrayView<const LocalOrdinal> colInds,
1415 typedef typename ArrayView<const LocalOrdinal>::iterator IT;
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);
1453 return Teuchos::OrdinalTraits<size_t>::invalid ();
1460 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1465 typedef typename ArrayView<const GlobalOrdinal>::iterator IT;
1466 ArrayView<const GlobalOrdinal> indices = getGlobalView (rowinfo);
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) {
1479 return Teuchos::OrdinalTraits<size_t>::invalid ();
1481 return p.first - beg;
1485 const IT loc = std::find (beg, end, ind);
1487 return Teuchos::OrdinalTraits<size_t>::invalid ();
1497 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1500 globalNumEntries_ = OrdinalTraits<global_size_t>::invalid();
1501 globalNumDiags_ = OrdinalTraits<global_size_t>::invalid();
1502 globalMaxNumRowEntries_ = OrdinalTraits<global_size_t>::invalid();
1503 haveGlobalConstants_ =
false;
1509 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1510 void CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::checkInternalState()
const
1512 #ifdef HAVE_TPETRA_DEBUG
1513 const global_size_t GSTI = OrdinalTraits<global_size_t>::invalid();
1514 const size_t STI = OrdinalTraits<size_t>::invalid();
1515 std::string err = typeName(*
this) +
"::checkInternalState(): Likely internal logic error. Please contact Tpetra team.";
1520 TEUCHOS_TEST_FOR_EXCEPTION( rowMap_ == null, std::logic_error, err );
1522 TEUCHOS_TEST_FOR_EXCEPTION( isFillActive() == isFillComplete(), std::logic_error, err );
1524 TEUCHOS_TEST_FOR_EXCEPTION( isFillActive() && lclGraph_ != null, std::logic_error, err );
1526 TEUCHOS_TEST_FOR_EXCEPTION( isFillComplete() ==
true && (colMap_ == null || rangeMap_ == null || domainMap_ == null), std::logic_error, err );
1528 TEUCHOS_TEST_FOR_EXCEPTION( isStorageOptimized() ==
true && indicesAreAllocated() ==
false, std::logic_error, err );
1530 TEUCHOS_TEST_FOR_EXCEPTION( isStorageOptimized() ==
true && getNodeAllocationSize() != getNodeNumEntries(), std::logic_error, err );
1532 TEUCHOS_TEST_FOR_EXCEPTION( haveGlobalConstants_ ==
false && ( globalNumEntries_ != GSTI || globalNumDiags_ != GSTI || globalMaxNumRowEntries_ != GSTI ), std::logic_error, err );
1534 TEUCHOS_TEST_FOR_EXCEPTION( haveGlobalConstants_ ==
true && ( globalNumEntries_ == GSTI || globalNumDiags_ == GSTI || globalMaxNumRowEntries_ == GSTI ), std::logic_error, err );
1535 TEUCHOS_TEST_FOR_EXCEPTION( haveGlobalConstants_ ==
true && ( globalNumEntries_ < nodeNumEntries_ || globalNumDiags_ < nodeNumDiags_ || globalMaxNumRowEntries_ < nodeMaxNumRowEntries_ ),
1536 std::logic_error, err );
1538 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreAllocated() ==
true && (numAllocForAllRows_ != 0 || numAllocPerRow_ != null), std::logic_error, err );
1540 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreAllocated() ==
false && (nodeNumAllocated_ != STI || nodeNumEntries_ != 0), std::logic_error, err );
1542 TEUCHOS_TEST_FOR_EXCEPTION( isStorageOptimized() && pftype_ !=
StaticProfile, std::logic_error, err );
1544 TEUCHOS_TEST_FOR_EXCEPTION( isGloballyIndexed() && rowPtrs_ != null && ((
size_t)rowPtrs_.size() != getNodeNumRows()+1 || rowPtrs_[getNodeNumRows()] != (size_t)gblInds1D_.size()), std::logic_error, err );
1545 TEUCHOS_TEST_FOR_EXCEPTION( isLocallyIndexed() && rowPtrs_ != null && ((
size_t)rowPtrs_.size() != getNodeNumRows()+1 || rowPtrs_[getNodeNumRows()] != (size_t)lclInds1D_.size()), std::logic_error, err );
1547 TEUCHOS_TEST_FOR_EXCEPTION( pftype_ ==
DynamicProfile && indicesAreAllocated() && getNodeNumRows() > 0 && lclInds2D_ == null && gblInds2D_ == null,
1548 std::logic_error, err );
1550 TEUCHOS_TEST_FOR_EXCEPTION( pftype_ ==
DynamicProfile && indicesAreAllocated() && getNodeNumRows() > 0 && (numRowEntries_ == null || (lclInds2D_ == null && gblInds2D_ == null)),
1551 std::logic_error, err );
1553 TEUCHOS_TEST_FOR_EXCEPTION( pftype_ ==
DynamicProfile && (lclInds1D_ != null || gblInds1D_ != null), std::logic_error, err );
1555 TEUCHOS_TEST_FOR_EXCEPTION( pftype_ ==
DynamicProfile && rowPtrs_ != null, std::logic_error, err );
1557 TEUCHOS_TEST_FOR_EXCEPTION( pftype_ ==
StaticProfile && indicesAreAllocated() && getNodeAllocationSize() > 0 && lclInds1D_ == null && gblInds1D_ == null,
1558 std::logic_error, err );
1560 TEUCHOS_TEST_FOR_EXCEPTION( pftype_ ==
StaticProfile && (lclInds2D_ != null || gblInds2D_ != null), std::logic_error, err );
1562 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreAllocated() ==
false && (rowPtrs_ != null || numRowEntries_ != null ||
1563 lclInds1D_ != null || lclInds2D_ != null ||
1564 gblInds1D_ != null || gblInds2D_ != null), std::logic_error, err );
1566 TEUCHOS_TEST_FOR_EXCEPTION( (indicesAreLocal_ ==
true || indicesAreGlobal_ ==
true) && indicesAreAllocated_ ==
false, std::logic_error, err );
1568 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreLocal_ ==
true && indicesAreGlobal_ ==
true, std::logic_error, err );
1570 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreLocal_ ==
true && (gblInds1D_ != null || gblInds2D_ != null), std::logic_error, err );
1572 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreGlobal_ ==
true && (lclInds1D_ != null || lclInds2D_ != null), std::logic_error, err );
1574 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreLocal_ ==
true && getNodeAllocationSize() > 0 && lclInds1D_ == null && getNodeNumRows() > 0 && lclInds2D_ == null,
1575 std::logic_error, err );
1577 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreGlobal_ ==
true && getNodeAllocationSize() > 0 && gblInds1D_ == null && getNodeNumRows() > 0 && gblInds2D_ == null,
1578 std::logic_error, err );
1580 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreAllocated() ==
true && nodeNumAllocated_ == STI, std::logic_error, err );
1582 TEUCHOS_TEST_FOR_EXCEPTION( indicesAreAllocated() ==
false && nodeNumAllocated_ != STI, std::logic_error, err );
1584 if (indicesAreAllocated()) {
1585 size_t actualNumAllocated = 0;
1587 if (isGloballyIndexed() && gblInds2D_ != null) {
1588 for (
size_t r = 0; r < getNodeNumRows(); ++r) {
1589 actualNumAllocated += gblInds2D_[r].size();
1592 else if (isLocallyIndexed() && lclInds2D_ != null) {
1593 for (
size_t r = 0; r < getNodeNumRows(); ++r) {
1594 actualNumAllocated += lclInds2D_[r].size();
1597 TEUCHOS_TEST_FOR_EXCEPTION(actualNumAllocated != nodeNumAllocated_, std::logic_error, err );
1599 else if (rowPtrs_ != null) {
1600 actualNumAllocated = rowPtrs_[getNodeNumRows()];
1601 TEUCHOS_TEST_FOR_EXCEPTION( isLocallyIndexed() ==
true && (
size_t)lclInds1D_.size() != actualNumAllocated, std::logic_error, err );
1602 TEUCHOS_TEST_FOR_EXCEPTION( isGloballyIndexed() ==
true && (
size_t)gblInds1D_.size() != actualNumAllocated, std::logic_error, err );
1603 TEUCHOS_TEST_FOR_EXCEPTION(actualNumAllocated != nodeNumAllocated_, std::logic_error, err );
1621 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1624 const LocalOrdinal lrow = rowMap_->getLocalElement(globalRow);
1625 size_t ret = OrdinalTraits<size_t>::invalid();
1626 if (hasRowInfo() && lrow != OrdinalTraits<LocalOrdinal>::invalid())
1628 RowInfo rowinfo = getRowInfo(lrow);
1629 ret = rowinfo.numEntries;
1637 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1640 size_t ret = OrdinalTraits<size_t>::invalid();
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);
1655 size_t ret = OrdinalTraits<size_t>::invalid();
1656 if (hasRowInfo() && lrow != OrdinalTraits<LocalOrdinal>::invalid())
1658 RowInfo rowinfo = getRowInfo(lrow);
1659 ret = rowinfo.allocSize;
1667 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1670 size_t ret = OrdinalTraits<size_t>::invalid();
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,...)";
1708 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(isGloballyIndexed() ==
true && hasColMap() ==
false, std::runtime_error,
": local indices cannot be produced.");
1709 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(rowMap_->isNodeLocalElement(localRow) ==
false, std::runtime_error,
1710 ": localRow (== " << localRow <<
") is not valid on this node.");
1711 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(hasRowInfo() ==
false, std::runtime_error,
": graph row information was deleted at fillComplete().");
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 <<
").");
1717 if (isLocallyIndexed()) {
1718 ArrayView<const LocalOrdinal> lview = getLocalView(rowinfo);
1719 std::copy( lview.begin(), lview.begin() + NumIndices, indices.begin());
1721 else if (isGloballyIndexed()) {
1722 ArrayView<const GlobalOrdinal> gview = getGlobalView(rowinfo);
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,...)";
1746 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(lrow == OrdinalTraits<LocalOrdinal>::invalid(), std::runtime_error,
1747 ": globalRow (== " << globalRow <<
") does not belong to this node.");
1748 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(hasRowInfo() ==
false, std::runtime_error,
": graph row information was deleted at fillComplete().");
1749 const RowInfo rowinfo = getRowInfo((
size_t)lrow);
1750 NumIndices = rowinfo.numEntries;
1751 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC((
size_t)indices.size() < NumIndices, std::runtime_error,
1752 ": specified storage (size==" << indices.size()
1753 <<
") is not large enough to hold all entries for this row (NumIndices == " << NumIndices <<
").");
1754 if (isLocallyIndexed()) {
1755 ArrayView<const LocalOrdinal> lview = getLocalView(rowinfo);
1756 for (
size_t j=0; j < NumIndices; ++j) {
1757 indices[j] = colMap_->getGlobalElement(lview[j]);
1760 else if (isGloballyIndexed()) {
1761 ArrayView<const GlobalOrdinal> gview = getGlobalView(rowinfo);
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()";
1774 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(isGloballyIndexed() ==
true, std::runtime_error,
": local indices cannot be provided.");
1775 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(hasRowInfo() ==
false, std::runtime_error,
": graph row information was deleted at fillComplete().");
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
1785 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( (
size_t)indices.size() != getNumEntriesInLocalRow(localRow), std::logic_error,
": Violated stated post-conditions. Please contact Tpetra team.");
1793 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1797 const char tfecfFuncName[] =
"getGlobalRowView()";
1798 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1799 isLocallyIndexed() ==
true, std::runtime_error,
1800 ": The graph is locally indexed, so we cannot return a view with global "
1801 "column indices. Use getGlobalRowCopy() instead.");
1803 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1804 hasRowInfo() ==
false, std::runtime_error,
1805 ": graph row information was deleted at fillComplete().");
1809 const LocalOrdinal localRow = rowMap_->getLocalElement (globalRow);
1811 if (localRow != Teuchos::OrdinalTraits<LocalOrdinal>::invalid ()) {
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
1819 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1820 as<size_t> (indices.size ()) != getNumEntriesInGlobalRow (globalRow),
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
1826 <<
") = " << getNumEntriesInGlobalRow (globalRow) << endl
1827 <<
"Please report this bug to the Tpetra developers.");
1828 #endif // HAVE_TPETRA_DEBUG
1834 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1838 const ArrayView<const LocalOrdinal> &indices)
1840 using Teuchos::ArrayView;
1841 typedef LocalOrdinal LO;
1842 const char tfecfFuncName[] =
"insertLocalIndices";
1844 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1845 isFillActive() ==
false, std::runtime_error,
1846 ": requires that fill is active.");
1847 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1848 isGloballyIndexed() ==
true, std::runtime_error,
1849 ": graph indices are global; use insertGlobalIndices().");
1850 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1851 hasColMap() ==
false, std::runtime_error,
1852 ": cannot insert local indices without a column map.");
1853 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1854 rowMap_->isNodeLocalElement(localRow) ==
false, std::runtime_error,
1855 ": row does not belong to this node.");
1856 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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
1869 using Teuchos::Array;
1870 using Teuchos::toString;
1872 typedef typename ArrayView<const LO>::size_type size_type;
1874 const map_type& colMap = * (getColMap ());
1875 Array<LO> badColInds;
1876 bool allInColMap =
true;
1877 for (size_type k = 0; k < indices.size (); ++k) {
1879 allInColMap =
false;
1880 badColInds.push_back (indices[k]);
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.";
1892 TEUCHOS_TEST_FOR_EXCEPTION(! allInColMap, std::invalid_argument, os.str ());
1895 #endif // HAVE_TPETRA_DEBUG
1897 insertLocalIndicesImpl (localRow, indices);
1899 #ifdef HAVE_TPETRA_DEBUG
1900 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1901 indicesAreAllocated() ==
false || isLocallyIndexed() ==
false,
1903 ": Violated stated post-conditions. Please contact Tpetra team.");
1910 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1914 const ArrayView<const LocalOrdinal> &indices)
1916 typedef LocalOrdinal LO;
1917 const char tfecfFuncName[] =
"insertLocalIndicesFiltered";
1919 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1920 isFillActive() ==
false, std::runtime_error,
1921 ": requires that fill is active.");
1922 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1923 isGloballyIndexed() ==
true, std::runtime_error,
1924 ": graph indices are global; use insertGlobalIndices().");
1925 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1926 hasColMap() ==
false, std::runtime_error,
1927 ": cannot insert local indices without a column map.");
1928 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1929 rowMap_->isNodeLocalElement(localRow) ==
false, std::runtime_error,
1930 ": row does not belong to this node.");
1931 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1932 hasRowInfo() ==
false, std::runtime_error,
1933 ": graph row information was deleted at fillComplete().");
1934 if (indicesAreAllocated() ==
false) {
1935 allocateIndices(LocalIndices);
1940 Array<LO> filtered_indices(indices);
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(
1954 indicesAreAllocated() ==
false || isLocallyIndexed() ==
false,
1956 ": Violated stated post-conditions. Please contact Tpetra team.");
1963 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
1967 const ArrayView<const GlobalOrdinal> &indices)
1969 typedef LocalOrdinal LO;
1970 typedef GlobalOrdinal GO;
1971 typedef typename ArrayView<const GO>::size_type size_type;
1972 const char tfecfFuncName[] =
"insertGlobalIndices";
1974 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1975 isLocallyIndexed() ==
true, std::runtime_error,
1976 ": graph indices are local; use insertLocalIndices().");
1977 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1978 hasRowInfo() ==
false, std::runtime_error,
1979 ": graph row information was deleted at fillComplete().");
1984 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
1985 isFillActive() ==
false, std::runtime_error,
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);
1993 if (myRow != Teuchos::OrdinalTraits<LO>::invalid ()) {
1994 #ifdef HAVE_TPETRA_DEBUG
1997 const map_type& colMap = * (getColMap ());
2002 Array<GO> badColInds;
2003 bool allInColMap =
true;
2004 for (size_type k = 0; k < indices.size (); ++k) {
2006 allInColMap =
false;
2007 badColInds.push_back (indices[k]);
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.";
2019 TEUCHOS_TEST_FOR_EXCEPTION(! allInColMap, std::invalid_argument, os.str ());
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
2036 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2037 indicesAreAllocated() ==
false || isGloballyIndexed() ==
false,
2039 ": Violated stated post-conditions. Please contact Tpetra team.");
2046 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2050 const ArrayView<const GlobalOrdinal> &indices)
2052 typedef LocalOrdinal LO;
2053 typedef GlobalOrdinal GO;
2054 const char tfecfFuncName[] =
"insertGlobalIndicesFiltered";
2056 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2057 isLocallyIndexed() ==
true, std::runtime_error,
2058 ": graph indices are local; use insertLocalIndices().");
2059 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2060 hasRowInfo() ==
false, std::runtime_error,
2061 ": graph row information was deleted at fillComplete().");
2066 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2067 isFillActive() ==
false, std::runtime_error,
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);
2075 if (myRow != Teuchos::OrdinalTraits<LO>::invalid ()) {
2078 Array<GO> filtered_indices(indices);
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);
2092 typedef typename ArrayView<const GO>::size_type size_type;
2093 const size_type numIndices = indices.size ();
2094 for (size_type k = 0; k < numIndices; ++k) {
2095 nonlocals_[grow].push_back (indices[k]);
2098 #ifdef HAVE_TPETRA_DEBUG
2099 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2100 indicesAreAllocated() ==
false || isGloballyIndexed() ==
false,
2102 ": Violated stated post-conditions. Please contact Tpetra team.");
2108 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2111 const char tfecfFuncName[] =
"removeLocalIndices()";
2112 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( isFillActive() ==
false, std::runtime_error,
": requires that fill is active.");
2113 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( isStorageOptimized() ==
true, std::runtime_error,
": cannot remove indices after optimizeStorage() has been called.");
2114 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( isGloballyIndexed() ==
true, std::runtime_error,
": graph indices are global.");
2115 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( rowMap_->isNodeLocalElement(lrow) ==
false, std::runtime_error,
": row does not belong to this node.");
2116 if (indicesAreAllocated() ==
false) {
2117 allocateIndices(LocalIndices);
2120 clearGlobalConstants();
2122 if (numRowEntries_ != null) {
2123 nodeNumEntries_ -= numRowEntries_[lrow];
2124 numRowEntries_[lrow] = 0;
2126 #ifdef HAVE_TPETRA_DEBUG
2127 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(getNumEntriesInLocalRow(lrow) != 0 || indicesAreAllocated() ==
false || isLocallyIndexed() ==
false, std::logic_error,
2128 ": Violated stated post-conditions. Please contact Tpetra team.");
2134 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2137 const char tfecfFuncName[] =
"setAllIndices()";
2138 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( hasColMap() ==
false, std::runtime_error,
": requires a ColMap.");
2139 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( (
size_t)rowPointers.size() != getNodeNumRows()+1, std::runtime_error,
": requires rowPointers.size() == getNodeNumRows()+1");
2140 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( lclInds1D_ != Teuchos::null || gblInds1D_ != Teuchos::null, std::runtime_error,
": cannot have 1D data structures allocated.");
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;
2146 lclInds1D_ = columnIndices;
2147 rowPtrs_ = rowPointers;
2148 nodeNumEntries_ = nodeNumAllocated_ = rowPtrs_[getNodeNumRows()];
2149 checkInternalState();
2155 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2158 using Teuchos::Array;
2160 using Teuchos::Comm;
2161 using Teuchos::gatherAll;
2162 using Teuchos::ireceive;
2163 using Teuchos::isend;
2164 using Teuchos::outArg;
2165 using Teuchos::REDUCE_MAX;
2166 using Teuchos::reduceAll;
2167 using Teuchos::toString;
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;
2175 typedef typename Array<GO>::size_type size_type;
2177 const char tfecfFuncName[] =
"globalAssemble";
2178 RCP<const Comm<int> > comm = getComm();
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
2186 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( ! isFillActive(), std::runtime_error,
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) {
2203 Array<pair<int, GO> > IdsAndRows;
2204 std::map<GO, int> NLR2Id;
2205 Teuchos::SerialDenseMatrix<int, char> globalNeighbors;
2206 Array<int> sendIDs, recvIDs;
2211 std::set<GO> setOfRows;
2212 for (NLITER iter = nonlocals_.begin(); iter != nonlocals_.end(); ++iter) {
2213 setOfRows.insert(iter->first);
2216 NLRs.resize(setOfRows.size());
2217 std::copy(setOfRows.begin(), setOfRows.end(), NLRs.begin());
2220 Array<int> NLRIds(NLRs.size());
2222 LookupStatus stat = rowMap_->getRemoteIndexList(NLRs(),NLRIds());
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) {
2239 Array<GO> invalidNonlocalRows;
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;
2255 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2256 gblerror != 0, std::runtime_error,
2257 ": nonlocal entries correspond to invalid rows."
2258 << endl << os.str ());
2265 IdsAndRows.reserve(NLRs.size());
2266 Array<char> localNeighbors(numImages, 0);
2267 typename Array<GO>::const_iterator nlr;
2268 typename Array<int>::const_iterator id;
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]) {
2278 sendIDs.push_back(j);
2282 std::sort(IdsAndRows.begin(),IdsAndRows.end());
2284 globalNeighbors.shapeUninitialized(numImages,numImages);
2285 gatherAll (*getComm(), numImages, localNeighbors.getRawPtr(),
2286 numImages * numImages, globalNeighbors.values());
2298 for (
int j=0; j<numImages; ++j) {
2299 if (globalNeighbors(myImageID,j)) {
2300 recvIDs.push_back(j);
2303 const size_t numRecvs = recvIDs.size();
2308 Array<pair<GO, GO> > IJSendBuffer;
2309 Array<size_t> sendSizes(sendIDs.size(), 0);
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) {
2318 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(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) {
2331 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(as<
typename Array<int>::size_type>(numSends) != sendIDs.size(), std::logic_error,
": internal logic error. Contact Tpetra team.");
2343 Array<RCP<Teuchos::CommRequest<int> > > requests;
2346 for (
size_t s = 0; s < numSends ; ++s) {
2349 requests.push_back (isend<int, size_t> (*comm,
2350 rcp (&sendSizes[s],
false),
2354 Array<size_t> recvSizes (numRecvs);
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
2369 requests.resize (0);
2375 Array<ArrayView<pair<GO,GO> > > sendBuffers(numSends,null);
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)
2388 ArrayRCP<pair<GO,GO> > tmpSendBuf =
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);
2395 Array<pair<GO,GO> > IJRecvBuffer (totalRecvSize);
2397 Array<ArrayView<pair<GO,GO> > > recvBuffers (numRecvs, null);
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) {
2409 ArrayRCP<pair<GO,GO> > tmpRecvBuf =
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)
2432 insertGlobalIndicesFiltered (ij->first, tuple<GO> (ij->second));
2434 checkInternalState();
2440 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2445 const char tfecfFuncName[] =
"resumeFill";
2446 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(! hasRowInfo(), std::runtime_error,
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();
2455 if (params != null) this->setParameterList (params);
2456 lowerTriangular_ =
false;
2457 upperTriangular_ =
false;
2459 indicesAreSorted_ =
true;
2460 noRedundancies_ =
true;
2461 fillComplete_ =
false;
2462 #ifdef HAVE_TPETRA_DEBUG
2463 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2464 ! isFillActive() || isFillComplete(), std::logic_error,
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>
2477 fillComplete(rowMap_,rowMap_,params);
2483 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2488 const RCP<ParameterList> ¶ms)
2490 #ifdef HAVE_TPETRA_DEBUG
2491 rowMap_->getComm ()->barrier ();
2492 #endif // HAVE_TPETRA_DEBUG
2493 const char tfecfFuncName[] =
"fillComplete()";
2494 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( ! isFillActive() || isFillComplete(),
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;
2509 if (! params.is_null ()) {
2510 assertNoNonlocalInserts =
2511 params->get<
bool> (
"No Nonlocal Changes", assertNoNonlocalInserts);
2515 const bool mayNeedGlobalAssemble = ! assertNoNonlocalInserts && numProcs > 1;
2516 if (mayNeedGlobalAssemble) {
2522 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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.");
2529 setDomainRangeMaps(domainMap,rangeMap);
2531 if (! hasColMap()) {
2534 if (isGloballyIndexed()) {
2544 computeGlobalConstants();
2546 fillLocalGraph(params);
2548 fillComplete_ =
true;
2549 #ifdef HAVE_TPETRA_DEBUG
2550 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( isFillActive() ==
true || isFillComplete() ==
false, std::logic_error,
": Violated stated post-conditions. Please contact Tpetra team.");
2553 checkInternalState();
2559 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2564 const RCP<ParameterList> ¶ms)
2566 #ifdef HAVE_TPETRA_DEBUG
2567 rowMap_->getComm ()->barrier ();
2568 #endif // HAVE_TPETRA_DEBUG
2569 const char tfecfFuncName[] =
"expertStaticFillComplete()";
2570 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( isFillComplete() ==
true || hasColMap() ==
false,
2571 std::runtime_error,
": fillComplete cannot have already been called and a ColMap is required.");
2573 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( getNodeNumRows() > 0 && rowPtrs_==Teuchos::null,
2574 std::runtime_error,
": a matrix will getNodeNumRows()>0 requires rowptr to be set.");
2576 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( domainMap == Teuchos::null || rangeMap == Teuchos::null,
2577 std::runtime_error,
": requires a non-null domainMap & rangeMap.");
2579 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( pftype_ !=
StaticProfile,
2580 std::runtime_error,
": requires StaticProfile.");
2586 nodeNumEntries_ = nodeNumAllocated_ = rowPtrs_[getNodeNumRows()];
2589 numAllocForAllRows_ = 0;
2590 numAllocPerRow_ = null;
2591 indicesAreAllocated_ =
true;
2594 indicesAreLocal_ =
true;
2595 indicesAreGlobal_ =
false;
2598 setDomainRangeMaps(domainMap,rangeMap);
2601 indicesAreSorted_ =
true;
2602 noRedundancies_ =
true;
2605 importer_=Teuchos::null;
2606 exporter_=Teuchos::null;
2607 if(importer != Teuchos::null) {
2608 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!importer->getSourceMap()->isSameAs(*getDomainMap()) || !importer->getTargetMap()->isSameAs(*getColMap()),
2609 std::invalid_argument,
": importer does not match matrix maps.");
2610 importer_ = importer;
2613 if(exporter != Teuchos::null) {
2614 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(!exporter->getSourceMap()->isSameAs(*getRowMap()) || !exporter->getTargetMap()->isSameAs(*getRangeMap()),
2615 std::invalid_argument,
": exporter does not match matrix maps.");
2616 exporter_ = exporter;
2621 computeGlobalConstants();
2624 fillLocalGraph(params);
2625 fillComplete_ =
true;
2627 #ifdef HAVE_TPETRA_DEBUG
2628 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC( isFillActive() ==
true || isFillComplete() ==
false, std::logic_error,
": Violated stated post-conditions. Please contact Tpetra team.");
2630 checkInternalState();
2637 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2640 const size_t numRows = getNodeNumRows();
2641 ArrayRCP<size_t> ptrs;
2642 ArrayRCP<LocalOrdinal> inds;
2643 bool requestOptimizedStorage =
true;
2644 if (params != null && params->get(
"Optimize Storage",
true) ==
false) requestOptimizedStorage =
false;
2647 ptrs = LocalMatOps::allocRowPtrs( getRowMap()->getNode(), numRowEntries_() );
2648 inds = LocalMatOps::template allocStorage<LocalOrdinal>( getRowMap()->getNode(), ptrs() );
2649 for (
size_t row=0; row < numRows; ++row) {
2650 const size_t numentrs = numRowEntries_[row];
2651 std::copy( lclInds2D_[row].begin(), lclInds2D_[row].begin()+numentrs, inds+ptrs[row] );
2656 if (nodeNumEntries_ != nodeNumAllocated_) {
2657 ptrs = LocalMatOps::allocRowPtrs( getRowMap()->getNode(), numRowEntries_() );
2658 inds = LocalMatOps::template allocStorage<LocalOrdinal>( getRowMap()->getNode(), ptrs() );
2659 for (
size_t row=0; row < numRows; ++row) {
2660 const size_t numentrs = numRowEntries_[row];
2661 std::copy( lclInds1D_+rowPtrs_[row], lclInds1D_+rowPtrs_[row]+numentrs, inds+ptrs[row] );
2670 if ( requestOptimizedStorage ) {
2672 numRowEntries_ = null;
2676 nodeNumAllocated_ = nodeNumEntries_;
2680 RCP<ParameterList> lclparams;
2681 if (params == null) lclparams = parameterList();
2682 else lclparams = sublist(params,
"Local Graph");
2683 lclGraph_ = rcp(
new local_graph_type( getRowMap()->getNodeNumElements(), getColMap()->getNodeNumElements(), getRowMap()->getNode(), lclparams ) );
2684 lclGraph_->setStructure(ptrs,inds);
2688 Teuchos::EDiag diag = ( getNodeNumDiags() < getNodeNumRows() ? Teuchos::UNIT_DIAG : Teuchos::NON_UNIT_DIAG );
2689 Teuchos::EUplo uplo = Teuchos::UNDEF_TRI;
2690 if (isUpperTriangular()) uplo = Teuchos::UPPER_TRI;
2691 else if (isLowerTriangular()) uplo = Teuchos::LOWER_TRI;
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()))) {
2705 domainMap_ = newDomainMap;
2710 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
false, std::runtime_error,
" requires matching maps and non-static graph.");
2717 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2718 const RCP<const typename LocalMatOps::template graph<LocalOrdinal,Node>::graph_type>
2727 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2728 const RCP<typename LocalMatOps::template graph<LocalOrdinal,Node>::graph_type>
2729 CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::getLocalGraphNonConst()
2737 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2738 void CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::computeGlobalConstants()
2741 using Teuchos::outArg;
2742 using Teuchos::reduceAll;
2743 typedef LocalOrdinal LO;
2744 typedef GlobalOrdinal GO;
2747 #ifdef HAVE_TPETRA_DEBUG
2748 TEUCHOS_TEST_FOR_EXCEPTION(! hasColMap(), std::logic_error,
"Tpetra::"
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
2756 if (! haveLocalConstants_) {
2768 upperTriangular_ =
true;
2769 lowerTriangular_ =
true;
2770 nodeMaxNumRowEntries_ = 0;
2774 const Map<LO,GO,Node>& rowMap = *rowMap_;
2775 const Map<LO,GO,Node>& colMap = *colMap_;
2787 if (indicesAreAllocated () && nodeNumAllocated_ > 0) {
2788 const size_t numLocalRows = getNodeNumRows ();
2789 for (
size_t localRow = 0; localRow < numLocalRows; ++localRow) {
2790 const GO globalRow = rowMap.getGlobalElement (localRow);
2792 const LO rlcid = colMap.getLocalElement (globalRow);
2793 RowInfo rowInfo = getRowInfo (localRow);
2794 ArrayView<const LO> rview = getLocalView (rowInfo);
2795 typename ArrayView<const LO>::iterator beg, end, cur;
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) {
2812 upperTriangular_ =
false;
2814 if (localRow < largestCol) {
2815 lowerTriangular_ =
false;
2819 nodeMaxNumRowEntries_ = std::max (nodeMaxNumRowEntries_, rowInfo.numEntries);
2822 haveLocalConstants_ =
true;
2828 if (haveGlobalConstants_ ==
false) {
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_));
2851 haveGlobalConstants_ =
true;
2858 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
2859 void CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::makeIndicesLocal()
2861 typedef LocalOrdinal LO;
2862 typedef GlobalOrdinal GO;
2866 computeIndexState();
2867 const char tfecfFuncName[] =
"makeIndicesLocal()";
2868 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2869 isLocallyIndexed() && isGloballyIndexed(), std::logic_error,
2870 ": inconsistent index state. Indices must be either local on all "
2871 "processes, or global on all processes.");
2876 const size_t nlrs = getNodeNumRows();
2877 if (isGloballyIndexed() && nlrs > 0) {
2883 if (nodeNumAllocated_ &&
sizeof (LO) ==
sizeof (GO)) {
2884 lclInds1D_ = arcp_reinterpret_cast<LO> (gblInds1D_).persistingView (0, nodeNumAllocated_);
2887 lclInds1D_ = LocalMatOps::template allocStorage<LO> (getRowMap ()->getNode (), rowPtrs_ ());
2889 for (
size_t r = 0; r < getNodeNumRows (); ++r) {
2890 const size_t offset = rowPtrs_[r];
2891 const size_t numentry = numRowEntries_[r];
2892 for (
size_t j = 0; j < numentry; ++j) {
2893 const GO gid = gblInds1D_[offset + j];
2894 const LO lid = colMap_->getLocalElement (gid);
2895 lclInds1D_[offset + j] = lid;
2896 #ifdef HAVE_TPETRA_DEBUG
2897 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2898 lclInds1D_[offset + j] == Teuchos::OrdinalTraits<LO>::invalid(),
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
2912 lclInds2D_ = arcp<Array<LO> > (nlrs);
2913 for (
size_t r = 0; r < getNodeNumRows (); ++r) {
2914 if (! gblInds2D_[r].empty ()) {
2915 const GO*
const ginds = gblInds2D_[r].getRawPtr ();
2916 const size_t rna = gblInds2D_[r].size ();
2917 const size_t numentry = numRowEntries_[r];
2918 lclInds2D_[r].resize (rna);
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
2925 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
2926 linds[j] == Teuchos::OrdinalTraits<LO>::invalid(),
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>
3041 TEUCHOS_TEST_FOR_EXCEPT(isGloballyIndexed()==
true);
3042 if (isSorted() ==
false) {
3043 for (
size_t row=0; row < getNodeNumRows(); ++row) {
3044 RowInfo rowInfo = getRowInfo(row);
3045 sortRowIndices(rowInfo);
3049 indicesAreSorted_ =
true;
3055 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3059 using Teuchos::REDUCE_MAX;
3060 using Teuchos::reduceAll;
3061 typedef LocalOrdinal LO;
3062 typedef GlobalOrdinal GO;
3063 const char tfecfFuncName[] =
"makeColMap";
3071 computeIndexState ();
3072 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
3073 isLocallyIndexed (), std::runtime_error,
3074 ": The graph is locally indexed. Calling makeColMap() to make the "
3075 "column Map requires that the graph be globally indexed.");
3080 Array<GO> myColumns;
3086 if (isGloballyIndexed ()) {
3110 const LO LINV = Teuchos::OrdinalTraits<LO>::invalid ();
3111 size_t numLocalColGIDs = 0, numRemoteColGIDs = 0;
3115 Array<char> GIDisLocal (domainMap_->getNodeNumElements (), 0);
3116 std::set<GO> RemoteGIDSet;
3117 const size_t myNumRows = getNodeNumRows ();
3118 for (
size_t r = 0; r < myNumRows; ++r) {
3119 RowInfo rowinfo = getRowInfo (r);
3120 if (rowinfo.numEntries > 0) {
3124 ArrayView<const GO> rowGids = getGlobalView (rowinfo);
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) {
3177 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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()) {
3187 colMap_ = domainMap_;
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));
3223 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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());
3252 ArrayView<const GO> domainElts = domainMap_->getNodeElementList ();
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];
3269 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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.");
3318 Teuchos::OrdinalTraits<global_size_t>::invalid ();
3319 const GO indexBase = domainMap_->getIndexBase ();
3320 colMap_ = rcp (
new map_type (gstInv, myColumns, indexBase,
3321 domainMap_->getComm (),
3322 domainMap_->getNode ()));
3323 checkInternalState ();
3328 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3331 TEUCHOS_TEST_FOR_EXCEPT( isGloballyIndexed() );
3332 TEUCHOS_TEST_FOR_EXCEPT( ! isSorted() );
3333 if (! isMerged ()) {
3334 for (
size_t row=0; row < getNodeNumRows(); ++row) {
3335 RowInfo rowInfo = getRowInfo(row);
3336 mergeRowIndices(rowInfo);
3339 noRedundancies_ =
true;
3344 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3351 TEUCHOS_TEST_FOR_EXCEPTION(! hasColMap (), std::logic_error,
"Tpetra::"
3352 "CrsGraph: It's not allowed to call makeImportExport() unless the graph "
3353 "has a column Map.");
3354 RCP<ParameterList> params = this->getNonconstParameterList ();
3363 if (importer_.is_null ()) {
3365 if (domainMap_ != colMap_ && (! domainMap_->isSameAs (*colMap_))) {
3366 if (params.is_null () || ! params->isSublist (
"Import")) {
3367 importer_ = rcp (
new import_type (domainMap_, colMap_));
3369 RCP<ParameterList> importSublist = sublist (params,
"Import",
true);
3370 importer_ = rcp (
new import_type (domainMap_, colMap_, importSublist));
3377 if (exporter_.is_null ()) {
3379 if (rangeMap_ != rowMap_ && ! rangeMap_->isSameAs (*rowMap_)) {
3380 if (params.is_null () || ! params->isSublist (
"Export")) {
3381 exporter_ = rcp (
new export_type (rowMap_, rangeMap_));
3384 RCP<ParameterList> exportSublist = sublist (params,
"Export",
true);
3385 exporter_ = rcp (
new export_type (rowMap_, rangeMap_, exportSublist));
3392 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3396 std::ostringstream oss;
3397 oss << DistObject<GlobalOrdinal,LocalOrdinal,GlobalOrdinal,Node>::description();
3398 if (isFillComplete()) {
3399 oss <<
"{status = fill complete"
3400 <<
", global rows = " << getGlobalNumRows()
3401 <<
", global cols = " << getGlobalNumCols()
3402 <<
", global num entries = " << getGlobalNumEntries()
3406 oss <<
"{status = fill not complete"
3407 <<
", global rows = " << getGlobalNumRows()
3414 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3418 const Teuchos::EVerbosityLevel verbLevel)
const
3420 const char tfecfFuncName[] =
"describe()";
3423 using Teuchos::VERB_DEFAULT;
3424 using Teuchos::VERB_NONE;
3425 using Teuchos::VERB_LOW;
3426 using Teuchos::VERB_MEDIUM;
3427 using Teuchos::VERB_HIGH;
3428 using Teuchos::VERB_EXTREME;
3429 Teuchos::EVerbosityLevel vl = verbLevel;
3430 if (vl == VERB_DEFAULT) vl = VERB_LOW;
3431 RCP<const Comm<int> > comm = this->getComm();
3432 const int myImageID = comm->getRank(),
3433 numImages = comm->getSize();
3435 for (
size_t dec=10; dec<getGlobalNumRows(); dec *= 10) {
3438 width = std::max<size_t>(width,Teuchos::as<size_t>(11)) + 2;
3439 Teuchos::OSTab tab(out);
3447 if (vl != VERB_NONE) {
3448 if (myImageID == 0) out << this->description() << std::endl;
3450 if (isFillComplete() && myImageID == 0) {
3451 out <<
"Global number of diagonals = " << globalNumDiags_ << std::endl;
3452 out <<
"Global max number of row entries = " << globalMaxNumRowEntries_ << std::endl;
3455 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
3456 if (myImageID == 0) out <<
"\nRow map: " << std::endl;
3457 rowMap_->describe(out,vl);
3458 if (colMap_ != null) {
3459 if (myImageID == 0) out <<
"\nColumn map: " << std::endl;
3460 colMap_->describe(out,vl);
3462 if (domainMap_ != null) {
3463 if (myImageID == 0) out <<
"\nDomain map: " << std::endl;
3464 domainMap_->describe(out,vl);
3466 if (rangeMap_ != null) {
3467 if (myImageID == 0) out <<
"\nRange map: " << std::endl;
3468 rangeMap_->describe(out,vl);
3472 if (vl == VERB_MEDIUM || vl == VERB_HIGH || vl == VERB_EXTREME) {
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;
3492 if (vl == VERB_HIGH || vl == VERB_EXTREME) {
3493 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(hasRowInfo() ==
false, std::runtime_error,
": reduce verbosity level; graph row information was deleted at fillComplete().");
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";
3499 if (vl == VERB_EXTREME) {
3503 for (
size_t r=0; r < getNodeNumRows(); ++r) {
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;
3509 if (vl == VERB_EXTREME) {
3510 if (isGloballyIndexed()) {
3511 ArrayView<const GlobalOrdinal> rowview = getGlobalView(rowinfo);
3512 for (
size_t j=0; j < rowinfo.numEntries; ++j) out << rowview[j] <<
" ";
3514 else if (isLocallyIndexed()) {
3515 ArrayView<const LocalOrdinal> rowview = getLocalView(rowinfo);
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>
3550 const Teuchos::ArrayView<const LocalOrdinal> &permuteToLIDs,
3551 const Teuchos::ArrayView<const LocalOrdinal> &permuteFromLIDs)
3553 using Teuchos::Array;
3554 using Teuchos::ArrayView;
3555 const char tfecfFuncName[] =
"copyAndPermute";
3557 const this_type& src_graph =
dynamic_cast<const this_type&
> (source);
3559 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
3560 permuteToLIDs.size() != permuteFromLIDs.size(), std::runtime_error,
3561 ": permuteToLIDs and permuteFromLIDs must have the same size.");
3564 const map_type& srcRowMap = * (src_graph.getRowMap ());
3565 const map_type& tgtRowMap = * (this->getRowMap ());
3567 Array<GlobalOrdinal> row_copy;
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);
3576 this->insertGlobalIndices (gid, row_copy ());
3579 ArrayView<const GlobalOrdinal> row;
3580 src_graph.getGlobalRowView (gid,row);
3581 insertGlobalIndices (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);
3593 this->insertGlobalIndices (mygid, row_copy ());
3596 ArrayView<const GlobalOrdinal> row;
3597 src_graph.getGlobalRowView (srcgid, row);
3598 this->insertGlobalIndices (mygid, row);
3604 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3608 const Teuchos::ArrayView<const LocalOrdinal> &exportLIDs,
3609 Teuchos::Array<GlobalOrdinal> &exports,
3610 const Teuchos::ArrayView<size_t> & numPacketsPerLID,
3611 size_t& constantNumPackets,
3614 using Teuchos::Array;
3615 const char tfecfFuncName[] =
"packAndPrepare";
3616 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
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);
3625 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
3626 this->isFillComplete (), std::runtime_error,
3627 ": The target CrsGraph of an Import or Export must not be fillComplete.");
3629 constantNumPackets = 0;
3631 size_t totalNumPackets = 0;
3632 Array<GlobalOrdinal> row;
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);
3647 row.resize(row_length);
3648 size_t check_row_length = 0;
3649 src_graph.getGlobalRowCopy(GID, row(), check_row_length);
3650 typename Array<GlobalOrdinal>::const_iterator
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>
3665 const Teuchos::ArrayView<const GlobalOrdinal> &imports,
3666 const Teuchos::ArrayView<size_t> &numPacketsPerLID,
3667 size_t constantNumPackets,
3688 const char tfecfFuncName[] =
"unpackAndCombine";
3689 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
3690 importLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
3691 ": importLIDs and numPacketsPerLID must have the same size.");
3692 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
3693 isFillComplete (), std::runtime_error,
3694 ": Import or Export operations are not allowed on the destination "
3695 "CrsGraph if it is fill complete.");
3696 size_t importsOffset = 0;
3698 typedef typename ArrayView<const LocalOrdinal>::const_iterator iter_type;
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];
3704 ArrayView<const GlobalOrdinal> row (&imports[importsOffset], row_length);
3705 insertGlobalIndicesFiltered (this->getMap ()->getGlobalElement (*impLIDiter), row);
3706 importsOffset += row_length;
3711 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node,
class LocalMatOps>
3716 using Teuchos::Comm;
3717 using Teuchos::null;
3718 using Teuchos::ParameterList;
3726 RCP<const map_type> rowMap, domainMap, rangeMap, colMap;
3727 RCP<import_type> importer;
3728 RCP<export_type> exporter;
3731 RCP<const Comm<int> > newComm =
3732 (newMap.is_null ()) ? null : newMap->getComm ();
3734 if (! domainMap_.is_null ()) {
3735 if (domainMap_.getRawPtr () == rowMap_.getRawPtr ()) {
3742 domainMap = domainMap_->replaceCommWithSubset (newComm);
3745 if (! rangeMap_.is_null ()) {
3746 if (rangeMap_.getRawPtr () == rowMap_.getRawPtr ()) {
3753 rangeMap = rangeMap_->replaceCommWithSubset (newComm);
3756 if (! colMap.is_null ()) {
3757 colMap = colMap_->replaceCommWithSubset (newComm);
3761 if (! newComm.is_null ()) {
3762 RCP<ParameterList> params = this->getNonconstParameterList ();
3770 if (! rangeMap_.is_null () &&
3771 rangeMap != rowMap &&
3772 ! rangeMap->isSameAs (*rowMap)) {
3773 if (params.is_null () || ! params->isSublist (
"Export")) {
3774 exporter = rcp (
new export_type (rowMap, rangeMap));
3777 RCP<ParameterList> exportSublist = sublist (params,
"Export",
true);
3778 exporter = rcp (
new export_type (rowMap, rangeMap, exportSublist));
3782 if (! domainMap_.is_null () &&
3783 domainMap != colMap &&
3784 ! domainMap->isSameAs (*colMap)) {
3785 if (params.is_null () || ! params->isSublist (
"Import")) {
3786 importer = rcp (
new import_type (domainMap, colMap));
3788 RCP<ParameterList> importSublist = sublist (params,
"Import",
true);
3789 importer = rcp (
new import_type (domainMap, colMap, importSublist));
3797 exporter_ = exporter;
3798 importer_ = importer;
3805 this->map_ = rowMap;
3806 domainMap_ = domainMap;
3807 rangeMap_ = rangeMap;
3820 #define TPETRA_CRSGRAPH_INSTANT(LO,GO,NODE) \
3822 template class CrsGraph< LO , GO , NODE >; \
3825 #endif // TPETRA_CRSGRAPH_DEF_HPP
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.
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.
bool isNodeGlobalElement(GlobalOrdinal globalIndex) const
Whether the given global index is valid for this Map on this process.
bool hasColMap() const
Whether the graph has a column Map.
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).
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.
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.
void insertGlobalIndices(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &indices)
Insert global indices into the graph.
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)
size_t getNodeAllocationSize() const
Returns the total number of indices allocated for the graph, across all rows on this node...
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.
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.
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.
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.
Abstract base class for objects that can be the source of an Import or Export operation.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
Returns the Map associated with the domain of this graph.
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.
std::string description() const
Return a simple one-line description of this object.
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 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 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.
virtual ~CrsGraph()
Destructor.
Base class for distributed Tpetra objects that support data redistribution.
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.
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.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
void setAllIndices(const ArrayRCP< size_t > &rowPointers, const ArrayRCP< LocalOrdinal > &columnIndices)
Set the graph's data directly, using 1-D storage.