Tpetra Matrix/Vector Services Version of the Day
Protected Member Functions | Protected Attributes | Related Functions
Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > Class Template Reference

A class for wrapping a CrsMatrix multiply in a Operator. More...

#include <Tpetra_CrsMatrixMultiplyOp_decl.hpp>

Inheritance diagram for Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >:
Inheritance graph
[legend]

List of all members.

Public Types

Typedefs that give access to the template parameters.
typedef Scalar scalar_type
 The type of the entries of the input and output multivectors.
typedef LocalOrdinal local_ordinal_type
 The local index type.
typedef GlobalOrdinal global_ordinal_type
 The global index type.
typedef Node node_type
 The Kokkos Node type.

Public Member Functions

Constructor and destructor
 CrsMatrixMultiplyOp (const Teuchos::RCP< const CrsMatrix< MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > &A)
 Constructor.
virtual ~CrsMatrixMultiplyOp ()
 Destructor.
Methods implementing Operator
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
 Compute Y = beta*Y + alpha*Op(A)*X, where Op(A) is either A, $A^T$, or $A^H$.
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 $B = A X$.
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
 Version of gaussSeidel(), with fewer requirements on X.
bool hasTransposeApply () const
 Whether this Operator's apply() method can apply the transpose or conjugate transpose.
Teuchos::RCP< const Map
< LocalOrdinal, GlobalOrdinal,
Node > > 
getDomainMap () const
 The domain Map of this Operator.
Teuchos::RCP< const Map
< LocalOrdinal, GlobalOrdinal,
Node > > 
getRangeMap () const
 The range Map of this Operator.

Protected Member Functions

void applyTranspose (const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode, Scalar alpha, Scalar beta) const
 Apply the transpose or conjugate transpose of the matrix to X, producing Y.
void applyNonTranspose (const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Scalar alpha, Scalar beta) const
 Apply the matrix (not its transpose) to X, producing Y.

Protected Attributes

const Teuchos::RCP< const
CrsMatrix< MatScalar,
LocalOrdinal, GlobalOrdinal,
Node, LocalMatOps > > 
matrix_
 The underlying CrsMatrix object.
Teuchos::RCP< MultiVector
< Scalar, LocalOrdinal,
GlobalOrdinal, Node > > 
importMV_
 Column Map MultiVector used in apply().
Teuchos::RCP< MultiVector
< Scalar, LocalOrdinal,
GlobalOrdinal, Node > > 
exportMV_
 Row Map MultiVector used in apply().

Related Functions

(Note that these are not member functions.)

template<class Scalar , class MatScalar , class LocalOrdinal , class GlobalOrdinal , class Node , class LocalMatOps >
Teuchos::RCP
< CrsMatrixMultiplyOp< Scalar,
MatScalar, LocalOrdinal,
GlobalOrdinal, Node,
LocalMatOps > > 
createCrsMatrixMultiplyOp (const Teuchos::RCP< const CrsMatrix< MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > &A)
 Non-member function to create a CrsMatrixMultiplyOp.

Detailed Description

template<class Scalar, class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
class Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >

A class for wrapping a CrsMatrix multiply in a Operator.

Note:
Most Tpetra users do not need to use this class. It will be useful to Tpetra users who want to do mixed-precision sparse matrix-vector multiply, where the sparse matrix's entries have a different precision than that of the input and output vectors. If your sparse matrix and vectors have the same type of entries, then you don't need to use this class.

This class makes a CrsMatrix<MatScalar, ...> "look like" an Operator<Scalar, ...>, where MatScalar and Scalar may be different types. It does so by working around a limitation of C++, namely that template methods of a class can't be virtual.

Here is a detailed description of how the language issue relates to CrsMatrix. If you call the apply method of CrsMatrix, you will always get the version that takes a MultiVector<Scalar, ...> input and produces a MultiVector<Scalar, ...> output. CrsMatrix actually implements a a templated sparse matrix-vector multiply operation (its localMultiply method). It is templated on the scalar types of its input and output multivectors (DomainScalar resp. RangeScalar). However, Operator can't access this templated mat-vec method. This is because Operator::apply is virtual, and therefore cannot have a template parameter for the Scalar type of the MultiVector input and output.

