aboutsummaryrefslogtreecommitdiff
path: root/src/solvers/h48
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-14 11:59:22 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-14 11:59:22 +0100
commit4a88a686d5e08404080ed6954b70c0db252aa220 (patch)
treec1fb469d5a2a68c8e4651ad7837d3dd6fe2ff93e /src/solvers/h48
parent9ac266c76f39620d8343e46ca41cb09d1534384c (diff)
downloadnissy-core-4a88a686d5e08404080ed6954b70c0db252aa220.tar.gz
nissy-core-4a88a686d5e08404080ed6954b70c0db252aa220.zip
Allow choosing number of threads when calling solve()
Diffstat (limited to 'src/solvers/h48')
-rw-r--r--src/solvers/h48/solve.h17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 8666007..0969c45 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -38,6 +38,7 @@ typedef struct {
38 int64_t nodes_visited; 38 int64_t nodes_visited;
39 int64_t table_fallbacks; 39 int64_t table_fallbacks;
40 int64_t table_lookups; 40 int64_t table_lookups;
41 int threads;
41 int ntasks; 42 int ntasks;
42 solve_h48_task_t *tasks; 43 solve_h48_task_t *tasks;
43 int thread_id; 44 int thread_id;
@@ -62,7 +63,7 @@ STATIC int64_t solve_h48_maketasks(
62 solve_h48_task_t [static STARTING_CUBES], int *); 63 solve_h48_task_t [static STARTING_CUBES], int *);
63STATIC void *solve_h48_runthread(void *); 64STATIC void *solve_h48_runthread(void *);
64STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t *); 65STATIC int64_t solve_h48_dfs(dfsarg_solve_h48_t *);
65STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, uint64_t, 66STATIC int64_t solve_h48(cube_t, int8_t, int8_t, uint64_t, int, uint64_t,
66 const void *, uint64_t, char *, long long [static NISSY_SIZE_SOLVE_STATS]); 67 const void *, uint64_t, char *, long long [static NISSY_SIZE_SOLVE_STATS]);
67 68
68STATIC int64_t 69STATIC int64_t
@@ -316,7 +317,7 @@ solve_h48_runthread(void *arg)
316 dfsarg = (dfsarg_solve_h48_t *)arg; 317 dfsarg = (dfsarg_solve_h48_t *)arg;
317 cube = dfsarg->start_cube; 318 cube = dfsarg->start_cube;
318 319
319 for (i = dfsarg->thread_id; i < dfsarg->ntasks; i += THREADS) { 320 for (i = dfsarg->thread_id; i < dfsarg->ntasks; i += dfsarg->threads) {
320 task = dfsarg->tasks[i]; 321 task = dfsarg->tasks[i];
321 memcpy(dfsarg->moves, task.moves, STARTING_MOVES); 322 memcpy(dfsarg->moves, task.moves, STARTING_MOVES);
322 dfsarg->cube = cube; 323 dfsarg->cube = cube;
@@ -407,6 +408,7 @@ solve_h48(
407 int8_t minmoves, 408 int8_t minmoves,
408 int8_t maxmoves, 409 int8_t maxmoves,
409 uint64_t maxsolutions, 410 uint64_t maxsolutions,
411 int threads,
410 uint64_t data_size, 412 uint64_t data_size,
411 const void *data, 413 const void *data,
412 uint64_t solutions_size, 414 uint64_t solutions_size,
@@ -461,7 +463,7 @@ solve_h48(
461 fallback2 = h48data + offset; 463 fallback2 = h48data + offset;
462 464
463 symmask = symmetry_mask(cube); 465 symmask = symmetry_mask(cube);
464 for (i = 0; i < THREADS; i++) { 466 for (i = 0; i < threads; i++) {
465 arg[i] = (dfsarg_solve_h48_t) { 467 arg[i] = (dfsarg_solve_h48_t) {
466 .start_cube = cube, 468 .start_cube = cube,
467 .cube = cube, 469 .cube = cube,
@@ -481,6 +483,7 @@ solve_h48(
481 .nodes_visited = 0, 483 .nodes_visited = 0,
482 .table_fallbacks = 0, 484 .table_fallbacks = 0,
483 .table_lookups = 0, 485 .table_lookups = 0,
486 .threads = threads,
484 .thread_id = i, 487 .thread_id = i,
485 .solutions_mutex = &solutions_mutex, 488 .solutions_mutex = &solutions_mutex,
486 }; 489 };
@@ -505,7 +508,7 @@ solve_h48(
505 if (*arg[0].nsols >= (int64_t)maxsolutions) 508 if (*arg[0].nsols >= (int64_t)maxsolutions)
506 goto solve_h48_done; 509 goto solve_h48_done;
507 510
508 for (i = 0; i < THREADS; i++) { 511 for (i = 0; i < threads; i++) {
509 arg[i].ntasks = ntasks; 512 arg[i].ntasks = ntasks;
510 arg[i].tasks = tasks; 513 arg[i].tasks = tasks;
511 } 514 }
@@ -520,12 +523,12 @@ solve_h48(
520 if (d >= 10) 523 if (d >= 10)
521 LOG("Found %" PRId64 " solutions, searching at depth %" 524 LOG("Found %" PRId64 " solutions, searching at depth %"
522 PRId8 "\n", nsols, d); 525 PRId8 "\n", nsols, d);
523 for (i = 0; i < THREADS; i++) { 526 for (i = 0; i < threads; i++) {
524 arg[i].depth = d; 527 arg[i].depth = d;
525 pthread_create( 528 pthread_create(
526 &thread[i], NULL, solve_h48_runthread, &arg[i]); 529 &thread[i], NULL, solve_h48_runthread, &arg[i]);
527 } 530 }
528 for (i = 0; i < THREADS; i++) 531 for (i = 0; i < threads; i++)
529 pthread_join(thread[i], NULL); 532 pthread_join(thread[i], NULL);
530 } 533 }
531 534
@@ -534,7 +537,7 @@ solve_h48_done:
534 goto solve_h48_error_solutions_buffer; 537 goto solve_h48_error_solutions_buffer;
535 538
536 nodes_visited = table_lookups = table_fallbacks = 0; 539 nodes_visited = table_lookups = table_fallbacks = 0;
537 for (i = 0; i < THREADS; i++) { 540 for (i = 0; i < threads; i++) {
538 nodes_visited += arg[i].nodes_visited; 541 nodes_visited += arg[i].nodes_visited;
539 table_fallbacks += arg[i].table_fallbacks; 542 table_fallbacks += arg[i].table_fallbacks;
540 table_lookups += arg[i].table_lookups; 543 table_lookups += arg[i].table_lookups;

Generated with cgit - Back to sebastiano.tronto.net