# Multi-threading not possible

**URL:** <https://discourse.julialang.org/t/multi-threading-not-possible/89698>\
**Category:** New to Julia\
**Tags:** multithreading\
**Created:** [November 3, 2022, 8:09am UTC](https://discourse.julialang.org/t/multi-threading-not-possible/89698 "2022-11-03T08:09:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Curtis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sam_curtis/32/37647_2.png) [@Sam\_Curtis](https://discourse.julialang.org/u/Sam_Curtis)\
**Post date:** [November 3, 2022, 8:09am UTC](https://discourse.julialang.org/t/multi-threading-not-possible/89698/1 "2022-11-03T08:09:43Z")

</div>

Hello all, I’ve been trying to increase the number of threads being used by julia in visual code. I tried initally through Julia to increase it,  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/4/f4f0a18d73076cca13dcb115bde53cdb140a7416.png)  
I have also tried using CMD (set JULIA\_NUM\_THREADS=4) as a new user can’t use more than one screen shot, it still hasn’t increased, I’m sure I’m typing in the code wrong but any help will be much appreciated

---

<div class="post-metadata">

**Author:** ![CodeGodz](https://avatars.discourse-cdn.com/v4/letter/c/aeb1de/32.png) [@CodeGodz](https://discourse.julialang.org/u/CodeGodz)\
**Post date:** [November 3, 2022, 8:22am UTC](https://discourse.julialang.org/t/multi-threading-not-possible/89698/2 "2022-11-03T08:22:27Z")

</div>

**Using export**  
You should set the number of threads outside the julia REPL itself (and use export [to export an environment variable](https://www.serverlab.ca/tutorials/linux/administration-linux/how-to-set-environment-variables-in-linux/)), like so:

`export JULIA_NUM_THREADS=4` (in your terminal)  
then you can open julia:  
`julia`  
and check the threads  
`Threads.nthreads()`

**Start julia with --threads**  
Alternatively, you can also start julia passing the number of threads:  
`julia --threads 4`  
The difference with `export` is that you would have to pass `--threads` every time you start the julia REPL, whereas with export you don’t (at least [as long as you use the same terminal](https://stackoverflow.com/questions/13046624/how-to-permanently-export-a-variable-in-linux/31546962) in which you exported)

Hope that’s clear 🙂

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [November 3, 2022, 8:24am UTC](https://discourse.julialang.org/t/multi-threading-not-possible/89698/3 "2022-11-03T08:24:01Z")

</div>

You need to start Julia with a command line switch to enable more threads.

In the VScode Julia Extension settings, edit the “Julia: Num Threads” settings in settings.json. Mine is set to:

```julia
    "julia.NumThreads": "auto",

```

This should select as many threads as possible, or you can manually enter a number. Then restart the REPL.

On my machine, this results in:

```julia
julia> Threads.nthreads()
20

```

---

<div class="post-metadata">

**Author:** ![Sam\_Curtis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sam_curtis/32/37647_2.png) [@Sam\_Curtis](https://discourse.julialang.org/u/Sam_Curtis)\
**Post date:** [November 3, 2022, 8:28am UTC](https://discourse.julialang.org/t/multi-threading-not-possible/89698/4 "2022-11-03T08:28:19Z")

</div>

Thanks a lot thats work perfectly
