Polyglot 1.4w Released

Discussion of anything and everything relating to chess playing software and machines.

Moderator: Ras

User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot 1.4w11 Released

Post by hgm »

Michel wrote:
winboard doesn't have a way to lower the engine priority, and I go nuts!
Ok let's ask H.G. Muller politely. He occasionally reads this forum :-)
Well, it sounds easy enough, if someone would tell me the required Windows API call. Or is Cygwin gcc smart enough to understand the nice() system call even with -mno-cygwin compiles?

I guess supplying this option for engines independently would only invite cheating. So I could add a single command-line option -niceEngines N.
Michel
Posts: 2292
Joined: Mon Sep 29, 2008 1:50 am

Re: Polyglot 1.4w11 Released

Post by Michel »

Since Eric is not replying here is the part of PG1.4w11 that sets the engine priority on windows

Code: Select all

static HANDLE child;

DWORD GetWin32Priority(int nice)
{
/*
REALTIME_PRIORITY_CLASS     0x00000100
HIGH_PRIORITY_CLASS         0x00000080
ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
NORMAL_PRIORITY_CLASS       0x00000020
BELOW_NORMAL_PRIORITY_CLASS 0x00004000
IDLE_PRIORITY_CLASS         0x00000040
*/
        if (nice < -15) return 0x00000080;
        if (nice < 0)   return 0x00008000;
        if (nice == 0)  return 0x00000020;
        if (nice < 15)  return 0x00004000;
        return 0x00000040;
}

void AdjustEnginePriority()
{
        if ((option_get_int("EngineNice"))){
        my_log("POLYGLOT Adjust Engine Piority");
    SetPriorityClass(child, GetWin32Priority(option_get_int("EngineNice")));
        }
}
"child" is the HANDLE of the engine. It is a (static) global variable set at creation
of the engine process.
bnemias
Posts: 373
Joined: Thu Aug 14, 2008 3:21 am
Location: Albuquerque, NM

Re: Polyglot 1.4w11 Released

Post by bnemias »

Michel wrote:Since Eric is not replying here is the part of PG1.4w11 that sets the engine priority on windows

Code: Select all

static HANDLE child;

DWORD GetWin32Priority(int nice)
{
/*
REALTIME_PRIORITY_CLASS     0x00000100
HIGH_PRIORITY_CLASS         0x00000080
ABOVE_NORMAL_PRIORITY_CLASS 0x00008000
NORMAL_PRIORITY_CLASS       0x00000020
BELOW_NORMAL_PRIORITY_CLASS 0x00004000
IDLE_PRIORITY_CLASS         0x00000040
*/
        if (nice < -15) return 0x00000080;
        if (nice < 0)   return 0x00008000;
        if (nice == 0)  return 0x00000020;
        if (nice < 15)  return 0x00004000;
        return 0x00000040;
}

void AdjustEnginePriority()
{
        if ((option_get_int("EngineNice"))){
        my_log("POLYGLOT Adjust Engine Piority");
    SetPriorityClass(child, GetWin32Priority(option_get_int("EngineNice")));
        }
}
"child" is the HANDLE of the engine. It is a (static) global variable set at creation
of the engine process.
Ugh. It never occurred to me that code might be used elsewhere or I would have commented things better. Be aware:

The SetPriorityClass() API call (And the creation flags in the CreateProcess() call) do not understand ABOVE_NORMAL_PRIORITY_CLASS or BELOW_NORMAL_PRIORITY_CLASS below windows 2000. (I think.. who knows, this stuff changes every windows version) So if you want to lower the priority on Windows 9x, the above code won't work unless your EngineNice option is 15 or greater. One of the older compilers I tested didn't have those flags in its headers, which is why I didn't use the identifiers.
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot 1.4w11 Released

Post by hgm »

OK, I put it in, and it seems to work. Just run WinBoard with the command-line option

-niceEngines N

and the engines will run at the altered priority. Default is N=0 (normal priority = the same as the GUI process). Wit N=10 or N=20 you can lower the priority to "below normal" or "low", respectively. I checked that this works with the task manager.

The option setting is saved in the winboard.ini, as I suppose that you would set it once and for all to get a smooth operation on and of your system.

With N=-10 or -20 you could raise the priority, I suppose, but this is not recommended.

The alpha.tst on my website is the winboard.exe that contains the change.
bnemias
Posts: 373
Joined: Thu Aug 14, 2008 3:21 am
Location: Albuquerque, NM

Re: Polyglot 1.4w11 Released

Post by bnemias »

hgm wrote:OK, I put it in, and it seems to work. Just run WinBoard with the command-line option

-niceEngines N
I tested it, and it works great.
User avatar
hgm
Posts: 28387
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Polyglot 1.4w11 Released

Post by hgm »

OK, so that is a good new feature to include in WinBoard 4.3.16 then! I already put the option in xboard.c as well (simply calling nice() with the given option value within the child process, just before exec()), but I haven't tested it yet.
Michel
Posts: 2292
Joined: Mon Sep 29, 2008 1:50 am

Re: Polyglot 1.4w11 Released

Post by Michel »

Now that I have done a lot of restructuring of the Windows code it appears that the native port of PG is based on a class called "PipeStruct."

Who is the author of that class? Is it Fonzy Bleumers?

I did some Googling. I found some chinese websites but the license of the code is unfortunately in Chinese....

I just would like to make sure the license is GPL compatible.
Marc Lacrosse
Posts: 511
Joined: Wed Mar 08, 2006 10:05 pm

Re: Polyglot 1.4w11 Released

Post by Marc Lacrosse »

Michel wrote:Now that I have done a lot of restructuring of the Windows code it appears that the native port of PG is based on a class called "PipeStruct."

Who is the author of that class? Is it Fonzy Bleumers?

I did some Googling. I found some chinese websites but the license of the code is unfortunately in Chinese....

I just would like to make sure the license is GPL compatible.
Original windows port was by Fabien himself (just before WCCC 2005) for the preparation of Fruit's tournament opening book.
It could well be that fabien himself was the author of this ?

Marc
Michel
Posts: 2292
Joined: Mon Sep 29, 2008 1:50 am

Re: Polyglot 1.4w11 Released

Post by Michel »

Original windows port was by Fabien himself (just before WCCC 2005) for the preparation of Fruit's tournament opening book.
It could well be that fabien himself was the author of this ?
That would be very nice. Can someone confirm this?

PG always ran on Windows but you needed the Cygwin dll. The current version
of PG uses the native WIN32 api.
F. Bluemers
Posts: 880
Joined: Thu Mar 09, 2006 11:21 pm
Location: Nederland

Re: Polyglot 1.4w11 Released

Post by F. Bluemers »

Michel wrote:
Original windows port was by Fabien himself (just before WCCC 2005) for the preparation of Fruit's tournament opening book.
It could well be that fabien himself was the author of this ?
That would be very nice. Can someone confirm this?

PG always ran on Windows but you needed the Cygwin dll. The current version
of PG uses the native WIN32 api.
no ,the cywinless port (and pipestruct) is from the chinese author "Morning Yellow" who also created mobile chess (wccc 2008) http://sourceforge.net/project/shownote ... _id=196069