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.
-
2I think that this question pre-supposes that the gcc compiler translates OpenMP calls into C. I rather suspect that it, and most other OpenMP-aware compilers, translate source into assembler including calls to system functions. I'm quite sure your compiler will produce assembler listings; that may be what you need to work with. I watch with interest for an answer which proves my expectations wrong.High Performance Mark– High Performance Mark2012-05-16 10:45:34 +00:00Commented May 16, 2012 at 10:45
-
Afaik, you can look at the source code from the gcc compiler e.g. omp.h and respective source files of the library (libgomp) to see what these pragmas do. But there is no replacement routine before calling the c compiler. see hereBort– Bort2012-05-16 10:51:28 +00:00Commented May 16, 2012 at 10:51
2 Answers
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.
Comments
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.