kml_sparse_?csrsymv
Compute the product of a vector and a sparse matrix that is stored in the CSR format. The operation is defined as follows:
y = A * x
x and y are vectors, and A is a symmetric upper or lower triangle matrix stored in the CSR format (3-array variation) with one-based indexing.
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_scsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const float *a, const KML_INT *ia, const KML_INT *ja, const float *x, float *y);
kml_sparse_status_t kml_sparse_dcsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const double *a, const KML_INT *ia, const KML_INT *ja, const double *x, double *y);
kml_sparse_status_t kml_sparse_ccsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const KML_Complex8 *a, const KML_INT *ia, const KML_INT *ja, const KML_Complex8 *x, KML_Complex8 *y);
kml_sparse_status_t kml_sparse_zcsrsymv(const kml_sparse_fill_mode_t uplo, const KML_INT m, const KML_Complex16 *a, const KML_INT *ia, const KML_INT *ja, const KML_Complex16 *x, KML_Complex16 *y);
Fortran interface:
RES = KML_SPARSE_SCSRSYMV(UPLO, M, A, IA, JA, X, Y);
RES = KML_SPARSE_DCSRSYMV(UPLO, M, A, IA, JA, X, Y);
RES = KML_SPARSE_CCSRSYMV(UPLO, M, A, IA, JA, X, Y);
RES = KML_SPARSE_ZCSRSYMV(UPLO, M, A, IA, JA, X, Y);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
uplo |
Enumeration type kml_sparse_fill_mode_t uplo |
Indicates whether the upper triangle or lower triangle of matrix A is used.
|
Input |
m |
Integer |
Number of rows and columns in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
a |
|
Non-zero elements in matrix A |
Input |
ia |
Integer |
Vector whose length is m+1. ia[i]-1 indicates the index of the first non-zero element in the ith row of matrix A in the val array. |
Input |
ja |
Integer |
ja[i] indicates the column number of the ith element of the val array in matrix A. |
Input |
x |
|
Vector x |
Input |
y |
|
Vector y, which is output after being updated. |
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_fill_mode_t uplo = KML_SPARSE_FILL_MODE_LOWER;
KML_INT m = 4;
float a[9] = {2, -3, 7, 1, -6, 8, -4, 5, 9};
KML_INT ja[9] = {1, 2, 4, 3, 4, 1, 3, 4, 1};
KML_INT ia[5] = {1, 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_scsrsymv(uplo, m, a, ia, ja, x, y);
/*
* Output Y:
* 31.000000 0.000000 16.000000 9.000000
*
*/
Fortran interface:
INTEGER(C_INT) :: UPLO = KML_SPARSE_FILL_MODE_LOWER
INTEGER(C_INT) :: M = 4
REAL(C_FLOAT) :: A(9), X(4), Y(4)
INTEGER(C_INT) :: JA(9), IA(5)
INTEGER(C_INT) :: STATUS
DATA A/2, -3, 7, 1, -6, 8, -4, 5, 9/
DATA JA/1, 2, 4, 3, 4, 1, 3, 4, 1/
DATA IA/1, 4, 6, 9, 10/
DATA X/1, 3, -2, 5/
DATA Y/-1, 1, 5, 3/
STATUS = KML_SPARSE_SCSRSYMV(UPLO, M, A, IA, JA, X, Y)
!
! OUTPUT Y:
! 31.000000 0.000000 16.000000 9.000000
!
!