- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
How to translate openmp code(#pragma omp parallel for and #pragma omp simd ) into C pseudo code(pthread or simd intrinsic function)?
- Tags:
- Parallel Computing
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sun, lei, I've carefully read your question and here are some of the suggestions:
The first of all C pseudo code is *NOT* the either pthread or simd intrinsic functions.
Just for your interest: the C pseudo code is just a plain text explanation of how a certain code in C/C++ works.
The C pseudo code for the specific OpenMP pragmas listed below against the code in C/C++:
#pragma omp parallel for:
#pragma omp parallel for private(i) for (int i = 0; i < N; i++) { // do some work in parallel } initialize i to zero (i = 0); while i less than N do: spawn i-th thread; do some work in parallel; end spawn; increment i by 1; end while;
#pragma omp simd:
#pragma omp simd { // An associated loop for (int i =0 ; i < N; i++) { // do some work in parallel } } initialize i to zero (i = 0); spawn each of N-threads in parallel; while i less than N / 4 do: do the loop vectorization using SIMD instructions: do some work in parallel #1 (i); do some work in parallel #2 (i + 1); do some work in parallel #3 (i + 2); do some work in parallel #4 (i + 3); end do; increment i by 4; end while;
Also, it's recommended to use the following OpenMP construct instead of using #pragma parallel for simd:
#pragma omp parallel { #pragma omp for simd for (int i = 0; i < N; i++) { // do some work in parallel } }
That's all. Have a good day ahead!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Was this solution helpful ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your reply. But I still don't know the real generated C code of openmp.
Arthur V. Ratz wrote:Was this solution helpful ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What do you exactly mean that you still don't know the real generated C code of openmp ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes.
Arthur V. Ratz wrote:What do you exactly mean that you still don't know the real generated C code of openmp ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When an OpenMP program is converted to executable it is linked with a OpenMP library which internally uses POSIX functions.
An OpenMP code is not converted to an implementation in "C" using POSIX functions. So there is no intermediate "C code" using POSIX functions for OpenMP programs. You can always write a equivalent program directly using POSIX functions pthread_create, pthread_join... , but it would require much more effort compare to implementing the same logic in OpenMP program.
As far as equivalent pseudo-code is concerned Arthur provided a good example.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page