Developer Guide

Contents

Calling
Intel® MKL
Functions from Multi-threaded Applications

This section summarizes typical usage models and available options for calling
Intel® MKL
functions from multi-threaded applications. These recommendations apply to any multi-threading environments: OpenMP*, Intel® Threading Building Blocks,
POSIX* threads,
and others.

Usage model: disable
Intel® MKL
internal threading for the whole application

When used:
Intel® MKL
internal threading interferes with application's own threading or may slow down the application.
Example:
the application is threaded at top level, or the application runs concurrently with other applications.
Options:
  • Link statically or dynamically with the sequential library
  • Link with the Single Dynamic Library
    mkl_rt
    .
    so
    and select the sequential library using an environment variable or a function call:
    • Set
      MKL_THREADING_LAYER=sequential
    • Call
      mkl_set_threading_layer(MKL_THREADING_SEQUENTIAL)

Usage model: partition system resources among application threads

When used:
application threads are specialized for a particular computation.
Example:
one thread solves equations on all cores but one, while another thread running on a single core updates a database.
Linking Options:
  • Link statically or dynamically with a threading library
  • Link with the Single Dynamic Library
    mkl_rt
    .
    so
    and select a threading library using an environment variable or a function call:
    • set
      MKL_THREADING_LAYER=intel
      or
      MKL_THREADING_LAYER=tbb
    • call
      mkl_set_threading_layer(MKL_THREADING_INTEL)
      or
      mkl_set_threading_layer(MKL_THREADING_TBB)
Other Options
for OpenMP Threading
:
  • Set the
    MKL_NUM_THREADS
    environment variable to a desired number of OpenMP threads for
    Intel® MKL
    .
  • Set the
    MKL_DOMAIN_NUM_THREADS
    environment variable to a desired number of OpenMP threads for
    Intel® MKL
    for a particular function domain.
    Use if the application threads work with different
    Intel® MKL
    function domains.
  • Call
    mkl_set_num_threads()
    Use to globally set a desired number of OpenMP threads for
    Intel® MKL
    at run time.
  • Call
    mkl_domain_set_num_threads()
    .
    Use if at some point application threads start working with different
    Intel® MKL
    function domains.
  • Call
    mkl_set_num_threads_local()
    .
    Use to set the number of OpenMP threads for
    Intel® MKL
    called from a particular thread.
If your application uses OpenMP* threading, you may need to provide additional settings:
  • Set the environment variable
    OMP_NESTED=TRUE
    , or alternatively call
    omp_set_nested(1)
    , to enable OpenMP nested parallelism.
  • Set the environment variable
    MKL_DYNAMIC=FALSE
    , or alternatively call
    mkl_set_dynamic(0)
    , to prevent
    Intel® MKL
    from dynamically reducing the number of OpenMP threads in nested parallel regions.
For details of the mentioned functions, see the Support Functions section of the
Intel® MKL
Developer Reference
, available in the Intel Software Documentation Library.
Optimization Notice
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
This notice covers the following instruction sets: SSE2, SSE4.2, AVX2, AVX-512.

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