aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nissy.c2
-rw-r--r--src/solvers/h48/gendata_h48.h58
-rw-r--r--src/solvers/h48/gendata_types_macros.h8
3 files changed, 58 insertions, 10 deletions
diff --git a/src/nissy.c b/src/nissy.c
index ba43e5d..f22f606 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -105,7 +105,7 @@ distribution_equal(
105 int wrong; 105 int wrong;
106 uint8_t i; 106 uint8_t i;
107 107
108 for (i = 0, wrong = 0; i <= MAX(maxvalue, 20); i++) { 108 for (i = 0, wrong = 0; i <= MIN(maxvalue, 20); i++) {
109 if (expected[i] != actual[i]) { 109 if (expected[i] != actual[i]) {
110 wrong++; 110 wrong++;
111 LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %" 111 LOG("Value %" PRIu8 ": expected %" PRIu64 ", found %"
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index ba0cc50..4478e9e 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -3,8 +3,8 @@ STATIC int64_t gendata_h48(gendata_h48_arg_t [static 1]);
3STATIC void gendata_h48h0k4(gendata_h48_arg_t [static 1]); 3STATIC void gendata_h48h0k4(gendata_h48_arg_t [static 1]);
4STATIC void gendata_h48k2(gendata_h48_arg_t [static 1]); 4STATIC void gendata_h48k2(gendata_h48_arg_t [static 1]);
5 5
6STATIC void * gendata_h48h0k4_runthread(void *); 6STATIC void *gendata_h48h0k4_runthread(void *);
7STATIC void * gendata_h48k2_runthread(void *); 7STATIC void *gendata_h48k2_runthread(void *);
8 8
9STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t [static 1]); 9STATIC_INLINE void gendata_h48_mark_atomic(gendata_h48_mark_t [static 1]);
10STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t [static 1]); 10STATIC_INLINE void gendata_h48_mark(gendata_h48_mark_t [static 1]);
@@ -12,6 +12,7 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(
12 cube_t, int8_t, h48k2_dfs_arg_t [static 1]); 12 cube_t, int8_t, h48k2_dfs_arg_t [static 1]);
13STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]); 13STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]);
14STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); 14STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]);
15STATIC void *getdistribution_h48_runthread(void *);
15STATIC void getdistribution_h48(const uint8_t *, 16STATIC void getdistribution_h48(const uint8_t *,
16 uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); 17 uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t);
17 18
@@ -643,6 +644,26 @@ makeinfo_h48k2(gendata_h48_arg_t arg[static 1])
643 return info; 644 return info;
644} 645}
645 646
647STATIC void *
648getdistribution_h48_runthread(void *arg)
649{
650 getdistribution_h48_data_t *data = (getdistribution_h48_data_t *)arg;
651 const uint8_t *table;
652 uint8_t j, k, m;
653 int64_t i;
654
655 memset(data->distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
656
657 k = data->k;
658 table = data->table;
659 m = H48_MASK(0, k);
660 for (i = data->min; i < data->max; i++)
661 for (j = 0; j < H48_DIV(k); j++)
662 data->distr[(table[i] & (m << (j*k))) >> (j*k)]++;
663
664 return NULL;
665}
666
646STATIC void 667STATIC void
647getdistribution_h48( 668getdistribution_h48(
648 const uint8_t *table, 669 const uint8_t *table,
@@ -650,16 +671,35 @@ getdistribution_h48(
650 uint8_t h, 671 uint8_t h,
651 uint8_t k 672 uint8_t k
652) { 673) {
653 uint8_t val; 674 getdistribution_h48_data_t targ[THREADS];
654 int64_t i, h48max; 675 pthread_t thread[THREADS];
676 uint64_t local_distr[THREADS][INFO_DISTRIBUTION_LEN];
677 int64_t i, j, nbytes, sz;
678
679 nbytes = H48_COORDMAX(h) / H48_DIV(k);
680 sz = nbytes / THREADS;
681 for (i = 0; i < THREADS; i++) {
682 targ[i] = (getdistribution_h48_data_t) {
683 .min = i * sz,
684 .max = i == THREADS - 1 ? nbytes : (i+1) * sz,
685 .k = k,
686 .distr = local_distr[i],
687 .table = table,
688 };
689 pthread_create(&thread[i], NULL,
690 getdistribution_h48_runthread, &targ[i]);
691 }
692
693 for (i = 0; i < THREADS; i++)
694 pthread_join(thread[i], NULL);
655 695
656 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); 696 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
697 for (i = 0; i < THREADS; i++)
698 for (j = 0; j < INFO_DISTRIBUTION_LEN; j++)
699 distr[j] += local_distr[i][j];
657 700
658 h48max = H48_COORDMAX(h); 701 for (i = nbytes * H48_DIV(k); i < H48_COORDMAX(h); i++)
659 for (i = 0; i < h48max; i++) { 702 distr[get_h48_pval(table, i, k)]++;
660 val = get_h48_pval(table, i, k);
661 distr[val]++;
662 }
663} 703}
664 704
665STATIC const uint32_t * 705STATIC const uint32_t *
diff --git a/src/solvers/h48/gendata_types_macros.h b/src/solvers/h48/gendata_types_macros.h
index 11940d8..3f0c666 100644
--- a/src/solvers/h48/gendata_types_macros.h
+++ b/src/solvers/h48/gendata_types_macros.h
@@ -121,3 +121,11 @@ typedef struct {
121 _Atomic uint8_t *table_atomic; 121 _Atomic uint8_t *table_atomic;
122 pthread_mutex_t **table_mutex; 122 pthread_mutex_t **table_mutex;
123} gendata_h48_mark_t; 123} gendata_h48_mark_t;
124
125typedef struct {
126 int64_t min;
127 int64_t max;
128 uint8_t k;
129 uint64_t *distr;
130 const uint8_t *table;
131} getdistribution_h48_data_t;

Generated with cgit - Back to sebastiano.tronto.net