diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-18 16:35:17 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-10-18 16:35:17 +0200 |
| commit | 5216fb4be01e88f5b4928a69287e8f7ee3b3af5b (patch) | |
| tree | 24aa57a0e34c49e0e6307caf8cf830f8dd26ed49 /src/solvers/h48/solve.h | |
| parent | 3d6c73c33276ecedba86cb871b4b5a089571629b (diff) | |
| download | nissy-core-5216fb4be01e88f5b4928a69287e8f7ee3b3af5b.tar.gz nissy-core-5216fb4be01e88f5b4928a69287e8f7ee3b3af5b.zip | |
Add node and fallback benchmarking
Diffstat (limited to 'src/solvers/h48/solve.h')
| -rw-r--r-- | src/solvers/h48/solve.h | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 778155c..67c596b 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -17,6 +17,8 @@ typedef struct { | |||
| 17 | uint8_t nissbranch; | 17 | uint8_t nissbranch; |
| 18 | int8_t npremoves; | 18 | int8_t npremoves; |
| 19 | uint8_t premoves[MAXLEN]; | 19 | uint8_t premoves[MAXLEN]; |
| 20 | _Atomic long long *nodes_visited; | ||
| 21 | _Atomic long long *table_fallbacks; | ||
| 20 | } dfsarg_solveh48_t; | 22 | } dfsarg_solveh48_t; |
| 21 | 23 | ||
| 22 | STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint8_t); | 24 | STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint8_t); |
| @@ -24,8 +26,8 @@ STATIC uint32_t allowednextmove_h48(uint8_t *, uint8_t, uint8_t); | |||
| 24 | STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); | 26 | STATIC void solve_h48_appendsolution(dfsarg_solveh48_t *); |
| 25 | STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); | 27 | STATIC_INLINE bool solve_h48_stop(dfsarg_solveh48_t *); |
| 26 | STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); | 28 | STATIC int64_t solve_h48_dfs(dfsarg_solveh48_t *); |
| 27 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, | 29 | STATIC int64_t solve_h48(cube_t, int8_t, int8_t, int8_t, uint64_t, |
| 28 | int8_t, uint64_t, const void *, uint64_t, char *); | 30 | const void *, uint64_t, char *, long long [static NISSY_SIZE_SOLVE_STATS]); |
| 29 | 31 | ||
| 30 | STATIC uint32_t | 32 | STATIC uint32_t |
| 31 | allowednextmove_h48(uint8_t *moves, uint8_t n, uint8_t h48branch) | 33 | allowednextmove_h48(uint8_t *moves, uint8_t n, uint8_t h48branch) |
| @@ -103,6 +105,8 @@ solve_h48_stop(dfsarg_solveh48_t *arg) | |||
| 103 | int8_t cbound, cbound_inv, h48bound, h48bound_inv; | 105 | int8_t cbound, cbound_inv, h48bound, h48bound_inv; |
| 104 | int64_t coord, coord_inv; | 106 | int64_t coord, coord_inv; |
| 105 | 107 | ||
| 108 | (*arg->nodes_visited)++; | ||
| 109 | |||
| 106 | arg->nissbranch = MM_NORMAL; | 110 | arg->nissbranch = MM_NORMAL; |
| 107 | cbound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); | 111 | cbound = get_h48_cdata(arg->cube, arg->cocsepdata, &data); |
| 108 | if (cbound + arg->nmoves + arg->npremoves > arg->depth) | 112 | if (cbound + arg->nmoves + arg->npremoves > arg->depth) |
| @@ -120,6 +124,7 @@ solve_h48_stop(dfsarg_solveh48_t *arg) | |||
| 120 | 124 | ||
| 121 | if (arg->k == 2) { | 125 | if (arg->k == 2) { |
| 122 | if (h48bound == 0) { | 126 | if (h48bound == 0) { |
| 127 | (*arg->table_fallbacks)++; | ||
| 123 | h48bound = get_h48_pval( | 128 | h48bound = get_h48_pval( |
| 124 | arg->h48data_fallback, coord >> arg->h, 4); | 129 | arg->h48data_fallback, coord >> arg->h, 4); |
| 125 | } else { | 130 | } else { |
| @@ -136,6 +141,7 @@ solve_h48_stop(dfsarg_solveh48_t *arg) | |||
| 136 | h48bound_inv = get_h48_pval(arg->h48data, coord_inv, arg->k); | 141 | h48bound_inv = get_h48_pval(arg->h48data, coord_inv, arg->k); |
| 137 | if (arg->k == 2) { | 142 | if (arg->k == 2) { |
| 138 | if (h48bound_inv == 0) { | 143 | if (h48bound_inv == 0) { |
| 144 | (*arg->table_fallbacks)++; | ||
| 139 | h48bound_inv = get_h48_pval( | 145 | h48bound_inv = get_h48_pval( |
| 140 | arg->h48data_fallback, coord_inv >> arg->h, 4); | 146 | arg->h48data_fallback, coord_inv >> arg->h, 4); |
| 141 | } else { | 147 | } else { |
| @@ -209,16 +215,19 @@ solve_h48( | |||
| 209 | uint64_t data_size, | 215 | uint64_t data_size, |
| 210 | const void *data, | 216 | const void *data, |
| 211 | uint64_t solutions_size, | 217 | uint64_t solutions_size, |
| 212 | char *solutions | 218 | char *solutions, |
| 219 | long long stats[static NISSY_SIZE_SOLVE_STATS] | ||
| 213 | ) | 220 | ) |
| 214 | { | 221 | { |
| 215 | _Atomic int64_t nsols; | 222 | _Atomic int64_t nsols; |
| 223 | _Atomic long long nodes, fallbacks; | ||
| 216 | dfsarg_solveh48_t arg; | 224 | dfsarg_solveh48_t arg; |
| 217 | tableinfo_t info, fbinfo; | 225 | tableinfo_t info, fbinfo; |
| 218 | 226 | ||
| 219 | if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) | 227 | if(readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) |
| 220 | goto solve_h48_error_data; | 228 | goto solve_h48_error_data; |
| 221 | 229 | ||
| 230 | nodes = fallbacks = 0; | ||
| 222 | arg = (dfsarg_solveh48_t) { | 231 | arg = (dfsarg_solveh48_t) { |
| 223 | .cube = cube, | 232 | .cube = cube, |
| 224 | .inverse = inverse(cube), | 233 | .inverse = inverse(cube), |
| @@ -230,7 +239,9 @@ solve_h48( | |||
| 230 | .cocsepdata = (uint32_t *)((char *)data + INFOSIZE), | 239 | .cocsepdata = (uint32_t *)((char *)data + INFOSIZE), |
| 231 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, | 240 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, |
| 232 | .solutions_size = solutions_size, | 241 | .solutions_size = solutions_size, |
| 233 | .nextsol = &solutions | 242 | .nextsol = &solutions, |
| 243 | .nodes_visited = &nodes, | ||
| 244 | .table_fallbacks = &fallbacks | ||
| 234 | }; | 245 | }; |
| 235 | 246 | ||
| 236 | if (info.bits == 2) { | 247 | if (info.bits == 2) { |
| @@ -256,7 +267,11 @@ solve_h48( | |||
| 256 | solve_h48_dfs(&arg); | 267 | solve_h48_dfs(&arg); |
| 257 | } | 268 | } |
| 258 | **arg.nextsol = '\0'; | 269 | **arg.nextsol = '\0'; |
| 259 | (*arg.nextsol)++; | 270 | |
| 271 | stats[0] = nodes; | ||
| 272 | stats[1] = fallbacks; | ||
| 273 | LOG("Nodes visited: %lld\nTable fallbacks: %lld\n", nodes, fallbacks); | ||
| 274 | |||
| 260 | return nsols; | 275 | return nsols; |
| 261 | 276 | ||
| 262 | solve_h48_error_data: | 277 | solve_h48_error_data: |
