aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48/gendata_h48.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/solvers/h48/gendata_h48.h')
-rw-r--r--src/solvers/h48/gendata_h48.h120
1 files changed, 111 insertions, 9 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index 3445570..75b7abf 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -103,14 +103,19 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *);
103STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); 103STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *);
104STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); 104STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg);
105STATIC void * gendata_h48k2_runthread(void *); 105STATIC void * gendata_h48k2_runthread(void *);
106STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); 106STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *);
107STATIC void getdistribution_h48(const uint8_t *,
108 uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t);
107 109
108STATIC uint32_t *get_cocsepdata_ptr(const void *); 110STATIC uint32_t *get_cocsepdata_ptr(const void *);
109STATIC uint8_t *get_h48data_ptr(const void *); 111STATIC uint8_t *get_h48data_ptr(const void *);
110 112
111STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); 113STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t);
112STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); 114STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t);
113STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); 115STATIC_INLINE uint8_t get_h48_bound(
116 cube_t, uint32_t, uint8_t, uint8_t, uint8_t *);
117
118size_t gendata_h48_derive(uint8_t, const void *, void *);
114 119
115STATIC uint64_t 120STATIC uint64_t
116gendata_h48short(gendata_h48short_arg_t *arg) 121gendata_h48short(gendata_h48short_arg_t *arg)
@@ -387,7 +392,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
387 [11] = 10 392 [11] = 10
388 }; 393 };
389 394
390 uint8_t t, selectedbase, *table; 395 uint8_t t, *table;
391 int64_t j; 396 int64_t j;
392 uint64_t i, ii, inext, count; 397 uint64_t i, ii, inext, count;
393 h48map_t shortcubes; 398 h48map_t shortcubes;
@@ -414,8 +419,9 @@ gendata_h48k2(gendata_h48_arg_t *arg)
414 }; 419 };
415 gendata_h48short(&shortarg); 420 gendata_h48short(&shortarg);
416 421
417 selectedbase = arg->base < 20 ? arg->base : base[arg->h]; 422 if (arg->base >= 20)
418 arg->info = makeinfo_h48k2(arg, selectedbase); 423 arg->base = base[arg->h];
424 arg->info = makeinfo_h48k2(arg);
419 425
420 inext = count = 0; 426 inext = count = 0;
421 pthread_mutex_init(&shortcubes_mutex, NULL); 427 pthread_mutex_init(&shortcubes_mutex, NULL);
@@ -425,7 +431,7 @@ gendata_h48k2(gendata_h48_arg_t *arg)
425 dfsarg[i] = (h48k2_dfs_arg_t){ 431 dfsarg[i] = (h48k2_dfs_arg_t){
426 .h = arg->h, 432 .h = arg->h,
427 .k = arg->k, 433 .k = arg->k,
428 .base = selectedbase, 434 .base = arg->base,
429 .shortdepth = shortdepth, 435 .shortdepth = shortdepth,
430 .cocsepdata = arg->cocsepdata, 436 .cocsepdata = arg->cocsepdata,
431 .table = table, 437 .table = table,
@@ -603,14 +609,17 @@ STATIC_INLINE bool
603gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) 609gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg)
604{ 610{
605 uint64_t val; 611 uint64_t val;
606 int64_t coord; 612 int64_t coord, mutex;
607 int8_t oldval; 613 int8_t oldval;
608 614
609 if (arg->h == 0 || arg->h == 11) { 615 if (arg->h == 0 || arg->h == 11) {
610 /* We are in the "real coordinate" case, we can stop 616 /* We are in the "real coordinate" case, we can stop
611 if this coordinate has already been visited */ 617 if this coordinate has already been visited */
612 coord = coord_h48(cube, arg->cocsepdata, arg->h); 618 coord = coord_h48(cube, arg->cocsepdata, arg->h);
619 mutex = H48_INDEX(coord, arg->k) % CHUNKS;
620 pthread_mutex_lock(arg->table_mutex[mutex]);
613 oldval = get_h48_pval(arg->table, coord, arg->k); 621 oldval = get_h48_pval(arg->table, coord, arg->k);
622 pthread_mutex_unlock(arg->table_mutex[mutex]);
614 return oldval <= depth; 623 return oldval <= depth;
615 } else { 624 } else {
616 /* With 0 < k < 11 we do not have a "real coordinate". 625 /* With 0 < k < 11 we do not have a "real coordinate".
@@ -637,7 +646,7 @@ gendata_h48k2_realcoord_runthread(void *arg)
637} 646}
638 647
639STATIC tableinfo_t 648STATIC tableinfo_t
640makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) 649makeinfo_h48k2(gendata_h48_arg_t *arg)
641{ 650{
642 tableinfo_t info; 651 tableinfo_t info;
643 652
@@ -651,7 +660,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base)
651 .classes = 0, 660 .classes = 0,
652 .h48h = arg->h, 661 .h48h = arg->h,
653 .bits = 2, 662 .bits = 2,
654 .base = base, 663 .base = arg->base,
655 .maxvalue = 3, 664 .maxvalue = 3,
656 .next = 0, 665 .next = 0,
657 }; 666 };
@@ -662,6 +671,25 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base)
662 return info; 671 return info;
663} 672}
664 673
674STATIC void
675getdistribution_h48(
676 const uint8_t *table,
677 uint64_t distr[static INFO_DISTRIBUTION_LEN],
678 uint8_t h,
679 uint8_t k
680) {
681 uint8_t val;
682 int64_t i, h48max;
683
684 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
685
686 h48max = H48_COORDMAX(h);
687 for (i = 0; i < h48max; i++) {
688 val = get_h48_pval(table, i, k);
689 distr[val]++;
690 }
691}
692
665STATIC uint32_t * 693STATIC uint32_t *
666get_cocsepdata_ptr(const void *data) 694get_cocsepdata_ptr(const void *data)
667{ 695{
@@ -695,3 +723,77 @@ get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table)
695 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); 723 coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h);
696 return get_h48_pval(table, coord, k); 724 return get_h48_pval(table, coord, k);
697} 725}
726
727size_t
728gendata_h48_derive(uint8_t h, const void *fulltable, void *buf)
729{
730 size_t cocsepsize, h48size;
731 uint8_t val_full, val_derive, *h48full, *h48derive;
732 int64_t i, j, h48max;
733 gendata_h48_arg_t arg;
734 tableinfo_t cocsepinfo, fulltableinfo;
735
736 /* Initializing values in case of error */
737 /* TODO cleanup this */
738 fulltableinfo.bits = 2;
739 fulltableinfo.base = 8;
740
741 readtableinfo_n(fulltable, 2, &fulltableinfo);
742 arg.h = h;
743 arg.k = fulltableinfo.bits;
744 arg.maxdepth = 20;
745 arg.buf = buf;
746 arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE);
747 arg.base = fulltableinfo.base;
748 arg.info = makeinfo_h48k2(&arg);
749
750 /* Technically this step is redundant, except that we
751 need selfsim and crep */
752 cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep);
753 arg.h48buf = (uint8_t *)buf + cocsepsize;
754 h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE;
755
756 if (buf == NULL)
757 goto gendata_h48_derive_return_size;
758
759 if (!readtableinfo(buf, &cocsepinfo)) {
760 LOG("gendata_h48: could not read info for cocsep table\n");
761 goto gendata_h48_derive_error;
762 }
763
764 cocsepinfo.next = cocsepsize;
765 if (!writetableinfo(&cocsepinfo, buf)) {
766 LOG("gendata_h48_derive: could not write info for cocsep table"
767 " with updated 'next' value\n");
768 goto gendata_h48_derive_error;
769 }
770
771 h48full = (uint8_t *)fulltable + cocsepsize + INFOSIZE;
772 h48derive = (uint8_t *)arg.h48buf + INFOSIZE;
773 memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k));
774 memset(arg.info.distribution, 0,
775 INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
776
777 h48max = H48_COORDMAX(fulltableinfo.h48h);
778 for (i = 0; i < h48max; i++) {
779 if (i % INT64_C(1000000000) == 0 && i > 0)
780 LOG("Processing %" PRId64 "th coordinate\n", i);
781 j = i >> (int64_t)(fulltableinfo.h48h - h);
782 val_full = get_h48_pval(h48full, i, arg.k);
783 val_derive = get_h48_pval(h48derive, j, arg.k);
784 set_h48_pval(h48derive, j, arg.k, MIN(val_full, val_derive));
785 }
786
787 getdistribution_h48(h48derive, arg.info.distribution, h, arg.k);
788
789 if (!writetableinfo(&arg.info, arg.h48buf)) {
790 LOG("gendata_h48_derive: could not write info for table\n");
791 goto gendata_h48_derive_error;
792 }
793
794gendata_h48_derive_return_size:
795 return cocsepsize + h48size;
796
797gendata_h48_derive_error:
798 return 0;
799}

Generated with cgit - Back to sebastiano.tronto.net