diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-14 11:59:22 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-12-14 11:59:22 +0100 |
| commit | 4a88a686d5e08404080ed6954b70c0db252aa220 (patch) | |
| tree | c1fb469d5a2a68c8e4651ad7837d3dd6fe2ff93e /shell/shell.c | |
| parent | 9ac266c76f39620d8343e46ca41cb09d1534384c (diff) | |
| download | nissy-core-4a88a686d5e08404080ed6954b70c0db252aa220.tar.gz nissy-core-4a88a686d5e08404080ed6954b70c0db252aa220.zip | |
Allow choosing number of threads when calling solve()
Diffstat (limited to 'shell/shell.c')
| -rw-r--r-- | shell/shell.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/shell/shell.c b/shell/shell.c index e548fd6..5a2d283 100644 --- a/shell/shell.c +++ b/shell/shell.c | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #define FLAG_MAXMOVES "-M" | 28 | #define FLAG_MAXMOVES "-M" |
| 29 | #define FLAG_OPTIMAL "-O" | 29 | #define FLAG_OPTIMAL "-O" |
| 30 | #define FLAG_MAXSOLUTIONS "-n" | 30 | #define FLAG_MAXSOLUTIONS "-n" |
| 31 | #define FLAG_THREADS "-t" | ||
| 31 | 32 | ||
| 32 | #define INFO_CUBEFORMAT(cube) cube " must be given in B32 format." | 33 | #define INFO_CUBEFORMAT(cube) cube " must be given in B32 format." |
| 33 | #define INFO_MOVESFORMAT "The accepted moves are U, D, R, L, F and B, " \ | 34 | #define INFO_MOVESFORMAT "The accepted moves are U, D, R, L, F and B, " \ |
| @@ -54,6 +55,7 @@ typedef struct { | |||
| 54 | unsigned maxmoves; | 55 | unsigned maxmoves; |
| 55 | unsigned optimal; | 56 | unsigned optimal; |
| 56 | unsigned maxsolutions; | 57 | unsigned maxsolutions; |
| 58 | unsigned threads; | ||
| 57 | } args_t; | 59 | } args_t; |
| 58 | 60 | ||
| 59 | static int64_t compose_exec(args_t *); | 61 | static int64_t compose_exec(args_t *); |
| @@ -88,6 +90,7 @@ static bool set_minmoves(int, char **, args_t *); | |||
| 88 | static bool set_maxmoves(int, char **, args_t *); | 90 | static bool set_maxmoves(int, char **, args_t *); |
| 89 | static bool set_optimal(int, char **, args_t *); | 91 | static bool set_optimal(int, char **, args_t *); |
| 90 | static bool set_maxsolutions(int, char **, args_t *); | 92 | static bool set_maxsolutions(int, char **, args_t *); |
| 93 | static bool set_threads(int, char **, args_t *); | ||
| 91 | static bool set_id(int, char **, args_t *); | 94 | static bool set_id(int, char **, args_t *); |
| 92 | 95 | ||
| 93 | static uint64_t rand64(void); | 96 | static uint64_t rand64(void); |
| @@ -113,6 +116,7 @@ struct { | |||
| 113 | OPTION(FLAG_MAXMOVES, 1, set_maxmoves), | 116 | OPTION(FLAG_MAXMOVES, 1, set_maxmoves), |
| 114 | OPTION(FLAG_OPTIMAL, 1, set_optimal), | 117 | OPTION(FLAG_OPTIMAL, 1, set_optimal), |
| 115 | OPTION(FLAG_MAXSOLUTIONS, 1, set_maxsolutions), | 118 | OPTION(FLAG_MAXSOLUTIONS, 1, set_maxsolutions), |
| 119 | OPTION(FLAG_THREADS, 1, set_threads), | ||
| 116 | OPTION(NULL, 0, NULL) | 120 | OPTION(NULL, 0, NULL) |
| 117 | }; | 121 | }; |
| 118 | 122 | ||
| @@ -193,9 +197,10 @@ struct { | |||
| 193 | "solve", | 197 | "solve", |
| 194 | "solve " FLAG_SOLVER " SOLVER" | 198 | "solve " FLAG_SOLVER " SOLVER" |
| 195 | "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " | 199 | "[" FLAG_MINMOVES " n] [" FLAG_MAXMOVES " N] " |
| 196 | FLAG_CUBE " CUBE", | 200 | FLAG_CUBE " CUBE" |
| 201 | FLAG_THREADS " T", | ||
| 197 | "Solve the given CUBE using SOLVER, " | 202 | "Solve the given CUBE using SOLVER, " |
| 198 | "using at least n and at most N moves. " | 203 | "using at least n and at most N moves, and T threads. " |
| 199 | INFO_CUBEFORMAT("CUBE"), | 204 | INFO_CUBEFORMAT("CUBE"), |
| 200 | solve_exec | 205 | solve_exec |
| 201 | ), | 206 | ), |
| @@ -475,7 +480,7 @@ solve_exec(args_t *args) | |||
| 475 | 480 | ||
| 476 | ret = nissy_solve( | 481 | ret = nissy_solve( |
| 477 | args->cube, args->str_solver, nissflag, args->minmoves, | 482 | args->cube, args->str_solver, nissflag, args->minmoves, |
| 478 | args->maxmoves, args->maxsolutions, args->optimal, | 483 | args->maxmoves, args->maxsolutions, args->optimal, args->threads, |
| 479 | size, buf, SOLUTIONS_BUFFER_SIZE, solutions, stats); | 484 | size, buf, SOLUTIONS_BUFFER_SIZE, solutions, stats); |
| 480 | 485 | ||
| 481 | free(buf); | 486 | free(buf); |
| @@ -557,6 +562,7 @@ parse_args(int argc, char **argv, args_t *args) | |||
| 557 | .maxmoves = 20, | 562 | .maxmoves = 20, |
| 558 | .optimal = -1, | 563 | .optimal = -1, |
| 559 | .maxsolutions = 1, | 564 | .maxsolutions = 1, |
| 565 | .threads = 0, | ||
| 560 | }; | 566 | }; |
| 561 | 567 | ||
| 562 | if (argc == 0) { | 568 | if (argc == 0) { |
| @@ -728,6 +734,12 @@ set_maxsolutions(int argc, char **argv, args_t *args) | |||
| 728 | return parse_uint(argv[0], &args->maxsolutions); | 734 | return parse_uint(argv[0], &args->maxsolutions); |
| 729 | } | 735 | } |
| 730 | 736 | ||
| 737 | static bool | ||
| 738 | set_threads(int argc, char **argv, args_t *args) | ||
| 739 | { | ||
| 740 | return parse_uint(argv[0], &args->threads); | ||
| 741 | } | ||
| 742 | |||
| 731 | void | 743 | void |
| 732 | log_stderr(const char *str, ...) | 744 | log_stderr(const char *str, ...) |
| 733 | { | 745 | { |
