colinfang
colinfang

Reputation: 21727

Is mkl_set_num_threads() capped by the number of physical cores?

In one PC I have an Intel i7 4790 which has 4 cores and 8 threads. Whenever I use mkl.set_num_threads(n) where the n > 4, it is set to 4 when I check it later from mkl.get_max_threads(). This makes sense as MKL doesn't benefit from Hyper Threading.

In another PC I have an Intel Xeon E5 2643 which also has 4 cores and 8 threads. However this time it is possible to set the number of threads to be 8. Why is that?

In both machines, if I mkl.set_num_threads(2), mkl.get_max_threads() returns 2 as expected.

Upvotes: 4

Views: 2126

Answers (1)

Swastik Padhi
Swastik Padhi

Reputation: 1909

Straight from: the documentation for mkl_get_max_threads:

int mkl_get_max_threads (void);

This function returns the number of OpenMP threads for Intel MKL to use in internal parallel regions. This number depends on whether dynamic adjustment of the number of threads by Intel MKL is disabled (by an environment setting or in a function call):

If the dynamic adjustment is disabled, the function inspects the environment settings and return values of the function calls below in the order they are listed until it finds a non-zero value:

  1. A call to mkl_set_num_threads_local
  2. The last of the calls to mkl_set_num_threads or mkl_domain_set_num_threads( …, MKL_DOMAIN_ALL)
  3. The MKL_DOMAIN_NUM_THREADS environment variable with the MKL_DOMAIN_ALL tag
  4. The MKL_NUM_THREADS environment variable
  5. A call to omp_set_num_threads
  6. The OMP_NUM_THREADS environment variable

If the dynamic adjustment is enabled, the function returns the number of physical cores on your system. The number of threads returned by this function is a hint, and Intel MKL may actually use a different number.

Upvotes: 4

Related Questions