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

sparse matrix multiplication problem

stansy
Beginner
111 Views

Hi,
Please help me to resolve the problem with the calculation of product of two sparse matrices stored in the CSR format.
The following program computes the product C = A * B and returns an incorrect result.

double a[] = {1,2,2,3,1,1,4};
double b[] = {1,2,3,4,5,1,4};
int ja[] = {1,2,1,2,3,2,3};
int ia[] = {1,3,6,8};
int jb[] = {1,2,1,2,3,2,3};
int ib[] = {1,3,6,8};
double* c = NULL;
int* jc = NULL, * ic = NULL;

int m = 3;
double beta = 1.0;
char trans = 'N';
int request, sort;
int info;
  
ic = new int[m+1];
request = 1; sort = 0;
mkl_dcsrmultcsr(&trans, &request, &sort, &m, &m, &m, a, ja, ia, a, ja, ia, c, jc, ic, NULL, &info);
c = new double[ic-1]; jc = new int[ic-1];
request = 2;
mkl_dcsrmultcsr(&trans, &request, &sort, &m, &m, &m, a, ja, ia, a, ja, ia, c, jc, ic, NULL, &info);

Results:
c =  5       8       2       8      14       7       2       7      17
ic = 1       4       7      10
jc =  1       2       3       1       2       3       1       2       3

A = { 1 2 0
      2 3 1
      0 1 4 }

B = { 1 3 0
         2 4 1
         0 5 4 }

C = { 5 8  2
        8 14 7
        2 7  17 }  (incorrect 2nd column)

Best Regards,
Stan

 

0 Kudos
2 Replies
Zhang_Z_Intel
Employee
111 Views
Thanks for letting us know your problem. I'm now trying to reproduce the issue, and I will update you as soon as I have some results. Best, Zhang
Zhang_Z_Intel
Employee
111 Views
Hi, I figured out the problem. Your "b" array is incorrectly specified. It's not in the correct order for the CSR format. It should be {1,3,2,4,1,5,4}. Zhang
Reply