#include "chess.h"
#include "data.h"
/* last modified 09/29/16 */
/*
*******************************************************************************
* *
* Bench() runs a 64 position benchmark during the build process. The test *
* positons are hard-coded. This is designed as a stand-alone benchmark to *
* comper different machines, or as a profile-guided-optimization test that *
* produces good profile data. *
* *
*******************************************************************************
*/
int Bench(int increase, int autotune) {
uint64_t nodes = 0;
int old_do, old_st, old_sd, total_time_used, pos, old_mt = smp_max_threads;
FILE *old_books, *old_book;
TREE *const tree = block[0];
char fen[64][80] = {
{"3q2k1/pb3p1p/4pbp1/2r5/PpN2N2/1P2P2P/5PP1/Q2R2K1 b"},
{"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b"},
{"3rr1k1/pp3pp1/1qn2np1/8/3p4/PP1R1P2/2P1NQPP/R1B3K1 b"},
{"4r1k1/r1q2ppp/ppp2n2/4P3/5Rb1/1N1BQ3/PPP3PP/R5K1 w"},
{"1r3k2/4q3/2Pp3b/3Bp3/2Q2p2/1p1P2P1/1P2KP2/3N4 w"},
{"3r1rk1/p5pp/bpp1pp2/8/q1PP1P2/b3P3/P2NQRPP/1R2B1K1 b"},
{"8/R7/2q5/8/6k1/8/1P5p/K6R w"},
{"2r3k1/1p2q1pp/2b1pr2/p1pp4/6Q1/1P1PP1R1/P1PN2PP/5RK1 w"},
{"4rrk1/pp1n3p/3q2pQ/2p1pb2/2PP4/2P3N1/P2B2PP/4RRK1 b"},
{"5r1k/6p/1n2Q2p/4p//7P/PP4PK/R1B1q/ w"},
{"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w"},
{"r1bqkb1r/4npp1/p1p4p/1p1pP1B1/8/1B6/PPPN1PPP/R2Q1RK1 w"},
{"7k/3p2pp/4q3/8/4Q3/5Kp1/P6b/8 w"},
{"2r1nrk1/p2q1ppp/bp1p4/n1pPp3/P1P1P3/2PBB1N1/4QPPP/R4RK1 w"},
{"8/3k4/8/8/8/4B3/4KB2/2B5 w"},
{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B2 b"},
{"1nk1r1r1/pp2n1pp/4p3/q2pPp1N/b1pP1P2/B1P2R2/2P1B1PP/R2Q2K1 w"},
{"2K5/p7/7P/5pR1/8/5k2/r7/8 w"},
{"3rr3/2pq2pk/p2p1pnp/8/2QBPP2/1P6/P5PP/4RRK1 b"},
{"r1b2rk1/2q1b1pp/p2ppn2/1p6/3QP3/1BN1B3/PPP3PP/R4RK1 w"},
{"8/8/8/8/5kp1/P7/8/1K1N4 w"},
{"r4k2/pb2bp1r/1p1qp2p/3pNp2/3P1P2/2N3P1/PPP1Q2P/2KRR3 w"},
{"r3k2r/p1ppqpb1/bn2pnp1/3PN3/1p2P3/2N2Q1p/PPPBBPPP/R3K2R w"}
};
int fen_depth = 16;
/*
************************************************************
* *
* Initialize. *
* *
************************************************************
*/
total_time_used = 0;
old_st = search_time_limit;
old_sd = search_depth;
old_do = display_options;
search_time_limit = 90000;
display_options = 1;
old_book = book_file;
book_file = 0;
old_books = books_file;
books_file = 0;
if (!autotune) {
if (increase)
Print(4095,
"Running serial benchmark (modifying depth by %d plies). . .\n",
increase);
else
Print(4095, "Running serial benchmark. . .\n");
}
/*
************************************************************
* *
* Now we loop through the 64 positions. We use the *
* ReadParse() procedure to break the FEN into tokens and *
* then call SetBoard() to set up the positions. Then a *
* call to Iterate() and we are done. *
* *
************************************************************
*/
for (pos = 0; pos < 64; pos++) {
nargs = ReadParse(buffer, args, " \t;=");
SetBoard(tree, nargs, args, 0);
search_depth = fen_depth + increase;
last_pv.pathd = 0;
thinking = 1;
tree->status[1] = tree->status[0];
InitializeHashTables(0);
Iterate(game_wtm, think, 0);
thinking = 0;
nodes += tree->nodes_searched;
total_time_used += (program_end_time - program_start_time);
nodes_per_second =
(uint64_t) tree->nodes_searched * 100 /
Max((uint64_t) program_end_time - program_start_time, 1);
if (pos % 7 == 0)
Print(4095, "pos: ");
Print(4095, "%2d(%s) ", pos + 1, DisplayKMB(nodes_per_second, 0));
if (pos % 7 == 6)
Print(4095, "\n");
}
/*
************************************************************
* *
* Serial benchmark done. Now dump the results. *
* *
************************************************************
*/
if (!autotune)
if (!autotune) {
Print(4095, "\nTotal nodes: %" PRIu64 "\n", nodes);
Print(4095, "Raw nodes per second: %d\n",
(int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
Print(4095, "Total elapsed time: %.2f\n\n",
((double) total_time_used / (double) 100.0));
}
/*
************************************************************
* *
* Now we repeat for two threads to provide PGO data for *
* the compiler. *
* *
************************************************************
*/
if (smp_max_threads == 0) {
smp_max_threads = 2;
Print(4095, "Running SMP benchmark (%d threads)...\n", smp_max_threads);
Print(4095, "pos: ");
for (pos = 0; pos < 2 && old_mt == 0; pos++) {
nargs = ReadParse(buffer, args, " \t;=");
SetBoard(tree, nargs, args, 0);
search_depth = fen_depth + increase;
last_pv.pathd = 0;
thinking = 1;
tree->status[1] = tree->status[0];
InitializeHashTables(0);
Iterate(game_wtm, think, 0);
thinking = 0;
nodes += tree->nodes_searched;
total_time_used += (program_end_time - program_start_time);
nodes_per_second =
(uint64_t) tree->nodes_searched * 100 /
Max((uint64_t) program_end_time - program_start_time, 1);
Print(4095, "%2d(%s) ", pos + 1, DisplayKMB(nodes_per_second, 0));
}
}
/*
************************************************************
* *
* Benchmark done. Now dump the results. *
* *
************************************************************
*/
if (!autotune)
if (!autotune && old_mt == 0) {
Print(4095, "\nTotal nodes: %" PRIu64 "\n", nodes);
Print(4095, "Raw nodes per second: %d\n",
(int) ((double) nodes / ((double) total_time_used / (double) 100.0)));
Print(4095, "Total elapsed time: %.2f\n\n",
((double) total_time_used / (double) 100.0));
}
input_stream = stdin;
early_exit = 99;
display_options = old_do;
search_time_limit = old_st;
search_depth = old_sd;
smp_max_threads = Max(0, old_mt);
books_file = old_books;
book_file = old_book;
InitializeChessBoard(tree);
return total_time_used;
}