-
Notifications
You must be signed in to change notification settings - Fork 13
Using OpenMP with clang compiler
The clang compiler as installed on most Linux systems does not compile OpenMP out of the box, because the clang specific omp.h
header file and the libomp.so
runtime library are not in the system path. To get these files, the best option is to obtain the clang source and compile the OpenMP runtime library yourself (see this dedicated web page).
The next step is to note down some system paths. In your custom clang installation, find the path to
- the folder where
omp.h
is located (withoutomp.h
itself; this should beLLVM_BUILD_PATH/projects/openmp/runtime/src/
) - the folder where
libomp.so
is located (withoutlibomp.so
itself; this should beLLVM_BUILD_PATH/lib/
)
Then, add the following lines to CMACIONIZE_SOURCE_PATH/CMakeLists.txt
:
- below
include_directories(${PROJECT_BINARY_DIR}/src)
, addinclude_directories(PATH_TO_OMP.H_FOLDER)
- below
find_package(OpenMP)
, addset(OPENMP_FOUND True)
andset(OPENMP_CXX_FLAGS "-fopenmp=libomp")
Run cmake
and make
as normal. This should now work.
When you try to run CMacIonize
or the unit tests, the system will now complain about not finding libomp.so
. To solve this, run the following command:
export LD_LIBRARY_PATH=PATH_TO_LIBOMP.SO_FOLDER:$LD_LIBRARY_PATH
Now running a shared memory parallel program should work.
More info on https://clang-omp.github.io/.