aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-07-09 18:55:51 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2024-07-09 18:55:51 +0200
commit275d8c66d2aa4793d986bcc7939cb4adcd64e018 (patch)
treedc187e373d46939f2c6918e04a13b51d1e87954c /tools
parent1d35e5189ba441967cb1585c340452e6125f5ba5 (diff)
downloadnissy-core-275d8c66d2aa4793d986bcc7939cb4adcd64e018.tar.gz
nissy-core-275d8c66d2aa4793d986bcc7939cb4adcd64e018.zip
Made stats tool parallel
Diffstat (limited to 'tools')
-rw-r--r--tools/stats_tables_h48/stats_tables_h48.c64
1 files changed, 49 insertions, 15 deletions
diff --git a/tools/stats_tables_h48/stats_tables_h48.c b/tools/stats_tables_h48/stats_tables_h48.c
index bcc62b4..fc8c981 100644
--- a/tools/stats_tables_h48/stats_tables_h48.c
+++ b/tools/stats_tables_h48/stats_tables_h48.c
@@ -1,11 +1,19 @@
1#include <pthread.h>
1#include <stdarg.h> 2#include <stdarg.h>
2#include <time.h> 3#include <time.h>
3#include "../timerun.h" 4#include "../timerun.h"
4#include "../../src/cube.h" 5#include "../../src/cube.h"
5 6
6#define MAXMOVES 20 7#define MAXMOVES 20
7#define NCUBES 10000 8#define NTHREADS 32
8#define LOG_EVERY (NCUBES / 20) 9#define NCUBES_PER_THREAD 10000
10#define LOG_EVERY (NCUBES_PER_THREAD / 10)
11
12typedef struct {
13 int n;
14 int thread_id;
15 int64_t v[12][100];
16} thread_arg_t;
9 17
10const char *filename = "tables/h48h0k4"; 18const char *filename = "tables/h48h0k4";
11char *buf; 19char *buf;
@@ -27,13 +35,16 @@ void log_stderr(const char *str, ...) {
27 va_end(args); 35 va_end(args);
28} 36}
29 37
30void run(void) { 38static void *
31 int i, j, k; 39run_thread(void *arg)
40{
32 char sols[12], cube[22]; 41 char sols[12], cube[22];
33 int64_t ep, eo, cp, co, v[12][100] = {0}; 42 int64_t ep, eo, cp, co;
34 double avg; 43 int i, j;
35 44
36 for (i = 0; i < NCUBES; i++) { 45 thread_arg_t *a = (thread_arg_t *)arg;
46
47 for (i = 0; i < a->n; i++) {
37 ep = rand64(); 48 ep = rand64();
38 eo = rand64(); 49 eo = rand64();
39 cp = rand64(); 50 cp = rand64();
@@ -42,19 +53,42 @@ void run(void) {
42 nissy_solve(cube, "h48stats", "", "", 53 nissy_solve(cube, "h48stats", "", "",
43 0, MAXMOVES, 1, -1, buf, sols); 54 0, MAXMOVES, 1, -1, buf, sols);
44 for (j = 0; j < 12; j++) 55 for (j = 0; j < 12; j++)
45 v[j][(int)sols[j]]++; 56 a->v[j][(int)sols[j]]++;
46 if ((i+1) % LOG_EVERY == 0) 57 if ((i+1) % LOG_EVERY == 0)
47 fprintf(stderr, "%d cubes solved...\n", i+1); 58 fprintf(stderr, "[thread %d] %d cubes solved...\n",
59 a->thread_id, i+1);
60 }
61
62 return NULL;
63}
64
65void 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]);
48 } 78 }
49 79
80 for (i = 0; i < NTHREADS; i++)
81 pthread_join(thread[i], NULL);
82
50 for (j = 0; j < 12; j++) { 83 for (j = 0; j < 12; j++) {
51 printf("Data for h=%d\n", j); 84 printf("Data for h=%" PRId64 "\n", j);
52 avg = 0.0; 85 for (k = 0, avg = 0.0; k <= 16; k++) {
53 for (k = 0; k <= 16; k++) { 86 for (i = 0, tot = 0; i < NTHREADS; i++)
54 printf("%d\t%" PRId64 "\n", k, v[j][k]); 87 tot += arg[i].v[j][k];
55 avg += v[j][k] * k; 88 printf("%" PRId64 "\t%" PRId64 "\n", k, tot);
89 avg += tot * k;
56 } 90 }
57 avg /= (double)NCUBES; 91 avg /= (double)(NCUBES_PER_THREAD * NTHREADS);
58 printf("Average: %.4lf\n", avg); 92 printf("Average: %.4lf\n", avg);
59 printf("\n"); 93 printf("\n");
60 } 94 }

Generated with cgit - Back to sebastiano.tronto.net