12 #ifndef XPETRA_CRSMATRIXWRAP_DECL_HPP
13 #define XPETRA_CRSMATRIXWRAP_DECL_HPP
15 #include <Tpetra_KokkosCompat_DefaultNode.hpp>
25 #include "Xpetra_Matrix.hpp"
27 #include "Xpetra_TpetraBlockCrsMatrix.hpp"
29 #include "Xpetra_TpetraCrsMatrix.hpp"
31 #include <Teuchos_SerialDenseMatrix.hpp>
32 #include <Teuchos_Hashtable.hpp>
46 template <
class Scalar,
49 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
55 #ifdef HAVE_XPETRA_TPETRA
60 #ifdef HAVE_XPETRA_TPETRA
73 size_t maxNumEntriesPerRow);
77 const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc);
80 CrsMatrixWrap(
const RCP<const Map> &rowMap,
const RCP<const Map> &colMap,
size_t maxNumEntriesPerRow);
83 CrsMatrixWrap(
const RCP<const Map> &rowMap,
const RCP<const Map> &colMap,
const ArrayRCP<const size_t> &NumEntriesPerRowToAlloc);
85 #ifdef HAVE_XPETRA_TPETRA
86 CrsMatrixWrap(
const RCP<const Map> &rowMap,
const RCP<const Map> &colMap,
const local_matrix_type &lclMatrix,
const Teuchos::RCP<Teuchos::ParameterList> ¶ms = null);
91 const RCP<const Map> &domainMap = Teuchos::null,
const RCP<const Map> &rangeMap = Teuchos::null,
92 const Teuchos::RCP<Teuchos::ParameterList> ¶ms = null);
95 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
101 CrsMatrixWrap(
const RCP<const CrsGraph> &graph,
const RCP<ParameterList> ¶mList = Teuchos::null);
105 const RCP<ParameterList> ¶mList = Teuchos::null);
127 void insertGlobalValues(GlobalOrdinal globalRow,
const ArrayView<const GlobalOrdinal> &cols,
const ArrayView<const Scalar> &vals);
137 void insertLocalValues(LocalOrdinal localRow,
const ArrayView<const LocalOrdinal> &cols,
const ArrayView<const Scalar> &vals);
146 const ArrayView<const GlobalOrdinal> &cols,
147 const ArrayView<const Scalar> &vals);
154 const ArrayView<const LocalOrdinal> &cols,
155 const ArrayView<const Scalar> &vals);
161 void scale(
const Scalar &alpha);
176 void resumeFill(
const RCP<ParameterList> ¶ms = null);
189 void fillComplete(
const RCP<const Map> &domainMap,
const RCP<const Map> &rangeMap,
const RCP<Teuchos::ParameterList> ¶ms = null);
205 void fillComplete(
const RCP<ParameterList> ¶ms = null);
269 const ArrayView<LocalOrdinal> &Indices,
270 const ArrayView<Scalar> &Values,
271 size_t &NumEntries)
const;
283 void getGlobalRowView(GlobalOrdinal GlobalRow, ArrayView<const GlobalOrdinal> &indices, ArrayView<const Scalar> &values)
const;
295 void getLocalRowView(LocalOrdinal LocalRow, ArrayView<const LocalOrdinal> &indices, ArrayView<const Scalar> &values)
const;
351 Teuchos::ETransp mode = Teuchos::NO_TRANS,
352 Scalar alpha = ScalarTraits<Scalar>::one(),
353 Scalar beta = ScalarTraits<Scalar>::zero())
const;
358 Teuchos::ETransp mode,
361 bool sumInterfaceValues,
363 const Teuchos::ArrayRCP<LocalOrdinal> ®ionInterfaceLIDs)
const;
367 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
getDomainMap()
const;
371 const RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
getRangeMap()
const;
388 const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
getMap()
const;
415 void describe(Teuchos::FancyOStream &out,
const Teuchos::EVerbosityLevel verbLevel = Teuchos::Describable::verbLevel_default)
const;
422 #ifdef HAVE_XPETRA_TPETRA
427 #warning "Xpetra Kokkos interface for CrsMatrix is enabled (HAVE_XPETRA_KOKKOS_REFACTOR) but Tpetra is disabled. The Kokkos interface needs Tpetra to be enabled, too."
469 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
470 Teuchos::RCP<Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
475 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
476 Teuchos::RCP<const Xpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
481 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
487 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
493 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
494 Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
495 toXpetra(
const Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> &A) {
501 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
502 Teuchos::RCP<const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
503 toXpetra(Teuchos::RCP<
const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> &A) {
509 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
510 Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
511 toXpetra(Teuchos::RCP<Tpetra::FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> &A) {
517 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
518 Teuchos::RCP<const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
519 toXpetra(Teuchos::RCP<
const Tpetra::FECrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>> &A) {
525 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
526 Teuchos::RCP<Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
531 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
532 Teuchos::RCP<const Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
537 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
538 Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> &
543 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
544 Tpetra::CrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> &
549 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
550 Teuchos::RCP<Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
555 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
556 Teuchos::RCP<const Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
561 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
562 Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> &
567 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
568 const Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> &
573 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
574 Teuchos::RCP<Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
579 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
580 Teuchos::RCP<const Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
585 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
586 Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> &
591 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
592 const Tpetra::BlockCrsMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> &
597 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
598 Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
602 if (!tmp_Crs.is_null()) {
606 if (tmp_BlockCrs.is_null())
607 throw Exceptions::BadCast(
"Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
608 return tmp_BlockCrs->getTpetra_BlockCrsMatrixNonConst();
612 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
613 Teuchos::RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
617 if (!tmp_Crs.is_null()) {
621 if (tmp_BlockCrs.is_null())
622 throw Exceptions::BadCast(
"Cast from Xpetra::CrsMatrix to Xpetra::TpetraCrsMatrix and Xpetra::TpetraBlockCrsMatrix failed");
623 return tmp_BlockCrs->getTpetra_BlockCrsMatrix();
627 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
628 Teuchos::RCP<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
632 if (!mat.is_null()) {
634 }
else if (!rmat.is_null()) {
635 return rmat->getTpetra_RowMatrixNonConst();
639 auto tRow = Teuchos::rcp_dynamic_cast<Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(tOp,
true);
644 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
645 Teuchos::RCP<const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>
649 if (!mat.is_null()) {
651 }
else if (!rmat.is_null()) {
652 return rmat->getTpetra_RowMatrix();
656 auto tRow = Teuchos::rcp_dynamic_cast<
const Tpetra::RowMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>(tOp,
true);
663 #define XPETRA_CRSMATRIXWRAP_SHORT
664 #endif // XPETRA_CRSMATRIXWRAP_DECL_HPP
void setObjectLabel(const std::string &objectLabel)
RCP< CrsMatrix > getCrsMatrix() const
Teuchos::RCP< Tpetra::RowMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > toTpetraRowMatrix(const Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &mat)
void rightScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Right scale matrix using the given vector entries.
bool isGloballyIndexed() const
If matrix indices are in the global range, this function returns true. Otherwise, this function retur...
Xpetra::TpetraCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > TpetraCrsMatrix
global_size_t getGlobalNumEntries() const
Returns the global number of entries in this matrix.
void replaceGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using global IDs.
virtual local_matrix_type::HostMirror getLocalMatrixHost() const
virtual local_matrix_type getLocalMatrixDevice() const
global_size_t getGlobalNumRows() const
Returns the number of global rows in this matrix.
size_t getLocalNumEntries() const
Returns the local number of entries in this matrix.
const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getMap() const
Implements DistObject interface.
const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Map associated with the domain of this operator. This will be null until fillComplete() i...
bool hasCrsGraph() const
Supports the getCrsGraph() call.
void scale(const Scalar &alpha)
Scale the current values of a matrix, this = alpha*this.
LocalOrdinal GetStorageBlockSize() const
Returns the block size of the storage mechanism, which is usually 1, except for Tpetra::BlockCrsMatri...
void removeEmptyProcessesInPlace(const Teuchos::RCP< const Map > &newMap)
Xpetra::MatrixView< Scalar, LocalOrdinal, GlobalOrdinal, Node > MatrixView
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.
Teuchos::RCP< Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > toCrsMatrix(const Teuchos::RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &matrix)
void doExport(const Matrix &dest, const Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Export.
virtual RCP< Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator()
Gets the operator out.
void updateDefaultView() const
size_t getNumEntriesInLocalRow(LocalOrdinal localRow) const
Returns the current number of entries on this node in the specified local row.
ScalarTraits< Scalar >::magnitudeType getFrobeniusNorm() const
Get Frobenius norm of the matrix.
Exception indicating invalid cast attempted.
void doImport(const Matrix &source, const Xpetra::Import< LocalOrdinal, GlobalOrdinal, Node > &importer, CombineMode CM)
Import.
std::string description() const
Return a simple one-line description of this object.
void getLocalDiagOffsets(Teuchos::ArrayRCP< size_t > &offsets) const
Get offsets of the diagonal entries in the matrix.
Xpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > CrsGraph
CrsMatrix::local_matrix_type local_matrix_type
void getLocalDiagCopy(Xpetra::Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &diag) const
Get a copy of the diagonal entries owned by this node, with local row idices.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
CrsMatrixWrap(const RCP< const Map > &rowMap)
Constructor for a dynamic profile matrix (Epetra only)
void residual(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
RCP< const CrsGraph > getCrsGraph() const
Returns the CrsGraph associated with this matrix.
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.
size_t getGlobalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on all nodes.
size_t global_size_t
Global size_t object.
void insertGlobalValues(GlobalOrdinal globalRow, const ArrayView< const GlobalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using global IDs.
void fillComplete(const RCP< const Map > &domainMap, const RCP< const Map > &rangeMap, const RCP< Teuchos::ParameterList > ¶ms=null)
Signal that data entry is complete, specifying domain and range maps.
RCP< CrsMatrix > matrixData_
bool haveGlobalConstants() const
Returns true if globalConstants have been computed; false otherwise.
virtual ~CrsMatrixWrap()
Destructor.
const RCP< const Map > & getColMap() const
Returns the Map that describes the column distribution in this matrix. This might be null until fillC...
void resumeFill(const RCP< ParameterList > ¶ms=null)
void replaceCrsMatrix(RCP< CrsMatrix > &M)
Expert only.
bool isFillComplete() const
Returns true if fillComplete() has been called and the matrix is in compute mode. ...
RCP< const Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrix() const
Get the underlying Tpetra matrix.
virtual void setAllToScalar(const Scalar &alpha)
Set all matrix entries equal to scalar.
Teuchos::RCP< Tpetra::BlockCrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > toTpetraBlock(const Teuchos::RCP< Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &A)
RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getTpetra_CrsMatrixNonConst() const
Get the underlying Tpetra matrix.
const RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Concrete implementation of Xpetra::Matrix.
global_size_t getGlobalNumCols() const
Returns the number of global columns in the matrix.
Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > Map
void insertLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Insert matrix entries, using local IDs.
size_t getLocalNumRows() const
Returns the number of matrix rows owned on the calling node.
CombineMode
Xpetra::Combine Mode enumerable type.
void leftScale(const Vector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x)
Left scale matrix using the given vector entries.
bool isLocallyIndexed() const
If matrix indices are in the local range, this function returns true. Otherwise, this function return...
size_t getLocalMaxNumRowEntries() const
Returns the maximum number of entries across all rows/columns on this node.
Xpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > CrsMatrix
virtual void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=ScalarTraits< Scalar >::one(), Scalar beta=ScalarTraits< Scalar >::zero()) const
Computes the sparse matrix-multivector multiplication.
KokkosSparse::CrsMatrix< impl_scalar_type, LocalOrdinal, execution_space, void, typename local_graph_type::size_type > local_matrix_type
The specialization of Kokkos::CrsMatrix that represents the part of the sparse matrix on each MPI pro...
size_t getNumEntriesInGlobalRow(GlobalOrdinal globalRow) const
Returns the current number of entries in the specified global row.
Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > Matrix
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.
Xpetra::CrsMatrixFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > CrsMatrixFactory
void replaceLocalValues(LocalOrdinal localRow, const ArrayView< const LocalOrdinal > &cols, const ArrayView< const Scalar > &vals)
Replace matrix entries, using local IDs.
Xpetra-specific matrix class.
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...
RCP< const CrsGraph< int, GlobalOrdinal, Node > > toXpetra(const Epetra_CrsGraph &g)