How does the SECTIONS directive in OpenMP distribute work?

前端 未结 8 769
情话喂你
情话喂你 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

    It may be helpful to add more information to the output line and to add more sections (if you have the thread-count)

    #pragma omp parallel sections
    {
        #pragma omp section
        {
            printf ("section 1 id = %d, \n", omp_get_thread_num()); 
        }
        #pragma omp section
        {
            printf ("section 2 id = %d, \n", omp_get_thread_num());
        }
        #pragma omp section
        {
            printf ("section 3 id = %d, \n", omp_get_thread_num());
        }
    }
    

    Then you may get more interesting output like this:

    section 1 id = 4,
    section 3 id = 3,
    section 2 id = 1,
    

    which shows how the sections may be executed in any order, by any available thread.

提交回复
热议问题