How does the SECTIONS directive in OpenMP distribute work?

前端 未结 8 778
情话喂你
情话喂你 2020-11-29 08:14

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?

8条回答
  •  感情败类
    2020-11-29 08:42

    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.

提交回复
热议问题