recv

paddle.distributed. recv ( tensor, src=0, group=None, sync_op=True ) [source]

Receive a tensor to the sender.

Parameters
  • tensor (Tensor) – The tensor to receive. Its data type should be float16, float32, float64, int32, int64, int8, uint8, bool or bfloat16.

  • src (int) – The source rank id.

  • group (Group, optional) – The group instance return by new_group or None for global default group. Default: None.

  • sync_op (bool, optional) – Whether this op is a sync op. The default value is True.

Returns

Return a task object.

Examples

>>> 
>>> import paddle
>>> import paddle.distributed as dist

>>> dist.init_parallel_env()
>>> if dist.get_rank() == 0:
...     data = paddle.to_tensor([7, 8, 9])
...     dist.send(data, dst=1)
>>> else:
...     data = paddle.to_tensor([1, 2, 3])
...     dist.recv(data, src=0)
>>> print(data)
>>> # [7, 8, 9] (2 GPUs)