# How to change the number of threads?

**URL:** <https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169>\
**Category:** General Usage\
**Tags:** parallel, multithreading\
**Created:** [September 30, 2017, 3:47pm UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169 "2017-09-30T15:47:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![jw3126](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jw3126/32/3086_2.png) [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Post date:** [September 30, 2017, 3:47pm UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/1 "2017-09-30T15:47:36Z")

</div>

How to change the number of threads? Currently it is one for me:

```nohighlight
julia> Threads.nthreads()
1

```

Is there a function/command line flag to add more threads? Is this documented somewhere?

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [September 30, 2017, 3:57pm UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/2 "2017-09-30T15:57:10Z")

</div>

Set the `JULIA_NUM_THREADS` environment variable. See [https://docs.julialang.org/en/stable/manual/parallel-computing/#Multi-Threading-(Experimental)-1](https://docs.julialang.org/en/stable/manual/parallel-computing/#Multi-Threading-(Experimental)-1) and [https://docs.julialang.org/en/stable/manual/environment-variables/#JULIA\_NUM\_THREADS-1](https://docs.julialang.org/en/stable/manual/environment-variables/#JULIA_NUM_THREADS-1).

---

<div class="post-metadata">

**Author:** ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)\
**Post date:** [December 11, 2018, 5:36pm UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/3 "2018-12-11T17:36:54Z")

</div>

In case anyone is searching for this, the correct links are now  
[https://docs.julialang.org/en/v1.0/manual/parallel-computing/#Multi-Threading-(Experimental)-1](https://docs.julialang.org/en/v1.0/manual/parallel-computing/#Multi-Threading-(Experimental)-1)  
and  
[https://docs.julialang.org/en/v1.0/manual/environment-variables/#JULIA\_NUM\_THREADS-1](https://docs.julialang.org/en/v1.0/manual/environment-variables/#JULIA_NUM_THREADS-1)

---

<div class="post-metadata">

**Author:** ![krenova](https://avatars.discourse-cdn.com/v4/letter/k/53a042/32.png) [@krenova](https://discourse.julialang.org/u/krenova)\
**Post date:** [April 4, 2019, 5:02am UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/4 "2019-04-04T05:02:24Z")

</div>

Any idea, if I’m using visual studio code (VS code), how do I `set JULIA_NUM_THREADS=n` before firing up julia?

I’ve tried changing settings to

> “julia.executablePath”: “cd C:\Users\home\AppData\Local\Julia-1.0.3\bin\ & set JULIA\_NUM\_THREADS=20 & julia.exe”

but the command does not work like it would in command line.

---

<div class="post-metadata">

**Author:** ![vlandau](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vlandau/32/8986_2.png) [@vlandau](https://discourse.julialang.org/u/vlandau)\
**Post date:** [August 6, 2019, 7:37pm UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/5 "2019-08-06T19:37:27Z")

</div>

Is there no way to spawn additional threads inside Julia itself? I’m developing a package that will support parallel processing, and I don’t want users to have to go in and change JULIA\_NUM\_THREADS manually.

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [October 2, 2019, 11:27am UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/6 "2019-10-02T11:27:25Z")

</div>

I followed the instructions on the documentation page, but somehow the number of threads doesn´t change if I change the value of the environment variable `JULIA_NUM_THREADS` .

Does somebody has an idea why? Have I done something wrong?

![grafik](https://global.discourse-cdn.com/julialang/original/3X/b/2/b233bb055bd290f9566a611b3c7277f053c4bb92.png)

![grafik](https://global.discourse-cdn.com/julialang/original/3X/6/1/61be70e4fc43aaaf2d40e13b183b1e3d0b540b2f.png)

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 2, 2019, 11:36am UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/7 "2019-10-02T11:36:35Z")

</div>

Is that in a terminal REPL or are you using Juno?

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [October 2, 2019, 11:37am UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/8 "2019-10-02T11:37:55Z")

</div>

In Juno. It works in the terminal REPL.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [October 2, 2019, 11:43am UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/9 "2019-10-02T11:43:04Z")

</div>

Juno has a set number of threads option in the Atom settings, which defaults to the number of cores. I don’t know exactly if it takes precedence over the environment-variable and if it gets the environment variable might depend on if you started it from a terminal or not.  
But the safest should be to set the number of threads in the `julia-client` settings.

---

<div class="post-metadata">

**Author:** ![Volker](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@Volker](https://discourse.julialang.org/u/Volker)\
**Post date:** [October 2, 2019, 11:53am UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/10 "2019-10-02T11:53:05Z")

</div>

Thanks a lot 🙂

---

<div class="post-metadata">

**Author:** ![cwittens](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cwittens/32/213036_2.png) [@cwittens](https://discourse.julialang.org/u/cwittens)\
**Post date:** [June 4, 2025, 3:00pm UTC](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/11 "2025-06-04T15:00:41Z")

</div>

The Link is not working anymore. Here is an up to date one for future reference:

> **[Multi-Threading · The Julia Language](https://docs.julialang.org/en/v1/manual/multi-threading/)**
>
> Documentation for The Julia Language.
