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

Segmentation fault on declaring variable while using mkl for matrix vector multiplication

prakrati
Beginner
437 Views



Hello ,
I am trying to use mkl library to do matrix vector multiplication .When I am declaring a variable char t3 ,its giving segmentation fault
and when I am commenting it ,its running fine.Please help me debug this problem
I have bolded the line and wrote a comment on it to identify it.

The error that I am getting is as follows:Output :

./matrixVectorMultMKL2.o 10 10 1
Intializing.. size = 10
Performing multiplication 100 times..
Segmentation fault

Please help!!!





#include

#include
#include "mkl_cblas.h"
#include "mkl.h"
#include

#include
void DisplayVector(double *vector, int size)
{
int i;
for (i=0 ; i printf("%lf ",vector);
}
printf("\\n");
}

static inline unsigned long long getticks() {
unsigned int _hi,_lo;
__asm__ __volatile__("rdtsc":"=a"(_lo),"=d"(_hi));
return ((unsigned long long)_hi << 32) | _lo;
}

double getTimeInSeconds(long long ticks) {

// first calculate processor speed
long long t1,t2,processorSpeed;
double timeInSeconds;
t1 = getticks();

sleep(1);
t2 = getticks();
processorSpeed = t2 - t1;
// now calculate time
timeInSeconds = ((double) ticks) / ((double) processorSpeed);

//timeInSeconds = ((double) ticks) / CLOCKS_PER_SEC ;
return timeInSeconds;
}

int main(int argc,char *argv[])
{
int i, size = atoi(argv[1]);
//int i;
//int size = 3;
long long t1,t2;
double *matrix = (double *) mkl_malloc (size * size * sizeof(double),16);
double *vector = (double *) mkl_malloc (size * sizeof(double),16);
double *resultVector = (double *) mkl_malloc (size * sizeof(double),16);

char t3; //Segmentation fault is coming due to this line

printf("Intializing.. size = %d\\n",size);
for (i=0; i<(size*size); i++) {
//matrix = i+1;
matrix = 1;
}
for (i=0;i //vector = i+1;
vector = 1;
resultVector = 0;
}

/*
void cblas_dgemv(const CBLAS_ORDER order,
const CBLAS_TRANSPOSE TransA, const MKL_INT M, const MKL_INT N,
const double alpha, const double *A, const MKL_INT lda,
const double *X, const MKL_INT incX, const double beta,
double *Y, const MKL_INT incY);

typedef enum {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
typedef enum {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113} CBLAS_TRANSPOSE; */

mkl_set_num_threads ( 8 );
printf("Performing multiplication 100 times..\\n");

t1 = getticks();
//printf("t1 = %Ld\\n",t1);
for (i=0;i<100;i++) {
cblas_dgemv(CblasRowMajor, CblasNoTrans, size, size,1,matrix,size,vector,1,0,resultVector,1);
}
t2 = getticks();

//printf("Clock ticks required : %Ld\\n",t2 - t1);

//t = getTimeInSeconds(t2 - t1);

printf("Time for multiplication : %lf\\n",(getTimeInSeconds(t2 - t1)) / 100.0);

//printf("Result vector : ");
//DisplayVector(resultVector,size);

return 0;
}


0 Kudos
5 Replies
mecej4
Honored Contributor III
437 Views
Which OS, C compiler, what version of MKL, and what were the compiler options used?

With Intel C 11.1.073 (IA32 or intel64) on SuSE Linux 11.3, the program, copied exactly from your post, can be compiled and run with no error messages when compiled with "icc -mkl -O ".
0 Kudos
Gennady_F_Intel
Moderator
437 Views
Yes, more details will help to reproduce the problem.
I used to try with the latest Intel compiler v12 bundled ( aka Composer XE 2011). no problems..
--Gennady
0 Kudos
prakrati
Beginner
437 Views
I am compiling it with GCC .The version of gcc and mkl is as follows:
GCC version used : gcc (GCC) 3.4.6 20060404 (Red Hat 3.4.6-8)


MKL version used : /app/intel/mkl/10.2.5.035

gcc matrixVectorMultMKL3.c -Wall -L $(MKLPATH) -I $(MKLINCLUDE) -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm -o matrixVectorMultMKL3.o

When I compiled using your command ,it ran successfully so I am just confused why its not running with the previous command

Thanks and Regards
Prakrati
0 Kudos
Gennady_F_Intel
Moderator
437 Views
That's very strange. Please try to remove all mkl routines calling. Will then be the same result?
0 Kudos
mecej4
Honored Contributor III
437 Views
If you want to use ILP64 libraries, you probably have to tell GCC through suitable options that the default integer should be 64 bits.
0 Kudos
Reply