# Thread affinitization: pinning Julia threads to cores

**URL:** https://discourse.julialang.org/t/thread-affinitization-pinning-julia-threads-to-cores/58069
**Category:** General Usage
**Tags:** multithreading
**Created:** [March 27, 2021, 8:04am UTC](https://discourse.julialang.org/t/thread-affinitization-pinning-julia-threads-to-cores/58069 "2021-03-27T08:04:36Z")
**Posts on this page:** 1
**Showing post:** 7

<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: [March 30, 2021, 3:19pm UTC](https://discourse.julialang.org/t/thread-affinitization-pinning-julia-threads-to-cores/58069/7 "2021-03-30T15:19:37Z")

</div>

To answer your question I did on my Linux:

```julia
gdb --args julia -e "exit()"
(gdb) b pthread_create
Breakpoint 1, 0x00007ffff77fb560 in pthread_create@@GLIBC_2.2.5 ()
   from /usr/bin/../lib/libpthread.so.0

```

and then looked at the backtraces of all the location were we are creating threads during startup.

- 1x `pthread_create` in `src/signals-unix.c`
- 7x `pthread_ctreate` in `blas_thread_init () from /usr/bin/../lib/julia/libopenblas64_.so`

Starting Julia with `-t 4` adds another three calls in `jl_start_threads`.

Setting `OPENBLAS_NUM_THREADS=1` as an environment removes the additional threads created by OpenBLAS. Leaving you with the main thread, the signal thread and the `-t N` N-1 worker threads.

I suspect that all of the thread pinning libraries like `numactl` treats all of them equally, which is why you see two Julia threads being pinned to the same process, since OpenBLAS in the mix oversubscribes the cores. There was some initial thinking about having OpenBLAS use the Julia thread pool [partr thread support for openblas · Issue #32786 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/32786), but that hasn’t been implemented yet.

---

_[View the full topic](https://discourse.julialang.org/t/thread-affinitization-pinning-julia-threads-to-cores/58069)._
