# Setting number of processors on Windows

**URL:** <https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680>\
**Category:** New to Julia\
**Created:** [April 16, 2020, 4:53am UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680 "2020-04-16T04:53:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [April 16, 2020, 4:53am UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/1 "2020-04-16T04:53:11Z")

</div>

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

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

```

It seems that the suggestion on this [previous](https://julialang.org/blog/2019/07/multithreading/) thread did not work. Could you tell me how to set the number of threads to 4 ?

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [April 16, 2020, 5:56am UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/2 "2020-04-16T05:56:41Z")

</div>

You set it as environment variable(in your command line console, not julia console). see the [doc](https://docs.julialang.org/en/v1/manual/parallel-computing/#Setup-1)

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.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 16, 2020, 6:44am UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/3 "2020-04-16T06:44:57Z")

</div>

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](https://discourse.julialang.org/t/how-to-change-the-number-of-threads/6169/7)

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 🙂 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
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

```

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [April 16, 2020, 12:34pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/4 "2020-04-16T12:34:02Z")

</div>

The doc says

```julia
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 ?

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [April 16, 2020, 12:36pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/5 "2020-04-16T12:36:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 16, 2020, 12:38pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/6 "2020-04-16T12:38:01Z")

</div>

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`:

```julia
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

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 16, 2020, 12:43pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/7 "2020-04-16T12:43:29Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [April 16, 2020, 12:48pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/8 "2020-04-16T12:48:12Z")

</div>

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

```julia
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.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [April 16, 2020, 1:02pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/9 "2020-04-16T13:02:25Z")

</div>

That just means that Julia isn’t in your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)#DOS,_OS/2,_and_Windows) - you can either add it or go to your Julia folder and type `julia` there

---

<div class="post-metadata">

**Author:** ![L\_Adam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/l_adam/32/12086_2.png) [@L\_Adam](https://discourse.julialang.org/u/L_Adam)\
**Post date:** [April 16, 2020, 1:08pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/10 "2020-04-16T13:08:52Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [April 16, 2020, 3:04pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/11 "2020-04-16T15:04:55Z")

</div>

> [@nilshg](#):
>
> set JULIA\_NUM\_THREADS=4

Thanks !

---

<div class="post-metadata">

**Author:** ![iamsuddhasattwa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iamsuddhasattwa/32/7441_2.png) [@iamsuddhasattwa](https://discourse.julialang.org/u/iamsuddhasattwa)\
**Post date:** [April 16, 2020, 3:05pm UTC](https://discourse.julialang.org/t/setting-number-of-processors-on-windows/37680/12 "2020-04-16T15:05:10Z")

</div>

Thanks !
