# How make a true distributed program

**URL:** <https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919>\
**Category:** Performance\
**Tags:** distributed\
**Created:** [January 2, 2022, 10:02am UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919 "2022-01-02T10:02:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![GalloLuigi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galloluigi/32/31349_2.png) [@GalloLuigi](https://discourse.julialang.org/u/GalloLuigi)\
**Post date:** [January 2, 2022, 10:02am UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919/1 "2022-01-02T10:02:49Z")

</div>

Hi on my local machine i have a program like this :

```julia
using Distributed

@distributed for(...)
  # some code
end

```

I want to “distribute” the for iterations to some remote virtual machines.  
How can I do it?

---

<div class="post-metadata">

**Author:** ![Noel\_Araujo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/noel_araujo/32/4862_2.png) [@Noel\_Araujo](https://discourse.julialang.org/u/Noel_Araujo)\
**Post date:** [January 3, 2022, 10:07am UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919/2 "2022-01-03T10:07:21Z")

</div>

You asked about virtual machines, which i don’t have experience. But at least I will provide my experience with my local network of desktops as a starting point.

- First: Configure your network, I followed this [link](https://easyoradba.com/2015/10/06/configure-passwordless-ssh-on-multiple-servers-and-execute-commands-on-multiple-servers-in-linux/).
- Second: Add the machines individually:

```julia
using Distributed
addprocs(2) # two process in local machine

ip_m2 = "m2@192.168.0.2"
nprocess_m2 = 3
machine2 = [(ip_m2,nprocess_m2)]
addprocs(machine2; topology=:master_worker, 
            exeflags=`--threads 4`, 
            enable_threaded_blas=true, 
            dir="/home/m2")

ip_m3 = "m3@192.168.0.3"
nprocess_m3 = 4
machine3 = [(ip_m3,nprocess_m3)]
addprocs(machine3; topology=:master_worker, 
            exeflags=`--threads 2`, 
            enable_threaded_blas=true, 
            dir="/home/m3")

```

- Third and last step: If previous steps worked, I just use all Distributed functions:

```julia
(...)
@everywhere using LinearAlgebra
@everywhere myfunc(x) = x+2

pmap(myfunc, 1:10) # instead of "for", i use pmap
(...)

```

I hope these code have some use for you.

---

<div class="post-metadata">

**Author:** ![GalloLuigi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galloluigi/32/31349_2.png) [@GalloLuigi](https://discourse.julialang.org/u/GalloLuigi)\
**Post date:** [January 3, 2022, 4:51pm UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919/3 "2022-01-03T16:51:52Z")

</div>

The virtual machines can already connect to each other via ssh.  
(my local machine can connect with remote machine via ssh)  
So can I skip step 1?

I have a difficult on remote worker creation (addprocs).  
I have try to run this code on my local machine:

```julia
using Distributed

#addprocs(2) # two process in local machine

ip_m2 ="luigal@193.205.161.5:5822"
nprocess_m2 = 3

machine2 = [(ip_m2,nprocess_m2)]
addprocs(machine2; topology=:master_worker, 
            exename="/usr/local/bin/julia",
            exeflags=`--threads 4`, 
            enable_threaded_blas=true, 
            dir="/home/luigal/")

ip_m3 = "luigal@193.205.161.5:5622"
nprocess_m3 = 4

machine3 = [(ip_m3,nprocess_m3)]
addprocs(machine3; topology=:master_worker, 
            exename="/usr/local/bin/julia",
            exeflags=`--threads 2`, 
            enable_threaded_blas=true, 
            dir="/home/luigal/")

```

i have this error:

 ![erroreeeee](https://global.discourse-cdn.com/julialang/original/3X/4/7/47fc4910cf39c5b75887d0e3dcaf8e91d75b5306.png)

---

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [January 3, 2022, 5:18pm UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919/4 "2022-01-03T17:18:43Z")

</div>

Did you enter the password when prompted? I would also recommend setting up SSH keys so you don’t have to deal with password prompts (although I don’t know how this works in Windows).

---

<div class="post-metadata">

**Author:** ![GalloLuigi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galloluigi/32/31349_2.png) [@GalloLuigi](https://discourse.julialang.org/u/GalloLuigi)\
**Post date:** [January 3, 2022, 5:32pm UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919/5 "2022-01-03T17:32:05Z")

</div>

Yes, I entered the password.

---

<div class="post-metadata">

**Author:** ![GalloLuigi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/galloluigi/32/31349_2.png) [@GalloLuigi](https://discourse.julialang.org/u/GalloLuigi)\
**Post date:** [January 5, 2022, 4:18pm UTC](https://discourse.julialang.org/t/how-make-a-true-distributed-program/73919/6 "2022-01-05T16:18:31Z")

</div>

Hi you have been very helpful. I am able to generate the processes on the machine but the execution of the program ends (not in the right way) without giving me any error messages.  
The processes on the machine result in sleeping and if I try to kill them my julia console warns me that they have been killed.  
How should I do to get the program running correctly?
