Does OMP Pragmas nesting have significance?

225 views Asked by At

I'm looking at some code like below (in a reviewer/auditor capacity). The nesting shown below was created with TABS in the source code.

#pragma omp parallel
    #pragma omp sections
    {
        #pragma omp section
            p2 = ModularExponentiation((a % p), dp, p);
        #pragma omp section
            q2 = ModularExponentiation((a % q), dq, q);
    }

Is the nesting a matter of style? Or does it have significance like in, say, Python?

1

There are 1 answers

4
Matt On BEST ANSWER

You can collapse the first two pragmas into one, and it won't change the semantics, so you can change

#pragma omp parallel
#pragma omp sections

into

#pragma omp parallel sections

However, the section pragmas must be nested inside of the sections pragma in order to specify task parallelism. One example of when you might want to keep them separate is if you want to do two parallel sections right after one another with a barrier in between, such as:

#pragma omp parallel
{
  #pragma omp sections
  {
    #pragma omp section
    { ... }
    #pragma omp section
    { ... }
  }
  #pragma omp sections
  {
    #pragma omp section
    { ... }
    #pragma omp section
    { ... }
  }
}

This will not need to create a new "team" for the second set of sections