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

Segmentation fault from a BLAS routine

stanleyimko
Beginner
898 Views
Dear all,

I am trying to implement a BLAS routine dsyrk with the following code. It was compiled successfully. But whenever I excute the output file, a Segmentation fault appears. I've checked the code from time to time and found no error. Please help. Thanks a lot.

The compilation line:
$ icpc syrk.cpp -L/libmkl_solver_ilp64.a -Wl,--start-group -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -openmp -lpthread -o syrk.out

The source code:
#include

extern "C"
{
#include "mkl.h"
}

using namespace std;

/********C := alpha * A'A + beta * C*********/
int main()
{
/* 2x3 matrix A
3 7 2
4 1 9
*/

const CBLAS_ORDER order = CblasRowMajor;
const CBLAS_TRANSPOSE trans = CblasTrans;
const CBLAS_UPLO uplo = CblasUpper;

const int N = 3; // the order of the matrix C
const int K = 2; // when trans = 'T', K is the number of rows of A
const double alpha = 1.0;
const double a[6] = {3.0, 7.0, 2.0, 4.0, 1.0, 9.0};
const int lda = 2; // the first dimension of A
const double beta = 0.0;
double c[9] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0} ;
const int ldc = 3;

cblas_dsyrk(order, uplo, trans, N, K, alpha, a, lda, beta, c, ldc);

for( int i = 0; i < 9; i++ )
cout << c << " ";
cout << endl;

return 0;
}

Stanley KO
0 Kudos
1 Solution
barragan_villanueva_
Valued Contributor I
898 Views
Hi,

It looks like root cause of your problem is related to LP64/ILP64.

If you linked with ILP64 MKL libraries you need to add compiler option -DMKL_ILP64 for C-compilation

Or please try to use LP64 model:

-L$MKLPATH $MKLPATH/libmkl_solver_lp64.a -Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -openmp -lpthread

Please seealso thread: http://software.intel.com/en-us/forums/showthread.php?t=76101&o=d&s=lr

View solution in original post

0 Kudos
5 Replies
barragan_villanueva_
Valued Contributor I
899 Views
Hi,

It looks like root cause of your problem is related to LP64/ILP64.

If you linked with ILP64 MKL libraries you need to add compiler option -DMKL_ILP64 for C-compilation

Or please try to use LP64 model:

-L$MKLPATH $MKLPATH/libmkl_solver_lp64.a -Wl,--start-group -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core -Wl,--end-group -openmp -lpthread

Please seealso thread: http://software.intel.com/en-us/forums/showthread.php?t=76101&o=d&s=lr
0 Kudos
stanleyimko
Beginner
898 Views
Dear Victor,

Thanks for your reply. I have tried both link in compilation. But the Error now becomes

MKL ERROR: Parameter 8 was incorrect on entry to cblas_dsyrk

I have checked the code and the BLAS manual but found no mistake in the input. Still don't know what's wrong.

Thanks.

Stanley KO
0 Kudos
stanleyimko
Beginner
898 Views
Dear Victor,

I've tried to set lda = 3 and it works. But I am so confused since according to the manual it should not be 3.

lda INTEGER. Specifies the first dimension of a as declared in
the calling (sub)program. When trans = 'N' or 'n', then
lda must be at least max(1,n), otherwise lda must be at
least max(1, k).

And the first dimension of my A is 2. Anyway, thanks for you kind help.

Regards,

Stanley KO
0 Kudos
barragan_villanueva_
Valued Contributor I
898 Views
Hi,

Well, it's not so simple to use CBLAScorrectly passing LDA etc...
0 Kudos
mecej4
Honored Contributor III
898 Views
C stores 2-D arrays by rows; Fortran, which underlies much of BLAS/LAPACK, stores by columns.

The C interface to MKL has to know how many columns there are in the actual matrix being passed as a 1-D array. In your example, there are 3 columns.
0 Kudos
Reply