diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-18 08:48:13 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-18 08:48:13 +0200 |
| commit | 8b94d135429a9f3253cc7f25a1453b412065c4a0 (patch) | |
| tree | 4a31d6def5421e95fb98505a2bc2653c18fca330 /src/solvers/h48/gendata_h48.h | |
| parent | 30b43f08955158d4f2066f4b50fe8d1241b3177b (diff) | |
| download | nissy-core-8b94d135429a9f3253cc7f25a1453b412065c4a0.tar.gz nissy-core-8b94d135429a9f3253cc7f25a1453b412065c4a0.zip | |
Refactor solver dispatch and checkdata
Diffstat (limited to 'src/solvers/h48/gendata_h48.h')
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 86 |
1 files changed, 24 insertions, 62 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index c1a9ced..644ddc2 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | STATIC long long gendata_h48_dispatch( | ||
| 2 | const char *, unsigned long long, unsigned char *); | ||
| 1 | STATIC uint64_t gendata_h48short(gendata_h48short_arg_t [static 1]); | 3 | STATIC uint64_t gendata_h48short(gendata_h48short_arg_t [static 1]); |
| 2 | STATIC int64_t gendata_h48(gendata_h48_arg_t [static 1]); | 4 | STATIC int64_t gendata_h48(gendata_h48_arg_t [static 1]); |
| 3 | STATIC void gendata_h48h0k4(gendata_h48_arg_t [static 1]); | 5 | STATIC void gendata_h48h0k4(gendata_h48_arg_t [static 1]); |
| @@ -12,9 +14,6 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop( | |||
| 12 | cube_t, int8_t, h48k2_dfs_arg_t [static 1]); | 14 | cube_t, int8_t, h48k2_dfs_arg_t [static 1]); |
| 13 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]); | 15 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t [static 1]); |
| 14 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); | 16 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t [static 1]); |
| 15 | STATIC void *getdistribution_h48_runthread(void *); | ||
| 16 | STATIC void getdistribution_h48(const unsigned char *, | ||
| 17 | uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); | ||
| 18 | 17 | ||
| 19 | STATIC const uint32_t *get_cocsepdata_constptr(const unsigned char *); | 18 | STATIC const uint32_t *get_cocsepdata_constptr(const unsigned char *); |
| 20 | STATIC const unsigned char *get_h48data_constptr(const unsigned char *); | 19 | STATIC const unsigned char *get_h48data_constptr(const unsigned char *); |
| @@ -28,6 +27,27 @@ STATIC_INLINE void set_h48_pval_atomic( | |||
| 28 | 27 | ||
| 29 | size_t gendata_h48_derive(uint8_t, const unsigned char *, unsigned char *); | 28 | size_t gendata_h48_derive(uint8_t, const unsigned char *, unsigned char *); |
| 30 | 29 | ||
| 30 | STATIC long long | ||
| 31 | gendata_h48_dispatch( | ||
| 32 | const char *solver, | ||
| 33 | unsigned long long data_size, | ||
| 34 | unsigned char *data | ||
| 35 | ) | ||
| 36 | { | ||
| 37 | long long err; | ||
| 38 | gendata_h48_arg_t arg; | ||
| 39 | |||
| 40 | err = parse_h48_hk(solver, &arg.h, &arg.k); | ||
| 41 | if (err != NISSY_OK) | ||
| 42 | return err; | ||
| 43 | |||
| 44 | arg.buf_size = data_size; | ||
| 45 | arg.buf = data; | ||
| 46 | arg.maxdepth = 20; | ||
| 47 | |||
| 48 | return gendata_h48(&arg); | ||
| 49 | } | ||
| 50 | |||
| 31 | STATIC uint64_t | 51 | STATIC uint64_t |
| 32 | gendata_h48short(gendata_h48short_arg_t arg[static 1]) | 52 | gendata_h48short(gendata_h48short_arg_t arg[static 1]) |
| 33 | { | 53 | { |
| @@ -649,64 +669,6 @@ makeinfo_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 649 | return info; | 669 | return info; |
| 650 | } | 670 | } |
| 651 | 671 | ||
| 652 | STATIC void * | ||
| 653 | getdistribution_h48_runthread(void *arg) | ||
| 654 | { | ||
| 655 | getdistribution_h48_data_t *data = (getdistribution_h48_data_t *)arg; | ||
| 656 | const unsigned char *table; | ||
| 657 | uint8_t j, k, m; | ||
| 658 | int64_t i; | ||
| 659 | |||
| 660 | memset(data->distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 661 | |||
| 662 | k = data->k; | ||
| 663 | table = data->table; | ||
| 664 | m = H48_MASK(0, k); | ||
| 665 | for (i = data->min; i < data->max; i++) | ||
| 666 | for (j = 0; j < H48_DIV(k); j++) | ||
| 667 | data->distr[(table[i] & (m << (j*k))) >> (j*k)]++; | ||
| 668 | |||
| 669 | return NULL; | ||
| 670 | } | ||
| 671 | |||
| 672 | STATIC void | ||
| 673 | getdistribution_h48( | ||
| 674 | const unsigned char *table, | ||
| 675 | uint64_t distr[static INFO_DISTRIBUTION_LEN], | ||
| 676 | uint8_t h, | ||
| 677 | uint8_t k | ||
| 678 | ) { | ||
| 679 | getdistribution_h48_data_t targ[THREADS]; | ||
| 680 | pthread_t thread[THREADS]; | ||
| 681 | uint64_t local_distr[THREADS][INFO_DISTRIBUTION_LEN]; | ||
| 682 | int64_t i, j, nbytes, sz; | ||
| 683 | |||
| 684 | nbytes = H48_COORDMAX(h) / H48_DIV(k); | ||
| 685 | sz = nbytes / THREADS; | ||
| 686 | for (i = 0; i < THREADS; i++) { | ||
| 687 | targ[i] = (getdistribution_h48_data_t) { | ||
| 688 | .min = i * sz, | ||
| 689 | .max = i == THREADS - 1 ? nbytes : (i+1) * sz, | ||
| 690 | .k = k, | ||
| 691 | .distr = local_distr[i], | ||
| 692 | .table = table, | ||
| 693 | }; | ||
| 694 | pthread_create(&thread[i], NULL, | ||
| 695 | getdistribution_h48_runthread, &targ[i]); | ||
| 696 | } | ||
| 697 | |||
| 698 | for (i = 0; i < THREADS; i++) | ||
| 699 | pthread_join(thread[i], NULL); | ||
| 700 | |||
| 701 | memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); | ||
| 702 | for (i = 0; i < THREADS; i++) | ||
| 703 | for (j = 0; j < INFO_DISTRIBUTION_LEN; j++) | ||
| 704 | distr[j] += local_distr[i][j]; | ||
| 705 | |||
| 706 | for (i = nbytes * H48_DIV(k); i < H48_COORDMAX(h); i++) | ||
| 707 | distr[get_h48_pval(table, i, k)]++; | ||
| 708 | } | ||
| 709 | |||
| 710 | STATIC const uint32_t * | 672 | STATIC const uint32_t * |
| 711 | get_cocsepdata_constptr(const unsigned char *data) | 673 | get_cocsepdata_constptr(const unsigned char *data) |
| 712 | { | 674 | { |
| @@ -821,7 +783,7 @@ gendata_h48_derive(uint8_t h, const unsigned char *fulltable, unsigned char *buf | |||
| 821 | h48derive, j, arg.k, MIN(val_full, val_derive)); | 783 | h48derive, j, arg.k, MIN(val_full, val_derive)); |
| 822 | } | 784 | } |
| 823 | 785 | ||
| 824 | getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); | 786 | getdistribution(h48derive, arg.info.distribution, &arg.info); |
| 825 | 787 | ||
| 826 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; | 788 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; |
| 827 | if (writetableinfo(&arg.info, bufsize, (unsigned char *)arg.h48buf) | 789 | if (writetableinfo(&arg.info, bufsize, (unsigned char *)arg.h48buf) |
