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

Sparse Matrix Matrix Multiplication

Ferdous__S_M
Beginner
475 Views

I have a matrix A I want to perform the following operation in MKL,

C = A*AT 

Where A is a sparse matrix and A is the row l from h of A. I am currently computing The AT and then multiplying it using spmmd. Note that C is a dense matrix. But this approach wastes memory because I need to compute Aseparately.  Is there any specific function in MKL that I can use for this? 

0 Kudos
3 Replies
Kirill_V_Intel
Employee
475 Views

Hello,

Have a look at mkl_sparse_?_syrkd, https://software.intel.com/en-us/mkl-developer-reference-c-mkl-sparse-syrkd. Isn't it what you're looking for?

Best,
Kirill

0 Kudos
Ferdous__S_M
Beginner
475 Views

Thanks. Not exactly. syrkd computes A*AT. But I do not want to compute it. What I need is a subset of the rows of A times the transpose of A. I do not see how I can use syrkd for achieving this.

0 Kudos
Kirill_V_Intel
Employee
475 Views

I see, I didn't notice it. So, I guess then that h is relatively small, right? (if it was comparable with the size of the matrix you could use syrk and then throw away the part which is not needed).

If h is very small, you might consider conveting A(1:h,:) and the resulting matrix to a dense format, and make use of mkl_sparse_?_mm (and use an extra transposition of the result). Say, if A(1:h,:) = B (dense), you can write A(1:h,:)*A^T = B * A^T = (A * B^T)^T, so you can transpose B while converting A(1:h,:) to the dense format, compute the result using mm and then transpose the (skinny, dense) matrix product to get the final result (in the dense format).

You can also try to play around with CSR/CSC formats and transposition to avoid transposing the matrix A at the cost of transposing the other objects (similar to what I describe above) but I am not sure it will bring you a lot of benefits. 

Also, if you tell us more about your use case and why it happens to be something important ~ critical for performance, we can add it to the list of feature requests. 

Best,
Kirill

0 Kudos
Reply