kml_sparse_?csrmultcsr
矩阵与矩阵计算,其中3个稀疏矩阵采用3-arrays CSR格式存储,为基1索引,具体执行操作为:C = op(A) * B。
其中,A、B、C是采用CSR格式存储的稀疏矩阵。
op(A)根据参数是以下3种情况之一:
- op(A) = A
- op(A) = AT
- op(A) = AH
接口定义
C interface:
kml_sparse_status_t kml_sparse_scsrmultcsr(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, 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, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
kml_sparse_status_t kml_sparse_dcsrmultcsr(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, 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, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
kml_sparse_status_t kml_sparse_ccsrmultcsr(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, 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, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
kml_sparse_status_t kml_sparse_zcsrmultcsr(const kml_sparse_operation_t opt, const KML_INT request, const KML_INT sort, 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, KML_INT *jc, KML_INT *ic, const KML_INT nzmax);
Fortran interface:
RES = KML_SPARSE_SCSRMULTCSR(OPT, REQUEST, SORT, M, N, K, A, JA, IA, B, JB, IB, C, JC, IC, NZMAX);
RES = KML_SPARSE_DCSRMULTCSR(OPT, REQUEST, SORT, M, N, K, A, JA, IA, B, JB, IB, C, JC, IC, NZMAX);
RES = KML_SPARSE_CCSRMULTCSR(OPT, REQUEST, SORT, M, N, K, A, JA, IA, B, JB, IB, C, JC, IC, NZMAX);
RES = KML_SPARSE_ZCSRMULTCSR(OPT, REQUEST, SORT, M, N, K, A, JA, IA, B, JB, IB, C, JC, IC, NZMAX);
参数
参数名 |
类型 |
描述 |
输入/输出 |
---|---|---|---|
opt |
枚举类型kml_sparse_operation_t |
表示是否转置:
|
输入 |
request |
整型数 |
|
输入 |
sort |
整型数 |
当前sort参数未定义。 |
输入 |
m |
整型数 |
矩阵A的行数,取值范围为[1, MAX_KML_INT]。 |
输入 |
n |
整型数 |
矩阵A的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
k |
整型数 |
矩阵B的列数,取值范围为[1, MAX_KML_INT]。 |
输入 |
a |
|
CSR格式中values数组,存储矩阵A的非零元素。 |
输入 |
ja |
整型数组 |
CSR格式中columns数组,用于表示矩阵A中非零元素所在的列索引。 |
输入 |
ia |
整型数组 |
长度为m+1的数组,包含矩阵A的行索引,ia[i] - ia[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
b |
|
CSR格式中values数组,存储矩阵B非零元素。 |
输入 |
jb |
整型数组 |
CSR格式中columns数组,用于表示矩阵B非零元素所在的列索引。 |
输入 |
ib |
整型数组 |
长度为m+1的数组,包含矩阵B的行索引,ib[i] – ib[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入 |
c |
|
CSR格式中values数组,存储矩阵C非零元素。 |
输入/输出 |
jc |
整型数组 |
CSR格式中columns数组,用于表示矩阵C非零元素所在的列索引。 |
输入/输出 |
ic |
整型数组 |
度为m+1的数组,包含矩阵C的行索引,ic[i] – ic[0]表示第i行第一个非零元素在val和indx数组内的下标。 |
输入/输出 |
nzmax |
整型数 |
在request=0、2时使用,如果C需要的内存超过nzmax对应内存大小时停止计算。 |
输入 |
返回值
函数执行状态,枚举类型kml_sparse_status_t。
依赖
C: "kspblas.h"
Fortran: "kspblas.f03"
示例
C interface:
kml_sparse_operation_t opt = KML_SPARSE_OPERATION_NON_TRANSPOSE; KML_INT m = 3; KML_INT n = 3; KML_INT k = 3; KML_INT request = 0; //同时计算c,jc,ic三个数组 KML_INT sort = 3; //a,b每行元素的列索引输入前未排序 float a[4] = {4, 5, 4, 5}; KML_INT ja[4] = {3, 2, 1, 3}; KML_INT ia[4] = {1, 2, 4, 5}; float b[4] = {7, 7, 6, 2}; KML_INT jb[4] = {3, 2, 3, 2}; KML_INT ib[4] = {1, 2, 3, 5}; float c[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; KML_INT jc[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; KML_INT ic[4] = {0, 0, 0, 0}; KML_INT nzmax = 9; kml_sparse_status_t status = kml_sparse_scsrmultcsr(opt, request, sort, m, n, k, a, ja, ia, b, jb, ib, c, jc, ic, nzmax); /* * Output c: * 8.00 24.00 35.00 28.00 10.00 30.00 * Output jc: * 2 3 2 3 2 3 * Output ic: * 1 3 5 7 * */
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 INTEGER(C_INT) :: REQUEST = 0 !同时计算C,JC,IC三个数组 INTEGER(C_INT) :: SORT = 3 !A,B每行元素的列索引输入前未排序 REAL(C_FLOAT) :: A(4), B(4), C(6) INTEGER(C_INT) :: JA(4), IA(4), JB(4), IB(4), JC(6), IC(4) INTEGER(C_INT) :: NZMAX = 9 INTEGER(C_INT) :: STATUS DATA A/4, 5, 4, 5/ DATA B/7, 7, 6, 2/ DATA C/0, 0, 0, 0, 0, 0/ DATA JA/3, 2, 1, 3/ DATA IA/1, 2, 4, 5/ DATA JB/3, 2, 3, 2/ DATA IB/1, 2, 3, 5/ DATA JC/0, 0, 0, 0, 0, 0/ DATA IC/0, 0, 0, 0/ STATUS = KML_SPARSE_SCSRMULTCSR(OPT, REQUEST, SORT, M, N, K, A, JA, IA, B, JB, IB, C, JC, IC, NZMAX) ! ! OUTPUT C: ! 8.00 24.00 35.00 28.00 10.00 30.00 ! OUTPUT JC: ! 2 3 2 3 2 3 ! OUTPUT IC: ! 1 3 5 7 !