简体   繁体   English

将OpenMP代码编译为C代码

[英]Compiling OpenMP code to C code

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. 有没有办法可以用OpenMP编译代码到C代码(将OpenMP部分翻译成普通的C),这样我就可以知道OpenMP生成了什么样的代码。 I am using gcc 4.4 compiler. 我正在使用gcc 4.4编译器。

Like the other commenters pointed out gcc doesn't translate OpenMP directives to plain C. 像其他评论者指出的那样,gcc没有将OpenMP指令翻译成普通的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. 但是如果你想了解gcc对你的指令做什么,你可以使用-fdump-tree-optimized选项进行编译。 This will generate the intermediate representation of the program which is at least C-like. 这将生成至少类似C的程序的中间表示。

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. 有几个阶段可以转储(查看gcc的手册页),在优化阶段,OpenMP指令已经被GOMP运行时库的调用所取代。 Looking at that representation might give you some insights into what's happening. 查看该表示可能会让您对正在发生的事情有所了解。

There is at least http://www2.cs.uh.edu/~openuh/ OpenUH (even listed at http://openmp.org/wp/openmp-compilers/ ), which can 至少有http://www2.cs.uh.edu/~openuh/ OpenUH(甚至列在http://openmp.org/wp/openmp-compilers/ ),它可以

emit optimized C or Fortran 77 code that may be compiled by a native compiler on other platforms. 发出优化的C或Fortran 77代码,这些代码可以由其他平台上的本机编译器编译。

Also there are: http://www.cs.uoi.gr/~ompi/ OMPi: 还有: 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. OMPi编译器使用OpenMP #pragmas获取C源代码并生成转换后的多线程C代码,准备由系统的本机编译器编译。

and OdinMP: 和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. 出于可移植性原因,OdinMP / CCp是用Java编写的,它采用带有OpenMP指令的C程序,并为POSIX线程生成一个C程序。

I should say that it is almost impossible to translate openmp code into Plain C; 我应该说将openmp代码转换为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. 因为旧的普通C不支持线程,我认为OpenMP源到源的翻译器还不知道C11。 OpenMP program can be translated either to C with POSIX threads or to C with some runtime library (like libgomp) calls. OpenMP程序可以使用POSIX线程转换为C,也可以转换为带有某些运行时库(如libgomp)调用的C语言。 For example, OpenUH has its own library which uses pthreads itself. 例如,OpenUH有自己的库,它自己使用pthreads。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM