Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Anupam_Dev
Beginner
50 Views

Threading in section

#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.
0 Kudos
1 Reply
jimdempseyatthecove
Black Belt
50 Views

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
Reply