Developer Guide

Developer Guide for Intel® oneAPI Math Kernel Library Windows*

ID 766692
Date 3/31/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

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 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* run-time library (RTL) and Intel® Threading Building Blocks (oneTBB) RTL, several calls to Intel® oneAPI Math Kernel Library 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 the technology other than Intel OpenMP and oneTBB (for example: Win32* threads on Windows*).

If more than one thread calls Intel® oneAPI Math Kernel Library, and the function being called is threaded, it may be important that you turn off Intel® oneAPI Math Kernel Library threading. Set the number of threads to one by any of the available means (seeTechniques 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 simultaneous activities of multiple threading RTLs, link the program against the Intel® oneAPI Math Kernel Library threading library that matches the compiler you use (see Linking Exampleson how to do this). If this is not possible, use Intel® oneAPI Math Kernel Library in the sequential mode. To do this, you should link with the appropriate threading library:mkl_sequential.lib or mkl_sequential.dll (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 simultaneous activities of multiple threading RTLs, link the program against the Intel® oneAPI Math Kernel Library oneTBB threading library and oneTBB RTL if it matches the compiler you use. If this is not possible, use Intel® oneAPI Math Kernel Library in the sequential mode. To do this, link with the appropriate threading library:mkl_sequential.lib or mkl_sequential_dll.lib (see Appendix C: Directory Structure in Detail).

You run multiple programs calling Intel® oneAPI Math Kernel Library on a multiprocessor system, for example, a program parallelized using a message-passing interface (MPI).

The threading RTLs from different programs you run may place a large number of threads on the same processor on the system and therefore overuse the machine resources. In this case, one of the solutions is to set the number of threads to one by any of the available means (see Techniques to Set the Number of Threads). The Intel® Distribution for LINPACK* Benchmark section discusses another solution for a Hybrid (OpenMP* + MPI) mode.

Using the mkl_set_num_threads and mkl_domain_set_num_threadsfunctions to control parallelism of Intel® oneAPI Math Kernel Library 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 themkl_set_num_threads_local function (see the "Support Functions" section in the Intel® oneAPI Math Kernel Library 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