tags:

views:

76

answers:

1

Hai

Will the thread be distributed to the blocks inside the sections or each thread will be assigned to each sections because when i execute the below code

NUMBER OF THREADS IS 3

pragma omp sections

{ #pragma omp section { printf ("id = %d, \n", omp_get_thread_num()); }

#pragma omp section
{ 
  printf ("id = %d, \n", 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, \n", omp_get_thread_num()); }

#pragma omp section
{ 
  printf ("id = %d, \n", omp_get_thread_num());
}

}

pragma omp sections

{ #pragma omp section { printf ("id = %d, \n", omp_get_thread_num()); }

#pragma omp section
{ 
  printf ("id = %d, \n", omp_get_thread_num());
}

}

OUTPUT:

id=1 id=1

id=2 id=2

From these output i couldn't understand what the concept of sections in openmp.

Thank You.

+3  A: 

The idea of parallel sections is to give the compiler a hint that the various (inner) sections can be performed in parallel, for example:

#pragma omp parallel sections
{
   #pragma omp section
   {
      /* Executes in thread 1 */
   } 
   #pragma omp section
   {
      /* Executes in thread 2 */
   } 
   #pragma omp section
   {
      /* Executes in thread 3 */
   } 
   /* ... */
}

This is a hint to the compiler and not guaranteed to happen, though it should. Your output is kind of what is expected; it says that there are #sections being executed in thread id 1, and in thread 2. The output order is non-deterministic as you don't know what thread will run first.

wump