Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

How to translate or expand openmp code into C pseudo code?

sun__lei
Beginner
2,767 Views

How to translate openmp code(#pragma omp parallel for and  #pragma omp simd ) into C pseudo code(pthread or simd intrinsic function)?

 

0 Kudos
6 Replies
ArthurRatz
Novice
2,767 Views

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!

0 Kudos
ArthurRatz
Novice
2,767 Views

Was this solution helpful ?

0 Kudos
sun__lei
Beginner
2,765 Views

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 ?

0 Kudos
ArthurRatz
Novice
2,765 Views

What do you exactly mean that you still don't know the real generated C code of openmp ?

0 Kudos
sun__lei
Beginner
2,765 Views

Yes.

Arthur V. Ratz wrote:

What do you exactly mean that you still don't know the real generated C code of openmp ?

0 Kudos
ASing3
Beginner
2,765 Views

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.

0 Kudos
Reply