<?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 Problem with mkl_ddnscsr in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068712#M22091</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;

&lt;P&gt;I’ve been having some problems using the “mkl_ddnscsr” function. I’ve followed the example that comes with the library but it’s not working properly. I can retrieve the non-zero elements in the dense matrix but the row and column vectors are returned empty (all elements are zeros). Below you can find my code; it’s a simplified version of the example in “dconverters.c”. I also have another doubt, what would be the most efficient way to use this function when working with large matrices and the number of non-zero elements is unknown; one way could be to set the a really high number for the maximum number of non-zero elements but that could lead to pre-allocating large vectors. Any help would be much appreciated.&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
#include "mkl_types.h"
#include "mkl_spblas.h"

int main (void)
{

#define M      4
#define N      4
#define LDA    4
#define NZMAX  8
#define NNZ    8
#define MBLK   2
#define NN     2
#define INFO   0
#define MN     16
#define IBASE1 1
#define IBASE2 1
#define LOCAT  2
#define IDIAG 3
#define NDIAG 4
#define INDIA 12
int		m = M, n=N, lda=LDA, nzmax=NZMAX, nnz = NNZ, mblk=MBLK, nn=NN, info=INFO ,mn=MN;
int	    ibase1 = IBASE1, ibase2 = IBASE2, locat = LOCAT, idiag = IDIAG, ndiag = NDIAG;
double	Adns[MN];
double	Acsr[NZMAX];
int		AI[M+1];
int		AJ[NZMAX];
int		i, j;
int		job[8];

job[0]=0;
job[1]=0;
job[2]=1;
job[3]=2;
job[4]=NZMAX;
job[5]=3;
		
for ( j=0; j&amp;lt;n; j++)
         for ( i=0; i&amp;lt;m; i++)
               Adns[i + lda*j]=0.0;

      Adns[0]=5.0;
      Adns[1]=9.0;
      Adns[4]=8.0;
      Adns[5]=2.0;
      Adns[10]=3.0;
      Adns[11]=1.0;
      Adns[14]=6.0;
      Adns[15]=4.0;
	  
mkl_ddnscsr(job,&amp;amp;m,&amp;amp;n,Adns,&amp;amp;lda,Acsr,AJ,AI,&amp;amp;info);

return 0;
}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;

&lt;P&gt;lggs&lt;/P&gt;</description>
    <pubDate>Fri, 20 May 2016 10:09:30 GMT</pubDate>
    <dc:creator>Gerardo_G_</dc:creator>
    <dc:date>2016-05-20T10:09:30Z</dc:date>
    <item>
      <title>Problem with mkl_ddnscsr</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068712#M22091</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;

&lt;P&gt;I’ve been having some problems using the “mkl_ddnscsr” function. I’ve followed the example that comes with the library but it’s not working properly. I can retrieve the non-zero elements in the dense matrix but the row and column vectors are returned empty (all elements are zeros). Below you can find my code; it’s a simplified version of the example in “dconverters.c”. I also have another doubt, what would be the most efficient way to use this function when working with large matrices and the number of non-zero elements is unknown; one way could be to set the a really high number for the maximum number of non-zero elements but that could lead to pre-allocating large vectors. Any help would be much appreciated.&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
#include "mkl_types.h"
#include "mkl_spblas.h"

int main (void)
{

#define M      4
#define N      4
#define LDA    4
#define NZMAX  8
#define NNZ    8
#define MBLK   2
#define NN     2
#define INFO   0
#define MN     16
#define IBASE1 1
#define IBASE2 1
#define LOCAT  2
#define IDIAG 3
#define NDIAG 4
#define INDIA 12
int		m = M, n=N, lda=LDA, nzmax=NZMAX, nnz = NNZ, mblk=MBLK, nn=NN, info=INFO ,mn=MN;
int	    ibase1 = IBASE1, ibase2 = IBASE2, locat = LOCAT, idiag = IDIAG, ndiag = NDIAG;
double	Adns[MN];
double	Acsr[NZMAX];
int		AI[M+1];
int		AJ[NZMAX];
int		i, j;
int		job[8];

job[0]=0;
job[1]=0;
job[2]=1;
job[3]=2;
job[4]=NZMAX;
job[5]=3;
		
for ( j=0; j&amp;lt;n; j++)
         for ( i=0; i&amp;lt;m; i++)
               Adns[i + lda*j]=0.0;

      Adns[0]=5.0;
      Adns[1]=9.0;
      Adns[4]=8.0;
      Adns[5]=2.0;
      Adns[10]=3.0;
      Adns[11]=1.0;
      Adns[14]=6.0;
      Adns[15]=4.0;
	  
mkl_ddnscsr(job,&amp;amp;m,&amp;amp;n,Adns,&amp;amp;lda,Acsr,AJ,AI,&amp;amp;info);

return 0;
}&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;

