What is the advantage of "#pragma omp master" as opposed to "#pragma omp single"?

In OpenMP, any code inside the #pragma omp master is executed by a single thread (leading) without an implied barrier at the end of the region. (See the section on the MASTER directive in the LLNL OpenMP tutorial ).

This seems to be equivalent to #pragma omp single nowait (except that instead of "master" any thread can execute a single region).

Under what circumstances, if any, is it useful to use #pragma omp master ?

+6
source share
2 answers

Although the single nowait is most equivalent to the master construct:

  • The master construct can be used inside the sharing construct if any need arises. This does not apply to the single nowait , since two sharing constructs cannot be nested in the same parallel region.

  • Some libraries want the main thread to perform certain operations. For example, an MPI library initializing with a thread support level of MPI_THREAD_FUNNELED allows only main threads to make MPI calls

+11
source

In addition to the restrictions on nesting, a single construct can be implemented more slowly than a master construct because it is more complex and flexible. You might want to check your specific implementation, but overall, master can be implemented faster, so multiple calls can be useful compared to the single nowait .

+5
source

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


All Articles