How do I aggregate my pragma omp directives?

General OpenMP discussion

How do I aggregate my pragma omp directives?

Postby ausairman » Sun Jan 15, 2012 3:11 pm

I have a method that is parallelised twice, and I'm sure that with barriers I could make it work with a single pragma omp directive, but I don't really know how (I've read the documentation but I simply don't understand how to implement it in practice). Here is conceptually what my code looks like:

Code: Select all
void world<TTrainer>::epoch() {
// do something

#pragma omp parallel
   {
#pragma omp for schedule(dynamic)
   for (int iter = 0; iter < lim; iter++) {
            // do something
      }
   }
}

// do something independent of the next task

// do something independent of the previous task

#pragma omp parallel
   {
#pragma omp for schedule(static)
   for (int iter = 0; iter < lim; iter++) {
      // do something in parallel
   }
}
// another serial section
}


Currently my parralel loops are in 2 separate pragma omp directives, and my tasks in between are run in serial, although they could really be run on 2 separate threads at the same time. Could someone please show me how I would modify this construct to achieve the 2 separate parallelized regions and share the two independant sections between 2 separate threads, all with as little overhead as possible (I can sort out the choice of serial/dynamic, but I mean the use of pragma omp directives)?
ausairman
 
Posts: 12
Joined: Mon Jul 11, 2011 5:40 am

Re: How do I aggregate my pragma omp directives?

Postby ftinetti » Mon Jan 16, 2012 5:45 am

Hi,

I don't know if I understood your description correctly, but my first suggestion would be to use the section directive, as:

Code: Select all
void world<TTrainer>::epoch() {
  // do something

#pragma omp parallel
{
  #pragma omp for schedule(dynamic)
     for (int iter = 0; iter < lim; iter++) {
            // do something
      }
   }

  #pragma omp sections
  {
    #pragma omp section
    // do something independent of the next task

    #pragma omp section
    // do something independent of the previous task
  }

  #pragma omp for schedule(static)
   for (int iter = 0; iter < lim; iter++) {
      // do something in parallel
   }
}
// another serial section
}


About overhead, well... as always, it depends on the computing tasks...

HTH.
ftinetti
 
Posts: 582
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 6 guests