logo

Changing the Number of Threads for parallel Computing in Julia on Linux 📂Julia

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

,2020-12-2018-02-14.png

Press Ctrl + Alt + T to open the terminal and type gedit ~/.bashrc. A window for editing environment variables will pop up like this.

,2020-12-2310-33-20.png


Step 2. Modification

,2020-12-2310-34-57.png

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.

,2020-12-2310-35-41.png