GCC does not support binding to the Intel OpenMP runtime library. The GCC internal code transformer converts OpenMP directives to ligomp specific calls, and they have an API different from the one pointed to by libiomp . In addition, mixing two separate OpenMP delays into one executable file (or into one process if modules with OpenMP support load dynamically) is a recipe for disaster. This is the reason why the MKL multithreaded driver comes in two flavors: one Intel and one GNU. The fact that the latter is missing on some machines is probably a defect in the installation.
Edit: Obviously, Intel's OpenMP environment provides a level of compatibility with GNU, which means that it could be used as a replacement for libgomp . At least the characters:
$ nm libiomp5.a | sort | grep GOMP_ 0000000000000000 T GOMP_barrier@ @VERSION 0000000000000000 T GOMP_barrier@GOMP _1.0 0000000000000000 T __kmp_api_GOMP_barrier 0000000000000000 T __kmp_api_GOMP_barrier_10_alias ...
In this case, you need to do the following:
- save
-fopenmp when compiling the code so that GCC recognizes OpenMP pragmas and converts the code to the corresponding calls in libgomp ; - If GCC is used to link an executable or shared library, do not pass the
-fopenmp during the link phase; instead go -L/path/to/libiomp5 -liomp5 ; - If GNU ld is used to link the executable / module, replace
-lgomp with -liomp5 .
If you cannot make the above changes, the thread on the Intel forums makes sense because of the way linker resolves link to link links, although it is really more hacked. Passing -Wl,--as-needed causes GNU ld not to allocate DT_NEEDED tags for any library that follows it on the command line, unless that library satisfies the undefined symbolic link, assuming the GCC driver will insert -lgomp somewhere after provided by the user. The idea is to prevent libgomp from linking to the executable even when there are no unresolved references to GOMP_... , which usually should not be so, since all links, even those from dynamically loaded modules, must be executed by libiomp5 . Preventing libgomp from loading RTLD is important because it has some constructor routines that are called whether characters are imported or not, and things that can interfere with IOMP.
The reference link will not work on non-ELF systems such as OS X. The Mach-O link editor does not support --as-needed , although there may be a different mechanism to achieve the same result on this OS.
source share