Site Tools


single-openmp

**This is an old revision of the document!**

Table of Contents

Single (OpenMP)

Single is an OpenMP directive that runs the enclosed block on exactly one thread, whichever arrives first.

All other threads skip the block and wait at an implicit barrier at the end, so the whole team is synchronised before continuing. It is commonly used for initialisation, I/O, and task generation.

#pragma omp parallel
{
    #pragma omp single
    initialise();    // one thread runs this; others wait at the closing brace
 
    process();       // all threads continue here once initialise() is done
}

The nowait clause removes the implicit barrier (#pragma omp single nowait), but is only safe when the rest of the parallel block does not depend on what the single block produced.

single-openmp.1781176085.txt.gz ยท Last modified: by Ivan Janevski