Distrubuted PyTorch code halts on multiple nodes when using MPI backend
I am trying to run Pytorch code on three nodes using openMPI but the code just halts without any errors or output. Eventually my purpose is to distribute a Pytorch graph on these nodes.

Three of my nodes are connected in same LAN and have SSH access to each other without password and have similar specifications:


Ubuntu 18.04
Cuda 10.0
OpenMPI built and installed from source
PyTorch built and installed from source


The code shown below works on single node - multiple processes, as:

&gt; mpirun -np 3 -H 192.168.100.101:3 python3 run.py


With following output:

INIT 0 of 3 Init env://
INIT 1 of 3 Init env://
INIT 2 of 3 Init env://
RUN 0 of 3 with tensor([0., 0., 0.])
RUN 1 of 3 with tensor([0., 0., 0.])
RUN 2 of 3 with tensor([0., 0., 0.])
Rank  1  has data  tensor(1.)
Rank  0  has data  tensor(1.)
Rank  2  has data  tensor(1.)


But when I placed the code on three nodes and run following command on each node separately, it does nothing:

&gt; mpirun -np 3 -H 192.168.100.101:1,192.168.100.102:1,192.168.100.103:1 python3 run.py


Please give some idea about any modifications in code or configurations for MPI to run given Pytorch code on multiple nodes?

#!/usr/bin/env python
import os
import torch
import torch.distributed as dist
from torch.multiprocessing import Process

def run(rank, size):
    tensor = torch.zeros(size)
    print(f"RUN {rank} of {size} with {tensor}")

    # incrementing the old tensor
    tensor += 1

    # sending tensor to next rank
    if rank == size-1:
       dist.send(tensor=tensor, dst=0)
    else:
       dist.send(tensor=tensor, dst=rank+1)

    # receiving tensor from previous rank
    if rank == 0:
        dist.recv(tensor=tensor, src=size-1)
    else:
        dist.recv(tensor=tensor, src=rank-1)

    print('Rank ', rank, ' has data ', tensor[0])


def init_processes(rank, size, fn, backend, init):
    print(f"INIT {rank} of {size} Init {init}")
    dist.init_process_group(backend, init, rank=rank, world_size=size)
    fn(rank, size)


if __name__ == "__main__":
    os.environ['MASTER_ADDR'] = '192.168.100.101'
    os.environ['BACKEND'] = 'mpi'
    os.environ['INIT_METHOD'] = 'env://'
    world_size = int(os.environ['OMPI_COMM_WORLD_SIZE'])
    world_rank = int(os.environ['OMPI_COMM_WORLD_RANK'])

    init_processes(world_rank, world_size, run, os.environ['BACKEND'], os.environ['INIT_METHOD'])


N.B. NCCL is not an option for me due to arm64-based hardware.

Apologies for replying late to this, but I could solve the issue by adding --mca btl_tcp_if_include eth1 flag to mpirun command. 

The reason for halt was that openMPI, by default, tries to locate and communicate with other nodes over local loopback network interface e.g. lo. We have to explicitly specify which interface(s) should be included (or excluded) to locate other other nodes.

I hope it would save someone's day :)
