mindspore.communication.get_world_rank_from_group_rank

View Source On Gitee
mindspore.communication.get_world_rank_from_group_rank(group, group_rank_id)[source]

Get the rank ID in the world communication group corresponding to the rank ID in the specified user communication group.

Note

This method isn't supported in GPU and CPU versions of MindSpore. The parameter group should not be "hccl_world_group". This method should be used after init().

Parameters
  • group (str) – The communication group to work on. The group is created by create_group.

  • group_rank_id (int) – A rank ID in the communication group.

Returns

int, the rank ID in world communication group.

Raises
  • TypeError – If group_rank_id is not an integer or the group is not a string.

  • ValueError – If group is 'hccl_world_group' or backend is invalid.

  • RuntimeError – If HCCL is not available or MindSpore is GPU/CPU version.

Supported Platforms:

Ascend GPU CPU

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.

>>> import mindspore as ms
>>> from mindspore import set_context
>>> from mindspore.communication import init, create_group, get_world_rank_from_group_rank, get_rank
>>> set_context(mode=ms.GRAPH_MODE)
>>> ms.set_device(device_target="Ascend")
>>> init()
>>> group = "0-4"
>>> rank_ids = [0,4]
>>> if get_rank() in rank_ids:
...     create_group(group, rank_ids)
...     world_rank_id = get_world_rank_from_group_rank(group, 1)
...     print("world_rank_id is: ", world_rank_id)
world_rank_id is: 4