From bb4aaf2da465cd1f3494bb3b5cc34943c25e0d90 Mon Sep 17 00:00:00 2001 From: AndyGrant Date: Sun, 1 Jul 2018 13:42:47 -0400 Subject: [PATCH] . --- src/makefile | 2 ++ src/search.c | 15 ++++++++++----- src/uci.c | 14 +++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/makefile b/src/makefile index d2b610cf..b828a42a 100644 --- a/src/makefile +++ b/src/makefile @@ -40,6 +40,8 @@ nopopcnt: pext: $(CC) $(CFLAGS) $(SRC) $(LIBS) $(PEXTFLAGS) -o $(EXE) +android: + $(CCDROID) $(AFLAGS) $(SRC) $(LIBS) -o $(EXE)$(VER)-android release: mkdir ../dist $(CC) $(RFLAGS) $(SRC) $(LIBS) -o ../dist/$(EXE)$(VER)-x64-nopopcnt.exe diff --git a/src/search.c b/src/search.c index bc644c22..9fd01355 100644 --- a/src/search.c +++ b/src/search.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -47,7 +48,7 @@ int LMRTable[64][64]; // Late Move Reductions, LMRTable[depth][played] -volatile int ABORT_SIGNAL; // Global ABORT flag for threads +atomic_int ABORT_SIGNAL; // Global ABORT flag for threads pthread_mutex_t LOCK = PTHREAD_MUTEX_INITIALIZER; // Global LOCK for threads @@ -61,7 +62,7 @@ void initSearch(){ uint16_t getBestMove(Thread* threads, Board* board, Limits* limits){ - ABORT_SIGNAL = 0; // Clear the ABORT signal for the new search + atomic_store(&ABORT_SIGNAL, 0); // Clear the ABORT signal for the new search updateTT(); // Table is on a new search, thus a new generation @@ -193,7 +194,9 @@ void* iterativeDeepening(void* vthread){ break; } - if (mainThread) ABORT_SIGNAL = 1; + // Force shutdown of all other threads + if (mainThread) + atomic_store(&ABORT_SIGNAL, 1); return NULL; } @@ -284,7 +287,8 @@ int search(Thread* thread, PVariation* pv, int alpha, int beta, int depth, int h longjmp(thread->jbuffer, 1); // Step 1B. Check to see if the master thread finished - if (ABORT_SIGNAL) longjmp(thread->jbuffer, 1); + if (atomic_load_explicit(&ABORT_SIGNAL, memory_order_relaxed)) + longjmp(thread->jbuffer, 1); // Step 2. Check for early exit conditions, including the fifty move rule, // mate distance pruning, max depth exceeded, or drawn by repitition. We @@ -739,7 +743,8 @@ int qsearch(Thread* thread, PVariation* pv, int alpha, int beta, int height){ longjmp(thread->jbuffer, 1); // Step 1B. Check to see if the master thread finished - if (ABORT_SIGNAL) longjmp(thread->jbuffer, 1); + if (atomic_load_explicit(&ABORT_SIGNAL, memory_order_relaxed)) + longjmp(thread->jbuffer, 1); // Step 2. Max Draft Cutoff. If we are at the maximum search draft, // then end the search here with a static eval of the current board diff --git a/src/uci.c b/src/uci.c index 1e7b5635..dcc08774 100644 --- a/src/uci.c +++ b/src/uci.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -46,7 +47,7 @@ extern int MoveOverhead; // Defined by Time.c extern unsigned TB_PROBE_DEPTH; // Defined by Syzygy.c -extern volatile int ABORT_SIGNAL; // For killing active search +extern atomic_int ABORT_SIGNAL; // For killing active search pthread_mutex_t READYLOCK = PTHREAD_MUTEX_INITIALIZER; @@ -104,16 +105,15 @@ int main(int argc, char **argv) { } else if (stringEquals(str, "isready")){ - pthread_mutex_lock(&READYLOCK); printf("readyok\n"); fflush(stdout); - pthread_mutex_unlock(&READYLOCK); } else if (stringStartsWith(str, "setoption")){ if (stringStartsWith(str, "setoption name Hash value ")){ megabytes = atoi(str + strlen("setoption name Hash value ")); + megabytes = MAX(1, MIN(65536, megabytes)); initTT(megabytes); printf("info string set Hash to %dMB\n", megabytes); } @@ -121,12 +121,14 @@ int main(int argc, char **argv) { if (stringStartsWith(str, "setoption name Threads value ")){ free(threads); nthreads = atoi(str + strlen("setoption name Threads value ")); + nthreads = MAX(1, MIN(2048, nthreads)); threads = createThreadPool(nthreads); printf("info string set Threads to %d\n", nthreads); } if (stringStartsWith(str, "setoption name MoveOverhead value ")){ MoveOverhead = atoi(str + strlen("setoption name MoveOverhead value ")); + MoveOverhead = MAX(0, MIN(10000, MoveOverhead)); printf("info string set MoveOverhead to %d\n", MoveOverhead); } @@ -137,6 +139,7 @@ int main(int argc, char **argv) { if (stringStartsWith(str, "setoption name SyzygyProbeDepth value ")){ TB_PROBE_DEPTH = atoi(str + strlen("setoption name SyzygyProbeDepth value ")); + TB_PROBE_DEPTH = MIN(127, TB_PROBE_DEPTH); printf("info string set SyzygyProbeDepth to %u\n", TB_PROBE_DEPTH); } @@ -159,7 +162,7 @@ int main(int argc, char **argv) { } else if (stringEquals(str, "stop")){ - ABORT_SIGNAL = 1; + atomic_store(&ABORT_SIGNAL, 1); pthread_join(pthreadsgo, NULL); } @@ -297,7 +300,8 @@ void uciPosition(char* str, Board* board){ } // Skip over all white space - while (*ptr == ' ') ptr++; + while (*ptr == ' ' || *ptr == '\t' || *ptr == '\r' || *ptr == '\n') + ptr++; // Reset move history whenever we reset the fifty move rule if (board->fiftyMoveRule == 0) board->numMoves = 0;