dara.hardware module

dara.hardware module#

Runtime CPU-core detection, used to size worker/thread counts portably.

detect_cpu_count()[source]#

Detect the number of CPU cores usable by this process.

Checked in priority order:
  1. SLURM_CPUS_PER_TASK, then SLURM_CPUS_ON_NODE (SLURM-managed jobs).

  2. os.sched_getaffinity(0) (Linux only; reflects taskset/affinity restrictions that os.cpu_count() ignores).

  3. os.cpu_count().

Return type:

int

Returns:

A positive integer. Falls back to 1 if nothing above yields a usable count.