diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-10 14:30:39 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-10 14:30:39 +0200 |
| commit | f8d247c53c3c3bd94fed645b5b47a9096cadc123 (patch) | |
| tree | 7a62cc7322ea8175a7df9b655d4a9d5e026a004a /tools | |
| parent | 2e93de4ad102973961cb24d5b91f0c299763299f (diff) | |
| download | nissy-core-f8d247c53c3c3bd94fed645b5b47a9096cadc123.tar.gz nissy-core-f8d247c53c3c3bd94fed645b5b47a9096cadc123.zip | |
Removed "options" from solver selection
Now the solver name fully determines the solver (and options)
to be used. For example, now one must specify "h48h0k4" as the
name of the solver.
This PR also fixes a couple of things in tools.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/000_gendata/gendata.c | 23 | ||||
| -rw-r--r-- | tools/001_derive_h48/derive_h48.c | 12 | ||||
| -rw-r--r-- | tools/100_checkdata/checkdata.c | 17 | ||||
| -rw-r--r-- | tools/200_stats_tables_h48/stats_tables_h48.c | 30 | ||||
| -rw-r--r-- | tools/300_solve_small/solve_small.c | 11 | ||||
| -rw-r--r-- | tools/expected_distributions.h | 2 | ||||
| -rw-r--r-- | tools/nissy_extra.h | 2 | ||||
| -rw-r--r-- | tools/tool.h | 88 | ||||
| -rwxr-xr-x | tools/tool.sh | 3 |
9 files changed, 101 insertions, 87 deletions
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c index 2798862..eec9f76 100644 --- a/tools/000_gendata/gendata.c +++ b/tools/000_gendata/gendata.c | |||
| @@ -1,16 +1,16 @@ | |||
| 1 | #include "../tool.h" | 1 | #include "../tool.h" |
| 2 | #include "../expected_distributions.h" | 2 | #include "../expected_distributions.h" |
| 3 | 3 | ||
| 4 | char *solver, *options; | 4 | char *solver; |
| 5 | uint64_t *expected; | 5 | uint64_t *expected; |
| 6 | 6 | ||
| 7 | static void | 7 | static void |
| 8 | run(void) { | 8 | run(void) { |
| 9 | int64_t size; | 9 | int64_t size; |
| 10 | bool consistent, expected; | ||
| 10 | char *buf, filename[1024]; | 11 | char *buf, filename[1024]; |
| 11 | 12 | ||
| 12 | getfilename(solver, options, filename); | 13 | size = generatetable(solver, &buf); |
| 13 | size = generatetable(solver, options, &buf); | ||
| 14 | switch (size) { | 14 | switch (size) { |
| 15 | case -1: | 15 | case -1: |
| 16 | return; | 16 | return; |
| @@ -18,11 +18,19 @@ run(void) { | |||
| 18 | goto gendata_run_finish; | 18 | goto gendata_run_finish; |
| 19 | default: | 19 | default: |
| 20 | nissy_datainfo(buf, write_stdout); | 20 | nissy_datainfo(buf, write_stdout); |
| 21 | if (check_distribution(solver, buf)) { | 21 | consistent = nissy_checkdata(solver, buf) == 0; |
| 22 | expected = check_distribution(solver, buf); | ||
| 23 | if (consistent && expected) { | ||
| 22 | printf("\n"); | 24 | printf("\n"); |
| 23 | printf("Generated %" PRId64 " bytes.\n", size); | 25 | printf("Generated %" PRId64 " bytes.\n", size); |
| 26 | sprintf(filename, "tables/%s", solver); | ||
| 24 | writetable(buf, size, filename); | 27 | writetable(buf, size, filename); |
| 25 | } | 28 | } |
| 29 | if (!consistent) | ||
| 30 | printf("Error: table is not consistent with info" | ||
| 31 | " (nissy_checkdata() failed)\n"); | ||
| 32 | if (!expected) | ||
| 33 | printf("Error: distribution is not as expected\n"); | ||
| 26 | break; | 34 | break; |
| 27 | } | 35 | } |
| 28 | 36 | ||
| @@ -33,15 +41,14 @@ gendata_run_finish: | |||
| 33 | int main(int argc, char **argv) { | 41 | int main(int argc, char **argv) { |
| 34 | uint8_t h, k; | 42 | uint8_t h, k; |
| 35 | 43 | ||
| 36 | if (argc < 3) { | 44 | if (argc < 2) { |
| 37 | fprintf(stderr, "Error: not enough arguments. " | 45 | fprintf(stderr, "Error: not enough arguments. " |
| 38 | "A solver and its options must be given.\n"); | 46 | "A solver must be given.\n"); |
| 39 | return 1; | 47 | return 1; |
| 40 | } | 48 | } |
| 41 | 49 | ||
| 42 | solver = argv[1]; | 50 | solver = argv[1]; |
| 43 | options = argv[2]; | 51 | parse_h48_solver(solver, &h, &k); |
| 44 | parse_h48_options(options, &h, &k, NULL); | ||
| 45 | expected = expected_h48[h][k]; | 52 | expected = expected_h48[h][k]; |
| 46 | 53 | ||
| 47 | nissy_setlogger(log_stderr); | 54 | nissy_setlogger(log_stderr); |
diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c index ba282ff..c5f28c8 100644 --- a/tools/001_derive_h48/derive_h48.c +++ b/tools/001_derive_h48/derive_h48.c | |||
| @@ -11,25 +11,25 @@ edit the base value in the source code and recompile. | |||
| 11 | 11 | ||
| 12 | #include "../tool.h" | 12 | #include "../tool.h" |
| 13 | 13 | ||
| 14 | char *opts_large, *opts_small, *filename_large, *filename_small; | 14 | char *solver_large, *solver_small, *filename_large, *filename_small; |
| 15 | 15 | ||
| 16 | void run(void) { | 16 | void run(void) { |
| 17 | derivedata_run(opts_large, opts_small, filename_large, filename_small); | 17 | derivedata_run(solver_large, solver_small, filename_large, filename_small); |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | int main(int argc, char **argv) { | 20 | int main(int argc, char **argv) { |
| 21 | if (argc < 5) { | 21 | if (argc < 5) { |
| 22 | fprintf(stderr, | 22 | fprintf(stderr, |
| 23 | "Error: not enough arguments. Required:\n" | 23 | "Error: not enough arguments. Required:\n" |
| 24 | "1. Options for large table\n" | 24 | "1. Solver name for large table\n" |
| 25 | "2. Options for derived table\n" | 25 | "2. Solver name for derived table\n" |
| 26 | "3. Filename containing large table\n" | 26 | "3. Filename containing large table\n" |
| 27 | "4. Filename for saving derived table\n"); | 27 | "4. Filename for saving derived table\n"); |
| 28 | return 1; | 28 | return 1; |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | opts_large = argv[1]; | 31 | solver_large = argv[1]; |
| 32 | opts_small = argv[2]; | 32 | solver_small = argv[2]; |
| 33 | filename_large = argv[3]; | 33 | filename_large = argv[3]; |
| 34 | filename_small = argv[4]; | 34 | filename_small = argv[4]; |
| 35 | 35 | ||
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c index 502925f..695a4dd 100644 --- a/tools/100_checkdata/checkdata.c +++ b/tools/100_checkdata/checkdata.c | |||
| @@ -1,15 +1,15 @@ | |||
| 1 | #include "../tool.h" | 1 | #include "../tool.h" |
| 2 | #include "../expected_distributions.h" | 2 | #include "../expected_distributions.h" |
| 3 | 3 | ||
| 4 | char *solver, *options, *filename; | 4 | char *solver, *filename; |
| 5 | 5 | ||
| 6 | static void | 6 | static void |
| 7 | run(void) { | 7 | run(void) { |
| 8 | int64_t size; | 8 | int64_t size, result; |
| 9 | char *buf; | 9 | char *buf; |
| 10 | FILE *f; | 10 | FILE *f; |
| 11 | 11 | ||
| 12 | size = nissy_datasize(solver, options); | 12 | size = nissy_datasize(solver); |
| 13 | 13 | ||
| 14 | if (size <= 0) { | 14 | if (size <= 0) { |
| 15 | fprintf(stderr, "Error in datasize\n"); | 15 | fprintf(stderr, "Error in datasize\n"); |
| @@ -24,22 +24,23 @@ run(void) { | |||
| 24 | buf = malloc(size); | 24 | buf = malloc(size); |
| 25 | fread(buf, size, 1, f); | 25 | fread(buf, size, 1, f); |
| 26 | fclose(f); | 26 | fclose(f); |
| 27 | nissy_checkdata(solver, options, buf); | 27 | result = nissy_checkdata(solver, buf); |
| 28 | free(buf); | 28 | free(buf); |
| 29 | 29 | ||
| 30 | printf("checkdata %s\n", result == 0 ? "succeeded" : "failed"); | ||
| 31 | |||
| 30 | /* TODO: cross-check with expected distributions? */ | 32 | /* TODO: cross-check with expected distributions? */ |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | int main(int argc, char **argv) { | 35 | int main(int argc, char **argv) { |
| 34 | if (argc < 4) { | 36 | if (argc < 3) { |
| 35 | fprintf(stderr, "Error: not enough arguments. " | 37 | fprintf(stderr, "Error: not enough arguments. " |
| 36 | "A solver, its options and a file name must be given.\n"); | 38 | "A solver and a file name must be given.\n"); |
| 37 | return 1; | 39 | return 1; |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | solver = argv[1]; | 42 | solver = argv[1]; |
| 41 | options = argv[2]; | 43 | filename = argv[2]; |
| 42 | filename = argv[3]; | ||
| 43 | nissy_setlogger(log_stderr); | 44 | nissy_setlogger(log_stderr); |
| 44 | 45 | ||
| 45 | timerun(run); | 46 | timerun(run); |
diff --git a/tools/200_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c index ea5fa5a..a9a2a1e 100644 --- a/tools/200_stats_tables_h48/stats_tables_h48.c +++ b/tools/200_stats_tables_h48/stats_tables_h48.c | |||
| @@ -3,11 +3,10 @@ | |||
| 3 | #include "../tool.h" | 3 | #include "../tool.h" |
| 4 | 4 | ||
| 5 | #define MAXMOVES 20 | 5 | #define MAXMOVES 20 |
| 6 | #define NCUBES_PER_THREAD 10000 | ||
| 7 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) | 6 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) |
| 8 | 7 | ||
| 8 | int NCUBES_PER_THREAD; | ||
| 9 | const char *solver = "h48stats"; | 9 | const char *solver = "h48stats"; |
| 10 | const char *options = ""; | ||
| 11 | const char *filename = "tables/h48h0k4"; | 10 | const char *filename = "tables/h48h0k4"; |
| 12 | char *buf; | 11 | char *buf; |
| 13 | 12 | ||
| @@ -29,7 +28,7 @@ uint64_t rand64(void) { | |||
| 29 | static void * | 28 | static void * |
| 30 | run_thread(void *arg) | 29 | run_thread(void *arg) |
| 31 | { | 30 | { |
| 32 | char sols[12], cube[22]; | 31 | char s[12], cube[22]; |
| 33 | int64_t ep, eo, cp, co; | 32 | int64_t ep, eo, cp, co; |
| 34 | int i, j; | 33 | int i, j; |
| 35 | 34 | ||
| @@ -41,10 +40,9 @@ run_thread(void *arg) | |||
| 41 | cp = rand64(); | 40 | cp = rand64(); |
| 42 | co = rand64(); | 41 | co = rand64(); |
| 43 | nissy_getcube(ep, eo, cp, co, "fix", cube); | 42 | nissy_getcube(ep, eo, cp, co, "fix", cube); |
| 44 | nissy_solve(cube, "h48stats", "", "", | 43 | nissy_solve(cube, "h48stats", "", 0, MAXMOVES, 1, -1, buf, s); |
| 45 | 0, MAXMOVES, 1, -1, buf, sols); | ||
| 46 | for (j = 0; j < 12; j++) | 44 | for (j = 0; j < 12; j++) |
| 47 | a->v[j][(int)sols[j]]++; | 45 | a->v[j][(int)s[j]]++; |
| 48 | if ((i+1) % LOG_EVERY == 0) | 46 | if ((i+1) % LOG_EVERY == 0) |
| 49 | fprintf(stderr, "[thread %d] %d cubes solved...\n", | 47 | fprintf(stderr, "[thread %d] %d cubes solved...\n", |
| 50 | a->thread_id, i+1); | 48 | a->thread_id, i+1); |
| @@ -85,11 +83,27 @@ void run(void) { | |||
| 85 | } | 83 | } |
| 86 | } | 84 | } |
| 87 | 85 | ||
| 88 | int main(void) { | 86 | int main(int argc, char **argv) { |
| 89 | srand(time(NULL)); | 87 | srand(time(NULL)); |
| 90 | nissy_setlogger(log_stderr); | 88 | nissy_setlogger(log_stderr); |
| 91 | 89 | ||
| 92 | if (getdata(solver, options, &buf, filename) != 0) | 90 | if (argc < 2) { |
| 91 | fprintf(stderr, "Error: not enough arguments. " | ||
| 92 | "Number of cubes per thread must be provided.\n"); | ||
| 93 | return 1; | ||
| 94 | } | ||
| 95 | |||
| 96 | NCUBES_PER_THREAD = atoi(argv[1]); | ||
| 97 | |||
| 98 | if (NCUBES_PER_THREAD < 1 || NCUBES_PER_THREAD > 1000000) { | ||
| 99 | fprintf(stderr, "Invalid number of cubes: must be > 0 and " | ||
| 100 | "< 1000000, but %d was given.\n", NCUBES_PER_THREAD); | ||
| 101 | return 1; | ||
| 102 | } | ||
| 103 | |||
| 104 | printf("Using %d cubes per thread (%d total)\n", | ||
| 105 | NCUBES_PER_THREAD, NCUBES_PER_THREAD * THREADS); | ||
| 106 | if (getdata(solver, &buf, filename) != 0) | ||
| 93 | return 1; | 107 | return 1; |
| 94 | 108 | ||
| 95 | timerun(run); | 109 | timerun(run); |
diff --git a/tools/300_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index b572cf5..ade949a 100644 --- a/tools/300_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c | |||
| @@ -1,8 +1,6 @@ | |||
| 1 | #include "../tool.h" | 1 | #include "../tool.h" |
| 2 | 2 | ||
| 3 | const char *solver = "h48"; | 3 | const char *solver = "h48h0k4"; |
| 4 | const char *options = "0;4;20"; | ||
| 5 | const char *filename = "tables/h48h0k4"; | ||
| 6 | char *buf; | 4 | char *buf; |
| 7 | 5 | ||
| 8 | char *scrambles[] = { | 6 | char *scrambles[] = { |
| @@ -28,7 +26,7 @@ void run(void) { | |||
| 28 | continue; | 26 | continue; |
| 29 | } | 27 | } |
| 30 | n = nissy_solve( | 28 | n = nissy_solve( |
| 31 | cube, "h48", options, "", 0, 20, 1, -1, buf, sol); | 29 | cube, solver, "", 0, 20, 1, -1, buf, sol); |
| 32 | if (n == 0) { | 30 | if (n == 0) { |
| 33 | printf("No solution\n"); | 31 | printf("No solution\n"); |
| 34 | fprintf(stderr, "No solution found\n"); | 32 | fprintf(stderr, "No solution found\n"); |
| @@ -39,10 +37,13 @@ void run(void) { | |||
| 39 | } | 37 | } |
| 40 | 38 | ||
| 41 | int main(void) { | 39 | int main(void) { |
| 40 | char filename[255]; | ||
| 41 | |||
| 42 | srand(time(NULL)); | 42 | srand(time(NULL)); |
| 43 | nissy_setlogger(log_stderr); | 43 | nissy_setlogger(log_stderr); |
| 44 | 44 | ||
| 45 | if (getdata(solver, options, &buf, filename) != 0) | 45 | sprintf(filename, "tables/%s", solver); |
| 46 | if (getdata(solver, &buf, filename) != 0) | ||
| 46 | return 1; | 47 | return 1; |
| 47 | 48 | ||
| 48 | timerun(run); | 49 | timerun(run); |
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h index 202edf9..1b97166 100644 --- a/tools/expected_distributions.h +++ b/tools/expected_distributions.h | |||
| @@ -155,7 +155,7 @@ check_distribution(const char *solver, const void *data) | |||
| 155 | { | 155 | { |
| 156 | tableinfo_t info = {0}; | 156 | tableinfo_t info = {0}; |
| 157 | 157 | ||
| 158 | if (!strcmp(solver, "h48")) { | 158 | if (!strncmp(solver, "h48", 3)) { |
| 159 | readtableinfo(data, &info); | 159 | readtableinfo(data, &info); |
| 160 | if (!distribution_equal( | 160 | if (!distribution_equal( |
| 161 | expected_cocsep, info.distribution, info.maxvalue)) { | 161 | expected_cocsep, info.distribution, info.maxvalue)) { |
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h index f9baf00..53c3df7 100644 --- a/tools/nissy_extra.h +++ b/tools/nissy_extra.h | |||
| @@ -9,4 +9,4 @@ for testing purposes only. | |||
| 9 | #include "../src/solvers/tables.h" | 9 | #include "../src/solvers/tables.h" |
| 10 | 10 | ||
| 11 | size_t gendata_h48_derive(uint8_t, const void *, void *); | 11 | size_t gendata_h48_derive(uint8_t, const void *, void *); |
| 12 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 12 | int parse_h48_solver(const char *, uint8_t [static 1], uint8_t [static 1]); |
diff --git a/tools/tool.h b/tools/tool.h index 2aaabae..02ff0f2 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -12,12 +12,11 @@ | |||
| 12 | static void log_stderr(const char *, ...); | 12 | static void log_stderr(const char *, ...); |
| 13 | static void log_stdout(const char *, ...); | 13 | static void log_stdout(const char *, ...); |
| 14 | static double timerun(void (*)(void)); | 14 | static double timerun(void (*)(void)); |
| 15 | static void getfilename(const char *, const char *, char *); | ||
| 16 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 17 | static int64_t generatetable(const char *, const char *, char **); | 16 | static int64_t generatetable(const char *, char **); |
| 18 | static int64_t derivetable(const char *, const char *, const char *, char **); | 17 | static int64_t derivetable(const char *, const char *, const char *, char **); |
| 19 | static int getdata(const char *, const char *, char **, const char *); | 18 | static int getdata(const char *, char **, const char *); |
| 20 | static void gendata_run(const char *, const char *, uint64_t[static 21]); | 19 | static void gendata_run(const char *, uint64_t[static 21]); |
| 21 | static void derivedata_run( | 20 | static void derivedata_run( |
| 22 | const char *, const char *, const char *, const char *); | 21 | const char *, const char *, const char *, const char *); |
| 23 | 22 | ||
| @@ -71,50 +70,39 @@ timerun(void (*run)(void)) | |||
| 71 | } | 70 | } |
| 72 | 71 | ||
| 73 | static void | 72 | static void |
| 74 | getfilename(const char *solver, const char *options, char *filename) | ||
| 75 | { | ||
| 76 | uint8_t h, k; | ||
| 77 | |||
| 78 | /* Only h48 supported for now */ | ||
| 79 | parse_h48_options(options, &h, &k, NULL); | ||
| 80 | |||
| 81 | sprintf(filename, "tables/%sh%dk%d", solver, h, k); | ||
| 82 | } | ||
| 83 | |||
| 84 | static void | ||
| 85 | writetable(const char *buf, int64_t size, const char *filename) | 73 | writetable(const char *buf, int64_t size, const char *filename) |
| 86 | { | 74 | { |
| 87 | FILE *f; | 75 | FILE *f; |
| 88 | 76 | ||
| 89 | if ((f = fopen(filename, "wb")) == NULL) { | 77 | if ((f = fopen(filename, "wb")) == NULL) { |
| 90 | fprintf(stderr, "Could not write tables to file %s" | 78 | printf("Could not write tables to file %s" |
| 91 | ", will be regenerated next time.\n", filename); | 79 | ", will be regenerated next time.\n", filename); |
| 92 | } else { | 80 | } else { |
| 93 | fwrite(buf, size, 1, f); | 81 | fwrite(buf, size, 1, f); |
| 94 | fclose(f); | 82 | fclose(f); |
| 95 | fprintf(stderr, "Table written to %s.\n", filename); | 83 | printf("Table written to %s.\n", filename); |
| 96 | } | 84 | } |
| 97 | } | 85 | } |
| 98 | 86 | ||
| 99 | static int64_t | 87 | static int64_t |
| 100 | generatetable(const char *solver, const char *options, char **buf) | 88 | generatetable(const char *solver, char **buf) |
| 101 | { | 89 | { |
| 102 | int64_t size, gensize; | 90 | int64_t size, gensize; |
| 103 | 91 | ||
| 104 | size = nissy_datasize(solver, options); | 92 | size = nissy_datasize(solver); |
| 105 | if (size == -1) { | 93 | if (size == -1) { |
| 106 | printf("Error getting table size.\n"); | 94 | printf("Error getting table size.\n"); |
| 107 | return -1; | 95 | return -1; |
| 108 | } | 96 | } |
| 109 | 97 | ||
| 110 | *buf = malloc(size); | 98 | *buf = malloc(size); |
| 111 | gensize = nissy_gendata(solver, options, *buf); | 99 | gensize = nissy_gendata(solver, *buf); |
| 112 | 100 | ||
| 113 | if (gensize != size) { | 101 | if (gensize != size) { |
| 114 | fprintf(stderr, "Error generating table"); | 102 | printf("Error generating table"); |
| 115 | if (gensize != -1) | 103 | if (gensize != -1) |
| 116 | fprintf(stderr, " (got %" PRId64 " bytes)", gensize); | 104 | printf(" (got %" PRId64 " bytes)", gensize); |
| 117 | fprintf(stderr, "\n"); | 105 | printf("\n"); |
| 118 | return -2; | 106 | return -2; |
| 119 | } | 107 | } |
| 120 | 108 | ||
| @@ -123,46 +111,53 @@ generatetable(const char *solver, const char *options, char **buf) | |||
| 123 | 111 | ||
| 124 | static int64_t | 112 | static int64_t |
| 125 | derivetable( | 113 | derivetable( |
| 126 | const char *opts_large, | 114 | const char *solver_large, |
| 127 | const char *opts_small, | 115 | const char *solver_small, |
| 128 | const char *filename_large, | 116 | const char *filename_large, |
| 129 | char **buf | 117 | char **buf |
| 130 | ) | 118 | ) |
| 131 | { | 119 | { |
| 132 | uint8_t h; | 120 | uint8_t h, k; |
| 133 | int64_t size, gensize; | 121 | int64_t size, gensize; |
| 134 | char *fulltable; | 122 | char *fulltable; |
| 135 | 123 | ||
| 136 | if (getdata("h48", opts_large, &fulltable, filename_large) != 0) { | 124 | if (getdata(solver_large, &fulltable, filename_large) != 0) { |
| 137 | printf("Error reading full table.\n"); | 125 | printf("Error reading full table.\n"); |
| 138 | return -1; | 126 | gensize = -1; |
| 127 | goto derivetable_error_nofree; | ||
| 139 | } | 128 | } |
| 140 | 129 | ||
| 141 | size = nissy_datasize("h48", opts_small); | 130 | size = nissy_datasize(solver_small); |
| 142 | if (size == -1) { | 131 | if (size == -1) { |
| 143 | printf("Error getting table size.\n"); | 132 | printf("Error getting table size.\n"); |
| 144 | free(fulltable); | 133 | gensize = -2; |
| 145 | return -1; | 134 | goto derivetable_error; |
| 135 | } | ||
| 136 | |||
| 137 | if (parse_h48_solver(solver_small, &h, &k) != 0) { | ||
| 138 | gensize = -3; | ||
| 139 | goto derivetable_error; | ||
| 146 | } | 140 | } |
| 147 | 141 | ||
| 148 | h = atoi(opts_small); /* TODO: use option parser */ | ||
| 149 | *buf = malloc(size); | 142 | *buf = malloc(size); |
| 150 | gensize = gendata_h48_derive(h, fulltable, *buf); | 143 | gensize = gendata_h48_derive(h, fulltable, *buf); |
| 151 | 144 | ||
| 152 | if (gensize != size) { | 145 | if (gensize != size) { |
| 153 | fprintf(stderr, "Error deriving table\n"); | 146 | printf("Error deriving table\n"); |
| 154 | free(fulltable); | 147 | gensize = -4; |
| 155 | return -2; | 148 | goto derivetable_error; |
| 156 | } | 149 | } |
| 157 | 150 | ||
| 151 | derivetable_error: | ||
| 158 | free(fulltable); | 152 | free(fulltable); |
| 153 | |||
| 154 | derivetable_error_nofree: | ||
| 159 | return gensize; | 155 | return gensize; |
| 160 | } | 156 | } |
| 161 | 157 | ||
| 162 | static int | 158 | static int |
| 163 | getdata( | 159 | getdata( |
| 164 | const char *solver, | 160 | const char *solver, |
| 165 | const char *options, | ||
| 166 | char **buf, | 161 | char **buf, |
| 167 | const char *filename | 162 | const char *filename |
| 168 | ) { | 163 | ) { |
| @@ -170,8 +165,8 @@ getdata( | |||
| 170 | FILE *f; | 165 | FILE *f; |
| 171 | 166 | ||
| 172 | if ((f = fopen(filename, "rb")) == NULL) { | 167 | if ((f = fopen(filename, "rb")) == NULL) { |
| 173 | fprintf(stderr, "Table file not found, generating it.\n"); | 168 | printf("Table file not found, generating it.\n"); |
| 174 | size = generatetable(solver, options, buf); | 169 | size = generatetable(solver, buf); |
| 175 | switch (size) { | 170 | switch (size) { |
| 176 | case -1: | 171 | case -1: |
| 177 | goto getdata_error_nofree; | 172 | goto getdata_error_nofree; |
| @@ -182,13 +177,13 @@ getdata( | |||
| 182 | break; | 177 | break; |
| 183 | } | 178 | } |
| 184 | } else { | 179 | } else { |
| 185 | fprintf(stderr, "Reading tables from file %s\n", filename); | 180 | printf("Reading tables from file %s\n", filename); |
| 186 | size = nissy_datasize(solver, options); | 181 | size = nissy_datasize(solver); |
| 187 | *buf = malloc(size); | 182 | *buf = malloc(size); |
| 188 | sizeread = fread(*buf, size, 1, f); | 183 | sizeread = fread(*buf, size, 1, f); |
| 189 | fclose(f); | 184 | fclose(f); |
| 190 | if (sizeread != 1) { | 185 | if (sizeread != 1) { |
| 191 | fprintf(stderr, "Error reading table, stopping\n"); | 186 | printf("Error reading table, stopping\n"); |
| 192 | goto getdata_error; | 187 | goto getdata_error; |
| 193 | } | 188 | } |
| 194 | } | 189 | } |
| @@ -204,14 +199,13 @@ getdata_error_nofree: | |||
| 204 | static void | 199 | static void |
| 205 | gendata_run( | 200 | gendata_run( |
| 206 | const char *solver, | 201 | const char *solver, |
| 207 | const char *options, | ||
| 208 | uint64_t expected[static 21] | 202 | uint64_t expected[static 21] |
| 209 | ) { | 203 | ) { |
| 210 | int64_t size; | 204 | int64_t size; |
| 211 | char *buf, filename[1024]; | 205 | char *buf, filename[1024]; |
| 212 | 206 | ||
| 213 | getfilename(solver, options, filename); | 207 | sprintf(filename, "tables/%s", solver); |
| 214 | size = generatetable(solver, options, &buf); | 208 | size = generatetable(solver, &buf); |
| 215 | switch (size) { | 209 | switch (size) { |
| 216 | case -1: | 210 | case -1: |
| 217 | return; | 211 | return; |
| @@ -234,8 +228,8 @@ gendata_run_finish: | |||
| 234 | 228 | ||
| 235 | static void | 229 | static void |
| 236 | derivedata_run( | 230 | derivedata_run( |
| 237 | const char *opts_large, | 231 | const char *solver_large, |
| 238 | const char *opts_small, | 232 | const char *solver_small, |
| 239 | const char *filename_large, | 233 | const char *filename_large, |
| 240 | const char *filename_small | 234 | const char *filename_small |
| 241 | ) | 235 | ) |
| @@ -243,7 +237,7 @@ derivedata_run( | |||
| 243 | int64_t size; | 237 | int64_t size; |
| 244 | char *buf; | 238 | char *buf; |
| 245 | 239 | ||
| 246 | size = derivetable(opts_large, opts_small, filename_large, &buf); | 240 | size = derivetable(solver_large, solver_small, filename_large, &buf); |
| 247 | switch (size) { | 241 | switch (size) { |
| 248 | case -1: | 242 | case -1: |
| 249 | return; | 243 | return; |
diff --git a/tools/tool.sh b/tools/tool.sh index 23d781d..aea203f 100755 --- a/tools/tool.sh +++ b/tools/tool.sh | |||
| @@ -29,15 +29,12 @@ date +'%Y-%m-%d %H:%M' | |||
| 29 | echo "" | 29 | echo "" |
| 30 | echo "======== config.mk ========" | 30 | echo "======== config.mk ========" |
| 31 | cat config.mk | 31 | cat config.mk |
| 32 | echo "===========================" | ||
| 33 | echo "" | 32 | echo "" |
| 34 | echo "=== tool configuration ====" | 33 | echo "=== tool configuration ====" |
| 35 | echo "TOOL=$toolname" | 34 | echo "TOOL=$toolname" |
| 36 | echo "TOOLARGS=$TOOLARGS" | 35 | echo "TOOLARGS=$TOOLARGS" |
| 37 | echo "CC=$CC" | 36 | echo "CC=$CC" |
| 38 | echo "===========================" | ||
| 39 | echo "" | 37 | echo "" |
| 40 | echo "======= tool output =======" | 38 | echo "======= tool output =======" |
| 41 | $BIN $TOOLARGS | 39 | $BIN $TOOLARGS |
| 42 | echo "===========================" | ||
| 43 | ) | tee "$file" "$LAST" | 40 | ) | tee "$file" "$LAST" |
