I simply want to convert a sparse matrix in COO format to CSR and I want the column indices for each row to be sorted. This is a recurrent problem but so far I haven't found a solution to the problem I'm facing on this forum or anywhere else.
I'm using RedHat EL5 with icc version 12.0 and the doc says MKL version is 10.3. I therefore know that to get sorted output I need to set job(1) to 2. I have the short code below taken from this forum which shows the problem.
/*
Matrix is
1 0 2 0
A = 0 0 3 0
5 0 7 8
nnz = 6, m = 3, n = 4
*/
#include
#include "mkl_spblas.h"
int main(int argc, char *argv[] )
{
double acoo[6] ={1.0, 8.0, 5.0, 3.0, 7.0, 2.0};
#ifdef ZEROINDEX
int rowind[6] ={0, 2, 2, 1, 2, 0};
int colind[6] ={0, 3, 0, 2, 2, 2};
int job[8]={1,0,0,0,6,0,0,0};
#else
int rowind[6] ={1, 3, 3, 2, 3, 1};
int colind[6] ={1, 4, 1, 3, 3, 3};
int job[8]={1,1,1,0,6,0,0,0};
#endif
int m=3, n=4, nnz=6;
double acsr[6];
int ia[4], ja[6], i, j, info;
#ifdef SORT
job[0] = 2;
#endif
mkl_dcsrcoo(job, &m, acsr, ja, ia, &nnz, acoo, rowind, colind, &info);
printf("info = %d", info);
printf("n AI=");
for(i = 0; i <= m; i++) printf(" %3d", ia[i]);
printf("n AJ=");
for(i = 0; i < m; i++)
{
printf(" |");
for(j = ia[i]-job[1]; j < ia[i+1]-job[1]; j++) printf(" %3d", ja[j]);
}
printf(" |n AX=");
for(i = 0; i < m; i++)
{
printf(" |");
for(j = ia[i]-job[1]; j < ia[i+1]-job[1]; j++) printf(" %3.1f", acsr[j]);
}
printf(" |n");
return 0;
}
If I compile without -DZEROINDEX and -DSORT, I get the following output
Sorted result with mkl_dcsrcoo
I simply want to convert a sparse matrix in COO format to CSR and I want the column indices for each row to be sorted. This is a recurrent problem but so far I haven't found a solution to the problem I'm facing on this forum or anywhere else.
I'm using RedHat EL5 with icc version 12.0 and the doc says MKL version is 10.3. I therefore know that to get sorted output I need to set job(1) to 2. I have the short code below taken from this forum which shows the problem.
/* Matrix is 1 0 2 0 A = 0 0 3 0 5 0 7 8 nnz = 6, m = 3, n = 4 */ #include #include "mkl_spblas.h" int main(int argc, char *argv[] ) { double acoo[6] ={1.0, 8.0, 5.0, 3.0, 7.0, 2.0}; #ifdef ZEROINDEX int rowind[6] ={0, 2, 2, 1, 2, 0}; int colind[6] ={0, 3, 0, 2, 2, 2}; int job[8]={1,0,0,0,6,0,0,0}; #else int rowind[6] ={1, 3, 3, 2, 3, 1}; int colind[6] ={1, 4, 1, 3, 3, 3}; int job[8]={1,1,1,0,6,0,0,0}; #endif int m=3, n=4, nnz=6; double acsr[6]; int ia[4], ja[6], i, j, info; #ifdef SORT job[0] = 2; #endif mkl_dcsrcoo(job, &m, acsr, ja, ia, &nnz, acoo, rowind, colind, &info); printf("info = %d", info); printf("n AI="); for(i = 0; i <= m; i++) printf(" %3d", ia[i]); printf("n AJ="); for(i = 0; i < m; i++) { printf(" |"); for(j = ia[i]-job[1]; j < ia[i+1]-job[1]; j++) printf(" %3d", ja[j]); } printf(" |n AX="); for(i = 0; i < m; i++) { printf(" |"); for(j = ia[i]-job[1]; j < ia[i+1]-job[1]; j++) printf(" %3.1f", acsr[j]); } printf(" |n"); return 0; }If I compile without -DZEROINDEX and -DSORT, I get the following output
which is expected i.e. the last row is correct although not sorted. If I include -DSORT then I get
which is also correct i.e. the last row is correct and sorted. Furthermore if I use the zero indexed version without sorting
I still get the correct conversion. But if I have both zero indexing and sorting, I get something rather unusual
I'm wondering if there's something I'm missing when using zero indexed arrays.