Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Gilbert_F_
Beginner
895 Views

Configure number of processors available to MKL NumPy

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
895 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.

RL5
Beginner
895 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?

Robert_C_Intel
Employee
895 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())"

 

RL5
Beginner
895 Views

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

Zhanwen_C_
Beginner
895 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())"

```

Reply