using if clause to select level of parallelisation

General OpenMP discussion

Re: using if clause to select level of parallelisation

Postby MarkB » Wed Aug 08, 2012 7:42 am

Hi Fernando,

ftinetti wrote:Now, I do have a specific question: when the if clause evaluates to false:
is it a sequential part? if so, the problem in the original code is not related to dynamic
is it a parallel part with just one thread? if so, either the spec should be fixed/made clearer or the gcc implementation I'm using has a bug

or I'm missing something else, which is what I'm guessing right now.


I'm sorry, I'm confused: what do think is the bug in gcc/error in the spec?
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am

Re: using if clause to select level of parallelisation

Postby ftinetti » Wed Aug 08, 2012 12:19 pm

Hi Mark,

ftinetti wrote:
Now, I do have a specific question: when the if clause evaluates to false:
is it a sequential part? if so, the problem in the original code is not related to dynamic
is it a parallel part with just one thread? if so, either the spec should be fixed/made clearer or the gcc implementation I'm using has a bug

or I'm missing something else, which is what I'm guessing right now.


I'm sorry, I'm confused: what do think is the bug in gcc/error in the spec?

I'll try to explain extracting code and text from previous posts in this thread. The following piece of code:
Code: Select all
  para_low = 0;
  #pragma omp parallel for if(para_low)
  for (i = 0; i < 1000; i++)
  {
    if (i == 0) printf("omp_in_parallel() return value: %d, and omp_get_active_level() returns: %d\n", omp_in_parallel(), omp_get_active_level());
    v1[i]= 0;
  }

produces the output
omp_in_parallel() return value: 0, and omp_get_active_level() returns: 0


Taking into account your explanation in a previous post:
A parallel construct will always generate a parallel region: there is no such thing as "plain sequential" execution. If the parallel region only contains one thread (either because an if clause evaluates to false, or for any other reason), then it is called an inactive parallel region. However, omp_in_parallel() only returns true if it is called from inside an active parallel region (i.e. one which is executing with more than one thread), hence the behaviour you observe in your example.

but the spec., in the explanation of omp_get_active_level() includes:
The routine always returns a nonnegative integer, and returns 0 if it is called from the sequential part of the program.

Thus, there is such thing as "sequential part of the program" which is what the return value of the function is indicating. Now I cannot distinguish the difference among "inactive parallel region" and "sequential part of the program".

Maybe I could "understand" something like: "returns 0 if it is called from an inactive parallel region" or "returns 0 if it is called from the sequential part of the program or an inactive parallel region". But I do not give it for granted...

Also, I do not understand:
omp_get_level() should always return 2 if called from inside the inner parallel, regardless of the number of threads or the value of the if clause expression.
omp_get_active_level() will only return 2 if both levels of parallel region are executed by more than one thread.

the "regardless" part specifically, since when the if clause evaluates to false the parallel region is an inactive one...

hmmmmm... maybe I just should read more... or better...

Anyway, thank you very much,

Fernando.
ftinetti
 
Posts: 575
Joined: Wed Feb 10, 2010 2:44 pm

Re: using if clause to select level of parallelisation

Postby MarkB » Thu Aug 09, 2012 3:29 am

Hi Fernando,

ftinetti wrote:Now I cannot distinguish the difference among "inactive parallel region" and "sequential part of the program".


The sequential part of the program is everything which is not contained in a parallel region. An inactive parallel region is simply defined as any parallel region executed by only one thread: this may happen for a number of reasons (including an if clause with an expression which evaluates to false: see Section 2.4.1 of the spec).

omp_get_active_level() returns the number of enclosing active parallel regions. So, indeed it will return 0 if all enclosing parallel regions are inactive, though the spec does not state this explicitly as a special case.

omp_get_level() returns the total number of (active or inactive) enclosing parallel regions.

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

Re: using if clause to select level of parallelisation

Postby ftinetti » Thu Aug 09, 2012 4:28 am

Thank you very much, Mark,

Fernando.
ftinetti
 
Posts: 575
Joined: Wed Feb 10, 2010 2:44 pm

Re: using if clause to select level of parallelisation

Postby MarkB » Thu Aug 09, 2012 4:30 am

ftinetti wrote:Thank you very much, Mark,


You're welcome!
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am

Re: using if clause to select level of parallelisation

Postby drorc » Thu Aug 09, 2012 8:42 pm

Thanks for your comments guys.

Time permitting I'll do some more work on this and try to create some reproducible experiments. It seems to me that evaluating different levels of parallelisation is a common thing to do, and using the if clause a convenient way of doing this. I'm a little surprised no one else has come across this.

Thanks again,

Dror
drorc
 
Posts: 4
Joined: Sun Aug 05, 2012 10:43 pm

Re: using if clause to select level of parallelisation

Postby MarkB » Fri Aug 10, 2012 2:31 am

Hi Dror,

drorc wrote: It seems to me that evaluating different levels of parallelisation is a common thing to do, and using the if clause a convenient way of doing this. I'm a little surprised no one else has come across this.


I think maybe having multiple levels of parallelism where you want to exploit one or the other but not both isn't all that common!
And most likely the problems you are seeing are specific to gcc and the platform(s) you are running on.

My impression is that the gcc OpenMP runtime doesn't really do a great job of managing its pool of underlying kernel threads. It might be interesting to experiment with fewer threads than you have cores and see if the problem is still evident.

drorc wrote:Time permitting I'll do some more work on this and try to create some reproducible experiments.


Let us know how you get on...

drorc wrote:Thanks again


You're welcome!
Mark.
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am

Previous

Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 12 guests