Does the number of threads increase the CPU execution time?

427 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

Creating threads is really computationally expensive. The OS does a lot of work that you’re not seeing directly. This is why most multi threaded applications use something called a thread pool where worker threads are already created and just waiting to be assigned work.

In your case you should create a thread pool on program startup and then feed it the matrix calculations as jobs to do. And it’s not going to be particularly useful unless you plan on doing a lot of calculations.

Other thing to keep in mind is that your dual core and hyperthreaded CPU has quirks that impact performance. Dual core means it has 2 hardware threads, which means the CPU can actually do 2 things concurrently. But hyperthreaded semi-doubles it and lets you do 4 things at once. It semi-doubles it because hyperthreaded cores act like 2 cores but the 2 cores share some parts. One of those parts is the ALU which does the actual computation. In your case you’re doing arithmetic with RAM so it’s very likely that hyperthreading actually slows you down.

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