diff options
Diffstat (limited to 'src/solvers')
| -rw-r--r-- | src/solvers/h48/solve.h | 25 | ||||
| -rw-r--r-- | src/solvers/h48/solve_multithread.h | 23 |
2 files changed, 36 insertions, 12 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: |
diff --git a/src/solvers/h48/solve_multithread.h b/src/solvers/h48/solve_multithread.h index 2755372..394350e 100644 --- a/src/solvers/h48/solve_multithread.h +++ b/src/solvers/h48/solve_multithread.h | |||
| @@ -20,8 +20,8 @@ STATIC void copy_queue(task_queue_t *, task_queue_t *, int, _Atomic int64_t *); | |||
| 20 | STATIC void *start_thread(void *); | 20 | STATIC void *start_thread(void *); |
| 21 | STATIC int64_t solve_h48_bfs(dfsarg_solveh48_t *, task_queue_t *, int8_t); | 21 | STATIC int64_t solve_h48_bfs(dfsarg_solveh48_t *, task_queue_t *, int8_t); |
| 22 | STATIC int64_t solve_h48_single(dfsarg_solveh48_t *, task_queue_t *); | 22 | STATIC int64_t solve_h48_single(dfsarg_solveh48_t *, task_queue_t *); |
| 23 | STATIC int64_t solve_h48_multithread(cube_t, int8_t, int8_t, int8_t, | 23 | STATIC int64_t solve_h48_multithread(cube_t, int8_t, int8_t, int8_t, uint64_t, |
| 24 | uint64_t, const void *, uint64_t, char *); | 24 | const void *, uint64_t, char *, long long [static NISSY_SIZE_SOLVE_STATS]); |
| 25 | 25 | ||
| 26 | STATIC void | 26 | STATIC void |
| 27 | solve_h48_appendsolution_thread(dfsarg_solveh48_t *arg, task_queue_t *tq) | 27 | solve_h48_appendsolution_thread(dfsarg_solveh48_t *arg, task_queue_t *tq) |
| @@ -255,10 +255,12 @@ solve_h48_multithread( | |||
| 255 | uint64_t data_size, | 255 | uint64_t data_size, |
| 256 | const void *data, | 256 | const void *data, |
| 257 | uint64_t solutions_size, | 257 | uint64_t solutions_size, |
| 258 | char *solutions | 258 | char *solutions, |
| 259 | long long stats[static NISSY_SIZE_SOLVE_STATS] | ||
| 259 | ) | 260 | ) |
| 260 | { | 261 | { |
| 261 | _Atomic int64_t nsols = 0; | 262 | _Atomic int64_t nsols = 0; |
| 263 | _Atomic long long nodes, fallbacks; | ||
| 262 | int p_depth = 0; | 264 | int p_depth = 0; |
| 263 | dfsarg_solveh48_t arg; | 265 | dfsarg_solveh48_t arg; |
| 264 | tableinfo_t info, fbinfo; | 266 | tableinfo_t info, fbinfo; |
| @@ -267,6 +269,7 @@ solve_h48_multithread( | |||
| 267 | if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) | 269 | if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) |
| 268 | goto solve_h48_multithread_error_data; | 270 | goto solve_h48_multithread_error_data; |
| 269 | 271 | ||
| 272 | nodes = fallbacks = 0; | ||
| 270 | arg = (dfsarg_solveh48_t){ | 273 | arg = (dfsarg_solveh48_t){ |
| 271 | .cube = cube, | 274 | .cube = cube, |
| 272 | .inverse = inverse(cube), | 275 | .inverse = inverse(cube), |
| @@ -279,7 +282,9 @@ solve_h48_multithread( | |||
| 279 | .cocsepdata = (uint32_t *)((char *)data + INFOSIZE), | 282 | .cocsepdata = (uint32_t *)((char *)data + INFOSIZE), |
| 280 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, | 283 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, |
| 281 | .solutions_size = solutions_size, | 284 | .solutions_size = solutions_size, |
| 282 | .nextsol = &solutions | 285 | .nextsol = &solutions, |
| 286 | .nodes_visited = &nodes, | ||
| 287 | .table_fallbacks = &fallbacks | ||
| 283 | }; | 288 | }; |
| 284 | 289 | ||
| 285 | if (info.bits == 2) { | 290 | if (info.bits == 2) { |
| @@ -301,7 +306,7 @@ solve_h48_multithread( | |||
| 301 | task_queue_t nq; | 306 | task_queue_t nq; |
| 302 | init_queue(&nq); | 307 | init_queue(&nq); |
| 303 | 308 | ||
| 304 | for (int i = 0; i < THREADS; i++){ | 309 | for (int i = 0; i < THREADS; i++) { |
| 305 | pthread_create(&threads[i], NULL, &start_thread, &nq); | 310 | pthread_create(&threads[i], NULL, &start_thread, &nq); |
| 306 | } | 311 | } |
| 307 | 312 | ||
| @@ -323,11 +328,15 @@ solve_h48_multithread( | |||
| 323 | atomic_store(&nq.terminate, true); | 328 | atomic_store(&nq.terminate, true); |
| 324 | pthread_cond_broadcast(&nq.cond); | 329 | pthread_cond_broadcast(&nq.cond); |
| 325 | 330 | ||
| 326 | for (int i = 0; i < THREADS; i++){ | 331 | for (int i = 0; i < THREADS; i++) { |
| 327 | pthread_join(threads[i], NULL); | 332 | pthread_join(threads[i], NULL); |
| 328 | } | 333 | } |
| 329 | **arg.nextsol = '\0'; | 334 | **arg.nextsol = '\0'; |
| 330 | (*arg.nextsol)++; | 335 | |
| 336 | stats[0] = nodes; | ||
| 337 | stats[1] = fallbacks; | ||
| 338 | LOG("Nodes visited: %lld\nTable fallbacks: %lld\n", nodes, fallbacks); | ||
| 339 | |||
| 331 | return nsols; | 340 | return nsols; |
| 332 | 341 | ||
| 333 | solve_h48_multithread_error_data: | 342 | solve_h48_multithread_error_data: |