&lt;P&gt;lggs&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 10:09:30 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068712#M22091</guid>
      <dc:creator>Gerardo_G_</dc:creator>
      <dc:date>2016-05-20T10:09:30Z</dc:date>
    </item>
    <item>
      <title>I added the following lines</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068713#M22092</link>
      <description>&lt;P&gt;I added the following lines to your code after line-54, and obtained correct results with MKL 11.2.4 and 11.3.3.&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;printf("Info from MKL call = %d\n",info);
printf("AI array : "); for(i=0; i&amp;lt;=n; i++)printf(" %2d",AI&lt;I&gt;); printf("\n");
printf("AJ array : "); for(i=0; i&amp;lt;nnz; i++)printf(" %2d",AJ&lt;I&gt;); printf("\n");
for(i=0; i&amp;lt;nnz; i++)printf(" %7.2f",Acsr&lt;I&gt;); printf("\n");
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;Regarding your second question, note that there is provision for making a "dry run" or "storage query" call by setting job[5]=0 with job[4] uninitialized, to find the value of nnz. Following this, you can allocate the Acsr and AJ arrays to their correct sizes, set job[4]=nnz, job[5]=1, and call the routine again, for a "wet run". Here is a complete example:&lt;/P&gt;

&lt;PRE class="brush:cpp;"&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;math.h&amp;gt;
#include "mkl_types.h"
#include "mkl_spblas.h"
#include "mkl_service.h"

int main (void){
int		m, n, lda, nzmax, nnz, info;
double	*Adns;
double	*Acsr=NULL;  // to be allocated
int		*AI;
int		*AJ=NULL;    // to be allocated
int		i, j;
int		job[6]; char buf[200];

mkl_get_version_string(buf,200);
printf("%s\n",buf);

job[0]=0;  // Dense to CSR
job[1]=0;  // 0-based indexing for Adns -- not used, really
job[2]=1;  // 1-based indexing for Acsr
job[3]=2;  // whole matrix in A
job[4]=0;  // first call will inquire for n_nz
job[5]=0;  // first call will inquire for n_nz
		
m=n=lda=4; 
Adns=(double *)(malloc(m*n*sizeof(double)));
for ( i=0; i&amp;lt;m*n; i++) Adns&lt;I&gt;=0.0;

Adns[0]=5.0;
Adns[1]=9.0;
Adns[4]=8.0;
Adns[5]=2.0;
Adns[10]=3.0;
Adns[11]=1.0;
Adns[14]=6.0;
Adns[15]=4.0;

AI=(int *)malloc((n+1)*sizeof(int));
mkl_ddnscsr(job,&amp;amp;m,&amp;amp;n,Adns,&amp;amp;lda,Acsr,AJ,AI,&amp;amp;info);  // storage query/dry run
nnz= job[2] ? AI&lt;N&gt;-1 : AI&lt;N&gt;;
printf("info = %d, nnz = %d\n",info,nnz);
for(i=0; i&amp;lt;=n; i++)printf(" %2d",AI&lt;I&gt;); printf("\n");
AJ=(int *)malloc(nnz*sizeof(int));
Acsr=(double *)malloc(nnz*sizeof(double));
job[4]=nnz; job[5]=1;
mkl_ddnscsr(job,&amp;amp;m,&amp;amp;n,Adns,&amp;amp;lda,Acsr,AJ,AI,&amp;amp;info);
printf("Info from second call = %d\n",info);
for(i=0; i&amp;lt;nnz; i++)printf(" %2d",AJ&lt;I&gt;); printf("\n");
for(i=0; i&amp;lt;nnz; i++)printf(" %7.2f",Acsr&lt;I&gt;); printf("\n");
return 0;
}
&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/N&gt;&lt;/N&gt;&lt;/I&gt;&lt;/PRE&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 12:28:00 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068713#M22092</guid>
      <dc:creator>mecej4</dc:creator>
      <dc:date>2016-05-20T12:28:00Z</dc:date>
    </item>
    <item>
      <title>Thanks for your help! The</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068714#M22093</link>
      <description>&lt;P&gt;Thanks for your help! The code I was using to print the answers was wrong (I have very limited experience with C++). I assumed there was a problem because I was also trying to call the mkl_ddnscsr function from Matlab using the SDL and I keep getting all zeros (for the row and column vectors), so I assumed I was doing something wrong from the beginning; at least now I know the correct way to use the function. I'll have to keep struggling with Matlab.&lt;/P&gt;

&lt;P&gt;Regards&lt;/P&gt;

&lt;P&gt;Gerardo&lt;/P&gt;

&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 May 2016 14:44:51 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Problem-with-mkl-ddnscsr/m-p/1068714#M22093</guid>
      <dc:creator>Gerardo_G_</dc:creator>
      <dc:date>2016-05-20T14:44:51Z</dc:date>
    </item>
  </channel>
</rss>

