Developer Guide

Developer Guide for Intel® oneAPI Math Kernel Library macOS*

ID 766688
Date 7/13/2023
Public

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

Document Table of Contents

oneMKL-specific Environment Variables for OpenMP Threading Control

Intel® oneAPI Math Kernel Library (oneMKL) provides environment variables and support functions to control Intel® oneAPI Math Kernel Library (oneMKL) threading independently of OpenMP. The Intel® oneAPI Math Kernel Library (oneMKL)-specific threading controls take precedence over their OpenMP equivalents. Use the Intel® oneAPI Math Kernel Library (oneMKL)-specific threading controls to distribute OpenMP threads between Intel® oneAPI Math Kernel Library (oneMKL) and the rest of your program.

NOTE:

Some Intel® oneAPI Math Kernel Library (oneMKL) routines may use fewer OpenMP threads than suggested by the threading controls if either the underlying algorithms do not support the suggested number of OpenMP threads or the routines perform better with fewer OpenMP threads because of lower OpenMP overhead and/or better data locality. Set theMKL_DYNAMIC environment variable to FALSE or call mkl_set_dynamic(0) to use the suggested number of OpenMP threads whenever the algorithms permit and regardless of OpenMP overhead and data locality.

The table below lists the Intel® oneAPI Math Kernel Library (oneMKL) environment variables for threading control, their equivalent functions, and OMP counterparts:

Environment Variable

Support Function

Comment

Equivalent OpenMP* Environment Variable

MKL_NUM_THREADS

mkl_set_num_threads

mkl_set_num_threads_local

Suggests the number of OpenMP threads to use.

OMP_NUM_THREADS

MKL_DOMAIN_NUM_
THREADS

mkl_domain_set_num_threads

Suggests the number of OpenMP threads for a particular function domain.

 

MKL_DYNAMIC

mkl_set_dynamic

Enables Intel® oneAPI Math Kernel Library (oneMKL) to dynamically change the number of OpenMP threads.

OMP_DYNAMIC

NOTE:

Call mkl_set_num_threads()to force Intel® oneAPI Math Kernel Library (oneMKL) to use a given number of OpenMP threads and prevent it from reacting to the environment variablesMKL_NUM_THREADS, MKL_DOMAIN_NUM_THREADS, and OMP_NUM_THREADS.

The example below shows how to force Intel® oneAPI Math Kernel Library (oneMKL) to use one thread:


// ******* C language *******

#include <mkl.h>
...
mkl_set_num_threads ( 1 );
            

            
// ******* Fortran language *******
...
call mkl_set_num_threads( 1 )