<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Sorted result with mkl_dcsrcoo in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Sorted-result-with-mkl-dcsrcoo/m-p/778441#M1252</link>
    <description>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.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]/*
 Matrix is

      1 0 2 0
 A =  0 0 3 0
      5 0 7 8

 nnz = 6, m = 3, n = 4
*/	
#include &lt;STDIO.H&gt;
#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, &amp;amp;m, acsr, ja, ia, &amp;amp;nnz, acoo, rowind, colind, &amp;amp;info);
	
	printf("info = %d", info);
	printf("\n AI=");
	for(i = 0; i &amp;lt;= m; i++) printf(" %3d", ia&lt;I&gt;);
	printf("\n AJ=");
	for(i = 0; i &amp;lt; m; i++)
	{
		printf(" |");
		for(j = ia&lt;I&gt;-job[1]; j &amp;lt; ia[i+1]-job[1]; j++) printf(" %3d", ja&lt;J&gt;);
	}
	printf(" |\n AX=");
	for(i = 0; i &amp;lt; m; i++)
	{
		printf(" |");
		for(j = ia&lt;I&gt;-job[1]; j &amp;lt; ia[i+1]-job[1]; j++) printf(" %3.1f", acsr&lt;J&gt;);
	}
	printf(" |\n");
	return 0;
}
[/cpp]&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; &lt;BR /&gt;&lt;BR /&gt;If I compile without -DZEROINDEX and -DSORT, I get the following output&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; which is expected i.e. the last row is correct although not sorted. If I include -DSORT then I get&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; which is also correct i.e. the last row is correct and sorted. Furthermore if I use the zero indexed version without sorting&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; I still get the correct conversion. But if I have both zero indexing and sorting, I get something rather unusual&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; I'm wondering if there's something I'm missing when using zero indexed arrays.</description>
    <pubDate>Tue, 02 Aug 2011 14:00:07 GMT</pubDate>
    <dc:creator>messenjah</dc:creator>
    <dc:date>2011-08-02T14:00:07Z</dc:date>
    <item>
      <title>Sorted result with mkl_dcsrcoo</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Sorted-result-with-mkl-dcsrcoo/m-p/778441#M1252</link>
      <description>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.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;[cpp]/*
 Matrix is

      1 0 2 0
 A =  0 0 3 0
      5 0 7 8

 nnz = 6, m = 3, n = 4
*/	
#include &lt;STDIO.H&gt;
#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, &amp;amp;m, acsr, ja, ia, &amp;amp;nnz, acoo, rowind, colind, &amp;amp;info);
	
	printf("info = %d", info);
	printf("\n AI=");
	for(i = 0; i &amp;lt;= m; i++) printf(" %3d", ia&lt;I&gt;);
	printf("\n AJ=");
	for(i = 0; i &amp;lt; m; i++)
	{
		printf(" |");
		for(j = ia&lt;I&gt;-job[1]; j &amp;lt; ia[i+1]-job[1]; j++) printf(" %3d", ja&lt;J&gt;);
	}
	printf(" |\n AX=");
	for(i = 0; i &amp;lt; m; i++)
	{
		printf(" |");
		for(j = ia&lt;I&gt;-job[1]; j &amp;lt; ia[i+1]-job[1]; j++) printf(" %3.1f", acsr&lt;J&gt;);
	}
	printf(" |\n");
	return 0;
}
[/cpp]&lt;/J&gt;&lt;/I&gt;&lt;/J&gt;&lt;/I&gt;&lt;/I&gt;&lt;/STDIO.H&gt;&lt;/PRE&gt; &lt;BR /&gt;&lt;BR /&gt;If I compile without -DZEROINDEX and -DSORT, I get the following output&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; which is expected i.e. the last row is correct although not sorted. If I include -DSORT then I get&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; which is also correct i.e. the last row is correct and sorted. Furthermore if I use the zero indexed version without sorting&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; I still get the correct conversion. But if I have both zero indexing and sorting, I get something rather unusual&lt;BR /&gt;&lt;PRE&gt;[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]&lt;/PRE&gt; I'm wondering if there's something I'm missing when using zero indexed arrays.</description>
      <pubDate>Tue, 02 Aug 2011 14:00:07 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Sorted-result-with-mkl-dcsrcoo/m-p/778441#M1252</guid>
      <dc:creator>messenjah</dc:creator>
      <dc:date>2011-08-02T14:00:07Z</dc:date>
    </item>
  </channel>
</rss>

