class_docstr: parallel.Execution is a tool for writing easy threading-based parallel tests.
  
  Execution.run is the main helper function, but there are a few magic getters that return
  correct thread-specific values when called from within an Execution.run-wrapped function.
  
  Example usage:
  
      SIZE = 10
      with parallel.Execution(SIZE) as pex:
          @pex.run
          def all_ranks():
              return pex.rank
  
          assert all_ranks == list(range(SIZE))
class_docstr_tok: ["parallel.Execution","is","a","tool","for","writing","easy","threading-based","parallel","tests",".","Execution.run","is","the","main","helper","function",",","but","there","are","a","few","magic","getters","that","return","correct","thread-specific","values","when","called","from","within","an","Execution.run-wrapped","function",".","Example","usage",":","SIZE","=","10","with","parallel.Execution","(","SIZE",")","as","pex",":","@","pex.run","def","all_ranks","(",")",":","return","pex.rank","assert","all_ranks","==","list","(","range","(","SIZE",")",")"]
code: def __init__(
      self,
      size: int,
      local_size: int = 1,
      make_distributed_context: bool = True,
  ) -> None:
      assert (
          size % local_size == 0
      ), f"size%local_size must be 0 ({size}%{local_size})"
      self.size = size
      self.local_size = local_size
      self.cross_size = size // local_size
      # We keep some thread-specific info to implement the magic getters.
      self._info: Dict[int, Tuple[int, int, int]] = {}
  
      self._dist = None
      if make_distributed_context:
  
          def _make_distributed_context() -> core.DistributedContext:
              return core.DistributedContext(
                  rank=self.rank,
                  size=self.size,
                  local_rank=self.local_rank,
                  local_size=self.local_size,
                  cross_rank=self.cross_rank,
                  cross_size=self.cross_size,
                  chief_ip="localhost",
              )
  
          self._dist = self.run(_make_distributed_context)
  
file_path: determined/harness/tests/parallel.py
imports: import contextlib
  import itertools
  import sys
  import threading
  import traceback
  from typing import Any, Callable, Dict, Iterator, List, Tuple, TypeVar
  import pytest
  from determined import core
label_desc: Use image node_id 1 to create a new Execution object  with example: obj = Execution(size, local_size, make_distributed_context)