code: def _test_distrib_one_rank_only_with_engine(device):
      def _test(barrier):
          engine = Engine(lambda e, b: b)
  
          batch_sum = torch.tensor(0).to(device)
  
          @engine.on(Events.ITERATION_COMPLETED)
          @idist.one_rank_only(with_barrier=barrier)  # ie rank == 0
          def _(_):
              batch_sum.data += torch.tensor(engine.state.batch).to(
                  device
              )
  
          engine.run([1, 2, 3], max_epochs=2)
  
          value_list = idist.all_gather(tensor=batch_sum)
  
          for r in range(idist.get_world_size()):
              if r == 0:
                  assert value_list[r].item() == 12
              else:
                  assert value_list[r].item() == 0
  
      _test(barrier=True)
      _test(barrier=False)
  
file_path: ignite/tests/ignite/distributed/utils/__init__.py
imports: import pytest
  import torch
  import torch.distributed
  import ignite.distributed
  from ignite.distributed.utils import sync
  from ignite.engine import Engine, Events
label_desc: Use image node_id 13 for calling a global function with example usage: _test_distrib_one_rank_only_with_engine(device) without return types