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

sparse matrix dense matrix multiplication

utab
Beginner
363 Views

Dear all,

For my Krylov subspace basis build up, I am doing some sparse matrix - dense matrix multiplications. That is fine. I use mkl_dcsrmm for this. But the question now is I am keeping my Krylov vectors in a

std::vector

conceptually, the vectors are the columns of my dense matrix. However, the above interface is considering all the matrices in row major order, is there a way to change this. Since I keep my basis in an array of arrays, I should somehow make it interpreted colum-wise. Is there a work around for this? Or both matrix ordering should be the same when using the routine so one could not be row major(the sparse matrix) and the dense matrix, column major? This is far more efficient and easy to use if there is a work-around for this task.

For instance for the below simple code, I would like b to be interpreted column wise not row-wise while a is still row-wise.

int main()
{
double a[] = {1.e0,2.e0,3.e0};
int ia[] = {0,1,2,3};
int ja[] = {0,1,2};
double b[] = {1.e0,4.e0,2.e0,5.e0,3.e0,6.e0};
double c[] = {0,0,0,0,0,0};
MKL_INT m = 3;
MKL_INT k= 3;
MKL_INT n = 2;
double alpha = 1.0;
double beta = 0.0;
//
char matdescra[6];
matdescra[0]= 'g';
matdescra[1]= 'l';
matdescra[2]= 'u';
matdescra[3]= 'c';
char transa = 'N';
mkl_dcsrmm(&transa,
&m, &n, &k,
&alpha,
matdescra,
a, ja, ia,
ia+1, b,
&n, &beta, c, &n);
//
for(int z=0;z<6;z++)
std::cout << c << std::endl;
return 0;
}

0 Kudos
3 Replies
Henrik_A_
Beginner
363 Views
Before I make a similar thread (Let me know if I should), I ran into the opposite problem: I wanted to scale a dense matrix by a diagonal matrix, and use mkl_ddiamm for this. However my dense matrix is in rowmajor order, and mkl_ddiamm does not have a parameter to transpose the dense matrix (to make it appear row major), not a parameter to set the column ordering information. Is there a better way to calculate diag(scalingVector) * matrix other than implementing it by hand?
0 Kudos
Peter_B_9
Beginner
363 Views

It appears that there's an undocumented "feature" in the mkl_dcsrmm and mkl_scsrmm family of functions. If the sparse matrix uses zero-based indexing, MKL treates the dense matrices as row-major. If the sparse matrix uses one-based indexing MKL treats the desnce matrices as column-major. If you wish to use column-major dense matrices you must use one-based indexing for the CSR matrix.

See http://software.intel.com/en-us/forums/topic/456104#comment-1749818

0 Kudos
asd__asdqwe
Beginner
363 Views

You are right, c.f. http://software.intel.com/en-us/forums/topic/365430#comment-1724980 from an answer from an Intel employee.

0 Kudos
Reply