Rate This Document
Findability
Accuracy
Completeness
Readability

kml_sparse_?csrmv

Compute the product of a matrix and a vector. The matrix is a sparse matrix stored in the CSR format.

y = alpha * A * x + beta * y, y = alpha * AT * x + beta * y, or y = alpha * AH * x + beta * y

alpha and beta are scaling coefficients, x and y are vectors, and A is a sparse vector in the CSR format.

Interface Definition

C interface:

kml_sparse_status_t kml_sparse_scsrmv(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT k, const float alpha, const char *matdescra, const float *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const float *x, const float beta, float *y);

kml_sparse_status_t kml_sparse_dcsrmv(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT k, const double alpha, const char *matdescra, const double *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const double *x, const double beta, double *y);

kml_sparse_status_t kml_sparse_ccsrmv(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT k, const KML_Complex8 alpha, const char *matdescra, const KML_Complex8 *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const KML_Complex8 *x, const KML_Complex8 beta, KML_Complex8 *y);

kml_sparse_status_t kml_sparse_zcsrmv(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT k, const KML_Complex16 alpha, const char *matdescra, const KML_Complex16 *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const KML_Complex16 *x, const KML_Complex16 beta, KML_Complex16 *y);

Fortran interface:

RES = KML_SPARSE_SCSRMV(OPT, M, K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, BETA, Y);

RES = KML_SPARSE_DCSRMV(OPT, M, K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, BETA, Y);

RES = KML_SPARSE_CCSRMV(OPT, M, K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, BETA, Y);

RES = KML_SPARSE_ZCSRMV(OPT, M, K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, BETA, Y);

Parameters

Parameter

Type

Description

Input/Output

opt

Enumeration type kml_sparse_operation_t

Operation on matrix A.

  • If opt = KML_SPARSE_OPERATION_NON_TRANSPOSE, then y = alpha * A * x + beta * y.
  • If opt = KML_SPARSE_OPERATION_TRANSPOSE, then y = alpha * AT * x + beta * y.
  • If opt = KML_SPARSE_OPERATION_CONJUGATE_TRANSPOSE, then y = alpha * AH * x + beta * y.

Input

m

Integer

Number of rows in matrix A. The value range is [1, MAX_KML_INT].

Input

k

Integer

Number of columns in matrix A. The value range is [1, MAX_KML_INT].

Input

alpha

  • For scsrmv, alpha is of single-precision floating-point type.
  • For dcsrmv, alpha is of double-precision floating-point type.
  • For ccsrmv, alpha is a single-precision complex number.
  • For zcsrmv, alpha is a double-precision complex number.

Coefficient

Input

matdescra

Char pointer

Matrix operation attribute. For details, see the description of matdescra.

Input

val

  • For scsrmv, val is a single-precision floating-point array.
  • For dcsrmv, val is a double-precision floating-point array.
  • For ccsrmv, val is a single-precision complex number array.
  • For zcsrmv, val is a double-precision complex number array.

Non-zero elements in matrix A

Input

indx

Integer array

indx[i] indicates the column number of the ith element of the val array in matrix A.

Input

pntrb

Integer array

Array of length m, containing row indices of matrix A. pntrb[i] - pntrb[0] indicates the subscript of the first non-zero element in row i in the val and indx arrays.

Input

pntre

Integer array

Array of length m, containing row indices of matrix A. pntre[i] - pntrb[0]-1 indicates the subscript of the last non-zero element in row i in the val and indx arrays.

Input

x

  • For scsrmv, x is a single-precision floating-point array.
  • For dcsrmv, x is a double-precision floating-point array.
  • For ccsrmv, x is a single-precision complex number array.
  • For zcsrmv, x is a double-precision complex number array.

Vector x

Input

beta

  • For scsrmv, beta is of the single-precision floating-point type.
  • For dcsrmv, beta is of the double-precision floating-point type.
  • For ccsrmv, beta is a single-precision complex number.
  • For zcsrmv, beta is a double-precision complex number.

Coefficient

Input

y

  • For scsrmv, y is a single-precision floating-point array.
  • For dcsrmv, y is a double-precision floating-point array.
  • For ccsrmv, y is a single-precision complex number array.
  • For zcsrmv, y is a double-precision complex number array.

Vector y, which is output after being updated.

Input/Output

The function does not verify the integrity of parameters. Ensure that the elements in pntrb and pntre do not exceed the maximum index value of the input matrix.

Return Value

Function execution status. The enumeration type is kml_sparse_status_t.

Dependencies

C: "kspblas.h"

Fortran: "kspblas.f03"

Examples

C interface:

    kml_sparse_operation_t opt = KML_SPARSE_OPERATION_NON_TRANSPOSE; 
    KML_INT m = 4; 
    KML_INT k = 4; 
    float alpha = 0.5; 
    float beta = 1.2; 
    char *matdescra = "G00F"; // General matrix with one-based indexing
    float val[9] = {2, -3, 7, 1, -6, 8, -4, 5, 9}; 
    KML_INT indx[9] = {1, 2, 4, 3, 4, 1, 3, 4, 1}; 
    KML_INT pntrb[4] = {1, 4, 6, 9}; 
    KML_INT pntre[4] = {4, 6, 9, 10}; 
    float x[4] = {1, 3, -2, 5}; 
    float y[4] = {-1, 1, 5, 3}; 
    kml_sparse_status_t status = kml_sparse_scsrmv(opt, m, k, alpha, matdescra, val, indx, pntrb, pntre, x, beta, y); 
    /* 
     *  Output Y: 
     *     12.80  -14.80  26.50   8.10 
     * 
     */

Fortran interface:

    INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE 
    INTEGER(C_INT) :: M = 4 
    INTEGER(C_INT) :: K = 4 
    REAL(C_FLOAT) :: ALPHA = 0.5 
    REAL(C_FLOAT) :: BETA = 1.2 
    CHARACTER(KIND=C_CHAR, LEN=4) :: MATDESCRA = "G00F" ! General matrix with one-based indexing
    REAL(C_FLOAT) :: VAL(9), X(4), Y(4)  
    INTEGER(C_INT) INDX(9), PNTRB(4), PNTRE(4) 
    INTEGER(C_INT) :: STATUS 
    DATA INDX/1, 2, 4, 3, 4, 1, 3, 4, 1/ 
    DATA PNTRB/1, 4, 6, 9/  
    DATA PNTRE/4, 6, 9, 10/ 
    DATA VAL /2, -3, 7, 1, -6, 8, -4, 5, 9/ 
    DATA X/1, 3, -2, 5/ 
    DATA Y/-1, 1, 5, 3/ 
    STATUS = KML_SPARSE_SCSRMV(OPT, M, K, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, BETA, Y) 
    ! 
    !  OUTPUT Y: 
    !     12.80  -14.80  26.50   8.10 
    !