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

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

Tripathi__Shailesh
1,382 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

 

 

0 Kudos
3 Replies
Zhen_Z_Intel
Employee
1,382 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

0 Kudos
Tripathi__Shailesh
1,382 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?

Thanks in advance!

Regards

Shailesh Tripathi 

0 Kudos
wiegerw
Beginner
997 Views

I ran into a similar problem. What I need to compute is C = A * B or C = A * B^T with A sparse and B, C dense. The solution I came up with is to rewrite these expressions into C = (B^T * A^T)^T and C = (B * A^T)^T. The remaining dense times sparse matrix multiplications are supported by MKL. This approach introduces a few extra transpose operations on dense matrices. But thanks to your suggestion I found out that these operations can be done without actually changing the underlying data, by swapping the rows/columns and row/column major attributes.

Of course it's possible to do all of this by yourself. What puzzles me is why such routines for sparse times dense matrix multiplication are missing in the MKL library. Perhaps for historical reasons the linear algebra packages offer only a minimal set of operations. But from a user's perspective this is far from ideal.

0 Kudos
Reply