Some more specifications about CANCEL construct

Discuss the OpenMP 4.0 API Specifications released July 2013 (Read Only)
Forum rules
The OpenMP Forums are now closed to new posts. Please visit Stack Overflow if you are in need of help: https://stackoverflow.com/questions/tagged/openmp
Locked
manolisfel
Posts: 3
Joined: Wed Nov 26, 2014 8:33 am

Some more specifications about CANCEL construct

Post by manolisfel »

Hello

I would like to clarify something about the CANCEL construct,if possible.In OpenMP Specifications for OpenMP 4.0.0 at paragaph 2.13 Cancellation Constructs states that:

The cancel construct activates cancellation of the binding construct only if cancel-var is true , in which case the construct causes the encountering task to continue execution at the end of the canceled construct.

Threads check for active cancellation only at cancellation points. Cancellation points are implied at the following locations:
• implicit barriers
• barrier regions
• cancel regions
• cancellation point regions

Here is a simple example of a #pragma omp for

Code: Select all

#pragma omp for schedule(dynamic) 
				for(i=0;i<30;i++){
					if (i==10)
						#pragma omp cancel for;
				}
The thread that encounters cancel, should continue at the end of the loop.My question is what happens with the other threads in the team:
(a) Do they stop executing the remaining iterations, too or
(b) Do they continue executing all their iterations till the end?

It looks like (b) is correct since they do not meet any cancellation point till the end, but this does not seem very intuitive.
Can anyone explain?

Thank you in advance,
Manolis

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Some more specifications about CANCEL construct

Post by MarkB »

manolisfel wrote:t looks like (b) is correct since they do not meet any cancellation point till the end, but this does not seem very intuitive.
Can anyone explain?
That would be my interpretation too (and in this case, since the schedule is dynamic, and the default chunksize 1, all the other iterations will be executed).

manolisfel
Posts: 3
Joined: Wed Nov 26, 2014 8:33 am

Re: Some more specifications about CANCEL construct

Post by manolisfel »

Thanks a lot for your reply and your time!

So if (b) is correct..Given that we have a sections construct, that has 10 sections in it and 2 threads executing it.

If the first thread encounters the cancellation of construct sections in the first section,it continues execution at the end of the canceled(sections) construct.

The second thread remains in the construct and executes all the remaining sections alone.

Is that correct too???

Thank you in advance,
Manolis

MarkB
Posts: 808
Joined: Thu Jan 08, 2009 10:12 am
Location: EPCC, University of Edinburgh

Re: Some more specifications about CANCEL construct

Post by MarkB »

manolisfel wrote:So if (b) is correct..Given that we have a sections construct, that has 10 sections in it and 2 threads executing it.

If the first thread encounters the cancellation of construct sections in the first section,it continues execution at the end of the canceled(sections) construct.

The second thread remains in the construct and executes all the remaining sections alone.

Is that correct too???
You can't rely on that behaviour, because the method of scheduling sections to threads is implementation defined (see page 62, lines 11-12 in the 4.0 spec). So the sections could be statically allocated to threads, and cancelling one section could result in others not being executed.
manolisfel wrote:Thanks a lot for your reply and your time!
You are very welcome!

manolisfel
Posts: 3
Joined: Wed Nov 26, 2014 8:33 am

Re: Some more specifications about CANCEL construct

Post by manolisfel »

Thank you again,

In our implementation, the method of scheduling threads on sections is dynamic.So I guess that, stopping all remaining sections after encountering cancellation,would be acceptable too!

Locked