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

segmentation fault

Bo_W_3
Beginner
583 Views

Hello everyone,

I am new usint MKL and get an "segmentation fault" error with my first MKL-programm. Can anyone help me?

My program computes:

A = alpha * B + beta * C

It should be very easy.  Segmentation fault happens at the function MKL_Domatadd.

Thanks,

Bo

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
#include <time.h>
#include "mkl.h"

int rows = 200;
int cols = 200;
double alphaB = 0.69;
double alphaC = 0.53;
//double alphaD = 0.34;

int main() {
    double *A, *B, *C;
    int i, r;

    A = (double *) mkl_malloc( rows * cols * sizeof( double ), 64);
    B = (double *) mkl_malloc( rows * cols * sizeof( double ), 64);
    C = (double *) mkl_malloc( rows * cols * sizeof( double ), 64);

    for ( i=0; i<rows * cols; i++) {
        B = (double) i;
        C = (double) sqrt(i);
//        D = (double) (i * i);
    }
    printf("after init \n");
    MKL_Domatadd ('r', 'n', 'n', rows, cols, alphaB, B, cols + 1, alphaC, C, cols + 1, A, cols + 1);
//    MKL_Domatadd ('r', 'n', 'n', rows, cols, 1, A, cols, alphaD, D, cols, A, cols);

    srand( time( NULL ) );
    r = rand() % (rows * cols);
    printf(" Value %g \n", A[ r ]);

    return 0;
}

 

0 Kudos
6 Replies
Zhang_Z_Intel
Employee
583 Views

Replace this line

MKL_Domatadd ('r', 'n', 'n', rows, cols, alphaB, B, cols + 1, alphaC, C, cols + 1, A, cols + 1);

with this

MKL_Domatadd ('r', 'n', 'n', rows, cols, alphaB, B, cols, alphaC, C, cols, A, cols);

The seg fault is because of the mistake in specifying the leading dimensions.

 

0 Kudos
Bo_W_3
Beginner
583 Views

Interesting, I have tried with MKL_Domatadd ('r', 'n', 'n', rows, cols, alphaB, B, cols, alphaC, C, cols, A, cols) before, but it didn't work.

And now, it works. Happy with that.

Thanks a lot. 

But if set rows and cols to 400, it doesn't work again.....

0 Kudos
Zhang_Z_Intel
Employee
583 Views

I couldn't reproduce the problem. Now I need more details from you to see why it didn't work:

* What are your OS and CPU type?

* Which version of MKL are you using?

* What compiler are you using? How do you build your code? How do you link with MKL?

0 Kudos
Bo_W_3
Beginner
583 Views

Probably due to OpenMP.... After i have replaced omp_get_wtime with other time function, it works perfectly, despite of how is the array size...

However, information about my system.

Os: Linux 2.6.32-358.23.2.el6.x86_64

CPU: Intel(R) Xeon(R) CPU E5-2680 0 @ 2.70GHz

MKL: intelmkl/10.2

Compiler: icc version 14.0.1

Path for include and link are set correctly

 

0 Kudos
Bo_W_3
Beginner
583 Views

Sorry, I have made a mistake.

I have written several versions of the same code. In my own home directory, I have called omp_get_wtime() to measure time.  If you replace

MKL_Domatadd ('r', 'n', 'n', rows, cols, alphaB, B, cols, alphaC, C, cols, A, cols);

with

time = omp_get_wtime();

MKL_Domatadd ('r', 'n', 'n', rows, cols, alphaB, B, cols, alphaC, C, cols, A, cols);

time = omp_get_wtime() - time;

Hopefully you can see that.

0 Kudos
Zhang_Z_Intel
Employee
583 Views

I inserted calls to omp_get_wtime() and I still did not see the problem. I'm using MKL 11.1.1 (the latest release). Other things (CPU, OS, compiler, etc.) are the same as yours. You are using MKL 10.2, which is old (released more than 3 years ago, probably). It could be a bug in 10.2, but the chance is low. Anyways, I'd suggest you try the latest release. You can download a 30-day free evaluation copy of the latest MKL from http://software.intel.com/en-us/intel-mkl

 

0 Kudos
Reply