diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-19 12:28:52 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-04-19 12:28:52 +0200 |
| commit | 3485be851f4fff1c9c6fe621f0619d2b4103bc06 (patch) | |
| tree | 894197f164a7ef66801ae3a701fb10a3c1e3f5e3 /src/solvers/h48 | |
| parent | 691da8f06614418ed847bdeefa4e708c372a3ecf (diff) | |
| download | nissy-core-3485be851f4fff1c9c6fe621f0619d2b4103bc06.tar.gz nissy-core-3485be851f4fff1c9c6fe621f0619d2b4103bc06.zip | |
Improved logging, especially for solve
Diffstat (limited to 'src/solvers/h48')
| -rw-r--r-- | src/solvers/h48/gendata_cocsep.h | 2 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 50 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 21 |
3 files changed, 41 insertions, 32 deletions
diff --git a/src/solvers/h48/gendata_cocsep.h b/src/solvers/h48/gendata_cocsep.h index cda1608..f07b71a 100644 --- a/src/solvers/h48/gendata_cocsep.h +++ b/src/solvers/h48/gendata_cocsep.h | |||
| @@ -67,7 +67,7 @@ gendata_cocsep( | |||
| 67 | "cocsep: computed %" PRIu16 " symmetry classes, " | 67 | "cocsep: computed %" PRIu16 " symmetry classes, " |
| 68 | "expected %zu\n", n, COCSEP_CLASSES); | 68 | "expected %zu\n", n, COCSEP_CLASSES); |
| 69 | 69 | ||
| 70 | LOG("cocsep data computed\n"); | 70 | LOG("[H48 gendata] cocsep data computed\n"); |
| 71 | 71 | ||
| 72 | /* The following output is just noise | 72 | /* The following output is just noise |
| 73 | 73 | ||
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 4478e9e..18157dc 100644 --- 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]) | |||
| 87 | return size; /* Dry-run */ | 87 | return size; /* Dry-run */ |
| 88 | 88 | ||
| 89 | if (arg->buf_size < size) { | 89 | if (arg->buf_size < size) { |
| 90 | LOG("Error computing H48 data: buffer is too small " | 90 | LOG("[H48 gendata] Error data: buffer is too small " |
| 91 | "(needed %" PRId64 " bytes but received %" PRId64 ")\n", | 91 | "(needed %" PRId64 " bytes but received %" PRId64 ")\n", |
| 92 | size, arg->buf_size); | 92 | size, arg->buf_size); |
| 93 | return NISSY_ERROR_BUFFER_SIZE; | 93 | return NISSY_ERROR_BUFFER_SIZE; |
| @@ -106,22 +106,24 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 106 | } else if (arg->k == 2) { | 106 | } else if (arg->k == 2) { |
| 107 | gendata_h48k2(arg); | 107 | gendata_h48k2(arg); |
| 108 | } else { | 108 | } else { |
| 109 | LOG("Cannot generate data for h = %" PRIu8 " and k = %" PRIu8 | 109 | LOG("[H48 gendata] Error: cannot generate data for h = %" PRIu8 |
| 110 | " (not implemented yet)\n", arg->h, arg->k); | 110 | " and k = %" PRIu8 " (not implemented yet)\n", |
| 111 | arg->h, arg->k); | ||
| 111 | return NISSY_ERROR_INVALID_SOLVER; | 112 | return NISSY_ERROR_INVALID_SOLVER; |
| 112 | } | 113 | } |
| 113 | 114 | ||
| 114 | r = readtableinfo(arg->buf_size, arg->buf, &cocsepinfo); | 115 | r = readtableinfo(arg->buf_size, arg->buf, &cocsepinfo); |
| 115 | if (r != NISSY_OK) { | 116 | if (r != NISSY_OK) { |
| 116 | LOG("gendata_h48: could not read info for cocsep table\n"); | 117 | LOG("[H48 gendata] Error: could not read info " |
| 118 | "for cocsep table\n"); | ||
| 117 | return NISSY_ERROR_UNKNOWN; | 119 | return NISSY_ERROR_UNKNOWN; |
| 118 | } | 120 | } |
| 119 | 121 | ||
| 120 | cocsepinfo.next = cocsepsize; | 122 | cocsepinfo.next = cocsepsize; |
| 121 | r = writetableinfo(&cocsepinfo, arg->buf_size, arg->buf); | 123 | r = writetableinfo(&cocsepinfo, arg->buf_size, arg->buf); |
| 122 | if (r != NISSY_OK) { | 124 | if (r != NISSY_OK) { |
| 123 | LOG("gendata_h48: could not write info for cocsep table" | 125 | LOG("[H48 gendata] Error: could not write info for " |
| 124 | " with updated 'next' value\n"); | 126 | "cocsep table with updated 'next' value\n"); |
| 125 | return NISSY_ERROR_UNKNOWN; | 127 | return NISSY_ERROR_UNKNOWN; |
| 126 | } | 128 | } |
| 127 | 129 | ||
| @@ -149,21 +151,23 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 149 | 151 | ||
| 150 | r = readtableinfo_n(arg->buf_size, arg->buf, 2, &h48info); | 152 | r = readtableinfo_n(arg->buf_size, arg->buf, 2, &h48info); |
| 151 | if (r != NISSY_OK) { | 153 | if (r != NISSY_OK) { |
| 152 | LOG("gendata_h48: could not read info for h48 table\n"); | 154 | LOG("[H48 gendata] Error: could not read info " |
| 155 | "for h48 table\n"); | ||
| 153 | return NISSY_ERROR_UNKNOWN; | 156 | return NISSY_ERROR_UNKNOWN; |
| 154 | } | 157 | } |
| 155 | h48info.next = h48size; | 158 | h48info.next = h48size; |
| 156 | r = writetableinfo(&h48info, | 159 | r = writetableinfo(&h48info, |
| 157 | arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); | 160 | arg->buf_size - cocsepsize, (char *)arg->buf + cocsepsize); |
| 158 | if (r != NISSY_OK) { | 161 | if (r != NISSY_OK) { |
| 159 | LOG("gendata_h48: could not write info for h48 table\n"); | 162 | LOG("[H48 gendata] Error: could not write info " |
| 163 | "for h48 table\n"); | ||
| 160 | return NISSY_ERROR_UNKNOWN; | 164 | return NISSY_ERROR_UNKNOWN; |
| 161 | } | 165 | } |
| 162 | 166 | ||
| 163 | if (arg->k == 2) { | 167 | if (arg->k == 2) { |
| 164 | r = readtableinfo_n(arg->buf_size, arg->buf, 3, &fallbackinfo); | 168 | r = readtableinfo_n(arg->buf_size, arg->buf, 3, &fallbackinfo); |
| 165 | if (r != NISSY_OK) { | 169 | if (r != NISSY_OK) { |
| 166 | LOG("gendata_h48: could not read info for h48 " | 170 | LOG("[H48 gendata] Error: could not read info for h48 " |
| 167 | "fallback table\n"); | 171 | "fallback table\n"); |
| 168 | return NISSY_ERROR_UNKNOWN; | 172 | return NISSY_ERROR_UNKNOWN; |
| 169 | } | 173 | } |
| @@ -173,8 +177,8 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 173 | r = writetableinfo(&fallbackinfo, | 177 | r = writetableinfo(&fallbackinfo, |
| 174 | arg->buf_size - of, (char *)arg->buf + of); | 178 | arg->buf_size - of, (char *)arg->buf + of); |
| 175 | if (r != NISSY_OK) { | 179 | if (r != NISSY_OK) { |
| 176 | LOG("gendata_h48: could not write info for h48 " | 180 | LOG("[H48 gendata] Error: could not write info for " |
| 177 | "fallback table\n"); | 181 | "h48 fallback table\n"); |
| 178 | return NISSY_ERROR_UNKNOWN; | 182 | return NISSY_ERROR_UNKNOWN; |
| 179 | } | 183 | } |
| 180 | } | 184 | } |
| @@ -233,7 +237,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | |||
| 233 | bfsarg[t].table_mutex[tt] = &table_mutex[tt]; | 237 | bfsarg[t].table_mutex[tt] = &table_mutex[tt]; |
| 234 | } | 238 | } |
| 235 | for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { | 239 | for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { |
| 236 | LOG("h48: generating depth %" PRId64 "\n", d); | 240 | LOG("[H48 gendata] Generating depth %" PRId64 "\n", d); |
| 237 | 241 | ||
| 238 | for (t = 0; t < THREADS; t++) { | 242 | for (t = 0; t < THREADS; t++) { |
| 239 | bfsarg[t].depth = d; | 243 | bfsarg[t].depth = d; |
| @@ -252,7 +256,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | |||
| 252 | done += cc; | 256 | done += cc; |
| 253 | arg->info.distribution[d] = cc; | 257 | arg->info.distribution[d] = cc; |
| 254 | 258 | ||
| 255 | LOG("found %" PRId64 "\n", cc); | 259 | LOG("[H48 gendata] Found %" PRId64 "\n", cc); |
| 256 | } | 260 | } |
| 257 | 261 | ||
| 258 | arg->info.maxvalue = d - 1; | 262 | arg->info.maxvalue = d - 1; |
| @@ -382,7 +386,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 382 | table = (uint8_t *)arg->h48buf + INFOSIZE; | 386 | table = (uint8_t *)arg->h48buf + INFOSIZE; |
| 383 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); | 387 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); |
| 384 | 388 | ||
| 385 | LOG("Computing depth <=%" PRIu8 "\n", shortdepth) | 389 | LOG("[H48 gendata] Computing depth <=%" PRIu8 "\n", shortdepth) |
| 386 | h48map_create(&shortcubes, capacity, randomizer); | 390 | h48map_create(&shortcubes, capacity, randomizer); |
| 387 | shortarg = (gendata_h48short_arg_t) { | 391 | shortarg = (gendata_h48short_arg_t) { |
| 388 | .maxdepth = shortdepth, | 392 | .maxdepth = shortdepth, |
| @@ -392,7 +396,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 392 | .map = &shortcubes | 396 | .map = &shortcubes |
| 393 | }; | 397 | }; |
| 394 | gendata_h48short(&shortarg); | 398 | gendata_h48short(&shortarg); |
| 395 | LOG("Computed %" PRIu64 " positions\n", shortarg.map->n); | 399 | LOG("[H48 gendata] Computed %" PRIu64 " positions\n", shortarg.map->n); |
| 396 | 400 | ||
| 397 | if (arg->base >= 20) | 401 | if (arg->base >= 20) |
| 398 | arg->base = base[arg->h]; | 402 | arg->base = base[arg->h]; |
| @@ -459,7 +463,8 @@ gendata_h48k2_runthread(void *arg) | |||
| 459 | pthread_mutex_unlock(dfsarg->shortcubes_mutex); | 463 | pthread_mutex_unlock(dfsarg->shortcubes_mutex); |
| 460 | 464 | ||
| 461 | if (count % UINT64_C(1000000) == 0) | 465 | if (count % UINT64_C(1000000) == 0) |
| 462 | LOG("Processing %" PRIu64 "th short cube\n", count); | 466 | LOG("[H48 gendata] Processing %" PRIu64 |
| 467 | "th short cube\n", count); | ||
| 463 | 468 | ||
| 464 | if (kv.val < dfsarg->shortdepth) { | 469 | if (kv.val < dfsarg->shortdepth) { |
| 465 | coord = kv.key >> (int64_t)(11 - dfsarg->h); | 470 | coord = kv.key >> (int64_t)(11 - dfsarg->h); |
| @@ -780,15 +785,16 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | |||
| 780 | 785 | ||
| 781 | bufsize = COCSEP_FULLSIZE + INFOSIZE; | 786 | bufsize = COCSEP_FULLSIZE + INFOSIZE; |
| 782 | if (readtableinfo(bufsize, buf, &cocsepinfo) != NISSY_OK) { | 787 | if (readtableinfo(bufsize, buf, &cocsepinfo) != NISSY_OK) { |
| 783 | LOG("gendata_h48: could not read info for cocsep table\n"); | 788 | LOG("[H48 derive gendata] Error: could not read info for " |
| 789 | "cocsep table\n"); | ||
| 784 | goto gendata_h48_derive_error; | 790 | goto gendata_h48_derive_error; |
| 785 | } | 791 | } |
| 786 | 792 | ||
| 787 | cocsepinfo.next = cocsepsize; | 793 | cocsepinfo.next = cocsepsize; |
| 788 | bufsize = COCSEP_FULLSIZE + INFOSIZE; | 794 | bufsize = COCSEP_FULLSIZE + INFOSIZE; |
| 789 | if (writetableinfo(&cocsepinfo, bufsize, buf) != NISSY_OK) { | 795 | if (writetableinfo(&cocsepinfo, bufsize, buf) != NISSY_OK) { |
| 790 | LOG("gendata_h48_derive: could not write info for cocsep table" | 796 | LOG("[H48 derive gendata] Error: could not write info for " |
| 791 | " with updated 'next' value\n"); | 797 | "cocsep table with updated 'next' value\n"); |
| 792 | goto gendata_h48_derive_error; | 798 | goto gendata_h48_derive_error; |
| 793 | } | 799 | } |
| 794 | 800 | ||
| @@ -801,7 +807,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | |||
| 801 | h48max = H48_COORDMAX(fulltableinfo.h48h); | 807 | h48max = H48_COORDMAX(fulltableinfo.h48h); |
| 802 | for (i = 0; i < h48max; i++) { | 808 | for (i = 0; i < h48max; i++) { |
| 803 | if (i % INT64_C(1000000000) == 0 && i > 0) | 809 | if (i % INT64_C(1000000000) == 0 && i > 0) |
| 804 | LOG("Processing %" PRId64 "th coordinate\n", i); | 810 | LOG("[H48 derive gendata] Processing %" PRId64 |
| 811 | "th coordinate\n", i); | ||
| 805 | j = i >> (int64_t)(fulltableinfo.h48h - h); | 812 | j = i >> (int64_t)(fulltableinfo.h48h - h); |
| 806 | val_full = get_h48_pval(h48full, i, arg.k); | 813 | val_full = get_h48_pval(h48full, i, arg.k); |
| 807 | val_derive = get_h48_pval(h48derive, j, arg.k); | 814 | val_derive = get_h48_pval(h48derive, j, arg.k); |
| @@ -813,7 +820,8 @@ gendata_h48_derive(uint8_t h, const void *fulltable, void *buf) | |||
| 813 | 820 | ||
| 814 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; | 821 | bufsize = arg.buf_size - COCSEP_FULLSIZE - INFOSIZE; |
| 815 | if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { | 822 | if (writetableinfo(&arg.info, bufsize, arg.h48buf) != NISSY_OK) { |
| 816 | LOG("gendata_h48_derive: could not write info for table\n"); | 823 | LOG("H48 derive gendata] Error: could not write info " |
| 824 | "for table\n"); | ||
| 817 | goto gendata_h48_derive_error; | 825 | goto gendata_h48_derive_error; |
| 818 | } | 826 | } |
| 819 | 827 | ||
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 78b4c97..0fd419d 100644 --- 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]) | |||
| 162 | return 0; | 162 | return 0; |
| 163 | pthread_mutex_lock(arg->solutions_mutex); | 163 | pthread_mutex_lock(arg->solutions_mutex); |
| 164 | ret = appendsolution(arg->solution_moves, | 164 | ret = appendsolution(arg->solution_moves, |
| 165 | arg->solution_settings, arg->solution_list, true); | 165 | arg->solution_settings, arg->solution_list, true, "H48"); |
| 166 | pthread_mutex_unlock(arg->solutions_mutex); | 166 | pthread_mutex_unlock(arg->solutions_mutex); |
| 167 | return ret; | 167 | return ret; |
| 168 | } | 168 | } |
| @@ -295,7 +295,7 @@ solve_h48_maketasks( | |||
| 295 | maketasks_arg->moves, maketasks_arg->nmoves); | 295 | maketasks_arg->moves, maketasks_arg->nmoves); |
| 296 | 296 | ||
| 297 | appret = appendsolution(&moves, solve_arg->solution_settings, | 297 | appret = appendsolution(&moves, solve_arg->solution_settings, |
| 298 | solve_arg->solution_list, true); | 298 | solve_arg->solution_list, true, "H48"); |
| 299 | return appret < 0 ? appret : NISSY_OK; | 299 | return appret < 0 ? appret : NISSY_OK; |
| 300 | } | 300 | } |
| 301 | 301 | ||
| @@ -458,16 +458,17 @@ solve_h48( | |||
| 458 | arg[i].tasks = tasks; | 458 | arg[i].tasks = tasks; |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | LOG("Prepared %d tasks\n", ntasks); | 461 | LOG("[H48 solve] Prepared %d tasks\n", ntasks); |
| 462 | 462 | ||
| 463 | for ( | 463 | for ( |
| 464 | d = MAX(minmoves, STARTING_MOVES + 1); | 464 | d = MAX(minmoves, STARTING_MOVES + 1); |
| 465 | !solutions_done(&sollist, &settings, d); | 465 | !solutions_done(&sollist, &settings, d); |
| 466 | d++ | 466 | d++ |
| 467 | ) { | 467 | ) { |
| 468 | if (d >= 10) | 468 | if (d >= 15) |
| 469 | LOG("Found %" PRId64 " solutions, searching at depth %" | 469 | LOG("[H48 solve] Found %" PRId64 " solutions, " |
| 470 | PRId8 "\n", sollist.nsols, d); | 470 | "searching at depth %" PRId8 "\n", |
| 471 | sollist.nsols, d); | ||
| 471 | for (i = 0; i < threads; i++) { | 472 | for (i = 0; i < threads; i++) { |
| 472 | arg[i].target_depth = d; | 473 | arg[i].target_depth = d; |
| 473 | pthread_create( | 474 | pthread_create( |
| @@ -491,16 +492,16 @@ solve_h48_done: | |||
| 491 | lookups_per_node = table_lookups / (long double)nodes_visited; | 492 | lookups_per_node = table_lookups / (long double)nodes_visited; |
| 492 | fallback_rate = nodes_visited == 0 ? 0.0 : | 493 | fallback_rate = nodes_visited == 0 ? 0.0 : |
| 493 | (table_fallbacks * 100) / (long double)table_lookups; | 494 | (table_fallbacks * 100) / (long double)table_lookups; |
| 494 | LOG("Nodes visited: %" PRId64 "\n", nodes_visited); | 495 | LOG("[H48 solve] Nodes visited: %" PRId64 "\n", nodes_visited); |
| 495 | LOG("Lookups: %" PRId64 " (%.3Lf per node)\n", | 496 | LOG("[H48 solve] Lookups: %" PRId64 " (%.3Lf per node)\n", |
| 496 | table_lookups, lookups_per_node); | 497 | table_lookups, lookups_per_node); |
| 497 | LOG("Table fallbacks: %" PRId64 " (%.3Lf%%)\n", | 498 | LOG("[H48 solve] Table fallbacks: %" PRId64 " (%.3Lf%%)\n", |
| 498 | table_fallbacks, fallback_rate); | 499 | table_fallbacks, fallback_rate); |
| 499 | 500 | ||
| 500 | return sollist.nsols; | 501 | return sollist.nsols; |
| 501 | 502 | ||
| 502 | solve_h48_error_data: | 503 | solve_h48_error_data: |
| 503 | LOG("solve_h48: error reading table\n"); | 504 | LOG("[H48 solve] Error reading data table\n"); |
| 504 | return NISSY_ERROR_DATA; | 505 | return NISSY_ERROR_DATA; |
| 505 | 506 | ||
| 506 | solve_h48_error_solutions_buffer: | 507 | solve_h48_error_solutions_buffer: |
