From 7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 29 Aug 2024 15:51:33 +0200 Subject: Refactor tools to remove duplicate code --- tools/002_stats_tables_h48/stats_tables_h48.c | 59 ++++----------------------- 1 file changed, 8 insertions(+), 51 deletions(-) (limited to 'tools/002_stats_tables_h48') diff --git a/tools/002_stats_tables_h48/stats_tables_h48.c b/tools/002_stats_tables_h48/stats_tables_h48.c index 2e48497..8b65862 100644 --- a/tools/002_stats_tables_h48/stats_tables_h48.c +++ b/tools/002_stats_tables_h48/stats_tables_h48.c @@ -1,22 +1,23 @@ #include -#include -#include "../timerun.h" -#include "../../src/nissy.h" + +#include "../tool.h" #define MAXMOVES 20 #define NTHREADS 32 #define NCUBES_PER_THREAD 10000 #define LOG_EVERY (NCUBES_PER_THREAD / 10) +const char *solver = "h48stats"; +const char *options = ""; +const char *filename = "tables/h48h0k4"; +char *buf; + typedef struct { int n; int thread_id; int64_t v[12][100]; } thread_arg_t; -const char *filename = "tables/h48h0k4"; -char *buf; - uint64_t rand64(void) { uint64_t i, ret; @@ -85,56 +86,12 @@ void run(void) { } } -int getdata(int64_t size) { - int64_t s; - FILE *f; - - buf = malloc(size); - - if ((f = fopen(filename, "rb")) == NULL) { - fprintf(stderr, "Table file not found, generating them." - " This can take a while.\n"); - s = nissy_gendata("h48stats", "", buf); - if (s != size) { - fprintf(stderr, "Error generating table"); - if (s != -1) - fprintf(stderr, " (got %" PRId64 " bytes)", s); - fprintf(stderr, "\n"); - return 1; - } - if ((f = fopen(filename, "wb")) == NULL) { - fprintf(stderr, "Could not write tables to file %s" - ", will be regenerated next time.\n", filename); - } else { - fwrite(buf, size, 1, f); - fclose(f); - } - } else { - fprintf(stderr, "Reading tables from file %s\n", filename); - fread(buf, size, 1, f); - fclose(f); - } - - return 0; -} - int main(void) { - int64_t size; - srand(time(NULL)); - nissy_setlogger(log_stderr); - size = nissy_datasize("h48stats", ""); - if (size == -1) { - printf("h48 stats: error in datasize\n"); - return 1; - } - if (getdata(size) != 0) { - printf("Error getting table, stopping\n"); - free(buf); + if (getdata(solver, options, &buf, filename) != 0) return 1; - } timerun(run, "h48 table stats"); -- cgit v1.3