- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm a bit confused about the method
mkl_get_max_threads()
According to the help documentation, it should return the number of physical cores (provided that dynamic adjustment is enabled).
However, when I run the code below on my 4-core machine, I get back "1" for "nT". How so?
if ( 1 == mkl_get_dynamic( ) )
{
long nT = mkl_get_max_threads();
mkl_set_num_threads( nT );
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi MiauCat,
Right, that should be the root cause. So you may reset the matrix
long nT = mkl_get_max_threads( );
mkl_set_num_threads( 1 );
<...some code...>
mkl_set_num_threads( nT );
The function is based on OpenMP function. so it detected the current OpenMP thread number. The documentation seems need to rewording. We will check this and fix them.
| The maximum number of threads for Intel MKL functions to use in internal parallel regions. |
Thank you!
Ying
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Right, generally, it returns physical cores. What is you CPU type or do you set OMP_NUM_THREAD in environment?
Could you please add the cpu check code as below and share your output?
or what exact MKL function are you calling? you may
export MKL_VERBOSE=1
run your exe.
and share the output
Best Regards,
Ying
MKLVersion Version;
mkl_get_version(&Version);
printf("Major version: %d\n",Version.MajorVersion);
printf("Minor version: %d\n",Version.MinorVersion);
printf("Update version: %d\n",Version.UpdateVersion);
printf("Product status: %s\n",Version.ProductStatus);
printf("Build: %s\n",Version.Build);
printf("Platform: %s\n",Version.Platform);
printf("Processor optimization: %s\n",Version.Processor);
printf("================================================================\n");
printf("\n");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Ying.
I've placed your code (plus a check for the environmental variables) in a separate piece of code and run it, and it seems to do the correct thing. However, the piece of code I've submitted earlier did return 1 for sure.
Unfortunately, that piece of code is scraped by now. I need to redo it for testing. It is not unlikely that the application (of which the code is only a small part of) set anything OMP related beforehand - but that (in theory) shouldn't influence the outcome, or should it?
Major version: 2017
Minor version: 0
Update version: 3
Product status: Product
Build: 20170413
Platform: Intel(R) 64 architecture
Processor optimization: Intel(R) Streaming SIMD Extensions 2 (Intel(R) SSE2) enabled processors
================================================================mkl_get_dynamic( ) returned: 1
mkl_get_max_threads( ) returned: 4
================================================================OMP_NUM_THREAD: -NOT SET-
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ying,
did some more testing and can reproduce my problem.
The reason I want to use mkl_get_max_threads( ) in a first place is to "reset" the threads to the normal situation after having it forced to use 1 thread only previosly. However, the moment I've set the mkl threads to 1, the according commands can not recover my physical cores anymore:
mkl_set_num_threads( 1 );
<...some code...>
if ( 1 == mkl_get_dynamic( ) )
{
<...debug output code...>
long nT = mkl_get_max_threads( );
mkl_set_num_threads( nT );
}
I do not reset the MKL threads because nT is still 1. The debug output is:
Major version: 2017 Minor version: 0 Update version: 3 Product status: Product Build: 20170413 Platform: Intel(R) 64 architecture Processor optimization: Intel(R) Streaming SIMD Extensions 2 (Intel(R) SSE2) enabled processors ================================================================ mkl_get_dynamic( ) returned: 1 mkl_get_max_threads( ) returned: 1 ================================================================ OMP_NUM_THREAD:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi MiauCat,
Right, that should be the root cause. So you may reset the matrix
long nT = mkl_get_max_threads( );
mkl_set_num_threads( 1 );
<...some code...>
mkl_set_num_threads( nT );
The function is based on OpenMP function. so it detected the current OpenMP thread number. The documentation seems need to rewording. We will check this and fix them.
| The maximum number of threads for Intel MKL functions to use in internal parallel regions. |
Thank you!
Ying
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ying,
thanks for clearing this up. Yes I also think that the documention needs a bit of update in this case - maybe with a nice example?
In particular the Description section was confusing in https://software.intel.com/en-us/mkl-developer-reference-fortran-mkl-get-max-threads where it currently just reads:
If the dynamic adjustment is enabled, the function returns the number of physical cores on your system.
But I also think there should be an example of "how to reset" properly in https://software.intel.com/en-us/mkl-developer-reference-fortran-mkl-set-num-threads.
A related question: In case the mkl_set_num_threads(); is called at higher level and outside "my" control, what to do?
Is it a valid or a stupid idea to use:
mkl_set_num_threads( really_high_value );
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi MiauCat,
thanks for the suggestion. The problem was escalated to our doc team.
About the mkl_set_num_threads( really_high_value ); is called at higher level and outside "my" control,
you can use mkl_get_max_threads() to get the really_high_value
or use mkl_set_num_threads( wanted number) to set the number.
If you want to get the number of physical cores of system, maybe use OpenMP function, OMP_GET_NUM_PROCS (OP).which should be ok in mkl application. ( for your reference https://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/302866
Best Regards,
Ying
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page