does pragma omp single flush all share variables?

General OpenMP discussion

does pragma omp single flush all share variables?

Postby ntt2011 » Thu Jan 24, 2013 8:36 pm

Hi all,

I have question regarding share variables in pragma single.

I have 2 for loops enclosed in a parallel region (to save the overhead cost). I have a pragma single in between to initialize some share variables for the second loop. My code is like this:

Code: Select all

#pragma omp parallel
{
    #pragma omp for
   for (i=0; i<N; i++)
      do_something(i);

   #pragma omp single
   {
        initialize_share_variables_for_the_second_for_loop();
   }

   #pragma omp flush (list of share variables)
   #pragma omp for
   for (j=0; j<M; j++)
        do_something (j);

}


My question is: does the "pragma omp flush" in my code needed ?
FYI, the program output is the same if I omit it, but I want to be safe here.
ntt2011
 
Posts: 10
Joined: Sun Dec 30, 2012 6:03 am

Re: does pragma omp single flush all share variables?

Postby MarkB » Fri Jan 25, 2013 4:22 am

Hi there,

There is an implied flush of all shared variables at the barrier at the end of the single region, so you don't need an explicit flush!
In general, if you use OpenMP directives/routines for synchronising threads (as opposed to synchronising using values in normal variables), you should
never need to use explicit flushes. A list of the points at which a flush is implied is on pages81/82 of the 3.1 specification.

Hope that helps,
Mark.
MarkB
 
Posts: 408
Joined: Thu Jan 08, 2009 10:12 am

Re: does pragma omp single flush all share variables?

Postby ntt2011 » Sun Jan 27, 2013 10:05 pm

Thank you. I appreciate it.
ntt2011
 
Posts: 10
Joined: Sun Dec 30, 2012 6:03 am


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 3 guests