I'm getting mixed signals whether it makes sense to have multiple threads performing the same CPU bound routine (each thread plowing through different data, of course).
If you are CPU bound, you are already taxing the processor, right? Why would it make sense to add additional CPU work then? Is the idea that you should try to match the number of CPU-bound threads to cores?
What about the case of a single core machine. Does multi-threading a CPU bound operation ever make sense?
Thanks in advance.
If you are CPU bound, you are already taxing the processor, right? Why would it make sense to add additional CPU work then? Is the idea that you should try to match the number of CPU-bound threads to cores?
Yes, this is basically the idea. If you're algorithm is CPU bound, it will tie up one processing core. If there are 4 in your system, using all 4 can give you a significant boost in overall throughput. Without multiple threads, you'll only ever use a single core to process your data.
What about the case of a single core machine. Does multi-threading a CPU bound operation ever make sense?
It can, but typically only if it's not purely CPU bound. If your routine is completely CPU bound, you typically want no more than 1 thread per core. If, however, certain portions of your algorithm have other characteristics, and are bound by other things, that portion can sometimes benefit from having the overall routine threaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With