编译器如何处理 OpenMP 指令
- 我想知道 OpenMP 如何 指令由编译器处理, 比如海湾合作委员会?
例如,在这段代码中
int main(int argc, char *argv[]) { #pragma omp 并行 printf("你好,世界。\n"); 返回0; }
gcc的预处理器是否修改了C代码 将 OpenMP 指令替换为 还有其他代码吗?
后面的代码是什么样的 预处理和就在之前 汇编?
谢谢和问候!
- I was wondering how OpenMP
directives are handled by compiler,
such as gcc? For example, in this code
int main(int argc, char *argv[]) { #pragma omp parallel printf("Hello, world.\n"); return 0; }
Does preprocessor of gcc modify the C code by
replacing the OpenMP directive with
some other code?What is the code like after
preprocessing and right before being
assembled?
Thanks and regards!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以进行网络搜索并查找讨论该主题的论文。我讨厌提供链接,因为它们不断变化,但在这种情况下,这是回答您的问题的最简单方法。您可以查看以下两个内容:
来自另一个世界的事物(或者:OpenMP 编译器如何工作?第 1 部分),作者:Michael Klemm
如何编译 OpenMP,作者:Barbara Chapman
希望这能回答您的问题。
You can do a web search and find papers discussing this topic. I hate to give links because they constantly change, but in this case it is the easiest way to answer your question. Here are two that you can look at:
The Thing from another World (or: How do OpenMP Compilers Work? Part 1), by Michael Klemm
How OpenMP is Compiled, by Barbara Chapman
Hopefully this will answer your question.
我不知道第一手资料,但 GCC(或任何编译器)在遇到这些编译指示时不太可能预处理代码。最有可能的是,GCC 只会在内部标记该块,然后生成适当的本机代码。没有中间 C++ 代码。
I don't know first hand, but it's very unlikely that GCC (or any compiler) will preprocess the code when it encounters those pragmas. Most likely, GCC will just flag that block internally and then generate the appropriate native code. There is no intermediate C++ code.