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

transpose matrix stored in CSR format using MKL

Thomas_D_
Beginner
1,491 Views

All,

I have some legacy parallel code that uses CSR format to store a very large, sparse matrix. In making some additions to the code, I have the need to transpose the matrix, storing the transpose in CSR format as well.

Is there a routine in the MKL that would help me do this? I thought of using a BLAS routine to repeatedly multiply column vectors with ones in successive locations by the matrix, and accumulate the results. Is there a better way?

Thanks,

Tom

0 Kudos
6 Replies
mecej4
Honored Contributor III
1,491 Views

Here is an idea for you to evaluate -- it may not be as efficient as writing your own code to do the transformation, but it is unlikely to lead to a bottleneck.

Note that the CSR representation of a matrix A is identical to the CSC representation of AT. Therefore, code using the relevant version of mkl_?csrcsc may be the easiest to implement.

Alternatively, convert the CSR representation to a COO representation, say (IC, JC, VC). The COO representation of the transpose is (JC,IC,VC). Convert this COO representation to a CSR representation of the transposed matrix.

Which option to use depends on what other transformations you need to perform, if any, in addition to transposing.

Routines for doing the conversions indicated are provided in MKL.

 

0 Kudos
Thomas_D_
Beginner
1,491 Views

Thanks, that look like a promising approach!

Regards,

Tom

0 Kudos
Li__Yapeng
Beginner
1,491 Views

The function of mkl_sparse_?_add can perform what you want.

0 Kudos
Gennady_F_Intel
Moderator
1,491 Views

good catch, thanks, but Tom, please take into account this functionality was added since MKL v.11.3 and i am not sure whch version of MKL do you use right now. The latest version of MKL is 2019 ( release, Aug 2018)

0 Kudos
Tibaldi__Alberto
Beginner
1,491 Views

Hi,

Another solution is to use MKL_SPARSE_CONVERT_CSR. Even if the matrix is in CSR format, if you perform (RACSR in my example is a matrix already stored in CSR format),

    mkl_status = MKL_SPARSE_CONVERT_CSR(RACSR, SPARSE_OPERATION_TRANSPOSE, RACSR)

after this command, RACSR is transposed.

Best Regards,

Alberto

0 Kudos
Gennady_F_Intel
Moderator
1,491 Views

just for info: the current ( MKL 2020) status of mkl_sparse_?_add routine: this routine is only supported for sparse matrices in CSR and BSR formats. It is not supported for COO or CSC formats.   

 

0 Kudos
Reply