# Thread pinning interacts with OpenMP?

**URL:** <https://discourse.julialang.org/t/thread-pinning-interacts-with-openmp/114204>\
**Category:** General Usage\
**Created:** [May 13, 2024, 3:14pm UTC](https://discourse.julialang.org/t/thread-pinning-interacts-with-openmp/114204 "2024-05-13T15:14:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 13, 2024, 3:14pm UTC](https://discourse.julialang.org/t/thread-pinning-interacts-with-openmp/114204/1 "2024-05-13T15:14:17Z")

</div>

This problem prevents me from using thread pinning. I wonder how Julia threads (implemented on top of pthreads, IIUC), mess with OpenMP threads?

> <https://github.com/carstenbauer/ThreadPinning.jl/issues/94?notification_referrer_id=NT_kwDOAJZjWLMxMDU2MjQxNTA1NTo5ODU1ODMy#issuecomment-2102764980>
>
> TLDR: An external OpenMP-equipped C++ library shows no parallel speedup when thr…ead pinning is used. Disabling pinning fixed the issue.
> 
> https://discourse.julialang.org/t/openmp-in-a-shared-library-opened-in-julia/113880/9

---

<div class="post-metadata">

**Author:** ![vchuravy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vchuravy/32/8_2.png) [@vchuravy](https://discourse.julialang.org/u/vchuravy)\
**Post date:** [May 14, 2024, 12:32pm UTC](https://discourse.julialang.org/t/thread-pinning-interacts-with-openmp/114204/2 "2024-05-14T12:32:32Z")

</div>

OpenMP and Julia both pthreads. So ThreadPinning.jl may not account for the OpenMP threads and it is not guaranteed what the mapping of pthreads to OpenMP threads is.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [May 14, 2024, 3:18pm UTC](https://discourse.julialang.org/t/thread-pinning-interacts-with-openmp/114204/3 "2024-05-14T15:18:06Z")

</div>

I appreciate that both Julia and OpenMP may use pthreads. This still does not explain why pinning some threads would make it impossible for an OpenMP code to run in parallel. There are definitely many threads left unspoken for. For instance, I run this on a machine with 64 hardware threads, and I start Julia with four threads. Yet, the OpenMP code does not achieve any speedup when I initially pin the threads. If I don’t pin the threads, the OpenMP code reports speedups as expected.
