Developer Guide

Contents

Techniques to Set the Number of Threads

Use the following techniques to specify the number of OpenMP threads to use in
Intel® MKL
:
  • Set one of the OpenMP or
    Intel® MKL
    environment variables:
    • OMP_NUM_THREADS
    • MKL_NUM_THREADS
    • MKL_DOMAIN_NUM_THREADS
  • Call one of the OpenMP or
    Intel® MKL
    functions:
    • omp_set_num_threads()
    • mkl_set_num_threads()
    • mkl_domain_set_num_threads()
    • mkl_set_num_threads_local()
A call to the
mkl_set_num_threads
or
mkl_domain_set_num_threads
function changes the number of OpenMP threads available to all in-progress calls (in concurrent threads) and future calls to
Intel® MKL
and may result in slow
Intel® MKL
performance and/or race conditions reported by run-time tools, such as Intel® Inspector.
To avoid such situations, use the mkl_set_num_threads_local function (see the "Support Functions" section in the
Intel® MKL
Developer Reference
for the function description).
When choosing the appropriate technique, take into account the following rules:
  • The
    Intel® MKL
    threading controls take precedence over the OpenMP controls because they are inspected first.
  • A function call takes precedence over any environment settings. The exception, which is a consequence of the previous rule, is that a call to the OpenMP subroutine
    omp_set_num_threads()
    does not have precedence over the settings of
    Intel® MKL
    environment variables such as
    MKL_NUM_THREADS
    . See Using Additional Threading Control for more details.
  • You cannot change run-time behavior in the course of the run using the environment variables because they are read only once at the first call to
    Intel® MKL
    .
If you use the Intel TBB threading technology, read the documentation for the
tbb::task_scheduler_init
class at https://www.threadingbuildingblocks.org/documentation to find out how to specify the number of threads.

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804