Difference between single directive and sections in OpenMP

I understand, I can use the directive singleto do the same work as when using sectionsjust add nowaitflags

The following code is no different from me compared to the directive section:

    void main(){
    #pragma omp parallel
        {
            int tid = omp_get_thread_num();
    #pragma omp single nowait
            {
                printf("Thread %d in #1 single construct.\n", tid);
            }
    #pragma omp single nowait
            {
                printf("Thread %d in #2 single construct.\n", tid);
            }
    #pragma omp single nowait
            {
                printf("Thread %d in #3 single construct.\n", tid);
            }
        }
    }

Can someone give me some examples using directives sectionsand singlein different scenarios?

+4
source share
2 answers

, single sections , , .

, single copyprivate, :

... , .

workbaring sections, , lastprivate reduction, single .

, , :

#pragma omp single nowait
        {
            printf("Thread %d in #1 single construct.\n", tid);
        }
#pragma omp single nowait
        {
            printf("Thread %d in #2 single construct.\n", tid);
        }
#pragma omp single nowait
        {
            printf("Thread %d in #3 single construct.\n", tid);
        } // No barrier here

a sections, a sections nowait. a sections, , single .

+3

single nowait , sections. OpenMP , single. , . OpenMP. , , .

, , , single . sections , for, for switch section. , .

Cheers,       -

+2

Source: https://habr.com/ru/post/1539848/


All Articles