# How to start a julia process on a remote machine with multiple threads?

**URL:** <https://discourse.julialang.org/t/how-to-start-a-julia-process-on-a-remote-machine-with-multiple-threads/96628>\
**Category:** General Usage\
**Tags:** distributed\
**Created:** [March 26, 2023, 2:41pm UTC](https://discourse.julialang.org/t/how-to-start-a-julia-process-on-a-remote-machine-with-multiple-threads/96628 "2023-03-26T14:41:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucasmsoares96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmsoares96/32/38743_2.png) [@lucasmsoares96](https://discourse.julialang.org/u/lucasmsoares96)\
**Post date:** [March 26, 2023, 2:41pm UTC](https://discourse.julialang.org/t/how-to-start-a-julia-process-on-a-remote-machine-with-multiple-threads/96628/1 "2023-03-26T14:41:10Z")

</div>

When starting a Julia session with the following command `julia --machine-file machine-file.txt -p 2`, the processes created on the remote machine have only one thread, even with the environment variable `JULIA_NUM_THREADS` defined as 8 in the local machine and the machine.

---

<div class="post-metadata">

**Author:** ![SteffenPL](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/steffenpl/32/206270_2.png) [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Post date:** [March 26, 2023, 4:29pm UTC](https://discourse.julialang.org/t/how-to-start-a-julia-process-on-a-remote-machine-with-multiple-threads/96628/2 "2023-03-26T16:29:07Z")

</div>

Just a quick reply, there is the CMD option `-t` for the number of threads. [Multi-Threading · The Julia Language](https://docs.julialang.org/en/v1/manual/multi-threading/) Notice the difference between threads and processes…

E.g. does `julia -t 8 ...` work? (Not sure why the `JULIA_NUM_THREADS` doesn’t work. Maybe it depends on the way you connect to the remove machine.)

---

<div class="post-metadata">

**Author:** ![LeePhillips](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leephillips/32/205514_2.png) [@LeePhillips](https://discourse.julialang.org/u/LeePhillips)\
**Post date:** [March 26, 2023, 4:42pm UTC](https://discourse.julialang.org/t/how-to-start-a-julia-process-on-a-remote-machine-with-multiple-threads/96628/3 "2023-03-26T16:42:06Z")

</div>

Starting with `julia -tn -pm --machine-file=etc.` does indeed get you `n` threads on each remote machine.

MORE DETAILS:

Just for completeness…In simple cases your -tn flag is propagated to the remote workers. But if you want to use different numbers of threads on different workers, you can use `addprocs()` ([Distributed Computing · The Julia Language](https://docs.julialang.org/en/v1/stdlib/Distributed/#Distributed.addprocs)):

```julia
julia> addprocs([("sp4", 2)]; exeflags="-t 3");
                       # ↑ 2 worker processes on sp4, please
julia> fetch(@spawnat 3 readchomp(`hostname`))
"sp4"

julia> fetch(@spawnat 3 Threads.nthreads())
3

julia> Threads.nthreads()
1

```

Here “sp4” is the hostname of another computer in my apartment that has Julia installed.

---

<div class="post-metadata">

**Author:** ![lucasmsoares96](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lucasmsoares96/32/38743_2.png) [@lucasmsoares96](https://discourse.julialang.org/u/lucasmsoares96)\
**Post date:** [March 26, 2023, 5:20pm UTC](https://discourse.julialang.org/t/how-to-start-a-julia-process-on-a-remote-machine-with-multiple-threads/96628/4 "2023-03-26T17:20:05Z")

</div>

It works. Thank you guys.
