Minimum working example for mkl_ddnscsr

Minimum working example for mkl_ddnscsr

Hi. Can anyone provide me with a minimum working example for mkl_ddnscsr? I have tried this so far

#include <stdio.h>
#include <stdlib.h>
#include <mkl.h>
int main(int argc, char *argv[])
  MKL_INT info;
  MKL_INT m = 3; //Number of rows of A
  MKL_INT n = 4; //Number of columns of A
  MKL_INT nnz = 6; //Number of non zero elements
  MKL_INT job[6] = {0,0,1,2,nnz,1};
  double  *Acsr = (double *)  calloc(nnz, sizeof(double)  );
  MKL_INT *Aj   = (MKL_INT *) calloc(nnz, sizeof(MKL_INT) );
  MKL_INT *Ai   = (MKL_INT *) calloc(m+1, sizeof(MKL_INT) );
  double A[3][4] = {{1.,3.,0.,0.},{0.,0.,4.,0.},{2.,5.,0.,6.}};
  mkl_ddnscsr ( job, &m, &n, A[0], &m, Acsr, Aj, Ai, &info);
  for (int i=0; i< nnz; i++) {
    if (Acsr[i] != 0) {
      printf( "column = %i, A = %fn", Aj[i], Acsr[i] );
  for (int i=0; i< m+1; i++) {
    printf("Ai[%i] = %in", i, Ai[i]);
  return 0;

But it returns these results

column = 1, A = 1.000000
column = 2, A = 3.000000
column = 4, A = 4.000000
column = 1, A = 4.000000
column = 3, A = 2.000000
column = 4, A = 5.000000
Ai[0] = 1
Ai[1] = 3
Ai[2] = 4
Ai[3] = 7

If I play with the value for the lda I can almost get the correct result, however I believe this is as the manual suggests. I am on using Ubuntu 12.04 and Composer 2013.3.163 if that makes difference.



4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You have obtained the CSR representation of AT rather than of A. The reason is that your array A, being a native 2-D array in C, is arranged in row-major order. The library routine expects column-major order, which is the order used for 2-D arrays in Fortran.

also you can have a look at the mkl_ddnscsr example from the mkl's package: "mkl_install_dir\examples\spblasc\source\ dconverters.c"

Hey great. Thanks a lot guys. I have it working now. Both suggestions were very helpful. Now I can try to so some science. Thank you very much :-)

Leave a Comment

Please sign in to add a comment. Not a member? Join today