HVM icon indicating copy to clipboard operation
HVM copied to clipboard

Option to limit the number of threads ?

Open khatharsis42 opened this issue 1 year ago • 5 comments

No matter how you run things, it will always run the maximum number of threads on your machine. This is not always the desired behaviour. It'd be nice if it could be changed, with perhaps an equivalent to OMP_NUM_THREADS for OpenMP ?

khatharsis42 avatar May 21 '24 11:05 khatharsis42

For now, we don't have the functionality of changing the number of max threads yet, however, you can change it in the code inside build.rs, changing let tpcl2 = (cores as f64).log2().floor() as u32; to let's say let tpcl2 = 3 for example, would run with 8 threads max (threads = 2^tpcl2)

kings177 avatar May 21 '24 13:05 kings177

Thank you !

khatharsis42 avatar May 21 '24 13:05 khatharsis42

BTW, it might be a good idea to make it so it doesn't use all the threads the system has, but rather all the cores. Especially since using too many threads seems to lead to some OOM errors ?

khatharsis42 avatar May 28 '24 13:05 khatharsis42

What's the reason the number of cores is always a power of two?

Janiczek avatar May 29 '24 10:05 Janiczek

@Janiczek a lot of developper have a superstitious belief the having stuff be base two makes the code go faster. In the case of threads, it doesn't make much sense, you should be more concerned about thread placement (ie not putting multiples threads running on the same core) and not overpopulating (ie using more threads than you have cores). This can be tricky, because most cores nowadays have hyperthreading enabled, meaning they can run multiple threads at once, albeit at decreased efficiency.

khatharsis42 avatar Jun 03 '24 07:06 khatharsis42