How is OpenMP directives handled by compiler
- 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 prepro开发者_如何学编程cessing and right before being assembled?
Thanks and regards!
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.
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.
精彩评论