# @threads :Static seems not doing static scheduling?

**URL:** https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386
**Category:** General Usage
**Tags:** question
**Created:** [March 21, 2023, 11:54am UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386 "2023-03-21T11:54:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 21, 2023, 11:54am UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/1 "2023-03-21T11:54:28Z")

</div>

I start julia with `set JULIA_EXCLUSIVE=1` and `julia -t 2` and I have multi-threaded code. Meanwhile running it, I don’t know why I can not see two cores working with their maximum? but rather a switching between cores although I used static scheduling. This is actually is killing the performance for the parallel code. Any reason for that or to solve it?  
Note that when I run the serial version of the code, somehow only two cores works (I don’t know also why not only one) but at least one core with its maximum

---

<div class="post-metadata">

### Author: ![BioTurboNick](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bioturbonick/32/6380_2.png) [@BioTurboNick](https://discourse.julialang.org/u/BioTurboNick)
#### Post date: [March 21, 2023, 2:22pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/2 "2023-03-21T14:22:22Z")

</div>

There’s no guarantee from the OS that one process thread will be pinned to one core, is there?

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 21, 2023, 2:28pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/3 "2023-03-21T14:28:57Z")

</div>

It seems no guarantee, but then what is the meaning of using `:Static` with `@threads`?

---

<div class="post-metadata">

### Author: ![jishnub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jishnub/32/33620_2.png) [@jishnub](https://discourse.julialang.org/u/jishnub)
#### Post date: [March 21, 2023, 2:39pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/4 "2023-03-21T14:39:15Z")

</div>

`static` implies that tasks are pinned to threads, and won’t migrate between threads. This means that `Threads.threadid()` will be a constant throughout in the task. It does not mean that the thread can’t migrate between cores.

---

<div class="post-metadata">

### Author: ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)
#### Post date: [March 21, 2023, 2:42pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/5 "2023-03-21T14:42:19Z")

</div>

For pinning threads to cores (rather than tasks to threads), you should probably use [[ANN] Announcing ThreadPinning.jl](https://discourse.julialang.org/t/ann-announcing-threadpinning-jl/92230)

---

<div class="post-metadata">

### Author: ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)
#### Post date: [March 21, 2023, 2:47pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/6 "2023-03-21T14:47:16Z")

</div>

Based on the screenshots, I assume that the OP is on Windows, which currently isn’t supported by ThreadPinning.jl. Instead, @Amro, you can try setting the environment variable `JULIA_EXCLUSIVE=1` before starting Julia.

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 21, 2023, 2:49pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/7 "2023-03-21T14:49:07Z")

</div>

> [@carstenbauer](#):
>
> you can try setting the environment variable `JULIA_EXCLUSIVE=1` before starting Julia.

Thanks for your feedback. Yes, it is windows. I have already mentioned that I used it in powershell (do I need to use it in environment variable in windows?). But still no cores are pinned. Does it needs a special care?

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 21, 2023, 2:52pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/8 "2023-03-21T14:52:35Z")

</div>

> [@Oscar\_Smith](#):
>
> For pinning threads to cores (rather than tasks to threads), you should probably use [[ANN] Announcing ThreadPinning.jl](https://discourse.julialang.org/t/ann-announcing-threadpinning-jl/92230)

Thanks for your feedback. As `carstenbauer` it is not supported for windows

---

<div class="post-metadata">

### Author: ![Amro](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@Amro](https://discourse.julialang.org/u/Amro)
#### Post date: [March 21, 2023, 2:54pm UTC](https://discourse.julialang.org/t/threads-static-seems-not-doing-static-scheduling/96386/9 "2023-03-21T14:54:16Z")

</div>

> [@jishnub](#):
>
> It does not mean that the thread can’t migrate between cores.

Thanks for your feedback. Is there a package in windows to pin threads to cores in Julia?
