Starting Scripts with multiple threads

I read Parallel Computing · The Julia Language and Getting Started · The Julia Language but can’t start Julia on Windows 10 with multiple threads.
Questions:

  • What is the difference between julia -p auto to start julia in cmd/terminal and set JULIA_NUM_THREADS=4?
  • Why is nprocs and addproc only available after julia is started via julia -p N?
  • How do I get Threads.@spawn println(Threads.threadid()) to work?

Thank you for all the great support!

Hi.

The difference between julia -p and export JULIA_NUM_THREADS is that the former starts additional workers, which are single instances of Julia each with its own memory, whereas the latter starts threads working in shared memory. I.e. if you do not want distributed memory in parallel code, you should probably rely on threads. nprocs and addprocs are only available if you import the package using Distributed, as these functions are not part of base. The -p flag does that on startup.

To start up threads on windows, try to maneuver to the folder where your Julia executable is, and then set the environment variable with the windows command line. You can also use the bash terminal provided by git, if you prefer that.

1 Like

I’m able to start a julia process via cmd with JULIA_NUM_THREADS = N enabled. But if I try to start julia from another program (in my case c#), julia will always run single threaded.

Is there a way to force julia system wide to run with JULIA_NUM_THREADS = N enabled?

1 Like