Compiling C code with openmp using clang-cl

2019-05-31 21:23发布

问题:

I am trying to compile C code in Visual Studio using Clang-Cl (via llvm-vs2014 in the platform toolset) with openmp code. When I enable openmp with /openmp I get a warning in clang-cl.exe that it was not used during compilation and my test code confirms that openmp is not working.

In addition I've tried Clang 3.7 with Microsoft CodeGen but it doesn't appear to support openmp yet (as verified by code).

Switching to Visual Studio 2015 allows the code to work but my default code (without any openmp) runs 50% slower.

Is there some way of getting openmp to work with the llvm-vs2014 platform toolset? Should I be using something outside of visual studio to get this to work?

回答1:

You can use:

clang -Xclang -fopenmp -l .\libiomp5md.lib

(note, though, that this is not officially supported by Microsoft)

Obviously, you have to have a copy of OpenMP runtime library. You can get and build it from https://www.openmprtl.org/.

Alternatively, you can build clang compiler along with OpenMP RTL yourself, from http://clang.llvm.org/.