Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

access to sub-matrices in CSR format

Vahid_Jalili
Beginner
810 Views
Hello all,

SupposeYis saved in sparse CSR formatby defining its values, columns and rowIndex vectors. Is that possible have access to its sub-matrices?
For example:

| 1 -1 0 -3 0 |
| -1 5 0 0 0 |
Y = | 0 0 4 6 4 |
| -3 0 6 7 0 |
| 0 0 4 0 -5 |

values[13] = {1.0, -1.0, -3.0, -1.0, 5.0, 4.0, 6.0, 4.0, -3.0, 6.0, 7.0, 4.0, -5.0};
columns[13] = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 2, 4};
rowIndex[6] = {0, 3, 5, 8, 11, 13};

Can I have access to sub-matrices of Y , e.g. [-3 0 // 0 0 // 6 4] or [0 0 4 // -3 0 6// 0 0 4] ?

Thanks for your help,
0 Kudos
4 Replies
Todd_R_Intel
Employee
810 Views
Hi there,

You could write code to unpack and access it I suppose, but if you're asking whether there is an easyway to access it or have MKL functions act upon it (as there is in LAPACK by specifying the first element and an appropriate leading dimension parameter as the stride) then I believe the answer is no.

Todd
0 Kudos
Sergey_K_Intel1
Employee
810 Views
The Intel MKL supports twovariations of thecompressed sparse row (CSR) format. The first variation proposed in the NISTSparse BLAS is specified by four arrays: the values, columns, pointerB, and pointerE. And the second variation is specified by three arrays:values, columns and rowIndex as you described above.Some MKLSparse BLAS routines can only works with the three arraysvarition of the CSR, all other routines can work with the both variations.

Compared to the classical three arrays variation of CSR mentioned by you, the NIST variation with four arraysallows working with submatrices. You just need to define pointerB and pointerE arraysproperly. You don't need to form additional the values and columns arrays since all sparse representations of submatrices can use only one copy of these arrays.

Hope it helps
All the best
Sergey
0 Kudos
Vahid_Jalili
Beginner
810 Views
Hello Sergey,
Thanks for your reply,
I am aware of pointerB and poiterE vectors used for CSR format:
For matrix Y they are as following:
pointerB = {0, 3, 5, 8, 11};
pointerE = {3, 5, 8, 11, 13};
But, still I cannot set these pointers correctly to extract submatrices, e.g. [0 0 4 // -3 0 6// 0 0 4] ?

I want to use these submatix inmkl_scsrmv

mkl_ccsrmv(&transa, &m, &k, α, matdescra, values, columns, pointerB, pointerE, sol_vec, β, rhs_vec);
If m and k should be dimensions of the original matrix (i.e. 5x5) or they should be dimensions of the submatrix (e.g 3x3)?
Thanks for your help.

--Vahid
0 Kudos
Sergey_K_Intel1
Employee
810 Views

Hello Vahid,

Your submatrix can be defined as follows:
int pointerB[3]={2, 3, 5} , pointerE[3]={3,3,8};
Here is a code example where submatrix is multiplied by vector {3,4, 5) with the help of mkl_dcsrmv
int main() {
//*******************************************************************************
// Declaration and initialization of parameters for sparse representation of
// the matrix A in the compressed sparse row format:
//*******************************************************************************
#define M 5
#define NNZ 13
#define MN
double values[NNZ] = {1.0, -1.0, -3.0, -1.0, 5.0, 4.0, 6.0, 4.0, -3.0, 6.0, 7.0, 4.0, -5.0};
int columns[NNZ] = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 2, 4};
int rowIndex[M+1] = {0, 3, 5, 8, 11, 13};
double sol_vec = {1.0, 2.0, 3.0, 4.0, 5.0};
double rhs_vec = {0.0, 0.0, 0.0, 0.0, 0.0};
double alpha=1.0, beta=0.0;
int pointerB[3]={2, 3, 5} , pointerE[3]={3,3,8};
char transa;
char matdescra[6];
int i, ishift, mn=3;

transa = 'n';
matdescra[0] = 'g';
matdescra[3] = 'c';
ishift=pointerB[0];
mkl_dcsrmv(&transa, &mn, &mn, α, matdescra,&values[ishift], &columns[ishift], pointerB, pointerE, sol_vec, β, rhs_vec);
for (i = 0; i < mn; i++) {
printf("%7.1f\n", rhs_vec);
};
}

As concerns as m and k, I'd recommend to use dimensions of the submatrix.

All the best
Sergey

0 Kudos
Reply