Intel® Distribution for Python*
Engage in discussions with community peers related to Python* applications and core computational packages.

Configure number of processors available to MKL NumPy

Gilbert_F_
Beginner
2,056 Views

Is there a config file or a command line parameter to set the number of available processors for MKLnumpy to take advantage of?  

Thanks

0 Kudos
5 Replies
Anton_M_Intel
Employee
2,056 Views

Welcome to the forum and thank you for the question!

MKL uses the best number of threads by default, e.g. (on Windows):

> python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"
16

If you want to change it, set MKL_NUM_THREADS environment variable to specify the number of threads to run in parallel, e.g.:

> set MKL_NUM_THREADS=1
> python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"
1

Please see this blog for more information regarding recommended environment variable settings for multithreading MKL. Or refer to MKL threading control API here.

0 Kudos
RL5
Beginner
2,056 Views

Anton Malakhov (Intel) wrote:

> python -c "import ctypes; mkl_rt = ctypes.CDLL('mkl_rt.dll'); print mkl_rt.mkl_get_max_threads()"
16

 

How does one check the number of threads in linux?

0 Kudos
Robert_C_Intel
Employee
2,056 Views
For linux, you need to change the name of the shared library:
python -c "import ctypes; mkl_rt = ctypes.CDLL('libmkl_rt.so'); print(mkl_rt.mkl_get_max_threads())"

 

0 Kudos
RL5
Beginner
2,056 Views

Thanks Robert, I was missing the 'lib' part of the name.

0 Kudos
Zhanwen_C_
Beginner
2,056 Views

For future reference, on a Mac you simply change "mkl_rt.dll"/"libmkl_rt.so" to "libmkl_rt.dylib", like so:

 

```python

python -c "import ctypes; mkl_rt = ctypes.CDLL('libmkl_rt.dylib'); print(mkl_rt.mkl_get_max_threads())"

```

0 Kudos
Reply