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