OpenMP: What is the difference between foo () and bar ()

void foo(void) {
    #pragma omp parallel
    {
        #pragma omp single
            {fprintf(stderr, "first part\n"); }
        #pragma omp barrier   
        #pragma omp single
           { fprintf(stderr, "second part\n"); }
    }
}
void bar (void) {
    #pragma omp parallel
    {
        #pragma  omp sections
        {
            fprintf(stderr, "first part\n"); 
             #pragma  omp section
             fprintf(stderr, "second part\n"); 
         }
    }
}

Q1 are foo () and bar () equivalent?

+3
source share
2 answers

They are not equivalent.

foo()will execute two fprintf(parts) sequentially. bar()can execute them in parallel.

For an exhaustive reference, you can refer to the IBM compiler documentation .

Essentially, in the case, a foo()single worker thread processes first part, then terminates, and resynchronizes with the main thread ( barrierby the way, implied at the end of singleconstruct.) Then, a new worker thread processes second part, terminates, and resynchronizes with the main thread.

bar() ( first part - .) .

#pragma omp parallel

omp . , . . .

, . .

.

#pragma omp single

omp , .

nowait.

#pragma omp, #pragma omp

omp , .

omp omp. omp. omp , omp.

omp , omp . omp, nowait .

+5

, OpenMP, resource.

  • SECTION " . .

  • SINGLE ", ; , , ."

  • A BARRIER , , .

+2

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


All Articles