diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-19 22:05:40 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2024-09-19 22:05:40 +0200 |
| commit | 5f2ad2155008b4b352069095c8137e5bef410d68 (patch) | |
| tree | 81c96b168273fe166edf5d6dbdf01e63a0bb0bda /src | |
| parent | b848b089edb6d8c9b0bd10b46926f76547aa99c3 (diff) | |
| download | nissy-core-5f2ad2155008b4b352069095c8137e5bef410d68.tar.gz nissy-core-5f2ad2155008b4b352069095c8137e5bef410d68.zip | |
Parallelized gendata_h0k4; set up for new gendata_realcoord
Diffstat (limited to 'src')
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 407 |
1 files changed, 298 insertions, 109 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index 2a62b1d..0ff8df5 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -33,6 +33,7 @@ _t by _ttrep). | |||
| 33 | typedef struct { | 33 | typedef struct { |
| 34 | uint8_t h; | 34 | uint8_t h; |
| 35 | uint8_t k; | 35 | uint8_t k; |
| 36 | uint8_t base; | ||
| 36 | uint8_t maxdepth; | 37 | uint8_t maxdepth; |
| 37 | tableinfo_t info; | 38 | tableinfo_t info; |
| 38 | void *buf; | 39 | void *buf; |
| @@ -56,6 +57,12 @@ typedef struct { | |||
| 56 | uint8_t *table; | 57 | uint8_t *table; |
| 57 | uint64_t *selfsim; | 58 | uint64_t *selfsim; |
| 58 | cube_t *crep; | 59 | cube_t *crep; |
| 60 | uint64_t start; | ||
| 61 | uint64_t end; | ||
| 62 | uint64_t count; | ||
| 63 | uint64_t *distribution; | ||
| 64 | pthread_mutex_t *distribution_mutex; | ||
| 65 | pthread_mutex_t *table_mutex[CHUNKS]; | ||
| 59 | } h48h0k4_bfs_arg_t; | 66 | } h48h0k4_bfs_arg_t; |
| 60 | 67 | ||
| 61 | typedef struct { | 68 | typedef struct { |
| @@ -75,17 +82,30 @@ typedef struct { | |||
| 75 | uint64_t *count; | 82 | uint64_t *count; |
| 76 | } h48k2_dfs_arg_t; | 83 | } h48k2_dfs_arg_t; |
| 77 | 84 | ||
| 85 | typedef struct { | ||
| 86 | cube_t cube; | ||
| 87 | int8_t depth; | ||
| 88 | uint8_t h; | ||
| 89 | uint8_t k; | ||
| 90 | uint32_t *cocsepdata; | ||
| 91 | uint64_t *selfsim; | ||
| 92 | uint8_t *table; | ||
| 93 | pthread_mutex_t **table_mutex; | ||
| 94 | } gendata_h48_mark_t; | ||
| 95 | |||
| 78 | STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); | 96 | STATIC uint64_t gendata_h48short(gendata_h48short_arg_t *); |
| 79 | STATIC size_t gendata_h48(gendata_h48_arg_t *); | 97 | STATIC size_t gendata_h48(gendata_h48_arg_t *); |
| 80 | STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); | 98 | STATIC size_t gendata_h48h0k4(gendata_h48_arg_t *); |
| 81 | STATIC int64_t gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *); | 99 | STATIC void gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *); |
| 82 | STATIC int64_t gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *); | 100 | STATIC void gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *); |
| 83 | STATIC int64_t gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *); | ||
| 84 | STATIC size_t gendata_h48k2(gendata_h48_arg_t *); | 101 | STATIC size_t gendata_h48k2(gendata_h48_arg_t *); |
| 85 | STATIC void * gendata_h48k2_runthread(void *); | 102 | STATIC void * gendata_h48h0k4_runthread(void *); |
| 86 | STATIC_INLINE void gendata_h48k2_mark(cube_t, int8_t, h48k2_dfs_arg_t *); | 103 | STATIC_INLINE uint64_t gendata_h48_mark(gendata_h48_mark_t *); |
| 87 | STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, uint8_t, h48k2_dfs_arg_t *); | 104 | STATIC_INLINE bool gendata_h48k2_dfs_stop(cube_t, int8_t, h48k2_dfs_arg_t *); |
| 105 | STATIC size_t gendata_h48k2_realcoord(gendata_h48_arg_t *); | ||
| 88 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); | 106 | STATIC void gendata_h48k2_dfs(h48k2_dfs_arg_t *arg); |
| 107 | STATIC void * gendata_h48k2_runthread(void *); | ||
| 108 | STATIC tableinfo_t makeinfo_h48k2(gendata_h48_arg_t *, uint8_t); | ||
| 89 | 109 | ||
| 90 | STATIC uint32_t *get_cocsepdata_ptr(const void *); | 110 | STATIC uint32_t *get_cocsepdata_ptr(const void *); |
| 91 | STATIC uint8_t *get_h48data_ptr(const void *); | 111 | STATIC uint8_t *get_h48data_ptr(const void *); |
| @@ -147,8 +167,12 @@ gendata_h48(gendata_h48_arg_t *arg) | |||
| 147 | arg->cocsepdata = (uint32_t *)cocsepdata_offset; | 167 | arg->cocsepdata = (uint32_t *)cocsepdata_offset; |
| 148 | arg->h48buf = (char *)arg->buf + cocsepsize; | 168 | arg->h48buf = (char *)arg->buf + cocsepsize; |
| 149 | 169 | ||
| 170 | arg->base = 99; // TODO: set this somewhere else | ||
| 171 | |||
| 150 | if (arg->h == 0 && arg->k == 4) { | 172 | if (arg->h == 0 && arg->k == 4) { |
| 151 | h48size = gendata_h48h0k4(arg); | 173 | h48size = gendata_h48h0k4(arg); |
| 174 | } else if ((arg->h == 0 || arg->h == 11) && arg->k == 2) { | ||
| 175 | h48size = gendata_h48k2_realcoord(arg); | ||
| 152 | } else if (arg->k == 2) { | 176 | } else if (arg->k == 2) { |
| 153 | h48size = gendata_h48k2(arg); | 177 | h48size = gendata_h48k2(arg); |
| 154 | } else { | 178 | } else { |
| @@ -179,17 +203,15 @@ gendata_h48_error: | |||
| 179 | return 0; | 203 | return 0; |
| 180 | } | 204 | } |
| 181 | 205 | ||
| 182 | /* | ||
| 183 | TODO description | ||
| 184 | generating fixed table with h=0, k=4 | ||
| 185 | */ | ||
| 186 | STATIC size_t | 206 | STATIC size_t |
| 187 | gendata_h48h0k4(gendata_h48_arg_t *arg) | 207 | gendata_h48h0k4(gendata_h48_arg_t *arg) |
| 188 | { | 208 | { |
| 189 | uint32_t j; | ||
| 190 | uint8_t *table; | 209 | uint8_t *table; |
| 191 | h48h0k4_bfs_arg_t bfsarg; | 210 | int64_t sc, done, d, h48max; |
| 192 | int64_t sc, cc, done, h48max; | 211 | uint64_t t, tt, isize, cc; |
| 212 | h48h0k4_bfs_arg_t bfsarg[THREADS]; | ||
| 213 | pthread_t thread[THREADS]; | ||
| 214 | pthread_mutex_t distribution_mutex, table_mutex[CHUNKS]; | ||
| 193 | 215 | ||
| 194 | if (arg->buf == NULL) | 216 | if (arg->buf == NULL) |
| 195 | goto gendata_h48h0k4_return_size; | 217 | goto gendata_h48h0k4_return_size; |
| @@ -216,109 +238,164 @@ gendata_h48h0k4(gendata_h48_arg_t *arg) | |||
| 216 | sc = coord_h48(SOLVED_CUBE, arg->cocsepdata, 0); | 238 | sc = coord_h48(SOLVED_CUBE, arg->cocsepdata, 0); |
| 217 | set_h48_pval(table, sc, 4, 0); | 239 | set_h48_pval(table, sc, 4, 0); |
| 218 | arg->info.distribution[0] = 1; | 240 | arg->info.distribution[0] = 1; |
| 219 | bfsarg = (h48h0k4_bfs_arg_t) { | 241 | |
| 220 | .cocsepdata = arg->cocsepdata, | 242 | isize = h48max / THREADS; |
| 221 | .table = table, | 243 | isize = (isize / H48_COEFF(arg->k)) * H48_COEFF(arg->k); |
| 222 | .selfsim = arg->selfsim, | 244 | pthread_mutex_init(&distribution_mutex, NULL); |
| 223 | .crep = arg->crep | 245 | for (t = 0; t < CHUNKS; t++) |
| 224 | }; | 246 | pthread_mutex_init(&table_mutex[t], NULL); |
| 225 | for ( | 247 | for (t = 0; t < THREADS; t++) { |
| 226 | done = 1, bfsarg.depth = 1, cc = 0; | 248 | bfsarg[t] = (h48h0k4_bfs_arg_t) { |
| 227 | done < h48max && bfsarg.depth <= arg->maxdepth; | 249 | .cocsepdata = arg->cocsepdata, |
| 228 | bfsarg.depth++ | 250 | .table = table, |
| 229 | ) { | 251 | .selfsim = arg->selfsim, |
| 230 | LOG("h48: generating depth %" PRIu8 "\n", bfsarg.depth); | 252 | .crep = arg->crep, |
| 231 | cc = gendata_h48h0k4_bfs(&bfsarg); | 253 | .start = isize * t, |
| 232 | done += cc; | 254 | .end = t == THREADS-1 ? (uint64_t)h48max : isize * (t+1), |
| 233 | arg->info.distribution[bfsarg.depth] = cc; | 255 | .distribution = arg->info.distribution, |
| 234 | LOG("found %" PRId64 "\n", cc); | 256 | .distribution_mutex = &distribution_mutex, |
| 257 | }; | ||
| 258 | for (tt = 0; tt < CHUNKS; tt++) | ||
| 259 | bfsarg[t].table_mutex[tt] = &table_mutex[tt]; | ||
| 235 | } | 260 | } |
| 261 | for (done = 1, d = 1; done < h48max && d <= arg->maxdepth; d++) { | ||
| 262 | LOG("h48: generating depth %" PRIu8 "\n", d); | ||
| 236 | 263 | ||
| 237 | arg->info.maxvalue = bfsarg.depth-1; | 264 | for (t = 0; t < THREADS; t++) { |
| 265 | bfsarg[t].depth = d; | ||
| 266 | bfsarg[t].count = 0; | ||
| 267 | pthread_create(&thread[t], NULL, | ||
| 268 | gendata_h48h0k4_runthread, &bfsarg[t]); | ||
| 269 | } | ||
| 238 | 270 | ||
| 239 | LOG("h48 pruning table computed\n"); | 271 | for (t = 0, cc = 0; t < THREADS; t++) { |
| 240 | LOG("Maximum pruning value: %" PRIu32 "\n", arg->info.maxvalue); | 272 | pthread_join(thread[t], NULL); |
| 241 | LOG("Pruning value distribution:\n"); | 273 | cc += bfsarg[t].count; |
| 242 | for (j = 0; j <= arg->info.maxvalue; j++) | 274 | } |
| 243 | LOG("%" PRIu8 ":\t%" PRIu32 "\n", j, arg->info.distribution[j]); | 275 | |
| 276 | done += cc; | ||
| 277 | arg->info.distribution[d] = cc; | ||
| 278 | |||
| 279 | LOG("found %" PRId64 "\n", cc); | ||
| 280 | } | ||
| 244 | 281 | ||
| 282 | arg->info.maxvalue = d - 1; | ||
| 245 | writetableinfo(&arg->info, arg->h48buf); | 283 | writetableinfo(&arg->info, arg->h48buf); |
| 246 | 284 | ||
| 247 | gendata_h48h0k4_return_size: | 285 | gendata_h48h0k4_return_size: |
| 248 | return H48_TABLESIZE(0, 4) + INFOSIZE; | 286 | return H48_TABLESIZE(0, 4) + INFOSIZE; |
| 249 | } | 287 | } |
| 250 | 288 | ||
| 251 | STATIC int64_t | 289 | STATIC void * |
| 252 | gendata_h48h0k4_bfs(h48h0k4_bfs_arg_t *arg) | 290 | gendata_h48h0k4_runthread(void *arg) |
| 253 | { | 291 | { |
| 254 | const uint8_t breakpoint = 10; /* Hand-picked optimal */ | 292 | static const uint8_t breakpoint = 10; /* Hand-picked optimal */ |
| 293 | |||
| 294 | h48h0k4_bfs_arg_t *bfsarg; | ||
| 295 | |||
| 296 | bfsarg = (h48h0k4_bfs_arg_t *)arg; | ||
| 255 | 297 | ||
| 256 | if (arg->depth < breakpoint) | 298 | if (bfsarg->depth < breakpoint) |
| 257 | return gendata_h48h0k4_bfs_fromdone(arg); | 299 | gendata_h48h0k4_bfs_fromdone(bfsarg); |
| 258 | else | 300 | else |
| 259 | return gendata_h48h0k4_bfs_fromnew(arg); | 301 | gendata_h48h0k4_bfs_fromnew(bfsarg); |
| 302 | |||
| 303 | return NULL; | ||
| 260 | } | 304 | } |
| 261 | 305 | ||
| 262 | STATIC int64_t | 306 | STATIC void |
| 263 | gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg) | 307 | gendata_h48h0k4_bfs_fromdone(h48h0k4_bfs_arg_t *arg) |
| 264 | { | 308 | { |
| 265 | uint8_t c, m, x; | 309 | uint8_t c, m; |
| 266 | uint32_t cc; | 310 | uint64_t i, d, mutex; |
| 267 | int64_t i, j, k; | 311 | int64_t j; |
| 268 | cube_t cube, moved; | 312 | cube_t cube, moved; |
| 313 | gendata_h48_mark_t markarg; | ||
| 269 | 314 | ||
| 270 | for (i = 0, cc = 0; i < (int64_t)H48_COORDMAX(0); i++) { | 315 | markarg = (gendata_h48_mark_t) { |
| 316 | .depth = arg->depth, | ||
| 317 | .h = 0, | ||
| 318 | .k = 4, | ||
| 319 | .cocsepdata = arg->cocsepdata, | ||
| 320 | .selfsim = arg->selfsim, | ||
| 321 | .table = arg->table, | ||
| 322 | .table_mutex = arg->table_mutex, | ||
| 323 | }; | ||
| 324 | |||
| 325 | for (i = arg->start, d = 0; i < arg->end; i++) { | ||
| 326 | mutex = H48_INDEX(i, 4) % CHUNKS; | ||
| 327 | pthread_mutex_lock(arg->table_mutex[mutex]); | ||
| 271 | c = get_h48_pval(arg->table, i, 4); | 328 | c = get_h48_pval(arg->table, i, 4); |
| 329 | pthread_mutex_unlock(arg->table_mutex[mutex]); | ||
| 272 | if (c != arg->depth - 1) | 330 | if (c != arg->depth - 1) |
| 273 | continue; | 331 | continue; |
| 274 | cube = invcoord_h48(i, arg->crep, 0); | 332 | cube = invcoord_h48(i, arg->crep, 0); |
| 275 | for (m = 0; m < 18; m++) { | 333 | for (m = 0; m < 18; m++) { |
| 276 | moved = move(cube, m); | 334 | moved = move(cube, m); |
| 277 | j = coord_h48(moved, arg->cocsepdata, 0); | 335 | j = coord_h48(moved, arg->cocsepdata, 0); |
| 278 | if (get_h48_pval(arg->table, j, 4) <= arg->depth) | 336 | mutex = H48_INDEX(j, 4) % CHUNKS; |
| 337 | pthread_mutex_lock(arg->table_mutex[mutex]); | ||
| 338 | c = get_h48_pval(arg->table, j, 4); | ||
| 339 | pthread_mutex_unlock(arg->table_mutex[mutex]); | ||
| 340 | if (c <= arg->depth) | ||
| 279 | continue; | 341 | continue; |
| 280 | FOREACH_H48SIM(moved, arg->cocsepdata, arg->selfsim, | 342 | markarg.cube = moved; |
| 281 | k = coord_h48(moved, arg->cocsepdata, 0); | 343 | d += gendata_h48_mark(&markarg); |
| 282 | x = get_h48_pval(arg->table, k, 4); | ||
| 283 | set_h48_pval(arg->table, k, 4, arg->depth); | ||
| 284 | cc += x != arg->depth; | ||
| 285 | ) | ||
| 286 | } | 344 | } |
| 287 | } | 345 | } |
| 288 | 346 | ||
| 289 | return cc; | 347 | pthread_mutex_lock(arg->distribution_mutex); |
| 348 | arg->count += d; | ||
| 349 | arg->distribution[arg->depth] += d; | ||
| 350 | pthread_mutex_unlock(arg->distribution_mutex); | ||
| 290 | } | 351 | } |
| 291 | 352 | ||
| 292 | STATIC int64_t | 353 | STATIC void |
| 293 | gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg) | 354 | gendata_h48h0k4_bfs_fromnew(h48h0k4_bfs_arg_t *arg) |
| 294 | { | 355 | { |
| 295 | uint8_t c, m, x; | 356 | uint8_t c, m, x; |
| 296 | uint32_t cc; | 357 | uint64_t i, d, mutex; |
| 297 | int64_t i, j; | 358 | int64_t j; |
| 298 | cube_t cube, moved; | 359 | cube_t cube, moved; |
| 360 | gendata_h48_mark_t markarg; | ||
| 299 | 361 | ||
| 300 | for (i = 0, cc = 0; i < (int64_t)H48_COORDMAX(0); i++) { | 362 | markarg = (gendata_h48_mark_t) { |
| 363 | .depth = arg->depth, | ||
| 364 | .h = 0, | ||
| 365 | .k = 4, | ||
| 366 | .cocsepdata = arg->cocsepdata, | ||
| 367 | .selfsim = arg->selfsim, | ||
| 368 | .table = arg->table, | ||
| 369 | .table_mutex = arg->table_mutex, | ||
| 370 | }; | ||
| 371 | |||
| 372 | for (i = arg->start, d = 0; i < arg->end; i++) { | ||
| 373 | mutex = H48_INDEX(i, 4) % CHUNKS; | ||
| 374 | pthread_mutex_lock(arg->table_mutex[mutex]); | ||
| 301 | c = get_h48_pval(arg->table, i, 4); | 375 | c = get_h48_pval(arg->table, i, 4); |
| 376 | pthread_mutex_unlock(arg->table_mutex[mutex]); | ||
| 302 | if (c != 0xF) | 377 | if (c != 0xF) |
| 303 | continue; | 378 | continue; |
| 304 | cube = invcoord_h48(i, arg->crep, 0); | 379 | cube = invcoord_h48(i, arg->crep, 0); |
| 305 | for (m = 0; m < 18; m++) { | 380 | for (m = 0; m < 18; m++) { |
| 306 | moved = move(cube, m); | 381 | moved = move(cube, m); |
| 307 | j = coord_h48(moved, arg->cocsepdata, 0); | 382 | j = coord_h48(moved, arg->cocsepdata, 0); |
| 383 | mutex = H48_INDEX(j, 4) % CHUNKS; | ||
| 384 | pthread_mutex_lock(arg->table_mutex[mutex]); | ||
| 308 | x = get_h48_pval(arg->table, j, 4); | 385 | x = get_h48_pval(arg->table, j, 4); |
| 386 | pthread_mutex_unlock(arg->table_mutex[mutex]); | ||
| 309 | if (x >= arg->depth) | 387 | if (x >= arg->depth) |
| 310 | continue; | 388 | continue; |
| 311 | FOREACH_H48SIM(cube, arg->cocsepdata, arg->selfsim, | 389 | markarg.cube = cube; |
| 312 | j = coord_h48(cube, arg->cocsepdata, 0); | 390 | d += gendata_h48_mark(&markarg); |
| 313 | x = get_h48_pval(arg->table, j, 4); | ||
| 314 | set_h48_pval(arg->table, j, 4, arg->depth); | ||
| 315 | cc += x == 0xF; | ||
| 316 | ) | ||
| 317 | break; /* Enough to find one, skip the rest */ | 391 | break; /* Enough to find one, skip the rest */ |
| 318 | } | 392 | } |
| 319 | } | 393 | } |
| 320 | 394 | ||
| 321 | return cc; | 395 | pthread_mutex_lock(arg->distribution_mutex); |
| 396 | arg->count += d; | ||
| 397 | arg->distribution[arg->depth] += d; | ||
| 398 | pthread_mutex_unlock(arg->distribution_mutex); | ||
| 322 | } | 399 | } |
| 323 | 400 | ||
| 324 | STATIC size_t | 401 | STATIC size_t |
| @@ -369,24 +446,8 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 369 | }; | 446 | }; |
| 370 | gendata_h48short(&shortarg); | 447 | gendata_h48short(&shortarg); |
| 371 | 448 | ||
| 372 | selectedbase = base[arg->h]; | 449 | selectedbase = arg->base < 20 ? arg->base : base[arg->h]; |
| 373 | arg->info = (tableinfo_t) { | 450 | arg->info = makeinfo_h48k2(arg, selectedbase); |
| 374 | .solver = "h48 solver h = , k = 2", | ||
| 375 | .type = TABLETYPE_PRUNING, | ||
| 376 | .infosize = INFOSIZE, | ||
| 377 | .fullsize = H48_TABLESIZE(arg->h, 2) + INFOSIZE, | ||
| 378 | .hash = 0, /* TODO */ | ||
| 379 | .entries = H48_COORDMAX(arg->h), | ||
| 380 | .classes = 0, | ||
| 381 | .h48h = arg->h, | ||
| 382 | .bits = 2, | ||
| 383 | .base = selectedbase, | ||
| 384 | .maxvalue = 3, | ||
| 385 | .next = 0, | ||
| 386 | }; | ||
| 387 | arg->info.solver[15] = (arg->h % 10) + '0'; | ||
| 388 | if (arg->h >= 10) | ||
| 389 | arg->info.solver[14] = (arg->h / 10) + '0'; | ||
| 390 | 451 | ||
| 391 | inext = count = 0; | 452 | inext = count = 0; |
| 392 | pthread_mutex_init(&shortcubes_mutex, NULL); | 453 | pthread_mutex_init(&shortcubes_mutex, NULL); |
| @@ -419,6 +480,7 @@ gendata_h48k2(gendata_h48_arg_t *arg) | |||
| 419 | 480 | ||
| 420 | h48map_destroy(&shortcubes); | 481 | h48map_destroy(&shortcubes); |
| 421 | 482 | ||
| 483 | /* TODO: inline into mark */ | ||
| 422 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { | 484 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { |
| 423 | t = get_h48_pval(table, j, 2); | 485 | t = get_h48_pval(table, j, 2); |
| 424 | arg->info.distribution[t]++; | 486 | arg->info.distribution[t]++; |
| @@ -474,20 +536,35 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | |||
| 474 | int8_t d; | 536 | int8_t d; |
| 475 | uint8_t m[4]; | 537 | uint8_t m[4]; |
| 476 | cube_t cube[4]; | 538 | cube_t cube[4]; |
| 539 | gendata_h48_mark_t markarg; | ||
| 540 | |||
| 541 | markarg = (gendata_h48_mark_t) { | ||
| 542 | .h = arg->h, | ||
| 543 | .k = arg->k, | ||
| 544 | .cocsepdata = arg->cocsepdata, | ||
| 545 | .selfsim = arg->selfsim, | ||
| 546 | .table = arg->table, | ||
| 547 | .table_mutex = arg->table_mutex, | ||
| 548 | }; | ||
| 477 | 549 | ||
| 478 | d = (int8_t)arg->shortdepth - (int8_t)arg->base; | 550 | d = (int8_t)arg->shortdepth - (int8_t)arg->base; |
| 479 | 551 | ||
| 480 | /* Depth d+0 (shortcubes) */ | 552 | /* Depth d+0 (shortcubes) */ |
| 481 | gendata_h48k2_mark(arg->cube, d, arg); | 553 | markarg.depth = d; |
| 554 | markarg.cube = arg->cube; | ||
| 555 | gendata_h48_mark(&markarg); | ||
| 482 | 556 | ||
| 483 | /* Depth d+1 */ | 557 | /* Depth d+1 */ |
| 558 | markarg.depth = d+1; | ||
| 484 | for (m[0] = 0; m[0] < 18; m[0]++) { | 559 | for (m[0] = 0; m[0] < 18; m[0]++) { |
| 485 | cube[0] = move(arg->cube, m[0]); | 560 | cube[0] = move(arg->cube, m[0]); |
| 486 | if (gendata_h48k2_dfs_stop(cube[0], d+1, arg)) | 561 | if (gendata_h48k2_dfs_stop(cube[0], d+1, arg)) |
| 487 | continue; | 562 | continue; |
| 488 | gendata_h48k2_mark(cube[0], d+1, arg); | 563 | markarg.cube = cube[0]; |
| 564 | gendata_h48_mark(&markarg); | ||
| 489 | 565 | ||
| 490 | /* Depth d+2 */ | 566 | /* Depth d+2 */ |
| 567 | markarg.depth = d+2; | ||
| 491 | for (m[1] = 0; m[1] < 18; m[1]++) { | 568 | for (m[1] = 0; m[1] < 18; m[1]++) { |
| 492 | if (m[0] / 3 == m[1] / 3) { | 569 | if (m[0] / 3 == m[1] / 3) { |
| 493 | m[1] += 2; | 570 | m[1] += 2; |
| @@ -496,11 +573,13 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | |||
| 496 | cube[1] = move(cube[0], m[1]); | 573 | cube[1] = move(cube[0], m[1]); |
| 497 | if (gendata_h48k2_dfs_stop(cube[1], d+2, arg)) | 574 | if (gendata_h48k2_dfs_stop(cube[1], d+2, arg)) |
| 498 | continue; | 575 | continue; |
| 499 | gendata_h48k2_mark(cube[1], d+2, arg); | 576 | markarg.cube = cube[1]; |
| 577 | gendata_h48_mark(&markarg); | ||
| 500 | if (d >= 0) | 578 | if (d >= 0) |
| 501 | continue; | 579 | continue; |
| 502 | 580 | ||
| 503 | /* Depth d+3 */ | 581 | /* Depth d+3 */ |
| 582 | markarg.depth = d+3; | ||
| 504 | for (m[2] = 0; m[2] < 18; m[2]++) { | 583 | for (m[2] = 0; m[2] < 18; m[2]++) { |
| 505 | if (!allowednextmove(m, 3)) { | 584 | if (!allowednextmove(m, 3)) { |
| 506 | m[2] += 2; | 585 | m[2] += 2; |
| @@ -509,48 +588,55 @@ gendata_h48k2_dfs(h48k2_dfs_arg_t *arg) | |||
| 509 | cube[2] = move(cube[1], m[2]); | 588 | cube[2] = move(cube[1], m[2]); |
| 510 | if (gendata_h48k2_dfs_stop(cube[2], d+3, arg)) | 589 | if (gendata_h48k2_dfs_stop(cube[2], d+3, arg)) |
| 511 | continue; | 590 | continue; |
| 512 | gendata_h48k2_mark(cube[2], d+3, arg); | 591 | markarg.cube = cube[2]; |
| 592 | gendata_h48_mark(&markarg); | ||
| 513 | if (d >= -1) | 593 | if (d >= -1) |
| 514 | continue; | 594 | continue; |
| 515 | 595 | ||
| 516 | /* Depth d+4 */ | 596 | /* Depth d+4 */ |
| 597 | markarg.depth = d+4; | ||
| 517 | for (m[3] = 0; m[3] < 18; m[3]++) { | 598 | for (m[3] = 0; m[3] < 18; m[3]++) { |
| 518 | if (!allowednextmove(m, 4)) { | 599 | if (!allowednextmove(m, 4)) { |
| 519 | m[3] += 2; | 600 | m[3] += 2; |
| 520 | continue; | 601 | continue; |
| 521 | } | 602 | } |
| 522 | cube[3] = move(cube[2], m[3]); | 603 | cube[3] = move(cube[2], m[3]); |
| 523 | gendata_h48k2_mark(cube[3], d+4, arg); | 604 | markarg.cube = cube[3]; |
| 605 | gendata_h48_mark(&markarg); | ||
| 524 | } | 606 | } |
| 525 | } | 607 | } |
| 526 | } | 608 | } |
| 527 | } | 609 | } |
| 528 | } | 610 | } |
| 529 | 611 | ||
| 530 | STATIC_INLINE void | 612 | STATIC_INLINE uint64_t |
| 531 | gendata_h48k2_mark(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) | 613 | gendata_h48_mark(gendata_h48_mark_t *arg) |
| 532 | { | 614 | { |
| 533 | uint8_t oldval, newval; | 615 | uint8_t oldval, newval; |
| 534 | int64_t coord, fullcoord, mutex; | 616 | uint64_t d; |
| 617 | int64_t coord, mutex; | ||
| 535 | 618 | ||
| 536 | FOREACH_H48SIM(cube, arg->cocsepdata, arg->selfsim, | 619 | d = 0; |
| 537 | fullcoord = coord_h48(cube, arg->cocsepdata, 11); | 620 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, |
| 538 | coord = fullcoord >> (int64_t)(11 - arg->h); | 621 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); |
| 539 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | 622 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; |
| 540 | pthread_mutex_lock(arg->table_mutex[mutex]); | 623 | pthread_mutex_lock(arg->table_mutex[mutex]); |
| 541 | oldval = get_h48_pval(arg->table, coord, arg->k); | 624 | oldval = get_h48_pval(arg->table, coord, arg->k); |
| 542 | newval = (uint8_t)MAX(depth, 0); | 625 | newval = (uint8_t)MAX(arg->depth, 0); |
| 626 | d += newval < oldval; | ||
| 543 | set_h48_pval(arg->table, coord, arg->k, MIN(oldval, newval)); | 627 | set_h48_pval(arg->table, coord, arg->k, MIN(oldval, newval)); |
| 544 | pthread_mutex_unlock(arg->table_mutex[mutex]); | 628 | pthread_mutex_unlock(arg->table_mutex[mutex]); |
| 545 | ) | 629 | ) |
| 630 | |||
| 631 | return d; | ||
| 546 | } | 632 | } |
| 547 | 633 | ||
| 548 | STATIC_INLINE bool | 634 | STATIC_INLINE bool |
| 549 | gendata_h48k2_dfs_stop(cube_t cube, uint8_t depth, h48k2_dfs_arg_t *arg) | 635 | gendata_h48k2_dfs_stop(cube_t cube, int8_t depth, h48k2_dfs_arg_t *arg) |
| 550 | { | 636 | { |
| 551 | uint64_t val; | 637 | uint64_t val; |
| 552 | int64_t coord; | 638 | int64_t coord; |
| 553 | uint8_t oldval; | 639 | int8_t oldval; |
| 554 | 640 | ||
| 555 | if (arg->h == 0 || arg->h == 11) { | 641 | if (arg->h == 0 || arg->h == 11) { |
| 556 | /* We are in the "real coordinate" case, we can stop | 642 | /* We are in the "real coordinate" case, we can stop |
| @@ -568,26 +654,107 @@ gendata_h48k2_dfs_stop(cube_t cube, uint8_t depth, h48k2_dfs_arg_t *arg) | |||
| 568 | } | 654 | } |
| 569 | } | 655 | } |
| 570 | 656 | ||
| 571 | STATIC_INLINE uint8_t | 657 | STATIC size_t |
| 572 | get_h48_pval(const uint8_t *table, int64_t i, uint8_t k) | 658 | gendata_h48k2_realcoord(gendata_h48_arg_t *arg) |
| 573 | { | 659 | { |
| 574 | return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); | 660 | #if 1 |
| 661 | return gendata_h48k2(arg); | ||
| 662 | #else | ||
| 663 | uint8_t t, selectedbase, *table; | ||
| 664 | uint64_t i, ii, count; | ||
| 665 | int64_t j; | ||
| 666 | h48k2_dfs_arg_t dfsarg[THREADS]; | ||
| 667 | pthread_t thread[THREADS]; | ||
| 668 | pthread_mutex_t count_mutex, table_mutex[CHUNKS]; | ||
| 669 | |||
| 670 | if (arg->buf == NULL) | ||
| 671 | goto gendata_h48k2_realcoord_return_size; | ||
| 672 | |||
| 673 | table = (uint8_t *)arg->h48buf + INFOSIZE; | ||
| 674 | if (arg->buf != NULL) | ||
| 675 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); | ||
| 676 | |||
| 677 | selectedbase = arg->base < 20 ? arg->base : (arg->h == 0 ? 8 : 10); | ||
| 678 | arg->info = makeinfo_h48k2(arg, selectedbase); | ||
| 679 | |||
| 680 | count = 0; | ||
| 681 | for (i = 0; i < CHUNKS; i++) | ||
| 682 | pthread_mutex_init(&table_mutex[i], NULL); | ||
| 683 | |||
| 684 | /* TODO | ||
| 685 | for (i = 0; i < THREADS; i++) { | ||
| 686 | dfsarg[i] = (h48k2_dfs_arg_t){ | ||
| 687 | .h = arg->h, | ||
| 688 | .k = arg->k, | ||
| 689 | .base = selectedbase, | ||
| 690 | .cocsepdata = arg->cocsepdata, | ||
| 691 | .table = table, | ||
| 692 | .selfsim = arg->selfsim, | ||
| 693 | .crep = arg->crep, | ||
| 694 | .shortcubes_mutex = &count_mutex, | ||
| 695 | .count = &count, | ||
| 696 | }; | ||
| 697 | for (ii = 0; ii < CHUNKS; ii++) | ||
| 698 | dfsarg[i].table_mutex[ii] = &table_mutex[ii]; | ||
| 699 | |||
| 700 | pthread_create(&thread[i], NULL, | ||
| 701 | gendata_h48k2_realcoord_runthread, &dfsarg[i]); | ||
| 702 | } | ||
| 703 | |||
| 704 | for (i = 0; i < THREADS; i++) | ||
| 705 | pthread_join(thread[i], NULL); | ||
| 706 | */ | ||
| 707 | |||
| 708 | /* TODO: inline into mark */ | ||
| 709 | for (j = 0; j < H48_COORDMAX(arg->h); j++) { | ||
| 710 | t = get_h48_pval(table, j, 2); | ||
| 711 | arg->info.distribution[t]++; | ||
| 712 | } | ||
| 713 | |||
| 714 | writetableinfo(&arg->info, arg->h48buf); | ||
| 715 | |||
| 716 | gendata_h48k2_realcoord_return_size: | ||
| 717 | return H48_TABLESIZE(arg->h, 2) + INFOSIZE; | ||
| 718 | #endif | ||
| 575 | } | 719 | } |
| 576 | 720 | ||
| 577 | STATIC_INLINE void | 721 | STATIC void * |
| 578 | set_h48_pval(uint8_t *table, int64_t i, uint8_t k, uint8_t val) | 722 | gendata_h48k2_realcoord_runthread(void *arg) |
| 579 | { | 723 | { |
| 580 | table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | 724 | /* TODO |
| 581 | | (val << H48_SHIFT(i, k)); | 725 | uint64_t count, coord, mutex; |
| 726 | h48k2_dfs_arg_t *dfsarg; | ||
| 727 | |||
| 728 | dfsarg = (h48k2_dfs_arg_t *)arg; | ||
| 729 | |||
| 730 | */ | ||
| 731 | return NULL; | ||
| 582 | } | 732 | } |
| 583 | 733 | ||
| 584 | STATIC_INLINE uint8_t | 734 | STATIC tableinfo_t |
| 585 | get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table) | 735 | makeinfo_h48k2(gendata_h48_arg_t *arg, uint8_t base) |
| 586 | { | 736 | { |
| 587 | int64_t coord; | 737 | tableinfo_t info; |
| 588 | 738 | ||
| 589 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); | 739 | info = (tableinfo_t) { |
| 590 | return get_h48_pval(table, coord, k); | 740 | .solver = "h48 solver h = , k = 2", |
| 741 | .type = TABLETYPE_PRUNING, | ||
| 742 | .infosize = INFOSIZE, | ||
| 743 | .fullsize = H48_TABLESIZE(arg->h, 2) + INFOSIZE, | ||
| 744 | .hash = 0, /* TODO */ | ||
| 745 | .entries = H48_COORDMAX(arg->h), | ||
| 746 | .classes = 0, | ||
| 747 | .h48h = arg->h, | ||
| 748 | .bits = 2, | ||
| 749 | .base = base, | ||
| 750 | .maxvalue = 3, | ||
| 751 | .next = 0, | ||
| 752 | }; | ||
| 753 | info.solver[15] = (arg->h % 10) + '0'; | ||
| 754 | if (arg->h >= 10) | ||
| 755 | info.solver[14] = (arg->h / 10) + '0'; | ||
| 756 | |||
| 757 | return info; | ||
| 591 | } | 758 | } |
| 592 | 759 | ||
| 593 | STATIC uint32_t * | 760 | STATIC uint32_t * |
| @@ -601,3 +768,25 @@ get_h48data_ptr(const void *data) | |||
| 601 | { | 768 | { |
| 602 | return (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE; | 769 | return (uint8_t *)data + COCSEP_FULLSIZE + INFOSIZE; |
| 603 | } | 770 | } |
| 771 | |||
| 772 | STATIC_INLINE uint8_t | ||
| 773 | get_h48_pval(const uint8_t *table, int64_t i, uint8_t k) | ||
| 774 | { | ||
| 775 | return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); | ||
| 776 | } | ||
| 777 | |||
| 778 | STATIC_INLINE void | ||
| 779 | set_h48_pval(uint8_t *table, int64_t i, uint8_t k, uint8_t val) | ||
| 780 | { | ||
| 781 | table[H48_INDEX(i, k)] = (table[H48_INDEX(i, k)] & (~H48_MASK(i, k))) | ||
| 782 | | (val << H48_SHIFT(i, k)); | ||
| 783 | } | ||
| 784 | |||
| 785 | STATIC_INLINE uint8_t | ||
| 786 | get_h48_bound(cube_t cube, uint32_t cdata, uint8_t h, uint8_t k, uint8_t *table) | ||
| 787 | { | ||
| 788 | int64_t coord; | ||
| 789 | |||
| 790 | coord = coord_h48_edges(cube, COCLASS(cdata), TTREP(cdata), h); | ||
| 791 | return get_h48_pval(table, coord, k); | ||
| 792 | } | ||
