stats_tables_h48.c (1953B)
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 }