Skip to content

Commit

Permalink
Update fengen
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonnold committed Feb 17, 2024
2 parents 9e7b0e9 + a255ae4 commit fe2a0f9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ dkms.conf
berserk
berserk-popcnt
.vscode
.idea
dist

*.log
Expand Down
1 change: 1 addition & 0 deletions src/delete-last-line.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sed -i '$ d' $1/*.fens
24 changes: 24 additions & 0 deletions src/fengen-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -uex

thread_count=$(($(nproc --all) - 1));
host_name=$(hostname | cut -c13-)
version=$(grep -Po '(?<=VERSION = )[\d]+' makefile)
network=$(grep -Po '(?<=MAIN_NETWORK = berserk-)[A-Za-z0-9]+(?=\.nn)' makefile)
file_name="berserk$version.$network.$host_name"

while true
do
./berserk --threads $thread_count \
--total 1000000 \
--output $1 \
--nodes 10000 \
--depth 0 \
--random-move-count 10 \
--random-move-min 1 \
--random-move-max 10 \
--random-multipv 0 \
--write-min 16 \
--file_name $file_name
done
21 changes: 8 additions & 13 deletions src/fengen/fengen.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ enum {

volatile int STOPPED = 0;

static void SigintHandler() {
printf("Ending games...\n");
STOPPED = 1;
}

char* NextPosition() {
pthread_mutex_lock(&book->mutex);
char* fen = book->fens[book->idx++];
Expand Down Expand Up @@ -135,9 +130,9 @@ void* PlayGames(void* arg) {

char filename[256];
if (fenGenParams.file_prefix[0]) {
sprintf(filename, "%s/%s_%d.fens", fenGenParams.dir, fenGenParams.file_prefix, idx);
sprintf(filename, "%s/%s.%d.fens", fenGenParams.dir, fenGenParams.file_prefix, idx);
} else {
sprintf(filename, "%s/berserk" VERSION "_%d.fens", fenGenParams.dir, idx);
sprintf(filename, "%s/berserk" VERSION ".%d.fens", fenGenParams.dir, idx);
}

FILE* fp = fopen(filename, "a");
Expand Down Expand Up @@ -233,8 +228,6 @@ void* PlayGames(void* arg) {
}

void Generate(uint64_t total) {
signal(SIGINT, SigintHandler);

int hashSize = 40.96 * Threads.count;
TTInit(hashSize);
printf("Initiating hash table to size: %d\n", hashSize);
Expand Down Expand Up @@ -268,19 +261,21 @@ void Generate(uint64_t total) {
for (int i = 0; i < Threads.count; i++)
pthread_create(&Threads.threads[i]->nativeThread, NULL, PlayGames, (void*) (intptr_t) i);

uint64_t generated = 0;
const int sleepInSeconds = 5;
uint64_t generated, last = 0;
while (!STOPPED) {
generated = 0;
for (int i = 0; i < Threads.count; i++)
generated += Threads.threads[i]->fens;

long elapsed = GetTimeMS() - startTime;
printf("Generated: %10lld [%6.2f/s] [%6lds]\n", generated, 1000.0 * generated / elapsed, elapsed / 1000);
long elapsed = Max(1, GetTimeMS() - startTime);
printf("Generated: %10lld [%8.2f/s] [%8.2f/s] [%8lds]\n", generated, 1000.0 * generated / elapsed, 1000.0 * (generated - last) / (sleepInSeconds * 1000.0), elapsed / 1000);

if (generated >= total)
break;

SleepInSeconds(5);
last = generated;
SleepInSeconds(sleepInSeconds);
}

STOPPED = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# General
EXE = berserk
SRC = *.c nn/*.c pyrrhic/tbprobe.c fengen/*.c
SRC = $(shell find {.,nn,fengen} -type f -name '*.c' -maxdepth 1) pyrrhic/tbprobe.c
CC = clang
VERSION = 20240215
MAIN_NETWORK = berserk-73e434fab450.nn
Expand Down

0 comments on commit fe2a0f9

Please sign in to comment.