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 or 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.
|
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 |
|
Coefficient |
Input |
matdescra |
Char pointer |
Matrix operation attribute. For details, see the description of matdescra. |
Input |
val |
|
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 |
|
Vector x |
Input |
beta |
|
Coefficient |
Input |
y |
|
Vector y. This parameter is output after update. |
Input/Output |
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
!