[Openmp-dev] OpenMP code and thread priority on OSX

Stéphane Letz via Openmp-dev openmp-dev at lists.llvm.org
Thu Nov 26 05:07:28 PST 2015

Le 26 nov. 2015 à 13:54, "Cownie, James H" <james.h.cownie at intel.com> a écrit :

> The OpenMP runtime does not manipulate thread priorities
> A first skim through https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KernelProgramming/scheduler/scheduler.html doesn't make it clear to me whether threads inherit their priority from their creator.
> Since OpenMP threads are created using pthread_create, that page suggests you may need to use pthread_setschedparam inside each thread to bump its priority.

The thing is that on OSX audio threads are actually "THREAD_TIME_CONSTRAINT_POLICY" threads, and this priority cannot be setup using Posix API, but needs "thread_policy_set" kind of API (as you can see in the URL you gave).

> (Or you may be able to hack the runtime to pass the priority as an attribute at thread creation time).

Can you possibly point me where exactly in the runtime code?

And would this kind of "inheritance policy" be better dynamically setup? I mean is this a requirement that could be needed for more use-cases to be part on the part of the official code?

> BEWARE, though, you will almost certainly also want to change the default sleep behaviour of your OpenMP threads. By default they will spin for 200ms before sleeping in the kernel, which is unlikely to be helpful to the overall user experience if they’re at high-priority! (See KMP_BLOCKTIME).

Ok thanks.
> Overall OpenMP is not designed for concurrency, but for parallelism, and you may find this a hard thing to make work.
> -- Jim

What do you mean by "not designed for concurrency, but for parallelism" in this specific use context?


Stéphane Letz

More information about the Openmp-dev mailing list