#pragma directives expansion

Hello everyone,

I know that an OpenMP #pragma directive is expanded into some lines of codes (or maybe I am wrong). I was hoping if someone could tell me where should I look for it?

For example, considering this piece of code:
#pragma omp parallel
{
printf(“Hello world! %d”, omp_get_thread_num());
}

will be converted to something like this:
f1();
{
printf(“Hello world! %d”, omp_get_thread_num());
}
f2();

If I am wrong tell me.And if you know where should I look for in the code, let me know about it.

Best Regards,
Millad

The parallel region will be outlined as a function. This function will be run by each threads. You can take a look at our group’s Wikipedia page regarding the OpenMP implementation in OpenUH.

Also you can take a look at Liao’s paper: OpenUH: An optimizing, portable OpenMP compiler

You can also have a look at http://openmp.llvm.org/Reference.pdf - it contains several examples of how different OpenMP directives are expanded.

You need to be clear, though, that the expansions are conceptual and for educational purposes. They’re showing what the transformations would look like if they were done in source code. However that doesn’t meant that is how they are done, in reality they’re transformations on the compiler’s intermediate representation. When compiling there is never a file that contains the transformed source code.

They’re shown in the document as if they were source code transformations because that’s easy to read and understand, not because that’s what really exists.

(If we showed the real internal transformation you would need to understand the compiler IR, which isn’t the point of the discussion.)

If you want an OpenMP implementation that does operate source to source, you might look at Rose. http://rosecompiler.org/ (Disclaimer, I haven’t looked at it in detail, but it seems to claim to have an OpenMP implementation). I doubt that it targets this runtime, though…

– Jim

James Cownie james.h.cownie@intel.com
SSG/DPD/TCAR (Technical Computing, Analyzers and Runtimes)

Tel: +44 117 9071438

BTW the Rose implementation was based on our OpenUH one and done by somebody from the UH group. So we have plenty of documentation on that :slight_smile:
Barbara

Thanks everybody. I really appreciate your responses.