c++ - What's the best way to demonstrate the effect of affinity setting? -


Once I saw that Windows does not have compute-intensive threads on a specific core - it keeps core switching instead. So I think the work will be done faster, if the thread will have access to the same data cache. And in fact, I was able to improve the speed of a constant ~ 1% after setting the mask of the thread to the mask in the same core (a PPMD ​​(D) compression thread. But then I used a simple demo for this effect Trying to make, more or less unsuccessful - that is, it works as expected on my system (Q9450):

But the people I asked were not able to reproduce the effect. Any suggestions?

  #include  2)]) + ((int and a) & Amp; (Bumkak & gt; & Gt; 4)]); } R = S; T = Gaiticcon (T) - T; Return T. 0; } DWORD WINAPI Loadcore (LPVOID) {SetthreadAfminMask (GetCryrentTrad), 2); While (1) benchmark (B); } Int main (int argc, char ** argv) {if ((argc> 1) & amp; amp; (atoi (argv [1]) 16)) buflog = atoi (argv [1]); Bufsize = 1 & lt; & Lt; Buflog; Bufmask = bufsize-1; A = new four [bufsize + 4]; B = new four [bufsize + 4]; Printf ("buflog =% i bufsize =% i \ n", bufflog, buffs); CreateThread (0, 0, and Loadcore, 0, 0, 0); Printf ("(Cash Flush) First Run =% .3fs \ n", Float (Benchmark (A)) / 1000); Float T1 = benchmark (A); T1 / = 1000; Printf ("time =% .3fs \ n", t1 with default connection); SetThreadAffinityMask (GetCurrentThread (), 1); Float T2 = Benchmark (A); T2 / = 1000; Printf ("Only time with first core =% .3fs \ n", T2); Printf ("Speed ​​gain% 4.2 F %% \ n", (T1-T2) * 100 / T1); Return 0; }  

P.S. If someone needs it, then I can post a link to the compiled version.

default affinity:

affinity core set to # 4

< P> Now, this is an archive Do you really think that the worker thread running around the CPU is fine?


Comments