Math Kernel Library Developer Guide

Techniques to Set the Number of Threads

Use the following techniques to specify the number of OpenMP threads to use in Intel® oneAPI Math Kernel Library:

Note

A call to the mkl_set_num_threads or mkl_domain_set_num_threadsfunction changes the number of OpenMP threads available to all in-progress calls (in concurrent threads) and future calls to Intel® oneAPI Math Kernel Library and may result in slow Intel® oneAPI Math Kernel Library performance and/or race conditions reported by run-time tools, such as Intel® Inspector.

To avoid such situations, use the mkl_set_num_threads_local function (see the "Support Functions" section in the Intel® oneAPI Math Kernel Library Developer Reference for the function description).

When choosing the appropriate technique, take into account the following rules:

If you use the Intel TBB threading technology, read the documentation for the tbb::task_scheduler_init class at https://www.threadingbuildingblocks.org/documentation to find out how to specify the number of threads.