Must a task be generated within a worksharing region?

General OpenMP discussion

Must a task be generated within a worksharing region?

Postby hzmonte » Wed Jan 11, 2017 12:28 pm

I have thought that an explicit task must, for practical purposes, be generated within a worksharing region, most commonly a single region, which in turn is within a parallel region. If it is generated directly within a parallel region but not within a worksharing region, it works but most likely the outcome is not as intended. But I just read Example tasking.8 on page 61 of the Version 4.5 Examples - a task is generated within a parallel region directly. Am I wrong?
hzmonte
 
Posts: 3
Joined: Thu Jan 05, 2017 2:29 am

Re: Must a task be generated within a worksharing region?

Postby MarkB » Thu Jan 12, 2017 3:42 am

hzmonte wrote:I have thought that an explicit task must, for practical purposes, be generated within a worksharing region, most commonly a single region, which in turn is within a parallel region.


There is no such restriction - it is perfectly OK to generate tasks outside a worksharing region. Using master instead of single, for example, is fine.

hzmonte wrote: If it is generated directly within a parallel region but not within a worksharing region, it works but most likely the outcome is not as intended.


I'm not sure what think might go wrong - can you give an example?
MarkB
 
Posts: 735
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Must a task be generated within a worksharing region?

Postby hzmonte » Fri Jan 13, 2017 1:06 pm

Let me re-phrase my question to: "Must a task be generated within a one-thread-only region?"

I do understand that there is no restriction, as far as the legality of the program is concerned. That was why I said "for practical purposes." This point is also made by a remark in the tasking.4 example in the version 4.5 Examples document (page 55): "only one thread of the parallel region should call fib() unless multiple concurrent Fibonacci computations are desired [therefore the task should be generated within a one-thread-only region such as a single region; i.e. the fib() function should be called within a one-thread-only region]." "it is perfectly OK to generate tasks outside a worksharing region" -- well, it is legal but may probably not come to the intended outcome - look at the fib() example.

There are many examples in the version 4.5 Examples document, such as tasking.4, that suggest a task, for most of the intended purposes, should be generated where only one thread is executing -- except tasking.8.
hzmonte
 
Posts: 3
Joined: Thu Jan 05, 2017 2:29 am

Re: Must a task be generated within a worksharing region?

Postby MarkB » Mon Jan 16, 2017 3:52 am

hzmonte wrote:Let me re-phrase my question to: "Must a task be generated within a one-thread-only region?"


Task generation by one thread at the top level is certainly a common use case, especially for recursive parallelism patterns. There are other patterns where generation by all threads may be useful, for example nested parallelism where tasks at the inner level are not well balanced.
MarkB
 
Posts: 735
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh


Return to Using OpenMP

Who is online

Users browsing this forum: Alexa [Bot] and 10 guests