Compiling OpenMP code to C code

匿名 (未验证) 提交于 2019-12-03 08:41:19

问题:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!