Users who want to access the templated sparse mat-vec in CrsMatrix through the Operator interface may wrap the CrsMatrix in an instance of this class. This class implements an Operator that takes MultiVector<Scalar, ...> input and output, but the CrsMatrix may contain any desired type MatScalar. The type MatScalar may differ from the Scalar type of the MultiVector input and output. That works around the "no virtual template methods" issue for input and output multivectors of the same type.

Interestingly enough, CrsMatrix implements its apply method using an instance of this class with Scalar == MatScalar. CrsMatrix does not actually contain an implementation of "nonlocal" (distributed over multiple MPI processes) mat-vec; its apply defers the nonlocal part to this class' apply() method. The same is true for the gaussSeidel() method.

Template Parameters:
ScalarThe type of the entries of the input and output MultiVector of the apply() method. Same as the first template parameter of Operator.
MatScalarThe type of the entries of the CrsMatrix; the first template parameter of CrsMatrix.
LocalOrdinalThe second template parameter of CrsMatrix and Operator.
GlobalOrdinalThe third template parameter of CrsMatrix and Operator.
NodeThe fourth template parameter of CrsMatrix and Operator.
LocalMatOpsThe fifth template parameter of CrsMatrix. (Operator only takes four template parameters.)

Definition at line 136 of file Tpetra_CrsMatrixMultiplyOp_decl.hpp.


Member Typedef Documentation

template<class Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
typedef Scalar Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >::scalar_type [inherited]
template<class Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
typedef LocalOrdinal Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >::local_ordinal_type [inherited]
template<class Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
typedef GlobalOrdinal Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >::global_ordinal_type [inherited]
template<class Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType>
typedef Node Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >::node_type [inherited]

Constructor & Destructor Documentation

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::CrsMatrixMultiplyOp ( const Teuchos::RCP< const CrsMatrix< MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > &  A)

Constructor.

Parameters:
A[in] The CrsMatrix to wrap as an Operator<Scalar, ...>.
template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
virtual Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::~CrsMatrixMultiplyOp ( ) [virtual]

Destructor.


Member Function Documentation

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
void Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::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 [virtual]

Compute Y = beta*Y + alpha*Op(A)*X, where Op(A) is either A, $A^T$, or $A^H$.

This method calls the underlying CrsMatrix object's localMultiply<Scalar,Scalar>() method.

Implements Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >.

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
void Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::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 $B = A X$.

"Hybrid" means Jacobi for interprocess communication, but Successive Over-Relaxation (SOR) or Gauss-Seidel for intraprocess computation. Gauss-Seidel is a special case of SOR, where the damping factor is one.

The Forward or Backward sweep directions have their usual SOR meaning within the process. Interprocess communication occurs once before the sweep, as it would in Jacobi.

The Symmetric sweep direction means first Forward, then Backward. Before each sweep is an interprocess communication, as in Jacobi. Thus, Symmetric results in two interprocess communication steps.

Parameters:
B[in] Right-hand side(s), in the range Map of the matrix.
X[in/out] On input: initial guess(es). On output: result multivector(s). This must be a domain Map view of a column Map multivector.
D[in] Inverse of diagonal entries of the matrix A, in the row Map of the matrix.
dampingFactor[in] SOR damping factor. A damping factor of one results in Gauss-Seidel.
direction[in] Sweep direction: Forward, Backward, or Symmetric.
numSweeps[in] Number of sweeps. We count each Symmetric sweep (including both its Forward and its Backward sweep) as one.
Precondition:
Domain, range, and row Maps of the sparse matrix are all the same. (The domain and range Maps must be the same because this kernel overwrites its input. The row Map must be the same because the kernel uses the same local indices for the rows of the sparse matrix, and for the rows of the input / output multivector.)
No other argument aliases X.
template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
void Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::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

Version of gaussSeidel(), with fewer requirements on X.

