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

Sparse Blas Matrix Multiplication

Dan4
Beginner
807 Views
Hi,

I have a problem using MKL Sparse Blas Level 3 routine "mkl_dcoomm" which calculates C=A*B where A is a sparse matrix in coordinate format and B is dense matrix. Clearly C is also a dense matrix. The problem is that I would like to perform C=A*B where B is sparse and A is dense (reverse of former case). Is there any other function for this (I didn't find!) or I should change my expression and use same matrix? My question might be very elementary, so sorry in advance!

Thanks for your help,

D.
0 Kudos
4 Replies
jaewonj
Novice
807 Views
Quoting - danltu.se
Hi,

I have a problem using MKL Sparse Blas Level 3 routine "mkl_dcoomm" which calculates C=A*B where A is a sparse matrix in coordinate format and B is dense matrix. Clearly C is also a dense matrix. The problem is that I would like to perform C=A*B where B is sparse and A is dense (reverse of former case). Is there any other function for this (I didn't find!) or I should change my expression and use same matrix? My question might be very elementary, so sorry in advance!

Thanks for your help,

D.
This might work.

C^T = (A*B)^T = B^T * A^T

B^T : set transa = 'T'
A^T : store A in row-major order, or transpose A if it is stored in column-major order
C^T : treat C as C-style dense array, or transpose C if you need column-major order






0 Kudos
Dan4
Beginner
807 Views
Quoting - jaewonj
This might work.

C^T = (A*B)^T = B^T * A^T

B^T : set transa = 'T'
A^T : store A in row-major order, or transpose A if it is stored in column-major order
C^T : treat C as C-style dense array, or transpose C if you need column-major order







Thank you janwonj for your answer. It can be a solution, but it sounds weired to me if MKL does not support such simple multiplication. Isn't really any suitable function to perform DENSE x SPARSE operation in MKL?
0 Kudos
jaewonj
Novice
807 Views
Quoting - danltu.se

Thank you janwonj for your answer. It can be a solution, but it sounds weired to me if MKL does not support such simple multiplication. Isn't really any suitable function to perform DENSE x SPARSE operation in MKL?
As far as I know MKL does not directly support dense * sparse BLAS level 3 function. I know it's not pleasant, but I think we need to compute C' = (A*B)'.


0 Kudos
Victor_Gladkikh
New Contributor I
807 Views
Quoting - danltu.se

Thank you janwonj for your answer. It can be a solution, but it sounds weired to me if MKL does not support such simple multiplication. Isn't really any suitable function to perform DENSE x SPARSE operation in MKL?

Anyway there are different ways to used MKL, but it depend to problem that required computation of DENSE matrix C

First way: Size of SPARSE matrix is enough small, then you could convert from COO to DENSE and use MKL dgemm.

Second way: Your interest is compute product y = C*x (x is vector) or Y=C*X (X is DENSE matrix) then you could used MKL by next way:

compute z = B * x (use mkl_dcoomv) and compute y= A * z (use dgemv)

or

compute Z = B * X (use mkl_dcoomm) and compute Y= A * Z (use dgemm)

0 Kudos
Reply