Is there a way I can compile code with OpenMP to C code (With OpenMP part translated to plain C), so that I can know what kind of code is being generated by OpenMP. I am using gcc 4.4 compiler.
问题:
回答1:
There is at least http://www2.cs.uh.edu/~openuh/ OpenUH (even listed at http://openmp.org/wp/openmp-compilers/), which can
emit optimized C or Fortran 77 code that may be compiled by a native compiler on other platforms.
Also there are: http://www.cs.uoi.gr/~ompi/ OMPi:
The OMPi compiler takes C source code with OpenMP #pragmas and produces transformed multithreaded C code, ready to be compiled by the native compiler of the system.
and OdinMP:
OdinMP/CCp was written in Java for portability reasons and takes a C-program with OpenMP directives and produces a C-program for POSIX threads.
I should say that it is almost impossible to translate openmp code into Plain C; because old plain C has no support of threads and I think OpenMP source-to-source translators are not aware of C11 yet. OpenMP program can be translated either to C with POSIX threads or to C with some runtime library (like libgomp) calls. For example, OpenUH has its own library which uses pthreads itself.
回答2:
Like the other commenters pointed out gcc doesn't translate OpenMP directives to plain C.
But if you want to get an idea of what gcc does with your directives you can compile with the -fdump-tree-optimized
option. This will generate the intermediate representation of the program which is at least C-like.
There are several stages that can be dumped (check the man page for gcc), at the optimized stage the OpenMP directives have been replaced with calls to the GOMP runtime library. Looking at that representation might give you some insights into what's happening.