diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-20 10:05:51 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-07-20 10:05:51 +0200 |
| commit | 5727f06c5694a4831881322876e3ba4d8ce3b743 (patch) | |
| tree | 8ec57e5862b05464b54aad3aad6f3d37653066a6 /tools/stats_tables_h48 | |
| parent | e20e4f550ae373414d9bc106b1615a5c5896c9c4 (diff) | |
| download | nissy-core-5727f06c5694a4831881322876e3ba4d8ce3b743.tar.gz nissy-core-5727f06c5694a4831881322876e3ba4d8ce3b743.zip | |
Finally fixed selfsim logic
Diffstat (limited to 'tools/stats_tables_h48')
| -rw-r--r-- | tools/stats_tables_h48/stats_tables_h48.c | 152 |
1 files changed, 0 insertions, 152 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 7c6bc3c..0000000 --- a/tools/stats_tables_h48/stats_tables_h48.c +++ /dev/null | |||
| @@ -1,152 +0,0 @@ | |||
| 1 | #include <pthread.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <time.h> | ||
| 4 | #include "../timerun.h" | ||
| 5 | #include "../../src/cube.h" | ||
| 6 | |||
| 7 | #define MAXMOVES 20 | ||
| 8 | #define NTHREADS 32 | ||
| 9 | #define NCUBES_PER_THREAD 10000 | ||
| 10 | #define LOG_EVERY (NCUBES_PER_THREAD / 10) | ||
| 11 | |||
| 12 | typedef struct { | ||
| 13 | int n; | ||
| 14 | int thread_id; | ||
| 15 | int64_t v[12][100]; | ||
| 16 | } thread_arg_t; | ||
| 17 | |||
| 18 | const char *filename = "tables/h48h0k4"; | ||
| 19 | char *buf; | ||
| 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 | void log_stderr(const char *str, ...) { | ||
| 31 | va_list args; | ||
| 32 | |||
| 33 | va_start(args, str); | ||
| 34 | vfprintf(stderr, str, args); | ||
| 35 | va_end(args); | ||
| 36 | } | ||
| 37 | |||
| 38 | static void * | ||
| 39 | run_thread(void *arg) | ||
| 40 | { | ||
| 41 | char sols[12], cube[22]; | ||
| 42 | int64_t ep, eo, cp, co; | ||
| 43 | int i, j; | ||
| 44 | |||
| 45 | thread_arg_t *a = (thread_arg_t *)arg; | ||
| 46 | |||
| 47 | for (i = 0; i < a->n; i++) { | ||
| 48 | ep = rand64(); | ||
| 49 | eo = rand64(); | ||
| 50 | cp = rand64(); | ||
| 51 | co = rand64(); | ||
| 52 | nissy_getcube(ep, eo, cp, co, "fix", cube); | ||
| 53 | nissy_solve(cube, "h48stats", "", "", | ||
| 54 | 0, MAXMOVES, 1, -1, buf, sols); | ||
| 55 | for (j = 0; j < 12; j++) | ||
| 56 | a->v[j][(int)sols[j]]++; | ||
| 57 | if ((i+1) % LOG_EVERY == 0) | ||
| 58 | fprintf(stderr, "[thread %d] %d cubes solved...\n", | ||
| 59 | a->thread_id, i+1); | ||
| 60 | } | ||
| 61 | |||
| 62 | return NULL; | ||
| 63 | } | ||
| 64 | |||
| 65 | void run(void) { | ||
| 66 | int64_t i, j, k, tot; | ||
| 67 | double avg; | ||
| 68 | pthread_t thread[NTHREADS]; | ||
| 69 | thread_arg_t arg[NTHREADS]; | ||
| 70 | |||
| 71 | for (i = 0; i < NTHREADS; i++) { | ||
| 72 | arg[i] = (thread_arg_t) { | ||
| 73 | .thread_id = i, | ||
| 74 | .n = NCUBES_PER_THREAD, | ||
| 75 | .v = {{0}} | ||
| 76 | }; | ||
| 77 | pthread_create(&thread[i], NULL, run_thread, &arg[i]); | ||
| 78 | } | ||
| 79 | |||
| 80 | for (i = 0; i < NTHREADS; i++) | ||
| 81 | pthread_join(thread[i], NULL); | ||
| 82 | |||
| 83 | for (j = 0; j < 12; j++) { | ||
| 84 | printf("Data for h=%" PRId64 "\n", j); | ||
| 85 | for (k = 0, avg = 0.0; k <= 16; k++) { | ||
| 86 | for (i = 0, tot = 0; i < NTHREADS; i++) | ||
| 87 | tot += arg[i].v[j][k]; | ||
| 88 | printf("%" PRId64 "\t%" PRId64 "\n", k, tot); | ||
| 89 | avg += tot * k; | ||
| 90 | } | ||
| 91 | avg /= (double)(NCUBES_PER_THREAD * NTHREADS); | ||
| 92 | printf("Average: %.4lf\n", avg); | ||
| 93 | printf("\n"); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | int getdata(int64_t size) { | ||
| 98 | int64_t s; | ||
| 99 | FILE *f; | ||
| 100 | |||
| 101 | buf = malloc(size); | ||
| 102 | |||
| 103 | if ((f = fopen(filename, "rb")) == NULL) { | ||
| 104 | fprintf(stderr, "Table file not found, generating them." | ||
| 105 | " This can take a while.\n"); | ||
| 106 | s = nissy_gendata("h48stats", "", buf); | ||
| 107 | if (s != size) { | ||
| 108 | fprintf(stderr, "Error generating table"); | ||
| 109 | if (s != -1) | ||
| 110 | fprintf(stderr, " (got %" PRId64 " bytes)", s); | ||
| 111 | fprintf(stderr, "\n"); | ||
| 112 | return 1; | ||
| 113 | } | ||
| 114 | if ((f = fopen(filename, "wb")) == NULL) { | ||
| 115 | fprintf(stderr, "Could not write tables to file %s" | ||
| 116 | ", will be regenerated next time.\n", filename); | ||
| 117 | } else { | ||
| 118 | fwrite(buf, size, 1, f); | ||
| 119 | fclose(f); | ||
| 120 | } | ||
| 121 | } else { | ||
| 122 | fprintf(stderr, "Reading tables from file %s\n", filename); | ||
| 123 | fread(buf, size, 1, f); | ||
| 124 | fclose(f); | ||
| 125 | } | ||
| 126 | |||
| 127 | return 0; | ||
| 128 | } | ||
| 129 | |||
| 130 | int main(void) { | ||
| 131 | int64_t size; | ||
| 132 | |||
| 133 | srand(time(NULL)); | ||
| 134 | |||
| 135 | nissy_setlogger(log_stderr); | ||
| 136 | size = nissy_datasize("h48stats", ""); | ||
| 137 | if (size == -1) { | ||
| 138 | printf("h48 stats: error in datasize\n"); | ||
| 139 | return 1; | ||
| 140 | } | ||
| 141 | |||
| 142 | if (getdata(size) != 0) { | ||
| 143 | printf("Error getting table, stopping\n"); | ||
| 144 | free(buf); | ||
| 145 | return 1; | ||
| 146 | } | ||
| 147 | |||
| 148 | timerun(run, "h48 table stats"); | ||
| 149 | |||
| 150 | free(buf); | ||
| 151 | return 0; | ||
| 152 | } | ||
