mindspore.ops.communication.get_world_size

View Source On AtomGit
mindspore.ops.communication.get_world_size(group=None)[source]

Get the rank size of the specified collective communication group.

Note

This method should be used after mindspore.ops.communication.init_process_group().

Parameters:

group (str, optional) – The communication group to work on. Normally, the group should be created by mindspore.ops.communication.new_group(). Default: None, which means "hccl_world_group" in Ascend.

Returns:

int, the rank size of the group. Returns -1, if the group is not available.

Raises:

TypeError – If group is not a string.

Supported Platforms:

Ascend

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 8 devices.

>>> import mindspore as ms
>>> from mindspore.ops.communication import init_process_group, get_world_size
>>> ms.set_device(device_target="Ascend")
>>> init_process_group()
>>> group_size = get_world_size()
>>> print("group_size is: ", group_size)
group_size is: 8