- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi I'm struggling with a peace of code because I'm not sure how it is going to be executed
[cpp]#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... } }[/cpp]Are the going to be executed all in parallel or each sections block in sequence.Thanks
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10x it helps I was reviewing a code and was wondering why there were two sections with only one section in each one.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page