# How do I actually control number of threads with JIT

**URL:** <https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745>\
**Category:** Support: How do I do ...?\
**Created:** [June 9, 2021, 2:33am UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745 "2021-06-09T02:33:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![brunomagacho](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/brunomagacho/32/342_2.png) [@brunomagacho](https://numba.discourse.group/u/brunomagacho)\
**Post date:** [June 9, 2021, 2:33am UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/1 "2021-06-09T02:33:03Z")

</div>

Hello guys,

I’m new to numba.

I run Lattice Boltzmann Simulations when using numba (specifically jit with parallel=True), I could speed up my simulations a lot, for example going from 13 hours to 4 hours in my home computer and thats amazing.

Then I runned my code in a cluster and the simulation took more time than in my home computer.

When I was checking the processors, I actually saw that the simulations was using only one of the processors of the cluster and not as I was expecting the number of threads that I set, using numba.set\_num\_threads(64).

So I would like to understand better how this works and if it would be possible to solve this.

In my home computer I have a Ryzen 7 3700x with 16 threads, and actually checking the numba.set\_num\_threads(), I tried to run with 8 threads (half) but when I was looking at my processors, it looks that all of them are in use, but with 50% of capacity. This let me confuse also, because I though that it would literally use 8 threads and it wasnt what happened.

Any help would be great.

---

<div class="post-metadata">

**Author:** ![DrTodd13](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/drtodd13/32/51_2.png) [@DrTodd13](https://numba.discourse.group/u/DrTodd13)\
**Post date:** [June 10, 2021, 3:49pm UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/2 "2021-06-10T15:49:47Z")

</div>

How did you run your code in a cluster?

---

<div class="post-metadata">

**Author:** ![brunomagacho](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/brunomagacho/32/342_2.png) [@brunomagacho](https://numba.discourse.group/u/brunomagacho)\
**Post date:** [June 10, 2021, 8:35pm UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/3 "2021-06-10T20:35:39Z")

</div>

Hello DrTodd13

A frind of mine has acess to one, but essentially he runned the same way as I do in my home computer, from the terminal. But I think that my biggest issue right now, a part from the cluster, is why when I set the number of threads to a value, all the threads remain in use but with a lower % of usage.

---

<div class="post-metadata">

**Author:** ![DrTodd13](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/drtodd13/32/51_2.png) [@DrTodd13](https://numba.discourse.group/u/DrTodd13)\
**Post date:** [June 10, 2021, 8:56pm UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/4 "2021-06-10T20:56:38Z")

</div>

Which Numba threading backend are you using?

---

<div class="post-metadata">

**Author:** ![brunomagacho](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/brunomagacho/32/342_2.png) [@brunomagacho](https://numba.discourse.group/u/brunomagacho)\
**Post date:** [June 10, 2021, 9:54pm UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/5 "2021-06-10T21:54:31Z")

</div>

Do you mean the threading layer? If so, I’m using the omp

---

<div class="post-metadata">

**Author:** ![DrTodd13](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/drtodd13/32/51_2.png) [@DrTodd13](https://numba.discourse.group/u/DrTodd13)\
**Post date:** [June 10, 2021, 11:52pm UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/6 "2021-06-10T23:52:33Z")

</div>

See if you still see the behavior with different threading layers. For OMP, you can also try “export OMP\_PROC\_BIND=true”.

---

<div class="post-metadata">

**Author:** ![brunomagacho](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/brunomagacho/32/342_2.png) [@brunomagacho](https://numba.discourse.group/u/brunomagacho)\
**Post date:** [June 11, 2021, 1:04am UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/7 "2021-06-11T01:04:50Z")

</div>

For all the threading layers I tried it happens, forksafe, threadsafe and default.

I’m sorry, but I don’t know where I should change this variable “export OMP\_PROC\_BIND=true”

I’m new with those tools and use a windows system. Where I can change this variable?

Thanks for the fast reply.

---

<div class="post-metadata">

**Author:** ![DrTodd13](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/drtodd13/32/51_2.png) [@DrTodd13](https://numba.discourse.group/u/DrTodd13)\
**Post date:** [June 11, 2021, 3:17pm UTC](https://numba.discourse.group/t/how-do-i-actually-control-number-of-threads-with-jit/745/8 "2021-06-11T15:17:35Z")

</div>

> **[Set Environment Variable in Windows {How-To} | phoenixNAP KB](https://phoenixnap.com/kb/windows-set-environment-variable)**
>
> This tutorial covers different ways to set, view, and unset environment variables in Windows using the GUI, Command Prompt and PowerShell.

You can look there for help to set an environment variable.
