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

Multithreading (BLAS sgemm)

Matthias_L_
Beginner
1,562 Views

Dear Forum,

I am trying to make MKL accelerate a matrix multiplication for me. It works, but MKL insists on doing it with a single thread. I played around a bit. But regardless of what I do - even when multiplying two randomly initialized 10000x10000 matrices - MKL does not use multiple threads. Am I missing something?

Function:

BLAS sgemm, via libmkl_rt.so

 

Environment settings:

MKL_NUM_THREADS=8; export MKL_NUM_THREADS
OMP_NUM_THREADS=8; export OMP_NUM_THREADS
MKL_DYNAMIC=FALSE; export MKL_DYNAMIC
OMP_DYNAMIC=FALSE; export OMP_DYNAMIC
MKL_DOMAIN_NUM_THREADS=MKL_DOMAIN_ALL,8; export MKL_DOMAIN_NUM_THREADS
OMP_DOMAIN_NUM_THREADS=MKL_DOMAIN_ALL,8; export OMP_DOMAIN_NUM_THREADS

 

Machine:

LinuxMint 17.2, Kernel: 3.19.0-26, CPU: 4th gen. i7, HT activated in BIOS

 

0 Kudos
1 Solution
Ying_H_Intel
Employee
1,562 Views

Hi Matthias L.

Do you have any result if MKL_VERBOSE=1 ?   Or are you calling sgemm in one multi-thread application? 

In some of situation, the MKL may not spawns threads as external threads. 

https://software.intel.com/en-us/articles/recommended-settings-for-calling-intelr-mkl-routines-from-multi-threaded-applications

Best Regards,

Ying 

 

View solution in original post

0 Kudos
4 Replies
Roman_D_Intel1
Employee
1,562 Views

Hi Matthias, how do you check that MKL runs single-threaded? Also, can you please show your LD_LIBRARY_PATH?

Usually setting OMP_NUM_THREADS is not even necessary since when it is not set, the Intel OpenMP library would use all the CPUs in the process CPU mask which is set to all CPUs by default.

0 Kudos
Gennady_F_Intel
Moderator
1,562 Views

please set the environment variable MKL_VERBOSE=1 to check how many threads has been used while ?gemm was called.

0 Kudos
Ying_H_Intel
Employee
1,563 Views

Hi Matthias L.

Do you have any result if MKL_VERBOSE=1 ?   Or are you calling sgemm in one multi-thread application? 

In some of situation, the MKL may not spawns threads as external threads. 

https://software.intel.com/en-us/articles/recommended-settings-for-calling-intelr-mkl-routines-from-multi-threaded-applications

Best Regards,

Ying 

 

0 Kudos
Matthias_L_
Beginner
1,562 Views

Thanks for your comments and sorry that it took so long. I got it working properly now. There was some conflict with the LD_LBIRARY_PATH. Instead the system loaded the another BLAS implementation that I had installed. Why that was I cannot tell. I can hereby confirm that the MK_VERBOSE is very helpful for diagnosing issues. And that

MKL_NUM_THREADS=8; export MKL_NUM_THREADS

OMP_NUM_THREADS=8; export OMP_NUM_THREADS

MKL_DYNAMIC=FALSE; export MKL_DYNAMIC

OMP_DYNAMIC=FALSE; export OMP_DYNAMIC

produces the right results one would expect (if one loads the right runtime library).

~Matthias

0 Kudos
Reply