mindspore.communication.get_process_group_ranks

View Source On Gitee
mindspore.communication.get_process_group_ranks(group=GlobalComm.WORLD_COMM_GROUP)[source]

Gets the ranks of the specific group and returns the process ranks in the communication group as a list.

Parameters

group (str, optional) – The communication group to work on. Default: GlobalComm.WORLD_COMM_GROUP , which means "hccl_world_group" in Ascend, and "nccl_world_group" in GPU.

Returns

List (List[int]), List of process ranks in the specified communication group.

Raises
  • TypeError – If the group is not a str.

  • RuntimeError – If device target is invalid, or backend is invalid, or distributed initialization fails.

Supported Platforms:

Ascend GPU

Examples

Note

Before running the following examples, you need to configure the communication environment variables.

For Ascend/GPU/CPU devices, it is recommended to use the msrun startup method without any third-party or configuration file dependencies.

Please see the msrun start up for more details.

This example should be run with 4 devices.

>>> import numpy as np
>>> from mindspore.communication import init, get_process_group_ranks
>>>
>>> init()
>>> output = get_process_group_ranks()
>>> print(output)
[0, 1, 2, 3]