First and foremost, single
and sections
directives have clearly different semantic purposes when it comes to reading code and using one to mimic the other may be highly misleading.
Regarding the technicalities, single
is the only worksharing directive to support the copyprivate
clause, which:
... provides a mechanism to use a private variable to broadcast a value from the data environment of one implicit task to the data environments of the other implicit tasks belonging to the parallel region.
The sections
worksharing construct on the other hand supports lastprivate
and reduction
clauses, which single
does not.
Finally, note that your snippet:
#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
does not mimic a sections
, but a sections nowait
. To mimic a sections
you must remember to have the very last single
construct maintaining its implicit barrier.