I’m using a project where each time you double the number of threads, you add between 40% to 60% overhead. As hyperthreading increases performance to a maximum of 30% this means, the program runs slower than in single thread mode on hyperthreaded systems.
The first steps seem to be simple.
Get the number of threads on the system through
len(os.sched_getaffinity(0))
Restrict the number of threads through z3 parameters.
Bind the threads to physical cores using
os.sched_setaffinity(0,mask)
.Leave smt solutions enabled for systems not containing Intel or amd inside
platform.machine()
.
However several problems arise for doing this.
How to know if the system has hyperthreading enabled?
Before using
os.sched_setaffinity(0,mask)
, how to know which cpu core numbers are physical or logical?
The problem is the program currently supports a wide number of platforms through python3: all Unixes, as well as Windows and Osx and Openvms while not forgetting PyPy.
Any patch to fix the problem shouldn’t spawn a new process nor add a non-included dependency nor drop support for some of the platforms above.
What can be a clean way to fix this?