12

My gcc compiles well, but clang fails with the following message:

clang -fopenmp=libomp -o main main.c
main.c:5:10: fatal error: 'omp.h' file not found

I also installed libomp5 package and changed flag to -fopenmp=libomp5 , though it didn't help either:

clang -fopenmp=libomp5 -o main main.c
clang: error: unsupported argument 'libomp5' to option 'fopenmp='
clang: error: unsupported argument 'libomp5' to option 'fopenmp='

these recommendations didn't work.

Would be grateful for hints on installing necessary 16.04 specific packages and passing corresponding flags.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Bulat M.
  • 841
  • 4
  • 14
  • 32

2 Answers2

23

I had the same problem.

sudo apt install libomp-dev

Fixed it with Ubuntu 16.10

//test.c
#include "omp.h"
#include <stdio.h>

int main(void) {
  #pragma omp parallel
  printf("thread %d\n", omp_get_thread_num());
}

Then

clang test.c -fopenmp
./a.out
thread 0
thread 5
thread 2
thread 1
thread 7
thread 3
thread 4
thread 6

Also

clant-3.9 test.c -fopenmp

works.


GCC and Clang use different OpenMP runtime libraries : libgomp and libomp respectivly.

Clang's runtime is the LLVM OpenMP runtime which in turn is based on the Intel OpenMP runtime (which is open source). https://www.openmprtl.org/

On my system GCC installed omp.h at

/usr/lib/gcc/x86_64-linux-gnu/6/include/omp.h

and libomp-dev insalled omp.h at

/usr/include/omp.h

These are different header files which include different function definitions. It may be okay to use either header file for e.g. omp_get_wtime() but in general I think it's probably better to use the header file that corresponds to the runtime that is linked to.

Z boson
  • 457
  • 3
  • 10
1

It seems omp.h file doesn't exist in your system PATH. firstly try to locate omp.h file if you don't know where it is:

find / -name 'omp.h' -type f

And then run this command to compile your code:

clang -o main main.c -I/path/to/omp/folder
Ghasem Pahlavan
  • 1,805
  • 14
  • 20
  • That does not fix the problem. It still can't find `omp.h`. – Z boson Apr 12 '17 at 13:48
  • Did you find any **omp.h** in your system? can you append output of these commands to your question? – Ghasem Pahlavan Apr 13 '17 at 07:48
  • `*.h` are header files, why would he want to add them into his path? they should be in `/usr/include` for example. – Ravexina Apr 13 '17 at 11:15
  • 1
    Thanks Ghasem, libomp-dev installation on 16.04 solved. – Bulat M. Apr 14 '17 at 05:42
  • `-I /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/include/` breaks compilation with clang because it picks GCC's other headers over the standard headers clang normally uses, e.g. for `immintrin.h`. And even using `-idirafter`, it's not compatible with the use of `__attribute__` declarations, errors such as: `omp.h:308:45: error: '__malloc__' attribute takes no arguments __GOMP_NOTHROW __attribute__((__malloc__, __malloc__ (omp_free),` – Peter Cordes Oct 21 '22 at 02:01