C# – Will Multi threading increase the speed of the calculation on Single Processor

cmultithreadingperformance

On a single processor, Will multi-threading increse the speed of the calculation. As we all know that, multi-threading is used for Increasing the User responsiveness and achieved by sepating UI thread and calculation thread. But lets talk about only console application. Will multi-threading increases the speed of the calculation. Do we get culculation result faster when we calculate through multi-threading.

what about on multi cores, will multi threading increse the speed or not.

Please help me. If you have any material to learn more about threading. please post.

Edit:
I have been asked a question, At any given time, only one thread is allowed to run on a single core. If so, why people use multithreading in a console application.

Thanks in advance,
Harsha

Best Answer

In general terms, no it won't speed up anything.

Presumably the same work overall is being done, but now there is the overhead of additional threads and context switches.

On a single processor with HyperThreading (two virtual processors) then the answer becomes "maybe".

Finally, even though there is only one CPU perhaps some of the threads can be pushed to the GPU or other hardware? This is kinda getting away from the "single processor" scenario but could technically be way of achieving a speed increase from multithreading on a single core PC.

Edit: your question now mentions multithreaded apps on a multicore machine. Again, in very general terms, this will provide an overall speed increase to your calculation. However, the increase (or lack thereof) will depend on how parallelizable the algorithm is, the contention for memory and cache, and the skill of the programmer when it comes to writing parallel code without locking or starvation issues.