Select cpus from os.sched_getaffinity()
Created by: waltersom
On a multi-user cluster with cgroups enforcing CPU affinity, the taskset lines fail, as cores not assigned to the job may be selected.
This gets the set of cores assigned, and only assigns cores in that set.
In addition as not all cores are guaranteed to be available (especially on a shared-use cluster), this counts the number of available cores, and passes that as --cpu
as appropriate.
In my testing, this continues to work on a single-user system (without any cgroups constraining things).