kml_sparse_?csrmultd
Compute the product of matrices. Two of them are sparse matrices stored in the CSR format with one-based indexing.
C = op(A) * B
C is a dense matrix, and A and B are sparse matrices in the CSR format.
op(A) can be defined as:
- op(A) = A
- op(A) = AT
- op(A) = AH
Interface Definition
C interface:
kml_sparse_status_t kml_sparse_scsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const float *a, const KML_INT *ja, const KML_INT *ia, const float *b, const KML_INT *jb, const KML_INT *ib, float *c, const KML_INT ldc);
kml_sparse_status_t kml_sparse_dcsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const double *a, const KML_INT *ja, const KML_INT *ia, const double *b, const KML_INT *jb, const KML_INT *ib, double *c, const KML_INT ldc);
kml_sparse_status_t kml_sparse_ccsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex8 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex8 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex8 *c, const KML_INT ldc);
kml_sparse_status_t kml_sparse_zcsrmultd(const kml_sparse_operation_t opt, const KML_INT m, const KML_INT n, const KML_INT k, const KML_Complex16 *a, const KML_INT *ja, const KML_INT *ia, const KML_Complex16 *b, const KML_INT *jb, const KML_INT *ib, KML_Complex16 *c, const KML_INT ldc);
Fortran interface:
RES = KML_SPARSE_SCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
RES = KML_SPARSE_DCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
RES = KML_SPARSE_CCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
RES = KML_SPARSE_ZCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
opt |
Enumeration type kml_sparse_operation_t |
Indicates whether to transpose.
|
Input |
m |
Integer |
Number of rows in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
n |
Integer |
Number of columns in matrix A. The value range is [1, MAX_KML_INT]. |
Input |
k |
Integer |
Number of columns in matrix B. The value range is [1, MAX_KML_INT]. |
Input |
a |
|
Array values storing non-zero elements of matrix A in the CSR format |
Input |
ja |
Integer array |
Array columns in the CSR format, which contains the column indices for non-zero elements in matrix A |
Input |
ia |
Integer array |
Array of length m+1, containing row indices of matrix A. ia[i] - ia[0] indicates the subscript of the first non-zero element in row i in the val and indx arrays. |
Input |
b |
|
Array values storing non-zero elements of matrix B in the CSR format. |
Input |
jb |
Integer array |
Array columns in the CSR format, which contains the column indices for non-zero elements in matrix B. |
Input |
ib |
Integer array |
Array containing row indices of elements in matrix B. ib[i] – ib[0] indicates the subscript of the first non-zero element in the ith row in the val and indx arrays. |
Input |
c |
|
Array of matrix C |
Output |
ldc |
Integer |
Leading dimension of dense matrix C. ldc*k |
Input |
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 = 3;
KML_INT n = 3;
KML_INT k = 3;
float a[4] = {1, 5, 4, 5};
KML_INT ja[4] = {3, 1, 1, 1};
KML_INT ia[4] = {1, 3, 4, 5};
float b[4] = {9, 4, 2, 8};
KML_INT jb[4] = {2, 3, 1, 1};
KML_INT ib[4] = {1, 3, 4, 5};
float c[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
KML_INT ldc = 3;
kml_sparse_status_t status = kml_sparse_scsrmultd(opt, m, n, k, a, ja, ia, b, jb, ib, c, ldc);
/*
* Output c:
* 8.00 0.00 0.00 45.00 36.00 45.00 20.00 16.00 20.00
*
*/
Fortran interface:
INTEGER(C_INT) :: OPT = KML_SPARSE_OPERATION_NON_TRANSPOSE
INTEGER(C_INT) :: M = 3
INTEGER(C_INT) :: N = 3
INTEGER(C_INT) :: K = 3
REAL(C_FLOAT) :: A(4), B(4), C(9)
INTEGER(C_INT) :: JA(4), IA(4), JB(4), IB(4)
INTEGER(C_INT) :: LDC = 3
INTEGER(C_INT) :: STATUS
DATA A/1, 5, 4, 5/
DATA B/9, 4, 2, 8/
DATA C/0, 0, 0, 0, 0, 0, 0, 0, 0/
DATA JA/3, 1, 1, 1/
DATA IA/1, 3, 4, 5/
DATA JB /2, 3, 1, 1/
DATA IB /1, 3, 4, 5/
STATUS = KML_SPARSE_SCSRMULTD(OPT, M, N, K, A, JA, IA, B, JB, IB, C, LDC)
!
! OUTPUT C:
! 8.00 0.00 0.00 45.00 36.00 45.00 20.00 16.00 20.00
!
