sparse matrix multiplication problem

sparse matrix multiplication problem

stansy的头像

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[m]-1]; jc = new int[ic[m]-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

 

3 帖子 / 0 new
最新文章
如需更全面地了解编译器优化,请参阅优化注意事项.
Zhang Z (Intel)的头像

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)的头像

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

登陆并发表评论。