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

MKL Python Libraries won't use all 4 processors

Jordan_N_
Beginner
391 Views

Hi, I use numpy for python that implements the MKL libraries in a lot of its linear algebra functions. I noticed that when i run my simulations, it doesn't use all 4 processors. Originally it only use 1 (it actually uses all 4, but only 25% of the system CPU power at any given time). I changed the environmental variable mkl_num_threads from 1 to 4, but now it only uses 50% of the total CPU cycles available. Actually if i set the number of threads to any value above 1 (tried 2, 3, 4, 6, and 8), it only uses 50% of the available cycles.

Any help would certainly be appreciated! 

0 Kudos
2 Replies
Dmitry_B_Intel
Employee
391 Views
Hi Jordan MKL may decide to use less threads than specified via env.var MKL_NUM_THREADS. You may tell it refrain from using less threads by setting env.var MKL_DYNAMIC=false. That CPU meter shows 25% migrating from cpu to cpu suggests that operating system tries to balance the load on the cpus by migrating threads of your application from cpu to cpu as the time goes. If you thread with OpenMP, you can tell the OpenMP runtime library to affinitize the threads of your application, thereby preventing their migration. This is attained by setting env.var KMP_AFFINITY, for example KMP_AFFINITY=compact. Description of the environment variables can be found in Intel Developer's Zone. Thanks Dima
0 Kudos
Zhang_Z_Intel
Employee
391 Views
Jordan, For more information on improving MKL performance using threading, please see this chapter in the User's Guide. The env-variables Dima mentioned in his reply can also be found in this chapter. Zhang
0 Kudos
Reply