Developer Guide for Intel® oneAPI Math Kernel Library for Linux*
Avoiding Conflicts in the Execution Environment
Certain situations can cause conflicts in the execution environment that make the use of threads in Intel® oneAPI Math Kernel Library (oneMKL) problematic. This section briefly discusses why these problems exist and how to avoid them.
If your program is parallelized by means other than Intel® OpenMP* runtime library and Intel® Threading Building Blocks (oneTBB) runtime library, several calls to Intel® oneAPI Math Kernel Library (oneMKL) may operate in a multithreaded mode at the same time and result in slow performance due to overuse of machine resources.
The following table considers several cases where the conflicts may arise and provides recommendations depending on your threading model:
Threading model |
Discussion |
|---|---|
You parallelize the program using a threading or parallel programming technology other than Intel OpenMP and oneTBB (for example: pthreads on Linux*). |
If more than one thread calls Intel® oneAPI Math Kernel Library (oneMKL) , and the function being called is threaded, it may be important that you turn off Intel® oneAPI Math Kernel Library (oneMKL) threading. Set the number of threads to one by any of the available means (see Techniques to Set the Number of Threads ). |
You parallelize the program using OpenMP directives and/or pragmas and compile the program using a non-Intel compiler. |
To avoid conflicts caused by multiple threading runtimes in the same application, link your application with the Intel® oneAPI Math Kernel Library (oneMKL) threading library that is compatible with the OpenMP runtime used by your application. If this is not possible, use Intel® oneAPI Math Kernel Library (oneMKL) in sequential mode by linking libmkl_sequential.a or libmkl_sequential.so (see Appendix C: Directory Structure in Detail). |
You thread the program using oneTBB threading technology and compile the program using a non-Intel compiler. |
To avoid conflicts caused by multiple threading runtimes in the same application, link your application with the Intel® oneAPI Math Kernel Library (oneMKL) oneTBB threading library and oneTBB runtime library. If this is not possible, use Intel® oneAPI Math Kernel Library (oneMKL) in sequential mode by linking libmkl_sequential.a or libmkl_sequential.so (see Appendix C: Directory Structure in Detail). |
You run multiple programs calling Intel® oneAPI Math Kernel Library (oneMKL) on a multiprocessor system, for example, a program parallelized using a message-passing interface (MPI). |
Using the mkl_set_num_threads and mkl_domain_set_num_threads functions to control parallelism of Intel® oneAPI Math Kernel Library (oneMKL) from parallel user threads may result in a race condition that impacts the performance of the application because these functions operate on internal control variables that are global, that is, apply to all threads. For example, if parallel user threads call these functions to set different numbers of threads for the same function domain, the number of threads actually set is unpredictable. To avoid this kind of data races, use the mkl_set_num_threads_local function (see the “Support Functions” section in the Intel® oneAPI Math Kernel Library (oneMKL) Developer Reference for the function description). |
Product and Performance Information |
|---|
Performance varies by use, configuration and other factors. Learn more at www.Intel.com/PerformanceIndex . Notice revision #20201201 |