Kokkos Node API and Local Linear Algebra Kernels Version of the Day
Classes
Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator > Class Template Reference

Alternate implementation of local sparse matrix-vector multiply and solve routines, for host-based Kokkos Node types. More...

#include <Kokkos_AltSparseOps.hpp>

Inheritance diagram for Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >:
Inheritance graph
[legend]

List of all members.

Classes

struct  bind_ordinal
 Sparse operations type for a different ordinal type. More...
struct  bind_scalar
 Sparse operations type for a different scalar type. More...
struct  graph
 Typedef for local graph class. More...
struct  matrix
 Typedef for local matrix class. More...

Public Types

Typedefs and structs
typedef Scalar scalar_type
 The type of the individual entries of the sparse matrix.
typedef Ordinal ordinal_type
 The type of the (local) indices describing the structure of the sparse matrix.
typedef Node node_type
 The Kokkos Node type.
typedef Allocator allocator_type
 The Allocator type, whose class methods allocate the three arrays.
typedef AltSparseOps< Scalar,
Ordinal, Node, Allocator > 
sparse_ops_type
 The type of this object, the sparse operator object.

Public Member Functions

Implementation of Teuchos::Describable
std::string description () const
 One-line description of this instance.
void describe (Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const
 Write a possibly more verbose description of this instance to out.
Teuchos::RCP
< Teuchos::SerialDenseMatrix
< int, scalar_type > > 
asDenseMatrix () const
 Convert to dense matrix and return.
Accessor routines
Teuchos::RCP< Node > getNode () const
 The Kokkos Node with which this object was instantiated.
Computational methods
template<class DomainScalar , class RangeScalar >
void multiply (Teuchos::ETransp trans, RangeScalar alpha, const MultiVector< DomainScalar, Node > &X, MultiVector< RangeScalar, Node > &Y) const
 Y := alpha * Op(A) * X.
template<class DomainScalar , class RangeScalar >
void multiply (Teuchos::ETransp trans, RangeScalar alpha, const MultiVector< DomainScalar, Node > &X, RangeScalar beta, MultiVector< RangeScalar, Node > &Y) const
 Y := beta * Y + alpha * Op(A) * X.
template<class DomainScalar , class RangeScalar >
void solve (Teuchos::ETransp trans, const MultiVector< DomainScalar, Node > &Y, MultiVector< RangeScalar, Node > &X) const
 Solve Y = Op(A) X for X, where we assume A is triangular.

Constructors and destructor

 AltSparseOps (const Teuchos::RCP< Node > &node)
 Constructor, with default parameters.
 AltSparseOps (const Teuchos::RCP< Node > &node, Teuchos::ParameterList &plist)
 Constructor, with custom parameters.
 ~AltSparseOps ()
 Destructor.
static Teuchos::RCP< const
Teuchos::ParameterList
getDefaultParameters ()
 Get a default ParameterList.

Initialization of graph and matrix

void setGraphAndMatrix (const Teuchos::RCP< const AltCrsGraph< Ordinal, Node > > &graph, const Teuchos::RCP< const AltCrsMatrix< Scalar, Ordinal, Node > > &matrix)
 Initialize sparse operations with a graph and matrix.
static Teuchos::ArrayRCP< size_t > allocRowPtrs (const Teuchos::RCP< Node > &node, const ArrayView< const size_t > &numEntriesPerRow)
 Allocate and initialize the storage for the row pointers.
static Teuchos::ArrayRCP< size_t > copyRowPtrs (const Teuchos::RCP< Node > &node, const Teuchos::ArrayView< const size_t > &rowPtrs)
 Copy the storage for the row pointers.
template<class T >
static Teuchos::ArrayRCP< T > allocStorage (const Teuchos::RCP< Node > &node, const Teuchos::ArrayView< const size_t > &rowPtrs)
 Allocate and initialize the storage for a sparse graph or matrix.
template<class T >
static Teuchos::ArrayRCP< T > copyStorage (const Teuchos::RCP< Node > &node, const Teuchos::ArrayView< const size_t > &rowPtrs, const Teuchos::ArrayView< const T > &inputVals)
 Copy the storage for a sparse graph or matrix.
static void finalizeGraph (Teuchos::EUplo uplo, Teuchos::EDiag diag, AltCrsGraph< Ordinal, Node > &graph, const Teuchos::RCP< Teuchos::ParameterList > &params)
 Finalize the graph.
static void finalizeMatrix (const AltCrsGraph< Ordinal, Node > &graph, AltCrsMatrix< Scalar, Ordinal, Node > &matrix, const Teuchos::RCP< Teuchos::ParameterList > &params)
 Finalize the matrix of an already-finalized graph.
static void finalizeGraphAndMatrix (Teuchos::EUplo uplo, Teuchos::EDiag diag, AltCrsGraph< Ordinal, Node > &graph, AltCrsMatrix< Scalar, Ordinal, Node > &matrix, const Teuchos::RCP< Teuchos::ParameterList > &params)
 Finalize a graph and a matrix.

Detailed Description

template<class Scalar, class Ordinal, class Node, class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
class Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >

Alternate implementation of local sparse matrix-vector multiply and solve routines, for host-based Kokkos Node types.

Template Parameters:
ScalarThe type of entries of the sparse matrix.
OrdinalThe type of (local) indices of the sparse matrix.
NodeThe Kokkos Node type. This is used only for first-touch allocation; see discussion below.
AllocatorClass that defines static methods for allocating the various arrays used by the compressed sparse row format. This is where first-touch allocation can be implemented, for example. We use first-touch allocation by default; if you don't want this, you should use details::AltSparseOpsDefaultAllocator<Ordinal, Node> as the Allocator type.

This class is called AltSparseOps ("alternate sparse operations") because the default local sparse operations class on host-based Kokkos Nodes is DefaultHostSparseOps. DefaultHostSparseOps relies on the Kokkos Node API for (intranode) parallelism. AltSparseOps provides an alternative implementation which does not rely on the Kokkos Node API for parallelizing the sparse kernels. In case the Kokkos Node API performs poorly on your platform (for example, if your C++ compiler does not inline well), you can always use AltSparseOps to get good performance. AltSparseOps will parallelize its kernels with OpenMP if you specify Node=OpenMPNode; otherwise, it will use sequential kernels.

Note that, depending on the Allocator template parameter, AltSparseOps may use the Kokkos Node API to do first-touch allocation in parallel of the sparse graph and matrix data structures. It would be best in that case to use Node=OpenMPNode, so that the first-touch allocation most closely matches the parallelization scheme. You may control OpenMP's parallelization scheme at run time by using environment variables; AltSparseOps will respect this.

For maximum compatibility with other implementations of local sparse ops, given your Scalar and Ordinal types, you should always access the local sparse ops type via the following typedef:

 typedef typename AltSparseOps<Scalar, Ordinal, Node, Allocator>::bind_scalar<Scalar>::other_type::typename bind_ordinal<Ordinal>::other_type sparse_ops_type;

The resulting sparse_ops_type typedef will always be a functioning implementation of local sparse ops, whether or not the "original" implementation of local sparse ops (in this case, AltSparseOps) supports your given combination of Scalar and Ordinal types.

Definition at line 935 of file Kokkos_AltSparseOps.hpp.


Member Typedef Documentation

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
typedef Scalar Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::scalar_type

The type of the individual entries of the sparse matrix.

Definition at line 941 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
typedef Ordinal Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::ordinal_type

The type of the (local) indices describing the structure of the sparse matrix.

Definition at line 943 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
typedef Node Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::node_type

The Kokkos Node type.

Definition at line 945 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
typedef Allocator Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::allocator_type

The Allocator type, whose class methods allocate the three arrays.

Definition at line 947 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
typedef AltSparseOps<Scalar, Ordinal, Node, Allocator> Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::sparse_ops_type

The type of this object, the sparse operator object.

Definition at line 949 of file Kokkos_AltSparseOps.hpp.


Constructor & Destructor Documentation

template<class Scalar , class Ordinal , class Node , class Allocator >
Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::AltSparseOps ( const Teuchos::RCP< Node > &  node)

Constructor, with default parameters.

We syntactically forbid setting parameters after construction, since setting parameters after calling setGraphAndMatrix() would require reorganizing the already optimized sparse matrix storage. If you want to set nondefault values of parameters, you must use the constructor that takes a ParameterList.

Parameters:
node[in/out] Kokkos Node instance.

Definition at line 1551 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::AltSparseOps ( const Teuchos::RCP< Node > &  node,
Teuchos::ParameterList plist 
)

Constructor, with custom parameters.

Both this constructor and finalizeGraphAndMatrix() accept a ParameterList. However, those sets of parameters are different. The constructor's parameters concern the algorithm, and the parameters for finalizeGraphAndMatrix() concern the data structure. It's possible to use different algorithms with the same data structure.

Parameters:
node[in/out] Kokkos Node instance.
params[in/out] Parameters for the solve. We fill in the given ParameterList with its default values, but we don't keep it around. (This saves a bit of memory.)

Definition at line 1572 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::~AltSparseOps ( )

Destructor.

Definition at line 1607 of file Kokkos_AltSparseOps.hpp.


Member Function Documentation

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
static Teuchos::RCP<const Teuchos::ParameterList> Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::getDefaultParameters ( ) [inline, static]

Get a default ParameterList.

The returned ParameterList has all accepted parameters, their default values, documentation, and validators (if applicable).

This is a class (static) method so that you can get the default ParameterList (with built-in documentation) before constructing a AltSparseOps instance.

Definition at line 1050 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
std::string Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::description ( ) const [inline, virtual]

One-line description of this instance.

Reimplemented from Teuchos::Describable.

Definition at line 1067 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::describe ( Teuchos::FancyOStream out,
const Teuchos::EVerbosityLevel  verbLevel = Teuchos::Describable::verbLevel_default 
) const [inline, virtual]

Write a possibly more verbose description of this instance to out.

Reimplemented from Teuchos::Describable.

Definition at line 1080 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator = details::AltSparseOpsFirstTouchAllocator<Ordinal, Node>>
Teuchos::RCP<Teuchos::SerialDenseMatrix<int, scalar_type> > Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::asDenseMatrix ( ) const [inline]

Convert to dense matrix and return.

Warning:
This method is for debugging only. It uses a lot of memory. Users should never call this method. Do not rely on this method continuing to exist in future releases.
SerialDenseMatrix currently requires Ordinal=int indices for BLAS and LAPACK compatibility. We make no attempt to check whether Ordinal -> int conversions overflow.

Definition at line 1174 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
RCP< Node > Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::getNode ( ) const

The Kokkos Node with which this object was instantiated.

Definition at line 1675 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
Teuchos::ArrayRCP< size_t > Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::allocRowPtrs ( const Teuchos::RCP< Node > &  node,
const ArrayView< const size_t > &  numEntriesPerRow 
) [static]

Allocate and initialize the storage for the row pointers.

Parameters:
node[in/out] Kokkos Node instance.
numEntriesPerRow[in] numEntriesPerRow[i] is the number of entries in row i, for all rows of the local sparse matrix.

Definition at line 2332 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
Teuchos::ArrayRCP< size_t > Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::copyRowPtrs ( const Teuchos::RCP< Node > &  node,
const Teuchos::ArrayView< const size_t > &  rowPtrs 
) [static]

Copy the storage for the row pointers.

Parameters:
node[in/out] Kokkos Node instance.
rowPtrs[in] The array of row offsets to copy.

You might like to call this method if the Allocator promises a special allocation method (like first-touch allocation), but the input array was not allocated by the Allocator.

Definition at line 2341 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
template<class T >
Teuchos::ArrayRCP< T > Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::allocStorage ( const Teuchos::RCP< Node > &  node,
const Teuchos::ArrayView< const size_t > &  rowPtrs 
) [static]

Allocate and initialize the storage for a sparse graph or matrix.

Parameters:
node[in/out] Kokkos Node instance.
rowPtrs[in] The array of row offsets; the 'ptr' array in the compressed sparse row storage format. rowPtrs.size() is one plus the number of rows in the local sparse matrix.

Definition at line 2351 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
template<class T >
Teuchos::ArrayRCP< T > Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::copyStorage ( const Teuchos::RCP< Node > &  node,
const Teuchos::ArrayView< const size_t > &  rowPtrs,
const Teuchos::ArrayView< const T > &  inputVals 
) [static]

Copy the storage for a sparse graph or matrix.

Parameters:
node[in/out] Kokkos Node instance.
rowPtrs[in] The array of row offsets; the 'ptr' array in the compressed sparse row storage format. rowPtrs.size() is one plus the number of rows in the local sparse matrix.
inputVals[in] The array of input values (or column indices) to copy.

You might like to call this method if the Allocator promises a special allocation method (like first-touch allocation), but inputVals was not allocated by the Allocator.

Definition at line 2361 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::finalizeGraph ( Teuchos::EUplo  uplo,
Teuchos::EDiag  diag,
AltCrsGraph< Ordinal, Node > &  graph,
const Teuchos::RCP< Teuchos::ParameterList > &  params 
) [static]

Finalize the graph.

Definition at line 1500 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::finalizeMatrix ( const AltCrsGraph< Ordinal, Node > &  graph,
AltCrsMatrix< Scalar, Ordinal, Node > &  matrix,
const Teuchos::RCP< Teuchos::ParameterList > &  params 
) [static]

Finalize the matrix of an already-finalized graph.

Definition at line 1515 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::finalizeGraphAndMatrix ( Teuchos::EUplo  uplo,
Teuchos::EDiag  diag,
AltCrsGraph< Ordinal, Node > &  graph,
AltCrsMatrix< Scalar, Ordinal, Node > &  matrix,
const Teuchos::RCP< Teuchos::ParameterList > &  params 
) [static]

Finalize a graph and a matrix.

Both the constructor and this method accept a ParameterList. However, those sets of parameters are different. The constructor's parameters concern the algorithm, and the parameters for this method concern the data structure. It's possible to use different algorithms with the same data structure.

Definition at line 1529 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::setGraphAndMatrix ( const Teuchos::RCP< const AltCrsGraph< Ordinal, Node > > &  graph,
const Teuchos::RCP< const AltCrsMatrix< Scalar, Ordinal, Node > > &  matrix 
)

Initialize sparse operations with a graph and matrix.

Definition at line 1682 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
template<class DomainScalar , class RangeScalar >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::multiply ( Teuchos::ETransp  trans,
RangeScalar  alpha,
const MultiVector< DomainScalar, Node > &  X,
MultiVector< RangeScalar, Node > &  Y 
) const

Y := alpha * Op(A) * X.

Apply the local sparse matrix A (or its transpose or conjugate transpose) to a multivector X, overwriting Y with the result. Op(A) means A, the transpose of A, or the conjugate transpose of A, depending on the trans argument.

Template Parameters:
DomainScalarThe type of entries in the input multivector X. This may differ from the type of entries in A or in Y.
RangeScalarThe type of entries in the output multivector Y. This may differ from the type of entries in A or in X.
Parameters:
trans[in] Whether to apply the matrix, its transpose, or its conjugate transpose (if applicable).
alpha[in] Scalar constant $\alpha$ by which to multiply the result of the sparse matrix-(multi)vector multiply.
X[in] Input multivector.
Y[out] Result multivector. Contents will be overwritten.

Definition at line 1952 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
template<class DomainScalar , class RangeScalar >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::multiply ( Teuchos::ETransp  trans,
RangeScalar  alpha,
const MultiVector< DomainScalar, Node > &  X,
RangeScalar  beta,
MultiVector< RangeScalar, Node > &  Y 
) const

Y := beta * Y + alpha * Op(A) * X.

Apply the local sparse matrix A (or its transpose or conjugate transpose) to a multivector X, accumulating the result into Y. Op(A) means A, the transpose of A, or the conjugate transpose of A, depending on the trans argument.

Template Parameters:
DomainScalarThe type of entries in the input multivector X. This may differ from the type of entries in A or in Y.
RangeScalarThe type of entries in the output multivector Y. This may differ from the type of entries in A or in X.
Parameters:
trans[in] Whether to apply the matrix, its transpose, or its conjugate transpose (if applicable).
alpha[in] Scalar constant $\alpha$ by which to multiply the result of the sparse matrix-(multi)vector multiply.
X[in] Input multivector.
beta[in] Scalar constant $\beta$ by which to multiply Y when summing with the result of the sparse matrix-(multi)vector multiply.
Y[in/out] Result multivector.

Definition at line 1967 of file Kokkos_AltSparseOps.hpp.

template<class Scalar , class Ordinal , class Node , class Allocator >
template<class DomainScalar , class RangeScalar >
void Kokkos::AltSparseOps< Scalar, Ordinal, Node, Allocator >::solve ( Teuchos::ETransp  trans,
const MultiVector< DomainScalar, Node > &  Y,
MultiVector< RangeScalar, Node > &  X 
) const

Solve Y = Op(A) X for X, where we assume A is triangular.

Solve the (upper or lower) triangular system Y = Op(A) X. Op(A) means A, the transpose of A, or the conjugate transpose of A, depending on the trans argument.

Template Parameters:
DomainScalarThe type of entries in the input multivector X. This may differ from the type of entries in A or in Y.
RangeScalarThe type of entries in the output multivector Y. This may differ from the type of entries in A or in X.
Parameters:
trans[in] Whether to solve with the matrix, its transpose, or its conjugate transpose (if applicable).
Y[in] Input multivector.
X[out] Result multivector.

Definition at line 1768 of file Kokkos_AltSparseOps.hpp.


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