Calling
oneMKL Functions from Multi-threaded Applications
oneMKL
Functions from Multi-threaded ApplicationsThis section summarizes typical usage models and available options for calling
functions from multi-threaded applications. These recommendations apply to any multi-threading environments: OpenMP*, Intel® Threading Building Blocks,
Intel® oneAPI Math Kernel Library
POSIX* threads,
and others.
Usage model: disable
oneMKL internal threading for the whole application
oneMKL
internal threading for the whole applicationWhen used:
Intel® oneAPI Math Kernel Library
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 Librarymkl_rt.and select the sequential library using an environment variable or a function call:dylib
- SetMKL_THREADING_LAYER=sequential
- Callmkl_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 Librarymkl_rt.and select a threading library using an environment variable or a function call:dylib
- setMKL_THREADING_LAYER=intelorMKL_THREADING_LAYER=tbb
- callmkl_set_threading_layer(MKL_THREADING_INTEL)ormkl_set_threading_layer(MKL_THREADING_TBB)
Other Options
for OpenMP Threading
:- Set theMKL_NUM_THREADSenvironment variable to a desired number of OpenMP threads for.Intel® oneAPI Math Kernel Library
- Set theMKL_DOMAIN_NUM_THREADSenvironment variable to a desired number of OpenMP threads forfor a particular function domain.Intel® oneAPI Math Kernel LibraryUse if the application threads work with differentfunction domains.Intel® oneAPI Math Kernel Library
- Callmkl_set_num_threads()Use to globally set a desired number of OpenMP threads forat run time.Intel® oneAPI Math Kernel Library
- Callmkl_domain_set_num_threads().Use if at some point application threads start working with differentfunction domains.Intel® oneAPI Math Kernel Library
- Callmkl_set_num_threads_local().Use to set the number of OpenMP threads forcalled from a particular thread.Intel® oneAPI Math Kernel Library
If your application uses OpenMP* threading, you may need to provide additional settings:
- Set the environment variableOMP_NESTED=TRUE, or alternatively callomp_set_nested(1), to enable OpenMP nested parallelism.
- Set the environment variableMKL_DYNAMIC=FALSE, or alternatively callmkl_set_dynamic(0), to preventfrom dynamically reducing the number of OpenMP threads in nested parallel regions.Intel® oneAPI Math Kernel Library
‡
For details of the mentioned functions, see the Support Functions section of the
Intel® oneAPI Math Kernel Library
Product and Performance Information
|
---|
Performance varies by use, configuration and other factors. Learn more at
www.Intel.com/PerformanceIndex.
Notice revision #20201201
|