Projects
Games
togaII-142
togaII-142-set_nrthreads.patch
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File togaII-142-set_nrthreads.patch of Package togaII-142
diff -Naur src.orig//color.h src/color.h --- src.orig//color.h 1970-01-01 01:00:00.000000000 +0100 +++ src/color.h 2008-12-26 19:40:42.000000000 +0100 @@ -0,0 +1,22 @@ +// color.h + +#ifndef COLOUR_H + +#define COLOUR_H + +// macros + +#define COLOUR_IS_OK(color) (((color)&~1)==0) + +#define COLOUR_IS_WHITE(color) ((color)==0) +#define COLOUR_IS_BLACK(color) ((color)!=0) + +#define COLOUR_IS(piece,color) (FLAG_IS((piece),COLOUR_FLAG(color))) +#define FLAG_IS(piece,flag) (((piece)&(flag))!=0) + +#define COLOUR_OPP(color) ((color)^(0^1)) +#define COLOUR_FLAG(color) ((color)+1) + +#endif // !defined COLOUR_H + +// end of color.h diff -Naur src.orig//input.cpp src/input.cpp --- src.orig//input.cpp 1970-01-01 01:00:00.000000000 +0100 +++ src/input.cpp 2008-12-26 19:40:35.000000000 +0100 @@ -0,0 +1,165 @@ +// posix.cpp + +// includes + +#include <ctime> + +#if defined(_WIN32) || defined(_WIN64) +#include <windows.h> + +#else // assume POSIX +#include <sys/resource.h> +#include <sys/time.h> +#include <sys/types.h> +#include <unistd.h> + +#endif + +#include "input.h" +#include "util.h" + +// prototypes + +#if !defined(_WIN32) && !defined(_WIN64) + +static double duration(const struct timeval *tv); + +#endif + +// functions + +// input_available() + +bool input_available() + { +#if defined(_WIN32) || defined(_WIN64) + + static bool init = false, is_pipe; + static HANDLE stdin_h; + DWORD val; + + // val = 0; // needed to make the compiler happy? + + // have a look at the "local" buffer first, *this time before init (no idea if it helps)* + + if(stdin->_cnt > 0) + return true; + + // input init (only done once) + + if(!init) + { + + init = true; + + stdin_h = GetStdHandle(STD_INPUT_HANDLE); + + is_pipe = !GetConsoleMode(stdin_h, &val); + + if(!is_pipe) + { + SetConsoleMode(stdin_h, val & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)); + FlushConsoleInputBuffer(stdin_h); // no idea if we can lose data doing this + } + } + + // different polling depending on input type + // does this code work at all for pipes? + + if(is_pipe) + { + if(!PeekNamedPipe(stdin_h, NULL, 0, NULL, &val, NULL)) + { + return true; + } + + return val > 0; // != 0??? + } + else + { + + GetNumberOfConsoleInputEvents(stdin_h, &val); + return val > 1; + } + + return false; + +#else // assume POSIX + + int val; + fd_set set[1]; + struct timeval time_val[1]; + + FD_ZERO(set); + FD_SET(STDIN_FILENO, set); + + time_val->tv_sec = 0; + time_val->tv_usec = 0; + + val = select(STDIN_FILENO + 1, set, NULL, NULL, time_val); + + return val > 0; + +#endif + + } + +// now_real() + +double now_real() + { + +#if defined(_WIN32) || defined(_WIN64) + + return double(GetTickCount()) / 1000.0; + +#else // assume POSIX + + struct timeval tv[1]; + struct timezone tz[1]; + + tz->tz_minuteswest = 0; + tz->tz_dsttime = 0; // DST_NONE not declared in linux + + gettimeofday(tv, tz); + + return duration(tv); + +#endif + + } + +// now_cpu() + +double now_cpu() + { + +#if defined(_WIN32) || defined(_WIN64) + + return double(clock()) / double(CLOCKS_PER_SEC); // OK if CLOCKS_PER_SEC is small enough + +#else // assume POSIX + + struct rusage ru[1]; + + getrusage(RUSAGE_SELF, ru); + + return duration(&ru->ru_utime); + +#endif + + } + +// duration() + +#if !defined(_WIN32) && !defined(_WIN64) + +static double duration(const struct timeval *tv) + { + + return double(tv->tv_sec) + double(tv->tv_usec) * 1E-6; + } + +#endif + +// end of posix.cpp diff -Naur src.orig//input.h src/input.h --- src.orig//input.h 1970-01-01 01:00:00.000000000 +0100 +++ src/input.h 2008-12-26 19:40:36.000000000 +0100 @@ -0,0 +1,15 @@ +// input.h + +#ifndef POSIX_H + +#define POSIX_H + +// functions + +extern bool input_available(); +extern double now_real(); +extern double now_cpu(); + +#endif // !defined POSIX_H + +// end of input.h diff -Naur src.orig//main.h src/main.h --- src.orig//main.h 1970-01-01 01:00:00.000000000 +0100 +++ src/main.h 2008-12-26 19:40:36.000000000 +0100 @@ -0,0 +1,12 @@ +#ifndef MAIN_H_ + +#define MAIN_H_ + +//#define LOCK + +#pragma warning( disable : 4100 ) +// Level 4 unreferenced formal parameter -> input.cpp/egtb.cpp/tbdecode.h + +char file_name[256]; + +#endif // MAIN_H_ diff -Naur src.orig//Makefile src/Makefile --- src.orig//Makefile 2009-09-02 07:28:31.948056736 +0200 +++ src/Makefile 2008-12-26 21:52:55.000000000 +0100 @@ -18,13 +18,15 @@ # general -CXX = gcc +CXX = g++ CXXFLAGS = -pipe -LDFLAGS = -lm -ldl -lpthread +LDFLAGS = -lm +LDFLAGS += -ldl -lpthread # C++ CXXFLAGS += -O3 -fno-exceptions -fno-rtti -Wall +#CXXFLAGS += -mno-cygwin -D_WIN32 -D_MSC_VER # optimisation diff -Naur src.orig//material.cpp src/material.cpp --- src.orig//material.cpp 2008-01-31 00:43:08.000000000 +0100 +++ src/material.cpp 2008-12-26 20:13:34.000000000 +0100 @@ -126,6 +126,22 @@ } } +// material_free() + +void material_free() { + + int ThreadId; + + ASSERT(sizeof(entry_t)==16); + + if (UseTable) { + + for (ThreadId = 0; ThreadId < NumberThreads; ThreadId++){ + my_free(Material[ThreadId]->table); + } + } +} + // material_clear() void material_clear(int ThreadId) { diff -Naur src.orig//material.h src/material.h --- src.orig//material.h 2007-11-13 22:41:16.000000000 +0100 +++ src/material.h 2008-12-26 20:13:35.000000000 +0100 @@ -57,6 +57,7 @@ extern void material_parameter(); extern void material_alloc (); +extern void material_free (); extern void material_clear (int ThreadId); extern void material_get_info (material_info_t * info, const board_t * board, int ThreadId); diff -Naur src.orig//move_list.cpp src/move_list.cpp --- src.orig//move_list.cpp 1970-01-01 01:00:00.000000000 +0100 +++ src/move_list.cpp 2008-12-26 19:40:37.000000000 +0100 @@ -0,0 +1,145 @@ +// list.cpp + +// includes + +#include "move_list.h" +#include "move.h" + +// functions + +// list_is_ok() + +bool list_is_ok(const list_t *list) + { + if(list == NULL) + return false; + + if(list->size < 0 || list->size >= 256) + return false; + + return true; + } + +// list_remove() + +void list_remove(list_t *list, int pos) + { + + int i; + + for ( i = pos; i < list->size - 1; i++ ) + { + list->move[i] = list->move[i + 1]; + list->value[i] = list->value[i + 1]; + } + + list->size--; + } + +// list_copy() + +void list_copy(list_t *dst, const list_t *src) + { + + int i; + + dst->size = src->size; + + for ( i = 0; i < src->size; i++ ) + { + dst->move[i] = src->move[i]; + dst->value[i] = src->value[i]; + } + } + +// list_sort() + +void list_sort(list_t *list) + { + + int size; + int i, j; + int move, value; + + // init + + size = list->size; + list->value[size] = -32768; + + // insert sort (stable) + + for ( i = size - 2; i >= 0; i-- ) + { + + move = list->move[i]; + value = list->value[i]; + + for ( j = i; value < list->value[j + 1]; j++ ) + { + list->move[j] = list->move[j + 1]; + list->value[j] = list->value[j + 1]; + } + + list->move[j] = move; + list->value[j] = value; + } + } + +// list_contain() + +bool list_contain(const list_t *list, int move) + { + + int i; + + for ( i = 0; i < list->size; i++ ) + { + if(list->move[i] == move) + return true; + } + + return false; + } + +// list_note() + +void list_note(list_t *list) + { + + int i, move; + + for ( i = 0; i < list->size; i++ ) + { + move = list->move[i]; + list->value[i] = -move_order(move); + } + } + +// list_filter() + +void list_filter(list_t *list, board_t *board, move_test_t test, bool keep) + { + + int pos; + int i, move, value; + + pos = 0; + + for ( i = 0; i < LIST_SIZE(list); i++ ) + { + + move = LIST_MOVE(list, i); + value = LIST_VALUE(list, i); + + if((*test)(move,board) == keep) + { + list->move[pos] = move; + list->value[pos] = value; + pos++; + } + } + + list->size = pos; + } + +// end of list.cpp diff -Naur src.orig//move_list.h src/move_list.h --- src.orig//move_list.h 1970-01-01 01:00:00.000000000 +0100 +++ src/move_list.h 2008-12-26 19:40:38.000000000 +0100 @@ -0,0 +1,50 @@ +// move_list.h + +#ifndef LIST_H + +#define LIST_H + +// includes + +#include "board.h" + +// macros + +#define LIST_CLEAR(list) ((list)->size=0) +#define LIST_ADD(list,mv) ((list)->move[(list)->size++]=(mv)) + +#define LIST_IS_EMPTY(list) ((list)->size==0) +#define LIST_SIZE(list) ((list)->size) + +#define LIST_MOVE(list,pos) ((list)->move[pos]) +#define LIST_VALUE(list,pos) ((list)->value[pos]) + +// types + +struct list_t + { + int size; + uint16 move[256]; + sint16 value[256]; + }; + +typedef bool (*move_test_t) (int move, board_t * board); + +// functions + +extern bool list_is_ok(const list_t *list); + +extern void list_remove(list_t *list, int pos); + +extern void list_copy(list_t *dst, const list_t *src); + +extern void list_sort(list_t *list); + +extern bool list_contain(const list_t *list, int move); +extern void list_note(list_t *list); + +extern void list_filter(list_t *list, board_t *board, move_test_t test, bool keep); + +#endif // !defined LIST_H + +// end of move_list.h diff -Naur src.orig//pawn.cpp src/pawn.cpp --- src.orig//pawn.cpp 2008-01-14 17:49:48.000000000 +0100 +++ src/pawn.cpp 2008-12-26 20:13:32.000000000 +0100 @@ -212,6 +212,23 @@ } } +// pawn_free() + +void pawn_free() { + + int ThreadId; + + ASSERT(sizeof(entry_t)==16); + + if (UseTable) { + + for (ThreadId = 0; ThreadId < NumberThreads; ThreadId++){ + + my_free(Pawn[ThreadId]->table); + } + } +} + // pawn_clear() void pawn_clear(int ThreadId) { diff -Naur src.orig//pawn.h src/pawn.h --- src.orig//pawn.h 2007-11-13 22:37:36.000000000 +0100 +++ src/pawn.h 2008-12-26 20:13:38.000000000 +0100 @@ -54,6 +54,7 @@ extern void pawn_init (); extern void pawn_alloc (); +extern void pawn_free (); extern void pawn_clear (int ThreadId); extern void pawn_get_info (pawn_info_t * info, const board_t * board, int ThreadId); diff -Naur src.orig//protocol.cpp src/protocol.cpp --- src.orig//protocol.cpp 2009-09-02 07:27:47.536089363 +0200 +++ src/protocol.cpp 2008-12-26 21:59:25.000000000 +0100 @@ -605,6 +605,23 @@ trans_alloc(Trans); } } + + if (Init && my_string_equal(name,"Number of Threads")) { // Init => already started + + ASSERT(!Searching); + + if (option_get_int("Number of Threads")!= NumberThreads) { + exit_threads(); + pawn_free(); + material_free(); + NumberThreads=option_get_int("Number of Threads"); + if(NumberThreads>MaxThreads) NumberThreads=MaxThreads; + pawn_alloc(); + material_alloc(); + search_clear(); + start_suspend_threads(); + } + } } // send_best_move() diff -Naur src.orig//search.cpp src/search.cpp --- src.orig//search.cpp 2009-09-02 07:27:47.536089363 +0200 +++ src/search.cpp 2008-12-26 21:47:18.000000000 +0100 @@ -128,6 +128,7 @@ SearchInfo[ThreadId]->can_stop = false; SearchInfo[ThreadId]->stop = false; SearchInfo[ThreadId]->stopped = false; + SearchInfo[ThreadId]->exited = false; SearchInfo[ThreadId]->check_nb = 10000; // was 100000 SearchInfo[ThreadId]->check_inc = 10000; // was 100000 SearchInfo[ThreadId]->last_time = 0.0; @@ -213,6 +214,23 @@ } #endif +// exit_threads() + +void exit_threads() { + int ThreadId; + bool all_exited=false; + SearchInput->exit_engine=true; // hack + resume_threads(); + while (!all_exited){ + all_exited = true; + for (ThreadId = 1; ThreadId < NumberThreads; ThreadId++){ + if (!SearchInfo[ThreadId]->exited) + all_exited = false; + } + } + SearchInput->exit_engine=false; // hack +} + // search() @@ -304,13 +322,14 @@ unsigned __stdcall search_thread (void *param) { int ThreadId = *((int*)param); + SearchInfo[ThreadId]->exited= false; while (!SearchInput->exit_engine){ search_smp(ThreadId); SearchInfo[ThreadId]->stopped = true; SuspendThread(threat_handle[ThreadId-1]); } - + SearchInfo[ThreadId]->exited= true; _endthreadex( 0 ); return 0; } @@ -318,13 +337,14 @@ void * search_thread (void *param) { int ThreadId = *((int*)param); + SearchInfo[ThreadId]->exited= false; my_sem_wait(&(thread_runnable[ThreadId-1])); while (!SearchInput->exit_engine){ search_smp(ThreadId); SearchInfo[ThreadId]->stopped = true; my_sem_wait(&(thread_runnable[ThreadId-1])); } - + SearchInfo[ThreadId]->exited= true; return NULL; } #endif diff -Naur src.orig//search.h src/search.h --- src.orig//search.h 2009-09-02 07:27:47.536089363 +0200 +++ src/search.h 2008-12-26 20:13:31.000000000 +0100 @@ -67,6 +67,7 @@ bool can_stop; volatile bool stop; volatile bool stopped; + volatile bool exited; int check_nb; int check_inc; double last_time; @@ -132,6 +133,7 @@ extern void start_suspend_threads(); extern void resume_threads(); +extern void exit_threads(); #endif // !defined SEARCH_H diff -Naur src.orig//util.h src/util.h --- src.orig//util.h 2008-10-22 09:50:44.000000000 +0200 +++ src/util.h 2008-12-26 20:35:17.000000000 +0100 @@ -33,7 +33,7 @@ // macros -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__MINGW32__) # define S64(u) (u##i64) # define U64(u) (u##ui64) #else diff -Naur src.orig//values.h src/values.h --- src.orig//values.h 1970-01-01 01:00:00.000000000 +0100 +++ src/values.h 2008-12-26 19:40:30.000000000 +0100 @@ -0,0 +1,28 @@ +// values.h + +#ifndef VALUE_H + +#define VALUE_H + +// macros + +#define VALUE_MATE(height) (-30000+(height)) +#define VALUE_PIECE(piece) (value_piece[piece]) + +// variables + +extern int value_piece[256]; + +// functions + +extern void value_init(); +extern bool value_is_ok(int value); +extern bool range_is_ok(int min, int max); +extern bool value_is_mate(int value); +extern int value_to_trans(int value, int height); +extern int value_from_trans(int value, int height); +extern int value_to_mate(int value); + +#endif // !defined VALUE_H + +// end of values.h
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.