Skip to content

SPARSE 2::spmv_struct

Luc Berger edited this page Sep 19, 2019 · 15 revisions

KokkosSparse::Experimental::spmv_struct()

Header File: KokkosSparse_spmv.hpp

Usage: KokkosSparse::Experimental::spmv_struct(mode,stencil,structure,alpha,A,x,beta,y);

Computes the product for matrix A and vector x(:) or each x(:,j) the absolute value, and assigns it to y(:) or y(:,j) respectively using a structured algorithm that leverages the knowledge of the mesh parameters stored in structure and the knowledge of the stencil type specified in stencil.

Interface

template <class AlphaType, class AMatrix, class XVector, class BetaType, class YVector>
void
spmv_struct(const char mode[],
            const int stencil_type,
            const Kokkos::View<typename AMatrix::non_const_ordinal_type*, Kokkos::HostSpace> structure,
            const AlphaType& alpha,
            const AMatrix& A,
            const XVector& x,
            const BetaType& beta,
            const YVector& y);

Parameters:

  • InputMode: "N" for no transpose, "T" for transpose, or "C" for conjugate transpose.
  • InputStencilType: "1" for first order finite difference stencil, "2" for first order finite element stencil
  • InputStructure: A Kokkos::View of size n where n is the number of dimensions in the mesh, each entry of the view store the number of node in that direction.
  • InputScalarType: Scalar multiplier for InputMatrix
  • InputMatrix: A KokkosSparse::CrsMatrix
  • InputVector: A rank-1 or rank-2 Kokkos::View with non-const data type.
  • InputScalarType Scalar multiplier for InputVector
  • Input/OutputVector: A rank-1 or rank-2 Kokkos::View with non-const data type.

Requirements:

  • OutputVector::value_type == OutputVector::non_const_value_type
  • A.rank == 2
  • y.rank == x.rank
  • y.rank == 1 or y.rank == 2
  • y.extent(0) == x.extent(0)
  • y.extent(1) == x.extent(1)

Example code

#include<Kokkos_Core.hpp>
#include<KokkosSparse_spmv.hpp>

int main(int argc, char* argv[]) {
   Kokkos::initialize();

   int N = atoi(argv[1]);

   using matrix_type = KokkosSparse::CrsMatrix<Scalar,int,Kokkos::DefaultExecutionSpace,void,int>;

   matrix_type A("A",N,N) = build_matrix();  // Some rountine that generates a valid structured crs matrix
   Kokkos::View<double*> x("X",N);
   Kokkos::View<double*> y("Y",N);
   Kokkos::deep_copy(A,1.0);
   Kokkos::deep_copy(x,-1.0);
   const double alpha = 1.0;
   const double beta  = 1.5;

   const int stencil_type = 1;

   KokkosSparse::Experimental::spmv_struct("N", stencil_type, structure,
                                           alpha, A, x, beta, y);

   Kokkos::finalize();
}
Clone this wiki locally