Search code examples
c++cudaopenmp

Compiling and linking CUDA source files with OpenMP support


It it possible to use OpenMP pragmas in CUDA source files (not in kernel code)?

I will combine GPU and CPU computation. But the nvcc compiler fails with "cannot find Unknown option 'openmp'", when I link the program with an openmp option (under Linux).

A workaround is to use OpenMP pragmas only in C/C++ files.


Solution

  • I've just found this

    http://www.cse.buffalo.edu/faculty/miller/Courses/CSE710/heavner.pdf

    Page 25 says:

    • With gcc:
      • #include omp.h

      • Add the -fompenmp [sic] flag

        • With nvcc, this should be -Xcompiler -fopenmp as this needs to be passed directly to gcc
        • -Xcompiler passes flags directly to host compiler
      • Add -lgomp flag during the linking stage.

    Note the misspelling of -fopenmp in the third line.