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

Help, mkl_dcsrgemv

Camuso__Marco
Beginner
1,462 Views

Hi and thanks for the attention! I'm a beginner and i would like to use the mkl library for my thesis. I must use the function mkl_dcsrgemv, but there are always the error: "segmentation error(core dump created)". The code used is the following and i don't see the error. Someone can help me?

code:

#include <stdio.h>

#include "mkl.h"

int main() {

   double *val,*x,*y;
   int *I,*J;
   int k;
   int M;
   char transa='N';
   M=4;
   
   val=(double *) calloc(M,sizeof(double));
   x=(double *) calloc(M,sizeof(double));
   y=(double *) calloc(M,sizeof(double));


   I=(int *) calloc (M,sizeof(int));
   J=(int *) calloc(M,sizeof(int));
   
   for(k=0;k<M;++k){
   
      val=2;
      x=2;
      J=k+1;
      I=k+1;   
   }
   
   I[M+1]=M+1;
   
  mkl_dcsrgemv(&transa,&M,val,I,J,x,y);
 
  printf("\n il vettore y: \n");
 
  for(k=0;k<M;++k){
    
      printf(" %lf \t %lf \n",val,y);
  }
  return 0;

}

0 Kudos
3 Replies
Gennady_F_Intel
Moderator
1,462 Views

which version of mkl do you use?

I release only all dynamically allocated arrays and linked against mkl 2020. it works

$ ./a.out

 il vettore y:
 2.000000        4.000000
 2.000000        4.000000
 2.000000        4.000000
 2.000000        0.000000
 

0 Kudos
mecej4
Honored Contributor III
1,462 Views

Since I is of length M, valid subscripts for I are integers from 0 to M-1, inclusive.

You are attempting to store into I[M+1], which is an invalid memory access.

0 Kudos
Gennady_F_Intel
Moderator
1,459 Views

are there any updates? Do you still see the segfault?


0 Kudos
Reply