10#ifndef TPETRA_CRSMATRIXMULTIPLYOP_HPP
11#define TPETRA_CRSMATRIXMULTIPLYOP_HPP
19#include "Tpetra_CrsMatrix.hpp"
23#include "Tpetra_LocalCrsMatrixOperator.hpp"
63template <
class Scalar,
77 using local_matrix_device_type =
78 typename crs_matrix_type::local_matrix_device_type;
91 A->getLocalMatrixDevice())) {}
105 Teuchos::ETransp
mode = Teuchos::NO_TRANS,
106 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
107 Scalar beta = Teuchos::ScalarTraits<Scalar>::zero())
const override {
109 Teuchos::typeName(*
this) <<
"::apply(): underlying matrix is not fill-complete.");
111 Teuchos::typeName(*
this) <<
"::apply(X,Y): X and Y must have the same number of vectors.");
113 Teuchos::typeName(*
this) <<
"::apply() does not currently support transposed multiplications for complex scalar types.");
114 if (
mode == Teuchos::NO_TRANS) {
132 return matrix_->getDomainMap();
146 const Teuchos::RCP<const crs_matrix_type>
matrix_;
163 mutable Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
importMV_;
177 mutable Teuchos::RCP<MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
exportMV_;
184 Teuchos::ETransp
mode,
192 using STS = Teuchos::ScalarTraits<Scalar>;
215 X = Teuchos::rcp(
new MV(
X_in, Teuchos::Copy));
218 X = Teuchos::rcpFromRef(
X_in);
245 auto X_lcl =
X->getLocalViewDevice(Access::ReadOnly);
255 Y_in.putScalar(STS::zero());
264 if (!
Y_in.isConstantStride() ||
X.getRawPtr() == &
Y_in) {
269 Y_lcl =
Y.getLocalViewDevice(Access::OverwriteAll);
271 Y_lcl =
Y.getLocalViewDevice(Access::ReadWrite);
278 Y_lcl =
Y_in.getLocalViewDevice(Access::OverwriteAll);
280 Y_lcl =
Y_in.getLocalViewDevice(Access::ReadWrite);
297 using Teuchos::NO_TRANS;
300 using Teuchos::rcp_const_cast;
301 using Teuchos::rcpFromRef;
305 typedef Teuchos::ScalarTraits<Scalar> STS;
308 if (
alpha == STS::zero()) {
309 if (
beta == STS::zero()) {
310 Y_in.putScalar(STS::zero());
311 }
else if (
beta != STS::one()) {
337 (!
Y_in.isDistributed() &&
matrix_->getComm()->getSize() != 1);
355 if (!
X_in.isConstantStride()) {
371 ProfilingRegion
regionImport(
"Tpetra::CrsMatrixMultiplyOp::apply: Import");
398 auto Y_lcl =
Y_rowMap->getLocalViewDevice(Access::OverwriteAll);
403 ProfilingRegion
regionExport(
"Tpetra::CrsMatrixMultiplyOp::apply: Export");
410 Y_in.putScalar(STS::zero());
438 if (
beta != STS::zero()) {
452 Y_lcl =
Y_in.getLocalViewDevice(Access::OverwriteAll);
454 Y_lcl =
Y_in.getLocalViewDevice(Access::ReadWrite);
465 ProfilingRegion
regionReduce(
"Tpetra::CrsMatrixMultiplyOp::apply: Reduce Y");
492 const bool force =
false)
const {
553 getRowMapMultiVector(
const MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& Y_rangeMap,
554 const bool force =
false)
const {
558 typedef Export<LocalOrdinal, GlobalOrdinal, Node> export_type;
560 const size_t numVecs = Y_rangeMap.getNumVectors();
561 RCP<const export_type> exporter =
matrix_->getGraph()->getExporter();
562 RCP<const map_type> rowMap =
matrix_->getRowMap();
574 if (!exporter.is_null() || force) {
576 Y_rowMap = rcp(
new MV(rowMap, numVecs));
593template <
class OpScalar,
599 CrsMatrixMultiplyOp<OpScalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node> >
605 return Teuchos::rcp(
new op_type(
A));
Forward declaration of Tpetra::CrsMatrixMultiplyOp.
Declaration of Tpetra::Details::Behavior, a class that describes Tpetra's behavior.
Declaration of Tpetra::Details::Profiling, a scope guard for Kokkos Profiling.
Stand-alone utility functions and macros.
A class for wrapping a CrsMatrix multiply in a Operator.
bool hasTransposeApply() const override
Whether this Operator's apply() method can apply the transpose or conjugate transpose.
void applyNonTranspose(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X_in, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y_in, Scalar alpha, Scalar beta) const
Apply the matrix (not its transpose) to X_in, producing Y_in.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > exportMV_
Row Map MultiVector used in apply().
void apply(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::zero()) const override
Compute Y = beta*Y + alpha*Op(A)*X, where Op(A) is either A, , or .
Teuchos::RCP< const map_type > getRangeMap() const override
The range Map of this Operator.
void applyTranspose(const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X_in, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y_in, Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
Apply the transpose or conjugate transpose of the matrix to X_in, producing Y_in.
CrsMatrixMultiplyOp(const Teuchos::RCP< const crs_matrix_type > &A)
Constructor.
~CrsMatrixMultiplyOp() override=default
Destructor (virtual for memory safety of derived classes).
Teuchos::RCP< CrsMatrixMultiplyOp< OpScalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node > > createCrsMatrixMultiplyOp(const Teuchos::RCP< const CrsMatrix< MatScalar, LocalOrdinal, GlobalOrdinal, Node > > &A)
Non-member function to create a CrsMatrixMultiplyOp.
const Teuchos::RCP< const crs_matrix_type > matrix_
The underlying CrsMatrix object.
Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > importMV_
Column Map MultiVector used in apply().
LocalCrsMatrixOperator< Scalar, MatScalar, typename crs_matrix_type::device_type > localMultiply_
Implementation of local sparse matrix-vector multiply.
Teuchos::RCP< const map_type > getDomainMap() const override
The domain Map of this Operator.
Struct that holds views of the contents of a CrsMatrix.
One or more distributed dense vectors.
Abstract interface for operators (e.g., matrices and preconditioners).
Namespace Tpetra contains the class and methods constituting the Tpetra library.
void deep_copy(MultiVector< DS, DL, DG, DN > &dst, const MultiVector< SS, SL, SG, SN > &src)
Copy the contents of the MultiVector src into dst.
@ ADD_ASSIGN
Accumulate new values into existing values (may not be supported in all classes)
@ INSERT
Insert new values that don't currently exist.