diff options
Diffstat (limited to 'tools/stats_tables_h48')
| -rw-r--r-- | tools/stats_tables_h48/stats_tables_h48.c | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/tools/stats_tables_h48/stats_tables_h48.c b/tools/stats_tables_h48/stats_tables_h48.c deleted file mode 100644 index 7df396a..0000000 --- a/tools/stats_tables_h48/stats_tables_h48.c +++ /dev/null | |||
| @@ -1,143 +0,0 @@ | |||
| 1 | #include <pthread.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include "../timerun.h" | ||
| 4 | #include "../../src/cube.h" | ||
| 5 | |||
| 6 | #define MAXMOVES 20 | ||
| 7 | #define NTHREADS 32 | ||
| 8 | #define NCUBES_PER_THREAD 10000 | ||
| 9 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) | ||
| 10 | |||
| 11 | typedef struct { | ||
| 12 | int n; | ||
| 13 | int thread_id; | ||
| 14 | int64_t v[12][100]; | ||
| 15 | } thread_arg_t; | ||
| 16 | |||
| 17 | const char *filename = "tables/h48h0k4"; | ||
| 18 | char *buf; | ||
| 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[NTHREADS]; | ||
| 60 | thread_arg_t arg[NTHREADS]; | ||
| 61 | |||
| 62 | for (i = 0; i < NTHREADS; 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 < NTHREADS; 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 < NTHREADS; 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 * NTHREADS); | ||
| 83 | printf("Average: %.4lf\n", avg); | ||
| 84 | printf("\n"); | ||
| 85 | } | ||
| 86 | } | ||
| 87 | |||
| 88 | int getdata(int64_t size) { | ||
| 89 | int64_t s; | ||
| 90 | FILE *f; | ||
| 91 | |||
| 92 | buf = malloc(size); | ||
| 93 | |||
| 94 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 95 | fprintf(stderr, "Table file not found, generating them." | ||
| 96 | " This can take a while.\n"); | ||
| 97 | s = nissy_gendata("h48stats", "", buf); | ||
| 98 | if (s != size) { | ||
| 99 | fprintf(stderr, "Error generating table"); | ||
| 100 | if (s != -1) | ||
| 101 | fprintf(stderr, " (got %" PRId64 " bytes)", s); | ||
| 102 | fprintf(stderr, "\n"); | ||
| 103 | return 1; | ||
| 104 | } | ||
| 105 | if ((f = fopen(filename, "wb")) == NULL) { | ||
| 106 | fprintf(stderr, "Could not write tables to file %s" | ||
| 107 | ", will be regenerated next time.\n", filename); | ||
| 108 | } else { | ||
| 109 | fwrite(buf, size, 1, f); | ||
| 110 | fclose(f); | ||
| 111 | } | ||
| 112 | } else { | ||
| 113 | fprintf(stderr, "Reading tables from file %s\n", filename); | ||
| 114 | fread(buf, size, 1, f); | ||
| 115 | fclose(f); | ||
| 116 | } | ||
| 117 | |||
| 118 | return 0; | ||
| 119 | } | ||
| 120 | |||
| 121 | int main(void) { | ||
| 122 | int64_t size; | ||
| 123 | |||
| 124 | srand(time(NULL)); | ||
| 125 | |||
| 126 | nissy_setlogger(log_stderr); | ||
| 127 | size = nissy_datasize("h48stats", ""); | ||
| 128 | if (size == -1) { | ||
| 129 | printf("h48 stats: error in datasize\n"); | ||
| 130 | return 1; | ||
| 131 | } | ||
| 132 | |||
| 133 | if (getdata(size) != 0) { | ||
| 134 | printf("Error getting table, stopping\n"); | ||
| 135 | free(buf); | ||
| 136 | return 1; | ||
| 137 | } | ||
| 138 | |||
| 139 | timerun(run, "h48 table stats"); | ||
| 140 | |||
| 141 | free(buf); | ||
| 142 | return 0; | ||
| 143 | } | ||
