mindspore.dataset.Dataset.recv
- Dataset.recv(src=0, group=None)[source]
The dataset communication interface receives data sent by the source Dataset using
mindspore.dataset.Dataset.send.Each call to the recv operation only receives data once.
Note
This is an experimental API that is subject to change or deletion.
- Parameters
src (Union[int, list[int]], optional) – List of the src rank id(s) to receive. If the Rank ID of the current process is specified, data will be obtained directly from itself. Default:
0, which indicates receive data from src rank 0.group (str, optional) – The communication group to work on. The group is created by
mindspore.communication.create_group(). Default:None, which indicatesGlobalComm.WORLD_COMM_GROUP.
- Returns
Union[Tensor, list[Tensor]], List of the Tensor(s) received.
Examples
>>> from mindspore.mint.distributed import init_process_group >>> from mindspore.mint.distributed import get_rank >>> import mindspore.dataset as ds >>> >>> # Launch 8 processes by msrun --worker_num=8 --local_worker_num=8 script.py >>> init_process_group() >>> this_rank = get_rank() >>> >>> # Create a dataset with 3 columns >>> input_columns = ["column1", "column2", "column3"] >>> dataset = ds.GeneratorDataset([(1, 2, 3), (3, 4, 5), (5, 6, 7)], column_names=input_columns) >>> >>> # Send data from rank: 0 to rank: [1, 2, 3, 4, 5, 6, 7] >>> if this_rank == 0: >>> dataset.send(dst=[1, 2, 3, 4, 5, 6, 7]) >>> if this_rank in [1, 2, 3, 4, 5, 6, 7]: >>> data1 = dataset.recv() >>> >>> # Receive a data from the current dataset >>> data2 = dataset.recv(src=get_rank()) >>> >>> # Send data from rank: [1, 2, 3, 4, 5, 6, 7] to rank: 0 >>> if this_rank in [1, 2, 3, 4, 5, 6, 7]: >>> dataset.send() >>> if this_rank == 0: >>> data3 = dataset.recv(src=[1, 2, 3, 4, 5, 6, 7])