diff options
Diffstat (limited to 'src/solvers/h48/solve_multithread.h')
| -rw-r--r-- | src/solvers/h48/solve_multithread.h | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/src/solvers/h48/solve_multithread.h b/src/solvers/h48/solve_multithread.h index 394350e..72f519e 100644 --- a/src/solvers/h48/solve_multithread.h +++ b/src/solvers/h48/solve_multithread.h | |||
| @@ -11,6 +11,8 @@ typedef struct { | |||
| 11 | pthread_cond_t cond; | 11 | pthread_cond_t cond; |
| 12 | pthread_cond_t active_cond; | 12 | pthread_cond_t active_cond; |
| 13 | atomic_bool terminate; | 13 | atomic_bool terminate; |
| 14 | _Atomic long long nodes_visited_global; | ||
| 15 | _Atomic long long table_fallbacks_global; | ||
| 14 | } task_queue_t; | 16 | } task_queue_t; |
| 15 | 17 | ||
| 16 | STATIC void solve_h48_appendsolution_thread(dfsarg_solveh48_t *, task_queue_t *); | 18 | STATIC void solve_h48_appendsolution_thread(dfsarg_solveh48_t *, task_queue_t *); |
| @@ -128,6 +130,8 @@ start_thread(void *arg) | |||
| 128 | pthread_mutex_unlock(&queue->mutex); | 130 | pthread_mutex_unlock(&queue->mutex); |
| 129 | 131 | ||
| 130 | solve_h48_single(&task, queue); | 132 | solve_h48_single(&task, queue); |
| 133 | queue->nodes_visited_global += task.nodes_visited; | ||
| 134 | queue->table_fallbacks_global += task.table_fallbacks; | ||
| 131 | 135 | ||
| 132 | pthread_mutex_lock(&queue->mutex); | 136 | pthread_mutex_lock(&queue->mutex); |
| 133 | queue->active--; | 137 | queue->active--; |
| @@ -243,6 +247,9 @@ solve_h48_single(dfsarg_solveh48_t *arg, task_queue_t *tq) | |||
| 243 | } | 247 | } |
| 244 | } | 248 | } |
| 245 | } | 249 | } |
| 250 | |||
| 251 | arg->nodes_visited = nextarg.nodes_visited; | ||
| 252 | arg->table_fallbacks = nextarg.table_fallbacks; | ||
| 246 | return ret; | 253 | return ret; |
| 247 | } | 254 | } |
| 248 | 255 | ||
| @@ -260,7 +267,6 @@ solve_h48_multithread( | |||
| 260 | ) | 267 | ) |
| 261 | { | 268 | { |
| 262 | _Atomic int64_t nsols = 0; | 269 | _Atomic int64_t nsols = 0; |
| 263 | _Atomic long long nodes, fallbacks; | ||
| 264 | int p_depth = 0; | 270 | int p_depth = 0; |
| 265 | dfsarg_solveh48_t arg; | 271 | dfsarg_solveh48_t arg; |
| 266 | tableinfo_t info, fbinfo; | 272 | tableinfo_t info, fbinfo; |
| @@ -269,7 +275,6 @@ solve_h48_multithread( | |||
| 269 | if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) | 275 | if (readtableinfo_n(data_size, data, 2, &info) != NISSY_OK) |
| 270 | goto solve_h48_multithread_error_data; | 276 | goto solve_h48_multithread_error_data; |
| 271 | 277 | ||
| 272 | nodes = fallbacks = 0; | ||
| 273 | arg = (dfsarg_solveh48_t){ | 278 | arg = (dfsarg_solveh48_t){ |
| 274 | .cube = cube, | 279 | .cube = cube, |
| 275 | .inverse = inverse(cube), | 280 | .inverse = inverse(cube), |
| @@ -283,8 +288,8 @@ solve_h48_multithread( | |||
| 283 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, | 288 | .h48data = (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE, |
| 284 | .solutions_size = solutions_size, | 289 | .solutions_size = solutions_size, |
| 285 | .nextsol = &solutions, | 290 | .nextsol = &solutions, |
| 286 | .nodes_visited = &nodes, | 291 | .nodes_visited = 0, |
| 287 | .table_fallbacks = &fallbacks | 292 | .table_fallbacks = 0 |
| 288 | }; | 293 | }; |
| 289 | 294 | ||
| 290 | if (info.bits == 2) { | 295 | if (info.bits == 2) { |
| @@ -306,6 +311,7 @@ solve_h48_multithread( | |||
| 306 | task_queue_t nq; | 311 | task_queue_t nq; |
| 307 | init_queue(&nq); | 312 | init_queue(&nq); |
| 308 | 313 | ||
| 314 | nq.nodes_visited_global = nq.table_fallbacks_global = 0; | ||
| 309 | for (int i = 0; i < THREADS; i++) { | 315 | for (int i = 0; i < THREADS; i++) { |
| 310 | pthread_create(&threads[i], NULL, &start_thread, &nq); | 316 | pthread_create(&threads[i], NULL, &start_thread, &nq); |
| 311 | } | 317 | } |
| @@ -333,13 +339,12 @@ solve_h48_multithread( | |||
| 333 | } | 339 | } |
| 334 | **arg.nextsol = '\0'; | 340 | **arg.nextsol = '\0'; |
| 335 | 341 | ||
| 336 | stats[0] = nodes; | 342 | stats[0] = nq.nodes_visited_global; |
| 337 | stats[1] = fallbacks; | 343 | stats[1] = nq.table_fallbacks_global; |
| 338 | LOG("Nodes visited: %lld\nTable fallbacks: %lld\n", nodes, fallbacks); | 344 | LOG("Nodes visited: %lld\nTable fallbacks: %lld\n", |
| 345 | nq.nodes_visited_global, nq.table_fallbacks_global); | ||
| 339 | 346 | ||
| 340 | return nsols; | 347 | return nsols; |
| 341 | 348 | ||
| 342 | solve_h48_multithread_error_data: | 349 | solve_h48_multithread_error_data: LOG("solve_h48: error reading table\n"); return NISSY_ERROR_DATA; |
| 343 | LOG("solve_h48: error reading table\n"); | ||
| 344 | return NISSY_ERROR_DATA; | ||
| 345 | } | 350 | } |
