Building Amy 0.8.7

Archive of the old Parsimony forum. Some messages couldn't be restored. Limitations: Search for authors does not work, Parsimony specific formats do not work, threaded view does not work properly. Posting is disabled.

Building Amy 0.8.7

Postby Lance Perkins » 06 Mar 2004, 02:32

Geschrieben von: / Posted by: Lance Perkins at 06 March 2004 02:32:55:

I discovered that in SMP mode, there is a serious bug at the end of the function IterateInt, in search.c.
The code:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
sd->best_move = mvs[0];
accesses memory (sd) that has already been freed!!!
This should be:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
else {
sd->best_move = mvs[0];
}
The best_move property is only ever used by the main/master (non-helper) thread.
Below are the steps to compile Amy 0.8.7, for either SMP or non-SMP mode, using MSVC or GCC/MinGW. You don't need pthread libs for this (who needs pthreads in Win32? we got rid of Cygwin dll with MinGW did we not?).
After you make these changes, the code should still build correctly in Unix/Linux.
untar/unzip
cd src
copy ..\config.h.in config.h
Notepad config.h
Add:
#define VERSION "0.8.7"
Replace:
#undef MP
with:
// #undef MP
Replace:
#undef HAVE_LIBPTHREAD
with:
#if MP
#define HAVE_LIBPTHREAD
#endif
Notepad amy.h
Replace:
#if HAVE_LIBPTHREAD
#include "pthread.h"
#endif
With:
#if HAVE_LIBPTHREAD
#if _WIN32
#define pthread_mutex_lock(m_) WaitForSingleObject(*(m_),INFINITE)
#define pthread_mutex_unlock(m_) ReleaseMutex(*(m_))
#define pthread_mutex_t HANDLE
#define PTHREAD_MUTEX_INITIALIZER ((HANDLE)NULL)
#define pthread_t HANDLE
#define pthread_join(t_,x_) WaitForSingleObject(t_,INFINITE)
#define pthread_create(tp_,a_,fp_,p_) (*(tp_) = CreateThread (NULL,1024*1024,fp_,p_,0,NULL))
#define pthread_attr_t int
#define pthread_attr_init(a_)
#define pthread_attr_setscope(a_,n_)
#define PTHREAD_SCOPE_SYSTEM 0
#else
#include "pthread.h"
#endif
#endif
Add:
typedef unsigned __int64 hash_t;
in the same place as:
typedef unsigned __int64 ran_t;
Notepad hashtable.c
At the end of the AllocateHT function, add:
#if MP && _WIN_32
TranspositionMutex = CreateMutex (NULL, FALSE, NULL);
PawnMutex = CreateMutex (NULL, FALSE, NULL);
ScoreMutex = CreateMutex (NULL, FALSE, NULL);
#endif
Notepad probe.c
At the end of the InitEGTB function, add:
#if MP && _WIN_32
EGTBMutex = CreateMutex (NULL, FALSE, NULL);
#endif
Notepad random.c
Replace:
double result = (double) Random64();
with:
#if _WIN32
double result = (double) (__int64) Random64();
#else
double result = (double) Random64();
#endif
Notepad search.c
Replace:
static void *IterateInt(void *x)
with:
#if _WIN32
static DWORD WINAPI IterateInt(LPVOID x)
#else
static void *IterateInt(void *x)
#endif
In function IterateInt, replace:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
sd->best_move = mvs[0];
with:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
else {
sd->best_move = mvs[0];
}
In function IterateInt, replace:
return NULL;
with:
#if _WIN32
return 0;
#else
return NULL;
#endif
Notepad tbindex.c
Replace:
extern "C" int TB_FASTCALL L_TbtProbeTable
with:
extern "C" int L_TbtProbeTable
Using MSVC (remove "-DMP=1" if you don't want SMP):
del *.obj
cl -nologo -DMP=1 -I. -c bitboard.c bookup.c commands.c dbase.c eco.c hashtable.c
cl -nologo -DMP=1 -I. -c init.c learn.c main.c mates.c movedata.c next.c pgn.c
cl -nologo -DMP=1 -I. -c probe.c random.c recog.c score.c search.c search_io.c
cl -nologo -DMP=1 -I. -c state_machine.c swap.c time_ctl.c utils.c version.c
cl -nologo -DMP=1 -c mytb.cpp
cl -Feamy.exe *.obj
Using GCC/MinGW32 (remove "-DMP=1" if you don't want SMP):
del *.o
gcc -O3 -DMP=1 -I. -c bitboard.c bookup.c commands.c dbase.c eco.c hashtable.c
gcc -O3 -DMP=1 -I. -c init.c learn.c main.c mates.c movedata.c next.c pgn.c
gcc -O3 -DMP=1 -I. -c probe.c random.c recog.c score.c search.c search_io.c
gcc -O3 -DMP=1 -I. -c state_machine.c swap.c time_ctl.c utils.c version.c
gcc -O3 -DMP=1 -I. -c mytb.cpp
gcc -o amy.exe *.o
Lance Perkins
 

Re: Building Amy 0.8.7

Postby Dann Corbit » 06 Mar 2004, 02:51

Geschrieben von: / Posted by: Dann Corbit at 06 March 2004 02:51:03:
Als Antwort auf: / In reply to: Building Amy 0.8.7 geschrieben von: / posted by: Lance Perkins at 06 March 2004 02:32:55:
I discovered that in SMP mode, there is a serious bug at the end of the function IterateInt, in search.c.
The code:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
sd->best_move = mvs[0];
accesses memory (sd) that has already been freed!!!
This should be:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
else {
sd->best_move = mvs[0];
}
The best_move property is only ever used by the main/master (non-helper) thread.
Below are the steps to compile Amy 0.8.7, for either SMP or non-SMP mode, using MSVC or GCC/MinGW. You don't need pthread libs for this (who needs pthreads in Win32? we got rid of Cygwin dll with MinGW did we not?).
Not sure if this is better, but it is what I used:
sd->best_move = mvs[0];
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
You can use pthreads with MS VC++ without the cygwin dll.
http://sources.redhat.com/pthreads-win32/
Don't forget the sleepycat database, or it won't use the books.



my ftp site {remove http:// unless you like error messages}
Dann Corbit
 

Re: Building Amy 0.8.7

Postby Lance Perkins » 06 Mar 2004, 03:45

Geschrieben von: / Posted by: Lance Perkins at 06 March 2004 03:45:10:
Als Antwort auf: / In reply to: Re: Building Amy 0.8.7 geschrieben von: / posted by: Dann Corbit at 06 March 2004 02:51:03:

Yours, I believe is better.
As for pthreads, I am aware that you can build it with MSVC. However, it is my opinion that this is an unnecessary code bloat for this application, and a performance hit, since Win32 API's are being wrapped instead of being called directly. Wouldn't a line of macro do a better job? The Win32 API's are just named differently. Name redirections suffice for most apps (like Amy for example).
I mentioned Cygwin not because I think you need it for pthreads. Instead, I am using the analogy of Cygwin in the days prior to Mingw, where we needed Cygwin libs just so we can run Win32 bins created by gcc. I'm really glad that the Mingw folks did what they did.
Two years ago, I offered the GNU Chess folks help in modifying the source to remove the dependency on Cygwin. All that was needed was less than 10 lines of code to be modified. I actually made the changes and sent it to them. The reply? They are not interested in supporting "proprietary" platforms. Well, over time it got Win32 native compile support anyway. Back then, I was thinking of bringing new ideas to GNU Chess after it runs in native Win32. But because they don't seem to be interested, I just took my ideas elsewhere.
I discovered that in SMP mode, there is a serious bug at the end of the function IterateInt, in search.c.
The code:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
sd->best_move = mvs[0];
accesses memory (sd) that has already been freed!!!
This should be:
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
else {
sd->best_move = mvs[0];
}
The best_move property is only ever used by the main/master (non-helper) thread.
Below are the steps to compile Amy 0.8.7, for either SMP or non-SMP mode, using MSVC or GCC/MinGW. You don't need pthread libs for this (who needs pthreads in Win32? we got rid of Cygwin dll with MinGW did we not?).
Not sure if this is better, but it is what I used:
sd->best_move = mvs[0];
if(!sd->master) {
FreePosition(sd->position);
FreeSearchData(sd);
}
You can use pthreads with MS VC++ without the cygwin dll.
http://sources.redhat.com/pthreads-win32/
Don't forget the sleepycat database, or it won't use the books.
Lance Perkins
 

Re: Building Amy 0.8.7

Postby Dann Corbit » 06 Mar 2004, 03:59

Geschrieben von: / Posted by: Dann Corbit at 06 March 2004 03:59:21:
Als Antwort auf: / In reply to: Re: Building Amy 0.8.7 geschrieben von: / posted by: Lance Perkins at 06 March 2004 03:45:10:
Yours, I believe is better.
As for pthreads, I am aware that you can build it with MSVC. However, it is my opinion that this is an unnecessary code bloat for this application, and a performance hit, since Win32 API's are being wrapped instead of being called directly. Wouldn't a line of macro do a better job? The Win32 API's are just named differently. Name redirections suffice for most apps (like Amy for example).
I mentioned Cygwin not because I think you need it for pthreads. Instead, I am using the analogy of Cygwin in the days prior to Mingw, where we needed Cygwin libs just so we can run Win32 bins created by gcc. I'm really glad that the Mingw folks did what they did.
Two years ago, I offered the GNU Chess folks help in modifying the source to remove the dependency on Cygwin. All that was needed was less than 10 lines of code to be modified. I actually made the changes and sent it to them. The reply? They are not interested in supporting "proprietary" platforms. Well, over time it got Win32 native compile support anyway. Back then, I was thinking of bringing new ideas to GNU Chess after it runs in native Win32. But because they don't seem to be interested, I just took my ideas elsewhere.
The binary is only a couple K bigger with the pthreads DLL linked in.
Since it is only called to start a search thread, I think the overhead will be so small you can't measure it.
The pthreads DLL itself is 65K, but several programs use it and you only need one copy.
Me too.
I find that is fairly typical. There is a subset of the Linux crowd that is totally Windows-phobic. I am quite sure that this tiny but very vocal minority is repsonsible for all sorts of retardation of Linux and compatible tools.
Yes, Microsoft has done some stinky things. Even some illegal and immoral things. About like any other company its size (which is not a justification, but an observation). But the radical stance of GPL freaks like Stallman is also damaging [in my view]. In a sense it is an exploitation of the poor schmucks who give their labor for free so companies like Redhat, SuSE, Mandrake, Debian, Slackware, RH, YellowDog, Peanut, Mitel can profit from it with no pay, no benefits no nothing. But I guess it is their choice anyway. It gets to be a religious shouting match anyway.
Imagine a company that does not provide any pay to the vast majority of its workers. It also provides no benefits. The 9 cents per hour sweat shops in 3rd world nations pale in comparison.
"But the kids enjoy making those sneakers!"
Oh, well.
Here is how I see operating systems:
They are tools used to solve business problems.
I don't care who makes them very much.
I like to be able to see the source code for things, but I expect the vendor to fix a broken operating system function, anyway.



my ftp site {remove http:// unless you like error messages}
Dann Corbit
 


Return to Archive (Old Parsimony Forum)

Who is online

Users browsing this forum: No registered users and 41 guests