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

program sleep when set OMP_NUM_THREADS more than one

chao_n_
Beginner
1,056 Views

Dear all,

   I have written some codes with MKL, but recently I found this codes did not work if the set OMP_NUM_THREADS more than one. Here is an example code. I compile it with icc test.c -mkl. When I run ./a.out, it will keep running and in sleep status. It seems that openMP did not work well. How can I solve the problem?

#include <omp.h>
#include <stdio.h>
#include <mkl.h>
int main(){
	int nID=100;
	int nSNP=100;
	double *mMatrix = (double*) calloc(nID*nSNP,sizeof(double));
	double *AGmatrix = (double*) calloc(nID*nID,sizeof(double));
    const CBLAS_LAYOUT Layout=CblasRowMajor;
    double alpha=1;
    double beta=0;
    cblas_dgemm (Layout, CblasTrans, CblasNoTrans, nID, nID, nSNP, alpha, mMatrix, 
	nID, mMatrix, nID, beta, AGmatrix, nID);
} 

 

0 Kudos
10 Replies
Zhen_Z_Intel
Employee
1,056 Views

Hi Chao,

What's your version of MKL? I tested with 2017 beta, the program could work. Because you set value of beta to 0, the error might be caused by dgemm function. Please try with other value of input parameters.

If you would like to use threading, also try with mkl_set_num_thread(1), if there still remain same problem, it should be problem of dgemm function. Please download and use latest version of MKL to avoid this problem.

Best regards,
Fiona

0 Kudos
chao_n_
Beginner
1,056 Views

Fiona Z. (Intel) wrote:

Hi Chao,

What's your version of MKL? I tested with 2017 beta, the program could work. Because you set value of beta to 0, the error might be caused by dgemm function. Please try with other value of input parameters.

If you would like to use threading, also try with mkl_set_num_thread(1), if there still remain same problem, it should be problem of dgemm function. Please download and use latest version of MKL to avoid this problem.

Best regards,
Fiona

I have updated my MKL to 2017 beta. When I set  mkl_set_num_thread(1) in the script, it reported undefined reference to `mkl_set_num_thread'. How can I solve this problem?

0 Kudos
chao_n_
Beginner
1,056 Views

Fiona Z. (Intel) wrote:

Hi Chao,

What's your version of MKL? I tested with 2017 beta, the program could work. Because you set value of beta to 0, the error might be caused by dgemm function. Please try with other value of input parameters.

If you would like to use threading, also try with mkl_set_num_thread(1), if there still remain same problem, it should be problem of dgemm function. Please download and use latest version of MKL to avoid this problem.

Best regards,
Fiona

I have updated my MKL to 2017 beta. When I set  mkl_set_num_thread(1) in the script, it reported undefined reference to `mkl_set_num_thread'. How can I solve this problem?

0 Kudos
chao_n_
Beginner
1,056 Views

Fiona Z. (Intel) wrote:

Hi Chao,

What's your version of MKL? I tested with 2017 beta, the program could work. Because you set value of beta to 0, the error might be caused by dgemm function. Please try with other value of input parameters.

If you would like to use threading, also try with mkl_set_num_thread(1), if there still remain same problem, it should be problem of dgemm function. Please download and use latest version of MKL to avoid this problem.

Best regards,
Fiona

I have updated my MKL to 2017 beta. When I set  mkl_set_num_thread(1) in the script, it reported undefined reference to `mkl_set_num_thread'. How can I solve this problem?

0 Kudos
TimP
Honored Contributor III
1,056 Views

If you don't resolve mkl_set_num_threads (I think it requires the plural 's') when linking, it seems possible you aren't linking against MKL (maybe some other BLAS library).

The MKL library should also parse the environment variable MKL_NUM_THREADS so as to permit you to test whether your problem is associated with number of threads.  MKL or any OpenMP threaded library should respond to OMP_NUM_THREADS if no over-riding setting is present.

0 Kudos
Zhen_Z_Intel
Employee
1,056 Views

Hi Chao,

Tim is right. If you use MKL defined function but you still get error message -- "undefined reference" while you build program, that means you didn't link with MKL correctly. However, I noticed it seems you used incorrect function, the name should be "mkl_set_num_threads", not "mkl_set_num_thread". Sorry for my typing mistake that misled you, hope you didn't waste time for this.

If you would like to learn more information about how to use threading in MKL program, please follow article:
Intel MKL-specific Environment Variables for OpenMP Threading Control

Hope it would be helpful to you. Thank you.

Best regards,
Fiona

0 Kudos
chao_n_
Beginner
1,056 Views

Fiona Z. (Intel) wrote:

Hi Chao,

Tim is right. If you use MKL defined function but you still get error message -- "undefined reference" while you build program, that means you didn't link with MKL correctly. However, I noticed it seems you used incorrect function, the name should be "mkl_set_num_threads", not "mkl_set_num_thread". Sorry for my typing mistake that misled you, hope you didn't waste time for this.

If you would like to learn more information about how to use threading in MKL program, please follow article:
Intel MKL-specific Environment Variables for OpenMP Threading Control

Hope it would be helpful to you. Thank you.

Best regards,
Fiona

I have tried mkl_set_num_threads, it works well now. Now it seems that it can run with multi-threads, even when I use "export OMP_NUM_THREADS=4" in the shell.  Maybe some other things mislead it before. 

Another question, can I package the codes with MKL into R with R CMD SHLIB

0 Kudos
Zhen_Z_Intel
Employee
1,056 Views

Hi Chao,

Yes, you could use Intel MKL with R programming and compile with GNU/ICC for MKL project. Here are some link could guide you how to link MKL to R and compile in Linux system:

Using Intel® MKL with R
Quick Linking Intel® MKL BLAS, LAPACK to R

Hope it could be useful to you. Thanks.

Best regards,
Fiona

0 Kudos
chao_n_
Beginner
1,056 Views

Fiona Z. (Intel) wrote:

Hi Chao,

Yes, you could use Intel MKL with R programming and compile with GNU/ICC for MKL project. Here are some link could guide you how to link MKL to R and compile in Linux system:

Using Intel® MKL with R
Quick Linking Intel® MKL BLAS, LAPACK to R

Hope it could be useful to you. Thanks.

Best regards,
Fiona

 

Hi Fiona,

    In the "Extending R with Intel MKL", it tells a method suited to windows system with Rtools. But how can I achieve the same goal in the linux system?

0 Kudos
Zhen_Z_Intel
Employee
1,056 Views

Hi Chao,

You could write c/cpp file using MKL function and call from R directly. There's no necessary to install any tool in linux. Here's a link telling some way of call c file from R, https://www.r-bloggers.com/three-ways-to-call-cc-from-r/

Best regards,
Fiona

0 Kudos
Reply