Changing the Number of Threads for parallel Computing in Julia on Linux
Guide
In Julia, parallel computing is routinely used, so sometimes it’s necessary to focus all of a computer’s resources on the computation. There are several ways to change the number of threads, but the most static and convenient method is to edit the environment variables.
Step 1. Edit System Environment Variables
Press Ctrl + Alt + T to open the terminal and type gedit ~/.bashrc
. A window for editing environment variables will pop up like this.
Step 2. Modification
Add export JULIA_NUM_THREADS=5
at the very bottom. You can modify it with the desired number of threads where it’s indicated in the screenshot. The appropriate number of threads varies with the computer’s specifications, but since we’re dealing with an example, let’s modify it to $5$ arbitrarily.
Step 3. Verification
using Base.Threads
nthreads()
Execute the above code in the Julia console to verify.