What's the difference between blocking and non-blocking send/recv in torch.distributed?

Viewed 16

In this post, the author introduces two methods to send/recv tensors: blocking and non-blocking. In the example,

"""Non-blocking point-to-point communication."""
    
def run(rank, size):
    tensor = torch.zeros(1)
    req = None
    if rank == 0:
        tensor += 1
        # Send the tensor to process 1
        req = dist.isend(tensor=tensor, dst=1)
        print('Rank 0 started sending')
    else:
        # Receive tensor from process 0
        req = dist.irecv(tensor=tensor, src=0)
        print('Rank 1 started receiving')
    req.wait()
    print('Rank ', rank, ' has data ', tensor[0])

But what is the difference? The above code make the non-blocking to be blocking by using the req.wait().

0 Answers
Related