commit 8954b4b7eaafa8e306f2aa6cbb7e32334107e6e1
parent 8145e034184ed5807c00f05b90101090c6513a29
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Fri, 24 May 2024 22:20:00 +0200
Added table generation utility
Diffstat:
5 files changed, 65 insertions(+), 10 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,34 @@
+#define _POSIX_C_SOURCE 200809L /* Required to use clock_gettime */
+
+#include <inttypes.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#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;
+}