Search code examples
visual-c++versionopenmpintel-mkl

Can two different version of OpenMP coexist in the same executable?


I must use Microsoft Visual C++ 2013 to build a project that uses OpenMP and links to the Intel MKL library, which also uses OpenMP. The issue is that Visual C++ 2013 uses OpenMP 2.0, while MKL is built with OpenMP 4.x.

Everything seems to work fine, even if this could be a false impression.

I get some of these warnings:

warning C4005: 'HUGE_VALF' : macro redefinition

I cannot just disable these warnings. How can I fix them?


As indicated in the answers, I have to exclude Microsoft's own OpenMP implementation and use Intel's one only. So I added this to my CMakeLists.txt file:

# Disable Microsoft's default OpenMP v.2 inclusion
set_target_properties(${PROJECT_LIB} PROPERTIES LINK_FLAGS /nodefaultlib:vcomp)
set_target_properties(${PROJECT_LIB} PROPERTIES LINK_FLAGS /nodefaultlib:vcompd)
set_target_properties(${PROJECT_LIB} PROPERTIES LINK_FLAGS libiomp5md.lib)

However I still get the same warnings...


Solution

  • You need to be very careful and ensure that there is only a single OpenMP runtime library linked into your code. If you don't you are almost certain to get twice as many threads as you should have, and consequently over-subscription of the hardware and poor performance.

    Intel recognised this problem, so the Intel openMP runtime library ("libiomp5") provides the runtime interfaces needed by code compiled by the Microsoft compiler. You can therefore link against the Intel runtime and all should be well.