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

## Dense-Sparse Matrix Multiplication routine instead if sparse-dense multiplication

Beginner
1,094 Views

Hello,

I have a problem where I need to multiply a dense matrix by a sparse matrix. The function "mkl_?csrmm" asks for the first matrix to be sparse and the second to be dense. But my case is opposite.

Problem: C = A * B + C , where A is dense and B is sparse.

I know that I can use "mkl_?csrmm" after taking the transpose of both matrices A and B but the transpose operation will be costly. Is there a better way or existing routine for dense-sparse matrix multiplication?

I am beginner so kindly forgive for mistakes. Thanks in advance!

Regards
Shailesh Tripathi

3 Replies
Employee
1,094 Views

Hi Tripathi,

I do not understand why you would like to be multiplied by sparse matrix. MKL only provide mm API that 1st matrix is sparse, and 2nd is dense. For the "mkl_sparse_?_mm" function, you can control transposition(A or AT) and layout(row-major or col-major) for both A and B, that would be easier for you. Thanks.

Best regards,
Fiona

Beginner
1,094 Views

Hello Fiona,

Thanks a lot you for your help. So you mean to say that if my dense matrix is row major but during the function call, if I treat it as column major (which means transpose), I would inherently get the product of two transpose (sparse also transposed). And the result matrix will also be returned as column major but it is basically the transpose of the row major. So basically, that would yield me what I want. Am I right?