Site Tools


nowait-openmp

Table of Contents

Nowait (OpenMP)

Nowait is an OpenMP clause that removes the implicit barrier at the end of a work-sharing construct. Threads that finish their portion of the work early proceed to the next statement immediately instead of waiting for stragglers. This is only safe when the subsequent code does not depend on the results of the current construct.

#pragma omp parallel
{
    #pragma omp for nowait
    for (int i = 0; i < N; i++)
        a[i] = foo(i);            // threads proceed as soon as their chunk is done
 
    #pragma omp for
    for (int i = 0; i < M; i++)
        b[i] = bar(i);            // does not use a[], so no barrier was needed above
}

nowait is especially effective when a parallel region contains several independent loops of uneven length. Without it, all threads stall at the end of each loop waiting for the slowest one.

nowait-openmp.txt ยท Last modified: by 127.0.0.1