- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
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.
#include <stdio.h> #include <stdlib.h> #include <math.h> #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<n; j++) for ( i=0; i<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,&m,&n,Adns,&lda,Acsr,AJ,AI,&info); return 0; }
Regards
lggs
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I added the following lines to your code after line-54, and obtained correct results with MKL 11.2.4 and 11.3.3.
printf("Info from MKL call = %d\n",info); printf("AI array : "); for(i=0; i<=n; i++)printf(" %2d",AI); printf("\n"); printf("AJ array : "); for(i=0; i<nnz; i++)printf(" %2d",AJ); printf("\n"); for(i=0; i<nnz; i++)printf(" %7.2f",Acsr); printf("\n");
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:
#include <stdio.h> #include <stdlib.h> #include <math.h> #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<m*n; i++) Adns=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,&m,&n,Adns,&lda,Acsr,AJ,AI,&info); // storage query/dry run nnz= job[2] ? AI-1 : AI ; printf("info = %d, nnz = %d\n",info,nnz); for(i=0; i<=n; i++)printf(" %2d",AI); printf("\n"); AJ=(int *)malloc(nnz*sizeof(int)); Acsr=(double *)malloc(nnz*sizeof(double)); job[4]=nnz; job[5]=1; mkl_ddnscsr(job,&m,&n,Adns,&lda,Acsr,AJ,AI,&info); printf("Info from second call = %d\n",info); for(i=0; i<nnz; i++)printf(" %2d",AJ); printf("\n"); for(i=0; i<nnz; i++)printf(" %7.2f",Acsr); printf("\n"); return 0; }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Regards
Gerardo

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page