Set Affinity

General discussion about computer chess...
Post Reply
mwyoung
Posts: 43
Joined: Thu Jan 05, 2012 1:13 am
Real Name: Mark Young

Set Affinity

Post by mwyoung » Sat May 19, 2012 1:23 pm

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.

zullil
Posts: 82
Joined: Thu Jun 10, 2010 10:17 am
Real Name: Louis Zulli
Location: Pennsylvania, USA

Re: Set Affinity

Post by zullil » Sat May 19, 2012 8:38 pm

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?

User923005
Posts: 616
Joined: Thu May 19, 2011 1:35 am

Re: Set Affinity

Post by User923005 » Sun May 20, 2012 12:21 am

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.

zullil
Posts: 82
Joined: Thu Jun 10, 2010 10:17 am
Real Name: Louis Zulli
Location: Pennsylvania, USA

Re: Set Affinity

Post by zullil » Sun May 20, 2012 2:17 am

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.

mwyoung
Posts: 43
Joined: Thu Jan 05, 2012 1:13 am
Real Name: Mark Young

Re: Set Affinity

Post by mwyoung » Sun May 20, 2012 5:14 am

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.....

hyatt
Posts: 1242
Joined: Thu Jun 10, 2010 2:13 am
Real Name: Bob Hyatt (Robert M. Hyatt)
Location: University of Alabama at Birmingham
Contact:

Re: Set Affinity

Post by hyatt » Sun May 20, 2012 5:59 pm

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...

User avatar
lmader
Posts: 70
Joined: Thu Jun 10, 2010 3:22 am

Re: Set Affinity

Post by lmader » Sun May 20, 2012 6:51 pm

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.

zullil
Posts: 82
Joined: Thu Jun 10, 2010 10:17 am
Real Name: Louis Zulli
Location: Pennsylvania, USA

Re: Set Affinity

Post by zullil » Sun May 20, 2012 7:13 pm

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.

User avatar
lmader
Posts: 70
Joined: Thu Jun 10, 2010 3:22 am

Re: Set Affinity

Post by lmader » Sun May 20, 2012 9:42 pm

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.

Post Reply