OMP how will this code execute

OMP how will this code execute

Hi I'm struggling with a peace of code because I'm not sure how it is going to be executed

#pragma omp parallel
		{
			#pragma omp sections
			{
				#pragma omp section
					do something...
				#pragma omp section
					do something...
			}
			#pragma omp sections
			{
				#pragma omp section
					do something...
			}
			#pragma omp sections
			{
				#pragma omp section
					do something...
			}
		}

Are the going to be executed all in parallel or each sections block in sequence.Thanks

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Michael Klemm (Intel)'s picture

Hi,

The sections constructs in your code will be executed in serial, that is, one block after the other. The section blocks in the individual sections constructs may be executed concurrently or in serial, depending on the number of threads.

So, in this code and two threads:

#pragma omp sections // A
{
#pragma omp section // A1
do something
#pragma omp section // A2
do something
}
#pragma omp sections // B
{
#pragma omp section //B1
do something
#pragma omp section //B2
}

You will see that A and B are executed after each other. A1 and A2 will be executed concurrentely as well as B1 and B2.

Individual section constructs may be executed in serial too, if you have less threads than you have section constructs. So, in the above example, if you would only create a single OpenMP thread, A1 and A2 would be executed in serial.

Does that help?

Cheers,
-michael

10x it helps I was reviewing a code and was wondering why there were two sections with only one section in each one.

Michael Klemm (Intel)'s picture

Hi,

That's a good point. Since I do not know the code you're referring to, it might very well be a mistake or on purpose. Except for crazy way of getting something like single, I cannot imagine a good use of a sections construct with just one secion.

Cheers,
-michael

Login to leave a comment.