Does the number of threads increase the CPU execution time?

428 views

I was doing an exercise in C of matrix multiplication using threads and I realized that as I increased the number of threads the same happened with the CPU time. My computer has 2 cores, each of which can run two threads (Intel Hyper-Threading), but why exactly does this happen?

In: Technology

5 Answers

Anonymous 0 Comments

There’s a lot of work being done behind the scenes to share time on your CPU. The OS and every background app running get time to run code on the CPU, even as your main app runs. If your CPU only has one thread, there has to be work done to check on each application to see if they have code to run.

With multiple threads, you can keep active code running, but if it ever performs a task that needs to wait for something outside of the CPU (like reading stuff off of a hard drive, or downloading a file over network), the second thread can pick up that idle time without a lot of work being done to park the one thread and pick up the new one.

When you start creating multiple threads in an application, you get to have more things being done while others are in those idle cycles. If you don’t have a lot of idle time in your application, then you won’t get much benefit of having more threads than CPU’s.

You are viewing 1 out of 5 answers, click here to view all answers.