A NOWAIT Problem!

General OpenMP discussion

A NOWAIT Problem!

Postby zoyo » Wed Jun 27, 2012 11:56 pm

hallo everyone,
i have a confusion about the parallel loop with nowait, see the example below:

...
!$omp parallel
...
do j=1,3
!$omp do
do i=1,4000
a(i,j)=...
enddo
!$omp end do nowait
endo do
...
!$omp end parallel
...

we assume this code is running on 4 threads, and the thread No. 3 is a much faster than No. 0.
so because of different compute ability, the situation may be like this:
thread 3 have just finished computing j=2, and start to do j=3, then it encounter !$omp do, while thread 0 is still doing j=1.
then the OpenMP api need to distribute the mission of j=3 to 4 threads.
my question is : does thread 0 know which section of the loop to do in j=3? and MORE IMPORTANT, does thread 0 know which section to do in j=2 ?????
do we need to guaranty that if one thread start doing j=3, all the other threads MUST had finished j=1,meanwhile ,doing j=2 at least.
and another quetion:is the first thread enconter the parallel loop do the first section of the loop, say i=1,1000 in this case?

thanks a lot!
zoyo
 
Posts: 5
Joined: Wed May 16, 2012 7:08 am

Re: A NOWAIT Problem!

Postby MarkB » Thu Jun 28, 2012 3:54 am

zoyo wrote:do we need to guaranty that if one thread start doing j=3, all the other threads MUST had finished j=1,meanwhile ,doing j=2 at least.


No you don't: it's perfectly OK for different threads to be in different run time instances of a do region arising from the same do construct in the code. (This works because the implementation takes care of the mapping of iterations to threads on a per run time instance basis).

zoyo wrote:and another quetion:is the first thread enconter the parallel loop do the first section of the loop, say i=1,1000 in this case?


Not if you use a STATIC schedule: the chunks of iterations are assigned strictly in thread order (so thread 0 will always get i=1,1000 in this case). It is also safe to assume that for a STATIC schedule, and for parallel loops of with the same number of iterations in the same parallel region, the mapping of iterations to threads will always be the same (see page 44 of the Version 3.1 specification).

(Note: strictly speaking, since your example does not specify a schedule clause, we should not assume that the implementation will use a STATIC schedule in this case, though, in practice, most implementations will).

If you used a DYNAMIC or GUIDED schedule, then the first thread to arrive would take the first chunk of iterations.
MarkB
 
Posts: 428
Joined: Thu Jan 08, 2009 10:12 am

Re: A NOWAIT Problem!

Postby zoyo » Wed Jul 04, 2012 12:46 am

thanks a lot !
zoyo
 
Posts: 5
Joined: Wed May 16, 2012 7:08 am


Return to Using OpenMP

Who is online

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

cron