Here’s another simple codes:
import os
import torch
import torch.distributed as dist
from torch.multiprocessing import Process
import sys
rank= int(sys.argv[1])
def run(rank, size):
if(rank==0):
group = dist.new_group(range(size))
g_list=[]
alphak=torch.DoubleTensor([1.0])
for i in range(size):
g_list.append(alphak)
    dist.gather(gather_list=g_list,tensor=alphak,group=group)

    for i in range(size):
        print(g_list[i])
else:
    group = dist.new_group(range(size))

    alphak=torch.DoubleTensor([rank])
    print(alphak)
    dist.gather(alphak,dst=0,group=group)

""" Distributed function to be implemented later. """

def init_processes(rank, size, fn, backend=‘tcp’):
""" Initialize the distributed environment. “”"
os.environ[‘MASTER_ADDR’] = '127.0.0.1’
os.environ[‘MASTER_PORT’] = '29500’
dist.init_process_group(backend, rank=rank, world_size=size)
fn(rank, size)
if name == “main”:
size = 3
init_processes(rank, size, run, backend=‘tcp’)

master still receive 3 numbers which is the same as worker 2, which is 2.

could any one help me understand what’s wrong with this?
thanks