How to change the number of threads?

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

julia> Threads.nthreads()
1

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

4 Likes

Set the JULIA_NUM_THREADS environment variable. See 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.

9 Likes

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
and
https://docs.julialang.org/en/v1.0/manual/environment-variables/#JULIA_NUM_THREADS-1

7 Likes

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.

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.

8 Likes

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

grafik

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

In Juno. It works in the terminal REPL.

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.

3 Likes

Thanks a lot :slight_smile: