code: def parallel_map(
      process: Callable[[InT], OutT],
      items: List[InT],
      parallelism: int,
      multiprocessing: bool = False,
  ) -> List[OutT]:
      """
      A wrapper for applying `process` to all `items`.
      """
      units = "processes" if multiprocessing else "threads"
      with htrack_block(
          f"Parallelizing computation on {len(items)} items over {parallelism} {units}"
      ):
          results: List
          if parallelism == 1:
              results = list(
                  tqdm(
                      map(process, items),
                      total=len(items),
                      disable=None,
                  )
              )
          elif multiprocessing:
              with ProcessPoolExecutor(
                  max_workers=parallelism
              ) as executor:
                  results = list(
                      tqdm(
                          executor.map(process, items),
                          total=len(items),
                          disable=None,
                      )
                  )
          else:
              with ThreadPoolExecutor(
                  max_workers=parallelism
              ) as executor:
                  results = list(
                      tqdm(
                          executor.map(process, items),
                          total=len(items),
                          disable=None,
                      )
                  )
      return results
  
imports: import json
  import os
  import shlex
  import subprocess
  import uuid
  import zstandard
  from typing import Any, Callable, Dict, List, Optional, TypeVar
  from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor
  from tqdm import tqdm
  import pyhocon
  from dataclasses import asdict, is_dataclass
  from helm.common.hierarchical_logger import hlog, htrack, htrack_block
label_desc: Use image node_id 18 for calling a global function with example usage: parallel_map(process, items, parallelism, multiprocessing) and returns: results