Developer Guide

Developer Guide for Intel® oneAPI Math Kernel Library Linux*

ID 766690
Date 3/22/2024
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 (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* run-time library (RTL) and Intel® Threading Building Blocks (oneTBB) RTL, 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 the 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 (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 (oneMKL) 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 (oneMKL) in the sequential mode. To do this, you should link with the appropriate threading library: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 simultaneous activities of multiple threading RTLs, link the program against the Intel® oneAPI Math Kernel Library (oneMKL) oneTBB threading library and oneTBB RTL if it matches the compiler you use. If this is not possible, use Intel® oneAPI Math Kernel Library (oneMKL) in the sequential mode. To do this, link with the appropriate threading library: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).

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 (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 themkl_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