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

Sorted result with mkl_dcsrcoo

messenjah
Beginner
697 Views
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.

[cpp]/*
 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);
	printf("\n AJ=");
	for(i = 0; i < m; i++)
	{
		printf(" |");
		for(j = ia-job[1]; j < ia[i+1]-job[1]; j++) printf(" %3d", ja);
	}
	printf(" |\n AX=");
	for(i = 0; i < m; i++)
	{
		printf(" |");
		for(j = ia-job[1]; j < ia[i+1]-job[1]; j++) printf(" %3.1f", acsr);
	}
	printf(" |\n");
	return 0;
}
[/cpp]


If I compile without -DZEROINDEX and -DSORT, I get the following output
[bash][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 |
[/bash]
which is expected i.e. the last row is correct although not sorted. If I include -DSORT then I get
[bash][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 |
[/bash]
which is also correct i.e. the last row is correct and sorted. Furthermore if I use the zero indexed version without sorting
[bash][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 |[/bash]
I still get the correct conversion. But if I have both zero indexing and sorting, I get something rather unusual
[bash][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 |[/bash]
I'm wondering if there's something I'm missing when using zero indexed arrays.
0 Kudos
0 Replies
Reply