OMP_NUM_THREADS should be set to #PhysicalCores / #Processes.
os.process_cpu_count, as @handaru mentioned and was added in Python 3.13, as well asnprocandhtop, gives the number of logical CPUs. Please usepsutil.cpu_count(logical=False)to get the number of physical CPUs.- Don’t forget to divide it by
nproc_per_nodeas @Kenzo mentioned, or you’ll have many processes competing for each core.