Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will `mkl_set_num_threads` upper-bound to the number of CPU Threads?

In OpenBLAS, if you call openblas_set_num_threads asking for a number of threads which is to be higher than the number of CPU threads that you have, then the actual number of threads it will be set to use is your number of CPU Threads.

This can be seen in the source code

I am wondering if MKL has the same behavior? The docs do not explicitly mention it. but they do say:

The number specified is a hint, and Intel® MKL may actually use a smaller number.

like image 817
Lyndon White Avatar asked Feb 15 '20 09:02

Lyndon White


Video Answer


1 Answers

It seems to cap at the number of cores (not the number of threads). The code below ran on a 6-Core Intel Core i7:

julia> using MKL_jll

julia> get_max_threads() = ccall((:mkl_get_max_threads, libmkl_rt), Int32, ());

julia> set_max_threads(n) = ccall((:mkl_set_num_threads, libmkl_rt), Cvoid, (Ptr{Int32},), Ref(Int32(n)));

julia> get_max_threads()
6

julia> set_max_threads(4)

julia> get_max_threads()
4

julia> set_max_threads(8)

julia> get_max_threads() # maxed out at 6
6

julia> set_max_threads(24)

julia> get_max_threads() # maxed out at 6
6

julia> set_max_threads(1)

julia> get_max_threads()
1
like image 82
Kristoffer Carlsson Avatar answered Oct 18 '22 22:10

Kristoffer Carlsson