# Multiple Computer Example

**URL:** <https://discourse.julialang.org/t/multiple-computer-example/10518>\
**Category:** Julia at Scale\
**Created:** [April 24, 2018, 10:42pm UTC](https://discourse.julialang.org/t/multiple-computer-example/10518 "2018-04-24T22:42:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 24, 2018, 10:42pm UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/1 "2018-04-24T22:42:10Z")

</div>

Does anybody have a really simple example of a local host farming out a task to another ssh-connected computer (with julia on it)?

think

```julia
@everywhere function abc(n::Int)
      sum=0; for i=1:n; sum+=i; end;#for
      return ( readstring(`hostname`), sum )
end#function

hosts = ["localhost", "friend.ucla.edu"]

println( pmap( i -> abc(i), 1:1000, hosts ) )

```

The docs look a bit overwhelming on the subject.

/iaw

---

<div class="post-metadata">

**Author:** ![NaOH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naoh/32/5632_2.png) [@NaOH](https://discourse.julialang.org/u/NaOH)\
**Post date:** [April 24, 2018, 11:29pm UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/2 "2018-04-24T23:29:19Z")

</div>

From:

- [https://docs.julialang.org/en/stable/manual/getting-started](https://docs.julialang.org/en/stable/manual/getting-started)

> Julia can be started in parallel mode with either the `-p` or the `--machinefile` options. `-p n` will launch an additional n worker processes, while `--machinefile` file will launch a worker for each line in file file. The machines defined in file must be accessible via a passwordless ssh login, with Julia installed at the same location as the current host. Each machine definition takes the form `[count*][user@]host[:port]` `[bind_addr[:port]]`. user defaults to current user, port to the standard ssh port. count is the number of workers to spawn on the node, and defaults to 1. The optional `bind-to bind_addr[:port]` specifies the ip-address and port that other workers should use to connect to this worker.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 25, 2018, 12:58am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/3 "2018-04-25T00:58:29Z")

</div>

thanks salchipapa. it doesn’t like me. the installation is exactly at the same spot in both machines.

```julia
$ julia --machinefile machinefile
ssh: Could not resolve hostname 5: nodename nor servname provided, or not known
ERROR: Unable to read host:port string from worker. Launch command exited with error?
read_worker_host_port(::Pipe) at ./distributed/cluster.jl:236
connect(::Base.Distributed.SSHManager, ::Int64, ::WorkerConfig) at ./distributed/managers.jl:391
create_worker(::Base.Distributed.SSHManager, ::WorkerConfig) at ./distributed/cluster.jl:443
setup_launched_worker(::Base.Distributed.SSHManager, ::WorkerConfig, ::Array{Int64,1}) at ./distributed/cluster.jl:389
(::Base.Distributed.##33#36{Base.Distributed.SSHManager,WorkerConfig,Array{Int64,1}})() at ./task.jl:335
Stacktrace:

```

reading the docs, it seems like all I need to do is to put into the machinefile

```julia
5 164.67.165.22

```

and I should be ready to go. (IP was made up.) is this a correct format (5 processes to be started up on 164.67.165.22.)

password-less and username-less ssh works just fine:

```julia
> ssh 164.67.165.22 '/Applications/Julia-0.6.app/Contents/Resources/julia/bin/julia -e "println(\"hello\")"'
hello

back to home

```

does it need another open port? anything else? what is the simplest way to check what this means?

regards,

/iaw

---

<div class="post-metadata">

**Author:** ![Michael\_Eastwood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_eastwood/32/669_2.png) [@Michael\_Eastwood](https://discourse.julialang.org/u/Michael_Eastwood)\
**Post date:** [April 25, 2018, 1:05am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/4 "2018-04-25T01:05:05Z")

</div>

Try something like this for now:

```julia
julia> addprocs([("machine1", 2), ("machine2", 1)])

```

This will launch 2 workers on `machine1` and 1 worker on `machine2`.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 25, 2018, 1:29am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/5 "2018-04-25T01:29:51Z")

</div>

> [@iwelch](#):
>
> readstring(`hostname`)

great. this works. it is incompatible with the `-p` julia switch, but works fine without it. I can add not only localhost, but do plain `addprocs()`, too. so I am pretty much all set. thank you.

PS: If someone has a working plain machinefile, I am curious what it should have looked like.

---

<div class="post-metadata">

**Author:** ![NaOH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naoh/32/5632_2.png) [@NaOH](https://discourse.julialang.org/u/NaOH)\
**Post date:** [April 25, 2018, 4:31am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/6 "2018-04-25T04:31:20Z")

</div>

I remember now (haven’t used it in a while), it seems that either the documentation is wrong, or that option is not working as intended, try:

`machinefile`:

```julia
164.67.165.22
164.67.165.22
164.67.165.22
164.67.165.22
164.67.165.22

```

instead of:

`5 164.67.165.22`

Then:

`julia -p 5 --machinefile machinefile`

That worked for me last time! This should give you 10 workers 5 local and 5 remote.

---

<div class="post-metadata">

**Author:** ![iwelch](https://avatars.discourse-cdn.com/v4/letter/i/8c91f0/32.png) [@iwelch](https://discourse.julialang.org/u/iwelch)\
**Post date:** [April 28, 2018, 4:02am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/7 "2018-04-28T04:02:14Z")

</div>

the machinefile version does not work on my end, at all.

```julia
bash$ \julia -p 3 --machinefile machinefile
ERROR: connect: connection refused (ECONNREFUSED)ERROR: ERROR:
Stacktrace:connect: connection refused (ECONNREFUSED)connect: connection refused (ECONNREFUSED)

Stacktrace:
Stacktrace: [1] try_yieldto
( [1] try_yieldto
( [1] try_yieldto::(Base.##296#297{Task}, ::Base.##296#297{Task}, ::Base.##296#297{Task}, ::Task):: at Task./event.jl:189)
 at [2] ./event.jl:189wait
( [2] )wait at ::(./event.jl:234Task)) at

```

and tons more output. the `addprocs` works fine.

regards,

/iaw

---

<div class="post-metadata">

**Author:** ![mgiugliano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgiugliano/32/5818_2.png) [@mgiugliano](https://discourse.julialang.org/u/mgiugliano)\
**Post date:** [July 26, 2019, 4:55pm UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/8 "2019-07-26T16:55:48Z")

</div>

Did I understand correctly that the file system on each remote machine must

- have the exact same path to call julia’s executable
- have the exact same folder(s) path as the current path on the “calling” machine  
?

This makes it impossible to distribute jobs between, say, a linux box a Mac and a Windows PC. Could this be intended? Am I wrong?

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [July 26, 2019, 5:07pm UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/9 "2019-07-26T17:07:07Z")

</div>

> [@mgiugliano](#):
>
> Did I understand correctly that the file system on each remote machine must
> 
> - have the exact same path to call julia’s executable
> - have the exact same folder(s) path as the current path on the “calling” machine  
> ?

No. You can use the keyword arguments `exename` to specify the julia binary location (and the environment to load) and `dir` to specify the working directory. I oft start workers on a small linux cluster from a windows machine.

```julia
params = (exename = `/path/to/julia/bin/julia --project=/path/to/project`, dir = "/path/to/working/directory")
addprocs([("some_remote_machine", 5)]; params...)

```

This will start 5 processes on `some_remote_machine`.

For more information see, for example, my parallel computing tutorial [here](https://github.com/crstnbr/JuliaWorkshop19/blob/master/3_Three/1_parallel_computing.ipynb), in particular the “THP cluster” part.

---

<div class="post-metadata">

**Author:** ![mgiugliano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgiugliano/32/5818_2.png) [@mgiugliano](https://discourse.julialang.org/u/mgiugliano)\
**Post date:** [July 26, 2019, 8:06pm UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/10 "2019-07-26T20:06:44Z")

</div>

Thank you so much, particularly for the tutorial!

---

<div class="post-metadata">

**Author:** ![darrencl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/darrencl/32/8552_2.png) [@darrencl](https://discourse.julialang.org/u/darrencl)\
**Post date:** [March 18, 2020, 12:29am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/11 "2020-03-18T00:29:20Z")

</div>

Is it possible to let Julia work out automatically the available process on a pool of machines instead of explicitly stating n processes in MachineA? It’s like we specify we want 64 process and tell Julia that we have Machine[A-Z], then it’s up to Julia which CPU to use.

Also, is there any performance difference if I use `SSHManager`, i.e. by explicitly stating the node as in your tutorial, vs using `ClusterManagers` (my cluster is `PBSManager`)? The reason being is I can’t get `PBSManager` working, since there is no clear example on what’s needed (I opened an issue [here](https://github.com/JuliaParallel/ClusterManagers.jl/issues/132))

---

<div class="post-metadata">

**Author:** ![moesphere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/moesphere/32/3348_2.png) [@moesphere](https://discourse.julialang.org/u/moesphere)\
**Post date:** [April 3, 2020, 11:07am UTC](https://discourse.julialang.org/t/multiple-computer-example/10518/12 "2020-04-03T11:07:23Z")

</div>

I am trying to connect from my Windows computer to several Linux computers via ssh.

It does not work if I use the REPL from the julia directory. However, it does work if I first start julia from the git bash on Windows and then add the workers. Does anyone experience the same behaviour and is there a reason for this or can it be fixed? I would like to use the REPL in atom (from where it also does not work).

The code I am using is

```julia
using Distributed
 addprocs([("john.doe@linuxcomputer", 3)]; dir="/home/john.doe/julia-project", exename="/home/john.doe/software/julia/julia-1.3.1/bin/julia", tunnel=true)

```

Note: I have activated passwordless ssh login beforehand.
