I'm already using OpenMP for some parallel processing and would like to add a control thread with a blocking receive. Most of the time this thread will be blocked and therefore I don't want it sitting there taking up a core. Ideally the blocking call would trigger a yield to an extra worker thread. How will OpenMP deal with the blocking call?
Something like this:
#include <omp.h>
int main()
{
int cores = omp_get_num_procs();
#pragma omp parallel num_threads(cores + 1)
if (omp_get_thread_num() == 0) {
send();
blockingReceive();
}
else
{
work();
}
}
This is not really a question about OpenMP, or, certainly not about the standard. In general it is very unlikely that the OpenMP implementation is aware that the thread executing the blockingReceive()
has blocked, since it cannot easily discover that it can block at compile time, and can't see it at run-time either unless it intercepts all system calls.
Instead, this is a question about how the operating system schedules threads when there are more threads than logicalCPUs (oversubscription). If we assume that your blockingReceive()
turns into a blocking read()
system call, then the OS knows that the thread is idle, and should schedule another thread onto that logicalCPU, which is what you wanted.