Setting number of processors on Windows

I have julia installed on Windows and I do not know how to set the number of processors.

julia> VERSION
v"1.4.0"
julia> JULIA_NUM_THREADS=4
4
julia> Threads.nthreads()
1

It seems that the suggestion on this previous thread did not work. Could you tell me how to set the number of threads to 4 ?

You set it as environment variable(in your command line console, not julia console). see the doc

For adding more processors at startup,
julia -p n, this will add n extra processors.
julia -p auto, this will add n extra processors with n corresponding to JULIA_NUM_THREADS you just set
Hope that help.

Note that the OP is asking about threads, not processors, which are two separate things. There’s already a discussion with some explanation and the relevant manual links here: How to change the number of threads? - #7 by BeastyBlacksmith

A simple way to do this is to just use Juno which automatically starts with NUM_THREADS set to the number of physical cores as default setting.

EDIT: I should have looked more closely at the topic title :slight_smile: So the title asks about processors, while the MWE given in the post looks at threads. For processors the answer above will work, similarly it is possible to set them after Julia has been started (which isn’t possible for the number of threads):

julia> using Distributed

julia> nprocs()
1

julia> addprocs(4)
4-element Array{Int64,1}:
 2
 3
 4
 5

julia> nprocs()
5

julia> Threads.nthreads()
1
1 Like

The doc says

C shell on Linux/OSX, CMD on Windows: 
set JULIA_NUM_THREADS=4

I dont even know what the first line means. If I enter set JULIA_NUM_THREADS=4 on the terminal and then launch Julia, the number of threads is still 1. Is there any way to use Julia without needing to know OS programming ?

I cannot install Juno from my Atom editor. The Julia REPL or a file menu does not appear even after installing.

It seems to me the most poorly designed IDE ever. Installing and running an IDE should be simple. It seems that the Julia developers have tried all means to bar people from using Julia from Windows.

The first line means exactly what it say: in C shell on Linux or OSX, or cmd in Windows, enter the command set JULIA_NUM_THREADS=4:

Microsoft Windows [Version 10.0.17134.1365]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\ngudat>set JULIA_NUM_THREADS=4

C:\Users\ngudat>julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.3.0-rc5.1 (2019-11-17)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> Threads.nthreads()
4
3 Likes

You might want to start a different thread for issues with installing Atom - I’m unsure however that it is productive to insinuate that the Julia developers in providing free software are somehow trying to deliberately make life harder for Windows.

It is generally well known that Windows is not a great development environment and doesn’t mesh well especially with the open source software world that largely runs on Linux - many people in the ecosystem go to great lengths to jump over obstacles that Microsoft puts in their path to make life as easy as possible for Windows users. (Tbf Microsoft also seems to recognize this and trying to alleviate the problems by having the Windows Subsystem for Linux, a new Windows Terminal etc etc)

1 Like

Thank you very much for the details. But I did try this before, and I get this error.

C:\Users\iamsu>julia
'julia' is not recognized as an internal or external command, operable program or batch file.

I have been launching julia from the start menu shortcut.

That just means that Julia isn’t in your PATH - you can either add it or go to your Julia folder and type julia there

3 Likes

I suppose you run julia in another session from your GUI shortcut? If you export JULIA_NUM_THREADS variable and type julia after that, julia will pick up that variable in current session and do whatever it needs to initialize 4 threads, in your case.

'julia' is not recognized as an internal or external command, operable program or batch file.
means system could not locate julia. You need to add the location of julia bin directory to your system path.

I haven’t used Juno yet. In Atom, suppose you could launch julia from atom’s power shell(does it need a plugin?), set JULIA_NUM_THREADS=4; julia should just work

I understand the frustration of transition from gui to command line interface. But that’s just how it works.

1 Like

Thanks !

Thanks !