kml_sparse_?csrmultcsr
Compute the product of matrices.
C = op(A) * B.
A, B, and C are sparse matrices in the CSR format (3-array variation) with one-based indexing.
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_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);
Parameters
Parameter |
Type |
Description |
Input/Output |
|---|---|---|---|
opt |
Enumeration type kml_sparse_operation_t |
Indicates whether to transpose.
|
Input |
request |
Integer |
|
Input |
sort |
Integer |
The sort parameter is not defined. |
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 of length m+1, containing row indices of matrix B. ib[i] – ib[0] indicates the subscript of the first non-zero element in row i in the val and indx arrays. |
Input |
c |
|
Array values storing non-zero elements of matrix C in the CSR format. |
Input/Output |
jc |
Integer array |
Array columns in the CSR format, which contains the column indices for non-zero elements in matrix C |
Input/Output |
ic |
Integer array |
Array of length m+1, containing row indices of matrix C. ic[i] – ic[0] indicates the subscript of the first non-zero element in the ith row in the val and indx arrays. |
Input/Output |
nzmax |
Integer |
This parameter is used if the value of request is 0 or 2. The function stops computing if the memory required by C exceeds the specified value of nzmax. |
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;
KML_INT request = 0; // Compute the c, jc, and ic arrays at the same time.
KML_INT sort = 3; // The row indices for elements in a and b have not been sorted before input.
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 ! Compute the C, JC, and IC arrays at the same time.
INTEGER(C_INT) :: SORT = 3 ! The row indices for elements in A and B have not been sorted before input.
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
!