code: def schedule_workers(
      num_workers: int, cores_per_worker: Optional[int] = None
  ):
      l_core_to_p_core, l_core_to_socket = get_cpu_info()
      try:
          cpuset = get_cgroup_cpuset()
      except Exception as _e:  # failed to query cgroup info
          cpuset = list(l_core_to_p_core.keys())
      cpuset = sorted(cpuset)
  
      p2l = {}
      p_cores_set = set()
      for logical_core in cpuset:
          physical_core = l_core_to_p_core[logical_core]
          p_cores_set.add(physical_core)
          if physical_core not in p2l:
              p2l[physical_core] = logical_core
      p_cores = sorted(p_cores_set)
  
      # we check the OMP_NUM_THREADS setting as the only
      # indentifier for resource limitation
      try:
          cpu_resource_limit = int(os.environ["OMP_NUM_THREADS"])
      except Exception as _e:
          cpu_resource_limit = len(p_cores)
      if len(p_cores) > cpu_resource_limit:
          p_cores = p_cores[:cpu_resource_limit]
  
      if cores_per_worker is None:
          cores_per_worker = len(p_cores) // num_workers
          invalidInputError(
              cores_per_worker > 0,
              "The number of processes must be less "
              "or equal to the number of physical cores",
          )
      else:
          invalidInputError(
              cores_per_worker > 0,
              "`cores_per_worker` must be greater than 0",
          )
  
      msg = (
          "total number of cores requested must be smaller or"
          " equal than the physical cores available"
      )
      invalidInputError(
          cores_per_worker * num_workers <= len(p_cores), msg
      )
  
      schedule = []
      for i in range(num_workers):
          schedule.append(
              [
                  p2l[core]
                  for core in p_cores[
                      i * cores_per_worker : (i + 1) * cores_per_worker
                  ]
              ]
          )
  
      return schedule
  
file_path: BigDL/python/nano/src/bigdl/nano/utils/common/schedule.py
imports: import subprocess
  import re
  import os
  from typing import Optional
  import platform
  import cpuinfo
  from bigdl.nano.utils.common import invalidInputError
label_desc: Use image node_id 3 for calling a global function with example usage: schedule_workers(num_workers, cores_per_worker) and returns: schedule