docstr: Basic unit test for broadcast using a process group of default world size.
docstr_tok: ["Basic","unit","test","for","broadcast","using","a","process","group","of","default","world","size","."]
code: def test_broadcast_result(self) -> None:
      """
      Basic unit test for broadcast using a process group of default world size.
      """
      store = c10d.FileStore(self.file_name, self.world_size)
      c10d.init_process_group(
          backend="gloo",
          store=store,
          rank=self.rank,
          world_size=self.world_size,
      )
      pg = c10d.new_group(pg_options=self.opts())
  
      func = mock.MagicMock()
      func.return_value = pg.rank()
  
      res = broadcast(data_or_fn=func, rank=0, pg=pg)
      assert res == 0, f"Expect res to be 0 (got {res})"
  
      if pg.rank() == 0:
          func.assert_called_once()
      else:
          func.assert_not_called()
  
      func.reset_mock()
  
      res = broadcast(data_or_fn=func, rank=1, pg=pg)
      assert res == 1, f"Expect res to be 1 (got {res})"
  
      if pg.rank() == 1:
          func.assert_called_once()
      else:
          func.assert_not_called()
  
file_path: pytorch/test/distributed/test_collective_utils.py
imports: from unittest import mock
  import torch.distributed
  from torch.distributed.collective_utils import all_gather, broadcast
  from torch.testing._internal.common_distributed import MultiProcessTestCase
label_desc: Use image node_id 4 for calling the TestCollectiveUtils obj's underlying member method code with example usage: obj.test_broadcast_result() without return types