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

sparse matrix dense matrix multiplication question

utab
Beginner
250 Views
Dear all,

I am trying to do a sparse matrix - dense matrix multiplication operation, however the below code does not give me what I want,
I use the sparse matrix that is used in the intel manual and examples and a dense matrix of
1 5
1 4
1 3
1 2
1 1
I guess my representation is correct in the code, however there is still sth wrong since I can not find the right answer. Could you please help me?

Best regards,
Umut

My code

#include

#include "mkl_types.h"
#include "mkl_spblas.h"

int main()
{
MKL_INT M = 5;
double values[] = {1.0, -1.0, -3.0, -2.0, 5.0, 4.0, 6.0, 4.0, -4.0, 2.0, 7.0, 8.0, -5.0};
MKL_INT columns[] = {0, 1, 3, 0, 1, 2, 3, 4, 0, 2, 3, 1, 4};
MKL_INT rowIndex[] = {0, 3, 5, 8, 11, 13};
MKL_INT pntrb[] = {0, 3, 5, 8, 11};
MKL_INT pntre[] = {3, 5, 8, 11, 13;
MKL_INT N = 2;
double b[] = {1.0, 5.0, 1.0, 4.0, 1.0, 3.0, 1.0, 2.0, 1.0,1.0};
double c[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,0.0};
char transa = 'N';
double alpha = 1.0;
double beta = 0.0;
char matdescra[6] = {'G','U','N','C',' ',' '};
mkl_dcsrmm(&transa, &M, &N, &M, α, matdescra, values, columns, pntrb, pntre, b, &N, β, c, &N);
// can not get the right result however.
for (int j = 0; j < M*N; j++) {
std::cout << c << std::endl;
}
return 0;
}

0 Kudos
0 Replies
Reply