diff options
28 files changed, 279 insertions, 295 deletions
| @@ -10,6 +10,7 @@ test/*/runtest | |||
| 10 | test/run | 10 | test/run |
| 11 | test/run.DSYM | 11 | test/run.DSYM |
| 12 | run.DSYM | 12 | run.DSYM |
| 13 | run.core | ||
| 13 | test/last.* | 14 | test/last.* |
| 14 | tools/results | 15 | tools/results |
| 15 | .vscode | 16 | .vscode |
| @@ -61,7 +61,7 @@ The results of the last test case run is saved in test/last.out (standard | |||
| 61 | output, the results compared with the .out files) and test/last.err | 61 | output, the results compared with the .out files) and test/last.err |
| 62 | (standard error). | 62 | (standard error). |
| 63 | 63 | ||
| 64 | Tests are always run in "debug mode": this means that optimizations are | 64 | Tests are always run in debug mode: this means that optimizations are |
| 65 | disabled and some extra logging is enabled. | 65 | disabled and some extra logging is enabled. |
| 66 | 66 | ||
| 67 | See the test folder and test/test.sh for details. | 67 | See the test folder and test/test.sh for details. |
| @@ -70,7 +70,7 @@ See the test folder and test/test.sh for details. | |||
| 70 | 70 | ||
| 71 | In the tools folder there are some small programs that test various | 71 | In the tools folder there are some small programs that test various |
| 72 | functionality of the H48 library. They work similarly to test, but they | 72 | functionality of the H48 library. They work similarly to test, but they |
| 73 | are not run in debug mode. | 73 | are not run in debug mode by default. |
| 74 | 74 | ||
| 75 | To run a tool you must select it with the environment variable `TOOL`. | 75 | To run a tool you must select it with the environment variable `TOOL`. |
| 76 | For example the command: | 76 | For example the command: |
| @@ -79,14 +79,26 @@ For example the command: | |||
| 79 | TOOL=stats make tool | 79 | TOOL=stats make tool |
| 80 | ``` | 80 | ``` |
| 81 | 81 | ||
| 82 | Will run the stats_tables_h48 tool. Like for tests, the value of the | 82 | Will run the stats_tables_h48 tool. |
| 83 | `TOOL` variable can be any regular expression matching the name of the | 83 | |
| 84 | tool. Unlike tests, one and only one tool will be selected for each run. | 84 | To pass some arguments to a tool, use the `TOOLARGS` variable: |
| 85 | |||
| 86 | ``` | ||
| 87 | TOOL=gendata TOOLARGS="h48 0;2;20" make tool | ||
| 88 | ``` | ||
| 89 | |||
| 90 | Like for tests, the value of the `TOOL` variable can be any regular | ||
| 91 | expression matching the name of the tool. Unlike tests, one and | ||
| 92 | only one tool will be selected for each run. The content of the | ||
| 93 | `TOOLARGS` variable is used directly as command line arguments for | ||
| 94 | the chosen tool. | ||
| 85 | 95 | ||
| 86 | Each tool run is automatically timed, so these tools can be used as | 96 | Each tool run is automatically timed, so these tools can be used as |
| 87 | benchmark. The output as well as the time of the run are saved to a | 97 | benchmark. The output as well as the time of the run are saved to a |
| 88 | file in the tools/results folder. | 98 | file in the tools/results folder. |
| 89 | 99 | ||
| 100 | To build and run a tool in debug mode, use `make debugtool`. | ||
| 101 | |||
| 90 | ## Running commands manually | 102 | ## Running commands manually |
| 91 | 103 | ||
| 92 | This project also includes a rudimentary shell that can be used to run | 104 | This project also includes a rudimentary shell that can be used to run |
diff --git a/src/nissy.c b/src/nissy.c index 6bc4aea..953471f 100644 --- a/src/nissy.c +++ b/src/nissy.c | |||
| @@ -11,8 +11,11 @@ | |||
| 11 | 11 | ||
| 12 | #include "nissy.h" | 12 | #include "nissy.h" |
| 13 | 13 | ||
| 14 | STATIC int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | 14 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); |
| 15 | STATIC int64_t write_result(cube_t, char [static 22]); | 15 | STATIC int64_t write_result(cube_t, char [static 22]); |
| 16 | STATIC bool distribution_equal( | ||
| 17 | const uint64_t [static 21], const uint64_t [static 21], uint8_t); | ||
| 18 | STATIC bool checkdata(const void *, const tableinfo_t *); | ||
| 16 | 19 | ||
| 17 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ | 20 | /* TODO: add option to get DR, maybe C-only, E-only, eo... */ |
| 18 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } | 21 | #define GETCUBE_OPTIONS(S, F) { .option = S, .fix = F } |
| @@ -24,7 +27,7 @@ struct { | |||
| 24 | GETCUBE_OPTIONS(NULL, NULL) | 27 | GETCUBE_OPTIONS(NULL, NULL) |
| 25 | }; | 28 | }; |
| 26 | 29 | ||
| 27 | STATIC int | 30 | int |
| 28 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) | 31 | parse_h48_options(const char *buf, uint8_t *h, uint8_t *k, uint8_t *maxdepth) |
| 29 | { | 32 | { |
| 30 | bool h_valid, k_valid, maxdepth_valid; | 33 | bool h_valid, k_valid, maxdepth_valid; |
| @@ -62,6 +65,52 @@ parse_h48_options_error: | |||
| 62 | return -1; | 65 | return -1; |
| 63 | } | 66 | } |
| 64 | 67 | ||
| 68 | STATIC bool | ||
| 69 | checkdata(const void *buf, const tableinfo_t *info) | ||
| 70 | { | ||
| 71 | uint64_t distr[21]; | ||
| 72 | |||
| 73 | if (!strncmp(info->solver, "cocsep", 6)) { | ||
| 74 | getdistribution_cocsep( | ||
| 75 | (uint32_t *)((char *)buf + INFOSIZE), distr); | ||
| 76 | } else if (!strncmp(info->solver, "h48", 3)) { | ||
| 77 | getdistribution_h48((uint8_t *)buf + INFOSIZE, distr, | ||
| 78 | info->h48h, info->bits); | ||
| 79 | } else { | ||
| 80 | LOG("checkdata: unknown solver %s\n", info->solver); | ||
| 81 | return false; | ||
| 82 | } | ||
| 83 | |||
| 84 | return distribution_equal(info->distribution, distr, info->maxvalue); | ||
| 85 | } | ||
| 86 | |||
| 87 | STATIC bool | ||
| 88 | distribution_equal( | ||
| 89 | const uint64_t expected[static 21], | ||
| 90 | const uint64_t actual[static 21], | ||
| 91 | uint8_t maxvalue | ||
| 92 | ) | ||
| 93 | { | ||
| 94 | int wrong; | ||
| 95 | uint8_t i; | ||
| 96 | |||
| 97 | for (i = 0, wrong = 0; i <= MAX(maxvalue, 20); i++) { | ||
| 98 | if (expected[i] != actual[i]) { | ||
| 99 | wrong++; | ||
| 100 | LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %" | ||
| 101 | PRIu64 "\n", i, expected[i], actual[i]); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | if (wrong > 0) { | ||
| 106 | LOG("checkdata: %d wrong values\n", wrong); | ||
| 107 | } else { | ||
| 108 | LOG("checkdata: table is consistent with info\n"); | ||
| 109 | } | ||
| 110 | |||
| 111 | return wrong > 0; | ||
| 112 | } | ||
| 113 | |||
| 65 | STATIC int64_t | 114 | STATIC int64_t |
| 66 | write_result(cube_t cube, char result[static 22]) | 115 | write_result(cube_t cube, char result[static 22]) |
| 67 | { | 116 | { |
| @@ -275,6 +324,23 @@ nissy_gendata( | |||
| 275 | } | 324 | } |
| 276 | 325 | ||
| 277 | int64_t | 326 | int64_t |
| 327 | nissy_checkdata( | ||
| 328 | const char *solver, | ||
| 329 | const char *options, | ||
| 330 | const void *data | ||
| 331 | ) | ||
| 332 | { | ||
| 333 | char *buf; | ||
| 334 | tableinfo_t info; | ||
| 335 | |||
| 336 | for (buf = (char *)data; readtableinfo(buf, &info); buf += info.next) | ||
| 337 | if (!checkdata(buf, &info)) | ||
| 338 | return 1; | ||
| 339 | |||
| 340 | return 0; | ||
| 341 | } | ||
| 342 | |||
| 343 | int64_t | ||
| 278 | nissy_solve( | 344 | nissy_solve( |
| 279 | const char cube[static 22], | 345 | const char cube[static 22], |
| 280 | const char *solver, | 346 | const char *solver, |
diff --git a/src/nissy.h b/src/nissy.h index 63e7a90..0545556 100644 --- a/src/nissy.h +++ b/src/nissy.h | |||
| @@ -93,6 +93,12 @@ int64_t nissy_derivedata( | |||
| 93 | void *generated_data | 93 | void *generated_data |
| 94 | ); | 94 | ); |
| 95 | 95 | ||
| 96 | int64_t nissy_checkdata( | ||
| 97 | const char *solver, | ||
| 98 | const char *options, | ||
| 99 | const void *data | ||
| 100 | ); | ||
| 101 | |||
| 96 | /* Print information on a data table via the provided callback writer */ | 102 | /* Print information on a data table via the provided callback writer */ |
| 97 | int64_t nissy_datainfo( | 103 | int64_t nissy_datainfo( |
| 98 | const void *table, | 104 | const void *table, |
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index 2189145..262793b 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h | |||
| @@ -25,6 +25,7 @@ STATIC_INLINE void set_visited(uint8_t *, int64_t); | |||
| 25 | 25 | ||
| 26 | STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); | 26 | STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); |
| 27 | STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); | 27 | STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); |
| 28 | STATIC void getdistribution_cocsep(const uint32_t *, uint64_t [static 21]); | ||
| 28 | 29 | ||
| 29 | STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); | 30 | STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); |
| 30 | 31 | ||
| @@ -157,6 +158,17 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) | |||
| 157 | return cc; | 158 | return cc; |
| 158 | } | 159 | } |
| 159 | 160 | ||
| 161 | STATIC void | ||
| 162 | getdistribution_cocsep(const uint32_t *table, uint64_t distr[static 21]) | ||
| 163 | { | ||
| 164 | size_t i; | ||
| 165 | |||
| 166 | memset(distr, 0, 21 * sizeof(uint64_t)); | ||
| 167 | |||
| 168 | for (i = 0; i < COCSEP_TABLESIZE; i++) | ||
| 169 | distr[CBOUND(table[i])]++; | ||
| 170 | } | ||
| 171 | |||
| 160 | STATIC_INLINE bool | 172 | STATIC_INLINE bool |
| 161 | get_visited(const uint8_t *a, int64_t i) | 173 | get_visited(const uint8_t *a, int64_t i) |
| 162 | { | 174 | { |
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index a88eb4f..48d5582 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -104,13 +104,16 @@ STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); | |||
| 104 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); | 104 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); |
| 105 | STATIC void * gendata_h48k2_runthread(void *); | 105 | STATIC void * gendata_h48k2_runthread(void *); |
| 106 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); | 106 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); |
| 107 | STATIC void getdistribution_h48( | ||
| 108 | const uint8_t *, uint64_t [static 21], uint8_t, uint8_t); | ||
| 107 | 109 | ||
| 108 | STATIC uint32_t *get_cocsepdata_ptr(const void *); | 110 | STATIC uint32_t *get_cocsepdata_ptr(const void *); |
| 109 | STATIC uint8_t *get_h48data_ptr(const void *); | 111 | STATIC uint8_t *get_h48data_ptr(const void *); |
| 110 | 112 | ||
| 111 | STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); | 113 | STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); |
| 112 | STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); | 114 | STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); |
| 113 | STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); | 115 | STATIC_INLINE uint8_t get_h48_bound( |
| 116 | cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); | ||
| 114 | 117 | ||
| 115 | size_t gendata_h48_derive(uint8_t, const void *, void *); | 118 | size_t gendata_h48_derive(uint8_t, const void *, void *); |
| 116 | 119 | ||
| @@ -665,6 +668,25 @@ makeinfo_h48k2(gendata_h48_arg_t *arg) | |||
| 665 | return info; | 668 | return info; |
| 666 | } | 669 | } |
| 667 | 670 | ||
| 671 | STATIC void | ||
| 672 | getdistribution_h48( | ||
| 673 | const uint8_t *table, | ||
| 674 | uint64_t distr[static 21], | ||
| 675 | uint8_t h, | ||
| 676 | uint8_t k | ||
| 677 | ) { | ||
| 678 | uint8_t val; | ||
| 679 | int64_t i, h48max; | ||
| 680 | |||
| 681 | memset(distr, 0, 21 * sizeof(uint64_t)); | ||
| 682 | |||
| 683 | h48max = H48_COORDMAX(h); | ||
| 684 | for (i = 0; i < h48max; i++) { | ||
| 685 | val = get_h48_pval(table, i, k); | ||
| 686 | distr[val]++; | ||
| 687 | } | ||
| 688 | } | ||
| 689 | |||
| 668 | STATIC uint32_t * | 690 | STATIC uint32_t * |
| 669 | get_cocsepdata_ptr(const void *data) | 691 | get_cocsepdata_ptr(const void *data) |
| 670 | { | 692 | { |
diff --git a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c index 41ab10a..c37de3e 100644 --- a/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c +++ b/test/120_gendata_h48h0k4/gendata_h48h0k4_tests.c | |||
| @@ -24,6 +24,7 @@ typedef struct { | |||
| 24 | typedef struct { | 24 | typedef struct { |
| 25 | uint8_t h; | 25 | uint8_t h; |
| 26 | uint8_t k; | 26 | uint8_t k; |
| 27 | uint8_t base; | ||
| 27 | uint8_t maxdepth; | 28 | uint8_t maxdepth; |
| 28 | tableinfo_t info; | 29 | tableinfo_t info; |
| 29 | void *buf; | 30 | void *buf; |
diff --git a/tools/0002_gendata_h48h0k2/gendata_h48h0k2.c b/tools/0002_gendata_h48h0k2/gendata_h48h0k2.c deleted file mode 100644 index 14f99ee..0000000 --- a/tools/0002_gendata_h48h0k2/gendata_h48h0k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 5473562, | ||
| 6 | [1] = 34776317, | ||
| 7 | [2] = 68566704, | ||
| 8 | [3] = 8750867, | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "0;2;20", "tables/h48h0k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 0, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0004_gendata_h48h0k4/gendata_h48h0k4.c b/tools/0004_gendata_h48h0k4/gendata_h48h0k4.c deleted file mode 100644 index ff34bb9..0000000 --- a/tools/0004_gendata_h48h0k4/gendata_h48h0k4.c +++ /dev/null | |||
| @@ -1,29 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | [0] = 1, | ||
| 5 | [1] = 1, | ||
| 6 | [2] = 4, | ||
| 7 | [3] = 34, | ||
| 8 | [4] = 331, | ||
| 9 | [5] = 3612, | ||
| 10 | [6] = 41605, | ||
| 11 | [7] = 474128, | ||
| 12 | [8] = 4953846, | ||
| 13 | [9] = 34776317, | ||
| 14 | [10] = 68566704, | ||
| 15 | [11] = 8749194, | ||
| 16 | [12] = 1673, | ||
| 17 | }; | ||
| 18 | |||
| 19 | void run(void) { | ||
| 20 | gendata_run("h48", "0;4;20", "tables/h48h0k4", expected); | ||
| 21 | } | ||
| 22 | |||
| 23 | int main(void) { | ||
| 24 | nissy_setlogger(log_stderr); | ||
| 25 | |||
| 26 | timerun(run, "benchmark gendata_h48 h = 0, k = 4"); | ||
| 27 | |||
| 28 | return 0; | ||
| 29 | } | ||
diff --git a/tools/000_gendata/gendata.c b/tools/000_gendata/gendata.c new file mode 100644 index 0000000..90166dd --- /dev/null +++ b/tools/000_gendata/gendata.c | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | #include "../expected_distributions.h" | ||
| 3 | |||
| 4 | char *solver, *options; | ||
| 5 | uint64_t *expected; | ||
| 6 | |||
| 7 | static void | ||
| 8 | run(void) { | ||
| 9 | int64_t size; | ||
| 10 | char *buf, filename[1024]; | ||
| 11 | |||
| 12 | getfilename(solver, options, filename); | ||
| 13 | size = generatetable(solver, options, &buf); | ||
| 14 | switch (size) { | ||
| 15 | case -1: | ||
| 16 | return; | ||
| 17 | case -2: | ||
| 18 | goto gendata_run_finish; | ||
| 19 | default: | ||
| 20 | nissy_datainfo(buf, write_stdout); | ||
| 21 | printf("\n"); | ||
| 22 | printf("Succesfully generated %" PRId64 " bytes. " | ||
| 23 | "See above for details on the tables.\n", size); | ||
| 24 | |||
| 25 | writetable(buf, size, filename); | ||
| 26 | break; | ||
| 27 | } | ||
| 28 | |||
| 29 | gendata_run_finish: | ||
| 30 | free(buf); | ||
| 31 | } | ||
| 32 | |||
| 33 | int main(int argc, char **argv) { | ||
| 34 | uint8_t h, k; | ||
| 35 | char description[256]; | ||
| 36 | |||
| 37 | if (argc < 3) { | ||
| 38 | fprintf(stderr, "Error: not enough arguments. " | ||
| 39 | "A solver and its options must be given.\n"); | ||
| 40 | return 1; | ||
| 41 | } | ||
| 42 | |||
| 43 | solver = argv[1]; | ||
| 44 | options = argv[2]; | ||
| 45 | parse_h48_options(options, &h, &k, NULL); | ||
| 46 | expected = expected_h48[h][k]; | ||
| 47 | sprintf(description, "benchmark gendata_h48 h = %" PRIu8 | ||
| 48 | ", k = %" PRIu8 "", h, k); | ||
| 49 | |||
| 50 | nissy_setlogger(log_stderr); | ||
| 51 | |||
| 52 | timerun(run, description); | ||
| 53 | |||
| 54 | return 0; | ||
| 55 | } | ||
diff --git a/tools/0012_gendata_h48h1k2/gendata_h48h1k2.c b/tools/0012_gendata_h48h1k2/gendata_h48h1k2.c deleted file mode 100644 index 0ebdcaa..0000000 --- a/tools/0012_gendata_h48h1k2/gendata_h48h1k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "1;2;20", "tables/h48h1k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 1, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0022_gendata_h48h2k2/gendata_h48h2k2.c b/tools/0022_gendata_h48h2k2/gendata_h48h2k2.c deleted file mode 100644 index f437e98..0000000 --- a/tools/0022_gendata_h48h2k2/gendata_h48h2k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "2;2;20", "tables/h48h2k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 2, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0032_gendata_h48h3k2/gendata_h48h3k2.c b/tools/0032_gendata_h48h3k2/gendata_h48h3k2.c deleted file mode 100644 index 2e0eab5..0000000 --- a/tools/0032_gendata_h48h3k2/gendata_h48h3k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "3;2;20", "tables/h48h3k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 3, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0042_gendata_h48h4k2/gendata_h48h4k2.c b/tools/0042_gendata_h48h4k2/gendata_h48h4k2.c deleted file mode 100644 index 868c360..0000000 --- a/tools/0042_gendata_h48h4k2/gendata_h48h4k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "4;2;20", "tables/h48h4k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 4, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0052_gendata_h48h5k2/gendata_h48h5k2.c b/tools/0052_gendata_h48h5k2/gendata_h48h5k2.c deleted file mode 100644 index d292d49..0000000 --- a/tools/0052_gendata_h48h5k2/gendata_h48h5k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "5;2;20", "tables/h48h5k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 5, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0062_gendata_h48h6k2/gendata_h48h6k2.c b/tools/0062_gendata_h48h6k2/gendata_h48h6k2.c deleted file mode 100644 index 910d514..0000000 --- a/tools/0062_gendata_h48h6k2/gendata_h48h6k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "6;2;20", "tables/h48h6k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 6, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0072_gendata_h48h7k2/gendata_h48h7k2.c b/tools/0072_gendata_h48h7k2/gendata_h48h7k2.c deleted file mode 100644 index b803328..0000000 --- a/tools/0072_gendata_h48h7k2/gendata_h48h7k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "7;2;20", "tables/h48h7k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 7, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0082_gendata_h48h8k2/gendata_h48h8k2.c b/tools/0082_gendata_h48h8k2/gendata_h48h8k2.c deleted file mode 100644 index 52c377a..0000000 --- a/tools/0082_gendata_h48h8k2/gendata_h48h8k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "8;2;20", "tables/h48h8k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 8, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0092_gendata_h48h9k2/gendata_h48h9k2.c b/tools/0092_gendata_h48h9k2/gendata_h48h9k2.c deleted file mode 100644 index 5d3e34a..0000000 --- a/tools/0092_gendata_h48h9k2/gendata_h48h9k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "9;2;20", "tables/h48h9k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 9, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0102_gendata_h48h10k2/gendata_h48h10k2.c b/tools/0102_gendata_h48h10k2/gendata_h48h10k2.c deleted file mode 100644 index 5e8fbb0..0000000 --- a/tools/0102_gendata_h48h10k2/gendata_h48h10k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "10;2;20", "tables/h48h10k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 10, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/0112_gendata_h48h11k2/gendata_h48h11k2.c b/tools/0112_gendata_h48h11k2/gendata_h48h11k2.c deleted file mode 100644 index 00c0747..0000000 --- a/tools/0112_gendata_h48h11k2/gendata_h48h11k2.c +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | |||
| 3 | uint64_t expected[21] = { | ||
| 4 | /* Base value is 8 */ | ||
| 5 | [0] = 0, /* Unknown */ | ||
| 6 | [1] = 0, /* Unknown */ | ||
| 7 | [2] = 0, /* Unknown */ | ||
| 8 | [3] = 0, /* Unknown */ | ||
| 9 | }; | ||
| 10 | |||
| 11 | void run(void) { | ||
| 12 | gendata_run("h48", "11;2;20", "tables/h48h11k2", expected); | ||
| 13 | } | ||
| 14 | |||
| 15 | int main(void) { | ||
| 16 | nissy_setlogger(log_stderr); | ||
| 17 | |||
| 18 | timerun(run, "benchmark gendata_h48 h = 11, k = 2"); | ||
| 19 | |||
| 20 | return 0; | ||
| 21 | } | ||
diff --git a/tools/100_checkdata/checkdata.c b/tools/100_checkdata/checkdata.c new file mode 100644 index 0000000..05961c1 --- /dev/null +++ b/tools/100_checkdata/checkdata.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | #include "../tool.h" | ||
| 2 | #include "../expected_distributions.h" | ||
| 3 | |||
| 4 | char *solver, *options, *filename; | ||
| 5 | |||
| 6 | static void | ||
| 7 | run(void) { | ||
| 8 | int64_t size; | ||
| 9 | char *buf; | ||
| 10 | FILE *f; | ||
| 11 | |||
| 12 | size = nissy_datasize(solver, options); | ||
| 13 | |||
| 14 | if (size <= 0) { | ||
| 15 | fprintf(stderr, "Error in datasize\n"); | ||
| 16 | return; | ||
| 17 | } | ||
| 18 | |||
| 19 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 20 | fprintf(stderr, "Error reading file %s\n", filename); | ||
| 21 | return; | ||
| 22 | } | ||
| 23 | |||
| 24 | buf = malloc(size); | ||
| 25 | fread(buf, size, 1, f); | ||
| 26 | fclose(f); | ||
| 27 | nissy_checkdata(solver, options, buf); | ||
| 28 | free(buf); | ||
| 29 | |||
| 30 | /* TODO: cross-check with expected distributions? */ | ||
| 31 | } | ||
| 32 | |||
| 33 | int main(int argc, char **argv) { | ||
| 34 | char description[256]; | ||
| 35 | |||
| 36 | if (argc < 4) { | ||
| 37 | fprintf(stderr, "Error: not enough arguments. " | ||
| 38 | "A solver, its options and a file name must be given.\n"); | ||
| 39 | return 1; | ||
| 40 | } | ||
| 41 | |||
| 42 | solver = argv[1]; | ||
| 43 | options = argv[2]; | ||
| 44 | filename = argv[3]; | ||
| 45 | sprintf(description, "checking data for solver %s" | ||
| 46 | "with options %s from file %s", solver, options, filename); | ||
| 47 | nissy_setlogger(log_stderr); | ||
| 48 | |||
| 49 | timerun(run, description); | ||
| 50 | |||
| 51 | return 0; | ||
| 52 | } | ||
diff --git a/tools/100_stats_tables_h48/stats_tables_h48.c b/tools/200_stats_tables_h48/stats_tables_h48.c index adac8fa..adac8fa 100644 --- a/tools/100_stats_tables_h48/stats_tables_h48.c +++ b/tools/200_stats_tables_h48/stats_tables_h48.c | |||
diff --git a/tools/200_solve_small/solve_small.c b/tools/300_solve_small/solve_small.c index 4d07728..4d07728 100644 --- a/tools/200_solve_small/solve_small.c +++ b/tools/300_solve_small/solve_small.c | |||
diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h new file mode 100644 index 0000000..27bd64a --- /dev/null +++ b/tools/expected_distributions.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | uint64_t expected_h48[12][9][21] = { | ||
| 2 | [0] = { | ||
| 3 | [2] = { | ||
| 4 | [0] = 5473562, | ||
| 5 | [1] = 34776317, | ||
| 6 | [2] = 68566704, | ||
| 7 | [3] = 8750867, | ||
| 8 | }, | ||
| 9 | [4] = { | ||
| 10 | [0] = 1, | ||
| 11 | [1] = 1, | ||
| 12 | [2] = 4, | ||
| 13 | [3] = 34, | ||
| 14 | [4] = 331, | ||
| 15 | [5] = 3612, | ||
| 16 | [6] = 41605, | ||
| 17 | [7] = 474128, | ||
| 18 | [8] = 4953846, | ||
| 19 | [9] = 34776317, | ||
| 20 | [10] = 68566704, | ||
| 21 | [11] = 8749194, | ||
| 22 | [12] = 1673, | ||
| 23 | }, | ||
| 24 | }, | ||
| 25 | }; | ||
diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h index 4294c24..1e714a7 100644 --- a/tools/nissy_extra.h +++ b/tools/nissy_extra.h | |||
| @@ -4,3 +4,4 @@ for testing purposes only. | |||
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | size_t gendata_h48_derive(uint8_t, const void *, void *); | 6 | size_t gendata_h48_derive(uint8_t, const void *, void *); |
| 7 | int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); | ||
diff --git a/tools/run_tool.sh b/tools/run_tool.sh index 7e09684..2216a66 100755 --- a/tools/run_tool.sh +++ b/tools/run_tool.sh | |||
| @@ -5,7 +5,7 @@ if [ -z "$TOOL" ]; then | |||
| 5 | exit 1 | 5 | exit 1 |
| 6 | fi | 6 | fi |
| 7 | 7 | ||
| 8 | CC="$CC -D_POSIX_C_SOURCE=199309L" | 8 | CC="$CC -D_POSIX_C_SOURCE=199309L" # For timer |
| 9 | 9 | ||
| 10 | BIN="tools/run" | 10 | BIN="tools/run" |
| 11 | d="$(date +'%Y-%m-%d-%H-%M-%S')" | 11 | d="$(date +'%Y-%m-%d-%H-%M-%S')" |
| @@ -16,7 +16,8 @@ for t in tools/*; do | |||
| 16 | fi | 16 | fi |
| 17 | toolname="$(basename "$t" .c)" | 17 | toolname="$(basename "$t" .c)" |
| 18 | $CC -o $BIN "$t"/*.c "$CUBEOBJ" || exit 1; | 18 | $CC -o $BIN "$t"/*.c "$CUBEOBJ" || exit 1; |
| 19 | $BIN | tee "tools/results/$toolname-$d.txt" "tools/results/last.out" | 19 | $BIN $TOOLARGS \ |
| 20 | | tee "tools/results/$toolname-$d.txt" "tools/results/last.out" | ||
| 20 | break | 21 | break |
| 21 | done | 22 | done |
| 22 | 23 | ||
diff --git a/tools/tool.h b/tools/tool.h index 59407b6..5eec318 100644 --- a/tools/tool.h +++ b/tools/tool.h | |||
| @@ -11,11 +11,12 @@ | |||
| 11 | static void log_stderr(const char *, ...); | 11 | static void log_stderr(const char *, ...); |
| 12 | static void log_stdout(const char *, ...); | 12 | static void log_stdout(const char *, ...); |
| 13 | static double timerun(void (*)(void), const char *); | 13 | static double timerun(void (*)(void), const char *); |
| 14 | static void getfilename(const char *, const char *, char *); | ||
| 14 | static void writetable(const char *, int64_t, const char *); | 15 | static void writetable(const char *, int64_t, const char *); |
| 15 | static int64_t generatetable(const char *, const char *, char **); | 16 | static int64_t generatetable(const char *, const char *, char **); |
| 16 | static int64_t derivetable(uint8_t, char **); | 17 | static int64_t derivetable(uint8_t, char **); |
| 17 | static int getdata(const char *, const char *, char **, const char *); | 18 | static int getdata(const char *, const char *, char **, const char *); |
| 18 | static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]); | 19 | static void gendata_run(const char *, const char *, uint64_t[static 21]); |
| 19 | static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); | 20 | static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); |
| 20 | 21 | ||
| 21 | static void | 22 | static void |
| @@ -73,6 +74,17 @@ timerun(void (*run)(void), const char *name) | |||
| 73 | } | 74 | } |
| 74 | 75 | ||
| 75 | static void | 76 | static void |
| 77 | getfilename(const char *solver, const char *options, char *filename) | ||
| 78 | { | ||
| 79 | uint8_t h, k; | ||
| 80 | |||
| 81 | /* Only h48 supported for now */ | ||
| 82 | parse_h48_options(options, &h, &k, NULL); | ||
| 83 | |||
| 84 | sprintf(filename, "tables/%sh%dk%d", solver, h, k); | ||
| 85 | } | ||
| 86 | |||
| 87 | static void | ||
| 76 | writetable(const char *buf, int64_t size, const char *filename) | 88 | writetable(const char *buf, int64_t size, const char *filename) |
| 77 | { | 89 | { |
| 78 | FILE *f; | 90 | FILE *f; |
| @@ -193,13 +205,12 @@ static void | |||
| 193 | gendata_run( | 205 | gendata_run( |
| 194 | const char *solver, | 206 | const char *solver, |
| 195 | const char *options, | 207 | const char *options, |
| 196 | const char *filename, /* TODO: remove filename, use solver name */ | ||
| 197 | uint64_t expected[static 21] | 208 | uint64_t expected[static 21] |
| 198 | ) { | 209 | ) { |
| 199 | int64_t size; | 210 | int64_t size; |
| 200 | char *buf; | 211 | char *buf, filename[1024]; |
| 201 | 212 | ||
| 202 | 213 | getfilename(solver, options, filename); | |
| 203 | size = generatetable(solver, options, &buf); | 214 | size = generatetable(solver, options, &buf); |
| 204 | switch (size) { | 215 | switch (size) { |
| 205 | case -1: | 216 | case -1: |
