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

Segmentation Fault when I include Thread Control

nunoxic
Beginner
217 Views
Hi,
I am compiling a simple BLAS program which has DGEMV. It works fine when I have no explicit thread control.

However, when I include

mkl_set_dynamic(1);
mkl_set_num_threads(4);
(C code)

just before the DGEMV call. The program doesn't compile and simply spits out "Segmentation Fault"

I have already tried ulimit -s unlimited and KMP_STACKSIZE but no use.

I am compiling using :

icc testing_dgemv.c -Wl,--start-group $MKLROOT/lib/intel64/libmkl_intel_lp64.a $MKLROOT/lib/intel64/libmkl_intel_thread.a $MKLROOT/lib/intel64/libmkl_core.a -Wl,--end-group -openmp -lpthread -lm

I also tried

icc testing_dgesv.c -mkl=parallel

Code :

#include
#include
int main()
{
int i, j,n,n2;
n=1500;
double* m = (double*)malloc( n*n*sizeof(double));
double* x = (double*)malloc( n*sizeof(double));
double* y = (double*)malloc( n*sizeof(double));

for(i=0;i{
x = (i+1)*(i+1)*1.00;
y = 0;
for(j=0;jm[i*n+j] = (i+j+2)*(j+1)*1.00;
}

mkl_set_dynamic(1);
mkl_set_num_threads(4);


cblas_dgemv(CblasRowMajor, CblasNoTrans, n, n, 1.0, m, n, x, 1, 0.0, y, 1);

return 0;
}



0 Kudos
1 Solution
barragan_villanueva_
Valued Contributor I
217 Views
Hi,

In previous postby Vipin there was not right suggestionabout using mkl_set_dynamic().
This function is needed if user needs nested parallelizm and allows or not 'soft' or 'hard' threading in MKL
(enables or disables dynamic adjustment of the number of threads).
See MKL doc.

As to the problem:
Please add all needed for the test header files:
stdlib.h for malloc
mkl.h or mkl_service.h for mkl_set_dynamic and mkl_set_num_thread.

After this correction the tests PASSED on requested 4-threads

OMP: Info #147: KMP_AFFINITY: Internal thread 0 bound to OS proc set {0,12}

OMP: Info #147: KMP_AFFINITY: Internal thread 3 bound to OS proc set {8,20}

OMP: Info #147: KMP_AFFINITY: Internal thread 2 bound to OS proc set {8,20}

OMP: Info #147: KMP_AFFINITY: Internal thread 1 bound to OS proc set {0,12}


View solution in original post

4 Replies
VipinKumar_E_Intel
217 Views

You may remove the mkl_set_dynamic(1) which is not required here, since you are already setting the the # of threads to be used by using mkl_set_num_threads(). Also, please include mkl.h.

--Vipin

barragan_villanueva_
Valued Contributor I
218 Views
Hi,

In previous postby Vipin there was not right suggestionabout using mkl_set_dynamic().
This function is needed if user needs nested parallelizm and allows or not 'soft' or 'hard' threading in MKL
(enables or disables dynamic adjustment of the number of threads).
See MKL doc.

As to the problem:
Please add all needed for the test header files:
stdlib.h for malloc
mkl.h or mkl_service.h for mkl_set_dynamic and mkl_set_num_thread.

After this correction the tests PASSED on requested 4-threads

OMP: Info #147: KMP_AFFINITY: Internal thread 0 bound to OS proc set {0,12}

OMP: Info #147: KMP_AFFINITY: Internal thread 3 bound to OS proc set {8,20}

OMP: Info #147: KMP_AFFINITY: Internal thread 2 bound to OS proc set {8,20}

OMP: Info #147: KMP_AFFINITY: Internal thread 1 bound to OS proc set {0,12}


nunoxic
Beginner
217 Views
Adding #include fixed it.
Thanks !
barragan_villanueva_
Valued Contributor I
217 Views
OK!

Without mkl_set_dynamic() is as a MKL FORTRAN function which requires argument passed by reference.

So, please add always correct header files and check your test with compiler -Wall option
Reply