Page 1 of 1

Set Affinity

Posted: Sat May 19, 2012 1:23 pm
by mwyoung
I have not seen this talked about. So I don't know if other computer chess players use set affinity when using their chess programs.

I always use the affinity option in task manager with big speed ups of 20% or great on all chess program even single core programs. Over not setting the programs affinity.

I have a i7 processor, with windows 7. So I don't know if this works with other cpu's.

For those who don't know who to set affinity in windows 7, here is an example for my system.

For Houdini 2.0c

From windows task manager right click on the houdini processes in the processes window of task manager. I have a 4 core system with 8 logical cores, So I uncheck all processors, and click logical cores 0, 2, 4 , 6.

For Rybka

You will see 4 processes of Rybka not one as with Houdini. Go into each processes of Rybka uncheck all processors and set each rybka processes to one cpu core.

example

Rybka.exe set cpu core 0
Rybka.exe set cpu core 2
rybka.exe set cpu core 4
rybka.exe set cpu core 6

If you have more or less cpu cores then I do expand or contract the pattern.

Re: Set Affinity

Posted: Sat May 19, 2012 8:38 pm
by zullil
mwyoung wrote:I have not seen this talked about. So I don't know if other computer chess players use set affinity when using their chess programs.

I always use the affinity option in task manager with big speed ups of 20% or great on all chess program even single core programs. Over not setting the programs affinity.

I have a i7 processor, with windows 7. So I don't know if this works with other cpu's.

For those who don't know who to set affinity in windows 7, here is an example for my system.

For Houdini 2.0c

From windows task manager right click on the houdini processes in the processes window of task manager. I have a 4 core system with 8 logical cores, So I uncheck all processors, and click logical cores 0, 2, 4 , 6.

For Rybka

You will see 4 processes of Rybka not one as with Houdini. Go into each processes of Rybka uncheck all processors and set each rybka processes to one cpu core.

example

Rybka.exe set cpu core 0
Rybka.exe set cpu core 2
rybka.exe set cpu core 4
rybka.exe set cpu core 6

If you have more or less cpu cores then I do expand or contract the pattern.
I've never used Windows, but I have to believe that the OS would assign each of the four Houdini threads to its own physical core. Are you sure you are doing better than what the OS does by default?

Re: Set Affinity

Posted: Sun May 20, 2012 12:21 am
by User923005
I guess that the o.p. has hyperthreading turned on. Hyperthreading is pretty well useless most of the time, and it is problematic for chess engines.

Re: Set Affinity

Posted: Sun May 20, 2012 2:17 am
by zullil
User923005 wrote:I guess that the o.p. has hyperthreading turned on. Hyperthreading is pretty well useless most of the time, and it is problematic for chess engines.
I wondered about this too. But even with hyperthreading enabled, I assume the OS would assign 4 threads to 4 physical cores, rather than have two threads share a physical core.

Re: Set Affinity

Posted: Sun May 20, 2012 5:14 am
by mwyoung
zullil wrote:
User923005 wrote:I guess that the o.p. has hyperthreading turned on. Hyperthreading is pretty well useless most of the time, and it is problematic for chess engines.
I wondered about this too. But even with hyperthreading enabled, I assume the OS would assign 4 threads to 4 physical cores, rather than have two threads share a physical core.

I have no hyperthreading option, I use 4 processes for 8 logical cores. By setting affinity I lock each of the 4 processes to its own pyshical core, now the operating system can not suffle that process to all 8 logical cores wasting cpu time. Now for example the first of the 4 threads can only use logical core 0, instead of being shuffled around to all 8 logical cores. This gives my system over a 20% speed up over not setting affinity.

This is easy to test, Set affinity on your system and see what results you get.....

Re: Set Affinity

Posted: Sun May 20, 2012 5:59 pm
by hyatt
mwyoung wrote:
zullil wrote:
User923005 wrote:I guess that the o.p. has hyperthreading turned on. Hyperthreading is pretty well useless most of the time, and it is problematic for chess engines.
I wondered about this too. But even with hyperthreading enabled, I assume the OS would assign 4 threads to 4 physical cores, rather than have two threads share a physical core.

I have no hyperthreading option, I use 4 processes for 8 logical cores. By setting affinity I lock each of the 4 processes to its own pyshical core, now the operating system can not suffle that process to all 8 logical cores wasting cpu time. Now for example the first of the 4 threads can only use logical core 0, instead of being shuffled around to all 8 logical cores. This gives my system over a 20% speed up over not setting affinity.

This is easy to test, Set affinity on your system and see what results you get.....

Won't do a thing on linux. It has had a processor affinity aware scheduler for years and with 8 cores and 4 threads the 4 threads will lock onto 4 cores automatically...

Don't know about (and don't care about) windows, of course...

Re: Set Affinity

Posted: Sun May 20, 2012 6:51 pm
by lmader
The Windows scheduler is processor affinity aware and both Windows Vista and Windows 7 have an excellent implementation. It will almost always beat manually setting processor affinity.

I think you may be seeing a speed up because by manually setting the processor affinity you are essentially taking the process off of the logical (hyperthreaded) cores, and restricting it to the physical cores. You can achieve a better result by setting an option in the chess engine itself to use (in the case of a 4 physical core + 4 hyperthreaded "cores") 4 threads instead of 8.

In other words, you don't want the chess engine using hyperthreaded cores, so most people do that by setting the number of threads for the engine to the number of physical cores. Then the OS (Windows included) will place those threads on physical cores, giving you a similar result but with the benefit of letting the OS manage this.

Re: Set Affinity

Posted: Sun May 20, 2012 7:13 pm
by zullil
lmader wrote:The Windows scheduler is processor affinity aware and both Windows Vista and Windows 7 have an excellent implementation. It will almost always beat manually setting processor affinity.

I think you may be seeing a speed up because by manually setting the processor affinity you are essentially taking the process off of the logical (hyperthreaded) cores, and restricting it to the physical cores. You can achieve a better result by setting an option in the chess engine itself to use (in the case of a 4 physical core + 4 hyperthreaded "cores") 4 threads instead of 8.

In other words, you don't want the chess engine using hyperthreaded cores, so most people do that by setting the number of threads for the engine to the number of physical cores. Then the OS (Windows included) will place those threads on physical cores, giving you a similar result but with the benefit of letting the OS manage this.
Yes, this is what I expected to hear about the OS. What is still unclear to me is the number of threads the OP set Houdini to use. If he set 4, then I assume that the OS would run each thread on its own physical core, regardless of whether or not hyperthreading were enabled.

Re: Set Affinity

Posted: Sun May 20, 2012 9:42 pm
by lmader
zullil wrote: Yes, this is what I expected to hear about the OS. What is still unclear to me is the number of threads the OP set Houdini to use. If he set 4, then I assume that the OS would run each thread on its own physical core, regardless of whether or not hyperthreading were enabled.
You are correct that if Houdini was set to use 4 threads, then the OS should have done the right thing. I don't know how many threads Houdini defaults to using, but many engines detect the number of "cores" (without knowing if any are only logical cores), and use them all.

There is a way to set the number of threads for Houdini, either through a config file or through the UCI params, not sure which.