+ // print_pv_info() prints to standard output and eventually to log file information on
+ // the current PV line. It is called at each iteration or after a new pv is found.
+
+ void print_pv_info(const Position& pos, SearchStack* ss, Value alpha, Value beta, Value value) {
+
+ cout << "info depth " << Iteration
+ << " score " << value_to_string(value)
+ << ((value >= beta) ? " lowerbound" :
+ ((value <= alpha)? " upperbound" : ""))
+ << " time " << current_search_time()
+ << " nodes " << TM.nodes_searched()
+ << " nps " << nps()
+ << " pv ";
+
+ for (int j = 0; ss->pv[j] != MOVE_NONE && j < PLY_MAX; j++)
+ cout << ss->pv[j] << " ";
+
+ cout << endl;
+
+ if (UseLogFile)
+ {
+ ValueType type = (value >= beta ? VALUE_TYPE_LOWER
+ : (value <= alpha ? VALUE_TYPE_UPPER : VALUE_TYPE_EXACT));
+
+ LogFile << pretty_pv(pos, current_search_time(), Iteration,
+ TM.nodes_searched(), value, type, ss->pv) << endl;
+ }
+ }
+
+
+ // init_thread() is the function which is called when a new thread is
+ // launched. It simply calls the idle_loop() function with the supplied
+ // threadID. There are two versions of this function; one for POSIX
+ // threads and one for Windows threads.
+
+#if !defined(_MSC_VER)
+
+ void* init_thread(void *threadID) {
+
+ TM.idle_loop(*(int*)threadID, NULL);
+ return NULL;
+ }
+
+#else
+
+ DWORD WINAPI init_thread(LPVOID threadID) {
+
+ TM.idle_loop(*(int*)threadID, NULL);
+ return 0;
+ }
+
+#endif
+
+
+ /// The ThreadsManager class
+
+ // resetNodeCounters(), resetBetaCounters(), searched_nodes() and
+ // get_beta_counters() are getters/setters for the per thread
+ // counters used to sort the moves at root.
+
+ void ThreadsManager::resetNodeCounters() {
+
+ for (int i = 0; i < MAX_THREADS; i++)
+ threads[i].nodes = 0ULL;
+ }
+
+ void ThreadsManager::resetBetaCounters() {
+
+ for (int i = 0; i < MAX_THREADS; i++)
+ threads[i].betaCutOffs[WHITE] = threads[i].betaCutOffs[BLACK] = 0ULL;
+ }
+
+ int64_t ThreadsManager::nodes_searched() const {
+
+ int64_t result = 0ULL;
+ for (int i = 0; i < ActiveThreads; i++)
+ result += threads[i].nodes;
+
+ return result;
+ }
+
+ void ThreadsManager::get_beta_counters(Color us, int64_t& our, int64_t& their) const {
+
+ our = their = 0UL;
+ for (int i = 0; i < MAX_THREADS; i++)
+ {
+ our += threads[i].betaCutOffs[us];
+ their += threads[i].betaCutOffs[opposite_color(us)];
+ }
+ }
+
+