Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7158 Discussions

mkl_set_num_threads() or MKL_Set_Num_Threads()?

sspine
Beginner
1,905 Views

I need to set MKL_NUM_THREADS dynamically in my programm. MKL user manual tells me to use mkl_set_num_threads(), but this function always crash my program. I find another function in MKL header file, MKL_Set_Num_Threads(). When I use the latter one instead, it is OK.

0 Kudos
4 Replies
Naveen_G_Intel
Employee
1,905 Views

Hi,

You are right. I noticed this issue; there is mismatch between header file and documentation. I will work with MKL development team to correct it.

Thanks,

Naveen Gv

0 Kudos
Vladimir_Lunev
New Contributor I
1,905 Views
Quoting - sspine

I need to set MKL_NUM_THREADS dynamically in my programm. MKL user manual tells me to use mkl_set_num_threads(), but this function always crash my program. I find another function in MKL header file, MKL_Set_Num_Threads(). When I use the latter one instead, it is OK.


Hi!

Please use #include "mkl.h" in your code. It's obligatory operator if you would like to use mkl_set_num_threads.

Here are a few lines from MKL documentation:

#include mkl.h // Mandatory to make these definitions work!
mkl_set_num_threads(num); // Equivalent to omp_set_num_threads( int )
return_code = mkl_domain_set_num_threads( num, MKL_FFT );
. . . . .

-Vladimir

0 Kudos
sspine
Beginner
1,905 Views

Hi!

Please use #include "mkl.h" in your code. It's obligatory operator if you would like to use mkl_set_num_threads.

Here are a few lines from MKL documentation:

#include mkl.h // Mandatory to make these definitions work!
mkl_set_num_threads(num); // Equivalent to omp_set_num_threads( int )
return_code = mkl_domain_set_num_threads( num, MKL_FFT );
. . . . .

-Vladimir

I know it is OK to include "mkl.h", this is because "mkl_service.h" typedefine mk_set_num_threads as MKL_Set_Num_Threads. But both mkl_set_num_threads() and MKL_Set_Num_Threads() are available in MKL dll or so. It is not make sense to me mkl_set_num_threads() function will crash my application.

0 Kudos
Vladimir_Lunev
New Contributor I
1,905 Views
Quoting - sspine

I know it is OK to include "mkl.h", this is because "mkl_service.h" typedefine mk_set_num_threads as MKL_Set_Num_Threads. But both mkl_set_num_threads() and MKL_Set_Num_Threads() are available in MKL dll or so. It is not make sense to me mkl_set_num_threads() function will crash my application.

Ok, I see.

Due to MKL support C and Fortran (which have a different styles for parameters passing), we provide the separate entries for C and Fortran users. So mkl_set_num_threads() is for Fortran users and MKL_Set_Num_Threads() is for C-users.
You are trying to make a call to the Fortran function from C using C-interface.

-Vladimir

0 Kudos
Reply