code: def one_rank_first(rank: int = 0, local: bool = False) -> Any:
      """Context manager that ensures a specific rank runs first before others in a distributed
      environment.
  
      Args:
          rank: rank of the process that should execute the code
              block inside the context manager first. Default, 0.
          local: flag to specify local rank or global rank.
              If True ``rank`` argument will define a local rank to run first.
              Default, False
  
      Examples:
          .. code-block:: python
  
              def download_dataset():
                  ...
  
              with idist.one_rank_first():
                  ds = download_dataset()
  
              dp = ds[0]
  
      .. versionadded:: 0.4.13
      """
  
      current_rank = get_local_rank() if local else get_rank()
      size = get_nproc_per_node() if local else get_world_size()
  
      if rank >= size or rank < 0:
          raise ValueError(
              f"rank should be between 0 and {size - 1}, but given {rank}"
          )
  
      if current_rank != rank:
          barrier()
  
      yield
  
      if current_rank == rank:
          barrier()
  
imports: import socket
  from contextlib import contextmanager
  from functools import wraps
  from typing import Any, Callable, List, Mapping, Optional, Tuple, Union
  import torch
  from ignite.distributed.comp_models import _SerialModel, has_hvd_support, has_native_dist_support, has_xla_support, registered_computation_models
  from ignite.utils import setup_logger
label_desc: Use image node_id 26 for calling a global function with example usage: one_rank_first(rank, local) without return types