kml_sparse_?csrsv
Solve a system of equations for a triangular sparse matrix that is stored in the CSR format. The operation is defined as follows:
A * y = alpha * x, AT * y = alpha * x, or AH * y = alpha * x
x and y are vectors, and A is a sparse matrix (m * m) in the CSR format. The non-zero elements of a given row in matrix A must be stored in the same order as they are displayed in the row (from left to right).
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_scsrsv(const kml_sparse_operation_t opt, const KML_INT m, const float alpha, const char *matdescra, const float *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const float *x, float *y);
kml_sparse_status_t kml_sparse_dcsrsv(const kml_sparse_operation_t opt, const KML_INT m, const double alpha, const char *matdescra, const double *val, const KML_INT *indx, const KML_INT *pntrb, const KML_INT *pntre, const double *x, double *y);
kml_sparse_status_t kml_sparse_ccsrsv(const kml_sparse_operation_t opt, const KML_INT m, 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, KML_Complex8 *y);
kml_sparse_status_t kml_sparse_zcsrsv(const kml_sparse_operation_t opt, const KML_INT m, 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, KML_Complex16 *y);
Fortran interface:
RES = KML_SPARSE_SCSRSV(OPT, M, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, Y);
RES = KML_SPARSE_DCSRSV(OPT, M, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, Y);
RES = KML_SPARSE_CCSRSV(OPT, M, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, Y);
RES = KML_SPARSE_ZCSRSV(OPT, M, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, 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 |
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 |
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;
float alpha = 1.0;
char *matdescra = "TLNF"; // 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, 2, 4, 1, 3, 1, 4};
KML_INT pntrb[4] = {1, 4, 6, 8};
KML_INT pntre[4] = {4, 6, 8, 10};
float x[4] = {1, 3, -2, 5};
float y[4] = {0, 0, 0, 0};
kml_sparse_status_t status = kml_sparse_scsrsv(opt, m, alpha, matdescra, val, indx, pntrb, pntre, x, y);
/*
* Output Y:
* 0.500000 3.000000 1.500000 0.277778
*
*/
Fortran interface:
INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE
INTEGER(C_INT) :: M = 4
REAL(C_FLOAT) :: ALPHA = 1.0
CHARACTER(KIND=C_CHAR, LEN=4) :: MATDESCRA = "TLNF" ! 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 VAL /2, -3, 7, 1, -6, 8, -4, 5, 9/
DATA INDX /1, 2, 4, 2, 4, 1, 3, 1, 4/
DATA PNTRB /1, 4, 6, 8/
DATA PNTRE/4, 6, 8, 10/
DATA X/1, 3, -2, 5/
DATA Y/0, 0, 0, 0/
STATUS = KML_SPARSE_SCSRSV(OPT, M, ALPHA, MATDESCRA, VAL, INDX, PNTRB, PNTRE, X, Y);
!
! OUTPUT Y:
! 0.500000 3.000000 1.500000 0.277778
!