- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
#include
#include
#include
void display1()
{
#pragma omp parallel for num_threads(5)
for(int i=0;i<10;i++)
printf("From display1 %d\\n\\n",omp_get_thread_num());
}
void display2()
{
printf("From display2 %d\\n\\n",omp_get_thread_num());
}
int main()
{
#pragma omp parallel sections
{
#pragma omp section
display1();
#pragma omp section
display2();
}
getch();
}
I got the result
From display1 0
From display2 1
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
Now i wanted to know that when i parallelized for in the function display1 why are all the omp_get_thread_num() in that section 0.
If it is not possible this way then how can we do this. I want to parallelize the sections as well as a part of a particular section.
#include
#include
void display1()
{
#pragma omp parallel for num_threads(5)
for(int i=0;i<10;i++)
printf("From display1 %d\\n\\n",omp_get_thread_num());
}
void display2()
{
printf("From display2 %d\\n\\n",omp_get_thread_num());
}
int main()
{
#pragma omp parallel sections
{
#pragma omp section
display1();
#pragma omp section
display2();
}
getch();
}
I got the result
From display1 0
From display2 1
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
From display1 0
Now i wanted to know that when i parallelized for in the function display1 why are all the omp_get_thread_num() in that section 0.
If it is not possible this way then how can we do this. I want to parallelize the sections as well as a part of a particular section.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You must enable nested parallelism
int main()
{
omp_set_nested(1); // 0=no nesting, (non zero)=enable nesting
#pragma omp parallel sections
{
#pragma omp section
display1();
#pragma omp section
display2();
}
getch();
}
You can also enable nesting by use of environment variable
set OMP_NESTED=TRUE
Jim Dempsey
int main()
{
omp_set_nested(1); // 0=no nesting, (non zero)=enable nesting
#pragma omp parallel sections
{
#pragma omp section
display1();
#pragma omp section
display2();
}
getch();
}
You can also enable nesting by use of environment variable
set OMP_NESTED=TRUE
Jim Dempsey

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