From bc2cba8529a163d129dec91b5ec448a29a14591a Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Thu, 26 Sep 2024 15:57:25 +0200 Subject: Added checkdata function --- src/solvers/h48/gendata_cocsep.h | 12 ++++++++++++ src/solvers/h48/gendata_h48.h | 24 +++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src/solvers/h48') diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index 2189145..262793b 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h @@ -25,6 +25,7 @@ STATIC_INLINE void set_visited(uint8_t *, int64_t); STATIC size_t gendata_cocsep(void *, uint64_t *, cube_t *); STATIC uint32_t gendata_cocsep_dfs(cocsep_dfs_arg_t *); +STATIC void getdistribution_cocsep(const uint32_t *, uint64_t [static 21]); STATIC_INLINE int8_t get_h48_cdata(cube_t, uint32_t *, uint32_t *); @@ -157,6 +158,17 @@ gendata_cocsep_dfs(cocsep_dfs_arg_t *arg) return cc; } +STATIC void +getdistribution_cocsep(const uint32_t *table, uint64_t distr[static 21]) +{ + size_t i; + + memset(distr, 0, 21 * sizeof(uint64_t)); + + for (i = 0; i < COCSEP_TABLESIZE; i++) + distr[CBOUND(table[i])]++; +} + STATIC_INLINE bool get_visited(const uint8_t *a, int64_t i) { diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 3445570..6e7b0ca 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -104,13 +104,16 @@ STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); STATIC void * gendata_h48k2_runthread(void *); STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); +STATIC void getdistribution_h48( + const uint8_t *, uint64_t [static 21], uint8_t, uint8_t); STATIC uint32_t *get_cocsepdata_ptr(const void *); STATIC uint8_t *get_h48data_ptr(const void *); STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); -STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); +STATIC_INLINE uint8_t get_h48_bound( + cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *arg) @@ -662,6 +665,25 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) return info; } +STATIC void +getdistribution_h48( + const uint8_t *table, + uint64_t distr[static 21], + uint8_t h, + uint8_t k +) { + uint8_t val; + int64_t i, h48max; + + memset(distr, 0, 21 * sizeof(uint64_t)); + + h48max = H48_COORDMAX(h); + for (i = 0; i < h48max; i++) { + val = get_h48_pval(table, i, k); + distr[val]++; + } +} + STATIC uint32_t * get_cocsepdata_ptr(const void *data) { -- cgit v1.3 From 0b32395de2500ad87e15fbb0ff4a852e313037e9 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 08:19:53 +0200 Subject: First try for derive tables --- src/nissy.h | 7 +++ src/solvers/h48/gendata_h48.h | 95 +++++++++++++++++++++++++++--- tools/1002_derive_h48h0k2/derive_h48h0k2.c | 21 +++++++ tools/nissy_extra.h | 6 ++ tools/tool.h | 64 ++++++++++++++++++++ 5 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 tools/1002_derive_h48h0k2/derive_h48h0k2.c create mode 100644 tools/nissy_extra.h (limited to 'src/solvers/h48') diff --git a/src/nissy.h b/src/nissy.h index 336130c..63e7a90 100644 --- a/src/nissy.h +++ b/src/nissy.h @@ -86,6 +86,13 @@ int64_t nissy_gendata( void *generated_data ); +/* Temporarily added to test h48 intermediate tables */ +int64_t nissy_derivedata( + const char *options, + const void *fulltable, + void *generated_data +); + /* Print information on a data table via the provided callback writer */ int64_t nissy_datainfo( const void *table, diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 3445570..a88eb4f 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -103,7 +103,7 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); STATIC void * gendata_h48k2_runthread(void *); -STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); +STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); STATIC uint32_t *get_cocsepdata_ptr(const void *); STATIC uint8_t *get_h48data_ptr(const void *); @@ -112,6 +112,8 @@ STATIC_INLINE uint8_t get_h48_pval(const uint8_t *, int64_t, uint8_t); STATIC_INLINE void set_h48_pval(uint8_t *, int64_t, uint8_t, uint8_t); STATIC_INLINE uint8_t get_h48_bound(cube_t, uint32_t, uint8_t, uint8_t, uint8_t *); +size_t gendata_h48_derive(uint8_t, const void *, void *); + STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *arg) { @@ -387,7 +389,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) [11] = 10 }; - uint8_t t, selectedbase, *table; + uint8_t t, *table; int64_t j; uint64_t i, ii, inext, count; h48map_t shortcubes; @@ -414,8 +416,9 @@ gendata_h48k2(gendata_h48_arg_t *arg) }; gendata_h48short(&shortarg); - selectedbase = arg->base < 20 ? arg->base : base[arg->h]; - arg->info = makeinfo_h48k2(arg, selectedbase); + if (arg->base >= 20) + arg->base = base[arg->h]; + arg->info = makeinfo_h48k2(arg); inext = count = 0; pthread_mutex_init(&shortcubes_mutex, NULL); @@ -425,7 +428,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) dfsarg[i] = (h48k2_dfs_arg_t){ .h = arg->h, .k = arg->k, - .base = selectedbase, + .base = arg->base, .shortdepth = shortdepth, .cocsepdata = arg->cocsepdata, .table = table, @@ -637,7 +640,7 @@ gendata_h48k2_realcoord_runthread(void *arg) } STATIC tableinfo_t -makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) +makeinfo_h48k2(gendata_h48_arg_t *arg) { tableinfo_t info; @@ -651,7 +654,7 @@ makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) .classes = 0, .h48h = arg->h, .bits = 2, - .base = base, + .base = arg->base, .maxvalue = 3, .next = 0, }; @@ -695,3 +698,81 @@ get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table) coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); return get_h48_pval(table, coord, k); } + +size_t +gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) +{ + size_t cocsepsize, h48size; + uint8_t val_full, val_derive, val_new, *h48full, *h48derive; + int64_t i, j, h48max; + gendata_h48_arg_t arg; + tableinfo_t cocsepinfo, fulltableinfo; + + /* Initializing values in case of error */ + fulltableinfo.bits = 2; + fulltableinfo.base = 8; + + readtableinfo_n(fulltable, 2, &fulltableinfo); + arg.h = h; + arg.k = fulltableinfo.bits; + arg.maxdepth = 20; + arg.buf = buf; + arg.cocsepdata = (uint32_t *)((char *)buf + INFOSIZE); + arg.base = fulltableinfo.base; + arg.info = makeinfo_h48k2(&arg); + + /* Technically this step is redundant, except that we + need selfsim and crep */ + cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); + arg.h48buf = (char *)buf + cocsepsize; + h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; + + if (buf == NULL) + goto gendata_h48_derive_return_size; + + if (!readtableinfo(buf, &cocsepinfo)) { + LOG("gendata_h48: could not read info for cocsep table\n"); + goto gendata_h48_derive_error; + } + + cocsepinfo.next = cocsepsize; + if (!writetableinfo(&cocsepinfo, buf)) { + LOG("gendata_h48_derive: could not write info for cocsep table" + " with updated 'next' value\n"); + goto gendata_h48_derive_error; + } + + h48full = (uint8_t *)fulltable + INFOSIZE; + h48derive = (uint8_t *)arg.h48buf + INFOSIZE; + memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); + memset(arg.info.distribution, 0, + INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); + + h48max = H48_COORDMAX(11); + for (i = 0; i < h48max; i++) { + if (i % INT64_C(1000000000) == 0) + LOG("Processing %" PRId64 "th coordinate\n", i); + j = i >> (int64_t)(11-h); + val_full = get_h48_pval(h48full, i, arg.k); + val_derive = get_h48_pval(h48derive, j, arg.k); + val_new = MIN(val_full, val_derive); + set_h48_pval(h48derive, j, arg.k, val_new); + } + + h48max = H48_COORDMAX(h); + for (i = 0; i < h48max; i++) { + val_derive = get_h48_pval(h48derive, i, arg.k); + arg.info.distribution[val_derive]++; + } + + if (!writetableinfo(&arg.info, buf)) { + LOG("gendata_h48_derive: could not write info for table\n"); + goto gendata_h48_derive_error; + } + +gendata_h48_derive_return_size: + return cocsepsize + h48size; + +gendata_h48_derive_error: + return 0; +} diff --git a/tools/1002_derive_h48h0k2/derive_h48h0k2.c b/tools/1002_derive_h48h0k2/derive_h48h0k2.c new file mode 100644 index 0000000..73fab2e --- /dev/null +++ b/tools/1002_derive_h48h0k2/derive_h48h0k2.c @@ -0,0 +1,21 @@ +#include "../tool.h" + +uint64_t expected[21] = { + /* Base value is 8 */ + [0] = 5473562, + [1] = 34776317, + [2] = 68566704, + [3] = 8750867, +}; + +void run(void) { + derivedata_run(0, "tables/h48h0k2_derived", expected); +} + +int main(void) { + nissy_setlogger(log_stderr); + + timerun(run, "benchmark derivedata_h48 h = 0, k = 2"); + + return 0; +} diff --git a/tools/nissy_extra.h b/tools/nissy_extra.h new file mode 100644 index 0000000..4294c24 --- /dev/null +++ b/tools/nissy_extra.h @@ -0,0 +1,6 @@ +/* +This header file exposes certain functions that are meant to be used +for testing purposes only. +*/ + +size_t gendata_h48_derive(uint8_t, const void *, void *); diff --git a/tools/tool.h b/tools/tool.h index 757657b..59407b6 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -6,14 +6,17 @@ #include #include "../src/nissy.h" +#include "nissy_extra.h" static void log_stderr(const char *, ...); static void log_stdout(const char *, ...); static double timerun(void (*)(void), const char *); static void writetable(const char *, int64_t, const char *); static int64_t generatetable(const char *, const char *, char **); +static int64_t derivetable(uint8_t, char **); static int getdata(const char *, const char *, char **, const char *); static void gendata_run(const char *, const char *, const char *, uint64_t[static 21]); +static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); static void log_stderr(const char *str, ...) @@ -109,6 +112,41 @@ generatetable(const char *solver, const char *options, char **buf) return gensize; } +static int64_t +derivetable(uint8_t h, char **buf) +{ + int64_t size, gensize; + char *fulltable; + + char options[20] = " ;2;20"; /* Fixed for k = 2 for now */ + options[0] = (char)(h + '0'); /* h = 10 not supported for now */ + + /* Support only b8 for now */ + if (getdata("h48", "11;2;20", &fulltable, "tables/h48h11k2_b8") != 0) { + printf("Error reading full table.\n"); + return -1; + } + + size = nissy_datasize("h48", options); + if (size == -1) { + printf("Error getting table size.\n"); + free(fulltable); + return -1; + } + + *buf = malloc(size); + gensize = gendata_h48_derive(h, fulltable, *buf); + + if (gensize != size) { + fprintf(stderr, "Error deriving table\n"); + free(fulltable); + return -2; + } + + free(fulltable); + return gensize; +} + static int getdata( const char *solver, @@ -182,3 +220,29 @@ gendata_run( gendata_run_finish: free(buf); } + +static void +derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) +{ + int64_t size; + char *buf; + + size = derivetable(h, &buf); + switch (size) { + case -1: + return; + case -2: + goto derivedata_run_finish; + default: + nissy_datainfo(buf, write_stdout); + printf("\n"); + printf("Succesfully generated %" PRId64 " bytes. " + "See above for details on the tables.\n", size); + + writetable(buf, size, filename); + break; + } + +derivedata_run_finish: + free(buf); +} -- cgit v1.3 From 388b55b4ea644aa1b6074a70652b8f62e7755280 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 09:11:00 +0200 Subject: Use constant instead of magic number --- src/nissy.c | 10 +++++----- src/solvers/h48/gendata_h48.h | 20 ++++++++------------ tools/001_derive_h48h0k2/derive_h48h0k2.c | 21 +++++++++++++++++++++ tools/1002_derive_h48h0k2/derive_h48h0k2.c | 21 --------------------- tools/tool.h | 2 +- 5 files changed, 35 insertions(+), 39 deletions(-) create mode 100644 tools/001_derive_h48h0k2/derive_h48h0k2.c delete mode 100644 tools/1002_derive_h48h0k2/derive_h48h0k2.c (limited to 'src/solvers/h48') diff --git a/src/nissy.c b/src/nissy.c index 953471f..2eed1b5 100644 --- a/src/nissy.c +++ b/src/nissy.c @@ -13,8 +13,8 @@ int parse_h48_options(const char *, uint8_t *, uint8_t *, uint8_t *); STATIC int64_t write_result(cube_t, char [static 22]); -STATIC bool distribution_equal( - const uint64_t [static 21], const uint64_t [static 21], uint8_t); +STATIC bool distribution_equal(const uint64_t [static INFO_DISTRIBUTION_LEN], + const uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t); STATIC bool checkdata(const void *, const tableinfo_t *); /* TODO: add option to get DR, maybe C-only, E-only, eo... */ @@ -68,7 +68,7 @@ parse_h48_options_error: STATIC bool checkdata(const void *buf, const tableinfo_t *info) { - uint64_t distr[21]; + uint64_t distr[INFO_DISTRIBUTION_LEN]; if (!strncmp(info->solver, "cocsep", 6)) { getdistribution_cocsep( @@ -86,8 +86,8 @@ checkdata(const void *buf, const tableinfo_t *info) STATIC bool distribution_equal( - const uint64_t expected[static 21], - const uint64_t actual[static 21], + const uint64_t expected[static INFO_DISTRIBUTION_LEN], + const uint64_t actual[static INFO_DISTRIBUTION_LEN], uint8_t maxvalue ) { diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 48d5582..b1ae38c 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -104,8 +104,8 @@ STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); STATIC void * gendata_h48k2_runthread(void *); STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *); -STATIC void getdistribution_h48( - const uint8_t *, uint64_t [static 21], uint8_t, uint8_t); +STATIC void getdistribution_h48(const uint8_t *, + uint64_t [static INFO_DISTRIBUTION_LEN], uint8_t, uint8_t); STATIC uint32_t *get_cocsepdata_ptr(const void *); STATIC uint8_t *get_h48data_ptr(const void *); @@ -671,14 +671,14 @@ makeinfo_h48k2(gendata_h48_arg_t *arg) STATIC void getdistribution_h48( const uint8_t *table, - uint64_t distr[static 21], + uint64_t distr[static INFO_DISTRIBUTION_LEN], uint8_t h, uint8_t k ) { uint8_t val; int64_t i, h48max; - memset(distr, 0, 21 * sizeof(uint64_t)); + memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); h48max = H48_COORDMAX(h); for (i = 0; i < h48max; i++) { @@ -725,12 +725,13 @@ size_t gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) { size_t cocsepsize, h48size; - uint8_t val_full, val_derive, val_new, *h48full, *h48derive; + uint8_t val_full, val_derive, *h48full, *h48derive; int64_t i, j, h48max; gendata_h48_arg_t arg; tableinfo_t cocsepinfo, fulltableinfo; /* Initializing values in case of error */ + /* TODO cleanup this */ fulltableinfo.bits = 2; fulltableinfo.base = 8; @@ -777,15 +778,10 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) j = i >> (int64_t)(11-h); val_full = get_h48_pval(h48full, i, arg.k); val_derive = get_h48_pval(h48derive, j, arg.k); - val_new = MIN(val_full, val_derive); - set_h48_pval(h48derive, j, arg.k, val_new); + set_h48_pval(h48derive, j, arg.k, MIN(val_full, val_derive)); } - h48max = H48_COORDMAX(h); - for (i = 0; i < h48max; i++) { - val_derive = get_h48_pval(h48derive, i, arg.k); - arg.info.distribution[val_derive]++; - } + getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); if (!writetableinfo(&arg.info, buf)) { LOG("gendata_h48_derive: could not write info for table\n"); diff --git a/tools/001_derive_h48h0k2/derive_h48h0k2.c b/tools/001_derive_h48h0k2/derive_h48h0k2.c new file mode 100644 index 0000000..73fab2e --- /dev/null +++ b/tools/001_derive_h48h0k2/derive_h48h0k2.c @@ -0,0 +1,21 @@ +#include "../tool.h" + +uint64_t expected[21] = { + /* Base value is 8 */ + [0] = 5473562, + [1] = 34776317, + [2] = 68566704, + [3] = 8750867, +}; + +void run(void) { + derivedata_run(0, "tables/h48h0k2_derived", expected); +} + +int main(void) { + nissy_setlogger(log_stderr); + + timerun(run, "benchmark derivedata_h48 h = 0, k = 2"); + + return 0; +} diff --git a/tools/1002_derive_h48h0k2/derive_h48h0k2.c b/tools/1002_derive_h48h0k2/derive_h48h0k2.c deleted file mode 100644 index 73fab2e..0000000 --- a/tools/1002_derive_h48h0k2/derive_h48h0k2.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "../tool.h" - -uint64_t expected[21] = { - /* Base value is 8 */ - [0] = 5473562, - [1] = 34776317, - [2] = 68566704, - [3] = 8750867, -}; - -void run(void) { - derivedata_run(0, "tables/h48h0k2_derived", expected); -} - -int main(void) { - nissy_setlogger(log_stderr); - - timerun(run, "benchmark derivedata_h48 h = 0, k = 2"); - - return 0; -} diff --git a/tools/tool.h b/tools/tool.h index 5eec318..d9071fb 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -130,7 +130,7 @@ derivetable(uint8_t h, char **buf) int64_t size, gensize; char *fulltable; - char options[20] = " ;2;20"; /* Fixed for k = 2 for now */ + char options[20] = " ;2;20"; /* Only for k = 2 for now */ options[0] = (char)(h + '0'); /* h = 10 not supported for now */ /* Support only b8 for now */ -- cgit v1.3 From 41be2d294e5b6f55d485d635065096f274bc89c1 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 16:37:55 +0200 Subject: Made table derivation tool more flexible So apparently my RAM is broken. That took me a while to figure out. While I get a replacement, I have to restrict myself to a weaker test for the intermediate tables: instead of deriving them from the huge table and checking that they are the same, I have to derive a small h0k2 table from the intermediate ones and check that it is correct. This is not a 100% proof of correctness, but it is good enough (and much faster). --- src/solvers/h48/gendata_h48.h | 19 ++++++++++-------- tools/001_derive_h48/derive_h48.c | 33 +++++++++++++++++++++++++++++++ tools/001_derive_h48h0k2/derive_h48h0k2.c | 21 -------------------- tools/expected_distributions.h | 8 ++++++++ tools/tool.h | 33 ++++++++++++++++++++----------- 5 files changed, 73 insertions(+), 41 deletions(-) create mode 100644 tools/001_derive_h48/derive_h48.c delete mode 100644 tools/001_derive_h48h0k2/derive_h48h0k2.c (limited to 'src/solvers/h48') diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index b1ae38c..d7f4c92 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -389,7 +389,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) [8] = 10, [9] = 10, [10] = 10, - [11] = 10 + [11] = 8 }; uint8_t t, *table; @@ -609,14 +609,17 @@ STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) { uint64_t val; - int64_t coord; + int64_t coord, mutex; int8_t oldval; if (arg->h == 0 || arg->h == 11) { /* We are in the "real coordinate" case, we can stop if this coordinate has already been visited */ coord = coord_h48(cube, arg->cocsepdata, arg->h); + mutex = H48_INDEX(coord, arg->k) % CHUNKS; + pthread_mutex_lock(arg->table_mutex[mutex]); oldval = get_h48_pval(arg->table, coord, arg->k); + pthread_mutex_unlock(arg->table_mutex[mutex]); return oldval <= depth; } else { /* With 0 < k < 11 we do not have a "real coordinate". @@ -747,7 +750,7 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) /* Technically this step is redundant, except that we need selfsim and crep */ cocsepsize = gendata_cocsep(buf, arg.selfsim, arg.crep); - arg.h48buf = (char *)buf + cocsepsize; + arg.h48buf = (uint8_t *)buf + cocsepsize; h48size = H48_TABLESIZE(h, arg.k) + INFOSIZE; if (buf == NULL) @@ -765,17 +768,17 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) goto gendata_h48_derive_error; } - h48full = (uint8_t *)fulltable + INFOSIZE; + h48full = (uint8_t *)fulltable + cocsepsize + INFOSIZE; h48derive = (uint8_t *)arg.h48buf + INFOSIZE; memset(h48derive, 0xFF, H48_TABLESIZE(h, arg.k)); memset(arg.info.distribution, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); - h48max = H48_COORDMAX(11); + h48max = H48_COORDMAX(fulltableinfo.h48h); for (i = 0; i < h48max; i++) { - if (i % INT64_C(1000000000) == 0) + if (i % INT64_C(1000000000) == 0 && i > 0) LOG("Processing %" PRId64 "th coordinate\n", i); - j = i >> (int64_t)(11-h); + j = i >> (int64_t)(fulltableinfo.h48h - h); val_full = get_h48_pval(h48full, i, arg.k); val_derive = get_h48_pval(h48derive, j, arg.k); set_h48_pval(h48derive, j, arg.k, MIN(val_full, val_derive)); @@ -783,7 +786,7 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) getdistribution_h48(h48derive, arg.info.distribution, h, arg.k); - if (!writetableinfo(&arg.info, buf)) { + if (!writetableinfo(&arg.info, arg.h48buf)) { LOG("gendata_h48_derive: could not write info for table\n"); goto gendata_h48_derive_error; } diff --git a/tools/001_derive_h48/derive_h48.c b/tools/001_derive_h48/derive_h48.c new file mode 100644 index 0000000..3c7f8cc --- /dev/null +++ b/tools/001_derive_h48/derive_h48.c @@ -0,0 +1,33 @@ +#include "../tool.h" + +char *opts_large, *opts_small, *filename_large, *filename_small; + +void run(void) { + derivedata_run(opts_large, opts_small, filename_large, filename_small); +} + +int main(int argc, char **argv) { + char description[256]; + + if (argc < 5) { + fprintf(stderr, + "Error: not enough arguments. Required:\n" + "1. Options for large table\n" + "2. Options for derived table\n" + "3. Filename containing large table\n" + "4. Filename for saving derived table\n"); + return 1; + } + + opts_large = argv[1]; + opts_small = argv[2]; + filename_large = argv[3]; + filename_small = argv[4]; + sprintf(description, "deriving %s from %s\n", opts_small, opts_large); + + nissy_setlogger(log_stderr); + + timerun(run, description); + + return 0; +} diff --git a/tools/001_derive_h48h0k2/derive_h48h0k2.c b/tools/001_derive_h48h0k2/derive_h48h0k2.c deleted file mode 100644 index 73fab2e..0000000 --- a/tools/001_derive_h48h0k2/derive_h48h0k2.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "../tool.h" - -uint64_t expected[21] = { - /* Base value is 8 */ - [0] = 5473562, - [1] = 34776317, - [2] = 68566704, - [3] = 8750867, -}; - -void run(void) { - derivedata_run(0, "tables/h48h0k2_derived", expected); -} - -int main(void) { - nissy_setlogger(log_stderr); - - timerun(run, "benchmark derivedata_h48 h = 0, k = 2"); - - return 0; -} diff --git a/tools/expected_distributions.h b/tools/expected_distributions.h index 27bd64a..535cab2 100644 --- a/tools/expected_distributions.h +++ b/tools/expected_distributions.h @@ -22,4 +22,12 @@ uint64_t expected_h48[12][9][21] = { [12] = 1673, }, }, + [1] = { + [2] = { + [0] = 6012079, + [1] = 45822302, + [2] = 142018732, + [3] = 41281787, + }, + }, }; diff --git a/tools/tool.h b/tools/tool.h index d9071fb..c44828d 100644 --- a/tools/tool.h +++ b/tools/tool.h @@ -14,10 +14,11 @@ static double timerun(void (*)(void), const char *); static void getfilename(const char *, const char *, char *); static void writetable(const char *, int64_t, const char *); static int64_t generatetable(const char *, const char *, char **); -static int64_t derivetable(uint8_t, char **); +static int64_t derivetable(const char *, const char *, const char *, char **); static int getdata(const char *, const char *, char **, const char *); static void gendata_run(const char *, const char *, uint64_t[static 21]); -static void derivedata_run(uint8_t, const char *, uint64_t[static 21]); +static void derivedata_run( + const char *, const char *, const char *, const char *); static void log_stderr(const char *str, ...) @@ -125,27 +126,30 @@ generatetable(const char *solver, const char *options, char **buf) } static int64_t -derivetable(uint8_t h, char **buf) +derivetable( + const char *opts_large, + const char *opts_small, + const char *filename_large, + char **buf +) { + uint8_t h; int64_t size, gensize; char *fulltable; - char options[20] = " ;2;20"; /* Only for k = 2 for now */ - options[0] = (char)(h + '0'); /* h = 10 not supported for now */ - - /* Support only b8 for now */ - if (getdata("h48", "11;2;20", &fulltable, "tables/h48h11k2_b8") != 0) { + if (getdata("h48", opts_large, &fulltable, filename_large) != 0) { printf("Error reading full table.\n"); return -1; } - size = nissy_datasize("h48", options); + size = nissy_datasize("h48", opts_small); if (size == -1) { printf("Error getting table size.\n"); free(fulltable); return -1; } + h = atoi(opts_small); /* TODO: use option parser */ *buf = malloc(size); gensize = gendata_h48_derive(h, fulltable, *buf); @@ -233,12 +237,17 @@ gendata_run_finish: } static void -derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) +derivedata_run( + const char *opts_large, + const char *opts_small, + const char *filename_large, + const char *filename_small +) { int64_t size; char *buf; - size = derivetable(h, &buf); + size = derivetable(opts_large, opts_small, filename_large, &buf); switch (size) { case -1: return; @@ -250,7 +259,7 @@ derivedata_run(uint8_t h, const char *filename, uint64_t expected[static 21]) printf("Succesfully generated %" PRId64 " bytes. " "See above for details on the tables.\n", size); - writetable(buf, size, filename); + writetable(buf, size, filename_small); break; } -- cgit v1.3 From 954a9f9100e8f30e0303a3815c4104526aceb4a0 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Fri, 27 Sep 2024 16:42:38 +0200 Subject: oopsie --- src/solvers/h48/gendata_h48.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/solvers/h48') diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index d7f4c92..75b7abf 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h @@ -389,7 +389,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) [8] = 10, [9] = 10, [10] = 10, - [11] = 8 + [11] = 10 }; uint8_t t, *table; -- cgit v1.3