From 8954b4b7eaafa8e306f2aa6cbb7e32334107e6e1 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 24 May 2024 22:20:00 +0200 Subject: Added table generation utility --- .gitignore | 5 +++++ Makefile | 8 +++++++- src/cube.h | 2 +- src/solve_generic.h | 26 ++++++++++++++++++-------- tables/tables.c | 34 ++++++++++++++++++++++++++++++++++ 5 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 tables/tables.c diff --git a/.gitignore b/.gitignore index 0191ea5..c676583 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ config.mk benchmark/results old/benchmark/results benchmark/run +gen +debuggen +perf.data +perf.data.old +tables/data/* test/*/runtest test/run test/last.* diff --git a/Makefile b/Makefile index a315476..f117b52 100644 --- a/Makefile +++ b/Makefile @@ -20,4 +20,10 @@ test: debugcube.o benchmark: cube.o CUBETYPE=${CUBETYPE} ./benchmark/bench.sh -.PHONY: all clean test benchmark +gen: cube.o + ${CC} ${CFLAGS} -o gen cube.o tables/tables.c + +debuggen: debugcube.o + ${CC} ${DBGFLAGS} -o debuggen debugcube.o tables/tables.c + +.PHONY: all clean test benchmark gen debuggen diff --git a/src/cube.h b/src/cube.h index 32547cf..694560a 100644 --- a/src/cube.h +++ b/src/cube.h @@ -161,4 +161,4 @@ void multisolve( /* Returns the number of bytes written to data, -1 in case of error. * TODO: write down how much memory every solver requires. */ -int64_t gendata(const char *solver, void *data); +int64_t gendata(const char *solver, const char *options, void *data); diff --git a/src/solve_generic.h b/src/solve_generic.h index 925aa33..6cdcc33 100644 --- a/src/solve_generic.h +++ b/src/solve_generic.h @@ -76,14 +76,6 @@ multisolve( } } -int64_t -gendata(const char *solver, void *data) -{ - DBG_LOG("gendata: not implemented yet\n"); - - return -1; -} - _static void solve_generic_appendsolution(dfsarg_generic_t *arg) { @@ -257,3 +249,21 @@ solve_simple( &estimate_simple ); } + +int64_t +gendata(const char *solver, const char *options, void *data) +{ + int64_t ret; + uint8_t maxdepth; + + if (!strcmp(solver, "H48")) { + /* TODO: write a generic parser for options */ + maxdepth = atoi(options); + ret = gendata_h48(data, 0, maxdepth); + } else { + DBG_LOG("gendata: implemented only for H48 solver\n"); + ret = -1; + } + + return ret; +} diff --git a/tables/tables.c b/tables/tables.c new file mode 100644 index 0000000..bd37831 --- /dev/null +++ b/tables/tables.c @@ -0,0 +1,34 @@ +#define _POSIX_C_SOURCE 200809L /* Required to use clock_gettime */ + +#include +#include +#include +#include +#include + +#include "../src/cube.h" + +#define SIZE_H1 118687270 + +char buf[SIZE_H1]; + +int main(int argc, char *argv[]) { + FILE *f; + struct timespec t0, t1; + double s; + + clock_gettime(CLOCK_MONOTONIC, &t0); + gendata("H48", argc > 1 ? argv[1] : "4", buf); + clock_gettime(CLOCK_MONOTONIC, &t1); + + if ((f = fopen("tables/data/h48_test", "wb")) == NULL) { + printf("Could not open file!\n"); + return 1; + } + fwrite(buf, SIZE_H1, 1, f); + + s = t1.tv_sec - t0.tv_sec + (t1.tv_nsec - t0.tv_nsec) / 1000000000.0; + printf("Data generated in %lfs\n", s); + + return 0; +} -- cgit v1.3