Skip to content

Using OpenMP with clang compiler

Bert Vandenbroucke edited this page Jan 22, 2017 · 1 revision

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 (without omp.h itself; this should be LLVM_BUILD_PATH/projects/openmp/runtime/src/)
  • the folder where libomp.so is located (without libomp.so itself; this should be LLVM_BUILD_PATH/lib/)

Then, add the following lines to CMACIONIZE_SOURCE_PATH/CMakeLists.txt:

  • below include_directories(${PROJECT_BINARY_DIR}/src), add include_directories(PATH_TO_OMP.H_FOLDER)
  • below find_package(OpenMP), add set(OPENMP_FOUND True) and set(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/.

Clone this wiki locally