# Starting Scripts with multiple threads

**URL:** https://discourse.julialang.org/t/starting-scripts-with-multiple-threads/38014
**Category:** New to Julia
**Tags:** question
**Created:** [April 22, 2020, 7:56am UTC](https://discourse.julialang.org/t/starting-scripts-with-multiple-threads/38014 "2020-04-22T07:56:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)
#### Post date: [April 22, 2020, 7:56am UTC](https://discourse.julialang.org/t/starting-scripts-with-multiple-threads/38014/1 "2020-04-22T07:56:03Z")

</div>

I read [Parallel Computing · The Julia Language](https://docs.julialang.org/en/v1/manual/parallel-computing/#Setup-1) and [Getting Started · The Julia Language](https://docs.julialang.org/en/v1/manual/getting-started/#man-getting-started-1) 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!

---

<div class="post-metadata">

### Author: ![dkiese](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dkiese](https://discourse.julialang.org/u/dkiese)
#### Post date: [April 22, 2020, 8:51am UTC](https://discourse.julialang.org/t/starting-scripts-with-multiple-threads/38014/2 "2020-04-22T08:51:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Impressium](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impressium/32/19575_2.png) [@Impressium](https://discourse.julialang.org/u/Impressium)
#### Post date: [April 27, 2020, 11:10am UTC](https://discourse.julialang.org/t/starting-scripts-with-multiple-threads/38014/3 "2020-04-27T11:10:27Z")

</div>

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?
