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

OpenMP with gcc and vc++

david_blankenship
519 Views

I have an application that currently uses MKL that I am making multicore ready with the addition of OpenMP. This application is built on Windows using the Microsoft VC++ compiler and on Linux using the GCC compiler. I have found some information on threading and MKL, but it is less than clear what the ramifications are and what the proper course of action should be.

I don't really need to have the MKL routines threaded. I do need to know what MKL routines are not thread safe so I can synchronize access to those. Does the non-threaded version of MLK work correctly with threaded applications that are not built with the Intel compiler? Incorrect answers or program failure is not an acceptable option.

From the MKL product page:

All Intel MKL functions are thread-safe. A non-threaded version of Intel MKL is also available

From the MKL issues page:

The Intel Math Kernel Library is designed and compiled for thread safety so it can be called from programs that are threaded. Calling Intel MKL routines that are threaded from multiple application threads can lead to conflict (including incorrect answers or program failures), if the calling library differs from the Intel MKL threading library.

From the MKL forum:

http://software.intel.com/en-us/forums//topic/54344

0 Kudos
4 Replies
TimP
Honored Contributor III
519 Views
Yes, that's my understanding, the serial (non-threaded) MKL can be called safely from a threaded application, regardless of the threading library. All MKL functions should be thread safe, as long as the threaded MKL is not used in an application built with an incompatible threading library..
0 Kudos
daben
Beginner
519 Views
I have had problems with this also on Linux. My understanding is that he MKL libraries are thread safe. But, I am finding that is not true. Try this example -- place vcExp within an openmp block, run it with omp_num_threads 1 and 2. You will get 2 different answers.
0 Kudos
Intel_C_Intel
Employee
519 Views

Well, let's make sure that we use common terms. Thread-safety means that each instance thread has its own set of parameters which will not be affected by the operations of other threads. For instance, if you have a for loop over i, and you thread it, you want to make sure that each thread has its own copy of iand that each thread changes i only for itself.

But there is no assurance that when you run threaded you can expect the same answers as when you run sequentially. However, for a vector function such as vcExp there should be no threading dependencies since all of the computation of the complex exponential of the input will be completed on a single thread.

Can you provide an example of the code where you noticed this issue so we can try it out?

Thanks,

Bruce

0 Kudos
Intel_C_Intel
Employee
519 Views

If you are threading your application and using a compiler other than the Intel compiler at the current time you will want to use the sequential version of MKL. The downside to this is that if you call a threaded MKL function from a non-threaded section of you code, you will not see the parallel benefits of the threaded MKL code you would normally expect. On the other hand, if you call MKL for threaded regions, everything will work just fine. And you will not have issues that can arise from having two runtime libraries (compiler threading library and libguide) each supplying the OpenMP functions called from your program and MKL. Furthermore the number of threads created will not get out of hand since only one threading library is performing that task.

MKL 10.0 will have a solution to this issue that will allow you to thread your application using some non-Intel compilers and still use threaded MKL.

Bruce

0 Kudos
Reply