JULIA_NUM_THREADS in VS Code (Windows 10 + WSL)

I recently came across this thread:

about setting the environment variable JULIA_NUM_THREADS in Windows, and was wondering if anyone know how this would work in VS Code (context: I am using a computer with Windows 10 and the Linux subsystem). The only way I have gotten Julia to start with multiple threads is to start a new bash session in the same directory as julia.exe, but this is inconvenient for when I am writing code (VS Code by default starts a session in the workspace directory).

Any assistance would be appreciated. Thanks.

5 Likes

You can set additional env variables for the julia REPL via the julia.additionalArgs setting of the Julia extension in VS Code.

2 Likes

I apologize if this is obvious, but could be more specific about what to add to the setting.json?

2 Likes

What argument should be added there? just julia.JULIA_NUM_ThREADS ?

I think we added an explicit setting for the number of threads now, but it might currently only be on the alpha build for the next version, which you can try here. That is also the only version that works with Julia 1.3 currently.

You can find it now in the settings of the Julia extension of vscode.
grafik

14 Likes

This extension setting works for me in the REPL, but it does not extend to the Run Tests (w/wo Coverage) Task. I don’t know the VS codebase, but I’ll take a look to see if it is an easy PR.

Yes, good point, we are not currently picking it up for the test runner. It should be an easy PR, the point where you would add this is here. PR would be great!

PR in place. https://github.com/julia-vscode/julia-vscode/pull/930. I’m not able to run the test suite on my machine, but the Travis builds are passing, in any case. I did test the functionality on my machine by directly editing the extension JS files. Let me know if you need anything done.

I apologize if this is obvious, but could be more specific about what to add to the setting.json?

This was never answered, and I’m using an old version of the Julia extension due to the problem and suggested solution here: Ctrl-C doesn't interrupt Alt-Enter code · Issue #767 · julia-vscode/julia-vscode · GitHub, so I do not have access to the the GUI Num Threads setting in the extension.

What exactly should one add to the setting.json to set the number of threads? Thank you.

Edit: If it makes a difference, I am on Ubuntu 18.04, not Windows 10.

I apologize if this is obvious, but could be more specific about what to add to the setting.json?

I did not figure out how to do this, but, for anyone in a similar situation, you can simply edit your .bashrc file to set the environment variable. Add export JULIA_NUM_THREADS=4 (replace 4 with desired number) as a line at the bottom of your .bashrc file, restart your computer (logging out and in might be enough), and you are all set.

1 Like

Just to answer this for anyone that finds this thread, I was using 1.7.2 Julia and the VSCode Julia extension v.1.6.6, and the nice box to change the number of threads wasn’t there. Instead there was a “Edit in settings.json” link.

I could change the threads in the terminal instance of Julia but it wouldn’t register in my Jupyter notebooks within VS Code. Eventually, I figured out the solution.

Here’s what I added to the settings.json file:

"julia.NumThreads": 12,
    "settingsSync.ignoredSettings": [
        "-julia.NumThreads"
    ],

Altogether, the settings.json file should look something like the following:

{
    # Probably has some settings for 
    # color schemes, zoomlevel, etc.

    # Then you should add these lines:
    "julia.NumThreads": 12,
    "settingsSync.ignoredSettings": [
        "-julia.NumThreads"
    ],
    
    
}
9 Likes