h48

A prototype for an optimal Rubik's cube solver, work in progress.
git clone https://git.tronto.net/h48
Download | Log | Files | Refs | README | LICENSE

commit 3485be851f4fff1c9c6fe621f0619d2b4103bc06
parent 691da8f06614418ed847bdeefa4e708c372a3ecf
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Sat, 19 Apr 2025 12:28:52 +0200

Improved logging, especially for solve

Diffstat:
Msrc/core/io_moves.h | 2+-
Msrc/core/moves.h | 19-------------------
Msrc/core/transform.h | 4++--
Msrc/nissy.c | 78++++++++++++++++++++++++++++++++++++------------------------------------------
Msrc/solvers/coord/gendata.h | 9+++++----
Msrc/solvers/coord/solve.h | 30++++++++++++++++--------------
Msrc/solvers/coord/utils.h | 2+-
Msrc/solvers/h48/gendata_cocsep.h | 2+-
Msrc/solvers/h48/gendata_h48.h | 50+++++++++++++++++++++++++++++---------------------
Msrc/solvers/h48/solve.h | 21+++++++++++----------
Msrc/solvers/solutions.h | 18++++++++++--------
Msrc/utils/math.h | 4++--
12 files changed, 114 insertions(+), 125 deletions(-)

diff --git a/src/core/io_moves.h b/src/core/io_moves.h @@ -14,7 +14,7 @@ STATIC int64_t writemoves(size_t n, const uint8_t [n], size_t m, char [m]); if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ break; \ if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ - LOG("Error: unknown move '%c'\n", *VAR_B); \ + LOG("Unknown move: %c\n", *VAR_B); \ return RET_ERROR; \ } \ if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ diff --git a/src/core/moves.h b/src/core/moves.h @@ -17,25 +17,6 @@ STATIC bool are_lastmoves_singlecw(size_t n, const uint8_t [n]); STATIC cube_t applymoves(cube_t, const char *); -#define FOREACH_READMOVE(ARG_BUF, ARG_MOVE, ARG_C, ARG_MAX, \ - RET_ERROR, ARG_ACTION) \ - const char *VAR_B; \ - uint8_t VAR_MOVE_NOMOD, VAR_MOD; \ - for (VAR_B = ARG_BUF, ARG_C = 0; *VAR_B != '\0'; VAR_B++, ARG_C++) { \ - while (*VAR_B == ' ' || *VAR_B == '\t' || *VAR_B == '\n') \ - VAR_B++; \ - if (*VAR_B == '\0' || ARG_C == ARG_MAX) \ - break; \ - if ((VAR_MOVE_NOMOD = readmove(*VAR_B)) == UINT8_ERROR) { \ - LOG("Error: unknown move '%c'\n", *VAR_B); \ - return RET_ERROR; \ - } \ - if ((VAR_MOD = readmodifier(*(VAR_B+1))) != 0) \ - VAR_B++; \ - ARG_MOVE = VAR_MOVE_NOMOD + VAR_MOD; \ - ARG_ACTION \ - } - STATIC_INLINE bool allowednextmove(uint8_t m1, uint8_t m2) { diff --git a/src/core/transform.h b/src/core/transform.h @@ -126,7 +126,7 @@ transform_edges(cube_t c, uint8_t t) case TRANS_BLm: return TRANS_EDGES_MIRRORED(BLm, c); default: - LOG("transform error, unknown transformation %" PRIu8 "\n", t); + LOG("transform error: unknown transformation %" PRIu8 "\n", t); return ZERO_CUBE; } } @@ -353,7 +353,7 @@ applytrans(cube_t cube, const char *buf) t = readtrans(buf); if (t == UINT8_ERROR) - LOG("Unknown transformation '%s'\n", buf); + LOG("Unknown transformation: %s\n", buf); return transform(cube, t); } diff --git a/src/nissy.c b/src/nissy.c @@ -60,7 +60,7 @@ parse_h48_solver(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) parse_h48_solver_error: *h = 0; *k = 0; - LOG("Error parsing solver: must be in \"h48h*k*\" format," + LOG("Error parsing H48 solver: must be in \"h48h*k*\" format," " but got %s\n", fullbuf); return NISSY_ERROR_INVALID_SOLVER; } @@ -72,7 +72,7 @@ checkdata(const char *buf, const tableinfo_t info[static 1]) if (my_strnlen(info->solver, INFO_SOLVER_STRLEN) == INFO_SOLVER_STRLEN) { - LOG("checkdata: error reading table info\n"); + LOG("[checkdata] Error reading table info\n"); return false; } else if (!strncmp(info->solver, "cocsep", 6)) { getdistribution_cocsep( @@ -88,7 +88,7 @@ checkdata(const char *buf, const tableinfo_t info[static 1]) } else if (!strncmp(info->solver, "coord helper table for ", 23)) { return true; } else { - LOG("checkdata: unknown solver %s\n", info->solver); + LOG("[checkdata] unknown solver %s\n", info->solver); return false; } @@ -154,7 +154,7 @@ nissy_compose( c = readcube("B32", cube); if (!isconsistent(c)) { - LOG("Error in nissy_compose: given cube is invalid\n"); + LOG("[compose] Error: the given cube is invalid\n"); err = NISSY_ERROR_INVALID_CUBE; goto nissy_compose_error; } @@ -162,7 +162,7 @@ nissy_compose( p = readcube("B32", permutation); if (!isconsistent(p)) { - LOG("Error in nissy_compose: given permutation is invalid\n"); + LOG("[compose] Error: given permutation is invalid\n"); err = NISSY_ERROR_INVALID_CUBE; goto nissy_compose_error; } @@ -170,7 +170,7 @@ nissy_compose( res = compose(c, p); if (!isconsistent(res)) { - LOG("Unknown error: resulting cube is invalid\n"); + LOG("[compose] Unknown error: resulting cube is invalid\n"); err = NISSY_ERROR_UNKNOWN; goto nissy_compose_error; } @@ -194,7 +194,7 @@ nissy_inverse( c = readcube("B32", cube); if (iserror(c)) { - LOG("Error in nissy_inverse: given cube is invalid\n"); + LOG("[inverse] Error: the given cube is invalid\n"); err = NISSY_ERROR_INVALID_CUBE; goto nissy_inverse_error; } @@ -202,7 +202,7 @@ nissy_inverse( res = inverse(c); if (!isconsistent(res)) { - LOG("Unknown error: inverted cube is invalid\n"); + LOG("[inverse] Unknown error: inverted cube is invalid\n"); err = NISSY_ERROR_UNKNOWN; goto nissy_inverse_error; } @@ -225,7 +225,7 @@ nissy_applymoves( long long err; if (moves == NULL) { - LOG("Error: 'moves' argument is NULL\n"); + LOG("[applymoves] Error: 'moves' argument is NULL\n"); err = NISSY_ERROR_NULL_POINTER; goto nissy_applymoves_error; } @@ -233,7 +233,7 @@ nissy_applymoves( c = readcube("B32", cube); if (!isconsistent(c)) { - LOG("Error in nissy_applymoves: given cube is invalid\n"); + LOG("[applymoves] Error: given cube is invalid\n"); err = NISSY_ERROR_INVALID_CUBE; goto nissy_applymoves_error; } @@ -266,7 +266,7 @@ nissy_applytrans( c = readcube("B32", cube); if (!isconsistent(c)) { - LOG("Error in nissy_applytrans: given cube is invalid\n"); + LOG("[applytrans] Error: given cube is invalid\n"); err = NISSY_ERROR_INVALID_CUBE; goto nissy_applytrans_error; } @@ -299,19 +299,19 @@ nissy_convert( long long err; if (format_in == NULL) { - LOG("Error: 'format_in' argument is NULL\n"); + LOG("[convert] Error: 'format_in' argument is NULL\n"); err = NISSY_ERROR_NULL_POINTER; goto nissy_convert_error; } if (format_out == NULL) { - LOG("Error: 'format_out' argument is NULL\n"); + LOG("[convert] Error: 'format_out' argument is NULL\n"); err = NISSY_ERROR_NULL_POINTER; goto nissy_convert_error; } if (cube_string == NULL) { - LOG("Error: 'cube_string' argument is NULL\n"); + LOG("[convert] Error: 'cube_string' argument is NULL\n"); err = NISSY_ERROR_NULL_POINTER; goto nissy_convert_error; } @@ -344,7 +344,7 @@ nissy_getcube( cube_t c; if (options == NULL) { - LOG("Error: 'options' argument is NULL\n"); + LOG("[getcube] Error: 'options' argument is NULL\n"); return NISSY_ERROR_NULL_POINTER; } @@ -355,8 +355,8 @@ nissy_getcube( c = getcube(ep, eo, cp, co); if (!isconsistent(c)) { - LOG("Error: could not get cube with ep=%lld, eo=%lld, " - "cp=%lld, co=%lld.\n", ep, eo, cp, co); + LOG("[getcube] Error: could not get cube with ep=%lld, " + "eo=%lld, cp=%lld, co=%lld.\n", ep, eo, cp, co); return NISSY_ERROR_OPTIONS; } @@ -374,7 +374,7 @@ nissy_datainfo( long long ret; if ((size_t)data % 8 != 0) { - LOG("nissy_datainfo: buffere is not 8-byte aligned\n"); + LOG("[datainfo] Error: buffer is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } @@ -429,7 +429,7 @@ nissy_dataid(const char *solver, char dataid[static NISSY_SIZE_DATAID]) } else if (!strncmp(solver, "coord_", 6)) { return dataid_coord(solver+6, dataid); } else { - LOG("gendata: unknown solver %s\n", solver); + LOG("[gendata] Unknown solver %s\n", solver); return NISSY_ERROR_INVALID_SOLVER; } } @@ -469,12 +469,12 @@ nissy_gendata_unsafe( gendata_h48_arg_t arg; if (solver == NULL) { - LOG("Error: 'solver' argument is NULL\n"); + LOG("[gendata] Error: 'solver' argument is NULL\n"); return NISSY_ERROR_NULL_POINTER; } if ((size_t)data % 8 != 0) { - LOG("nissy_gendata: buffere is not 8-byte aligned\n"); + LOG("[gendata] Error: buffer is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } @@ -489,7 +489,7 @@ nissy_gendata_unsafe( } else if (!strncmp(solver, "coord_", 6)) { return gendata_coord_dispatch(solver+6, data); } else { - LOG("gendata: unknown solver %s\n", solver); + LOG("[gendata] Unknown solver %s\n", solver); return NISSY_ERROR_INVALID_SOLVER; } } @@ -505,7 +505,7 @@ nissy_checkdata( int64_t err; if ((size_t)data % 8 != 0) { - LOG("nissy_checkdata: buffere is not 8-byte aligned\n"); + LOG("[checkdata] Error: buffer is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } @@ -514,8 +514,8 @@ nissy_checkdata( buf += info.next, data_size -= info.next) { if (!checkdata(buf, &info)) { - LOG("Error: data for solver '%s' is corrupted!\n", - info.solver); + LOG("[checkdata] Error: data for solver '%s' is " + "corrupted!\n", info.solver); return NISSY_ERROR_DATA; } @@ -549,44 +549,38 @@ nissy_solve( int t; if (solver == NULL) { - LOG("Error: 'solver' argument is NULL\n"); + LOG("[solve] Error: 'solver' argument is NULL\n"); return NISSY_ERROR_NULL_POINTER; } c = readcube_B32(cube); if (!isconsistent(c)) { - LOG("solve: cube is invalid\n"); + LOG("[solve] Error: cube is invalid\n"); return NISSY_ERROR_INVALID_CUBE; } if (!issolvable(c)) { /* TODO: this is step-dependent */ - LOG("solve: cube is not solvable\n"); + LOG("[solve] Error: cube is not solvable\n"); return NISSY_ERROR_UNSOLVABLE_CUBE; } /* TODO: checks for minmoves, maxmoves, nissflag */ if (maxsols == 0) { - LOG("solve: 'maxsols' is 0, returning no solution\n"); + LOG("[solve] 'maxsols' is 0, returning no solution\n"); return 0; } - t = threads == 0 ? THREADS : threads; - if (t < 0) { - LOG("solve: 'threads' is negative. Please provide a " - "number of threads between 1 and %d\n", THREADS); - return NISSY_ERROR_OPTIONS; - } - if (t > THREADS) { - LOG("solve: 'threads' is above the maximum value of %d\n", - THREADS); - return NISSY_ERROR_OPTIONS; - } + if (threads > THREADS) + LOG("[solve] Selected number of threads (%u) is above the " + "maximum value (%d), using %d threads instead\n", + threads, THREADS, THREADS); + t = threads == 0 ? THREADS : MIN(THREADS, threads); if ((size_t)data % 8 != 0) { - LOG("nissy_solve: buffere is not 8-byte aligned\n"); + LOG("[solve] Error: data buffer is not 8-byte aligned\n"); return NISSY_ERROR_DATA; } @@ -601,7 +595,7 @@ nissy_solve( minmoves, maxmoves, maxsols, optimal, t, data_size, data, sols_size, sols); } else { - LOG("solve: unknown solver '%s'\n", solver); + LOG("[solve] Error: unknown solver '%s'\n", solver); return NISSY_ERROR_INVALID_SOLVER; } } diff --git a/src/solvers/coord/gendata.h b/src/solvers/coord/gendata.h @@ -22,7 +22,7 @@ gendata_coord_dispatch(const char *coordstr, void *buf) parse_coord_and_axis(strlen(coordstr), coordstr, &coord, NULL); if (coord == NULL) { - LOG("Could not parse coordinate '%s'\n", coordstr); + LOG("Error: could not parse coordinate '%s'\n", coordstr); return NISSY_ERROR_INVALID_SOLVER; } @@ -82,7 +82,7 @@ gendata_coord_return_size: return ninfo * INFOSIZE + coord_dsize + tablesize; gendata_coord_error: - LOG("An unexpected error occurred when generating the data.\n"); + LOG("Unexpected error generating coordinate data\n"); return 0; } @@ -136,8 +136,9 @@ genptable_coord( } tot += t; info.distribution[d] = t; - LOG("Depth %" PRIu64 ": found %" PRIu64 " (%" PRIu64 " of %" - PRIu64 ")\n", d, t, tot, coord->max); + LOG("[%s gendata] Depth %" PRIu64 ": found %" PRIu64 " (%" + PRIu64 " of %" PRIu64 ")\n", + coord->name, d, t, tot, coord->max); } info.maxvalue = d-1; diff --git a/src/solvers/coord/solve.h b/src/solvers/coord/solve.h @@ -121,7 +121,8 @@ solve_coord_dfs(dfsarg_solve_coord_t arg[static 1]) if (!coord_solution_admissible(arg)) return 0; return appendsolution(arg->solution_moves, - arg->solution_settings, arg->solution_list, true); + arg->solution_settings, arg->solution_list, true, + arg->coord->name); } if (solve_coord_dfs_stop(arg)) @@ -220,12 +221,13 @@ solve_coord_dispatch( strlen(coord_and_axis), coord_and_axis, &coord, &axis); if (coord == NULL) { - LOG("Could not parse coordinate from '%s'\n", coord_and_axis); + LOG("Error: could not parse coordinate from '%s'\n", + coord_and_axis); return NISSY_ERROR_INVALID_SOLVER; } if (axis == UINT8_ERROR) { - LOG("Could not parse axis from '%s'\n", coord_and_axis); + LOG("Error: could not parse axis from '%s'\n", coord_and_axis); return NISSY_ERROR_INVALID_SOLVER; } @@ -316,8 +318,8 @@ solve_coord( }; if (coord->coord(c, coord_data) == 0) { - if (minmoves == 0 && !appendsolution( - &solution_moves, &solution_settings, &solution_list, true)) + if (minmoves == 0 && !appendsolution(&solution_moves, + &solution_settings, &solution_list, true, coord->name)) goto solve_coord_error_buffer; goto solve_coord_done; } @@ -327,18 +329,17 @@ solve_coord( !solutions_done(&solution_list, &solution_settings, d); d++ ) { - if (d >= 10) - LOG("Found %" PRIu64 " solutions, searching at depth %" - PRId8 "\n", solution_list.nsols, d); + if (d >= 12) + LOG("[%s solve] Found %" PRIu64 " solutions, " + "searching at depth %" PRId8 "\n", + coord->name, solution_list.nsols, d); arg.target_depth = d; solution_moves_reset(arg.solution_moves); ndepth = solve_coord_dfs(&arg); - if (ndepth < 0) { - LOG("Error %" PRId64 "\n", ndepth); + if (ndepth < 0) return ndepth; - } solution_list.nsols += (uint64_t)ndepth; } @@ -347,14 +348,15 @@ solve_coord_done: return (int64_t)solution_list.nsols; solve_coord_error_data: - LOG("solve_coord: error reading table\n"); + LOG("[%s solve] Error reading table\n", coord->name); return NISSY_ERROR_DATA; solve_coord_error_buffer: - LOG("Could not append solution to buffer: size too small\n"); + LOG("[%s solve] Error appending solution to buffer: size too small\n", + coord->name); return NISSY_ERROR_BUFFER_SIZE; solve_coord_error_unsolvable: - LOG("Cube not ready for solving %s\n", coord->name); + LOG("[%s solve] Error: cube not ready\n", coord->name); return NISSY_ERROR_UNSOLVABLE_CUBE; } diff --git a/src/solvers/coord/utils.h b/src/solvers/coord/utils.h @@ -59,7 +59,7 @@ dataid_coord(const char *ca, char dataid[static NISSY_SIZE_DATAID]) parse_coord_and_axis(strlen(ca), ca, &c, NULL); if (c == NULL) { - LOG("dataid_coord: cannot parse coordinate from '%s'\n", ca); + LOG("Error: cannot parse coordinate from '%s'\n", ca); return NISSY_ERROR_INVALID_SOLVER; } diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h @@ -67,7 +67,7 @@ gendata_cocsep( "cocsep: computed %" PRIu16 " symmetry classes, " "expected %zu\n", n, COCSEP_CLASSES); - LOG("cocsep data computed\n"); + LOG("[H48 gendata] cocsep data computed\n"); /* The following output is just noise diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h @@ -87,7 +87,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) return size; /* Dry-run */ if (arg->buf_size < size) { - LOG("Error computing H48 data: buffer is too small " + LOG("[H48 gendata] Error data: buffer is too small " "(needed %" PRId64 " bytes but received %" PRId64 ")\n", size, arg->buf_size); return NISSY_ERROR_BUFFER_SIZE; @@ -106,22 +106,24 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) } else if (arg->k == 2) { gendata_h48k2(arg); } else { - LOG("Cannot generate data for h = %" PRIu8 " and k = %" PRIu8 - " (not implemented yet)\n", arg->h, arg->k); + LOG("[H48 gendata] Error: cannot generate data for h = %" PRIu8 + " and k = %" PRIu8 " (not implemented yet)\n", + arg->h, arg->k); return NISSY_ERROR_INVALID_SOLVER; } r = readtableinfo(arg->buf_size, arg->buf, &cocsepinfo); if (r != NISSY_OK) { - LOG("gendata_h48: could not read info for cocsep table\n"); + LOG("[H48 gendata] Error: could not read info " + "for cocsep table\n"); return NISSY_ERROR_UNKNOWN; } cocsepinfo.next = cocsepsize; r = writetableinfo(&cocsepinfo, arg->buf_size, arg->buf); if (r != NISSY_OK) { - LOG("gendata_h48: could not write info for cocsep table" - " with updated 'next' value\n"); + LOG("[H48 gendata] Error: could not write info for " + "cocsep table with updated 'next' value\n"); return NISSY_ERROR_UNKNOWN; } @@ -149,21 +151,23 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) r = readtableinfo_n(arg->buf_size, arg->buf, 2, &h48info); if (r != NISSY_OK) { - LOG("gendata_h48: could not read info for h48 table\n"); + LOG("[H48 gendata] Error: could not read info " + "for h48 table\n"); return NISSY_ERROR_UNKNOWN; } h48info.next = h48size; r = writetableinfo(&h48info, arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); if (r != NISSY_OK) { - LOG("gendata_h48: could not write info for h48 table\n"); + LOG("[H48 gendata] Error: could not write info " + "for h48 table\n"); return NISSY_ERROR_UNKNOWN; } if (arg->k == 2) { r = readtableinfo_n(arg->buf_size, arg->buf, 3, &fallbackinfo); if (r != NISSY_OK) { - LOG("gendata_h48: could not read info for h48 " + LOG("[H48 gendata] Error: could not read info for h48 " "fallback table\n"); return NISSY_ERROR_UNKNOWN; } @@ -173,8 +177,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) r = writetableinfo(&fallbackinfo, arg->buf_size - of, (char *)arg->buf + of); if (r != NISSY_OK) { - LOG("gendata_h48: could not write info for h48 " - "fallback table\n"); + LOG("[H48 gendata] Error: could not write info for " + "h48 fallback table\n"); return NISSY_ERROR_UNKNOWN; } } @@ -233,7 +237,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) bfsarg[t].table_mutex[tt] = &table_mutex[tt]; } for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { - LOG("h48: generating depth %" PRId64 "\n", d); + LOG("[H48 gendata] Generating depth %" PRId64 "\n", d); for (t = 0; t < THREADS; t++) { bfsarg[t].depth = d; @@ -252,7 +256,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) done += cc; arg->info.distribution[d] = cc; - LOG("found %" PRId64 "\n", cc); + LOG("[H48 gendata] Found %" PRId64 "\n", cc); } arg->info.maxvalue = d - 1; @@ -382,7 +386,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) table = (uint8_t *)arg->h48buf + INFOSIZE; memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); - LOG("Computing depth <=%" PRIu8 "\n", shortdepth) + LOG("[H48 gendata] Computing depth <=%" PRIu8 "\n", shortdepth) h48map_create(&shortcubes, capacity, randomizer); shortarg = (gendata_h48short_arg_t) { .maxdepth = shortdepth, @@ -392,7 +396,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) .map = &shortcubes }; gendata_h48short(&shortarg); - LOG("Computed %" PRIu64 " positions\n", shortarg.map->n); + LOG("[H48 gendata] Computed %" PRIu64 " positions\n", shortarg.map->n); if (arg->base >= 20) arg->base = base[arg->h]; @@ -459,7 +463,8 @@ gendata_h48k2_runthread(void *arg) pthread_mutex_unlock(dfsarg->shortcubes_mutex); if (count % UINT64_C(1000000) == 0) - LOG("Processing %" PRIu64 "th short cube\n", count); + LOG("[H48 gendata] Processing %" PRIu64 + "th short cube\n", count); if (kv.val < dfsarg->shortdepth) { coord = kv.key >> (int64_t)(11 - dfsarg->h); @@ -780,15 +785,16 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) bufsize = COCSEP_FULLSIZE + INFOSIZE; if (readtableinfo(bufsize, buf, &cocsepinfo) != NISSY_OK) { - LOG("gendata_h48: could not read info for cocsep table\n"); + LOG("[H48 derive gendata] Error: could not read info for " + "cocsep table\n"); goto gendata_h48_derive_error; } cocsepinfo.next = cocsepsize; bufsize = COCSEP_FULLSIZE + INFOSIZE; if (writetableinfo(&cocsepinfo, bufsize, buf) != NISSY_OK) { - LOG("gendata_h48_derive: could not write info for cocsep table" - " with updated 'next' value\n"); + LOG("[H48 derive gendata] Error: could not write info for " + "cocsep table with updated 'next' value\n"); goto gendata_h48_derive_error; } @@ -801,7 +807,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) h48max = H48_COORDMAX(fulltableinfo.h48h); for (i = 0; i < h48max; i++) { if (i % INT64_C(1000000000) == 0 && i > 0) - LOG("Processing %" PRId64 "th coordinate\n", i); + LOG("[H48 derive gendata] Processing %" PRId64 + "th coordinate\n", i); j = i >> (int64_t)(fulltableinfo.h48h - h); val_full = get_h48_pval(h48full, i, arg.k); val_derive = get_h48_pval(h48derive, j, arg.k); @@ -813,7 +820,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { - LOG("gendata_h48_derive: could not write info for table\n"); + LOG("H48 derive gendata] Error: could not write info " + "for table\n"); goto gendata_h48_derive_error; } diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h @@ -162,7 +162,7 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) return 0; pthread_mutex_lock(arg->solutions_mutex); ret = appendsolution(arg->solution_moves, - arg->solution_settings, arg->solution_list, true); + arg->solution_settings, arg->solution_list, true, "H48"); pthread_mutex_unlock(arg->solutions_mutex); return ret; } @@ -295,7 +295,7 @@ solve_h48_maketasks( maketasks_arg->moves, maketasks_arg->nmoves); appret = appendsolution(&moves, solve_arg->solution_settings, - solve_arg->solution_list, true); + solve_arg->solution_list, true, "H48"); return appret < 0 ? appret : NISSY_OK; } @@ -458,16 +458,17 @@ solve_h48( arg[i].tasks = tasks; } - LOG("Prepared %d tasks\n", ntasks); + LOG("[H48 solve] Prepared %d tasks\n", ntasks); for ( d = MAX(minmoves, STARTING_MOVES + 1); !solutions_done(&sollist, &settings, d); d++ ) { - if (d >= 10) - LOG("Found %" PRId64 " solutions, searching at depth %" - PRId8 "\n", sollist.nsols, d); + if (d >= 15) + LOG("[H48 solve] Found %" PRId64 " solutions, " + "searching at depth %" PRId8 "\n", + sollist.nsols, d); for (i = 0; i < threads; i++) { arg[i].target_depth = d; pthread_create( @@ -491,16 +492,16 @@ solve_h48_done: lookups_per_node = table_lookups / (long double)nodes_visited; fallback_rate = nodes_visited == 0 ? 0.0 : (table_fallbacks * 100) / (long double)table_lookups; - LOG("Nodes visited: %" PRId64 "\n", nodes_visited); - LOG("Lookups: %" PRId64 " (%.3Lf per node)\n", + LOG("[H48 solve] Nodes visited: %" PRId64 "\n", nodes_visited); + LOG("[H48 solve] Lookups: %" PRId64 " (%.3Lf per node)\n", table_lookups, lookups_per_node); - LOG("Table fallbacks: %" PRId64 " (%.3Lf%%)\n", + LOG("[H48 solve] Table fallbacks: %" PRId64 " (%.3Lf%%)\n", table_fallbacks, fallback_rate); return sollist.nsols; solve_h48_error_data: - LOG("solve_h48: error reading table\n"); + LOG("[H48 solve] Error reading data table\n"); return NISSY_ERROR_DATA; solve_h48_error_solutions_buffer: diff --git a/src/solvers/solutions.h b/src/solvers/solutions.h @@ -7,7 +7,8 @@ STATIC bool solution_moves_equal( STATIC bool solution_moves_is_duplicate(size_t n, const solution_moves_t[n+1]); STATIC bool appendchar(solution_list_t [static 1], char); STATIC int64_t appendsolution(const solution_moves_t [static 1], - const solution_settings_t [static 1], solution_list_t [static 1], bool); + const solution_settings_t [static 1], solution_list_t [static 1], bool, + const char *); STATIC bool solutions_done(const solution_list_t [static 1], const solution_settings_t [static 1], int8_t depth); @@ -34,7 +35,7 @@ STATIC bool solution_list_init(solution_list_t sols[static 1], size_t n, char buf[n]) { if (n == 0) { - LOG("Cannot use solution buffer with size 0\n"); + LOG("Error: cannot use solution buffer with size 0\n"); return false; } @@ -98,7 +99,8 @@ appendsolution( const solution_moves_t moves[static 1], const solution_settings_t settings[static 1], solution_list_t list[static 1], - bool log + bool log, + const char *solver_name ) { int64_t r, strl; @@ -184,8 +186,8 @@ appendsolution( if (log) { list->buf[list->used-1] = '\0'; - LOG("Found solution #%" PRIu64 ": %s\n", - list->nsols, last_start); + LOG("[%s solve] Found solution #%" PRIu64 ": %s\n", + solver_name, list->nsols, last_start); list->buf[list->used-1] = '\n'; } } @@ -194,14 +196,14 @@ appendsolution( return r; appendsolution_error_buffer: - LOG("Could not append solution to buffer: size too small\n"); + LOG("[%s solve] Error: buffer too small\n", solver_name); list->buf[0] = '\0'; return NISSY_ERROR_BUFFER_SIZE; appendsolution_error_solution_length: - LOG("Error: solution is too long (%" PRIu8 ").\n" + LOG("[%s solve] Error: solution is too long (%" PRIu8 ").\n" "This is a bug, please report it.\n", - moves->nmoves + moves->npremoves); + solver_name, moves->nmoves + moves->npremoves); list->buf[0] = '\0'; return NISSY_ERROR_UNKNOWN; } diff --git a/src/utils/math.h b/src/utils/math.h @@ -138,7 +138,7 @@ digitstosumzero(size_t n, const uint8_t a[n], uint8_t b) size_t i, sum; if (!((n == 8 && b == 3 ) || (n == 12 && b == 2))) { - LOG("Won't compute 'sumzero' for n=%zu and b=%" PRIu8 + LOG("Error: won't compute 'sumzero' for n=%zu and b=%" PRIu8 " (use n=8 b=3 or n=12 b=2)\n", n, b); return -1; } @@ -168,7 +168,7 @@ sumzerotodigits(int64_t d, size_t n, uint8_t b, uint8_t a[n]) size_t i; if (!((n == 8 && b == 3 ) || (n == 12 && b == 2))) { - LOG("Won't compute 'digits' for n=%zu and b=%" PRIu8 + LOG("Error: won't compute 'digits' for n=%zu and b=%" PRIu8 " (use n=8 b=3 or n=12 b=2)\n", n, b); goto sumzerotodigits_error; }