4
$\begingroup$

What are the reasons for decreasing the number of threads in a parallel implementation ?

Assume that we have two implementations, the first one with 4 threads, and a second one with 8 threads, and both have exactly the same run time. What are the various reasons to prefer the first one?

I stress on the fact that the two implementations have the same run times.

The obvious reasons are the following:

  • If we have 8 processors, we can execute at the same time this implementation on two different sets of inputs thus performing twice the work,

  • Less resources consumption by the OS which handles less number of threads.

I'm looking for other reasons...

$\endgroup$
3
  • 1
    $\begingroup$ Are there any differences between the two implementiations beside the number of threads? I don't see why you would want to change something that works. $\endgroup$
    – adrianN
    Commented Oct 18, 2013 at 7:13
  • $\begingroup$ When a given number of threads is has a worse performance than a smaller number of threads, you prefer the latter of course. $\endgroup$
    – user10830
    Commented Oct 18, 2013 at 11:49
  • $\begingroup$ Under what conditions are the execution times equal? Are both run on single core/single thread processors (fast sync, no hardware parallelism)? Are both run on 8 core processors with 4 cores idle for the 4-thread version (and are the 4 active cores using turboboost to exploit thermal headroom)? Is a 4 core/8 thread processor used? Is the program responsive (e.g., webserver) and timed under peak load? Etc. $\endgroup$
    – user4577
    Commented Oct 18, 2013 at 18:50

3 Answers 3

3
$\begingroup$

Some other benefits from a security point of view for running the 4 threads implementation would be :

  • Obfuscation of the actual processors being used by the algorithm, in case an attacker is looking to interfere with the execution.

  • If you have 8 processors you can run simultaneously the same algorithm twice using the same input to check the integrity of your results.

$\endgroup$
2
$\begingroup$

Obviously, an algorithm that takes 4 threads one minute each is better than an algorithm that takes 8 threads one minute each. The solution that only needs 4 threads/processors uses half as much energy as the one that needs 8 threads/processors. Also, if you have 8 processors, the former leaves 4 processors idle and free to work on other tasks. Finally, if you have fewer than 8 processors, the latter will probably see contention and will in practice run longer.

Is this a real problem? The answer seems so clearcut; there's no reason to prefer the solution that does twice as much work in total.

$\endgroup$
1
$\begingroup$
  • If you have less processors than the number of threads, this will cause contention of the thread scheduling over the CPUs (the OS will have to context switch between threads, because there are more threads than CPUs).
  • If the threads access a single resource, more threads will cause more contention (threads will have to wait for eachother); thus sometimes increasing the number of threads will not benefit a program; it can even harm the performance, as now there is a lot more OS/CPU handling/management of the critical sections.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.