aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nissy.c16
-rw-r--r--src/nissy.h4
-rw-r--r--src/solvers/h48/solve.h17
3 files changed, 29 insertions, 8 deletions
diff --git a/src/nissy.c b/src/nissy.c
index f933cab..5d009ba 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -489,6 +489,7 @@ nissy_solve(
489 unsigned maxmoves, 489 unsigned maxmoves,
490 unsigned maxsols, 490 unsigned maxsols,
491 int optimal, 491 int optimal,
492 int threads,
492 unsigned long long data_size, 493 unsigned long long data_size,
493 const char data[data_size], 494 const char data[data_size],
494 unsigned sols_size, 495 unsigned sols_size,
@@ -499,6 +500,7 @@ nissy_solve(
499 cube_t c; 500 cube_t c;
500 long long parse_ret; 501 long long parse_ret;
501 uint8_t h, k; 502 uint8_t h, k;
503 int t;
502 504
503 if (solver == NULL) { 505 if (solver == NULL) {
504 LOG("Error: 'solver' argument is NULL\n"); 506 LOG("Error: 'solver' argument is NULL\n");
@@ -522,10 +524,22 @@ nissy_solve(
522 return 0; 524 return 0;
523 } 525 }
524 526
527 t = threads == 0 ? THREADS : threads;
528 if (t < 0) {
529 LOG("solve: 'threads' is negative. Please provide a "
530 "number of threads between 1 and %d\n", THREADS);
531 return NISSY_ERROR_OPTIONS;
532 }
533 if (t > THREADS) {
534 LOG("solve: 'threads' is above the maximum value of %d\n",
535 THREADS);
536 return NISSY_ERROR_OPTIONS;
537 }
538
525 if (!strncmp(solver, "h48", 3)) { 539 if (!strncmp(solver, "h48", 3)) {
526 parse_ret = parse_h48_solver(solver, &h, &k); 540 parse_ret = parse_h48_solver(solver, &h, &k);
527 if (parse_ret == NISSY_OK) 541 if (parse_ret == NISSY_OK)
528 return solve_h48(c, minmoves, maxmoves, maxsols, 542 return solve_h48(c, minmoves, maxmoves, maxsols, t,
529 data_size, data, sols_size, sols, stats); 543 data_size, data, sols_size, sols, stats);
530 else 544 else
531 return parse_ret; 545 return parse_ret;
diff --git a/src/nissy.h b/src/nissy.h
index 8394fad..94c604c 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -259,6 +259,9 @@ Parameters:
259 maxsols - The maximum number of solutions. 259 maxsols - The maximum number of solutions.
260 optimal - If set to a non-negative value, the maximum number of moves 260 optimal - If set to a non-negative value, the maximum number of moves
261 above the optimal solution length. 261 above the optimal solution length.
262 threads - The number of threads to use. Must be less than or equalt to
263 the value of the compile-time constant THREADS. If set to 0,
264 the default value THREADS will be used.
262 data_size - The size of the data buffer. 265 data_size - The size of the data buffer.
263 data - The data for the solver. Can be computed with gendata. 266 data - The data for the solver. Can be computed with gendata.
264 sols_size - The size of the solutions buffer. 267 sols_size - The size of the solutions buffer.
@@ -286,6 +289,7 @@ nissy_solve(
286 unsigned maxmoves, 289 unsigned maxmoves,
287 unsigned maxsolutions, 290 unsigned maxsolutions,
288 int optimal, 291 int optimal,
292 int threads,
289 unsigned long long data_size, 293 unsigned long long data_size,
290 const char data[data_size], 294 const char data[data_size],
291 unsigned sols_size, 295 unsigned sols_size,
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