Skip to content

Commit

Permalink
historical commit dds 2.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
bohag authored and hostilefork committed Nov 25, 2014
1 parent 4f716cc commit c68aefc
Show file tree
Hide file tree
Showing 6 changed files with 750 additions and 111 deletions.
56 changes: 27 additions & 29 deletions DLL-dds_223_o.rtf → DLL-dds_224_o.rtf

Large diffs are not rendered by default.

661 changes: 661 additions & 0 deletions DLL-dds_240_q.rtf

Large diffs are not rendered by default.

97 changes: 31 additions & 66 deletions dds.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/* DDS 2.2.3 A bridge double dummy solver. */
/* DDS 2.2.4 A bridge double dummy solver. */
/* Copyright (C) 2006-2012 by Bo Haglund */
/* Cleanups and porting to Linux and MacOSX (C) 2006 by Alex Martelli */
/* */
Expand Down Expand Up @@ -42,10 +42,6 @@ int noOfThreads=MAXNOOFTHREADS; /* The number of entries to the transposition t
one entry per thread. */
int noOfCores; /* The number of processor cores, however cannot be higher than noOfThreads. */

/*#if defined(_MSC_VER)
CRITICAL_SECTION solv_crit;
#endif*/

#ifdef _MANAGED
#pragma managed(push, off)
#endif
Expand All @@ -59,14 +55,8 @@ extern "C" BOOL APIENTRY DllMain(HMODULE hModule,

if (ul_reason_for_call==DLL_PROCESS_ATTACH) {
InitStart(0, 0);
/*#if defined(_MSC_VER)
InitializeCriticalSection(&solv_crit);
#endif*/
}
else if (ul_reason_for_call==DLL_PROCESS_DETACH) {
/*#if defined(_MSC_VER)
DeleteCriticalSection(&solv_crit);
#endif*/
for (k=0; k<noOfThreads; k++) {
Wipe(k);
if (localVar[k].pw[0])
Expand Down Expand Up @@ -139,7 +129,7 @@ extern "C" BOOL APIENTRY DllMain(HMODULE hModule,
but preferable InitStart should be called outside
SolveBoard like in DllMain for Windows. */

if ((thrId<0)||(thrId>=noOfThreads)) {
if ((thrId<0)||(thrId>=noOfThreads)) { /* Fault corrected after suggestion by Dirk Willecke. */
DumpInput(-15, dl, target, solutions, mode);
return -15;
}
Expand Down Expand Up @@ -860,7 +850,8 @@ void InitStart(int gb_ram, int ncores) {
MEMORYSTATUSEX statex;
statex.dwLength = sizeof (statex);

GlobalMemoryStatusEx (&statex);
GlobalMemoryStatusEx (&statex); /* Using GlobalMemoryStatusEx instead of GlobalMemoryStatus
was suggested by Lorne Anderson. */

pcmem=(unsigned long long)statex.ullTotalPhys/1024;

Expand All @@ -875,7 +866,7 @@ void InitStart(int gb_ram, int ncores) {
noOfCores=Min(noOfThreads, (int)temp.dwNumberOfProcessors);

#endif
#ifdef __linux__
#ifdef __linux__ /* The code for linux was suggested by Antony Lee. */
FILE* fifo = popen("free -k | tail -n+3 | head -n1 | awk '{print $NF}'", "r");
fscanf(fifo, "%ld", &pcmem);
fclose(fifo);
Expand Down Expand Up @@ -965,9 +956,7 @@ void InitStart(int gb_ram, int ncores) {
localVar[k].wmem=(WSIZE+1)*sizeof(struct winCardType);
localVar[k].nmem=(NSIZE+1)*sizeof(struct nodeCardsType);
localVar[k].lmem=(LSIZE+1)*sizeof(struct posSearchType);
/*localVar[k].maxIndex=(int)(
localVar[k].maxmem-localVar[k].summem)/((WSIZE+1) * sizeof(struct winCardType));*/
localVar[k].maxIndex=(int)(
localVar[k].maxIndex=(int)(
(localVar[k].maxmem-localVar[k].summem)/((WSIZE+1) * sizeof(struct winCardType)));

localVar[k].pw = (struct winCardType **)calloc(localVar[k].maxIndex+1, sizeof(struct winCardType *));
Expand Down Expand Up @@ -2372,19 +2361,7 @@ int QuickTricks(struct pos * posPoint, int hand,
commPartner=FALSE;
for (s=0; s<=3; s++) {
if ((trump!=4)&&(trump!=s)) {
/*if ((posPoint->rankInSuit[hand][s]!=0)&&((posPoint->rankInSuit[lho[hand]][s]!=0)||
(posPoint->rankInSuit[lho[hand]][trump]==0))&&
((posPoint->rankInSuit[rho[hand]][s]!=0)||(posPoint->rankInSuit[rho[hand]][trump]==0))&&
(posPoint->rankInSuit[partner[hand]][s]==0)&&(posPoint->rankInSuit[partner[hand]][trump]>0)
&&((posPoint->winner[s].hand==lho[hand])||(posPoint->winner[s].hand==rho[hand]))&&
((posPoint->winner[trump].hand==lho[hand])||(posPoint->winner[trump].hand==rho[hand]))) {
commPartner=TRUE;
commSuit=s;
commRank=0;
ruff=TRUE;
break;
}
else*/ if (posPoint->winner[s].hand==partner[hand]) {
if (posPoint->winner[s].hand==partner[hand]) {
/* Partner has winning card */
if (posPoint->rankInSuit[hand][s]!=0) {
/* Own hand has card in suit */
Expand Down Expand Up @@ -2465,16 +2442,7 @@ int QuickTricks(struct pos * posPoint, int hand,
countPart=posPoint->length[partner[hand]][suit];
opps=countLho | countRho;

/*if ((ruff)&&(suit==commSuit)) {
qtricks++;
if (qtricks>=cutoff)
return qtricks;
suit++;
if ((trump!=4) && (suit==trump))
suit++;
continue;
}
else*/ if (!opps && (countPart==0)) {
if (!opps && (countPart==0)) {
if (countOwn==0) {
/* Continue with next suit. */
if ((trump!=4)&&(trump!=suit)) {
Expand Down Expand Up @@ -3466,7 +3434,7 @@ int MoveGen(struct pos * posPoint, int depth, int trump, struct movePlyType *mpl
k--;
}
if (m!=1) {
if ((trump!=4)/*&&(posPoint->winner[trump].hand!=-1)*/) {
if ((trump!=4)&&(posPoint->winner[trump].rank!=0)) {
for (k=0; k<=m-1; k++)
mply->move[k].weight=WeightAllocTrump(posPoint,
&(mply->move[k]), depth, ris, trump, thrId);
Expand Down Expand Up @@ -3516,7 +3484,7 @@ int MoveGen(struct pos * posPoint, int depth, int trump, struct movePlyType *mpl
}
}

if ((trump!=4)/*&&(posPoint->winner[trump].hand!=-1)*/) {
if ((trump!=4)&&(posPoint->winner[trump].rank!=0)) {
for (k=0; k<=m-1; k++)
mply->move[k].weight=WeightAllocTrump(posPoint,
&(mply->move[k]), depth, 0/*ris*/, trump, thrId);
Expand Down Expand Up @@ -3544,7 +3512,7 @@ int WeightAllocNT(struct pos * posPoint, struct moveType * mp, int depth,
unsigned short notVoidInSuit, int thrId) {
int weight=0, k, l, kk, ll, suit, suitAdd=0, leadSuit;
int suitWeightDelta, first, q;
int rRank;
int rRank, thirdBestHand;
int suitBonus=0;
int winMove=FALSE;
unsigned short suitCount, suitCountLH, suitCountRH, aggr;
Expand All @@ -3560,6 +3528,7 @@ int WeightAllocNT(struct pos * posPoint, struct moveType * mp, int depth,

switch (posPoint->handRelFirst) {
case 0:
thirdBestHand=localVar[thrId].rel[aggr].absRank[3][suit].hand;
suitCount=posPoint->length[q][suit];
suitCountLH=posPoint->length[lho[q]][suit];
suitCountRH=posPoint->length[rho[q]][suit];
Expand Down Expand Up @@ -3624,6 +3593,13 @@ int WeightAllocNT(struct pos * posPoint, struct moveType * mp, int depth,
weight+=20/*17*//*14*/;
}
else {
if ((posPoint->secondBest[suit].hand==partner[first])&&(partner[first]==thirdBestHand))
suitWeightDelta+=22/*20*//*10*/;
else if(((posPoint->secondBest[suit].hand==first)&&(partner[first]==thirdBestHand)&&
(posPoint->length[partner[first]][suit]>1))||((posPoint->secondBest[suit].hand==partner[first])&&
(first==thirdBestHand)&&(posPoint->length[partner[first]][suit]>1)))
suitWeightDelta+=24/*20*//*10*/;

if (((suitCountLH==1)&&(posPoint->winner[suit].hand==lho[first]))
||((suitCountRH==1)&&(posPoint->winner[suit].hand==rho[first])))
weight=suitWeightDelta+25/*23*//*22*/+rRank;
Expand Down Expand Up @@ -3826,7 +3802,7 @@ int WeightAllocNT(struct pos * posPoint, struct moveType * mp, int depth,
int WeightAllocTrump(struct pos * posPoint, struct moveType * mp, int depth,
unsigned short notVoidInSuit, int trump, int thrId) {
int weight=0, k, l, kk, ll, suit, suitAdd=0, leadSuit;
int suitWeightDelta, first, q, rRank;
int suitWeightDelta, first, q, rRank, thirdBestHand;
int suitBonus=0;
int winMove=FALSE;
unsigned short suitCount, suitCountLH, suitCountRH, aggr;
Expand All @@ -3842,6 +3818,7 @@ int WeightAllocTrump(struct pos * posPoint, struct moveType * mp, int depth,

switch (posPoint->handRelFirst) {
case 0:
thirdBestHand=localVar[thrId].rel[aggr].absRank[3][suit].hand;
suitCount=posPoint->length[q][suit];
suitCountLH=posPoint->length[lho[q]][suit];
suitCountRH=posPoint->length[rho[q]][suit];
Expand Down Expand Up @@ -3988,6 +3965,14 @@ int WeightAllocTrump(struct pos * posPoint, struct moveType * mp, int depth,
weight+=14/*15*//*12*//*11*/;
}
else {
if ((posPoint->secondBest[suit].hand==partner[first])&&(partner[first]==thirdBestHand))
suitWeightDelta+=20/*22*/;
else if(((posPoint->secondBest[suit].hand==first)&&(partner[first]==thirdBestHand)&&
(posPoint->length[partner[first]][suit]>1))||
((posPoint->secondBest[suit].hand==partner[first])&&
(first==thirdBestHand)&&(posPoint->length[partner[first]][suit]>1)))
suitWeightDelta+=20/*24*/;

if (((suitCountLH==1)&&(posPoint->winner[suit].hand==lho[first]))
||((suitCountRH==1)&&(posPoint->winner[suit].hand==rho[first])))
weight=suitWeightDelta+rRank-2;
Expand Down Expand Up @@ -5579,16 +5564,6 @@ DWORD CALLBACK SolveChunkDDtable (void *) {
int thid;
long j;

/*EnterCriticalSection(&solv_crit);
__try
{
threadIndex++;
thid=threadIndex;
}
__finally
{
LeaveCriticalSection(&solv_crit);
}*/
thid=InterlockedIncrement(&threadIndex);

while ((j=_InterlockedExchangeAdd(&current, chunk))<param.noOfBoards) {
Expand Down Expand Up @@ -5680,16 +5655,6 @@ DWORD CALLBACK SolveChunk (void *) {
int thid;
long j;

/*EnterCriticalSection(&solv_crit);
__try
{
threadIndex++;
thid=threadIndex;
}
__finally
{
LeaveCriticalSection(&solv_crit);
}*/
thid=InterlockedIncrement(&threadIndex);

while ((j=(InterlockedIncrement(&current)-1))<param.noOfBoards) {
Expand Down Expand Up @@ -5785,7 +5750,7 @@ int SolveAllBoards4(struct boards *bop, struct solvedBoards *solvedp) {
for (i=0; i<MAXNOOFBOARDS; i++)
solvedp->solvedBoard[i].cards=0;

omp_set_num_threads(noOfCores);
omp_set_num_threads(noOfCores); /* Added after suggestion by Dirk Willecke. */

#pragma omp parallel shared(bop, solvedp, chunk, fail) private(k)
{
Expand Down Expand Up @@ -5827,7 +5792,7 @@ int SolveAllBoards1(struct boards *bop, struct solvedBoards *solvedp) {
for (i=0; i<MAXNOOFBOARDS; i++)
solvedp->solvedBoard[i].cards=0;

omp_set_num_threads(noOfCores);
omp_set_num_threads(noOfCores); /* Added after suggestion by Dirk Willecke. */

#pragma omp parallel shared(bop, solvedp, chunk, fail) private(k)
{
Expand Down
11 changes: 6 additions & 5 deletions dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

/* end of portability-macros section */

#define DDS_VERSION 20203 /* Version 2.2.3. Allowing for 2 digit
#define DDS_VERSION 20204 /* Version 2.2.4. Allowing for 2 digit
minor versions */

#define PBN
Expand Down Expand Up @@ -365,10 +365,6 @@ struct localVarType {
int lenSetSize; /* Index with range 0 to lenSetSizeLimit */
};

/*#if defined(_WIN32)
extern CRITICAL_SECTION solv_crit;
#endif*/

extern int noOfThreads;
extern int noOfCores;
extern struct localVarType localVar[MAXNOOFTHREADS];
Expand Down Expand Up @@ -444,6 +440,11 @@ EXTERN_C DLLEXPORT int STDCALL SolveAllBoards(struct boardsPBN *bop, struct solv
#endif
#endif

#ifdef __linux
/*paul hide 2012-11-6 added the following as in previous version*/
EXTERN_C void InitStart(int gb_ram, int ncores); /* For usage with ctypes in Linux. */
#endif

void InitStart(int gb_ram, int ncores);
void InitGame(int gameNo, int moveTreeFlag, int first, int handRelFirst, int thrId);
void InitSearch(struct pos * posPoint, int depth,
Expand Down
17 changes: 9 additions & 8 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
DDS 2.2.1, Bo Haglund 2012-07-16
DDS 2.2.4, Bo Haglund 2012-11-07

For Win32, DDS compiles with Visual C++ 2010 Express edition
and the Mingw port of gcc.
and the TDM-GCC/Mingw port of gcc.

When using Visual C++, the statement
#include "stdafx.h" at the beginning of dds.cpp must be uncommented.

When not using Visual C++, the compilation of DDS includes function CalcDDtable
implemented using GCC/MingW OpenMP.
implemented using TDM-GCC/MingW OpenMP.


Linking with an application using DDS
Expand All @@ -24,20 +24,21 @@ Maximum number of threads
The maximum number of simultaneous threads depends on the PC physical memory size:
1 GB or less, max 2 threads.
2 GB, max 4 threads.
3 or 4 GB, max 8 threads.
3 or 4 GB, max 16 threads.

For Windows, allocating memory for the maximum number of simultaneous threads can
For e.g. Windows, allocating memory for the maximum number of simultaneous threads can
be done by reading out the physical memory size from Windows. This is done in the DDS.DLL.
Another alternative is to provide the physical memory size as a parameter (gb_ram) in the
InitStart call. This alternative needs to be used when the operating system is not Windows.
InitStart call. This alternative needs to be used when the operating system does not support
memory autoconfiguration.


Setting the number of simultaneous threads when calling CalcDDtable.
--------------------------------------------------------------------
For Windows, this can be done either by reading out the number of processor cores from
Windows and using this for setting the number of threads, or by supplying the number of
threads (ncores) in InitStart. This latter alternative needs to be used when the operating
system is not Windows.
system does not support reading out of the number of processors.


Options at DDS compilation
Expand All @@ -54,7 +55,7 @@ The possible configurens thus are:
2) "PBN": Support for SolveBoardPBN and CalcDDtablePBN.
3) None of these definitions: No support for any of the above 3 functions.

Staying with the previous configuration might be needed when 2.2.2 is to replace an
Staying with the previous configuration might be needed when 2.2.4 is to replace an
older 2.x.y version, and the application using DDS cannot handle a changed interface.


Expand Down
19 changes: 16 additions & 3 deletions release_notes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,25 @@ DDS 2.2.3 add Mingw compiled DLLs and makes a number of code improvements.
Maximum number of threads is increased to 16.
The 2.2.3 Mingw DLLs are about 5% faster than the 2.2.2 DLLs.


Release Notes DDS 1.1.16
-----------------------
------------------------
DDS 1.1.16 add Mingw compiled DLLs and makes a number of code improvements.
The 2.2.3 Mingw DLLs are about 5% faster than the 1.1.15 DLLs.
The 1.1.16 Mingw DLLs are about 5% faster than the 1.1.15 DLLs.


Release Notes DDS 2.2.4
-----------------------
A newer port from GCC to Windows, the TDM-GCC 4.7.1 version is used. It gives
faster DLLs and only requires one supporting DLL, which supports OpenMP.
Also, the move ordering has been slighly improved.
A total speed increase of 4% is achieved compared to 2.2.3.

Release Notes DDS 1.1.17
------------------------
A newer port from GCC to Windows, the TDM-GCC 4.7.1 version is used. It gives
faster DLLs and does not require any supporting DLLs.
Also, the move ordering has been slighly improved.
A total speed increase of 4% is achieved compared to 1.1.16.



Expand Down

0 comments on commit c68aefc

Please sign in to comment.