This method is just like gaussSeidel(), except that X need only be in the domain Map. This method does not require that X be a domain Map view of a column Map multivector. As a result, this method must copy X into a domain Map multivector before operating on it.

Parameters:
X[in/out] On input: initial guess(es). On output: result multivector(s).
B[in] Right-hand side(s), in the range Map.
D[in] Inverse of diagonal entries of the matrix, in the row Map.
dampingFactor[in] SOR damping factor. A damping factor of one results in Gauss-Seidel.
direction[in] Sweep direction: Forward, Backward, or Symmetric.
numSweeps[in] Number of sweeps. We count each Symmetric sweep (including both its Forward and its Backward sweep) as one.
Precondition:
Domain, range, and row Maps of the sparse matrix are all the same.
No other argument aliases X.
template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
bool Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::hasTransposeApply ( ) const [virtual]

Whether this Operator's apply() method can apply the transpose or conjugate transpose.

This is always true, since it is true for the CrsMatrix that this object wraps.

Reimplemented from Tpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node >.

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::getDomainMap ( ) const [virtual]
template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::getRangeMap ( ) const [virtual]
template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
void Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::applyTranspose ( const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &  X,
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &  Y,
Teuchos::ETransp  mode,
Scalar  alpha,
Scalar  beta 
) const [protected]

Apply the transpose or conjugate transpose of the matrix to X, producing Y.

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
void Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::applyNonTranspose ( const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &  X,
MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &  Y,
Scalar  alpha,
Scalar  beta 
) const [protected]

Apply the matrix (not its transpose) to X, producing Y.


Friends And Related Function Documentation

template<class Scalar , class MatScalar , class LocalOrdinal , class GlobalOrdinal , class Node , class LocalMatOps >
Teuchos::RCP< CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > createCrsMatrixMultiplyOp ( const Teuchos::RCP< const CrsMatrix< MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps > > &  A) [related]

Non-member function to create a CrsMatrixMultiplyOp.

The function has the same template parameters of CrsMatrixMultiplyOp.

Parameters:
A[in] The CrsMatrix instance to wrap in an CrsMatrixMultiplyOp.
Returns:
The CrsMatrixMultiplyOp wrapper for the given CrsMatrix.

Member Data Documentation

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
const Teuchos::RCP<const CrsMatrix<MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> > Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::matrix_ [protected]

The underlying CrsMatrix object.

Definition at line 266 of file Tpetra_CrsMatrixMultiplyOp_decl.hpp.

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::importMV_ [mutable, protected]

Column Map MultiVector used in apply().

This is a column Map MultiVector. It is used as the target of the forward mode Import operation (if necessary) in applyNonTranspose(), and the source of the reverse mode Export operation (if necessary) in applyTranspose(). Both of these methods create this MultiVector on demand if needed, and reuse it (if possible) for subsequent calls.

This is declared mutable because the apply() method is const, yet the method needs to cache the MultiVector for later use.

Definition at line 280 of file Tpetra_CrsMatrixMultiplyOp_decl.hpp.

template<class Scalar , class MatScalar = Scalar, class LocalOrdinal = int, class GlobalOrdinal = LocalOrdinal, class Node = KokkosClassic::DefaultNode::DefaultNodeType, class LocalMatOps = typename KokkosClassic::DefaultKernels<MatScalar,LocalOrdinal,Node>::SparseOps>
Teuchos::RCP<MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > Tpetra::CrsMatrixMultiplyOp< Scalar, MatScalar, LocalOrdinal, GlobalOrdinal, Node, LocalMatOps >::exportMV_ [mutable, protected]

Row Map MultiVector used in apply().

This is a row Map MultiVector. It is uses as the source of the forward mode Export operation (if necessary) in applyNonTranspose(), and the target of the reverse mode Import operation (if necessary) in applyTranspose(). Both of these methods create this MultiVector on demand if needed, and reuse it (if possible) for subsequent calls.

This is declared mutable because the apply() method is const, yet the method needs to cache the MultiVector for later use.

Definition at line 294 of file Tpetra_CrsMatrixMultiplyOp_decl.hpp.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines