Strange slow down and affinity !

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

MahmoudUthman
Posts: 234
Joined: Sat Jan 17, 2015 11:54 pm

Strange slow down and affinity !

Post by MahmoudUthman »

Sometimes I notice a strange slow down in the search to the point that iteration N-1 almost equals iteration N's time in normal state.
here's an example output :
Slowdown

Code: Select all

position startpos
go wtime 1000000
info depth 1 score cp 61 nodes 23 time 0 pv e2e3
info depth 2 score cp 0 nodes 94 time 1 pv e2e3 g8f6
info depth 3 score cp 56 nodes 541 time 4 pv e2e3 e7e6 b1c3
info depth 4 score cp 0 nodes 2174 time 7 pv b1c3 e7e6 e2e3
info depth 5 score cp 54 nodes 5198 time 13 pv b1c3 g8f6 g1f3 d7d6 d2d3
info depth 6 score cp 0 nodes 25157 time 41 pv b1c3 b8c6 d2d4 d7d5 g1f3 g8f6
info depth 7 score cp 54 nodes 48570 time 69 pv b1c3 g8f6 g1f3 b8c6 e2e3
info depth 8 score cp 5 nodes 92179 time 124 pv b1c3 g8f6 g1f3 b8c6 e2e4 e7e6 f1b5 f8b4
info depth 9 score cp 44 nodes 149637 time 179 pv b1c3 g8f6 g1f3 e7e6 e2e3 b8c6 f1d3 f8b4 e1g1
info depth 10 score cp 27 nodes 557333 time 529 pv e2e4 e7e6 g1f3 g8f6 e4e5 f6e4 d1e2 d7d5 b1c3 e4c5
info depth 11 score cp 60 nodes 802588 time 748 pv e2e4 e7e6 g1f3 f8e7 b1c3 g8f6 d2d4 d7d5 e4e5 f6e4 f1d3 e4c3 b2c3
info depth 12 score cp 40 nodes 1071053 time 990 pv e2e4 e7e6 d2d4 d7d5 e4e5 f8e7 g1f3 e8f8 f1d3 c7c5 e1g1 b8c6
info depth 13 score cp 46 nodes 1329554 time 1269 pv e2e4 e7e6 d2d4 d7d5 e4e5 c7c5 g1f3 c5d4 f3d4 c8d7 f1e2
info depth 14 score cp 51 nodes 2396760 time 2580 pv e2e4 e7e6 g1f3 f8e7 d2d4 d7d5 e4e5 c7c5 f1e2 b8c6 e1g1 e8f8 c2c3
info depth 15 score cp 44 nodes 3740992 time 4115 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 f3g5 d7d5 e4d5 c6a5 d2d3 h7h6 g5f3 f8d6 e1g1 a5c4 d3c4
info depth 16 score cp 30 nodes 4946096 time 5391 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 f3g5 d7d5 e4d5 c6a5 c4b5 c7c6 d5c6 b7c6 b5d3 f8d6 e1g1
info depth 17 score cp 28 nodes 6676881 time 7221 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 e1g1 a7a6 d2d3 d7d6 a2a3 e8g8 b2b4 c5d4 c1g5
info depth 18 score cp 29 nodes 8952016 time 9880 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 d2d3 c6a5 f3e5 a5c4 d3c4 e8g8 e5d3 c5d4 c3e2 d4b6
info depth 19 score cp 37 nodes 12429851 time 13969 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 d2d3 a7a6 c3d5 d7d6 c1g5 c8e6 e1g1 e8g8 d5f6 g7f6 g5h6 f8e8 c4e6 f7e6
bestmove e2e4
Normal

Code: Select all

position startpos
go wtime 1000000
info depth 1 score cp 61 nodes 23 time 0 pv e2e3
info depth 2 score cp 0 nodes 94 time 1 pv e2e3 g8f6
info depth 3 score cp 56 nodes 541 time 2 pv e2e3 e7e6 b1c3
info depth 4 score cp 0 nodes 2174 time 4 pv b1c3 e7e6 e2e3
info depth 5 score cp 54 nodes 5198 time 7 pv b1c3 g8f6 g1f3 d7d6 d2d3
info depth 6 score cp 0 nodes 25157 time 25 pv b1c3 b8c6 d2d4 d7d5 g1f3 g8f6
info depth 7 score cp 54 nodes 48570 time 44 pv b1c3 g8f6 g1f3 b8c6 e2e3
info depth 8 score cp 5 nodes 92179 time 78 pv b1c3 g8f6 g1f3 b8c6 e2e4 e7e6 f1b5 f8b4
info depth 9 score cp 44 nodes 149637 time 123 pv b1c3 g8f6 g1f3 e7e6 e2e3 b8c6 f1d3 f8b4 e1g1
info depth 10 score cp 27 nodes 557333 time 398 pv e2e4 e7e6 g1f3 g8f6 e4e5 f6e4 d1e2 d7d5 b1c3 e4c5
info depth 11 score cp 60 nodes 802588 time 575 pv e2e4 e7e6 g1f3 f8e7 b1c3 g8f6 d2d4 d7d5 e4e5 f6e4 f1d3 e4c3 b2c3
info depth 12 score cp 40 nodes 1071053 time 738 pv e2e4 e7e6 d2d4 d7d5 e4e5 f8e7 g1f3 e8f8 f1d3 c7c5 e1g1 b8c6
info depth 13 score cp 46 nodes 1329554 time 901 pv e2e4 e7e6 d2d4 d7d5 e4e5 c7c5 g1f3 c5d4 f3d4 c8d7 f1e2
info depth 14 score cp 51 nodes 2396760 time 1617 pv e2e4 e7e6 g1f3 f8e7 d2d4 d7d5 e4e5 c7c5 f1e2 b8c6 e1g1 e8f8 c2c3
info depth 15 score cp 44 nodes 3740992 time 2500 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 f3g5 d7d5 e4d5 c6a5 d2d3 h7h6 g5f3 f8d6 e1g1 a5c4 d3c4
info depth 16 score cp 30 nodes 4946096 time 3295 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 f3g5 d7d5 e4d5 c6a5 c4b5 c7c6 d5c6 b7c6 b5d3 f8d6 e1g1
info depth 17 score cp 28 nodes 6676881 time 4457 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 e1g1 a7a6 d2d3 d7d6 a2a3 e8g8 b2b4 c5d4 c1g5
info depth 18 score cp 29 nodes 8952016 time 6258 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 d2d3 c6a5 f3e5 a5c4 d3c4 e8g8 e5d3 c5d4 c3e2 d4b6
info depth 19 score cp 37 nodes 12429851 time 8702 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 d2d3 a7a6 c3d5 d7d6 c1g5 c8e6 e1g1 e8g8 d5f6 g7f6 g5h6 f8e8 c4e6 f7e6
info depth 20 score cp 23 nodes 20967128 time 14860 pv e2e4 e7e5 g1f3 b8c6 f1c4 g8f6 b1c3 f8c5 d2d3 c6a5 a2a3 a5c4 d3c4 f6g4 e1g1 d7d6 h2h3 g4f2 f1f2 c5f2 g1f2
bestmove e2e4
I ran the program while monitoring the CPU cores' clocks using HW-monitor , before starting the search all cores were near their lowest once the search started the clock of one core rose to the maximum but then this kept changing from one core to another rapidly so I set the affinity of the engine to one core and the slowdown disappeared , I tested this multiple times before I post this , did anyone else experience this and what could be the cause of this strange OS behavior , by the way this only started happening frequently lately , also do major engines set the affinity or leave it to the OS ?

PS: Windows 10 I7-5820K , & compiled using different compilers just to make sure.
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: Strange slow down and affinity !

Post by jdart »

Some multi-core engines have support for setting affinity (pinning threads to cores). I have not actually seen a big benefit from it in my testing, but YMMV.

It can be hard to do this portably. I use the hwloc library for this. Some other issues: logical vs physical cores (hyperthreading) - not always easy to distinguish these and you need to decide what your strategy is for that. Also core numbering is not standardized. Pinning works fine if one engine is using all cores on a machine, but if using multiple engines each with affinity support it can get tricky because they do it different ways.

--Jon
MahmoudUthman
Posts: 234
Joined: Sat Jan 17, 2015 11:54 pm

Re: Strange slow down and affinity !

Post by MahmoudUthman »

jdart wrote:Some multi-core engines have support for setting affinity (pinning threads to cores). I have not actually seen a big benefit from it in my testing, but YMMV.

It can be hard to do this portably. I use the hwloc library for this. Some other issues: logical vs physical cores (hyperthreading) - not always easy to distinguish these and you need to decide what your strategy is for that. Also core numbering is not standardized. Pinning works fine if one engine is using all cores on a machine, but if using multiple engines each with affinity support it can get tricky because they do it different ways.

--Jon
Mine isn't multithreaded , so it even affects single threaded heavily when the OS manages it in a bad way , another thing that elevated the problem was setting the process priority to real-time , but setting the affinity still produced better performance.
Is there no way to ask the OS to keep us on the same core/s if possible instead of hardcoded affinity "to avoid load balancing problems too"?
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Strange slow down and affinity !

Post by Ferdy »

Turbo boost enabled or disabled?
Hyper-threading enabled or disabled?
MahmoudUthman
Posts: 234
Joined: Sat Jan 17, 2015 11:54 pm

Re: Strange slow down and affinity !

Post by MahmoudUthman »

Ferdy wrote:Turbo boost enabled or disabled?
Hyper-threading enabled or disabled?
both enabled
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Strange slow down and affinity !

Post by Ferdy »

MahmoudUthman wrote:
Ferdy wrote:Turbo boost enabled or disabled?
Hyper-threading enabled or disabled?
both enabled
Assigning a process to a certain core by affinity is generally faster when ht is enabled in a system. In addition the system might have activated the turbo too, resulting in a faster search. When turbo is enabled it is difficult to predict the engine performance, there are a lot of conditions of when the system activates it. I disable turbo when running engine tests.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: Strange slow down and affinity !

Post by Rebel »

MahmoudUthman wrote: PS: Windows 10
There you go :lol:

Aside what others already said:

Windows has a will of its own, it does all sorts of mysterious things in the background, your HD will start rattling and you have no idea why that is.

PC connected to the Internet? Terrible.

What's more running in the background?

For serious testing have a clean second PC and disable as much as you can.