How make a true distributed program

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

using Distributed

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

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

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.
  • Second: Add the machines individually:
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:
(...)
@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.

3 Likes

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:

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:

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).

1 Like

Yes, I entered the password.

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?