From a8c4da5b955eab2eed9ebb03ee4b1212ec6fe042 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Sat, 20 Nov 2021 16:08:43 +0100 Subject: Multithreading seems to be working now, it was easier than expected! --- src/commands.c | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'src/commands.c') diff --git a/src/commands.c b/src/commands.c index 10e4eb8..b089a1c 100644 --- a/src/commands.c +++ b/src/commands.c @@ -28,7 +28,7 @@ Command solve_cmd = { .name = "solve", .usage = "solve STEP [OPTIONS] SCRAMBLE", - .description = "Solve a step", + .description = "Solve a step; see command steps for a list of steps", .parse_args = solve_parse_args, .exec = solve_exec }; @@ -116,6 +116,7 @@ solve_parse_args(int c, char **v) a->opts->min_moves = 0; a->opts->max_moves = 20; a->opts->max_solutions = 1; + a->opts->nthreads = 1; a->opts->optimal_only = false; a->opts->can_niss = false; a->opts->verbose = false; @@ -127,7 +128,8 @@ solve_parse_args(int c, char **v) val = strtol(v[++i], NULL, 10); if (val < 0 || val > 100) { fprintf(stderr, - "Invalid min number of moves.\n"); + "Invalid min number of moves" + "(0 <= m <= 100).\n"); return a; } a->opts->min_moves = val; @@ -135,10 +137,20 @@ solve_parse_args(int c, char **v) val = strtol(v[++i], NULL, 10); if (val < 0 || val > 100) { fprintf(stderr, - "Invalid max number of moves.\n"); + "Invalid max number of moves" + "(0 <= M <= 100).\n"); return a; } a->opts->max_moves = val; + } else if (!strcmp(v[i], "-t")) { + val = strtol(v[++i], NULL, 10); + if (val < 1 || val > 64) { + fprintf(stderr, + "Invalid number of threads." + "1 <= t <= 64\n"); + return a; + } + a->opts->nthreads = val; } else if (!strcmp(v[i], "-s")) { val = strtol(v[++i], NULL, 10); if (val < 1 || val > 1000000) { @@ -255,11 +267,19 @@ print_exec(CommandArgs *args) static void help_exec(CommandArgs *args) { - /* TODO: print full nissy manpage */ if (args->command == NULL) { - printf("Type help COMMAND for information on a "); - printf("specific command.\n"); - printf("A more complete manual page is work in progress.\n"); + printf( + "Use the nissy command \"help COMMAND\" for a short " + "description of a specific command.\n" + "Use the nissy command \"commands\" for a list of " + "available commands.\n" + "See the manual page for more details. The manual" + " page is available with \"man nissy\" on a UNIX" + " system (such a Linux or MacOS) or in pdf and html" + " format in the docs folder.\n" + "Nissy is available for free at " + "https://github.com/sebastianotronto/nissy" + ); } else { printf("Command %s: %s\nusage: %s\n", args->command->name, args->command->description, args->command->usage); -- cgit v1.3