mindspore.ops.communication.barrier
- mindspore.ops.communication.barrier(group=None, async_op=False, device_ids=None)[source]
Synchronizes all processes in the specified group. Once the process call this operation, it will be blocked until all processes call this operation. After all processes finish calling the operations, the blocked processes will be woken and continue their task.
- Parameters
group (str, optional) – The communication group to work on. Default:
None, which means"hccl_world_group"in Ascend.async_op (bool, optional) – Whether this operator should be an async operator. Default:
False.device_ids (list[int], optional) – Currently It is a reserved Parameter. Default is
None.
- Returns
CommHandle. If async_op is set to
True, CommHandle is an async work handle. If async_op is set toFalse, CommHandle will beNone.- Raises
TypeError – group is not a str or async_op is not a bool.
RuntimeError – If backend is invalid, or distributed initialization fails.
- Supported Platforms:
AscendCPU
Examples
Note
Before running the following examples, you need to configure the communication environment variables.
For Ascend devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies. Please see the msrun startup for more details.
This example should be run with 2 devices.
>>> from mindspore.ops.communication import init_process_group >>> from mindspore.communication.comm_func import barrier >>> # Launch 2 processes. >>> init_process_group() >>> barrier() >>> print("barrier finish!") barrier finish!