Open EricDeveaud opened 1 year ago
os.sched_getaffinity
only available in python3
for python 2 a solution will be:
import re
try:
m = re.search(r'(?m)^Cpus_allowed:\s*(.*)$', open('/proc/self/status').read())
if m:
num_cpus = bin(int(m.group(1).replace(',', ''), 16)).count('1')
except IOError:
num_cpus = os.cpu_count()
regards
Erci
Hello,
centrifuge_evaluate.py
usesmultiprocessing.cpu_count()
to ge the number of cpus. butmultiprocessing.cpu_count()
return the number of cpu in the machine, But this is not the same as the number of cpu available to the process. For example, you can run in a taskset context or a batch scheduler like slurm.see:
I would suggest to use len(os.sched_getaffinity(0)) instead of multiprocessing.cpu_count()
NB Mac OSX python does not
have os.sched_getaffinity
so a portable way to code it would beregards
Eric regards
Eric