diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-30 07:52:53 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-08-30 07:52:53 +0200 |
| commit | c548499e68e473452592c9b0bf860f76bd8b94b8 (patch) | |
| tree | 02219807113dde108e278f38f3dd5874f7e3dc18 /tools/002_stats_tables_h48 | |
| parent | 7e6c14a2f6e9e9cbac3431f3085c42bbe474d13d (diff) | |
| download | nissy-core-c548499e68e473452592c9b0bf860f76bd8b94b8.tar.gz nissy-core-c548499e68e473452592c9b0bf860f76bd8b94b8.zip | |
Added tool for checking new tables (and they are wrong)
Diffstat (limited to 'tools/002_stats_tables_h48')
| -rw-r--r-- | tools/002_stats_tables_h48/stats_tables_h48.c | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/tools/002_stats_tables_h48/stats_tables_h48.c b/tools/002_stats_tables_h48/stats_tables_h48.c deleted file mode 100644 index 8b65862..0000000 --- a/tools/002_stats_tables_h48/stats_tables_h48.c +++ /dev/null | |||
| @@ -1,100 +0,0 @@ | |||
| 1 | #include <pthread.h> | ||
| 2 | |||
| 3 | #include "../tool.h" | ||
| 4 | |||
| 5 | #define MAXMOVES 20 | ||
| 6 | #define NTHREADS 32 | ||
| 7 | #define NCUBES_PER_THREAD 10000 | ||
| 8 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) | ||
| 9 | |||
| 10 | const char *solver = "h48stats"; | ||
| 11 | const char *options = ""; | ||
| 12 | const char *filename = "tables/h48h0k4"; | ||
| 13 | char *buf; | ||
| 14 | |||
| 15 | typedef struct { | ||
| 16 | int n; | ||
| 17 | int thread_id; | ||
| 18 | int64_t v[12][100]; | ||
| 19 | } thread_arg_t; | ||
| 20 | |||
| 21 | uint64_t rand64(void) { | ||
| 22 | uint64_t i, ret; | ||
| 23 | |||
| 24 | for (i = 0, ret = 0; i < 64; i++) | ||
| 25 | ret |= (uint64_t)(rand() % 2) << i; | ||
| 26 | |||
| 27 | return ret; | ||
| 28 | } | ||
| 29 | |||
| 30 | static void * | ||
| 31 | run_thread(void *arg) | ||
| 32 | { | ||
| 33 | char sols[12], cube[22]; | ||
| 34 | int64_t ep, eo, cp, co; | ||
| 35 | int i, j; | ||
| 36 | |||
| 37 | thread_arg_t *a = (thread_arg_t *)arg; | ||
| 38 | |||
| 39 | for (i = 0; i < a->n; i++) { | ||
| 40 | ep = rand64(); | ||
| 41 | eo = rand64(); | ||
| 42 | cp = rand64(); | ||
| 43 | co = rand64(); | ||
| 44 | nissy_getcube(ep, eo, cp, co, "fix", cube); | ||
| 45 | nissy_solve(cube, "h48stats", "", "", | ||
| 46 | 0, MAXMOVES, 1, -1, buf, sols); | ||
| 47 | for (j = 0; j < 12; j++) | ||
| 48 | a->v[j][(int)sols[j]]++; | ||
| 49 | if ((i+1) % LOG_EVERY == 0) | ||
| 50 | fprintf(stderr, "[thread %d] %d cubes solved...\n", | ||
| 51 | a->thread_id, i+1); | ||
| 52 | } | ||
| 53 | |||
| 54 | return NULL; | ||
| 55 | } | ||
| 56 | |||
| 57 | void run(void) { | ||
| 58 | int64_t i, j, k, tot; | ||
| 59 | double avg; | ||
| 60 | pthread_t thread[NTHREADS]; | ||
| 61 | thread_arg_t arg[NTHREADS]; | ||
| 62 | |||
| 63 | for (i = 0; i < NTHREADS; i++) { | ||
| 64 | arg[i] = (thread_arg_t) { | ||
| 65 | .thread_id = i, | ||
| 66 | .n = NCUBES_PER_THREAD, | ||
| 67 | .v = {{0}} | ||
| 68 | }; | ||
| 69 | pthread_create(&thread[i], NULL, run_thread, &arg[i]); | ||
| 70 | } | ||
| 71 | |||
| 72 | for (i = 0; i < NTHREADS; i++) | ||
| 73 | pthread_join(thread[i], NULL); | ||
| 74 | |||
| 75 | for (j = 0; j < 12; j++) { | ||
| 76 | printf("Data for h=%" PRId64 "\n", j); | ||
| 77 | for (k = 0, avg = 0.0; k <= 16; k++) { | ||
| 78 | for (i = 0, tot = 0; i < NTHREADS; i++) | ||
| 79 | tot += arg[i].v[j][k]; | ||
| 80 | printf("%" PRId64 "\t%" PRId64 "\n", k, tot); | ||
| 81 | avg += tot * k; | ||
| 82 | } | ||
| 83 | avg /= (double)(NCUBES_PER_THREAD * NTHREADS); | ||
| 84 | printf("Average: %.4lf\n", avg); | ||
| 85 | printf("\n"); | ||
| 86 | } | ||
| 87 | } | ||
| 88 | |||
| 89 | int main(void) { | ||
| 90 | srand(time(NULL)); | ||
| 91 | nissy_setlogger(log_stderr); | ||
| 92 | |||
| 93 | if (getdata(solver, options, &buf, filename) != 0) | ||
| 94 | return 1; | ||
| 95 | |||
| 96 | timerun(run, "h48 table stats"); | ||
| 97 | |||
| 98 | free(buf); | ||
| 99 | return 0; | ||
| 100 | } | ||
