Answer a question

I was trying to use Julia's multi-threading in VS Code on a Jupyter notebook, but all the help I found show that the VS Code extension that had a nice GUI that let you change the number of threads under "Julia: Num Threads" in the extension's settings like so:

Picture of what Julia extension settings should look like.

However, this wasn't available for me (Windows 10, Julia 1.7.2, and VS Code Julia extension v1.6.6). Instead, it said "Edit in settings.json" which I was totally unfamiliar with. It looks like this for me:

Picture of what settings actually looked like.

It's worth noting that opening the VS Code Powershell and changing the environment variables with $env:JULIA_NUM_THREADS=4 did work... But only for the terminal in VS Code and left my VS Code Jupyter notebook unaffected.

What do I need to add to the settings.json file to change the threads for a Jupyter notebook in the VS Code Julia extension?

Answers

So I figured out how to fix the problem.

The quick fix (no details explaining stuff)

I clicked the "Edit in settings.json" link under "Julia: Num Threads", and then added the lines,

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

between the first and last curly braces (ie, the outermost curly braces, { ... }.

The longer answer

Determining the number of threads on your CPU

I like to manually set the number of threads for hardware specific constraints, so I needed to determine what my max number of CPU threads was. To do this, I opened up PowerShell and typed in wmic cpu get name, and then got a result of

Name
Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz

I copied this into a search engine, and clicked on a link from a webpage on Intel.com that was titled the same as the name of the processor. There was a section on the page titled "CPU Specifications" that had "Total Threads" listed as 12.

Example of settings.json file and a basic overview of JSON syntax

Example

So the settings.json file should look something like,

{
    // There will probably be some other VS Code settings with a layout similar to 
    "nameOfFeatureInVSCode.specificSetting": true,

    // You might also see stuff with a list of values like
    "nameOfOtherFeature.settingThatCanUseMultipleValues": [
        "FirstStringSetting",
        "SecondStringSetting"
    ],

   // And all you need to do is add these lines
    "julia.NumThreads": 12,
    "settingsSync.ignoredSettings": [
        "-julia.NumThreads"
    ],

}

Basic overview of JSON

Note that the thing following the colon (: <value>) could be a boolean value, string, integer, or other data types depending on the particular setting.

If you're coming from Python, you'll notice the JSON syntax is like the syntax for dictionaries in Python in which there are key-value pairs. So, like Python dicts, the key is on the left side of the colon, the value is on the right side of the colon, and the value can be a list of data values.

Logo

开发云社区提供前沿行业资讯和优质的学习知识,同时提供优质稳定、价格优惠的云主机、数据库、网络、云储存等云服务产品