In OpenMP when using omp sections
, will the threads be distributed to the blocks inside the sections, or will each thread be assigned to each sections?
When nthreads == 3
:
#pragma omp sections
{
#pragma omp section
{
printf ("id = %d,
", omp_get_thread_num());
}
#pragma omp section
{
printf ("id = %d,
", omp_get_thread_num());
}
}
Output:
id=1
id=1
But when I execute the following code:
#pragma omp sections
{
#pragma omp section
{
printf ("id = %d,
", omp_get_thread_num());
}
#pragma omp section
{
printf ("id = %d,
", omp_get_thread_num());
}
}
#pragma omp sections
{
#pragma omp section
{
printf ("id = %d,
", omp_get_thread_num());
}
#pragma omp section
{
printf ("id = %d,
", omp_get_thread_num());
}
}
Output:
id=1
id=1
id=2
id=2
From these output I can't understand what the concept of sections is in OpenMP.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…