mindspore.mint.distributed.get_global_rank

View Source On Gitee
mindspore.mint.distributed.get_global_rank(group, group_rank)[source]

A function that returns the rank id in the world group corresponding to the rank which id is 'group_rank' in the user group.

Note

This method should be used after init_process_group().

Parameters
  • group (str) – The communication group to work on. Normally, the group should be created by mindspore.mint.distributed.new_group. If None, which means "hccl_world_group" in Ascend.

  • group_rank (int) – Group rank to query.

Returns

An integer scalar with the rank id in the world group.

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

  • TypeError – If the group_rank is not an integer.

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

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 start up for more details.

This example should be run with 8 devices.

>>> from mindspore import set_context
>>> from mindspore.mint.distributed import init_process_group, get_global_rank, new_group, get_rank
>>> set_context(device_target="Ascend")
>>> # Launch 8 processes.
>>> init_process_group()
>>> rank_ids = [0,4]
>>> if get_rank() in rank_ids:
...     group = new_group(rank_ids)
...     world_rank_id = get_global_rank(group, 1)
...     print("world_rank_id is: ", world_rank_id)
#rank 0 and 4:
world_rank_id is: 4