I'm interested in running some reasonably heavyweight processing on my desktop/laptop (not so bad that it requires a cluster, but needs a good home machine). My question is how many threads to create in order to get the job done most quickly (assume that the application distributes the workload with very few overheads).

I would usually create one thread per processor, but I was wondering if the hyperthreading capability on the Core i5/i7 means that I should actually be creating two threads per processor (i.e. one thread per virtual processor). Anyone know?

*Obviously, a reasonable answer would be try it and see. As it takes about 12 hours to run, I'd prefer to get it right the first time, but I'll happily post results if I get a chance to run it both ways.

closed as off topic by soandos, Diogo, BBlake, ChrisF, Dave Oct 31 '12 at 14:29

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1 per virtual processor is generally better – soandos Oct 31 '12 at 1:25
  • Well I'm quite new to this forum, but why is asking a question about threading/performance "off-topic" here? Can you suggest a better venue? – Alex Oct 31 '12 at 23:39
  • 1
    Its not the threading is off topic. The problem is that it is open ended, and not nearly enough information is provided. As per the FAQ such questions are either not on topic, not constructive, or not a real question. – soandos Nov 1 '12 at 1:13
  • The fact that there is no simple answer was not obvious when I asked the question... Perhaps a request for more detail would've sufficed. – Alex Nov 1 '12 at 5:16

This is an open ended question that requires expensive benchmarking. I have personally seen it go both ways. Unless you really messed up your mulitthreading, the difference will be about +-10% so it is worth trying it both ways. Even if takes a long time.

Many High Performance Computing clusters build from Intel components have HT disabled. This is for good reason as those codes tend to saturate the hardware and hence their performance is very tied to the saturation of the memory access - which will be worse in the HT case as threads are compting and switching on and off. See http://semiaccurate.com/2012/04/25/does-disabling-hyper-threading-increase-performance/ .

But if your code is not highly tuned you may not experience nearly same performance increase see http://semiaccurate.com/2012/04/25/does-disabling-hyper-threading-increase-performance/.

enter image description here

It appears that for single CPU computing disabling hyperthreading can increase some software by 1% but also hurt other software by signficantly more. Perhaps by ~10%.

This means that unless your benchmarks say otherwise you should create 1 thread per hyperthreaded/real core on your desktop machine.

  • That's very interesting - my code is not dealing with the machine at a low level, just using threads (in JVM actually - does it make a difference?) – Alex Oct 31 '12 at 8:38
  • @Alex, if you are using java there is almost no way you are getting peak performance. This is more of a SA comment but take a look at vanillajava.blogspot.com/2012/01/… for allocating threads. – Mikhail Oct 31 '12 at 8:57

I am talking completely from experiences with F@H folding here in saying that a single thread per core (be it virtual or physical) is best.

In saying that, it might be a good idea to leave a single core free to deal with background processes, and general computer tasks, as even a little bit of usage can throw a task to its knees.

Look into CPU affinity if you would like to keep track of where things are running. As a general rule, assign to physical cores first (i.e: even numberings), then the hyperthread cores.

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