Sorted result with mkl_dcsrcoo

Sorted result with mkl_dcsrcoo

Ritratto di messenjah

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

[uuu@xxx build]$ icc test.c -o test -lmkl_intel_lp64 -lmkl_sequential -lmkl_core
[uuu@xxx build]$ ./test
info = 0
 AI=   1   3   4   7
 AJ= |   1   3 |   3 |   4   1   3 |
 AX= | 1.0 2.0 | 3.0 | 8.0 5.0 7.0 |

which is expected i.e. the last row is correct although not sorted. If I include -DSORT then I get

[uuu@xxx build]$ icc test.c -o test -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -DSORT
[uuu@xxx build]$ ./test
info = 0
 AI=   1   3   4   7
 AJ= |   1   3 |   3 |   1   3   4 |
 AX= | 1.0 2.0 | 3.0 | 5.0 7.0 8.0 |

which is also correct i.e. the last row is correct and sorted. Furthermore if I use the zero indexed version without sorting

[uuu@xxx build]$ icc test.c -o test -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -DZEROINDEX
[uuu@xxx build]$ ./test
info = 0
 AI=   0   2   3   6
 AJ= |   0   2 |   2 |   3   0   2 |
 AX= | 1.0 2.0 | 3.0 | 8.0 5.0 7.0 |

I still get the correct conversion. But if I have both zero indexing and sorting, I get something rather unusual

[uuu@xxxbuild]$ icc test.c -o test -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -DZEROINDEX -DSORT
[uuu@xxxbuild]$ ./test
info = 0
 AI=   0   2   3   6
 AJ= |   0   2 |   0 |   2   3   2 |
 AX= | 1.0 2.0 | 5.0 | 3.0 8.0 7.0 |

I'm wondering if there's something I'm missing when using zero indexed arrays.

1 contenuto / 0 new
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione