Search code examples
openmp

Does openmp taskwait free the core the task is running on?


Basically what the question says.

Let's say I have a task running on a core and at some point I want to wait for its child tasks to complete (using the taskwait directive). While the task is waiting, can other tasks use the core bound to the waiting task? Or is that core blocked?


Solution

  • Yes, an OpenMP runtime can execute other tasks during a taskwait directive because this directive is an implicit scheduling point in OpenMP. However, this is not mandatory. Both the Intel/Clang OpenMP runtime (IOMP) as well as the one of GCC (GOMP) do it. Most runtime try to do it for sake of performance.

    Here is what the OpenMP 5.1 standard states:

    Section 2.12.6:
    Whenever a thread reaches a task scheduling point, the implementation may cause it to perform a task switch, beginning or resuming execution of a different task bound to the current team. Task scheduling points are implied at the following locations:

    • [...] in a taskwait region [...].

    Note that other threads can wait either actively or passively for new incoming tasks. Thus, cores can be busy waiting for new tasks to be scheduled if no task is available (ie. the core is not free). You can control this using the environment variable OMP_WAIT_POLICY.