Search code examples
c++ctaskopenmpbarrier

Waiting for OpenMP task completion at implicit barriers?


If I create a bunch of OpenMP tasks and do not use taskwait, where does the program wait for that tasks completion? Consider the following example:

#pragma omp parallel
{
   #pragma omp single
   {
      for (int i = 0; i < 1000; i++) {
         #pragma omp task
         ... // e.g., call some independent function
      }
      // no taskwait here
   }
   // all the tasks completed now?
}

Does the program wait for task completion at the implicit barrier at the end of the single block? I assume so, but cannot find any information about this issue in the OpenMP Specification.

EDIT

From barrier description in OpenMP Spec.:

All threads of the team executing the binding parallel region must execute the barrier region and complete execution of all explicit tasks bound to this parallel region before any are allowed to continue execution beyond the barrier.

This, however, does not says whether I am responsible for task completion or the OpenMP runtime does it for me.


Solution

  • Task completion in OpenMP is implicit, not explicit (1.2.5 Tasking Terminology)

    task completion Task completion occurs when the end of the structured block associated with the construct that generated the task is reached.

    There is an implicit barrier at the end of the single worksharing construct. As you mentioned, barriers wait for explicit tasks. Therefore all tasks will be completed at the of the single block.