Search code examples
juliadistributed-computing

Setting nprocs() using the ./startup.jl file


Why does setting ENV[JULIA_CPU_THREADS]=5 and ENV[JULIA_NUM_THREADS]=5 not affect nprocs() ? Here is what I get on startup:

julia> versioninfo()
Julia Version 1.3.1
Commit 2d5741174c (2019-12-30 21:36 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-9600K CPU @ 3.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
Environment:
  JULIA_CPU_THREADS = 5
  JULIA_NUM_THREADS = 5
julia> nprocs()
1

So the environment variables are being set but the processes are not being allocated?


Solution

  • The reason is that threads aren't processes. There are different kinds of "parallelism". Processes are used for distributed (multi-core) computing, threads are used for multithreading (on a single machine/node). See the Parallel Computing section of the Julia documentation for more information.

    To start Julia with multiple processes use the command line flag -p N, where N is the number of worker processes. Alternatively, you can addprocs to add processes programmatically in a script (like startup.jl).