Starting Julia with multiple threads on Mac M1

If you set an environment variable via export in the terminal, it will only be set within this session. That is, if you open jupyter in a different terminal or by “clicking on the jupyter application”, the environment variable won’t be set there.

There are three ways around it.

  1. As I mentioned before, just put export JULIA_NUM_THREADS=6 into your ~/.bashrc or ~/.zshrc (depending on your shell, see echo $SHELL). This will “globally” set the environment variable such that it should be respected by all applications (including jupyter and julia itself) irrespective of how you start them.

  2. Start jupyter via the terminal as follows: JULIA_NUM_THREADS=6 jupyter

  3. Create an IJulia kernel that automatically sets JULIA_NUM_THREADS before it starts the kernel.

using IJulia
installkernel("Julia (6 threads)", env=Dict("JULIA_NUM_THREADS"=>"6"))
5 Likes