# Adding Threads

**URL:** <https://discourse.julialang.org/t/adding-threads/36011>\
**Category:** Julia at Scale\
**Created:** [March 15, 2020, 2:27pm UTC](https://discourse.julialang.org/t/adding-threads/36011 "2020-03-15T14:27:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [March 15, 2020, 2:27pm UTC](https://discourse.julialang.org/t/adding-threads/36011/1 "2020-03-15T14:27:29Z")

</div>

i’m newbie parallel computing and i’m trying to practice it a little bit and when i want to add threads: `set JULIA_NUM_THREADS =4` i get this Error and i don’t get if i should add something or what: `ERROR: syntax: extra token "JULIA_NUM_THREADS" after end of expression`

---

<div class="post-metadata">

**Author:** ![visr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/visr/32/17204_2.png) [@visr](https://discourse.julialang.org/u/visr)\
**Post date:** [March 15, 2020, 2:36pm UTC](https://discourse.julialang.org/t/adding-threads/36011/2 "2020-03-15T14:36:36Z")

</div>

It looks like you are doing this inside a Julia session. JULIA\_NUM\_THREADS is an environment variable that needs to be set already at the time you start a new Julia session, it cannot be done afterwards. See also [Environment Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/environment-variables/index.html#JULIA_NUM_THREADS-1).

---

<div class="post-metadata">

**Author:** ![marouane1994](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Post date:** [March 15, 2020, 2:49pm UTC](https://discourse.julialang.org/t/adding-threads/36011/3 "2020-03-15T14:49:06Z")

</div>

oh i get it it’s working now thanks

---

<div class="post-metadata">

**Author:** ![MJF](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@MJF](https://discourse.julialang.org/u/MJF)\
**Post date:** [June 10, 2022, 1:39pm UTC](https://discourse.julialang.org/t/adding-threads/36011/4 "2022-06-10T13:39:42Z")

</div>

So where can you set the number of threads if not in the REPL or the file itself?

---

<div class="post-metadata">

**Author:** ![pkienscherf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pkienscherf/32/13903_2.png) [@pkienscherf](https://discourse.julialang.org/u/pkienscherf)\
**Post date:** [June 10, 2022, 2:01pm UTC](https://discourse.julialang.org/t/adding-threads/36011/5 "2022-06-10T14:01:24Z")

</div>

You can, e.g., start Julia with `julia -t 4` (here, with 4 threads) from your terminal for a single session. The environment variable can for instance be set in your bash configuration file. How exactly this is done depends somewhat on your system, see here: [Environment Variables · The Julia Language](https://docs.julialang.org/en/v1/manual/environment-variables/)
