linuxmultithreadingprocessoperating-systemkernel

Time execution of multithreaded process runing on a multiprocessor system


I have this question concerning multithreaded processes running on multiprocessors.

My machine has eight logical processors (four physical cores and two threads per core).

I run a process each time with different number of threads (work of process is distributed on those threads created), and I displayed time for the process to complete execution along with time information displayed by "time command" in Linux.

Now the time of execution of the process was decreasing as I increase the number of threads, which is logical since the work is being divided on the threads and these threads benefit of parallelism. Based on what I understand when number of threads greater than the number of processors, i.e., the number of threads is 16 for example, the time it takes the process to execute should increase. But my results were:

For the number of threads = 8, the time for process execution was 592 ms:

Enter image description here

And for number of threads=16, the time of process execution was 594 ms:

Enter image description here

I only see an increase of 2 ms. Why didn't it highly increase since we literally have number of threads in the process double the number of processors?


Solution

  • You have a ditch to dig, but you only have 8 shovels. Does it matter much if there are 8 spare workers on coffee-break? Sure, a little time might be lost after the break when the shovels are handed over to the rested diggers but, overall, it's not going to make much difference to how long it takes to finish the ditch.