[DUG] Multi Threading and HyperThreaded CPUs

Peter Ingham ping_delphilist at 3days.co.nz
Tue Nov 13 17:15:52 NZDT 2007


A few days ago, a statement was made to the effect that using 
Hyperthreading gave no advantage to a Multi-threaded application.

This did not sound at all correct, so I carefully constructed a test 
program to investigate the actual behaviour in a variety of 
configurations.   The comments below are all based on tests performed 
with this application.

The program consists of a tight loop doing "Work" (no FP)  which can be 
run in a varying number of threads (The gross amount of work done is not 
affected by the number of threads).

Threads do update the GUI (via Synchronise calls) infrequently (rate is 
adjustable).

Due to the simplicity of the code  (No shared structures other than the 
GUI),  the "workers" do not need to resort to internal thread safety 
techniques (e.g.: Using TThreadList instead of TList).

Results:
  Single CPU, or HT OFF:    No significant difference in total time for 
1 vs 2 or more threads (as expected)

  P4 2.8 HT ON:	2 or more Threads runs at 200% the speed of 1.

  AMD X2 (dual core): 2 or more Threads runs at 185% the speed of 1.

So,  if you are running cpu-bound tasks on an HT system and do not see 
an improvement with 2 or more threads, then your Threading code is not 
optimal.


HOWEVER
Performance of a Single Threaded application with HT turned on is only 
55% of the performance when HT is turned off.

So using HT reduces the performance of a single threaded application 
(e.g. the Delphi IDE & Compiler), but provides 110% of the performance 
when multi-threading is used.

Given that most Systems in the future will feature multiple cores, then 
for Compute-bound applications, then it makes sense to incorporate 
Multi-threading techniques (if you implement them correctly).



Cheers


More information about the Delphi mailing list