42 #ifndef TPETRA_CRSMATRIX_DECL_HPP
43 #define TPETRA_CRSMATRIX_DECL_HPP
45 #include <Kokkos_DefaultNode.hpp>
46 #include <Kokkos_DefaultKernels.hpp>
48 #include "Tpetra_ConfigDefs.hpp"
49 #include "Tpetra_RowMatrix_decl.hpp"
50 #include "Tpetra_Exceptions.hpp"
51 #include "Tpetra_DistObject.hpp"
52 #include "Tpetra_CrsGraph.hpp"
53 #include "Tpetra_Vector.hpp"
189 template <
class Scalar,
190 class LocalOrdinal = int,
191 class GlobalOrdinal = LocalOrdinal,
192 class Node = Kokkos::DefaultNode::DefaultNodeType,
193 class LocalMatOps =
typename Kokkos::DefaultKernels<Scalar,LocalOrdinal,Node>::SparseOps >
195 public DistObject<char, LocalOrdinal,GlobalOrdinal,Node> {
197 typedef Scalar scalar_type;
198 typedef LocalOrdinal local_ordinal_type;
199 typedef GlobalOrdinal global_ordinal_type;
200 typedef Node node_type;
203 typedef LocalMatOps mat_vec_type;
204 typedef LocalMatOps mat_solve_type;
206 template <
class S2,
class LO2,
class GO2,
class N2,
class LMO2>
230 size_t maxNumEntriesPerRow,
232 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
252 const ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
254 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
280 size_t maxNumEntriesPerRow,
282 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
308 const ArrayRCP<const size_t>& NumEntriesPerRowToAlloc,
310 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
333 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null);
360 const ArrayRCP<size_t> & rowPointers,
361 const ArrayRCP<LocalOrdinal> & columnIndices,
362 const ArrayRCP<Scalar> & values,
363 const RCP<ParameterList>& params = null);
383 template <
class Node2>
384 RCP<CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node2,typename Kokkos::DefaultKernels<void,LocalOrdinal,Node2>::SparseOps> >
385 clone(
const RCP<Node2> &node2,
const RCP<ParameterList> ¶ms = null)
387 const char tfecfFuncName[] =
"clone()";
388 bool fillCompleteClone =
true;
391 if (params != null) fillCompleteClone = params->get(
"fillComplete clone",fillCompleteClone);
392 if (params != null) useLocalIndices = params->get(
"Locally indexed clone",useLocalIndices);
393 if (params != null && params->get(
"Static profile clone",
true) ==
false) pftype =
DynamicProfile;
395 TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
396 hasColMap() ==
false && useLocalIndices ==
true,
398 ": requested clone using local indices, but source graph doesn't have a column map yet."
403 RCP<const Map2> clonedRowMap =
getRowMap()->template
clone(node2);
405 RCP<CrsMatrix2> clonedMatrix;
406 ArrayRCP<const size_t> numEntries;
407 size_t numEntriesForAll = 0;
408 if (staticGraph_->indicesAreAllocated() ==
false) {
409 if (staticGraph_->numAllocPerRow_ != null) numEntries = staticGraph_->numAllocPerRow_;
410 else numEntriesForAll = staticGraph_->numAllocForAllRows_;
412 else if (staticGraph_->numRowEntries_ != null) numEntries = staticGraph_->numRowEntries_;
413 else if (staticGraph_->nodeNumAllocated_ == 0) numEntriesForAll = 0;
416 TEUCHOS_TEST_FOR_EXCEPTION(
getProfileType() !=
StaticProfile, std::logic_error,
"Internal logic error. Please report this to Tpetra team." )
418 numEntriesForAll = 0;
419 ArrayRCP<size_t> numEnt;
420 if (numRows) numEnt = arcp<size_t>(numRows);
421 for (
size_t i=0; i<numRows; ++i) {
422 numEnt[i] = staticGraph_->rowPtrs_[i+1] - staticGraph_->rowPtrs_[i];
427 RCP<ParameterList> matrixparams = sublist(params,
"CrsMatrix");
428 if (useLocalIndices) {
429 RCP<const Map2> clonedColMap =
getColMap()->template
clone(node2);
430 if (numEntries == null) clonedMatrix = rcp(
new CrsMatrix2(clonedRowMap,clonedColMap,numEntriesForAll,pftype,matrixparams));
431 else clonedMatrix = rcp(
new CrsMatrix2(clonedRowMap,clonedColMap,numEntries,pftype,matrixparams));
434 if (numEntries == null) clonedMatrix = rcp(
new CrsMatrix2(clonedRowMap,numEntriesForAll,pftype,matrixparams));
435 else clonedMatrix = rcp(
new CrsMatrix2(clonedRowMap,numEntries,pftype,matrixparams));
439 numEntriesForAll = 0;
443 clonedMatrix->allocateValues(LocalIndices,CrsMatrix2::GraphNotYetAllocated);
446 ArrayView<const LocalOrdinal> linds;
447 ArrayView<const Scalar> vals;
448 for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex();
449 lrow <= clonedRowMap->getMaxLocalIndex();
453 if (linds.size()) clonedMatrix->insertLocalValues(lrow, linds, vals);
458 Array<LocalOrdinal> linds;
460 for (LocalOrdinal lrow = clonedRowMap->getMinLocalIndex();
461 lrow <= clonedRowMap->getMaxLocalIndex();
464 size_t theNumEntries;
466 vals.resize( linds.size() );
467 this->
getLocalRowCopy(clonedRowMap->getGlobalElement(lrow), linds(), vals(), theNumEntries);
468 if (theNumEntries) clonedMatrix->insertLocalValues(lrow, linds(0,theNumEntries), vals(0,theNumEntries) );
474 clonedMatrix->allocateValues(GlobalIndices,CrsMatrix2::GraphNotYetAllocated);
477 ArrayView<const GlobalOrdinal> ginds;
478 ArrayView<const Scalar> vals;
479 for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex();
480 grow <= clonedRowMap->getMaxGlobalIndex();
484 if (ginds.size()) clonedMatrix->insertGlobalValues(grow, ginds, vals);
489 Array<GlobalOrdinal> ginds;
491 for (GlobalOrdinal grow = clonedRowMap->getMinGlobalIndex();
492 grow <= clonedRowMap->getMaxGlobalIndex();
495 size_t theNumEntries;
497 vals.resize( ginds.size() );
499 if (theNumEntries) clonedMatrix->insertGlobalValues(grow, ginds(0,theNumEntries), vals(0,theNumEntries) );
504 if (fillCompleteClone) {
505 RCP<ParameterList> fillparams = sublist(params,
"fillComplete");
507 RCP<const Map2> clonedRangeMap;
508 RCP<const Map2> clonedDomainMap;
513 clonedRangeMap = clonedRowMap;
519 clonedDomainMap = clonedRowMap;
521 clonedMatrix->fillComplete(clonedDomainMap, clonedRangeMap, fillparams);
523 catch (std::exception &e) {
524 const bool caughtExceptionOnClone =
true;
525 TEUCHOS_TEST_FOR_EXCEPTION(caughtExceptionOnClone,
527 Teuchos::typeName(*
this)
528 <<
"\ncaught the following exception while calling fillComplete() on clone of type\n"
529 << Teuchos::typeName(*clonedMatrix)
615 const ArrayView<const GlobalOrdinal>& cols,
616 const ArrayView<const Scalar>& vals);
659 const ArrayView<const LocalOrdinal> &cols,
660 const ArrayView<const Scalar> &vals);
669 const ArrayView<const GlobalOrdinal> &cols,
670 const ArrayView<const Scalar> &vals);
677 const ArrayView<const LocalOrdinal> &cols,
678 const ArrayView<const Scalar> &vals);
708 const ArrayView<const GlobalOrdinal> &cols,
709 const ArrayView<const Scalar> &vals);
721 const ArrayView<const LocalOrdinal> &cols,
722 const ArrayView<const Scalar> &vals);
728 void scale(
const Scalar &alpha);
738 void setAllValues(
const ArrayRCP<size_t> & rowPointers,
const ArrayRCP<LocalOrdinal> & columnIndices,
const ArrayRCP<Scalar> & values);
787 void resumeFill (
const RCP<ParameterList>& params = null);
811 const RCP<ParameterList> ¶ms = null);
825 void fillComplete(
const RCP<ParameterList> ¶ms = null);
843 const RCP<ParameterList> ¶ms=Teuchos::null);
882 const RCP<const Comm<int> > &
getComm()
const;
888 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
getRowMap()
const;
891 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
getColMap()
const;
894 RCP<const RowGraph<LocalOrdinal,GlobalOrdinal,Node> >
getGraph()
const;
897 RCP<const CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> >
getCrsGraph()
const;
1040 const ArrayView<GlobalOrdinal> &Indices,
1041 const ArrayView<Scalar> &Values,
1059 const ArrayView<LocalOrdinal> &Indices,
1060 const ArrayView<Scalar> &Values,
1074 void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values)
const;
1086 void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values)
const;
1152 const Teuchos::ArrayView<const size_t>& offsets)
const;
1212 template <
class DomainScalar,
class RangeScalar>
1216 Teuchos::ETransp trans,
1218 RangeScalar beta)
const;
1244 template <
class DomainScalar,
class RangeScalar>
1249 const RangeScalar& dampingFactor,
1250 const Kokkos::ESweepDirection direction)
const;
1268 template <
class DomainScalar,
class RangeScalar>
1272 Teuchos::ETransp trans)
const;
1276 RCP<CrsMatrix<T,LocalOrdinal,GlobalOrdinal,Node> >
convert()
const;
1295 Teuchos::ETransp mode = Teuchos::NO_TRANS,
1296 Scalar alpha = ScalarTraits<Scalar>::one(),
1297 Scalar beta = ScalarTraits<Scalar>::zero())
const;
1305 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
getDomainMap()
const;
1310 const RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
getRangeMap()
const;
1384 const Scalar& dampingFactor,
1386 const int numSweeps)
const;
1420 const Scalar& dampingFactor,
1422 const int numSweeps,
1423 const bool zeroInitialGuess)
const;
1435 virtual Teuchos::RCP<RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
1436 add (
const Scalar& alpha,
1441 const Teuchos::RCP<Teuchos::ParameterList>& params)
const;
1451 void describe(Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default)
const;
1463 const ArrayView<const LocalOrdinal> &permuteToLIDs,
1464 const ArrayView<const LocalOrdinal> &permuteFromLIDs);
1468 const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
1469 Teuchos::Array<char>& exports,
1470 const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1471 size_t& constantNumPackets,
1483 pack (
const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
1484 Teuchos::Array<char>& exports,
1485 const Teuchos::ArrayView<size_t>& numPacketsPerLID,
1486 size_t& constantNumPackets,
1499 unpackAndCombine (
const Teuchos::ArrayView<const LocalOrdinal> &importLIDs,
1500 const Teuchos::ArrayView<const char> &imports,
1501 const Teuchos::ArrayView<size_t> &numPacketsPerLID,
1502 size_t constantNumPackets,
1508 template<
class CrsMatrixType>
1509 friend Teuchos::RCP<CrsMatrixType>
1510 importAndFillCompleteCrsMatrix (
const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
1511 const Import<
typename CrsMatrixType::local_ordinal_type,
1512 typename CrsMatrixType::global_ordinal_type,
1513 typename CrsMatrixType::node_type>& importer,
1514 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
1515 typename CrsMatrixType::global_ordinal_type,
1516 typename CrsMatrixType::node_type> >& domainMap,
1517 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
1518 typename CrsMatrixType::global_ordinal_type,
1519 typename CrsMatrixType::node_type> >& rangeMap,
1520 const Teuchos::RCP<Teuchos::ParameterList>& params);
1522 template<
class CrsMatrixType>
1523 friend Teuchos::RCP<CrsMatrixType>
1524 exportAndFillCompleteCrsMatrix (
const Teuchos::RCP<const CrsMatrixType>& sourceMatrix,
1525 const Export<
typename CrsMatrixType::local_ordinal_type,
1526 typename CrsMatrixType::global_ordinal_type,
1527 typename CrsMatrixType::node_type>& exporter,
1528 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
1529 typename CrsMatrixType::global_ordinal_type,
1530 typename CrsMatrixType::node_type> >& domainMap,
1531 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
1532 typename CrsMatrixType::global_ordinal_type,
1533 typename CrsMatrixType::node_type> >& rangeMap,
1534 const Teuchos::RCP<Teuchos::ParameterList>& params);
1542 Teuchos::RCP<CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps> >
1544 const Teuchos::RCP<const map_type>& domainMap,
1545 const Teuchos::RCP<const map_type>& rangeMap,
1546 const Teuchos::RCP<Teuchos::ParameterList>& params)
const;
1554 Teuchos::RCP<CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> >
1556 const Teuchos::RCP<const map_type>& domainMap = Teuchos::null,
1557 const Teuchos::RCP<const map_type>& rangeMap = Teuchos::null,
1558 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
const;
1576 insertGlobalValuesFiltered (
const GlobalOrdinal globalRow,
1577 const ArrayView<const GlobalOrdinal> &indices,
1578 const ArrayView<const Scalar> &values);
1586 insertLocalValuesFiltered (
const LocalOrdinal localRow,
1587 const ArrayView<const LocalOrdinal> &indices,
1588 const ArrayView<const Scalar> &values);
1598 combineGlobalValues (
const GlobalOrdinal globalRowIndex,
1599 const Teuchos::ArrayView<const GlobalOrdinal> columnIndices,
1600 const Teuchos::ArrayView<const Scalar> values,
1634 template<
class BinaryFunction>
1636 transformLocalValues (LocalOrdinal localRow,
1637 const Teuchos::ArrayView<const LocalOrdinal>& indices,
1638 const Teuchos::ArrayView<const Scalar> & values,
1641 typedef LocalOrdinal LO;
1642 typedef GlobalOrdinal GO;
1644 using Teuchos::Array;
1645 using Teuchos::ArrayView;
1647 TEUCHOS_TEST_FOR_EXCEPTION(
1650 "Tpetra::CrsMatrix::transformLocalValues: Fill must be active in order "
1651 "to call this method. That is, isFillActive() must return true. If "
1652 "you have already called fillComplete(), you need to call resumeFill() "
1653 "before you can replace values.");
1654 TEUCHOS_TEST_FOR_EXCEPTION(
1655 values.size () != indices.size (),
1657 "Tpetra::CrsMatrix::transformLocalValues: values.size () = "
1658 << values.size () <<
" != indices.size () = " << indices.size ()
1660 TEUCHOS_TEST_FOR_EXCEPTION(
1663 "Tpetra::CrsMatrix::transformLocalValues: We cannot transform local "
1664 "indices without a column map.");
1665 const bool isLocalRow =
getRowMap ()->isNodeLocalElement (localRow);
1666 TEUCHOS_TEST_FOR_EXCEPTION(
1669 "Tpetra::CrsMatrix::transformLocalValues: The specified local row "
1670 << localRow <<
" does not belong to this process "
1673 RowInfo rowInfo = staticGraph_->getRowInfo (localRow);
1674 if (indices.size () > 0) {
1675 ArrayView<Scalar> curVals = this->getViewNonConst (rowInfo);
1677 staticGraph_->template transformLocalValues<Scalar, BinaryFunction> (rowInfo, curVals, indices, values, f);
1681 const Map<LO, GO, NT>& colMap = * (this->
getColMap ());
1682 Array<GO> gindices (indices.size ());
1683 typename ArrayView<const LO>::iterator lindit = indices.begin();
1684 typename Array<GO>::iterator gindit = gindices.begin();
1685 while (lindit != indices.end()) {
1689 *gindit++ = colMap.getGlobalElement (*lindit++);
1691 staticGraph_->template transformGlobalValues<Scalar, BinaryFunction> (rowInfo, curVals, gindices (), values, f);
1726 template<
class BinaryFunction>
1728 transformGlobalValues (GlobalOrdinal globalRow,
1729 const Teuchos::ArrayView<const GlobalOrdinal>& indices,
1730 const Teuchos::ArrayView<const Scalar> & values,
1733 typedef LocalOrdinal LO;
1734 typedef GlobalOrdinal GO;
1736 using Teuchos::Array;
1737 using Teuchos::ArrayView;
1739 TEUCHOS_TEST_FOR_EXCEPTION(
1742 "Tpetra::CrsMatrix::transformGlobalValues: Fill must be active in order "
1743 "to call this method. That is, isFillActive() must return true. If "
1744 "you have already called fillComplete(), you need to call resumeFill() "
1745 "before you can replace values.");
1746 TEUCHOS_TEST_FOR_EXCEPTION(
1747 values.size () != indices.size (),
1749 "Tpetra::CrsMatrix::transformGlobalValues: values.size () = "
1750 << values.size () <<
" != indices.size () = " << indices.size ()
1753 const LO lrow = this->
getRowMap()->getLocalElement(globalRow);
1755 if (lrow == OTL::invalid()) {
1763 std::ostringstream os;
1764 os <<
"transformGlobalValues: The given global row index "
1765 << globalRow <<
" is not owned by the calling process (rank "
1766 << this->
getRowMap()->getComm()->getRank() <<
").";
1767 throw Details::InvalidGlobalRowIndex<GO> (os.str (), globalRow);
1770 RowInfo rowInfo = staticGraph_->getRowInfo (lrow);
1771 if (indices.size () > 0) {
1772 ArrayView<Scalar> curVals = this->getViewNonConst (rowInfo);
1775 const Map<LO, GO, NT> &colMap = * (this->
getColMap ());
1776 Array<LO> lindices (indices.size ());
1777 typename ArrayView<const GO>::iterator gindit = indices.begin();
1778 typename Array<LO>::iterator lindit = lindices.begin();
1779 while (gindit != indices.end()) {
1783 *lindit++ = colMap.getLocalElement (*gindit++);
1785 staticGraph_->template transformLocalValues<Scalar, BinaryFunction> (rowInfo, curVals, lindices (), values, f);
1788 staticGraph_->template transformGlobalValues<Scalar, BinaryFunction> (rowInfo, curVals, indices, values, f);
1795 typedef OrdinalTraits<LocalOrdinal> OTL;
1796 typedef ScalarTraits<Scalar> STS;
1797 typedef typename STS::magnitudeType Magnitude;
1798 typedef ScalarTraits<Magnitude> STM;
1799 typedef MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> MV;
1800 typedef Vector<Scalar,LocalOrdinal,GlobalOrdinal,Node> V;
1801 typedef CrsGraph<LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> Graph;
1802 typedef typename LocalMatOps::template bind_scalar<Scalar>::other_type sparse_ops_type;
1803 typedef typename sparse_ops_type::template graph<LocalOrdinal,Node>::graph_type local_graph_type;
1804 typedef typename sparse_ops_type::template matrix<Scalar,LocalOrdinal,Node>::matrix_type local_matrix_type;
1806 typedef Export<LocalOrdinal, GlobalOrdinal, Node> export_type;
1807 typedef Import<LocalOrdinal, GlobalOrdinal, Node> import_type;
1810 enum GraphAllocationStatus {
1811 GraphAlreadyAllocated,
1812 GraphNotYetAllocated
1831 void allocateValues (ELocalGlobal lg, GraphAllocationStatus gas);
1915 const bool force =
false)
const;
1940 const bool force =
false)
const;
1953 const Teuchos::ETransp mode,
1958 ArrayView<const Scalar> getView(
RowInfo rowinfo)
const;
1959 ArrayView< Scalar> getViewNonConst(
RowInfo rowinfo);
1975 void checkInternalState()
const;
1989 RCP<const Graph> staticGraph_;
1990 RCP< Graph> myGraph_;
2019 ArrayRCP<Scalar> values1D_;
2020 ArrayRCP<Array<Scalar> > values2D_;
2042 std::map<GlobalOrdinal, Array<std::pair<GlobalOrdinal,Scalar> > >
nonlocals_;
2059 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
2060 Teuchos::RCP<CrsMatrix<Scalar,LocalOrdinal,GlobalOrdinal,Node> >
2062 size_t maxNumEntriesPerRow = 0,
2063 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2067 return rcp (
new matrix_type (map, maxNumEntriesPerRow,
DynamicProfile, params));
2121 template<
class CrsMatrixType>
2122 Teuchos::RCP<CrsMatrixType>
2124 const Import<
typename CrsMatrixType::local_ordinal_type,
2125 typename CrsMatrixType::global_ordinal_type,
2126 typename CrsMatrixType::node_type>& importer,
2127 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
2128 typename CrsMatrixType::global_ordinal_type,
2129 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
2130 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
2131 typename CrsMatrixType::global_ordinal_type,
2132 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
2133 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2135 return sourceMatrix->importAndFillComplete (importer, domainMap, rangeMap, params);
2171 template<
class CrsMatrixType>
2172 Teuchos::RCP<CrsMatrixType>
2174 const Export<
typename CrsMatrixType::local_ordinal_type,
2175 typename CrsMatrixType::global_ordinal_type,
2176 typename CrsMatrixType::node_type>& exporter,
2177 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
2178 typename CrsMatrixType::global_ordinal_type,
2179 typename CrsMatrixType::node_type> >& domainMap = Teuchos::null,
2180 const Teuchos::RCP<
const Map<
typename CrsMatrixType::local_ordinal_type,
2181 typename CrsMatrixType::global_ordinal_type,
2182 typename CrsMatrixType::node_type> >& rangeMap = Teuchos::null,
2183 const Teuchos::RCP<Teuchos::ParameterList>& params = Teuchos::null)
2185 return sourceMatrix->exportAndFillComplete (exporter, domainMap, rangeMap, params);
Teuchos::RCP< MV > exportMV_
Row Map MultiVector used in apply().
Communication plan for data redistribution from a uniquely-owned to a (possibly) multiply-owned distr...
void localGaussSeidel(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const RangeScalar &dampingFactor, const Kokkos::ESweepDirection direction) const
Gauss-Seidel or SOR on .
size_t getNodeNumRows() const
Returns the number of matrix rows owned on the calling node.
void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView< const GlobalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of global indices in a specified row of the matrix.
void unpackAndCombine(const Teuchos::ArrayView< const LocalOrdinal > &importLIDs, const Teuchos::ArrayView< const char > &imports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t constantNumPackets, Distributor &distor, CombineMode combineMode)
Unpack the imported column indices and values, and combine into matrix.
void sortEntries()
Sort the entries of each row by their column indices.
RCP< Node > getNode() const
Returns the underlying node.
Sparse matrix that presents a compressed sparse row interface.
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
GlobalOrdinal getIndexBase() const
Returns the index base for global indices for this matrix.
void insertLocalValues(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using local indices.
void sumIntoGlobalValues(const GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Sum into one or more sparse matrix entries, using global indices.
void mergeRedundantEntries()
Merge entries in each row with the same column indices.
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
bool isStaticGraph() const
Indicates that the graph is static, so that new entries cannot be added to this matrix.
RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRowMap() const
Returns the Map that describes the row distribution in this matrix.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Returns the Frobenius norm of the matrix.
virtual void packAndPrepare(const SrcDistObject &source, const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor)
Perform any packing or preparation required for communication.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
void getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView< LocalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified local row of the matrix. Put into storage allocated by calli...
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
One or more distributed dense vectors.
void insertGlobalValues(const GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert one or more entries into the matrix, using global indices.
size_t getNodeNumDiags() const
Returns the number of local diagonal entries, based on global row/column index comparisons.
bool fillComplete_
Whether the matrix is fill complete.
RCP< CrsMatrix< T, LocalOrdinal, GlobalOrdinal, Node > > convert() const
Returns another CrsMatrix with the same entries, but represented as a different scalar type...
void globalAssemble()
Communicate nonlocal contributions to other processes.
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
Allocation information for a locally owned row in a CrsGraph or CrsMatrix.
void getGlobalRowCopy(GlobalOrdinal GlobalRow, const ArrayView< GlobalOrdinal > &Indices, const ArrayView< Scalar > &Values, size_t &NumEntries) const
Extract a list of entries in a specified global row of this matrix. Put into pre-allocated storage...
void fillLocalMatrix(const RCP< ParameterList > ¶ms)
Fill data into the local matrix.
void setAllValues(const ArrayRCP< size_t > &rowPointers, const ArrayRCP< LocalOrdinal > &columnIndices, const ArrayRCP< Scalar > &values)
Sets the 1D pointer arrays of the graph.
void gaussSeidel(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps) const
"Hybrid" Jacobi + (Gauss-Seidel or SOR) on .
virtual void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &newMap)
Remove processes owning zero rows from the Maps and their communicator.
RCP< sparse_ops_type > lclMatOps_
Teuchos::RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > createCrsMatrix(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map, size_t maxNumEntriesPerRow=0, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Non-member function to create an empty CrsMatrix given a row map and a non-zero profile.
Teuchos::RCP< CrsMatrixType > importAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Import< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &importer, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Import and fillComplete().
size_t global_size_t
Global size_t object.
void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalarThis.
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Compute a sparse matrix-MultiVector multiply.
bool isFillComplete() const
Returns true if the matrix is in compute mode, i.e. if fillComplete() has been called.
global_size_t getGlobalNumRows() const
Number of global elements in the row map of this matrix.
void getLocalDiagCopy(Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row indices.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getDomainMap() const
The domain Map of this operator.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getRangeMap() const
The range Map of this operator.
size_t getNodeNumCols() const
Returns the number of columns connected to the locally owned rows of this matrix. ...
bool isUpperTriangular() const
Indicates whether the matrix is upper triangular.
void fillLocalGraphAndMatrix(const RCP< ParameterList > ¶ms)
Fill data into the local graph and matrix.
void applyNonTranspose(const MV &X_in, MV &Y_in, Scalar alpha, Scalar beta) const
Special case of apply() for mode == Teuchos::NO_TRANS.
void getLocalRowView(LocalOrdinal LocalRow, ArrayView< const LocalOrdinal > &indices, ArrayView< const Scalar > &values) const
Extract a const, non-persisting view of local indices in a specified row of the matrix.
RCP< local_matrix_type > lclMatrix_
ESweepDirection
Sweep direction for Gauss-Seidel or Successive Over-Relaxation (SOR).
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 matrix that already has data.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
Communication plan for data redistribution from a (possibly) multiply-owned to a uniquely-owned distr...
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.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
std::map< GlobalOrdinal, Array< std::pair< GlobalOrdinal, Scalar > > > nonlocals_
Nonlocal data added using insertGlobalValues().
Sets up and executes a communication plan for a Tpetra DistObject.
CombineMode
Tpetra::Combine Mode enumerable type.
void localSolve(const MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, Teuchos::ETransp trans) const
Solves a linear system when the underlying matrix is triangular.
std::string description() const
A simple one-line description of this object.
bool isFillActive() const
Returns true if the matrix is in edit mode.
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Teuchos::RCP< MV > getColumnMapMultiVector(const MV &X_domainMap, const bool force=false) const
Create a (or fetch a cached) column Map MultiVector.
Abstract base class for objects that can be the source of an Import or Export operation.
virtual bool supportsRowViews() const
Returns true if getLocalRowView() and getGlobalRowView() are valid for this class.
size_t getNodeNumEntries() const
Returns the local number of entries in this matrix.
void gaussSeidelCopy(MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &D, const Scalar &dampingFactor, const ESweepDirection direction, const int numSweeps, const bool zeroInitialGuess) const
Version of gaussSeidel(), with fewer requirements on X.
void applyTranspose(const MV &X_in, MV &Y_in, const Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Special case of apply() for mode != Teuchos::NO_TRANS.
void clearGlobalConstants()
Clear matrix properties that require collectives.
size_t getNodeMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
ProfileType getProfileType() const
Returns true if the matrix was allocated with static data structures.
virtual Teuchos::RCP< RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > add(const Scalar &alpha, const RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &domainMap, const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &rangeMap, const Teuchos::RCP< Teuchos::ParameterList > ¶ms) const
Implementation of RowMatrix::add: return alpha*A + beta*this.
global_size_t getGlobalNumDiags() const
Returns the number of global diagonal entries, based on global row/column index comparisons.
virtual ~CrsMatrix()
Destructor.
Magnitude frobNorm_
Cached Frobenius norm of the (global) matrix.
global_size_t getGlobalNumCols() const
Number of global columns in the matrix.
const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > & getColMap() const
Returns the Map that describes the column distribution in this matrix.
A distributed graph accessed by rows (adjacency lists) and stored sparsely.
Describes a parallel distribution of objects over processes.
bool isLowerTriangular() const
Indicates whether the matrix is lower triangular.
A read-only, row-oriented interface to a sparse matrix.
void computeGlobalConstants()
Compute matrix properties that require collectives.
A distributed dense vector.
void replaceDomainMapAndImporter(const Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > &newDomainMap, Teuchos::RCP< const Tpetra::Import< LocalOrdinal, GlobalOrdinal, Node > > &newImporter)
Replace the current domain Map and Import with the given objects.
Teuchos::RCP< CrsMatrixType > exportAndFillCompleteCrsMatrix(const Teuchos::RCP< const CrsMatrixType > &sourceMatrix, const Export< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > &exporter, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &domainMap=Teuchos::null, const Teuchos::RCP< const Map< typename CrsMatrixType::local_ordinal_type, typename CrsMatrixType::global_ordinal_type, typename CrsMatrixType::node_type > > &rangeMap=Teuchos::null, const Teuchos::RCP< Teuchos::ParameterList > ¶ms=Teuchos::null)
Nonmember CrsMatrix constructor that fuses Export and fillComplete().
void resumeFill(const RCP< ParameterList > ¶ms=null)
Resume operations that may change the values or structure of the matrix.
bool hasColMap() const
Indicates whether the matrix has a well-defined column map.
bool hasTransposeApply() const
Whether apply() allows applying the transpose or conjugate transpose.
Teuchos::RCP< MV > importMV_
Column Map MultiVector used in apply() and gaussSeidel().
void localMultiply(const MultiVector< DomainScalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< RangeScalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp trans, RangeScalar alpha, RangeScalar beta) const
Compute a sparse matrix-MultiVector product local to each process.
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries on this node in the specified global row.
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.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
Base class for distributed Tpetra objects that support data redistribution.
bool isStorageOptimized() const
Returns true if storage has been optimized.
void sumIntoLocalValues(const LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Sum into one or more sparse matrix entries, using local indices.
void allocateValues(ELocalGlobal lg, GraphAllocationStatus gas)
Allocate values (and optionally indices) using the Node.
virtual void pack(const Teuchos::ArrayView< const LocalOrdinal > &exportLIDs, Teuchos::Array< char > &exports, const Teuchos::ArrayView< size_t > &numPacketsPerLID, size_t &constantNumPackets, Distributor &distor) const
Implementation of SrcDistObjectWithPack.
virtual bool checkSizes(const SrcDistObject &source)
Compare the source and target (this) objects for compatibility.
const RCP< const Comm< int > > & getComm() const
Returns the communicator.
Teuchos::RCP< MV > getRowMapMultiVector(const MV &Y_rangeMap, const bool force=false) const
Create a (or fetch a cached) row Map MultiVector.
RCP< CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node2, typename Kokkos::DefaultKernels< void, LocalOrdinal, Node2 >::SparseOps > > clone(const RCP< Node2 > &node2, const RCP< ParameterList > ¶ms=null)
Create a cloned CrsMatrix for a different node type.
RCP< const RowGraph< LocalOrdinal, GlobalOrdinal, Node > > getGraph() const
Returns the RowGraph associated with this matrix.