Sunday, 30 October 2011

sine calculation in parallel with threading


CPU:

intel core i5 dual core 2/4 1.6GHz with turbo boost

Platform:

MAC OS X Lion

Code executed (details omitted but posix threads used):

forint i =0; i<1000000000;i++) Count = sinf(Count*M_PI);

Results:
starting testing ...
starting thread 1 ...
result 0 test done in 21948373339 for thread 1
All done in 21948849377 exit now

21s voor 1 miljard sinussen. Hier gaat enkel de turbo boost meespelen die de frq naar 2.4Hz zal tunen.

starting testing ...
starting thread 1 ...
starting thread 2 ...
result 0 test done in 23809803704 for thread 1
result 0 test done in 23821499909 for thread 2
All done in 23821746782 exit now

23s voor 2 miljard sinussen met 2 threads
-> ca 2s/21s 10% overhead dus ca 5% per thread 1.85 keer sneller dan single core !

starting testing ...
starting thread 1 ...
starting thread 2 ...
starting thread 3 ...
starting thread 4 ...
result 0 test done in 27219048602 for thread 3
result 0 test done in 27288943782 for thread 2
result 0 test done in 27326104536 for thread 1
result 0 test done in 27363137220 for thread 4
All done in 27364857830 exit now

27s voor 4 miljard sinussen met 4 threads
-> Dus enkel 6s/21s of ca 28% overhead 7% per thread dus stijgt iets
-> Let wel op dus normaal op single core zou dit 85s zijn dus 3,1 keer sneller  !


starting testing ...
starting thread 1 ...
starting thread 2 ...
starting thread 3 ...
starting thread 4 ...
starting thread 5 ...
starting thread 6 ...
starting thread 7 ...
starting thread 8 ...
result 0 test done in 57289942166 for thread 7
result 0 test done in 57330855210 for thread 2
result 0 test done in 57382476204 for thread 3
result 0 test done in 57391857694 for thread 4
result 0 test done in 57424375220 for thread 1
result 0 test done in 57453518502 for thread 5
result 0 test done in 57456194280 for thread 6
result 0 test done in 57446887863 for thread 8
All done in 57462987830 exit now

57s dus voor 8 miljard sinussen met 8 threads , met single core 21 * 8 = 170s ! -> Hier verdubbelt de tijd uiteraard omdat ik maar 4 threads op core heb maar nog steeds 3 keer sneller als single core
Conclusion: 
Dus tussen de 2-4 threads is ideaal met deze i5 core. Je ziet dus ook dat wanneer men spreekt van multicores and threading dat dit met een korreltje zout moet worden genomen. Zo een i5 core is een stuk sneller als een gewone intel core duo op voorwaarde dat je optimaal gebruik kunt maken van een parallelle uitvoering. Jammer genoeg zijn niet alle problemen zo op te lossen en blijft de frequentie een domineerde rol spelen bij de meeste sequentiële uitvoeringen.