My answer ended up being a bit more elaborated than I thought. While you might have luck by using the OpenMP implementation that comes with GCC (the paths of omp.h
and libgomp.so
can be found with the commands: gcc --print-file-name=include/omp.h
and gcc --print-file-name=libgomp.so
respectively), I'd suggest to do an out-of-tree build of the OpenMP subproject for the LLVM's exact version you use, as described here: http://openmp.llvm.org. The section "Status" of the same page says that since Clang 3.8, the OpenMP runtime is built as a normal part of the Clang build, so in theory we shouldn't need to do that manually. However, I didn't manage to enable OpenMP support just by installing the clang and llvm packages that come with Fedora. I've made a very small script (along the lines of the instructions in the page linked above), which allows you to locally install the OpenMP version compatible with Clang 3.9.1 (the one that comes with Fedora 25):
#!/bin/bash
cd ~ &&
rm -rf $HOME/BUILDS/CLANG391_OMP &&
mkdir -p $HOME/BUILDS/CLANG391_OMP &&
cd $HOME/BUILDS &&
svn co http://llvm.org/svn/llvm-project/openmp/tags/RELEASE_391/final openmp &&
cd openmp/runtime &&
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$HOME/BUILDS/CLANG391_OMP ../ &&
make -j4 &&
make install &&
cd ~ &&
rm -rf $HOME/BUILDS/openmp
you can just save it as build_clang391_omp.sh
and make it executable with chmod +x build_clang391_omp.sh
. Before launching the script (with ./build_clang391_omp.sh
, as normal user), make sure you have at least the packages svn
, cmake
, clang
and the group "C Development Tools and Libraries"
installed through dnf
.
The building process is generally very fast and you will end up having the folder CLANG391_OMP
inside $HOME/BUILDS
. Now you can build your OpenMP-based test. Type in a terminal:
clang++ -fopenmp -I$HOME/BUILDS/CLANG391_OMP/include -L$HOME/BUILDS/CLANG391_OMP/lib test-openmp.cpp -o test-openmp
and then launch the executable:
LD_LIBRARY_PATH=$HOME/BUILDS/CLANG391_OMP/lib:$LD_LIBRARY_PATH ./test-openmp
which gives:
22 April 2017 03:18:01 PM
DIJKSTRA_OPENMP
C++ version
Use Dijkstra's algorithm to determine the minimum
distance from node 0 to each node in a graph,
given the distances between each pair of nodes.
Although a very small example is considered, we
demonstrate the use of OpenMP directives for
parallel execution.
Distance matrix:
0 40 15 Inf Inf Inf
40 0 20 10 25 6
15 20 0 100 Inf Inf
Inf 10 100 0 Inf Inf
Inf 25 Inf Inf 0 8
Inf 6 Inf Inf 8 0
P0: Parallel region begins with 8 threads.
P0 P P P P24: First=3: First= Last=0 Last=2-1
P3: First=2 Last=52
P7: First=5: First= Last=1 Last=51
P6: First=4 Last=4
: First=3 Last=3
1: First=0 Last=0
P2: Connecting node 2
P2: Connecting node 1
P3: Connecting node 5
P2: Connecting node 3
P0: Connecting node 4
P2: Exiting parallel region.
Minimum distances from node 0:
0 ...
(more)