From c4f64cf2556c0f8597e1fbc19d7c664b8da94612 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 11 Oct 2024 19:24:15 +0200 Subject: Added buffer sizes in API args --- tools/000_gendata/gendata.c | 6 +++--- tools/001_derive_h48/derive_h48.c | 3 +-- tools/100_checkdata/checkdata.c | 8 ++++---- tools/200_stats_tables_h48/stats_tables_h48.c | 12 ++++++++---- tools/300_solve_small/solve_small.c | 24 +++++++++++++----------- tools/tool.h | 7 ++++--- 6 files changed, 33 insertions(+), 27 deletions(-) (limited to 'tools') diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index eec9f76..0d647f9 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c @@ -17,8 +17,8 @@ run(void) { case -2: goto gendata_run_finish; default: - nissy_datainfo(buf, write_stdout); - consistent = nissy_checkdata(solver, buf) == 0; + nissy_datainfo(size, buf, write_stdout); + consistent = nissy_checkdata(size, buf) == 0; expected = check_distribution(solver, buf); if (consistent && expected) { printf("\n"); @@ -42,7 +42,7 @@ int main(int argc, char **argv) { uint8_t h, k; if (argc < 2) { - fprintf(stderr, "Error: not enough arguments. " + printf("Error: not enough arguments. " "A solver must be given.\n"); return 1; } diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c index c5f28c8..c964882 100644 --- a/tools/001_derive_h48/derive_h48.c +++ b/tools/001_derive_h48/derive_h48.c @@ -19,8 +19,7 @@ void run(void) { int main(int argc, char **argv) { if (argc < 5) { - fprintf(stderr, - "Error: not enough arguments. Required:\n" + printf("Error: not enough arguments. Required:\n" "1. Solver name for large table\n" "2. Solver name for derived table\n" "3. Filename containing large table\n" diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c index 695a4dd..2005f17 100644 --- a/tools/100_checkdata/checkdata.c +++ b/tools/100_checkdata/checkdata.c @@ -12,19 +12,19 @@ run(void) { size = nissy_datasize(solver); if (size <= 0) { - fprintf(stderr, "Error in datasize\n"); + printf("Error in datasize\n"); return; } if ((f = fopen(filename, "rb")) == NULL) { - fprintf(stderr, "Error reading file %s\n", filename); + printf("Error reading file %s\n", filename); return; } buf = malloc(size); fread(buf, size, 1, f); fclose(f); - result = nissy_checkdata(solver, buf); + result = nissy_checkdata(size, buf); free(buf); printf("checkdata %s\n", result == 0 ? "succeeded" : "failed"); @@ -34,7 +34,7 @@ run(void) { int main(int argc, char **argv) { if (argc < 3) { - fprintf(stderr, "Error: not enough arguments. " + printf("Error: not enough arguments. " "A solver and a file name must be given.\n"); return 1; } diff --git a/tools/200_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c index a9a2a1e..11df137 100644 --- a/tools/200_stats_tables_h48/stats_tables_h48.c +++ b/tools/200_stats_tables_h48/stats_tables_h48.c @@ -6,6 +6,7 @@ #define LOG_EVERY (NCUBES_PER_THREAD / 10) int NCUBES_PER_THREAD; +int64_t size = 0; const char *solver = "h48stats"; const char *filename = "tables/h48h0k4"; char *buf; @@ -40,11 +41,12 @@ run_thread(void *arg) cp = rand64(); co = rand64(); nissy_getcube(ep, eo, cp, co, "fix", cube); - nissy_solve(cube, "h48stats", "", 0, MAXMOVES, 1, -1, buf, s); + nissy_solve(cube, "h48stats", NISSY_NISSFLAG_NORMAL, + 0, MAXMOVES, 1, -1, size, buf, 12, s); for (j = 0; j < 12; j++) a->v[j][(int)s[j]]++; if ((i+1) % LOG_EVERY == 0) - fprintf(stderr, "[thread %d] %d cubes solved...\n", + printf("[thread %d] %d cubes solved...\n", a->thread_id, i+1); } @@ -57,6 +59,8 @@ void run(void) { pthread_t thread[THREADS]; thread_arg_t arg[THREADS]; + size = nissy_datasize(solver); + for (i = 0; i < THREADS; i++) { arg[i] = (thread_arg_t) { .thread_id = i, @@ -88,7 +92,7 @@ int main(int argc, char **argv) { nissy_setlogger(log_stderr); if (argc < 2) { - fprintf(stderr, "Error: not enough arguments. " + printf("Error: not enough arguments. " "Number of cubes per thread must be provided.\n"); return 1; } @@ -96,7 +100,7 @@ int main(int argc, char **argv) { NCUBES_PER_THREAD = atoi(argv[1]); if (NCUBES_PER_THREAD < 1 || NCUBES_PER_THREAD > 1000000) { - fprintf(stderr, "Invalid number of cubes: must be > 0 and " + printf("Invalid number of cubes: must be > 0 and " "< 1000000, but %d was given.\n", NCUBES_PER_THREAD); return 1; } diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index ade949a..5400436 100644 --- a/tools/300_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c @@ -1,6 +1,9 @@ #include "../tool.h" +#define SOL_BUFFER_LEN 1000 + const char *solver = "h48h0k4"; +int64_t size = 0; char *buf; char *scrambles[] = { @@ -14,25 +17,22 @@ char *scrambles[] = { void run(void) { int i; int64_t n; - char sol[100], cube[22]; + char sol[SOL_BUFFER_LEN], cube[22]; printf("Solved the following scrambles:\n\n"); for (i = 0; scrambles[i] != NULL; i++) { printf("%d. %s\n", i+1, scrambles[i]); - fprintf(stderr, "Solving scramble %s\n", scrambles[i]); + printf("Solving scramble %s\n", scrambles[i]); if (nissy_frommoves(scrambles[i], cube) == -1) { - fprintf(stderr, "Invalid scramble\n"); - printf("Invalid\n"); + printf("Invalid scramble\n"); continue; } - n = nissy_solve( - cube, solver, "", 0, 20, 1, -1, buf, sol); - if (n == 0) { - printf("No solution\n"); - fprintf(stderr, "No solution found\n"); - } else { + n = nissy_solve(cube, solver, NISSY_NISSFLAG_NORMAL, + 0, 20, 1, -1, size, buf, SOL_BUFFER_LEN, sol); + if (n == 0) + printf("No solution found\n"); + else printf("Solutions:\n%s\n", sol); - } } } @@ -46,6 +46,8 @@ int main(void) { if (getdata(solver, &buf, filename) != 0) return 1; + size = nissy_datasize(solver); + timerun(run); free(buf); diff --git a/tools/tool.h b/tools/tool.h index 02ff0f2..2fc0224 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -96,7 +96,7 @@ generatetable(const char *solver, char **buf) } *buf = malloc(size); - gensize = nissy_gendata(solver, *buf); + gensize = nissy_gendata(solver, size, *buf); if (gensize != size) { printf("Error generating table"); @@ -212,7 +212,7 @@ gendata_run( case -2: goto gendata_run_finish; default: - nissy_datainfo(buf, write_stdout); + nissy_datainfo(size, buf, write_stdout); printf("\n"); printf("Succesfully generated %" PRId64 " bytes. " "See above for details on the tables.\n", size); @@ -237,6 +237,7 @@ derivedata_run( int64_t size; char *buf; + buf = NULL; size = derivetable(solver_large, solver_small, filename_large, &buf); switch (size) { case -1: @@ -244,7 +245,7 @@ derivedata_run( case -2: goto derivedata_run_finish; default: - nissy_datainfo(buf, write_stdout); + nissy_datainfo(size, buf, write_stdout); printf("\n"); printf("Succesfully generated %" PRId64 " bytes. " "See above for details on the tables.\n", size); -- cgit v1.3