Intel MKL provides optional threading controls, that is, the environment variables and support functions that are independent of OpenMP. They behave similar to their OpenMP equivalents, but take precedence over them in the meaning that the MKL-specific threading controls are inspected first. By using these controls along with OpenMP variables, you can thread the part of the application that does not call Intel MKL and the library independently from each other.
These controls enable you to specify the number of threads for Intel MKL independently of the OpenMP settings. Although Intel MKL may actually use a different number of threads from the number suggested, the controls will also enable you to instruct the library to try using the suggested number when the number used in the calling application is unavailable.
Sometimes Intel MKL does not have a choice on the number of threads for certain reasons, such as system resources.
Use of the Intel MKL threading controls in your application is optional. If you do not use them, the library will mainly behave the same way as Intel MKL 9.1 in what relates to threading with the possible exception of a different default number of threads.
Section "Number of User Threads" in the "Fourier Transform Functions" chapter of the Intel MKL Reference Manual shows how the Intel MKL threading controls help to set the number of threads for the FFT computation.
The table below lists the Intel MKL environment variables for threading control, their equivalent functions, and OMP counterparts:
Environment Variable |
Support Function |
Comment |
Equivalent OpenMP* Environment Variable |
---|---|---|---|
MKL_NUM_THREADS |
mkl_set_num_threads |
Suggests the number of threads to use. |
OMP_NUM_THREADS |
MKL_DOMAIN_NUM_ |
mkl_domain_set_num_threads |
Suggests the number of threads for a particular function domain. |
|
MKL_DYNAMIC |
mkl_set_dynamic |
Enables Intel MKL to dynamically change the number of threads. |
OMP_DYNAMIC |
The functions take precedence over the respective environment variables.
Therefore, if you want Intel MKL to use a given number of threads in your application and do not want users of your application to change this number using environment variables, set the number of threads by a call to
mkl_set_num_threads(),
which will have full precedence over any environment variables being set.
The example below illustrates the use of the Intel MKL function mkl_set_num_threads() to set one thread.
// ******* C language ******* #include <omp.h> #include <mkl.h> ... mkl_set_num_threads ( 1 );
// ******* Fortran language ******* ... call mkl_set_num_threads( 1 )
See the Intel MKL Reference Manual for the detailed description of the threading control functions, their parameters, calling syntax, and more code examples.