diff options
Diffstat (limited to 'src/solvers/h48')
| -rw-r--r-- | src/solvers/h48/gendata_h48.h | 79 | ||||
| -rw-r--r-- | src/solvers/h48/gendata_types_macros.h | 16 | ||||
| -rw-r--r-- | src/solvers/h48/solve.h | 26 | ||||
| -rw-r--r-- | src/solvers/h48/utils.h | 11 |
4 files changed, 74 insertions, 58 deletions
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h index c75556d..7ccadd6 100644 --- a/src/solvers/h48/gendata_h48.h +++ b/src/solvers/h48/gendata_h48.h | |||
| @@ -21,9 +21,9 @@ STATIC const unsigned char *get_h48data_constptr(const unsigned char *); | |||
| 21 | STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t); | 21 | STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t); |
| 22 | STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t); | 22 | STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t); |
| 23 | STATIC_INLINE uint8_t get_h48_pval_atomic( | 23 | STATIC_INLINE uint8_t get_h48_pval_atomic( |
| 24 | _Atomic const unsigned char *, uint64_t, uint8_t); | 24 | wrapthread_atomic const unsigned char *, uint64_t, uint8_t); |
| 25 | STATIC_INLINE void set_h48_pval_atomic( | 25 | STATIC_INLINE void set_h48_pval_atomic( |
| 26 | _Atomic unsigned char *, uint64_t, uint8_t, uint8_t); | 26 | wrapthread_atomic unsigned char *, uint64_t, uint8_t, uint8_t); |
| 27 | 27 | ||
| 28 | STATIC long long | 28 | STATIC long long |
| 29 | gendata_h48_dispatch( | 29 | gendata_h48_dispatch( |
| @@ -115,7 +115,7 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 115 | 115 | ||
| 116 | cocsepdata_offset = arg->buf + INFOSIZE; | 116 | cocsepdata_offset = arg->buf + INFOSIZE; |
| 117 | arg->cocsepdata = (uint32_t *)cocsepdata_offset; | 117 | arg->cocsepdata = (uint32_t *)cocsepdata_offset; |
| 118 | arg->h48buf = (_Atomic unsigned char*)arg->buf + cocsepsize; | 118 | arg->h48buf = (wrapthread_atomic unsigned char*)arg->buf + cocsepsize; |
| 119 | 119 | ||
| 120 | arg->base = 99; | 120 | arg->base = 99; |
| 121 | 121 | ||
| @@ -207,13 +207,13 @@ gendata_h48(gendata_h48_arg_t arg[static 1]) | |||
| 207 | STATIC void | 207 | STATIC void |
| 208 | gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | 208 | gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) |
| 209 | { | 209 | { |
| 210 | _Atomic unsigned char *table; | 210 | wrapthread_atomic unsigned char *table; |
| 211 | uint8_t val; | 211 | uint8_t val; |
| 212 | uint64_t i, sc, done, d, h48max; | 212 | uint64_t i, sc, done, d, h48max; |
| 213 | uint64_t t, tt, isize, cc, bufsize; | 213 | uint64_t t, tt, isize, cc, bufsize; |
| 214 | h48h0k4_bfs_arg_t bfsarg[THREADS]; | 214 | h48h0k4_bfs_arg_t bfsarg[THREADS]; |
| 215 | pthread_t thread[THREADS]; | 215 | wrapthread_define_var_thread_t(thread[THREADS]); |
| 216 | pthread_mutex_t table_mutex[CHUNKS]; | 216 | wrapthread_define_var_mutex_t(table_mutex[CHUNKS]); |
| 217 | 217 | ||
| 218 | arg->info = (tableinfo_t) { | 218 | arg->info = (tableinfo_t) { |
| 219 | .solver = "h48 solver h = 0, k = 4", | 219 | .solver = "h48 solver h = 0, k = 4", |
| @@ -241,7 +241,7 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | |||
| 241 | isize = h48max / THREADS; | 241 | isize = h48max / THREADS; |
| 242 | isize = (isize / H48_COEFF(arg->k)) * H48_COEFF(arg->k); | 242 | isize = (isize / H48_COEFF(arg->k)) * H48_COEFF(arg->k); |
| 243 | for (t = 0; t < CHUNKS; t++) | 243 | for (t = 0; t < CHUNKS; t++) |
| 244 | pthread_mutex_init(&table_mutex[t], NULL); | 244 | wrapthread_mutex_init(&table_mutex[t], NULL); |
| 245 | for (t = 0; t < THREADS; t++) { | 245 | for (t = 0; t < THREADS; t++) { |
| 246 | bfsarg[t] = (h48h0k4_bfs_arg_t) { | 246 | bfsarg[t] = (h48h0k4_bfs_arg_t) { |
| 247 | .cocsepdata = arg->cocsepdata, | 247 | .cocsepdata = arg->cocsepdata, |
| @@ -259,12 +259,12 @@ gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) | |||
| 259 | 259 | ||
| 260 | for (t = 0; t < THREADS; t++) { | 260 | for (t = 0; t < THREADS; t++) { |
| 261 | bfsarg[t].depth = d; | 261 | bfsarg[t].depth = d; |
| 262 | pthread_create(&thread[t], NULL, | 262 | wrapthread_create(&thread[t], NULL, |
| 263 | gendata_h48h0k4_runthread, &bfsarg[t]); | 263 | gendata_h48h0k4_runthread, &bfsarg[t]); |
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | for (t = 0; t < THREADS; t++) | 266 | for (t = 0; t < THREADS; t++) |
| 267 | pthread_join(thread[t], NULL); | 267 | wrapthread_join(thread[t], NULL); |
| 268 | 268 | ||
| 269 | for (i = 0, cc = 0; i < h48max; i++) { | 269 | for (i = 0, cc = 0; i < h48max; i++) { |
| 270 | val = get_h48_pval_atomic(table, i, 4); | 270 | val = get_h48_pval_atomic(table, i, 4); |
| @@ -395,13 +395,14 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 395 | int sleeptime; | 395 | int sleeptime; |
| 396 | unsigned char *table; | 396 | unsigned char *table; |
| 397 | uint64_t j; | 397 | uint64_t j; |
| 398 | _Atomic uint64_t count; | 398 | wrapthread_atomic uint64_t count; |
| 399 | uint64_t i, ii, inext, bufsize, done, nshort, velocity; | 399 | uint64_t i, ii, inext, bufsize, done, nshort, velocity; |
| 400 | h48map_t shortcubes; | 400 | h48map_t shortcubes; |
| 401 | gendata_h48short_arg_t shortarg; | 401 | gendata_h48short_arg_t shortarg; |
| 402 | h48k2_dfs_arg_t dfsarg[THREADS]; | 402 | h48k2_dfs_arg_t dfsarg[THREADS]; |
| 403 | pthread_t thread[THREADS]; | 403 | wrapthread_define_var_thread_t(thread[THREADS]); |
| 404 | pthread_mutex_t shortcubes_mutex, table_mutex[CHUNKS]; | 404 | wrapthread_define_var_mutex_t(shortcubes_mutex); |
| 405 | wrapthread_define_var_mutex_t(table_mutex[CHUNKS]); | ||
| 405 | 406 | ||
| 406 | table = (unsigned char *)arg->h48buf + INFOSIZE; | 407 | table = (unsigned char *)arg->h48buf + INFOSIZE; |
| 407 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); | 408 | memset(table, 0xFF, H48_TABLESIZE(arg->h, arg->k)); |
| @@ -425,9 +426,9 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 425 | 426 | ||
| 426 | inext = 0; | 427 | inext = 0; |
| 427 | count = 0; | 428 | count = 0; |
| 428 | pthread_mutex_init(&shortcubes_mutex, NULL); | 429 | wrapthread_mutex_init(&shortcubes_mutex, NULL); |
| 429 | for (i = 0; i < CHUNKS; i++) | 430 | for (i = 0; i < CHUNKS; i++) |
| 430 | pthread_mutex_init(&table_mutex[i], NULL); | 431 | wrapthread_mutex_init(&table_mutex[i], NULL); |
| 431 | for (i = 0; i < THREADS; i++) { | 432 | for (i = 0; i < THREADS; i++) { |
| 432 | dfsarg[i] = (h48k2_dfs_arg_t){ | 433 | dfsarg[i] = (h48k2_dfs_arg_t){ |
| 433 | .h = arg->h, | 434 | .h = arg->h, |
| @@ -446,7 +447,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 446 | for (ii = 0; ii < CHUNKS; ii++) | 447 | for (ii = 0; ii < CHUNKS; ii++) |
| 447 | dfsarg[i].table_mutex[ii] = &table_mutex[ii]; | 448 | dfsarg[i].table_mutex[ii] = &table_mutex[ii]; |
| 448 | 449 | ||
| 449 | pthread_create( | 450 | wrapthread_create( |
| 450 | &thread[i], NULL, gendata_h48k2_runthread, &dfsarg[i]); | 451 | &thread[i], NULL, gendata_h48k2_runthread, &dfsarg[i]); |
| 451 | } | 452 | } |
| 452 | 453 | ||
| @@ -464,9 +465,9 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 464 | done = count; | 465 | done = count; |
| 465 | while (nshort - done > (velocity * sleeptime) / 1000) { | 466 | while (nshort - done > (velocity * sleeptime) / 1000) { |
| 466 | msleep(sleeptime); | 467 | msleep(sleeptime); |
| 467 | pthread_mutex_lock(&shortcubes_mutex); | 468 | wrapthread_mutex_lock(&shortcubes_mutex); |
| 468 | done = count; | 469 | done = count; |
| 469 | pthread_mutex_unlock(&shortcubes_mutex); | 470 | wrapthread_mutex_unlock(&shortcubes_mutex); |
| 470 | LOG("Processed %" PRIu64 " / %" PRIu64 " cubes\n", | 471 | LOG("Processed %" PRIu64 " / %" PRIu64 " cubes\n", |
| 471 | (done / 1000) * 1000, nshort); | 472 | (done / 1000) * 1000, nshort); |
| 472 | } | 473 | } |
| @@ -476,7 +477,7 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 476 | } | 477 | } |
| 477 | 478 | ||
| 478 | for (i = 0; i < THREADS; i++) | 479 | for (i = 0; i < THREADS; i++) |
| 479 | pthread_join(thread[i], NULL); | 480 | wrapthread_join(thread[i], NULL); |
| 480 | 481 | ||
| 481 | h48map_destroy(&shortcubes); | 482 | h48map_destroy(&shortcubes); |
| 482 | 483 | ||
| @@ -492,29 +493,30 @@ gendata_h48k2(gendata_h48_arg_t arg[static 1]) | |||
| 492 | STATIC void * | 493 | STATIC void * |
| 493 | gendata_h48k2_runthread(void *arg) | 494 | gendata_h48k2_runthread(void *arg) |
| 494 | { | 495 | { |
| 495 | uint64_t coord, mutex; | 496 | uint64_t coord; |
| 496 | kvpair_t kv; | 497 | kvpair_t kv; |
| 497 | h48k2_dfs_arg_t *dfsarg; | 498 | h48k2_dfs_arg_t *dfsarg; |
| 499 | wrapthread_define_if_threads(uint64_t, mutex); | ||
| 498 | 500 | ||
| 499 | dfsarg = (h48k2_dfs_arg_t *)arg; | 501 | dfsarg = (h48k2_dfs_arg_t *)arg; |
| 500 | 502 | ||
| 501 | while (true) { | 503 | while (true) { |
| 502 | pthread_mutex_lock(dfsarg->shortcubes_mutex); | 504 | wrapthread_mutex_lock(dfsarg->shortcubes_mutex); |
| 503 | 505 | ||
| 504 | kv = h48map_nextkvpair(dfsarg->shortcubes, dfsarg->next); | 506 | kv = h48map_nextkvpair(dfsarg->shortcubes, dfsarg->next); |
| 505 | if (*dfsarg->next == dfsarg->shortcubes->capacity) { | 507 | if (*dfsarg->next == dfsarg->shortcubes->capacity) { |
| 506 | pthread_mutex_unlock(dfsarg->shortcubes_mutex); | 508 | wrapthread_mutex_unlock(dfsarg->shortcubes_mutex); |
| 507 | break; | 509 | break; |
| 508 | } | 510 | } |
| 509 | (*dfsarg->count)++; | 511 | (*dfsarg->count)++; |
| 510 | pthread_mutex_unlock(dfsarg->shortcubes_mutex); | 512 | wrapthread_mutex_unlock(dfsarg->shortcubes_mutex); |
| 511 | 513 | ||
| 512 | if (kv.val < dfsarg->shortdepth) { | 514 | if (kv.val < dfsarg->shortdepth) { |
| 513 | coord = kv.key >> (uint64_t)(11 - dfsarg->h); | 515 | coord = kv.key >> (uint64_t)(11 - dfsarg->h); |
| 514 | mutex = H48_INDEX(coord, dfsarg->k) % CHUNKS; | 516 | mutex = H48_INDEX(coord, dfsarg->k) % CHUNKS; |
| 515 | pthread_mutex_lock(dfsarg->table_mutex[mutex]); | 517 | wrapthread_mutex_lock(dfsarg->table_mutex[mutex]); |
| 516 | set_h48_pval(dfsarg->table, coord, dfsarg->k, 0); | 518 | set_h48_pval(dfsarg->table, coord, dfsarg->k, 0); |
| 517 | pthread_mutex_unlock(dfsarg->table_mutex[mutex]); | 519 | wrapthread_mutex_unlock(dfsarg->table_mutex[mutex]); |
| 518 | } else { | 520 | } else { |
| 519 | dfsarg->cube = invcoord_h48(kv.key, dfsarg->crep, 11); | 521 | dfsarg->cube = invcoord_h48(kv.key, dfsarg->crep, 11); |
| 520 | gendata_h48k2_dfs(dfsarg); | 522 | gendata_h48k2_dfs(dfsarg); |
| @@ -607,7 +609,8 @@ STATIC_INLINE void | |||
| 607 | gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) | 609 | gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) |
| 608 | { | 610 | { |
| 609 | uint8_t oldval, newval; | 611 | uint8_t oldval, newval; |
| 610 | uint64_t coord, mutex; | 612 | uint64_t coord; |
| 613 | wrapthread_define_if_threads(uint64_t, mutex); | ||
| 611 | 614 | ||
| 612 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, | 615 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, |
| 613 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); | 616 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); |
| @@ -615,10 +618,10 @@ gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) | |||
| 615 | newval = (uint8_t)MAX(arg->depth, 0); | 618 | newval = (uint8_t)MAX(arg->depth, 0); |
| 616 | if (newval < oldval) { | 619 | if (newval < oldval) { |
| 617 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | 620 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; |
| 618 | pthread_mutex_lock(arg->table_mutex[mutex]); | 621 | wrapthread_mutex_lock(arg->table_mutex[mutex]); |
| 619 | set_h48_pval_atomic( | 622 | set_h48_pval_atomic( |
| 620 | arg->table_atomic, coord, arg->k, newval); | 623 | arg->table_atomic, coord, arg->k, newval); |
| 621 | pthread_mutex_unlock(arg->table_mutex[mutex]); | 624 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); |
| 622 | } | 625 | } |
| 623 | ) | 626 | ) |
| 624 | } | 627 | } |
| @@ -627,16 +630,17 @@ STATIC_INLINE void | |||
| 627 | gendata_h48_mark(gendata_h48_mark_t arg[static 1]) | 630 | gendata_h48_mark(gendata_h48_mark_t arg[static 1]) |
| 628 | { | 631 | { |
| 629 | uint8_t oldval, newval; | 632 | uint8_t oldval, newval; |
| 630 | uint64_t coord, mutex; | 633 | uint64_t coord; |
| 634 | wrapthread_define_if_threads(uint64_t, mutex); | ||
| 631 | 635 | ||
| 632 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, | 636 | FOREACH_H48SIM(arg->cube, arg->cocsepdata, arg->selfsim, |
| 633 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); | 637 | coord = coord_h48(arg->cube, arg->cocsepdata, arg->h); |
| 634 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | 638 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; |
| 635 | pthread_mutex_lock(arg->table_mutex[mutex]); | 639 | wrapthread_mutex_lock(arg->table_mutex[mutex]); |
| 636 | oldval = get_h48_pval(arg->table, coord, arg->k); | 640 | oldval = get_h48_pval(arg->table, coord, arg->k); |
| 637 | newval = (uint8_t)MAX(arg->depth, 0); | 641 | newval = (uint8_t)MAX(arg->depth, 0); |
| 638 | set_h48_pval(arg->table, coord, arg->k, MIN(newval, oldval)); | 642 | set_h48_pval(arg->table, coord, arg->k, MIN(newval, oldval)); |
| 639 | pthread_mutex_unlock(arg->table_mutex[mutex]); | 643 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); |
| 640 | ) | 644 | ) |
| 641 | } | 645 | } |
| 642 | 646 | ||
| @@ -644,7 +648,8 @@ STATIC_INLINE bool | |||
| 644 | gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) | 648 | gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) |
| 645 | { | 649 | { |
| 646 | uint64_t val; | 650 | uint64_t val; |
| 647 | uint64_t coord, mutex; | 651 | uint64_t coord; |
| 652 | wrapthread_define_if_threads(uint64_t, mutex); | ||
| 648 | int8_t oldval; | 653 | int8_t oldval; |
| 649 | 654 | ||
| 650 | if (arg->h == 0 || arg->h == 11) { | 655 | if (arg->h == 0 || arg->h == 11) { |
| @@ -652,9 +657,9 @@ gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) | |||
| 652 | if this coordinate has already been visited */ | 657 | if this coordinate has already been visited */ |
| 653 | coord = coord_h48(cube, arg->cocsepdata, arg->h); | 658 | coord = coord_h48(cube, arg->cocsepdata, arg->h); |
| 654 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; | 659 | mutex = H48_INDEX(coord, arg->k) % CHUNKS; |
| 655 | pthread_mutex_lock(arg->table_mutex[mutex]); | 660 | wrapthread_mutex_lock(arg->table_mutex[mutex]); |
| 656 | oldval = get_h48_pval(arg->table, coord, arg->k); | 661 | oldval = get_h48_pval(arg->table, coord, arg->k); |
| 657 | pthread_mutex_unlock(arg->table_mutex[mutex]); | 662 | wrapthread_mutex_unlock(arg->table_mutex[mutex]); |
| 658 | return oldval <= d; | 663 | return oldval <= d; |
| 659 | } else { | 664 | } else { |
| 660 | /* With 0 < k < 11 we do not have a "real coordinate". | 665 | /* With 0 < k < 11 we do not have a "real coordinate". |
| @@ -711,7 +716,11 @@ get_h48_pval(const unsigned char *table, uint64_t i, uint8_t k) | |||
| 711 | } | 716 | } |
| 712 | 717 | ||
| 713 | STATIC_INLINE uint8_t | 718 | STATIC_INLINE uint8_t |
| 714 | get_h48_pval_atomic(_Atomic const unsigned char *table, uint64_t i, uint8_t k) | 719 | get_h48_pval_atomic( |
| 720 | wrapthread_atomic const unsigned char *table, | ||
| 721 | uint64_t i, | ||
| 722 | uint8_t k | ||
| 723 | ) | ||
| 715 | { | 724 | { |
| 716 | return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); | 725 | return (table[H48_INDEX(i, k)] & H48_MASK(i, k)) >> H48_SHIFT(i, k); |
| 717 | } | 726 | } |
| @@ -725,7 +734,7 @@ set_h48_pval(unsigned char *table, uint64_t i, uint8_t k, uint8_t val) | |||
| 725 | 734 | ||
| 726 | STATIC_INLINE void | 735 | STATIC_INLINE void |
| 727 | set_h48_pval_atomic( | 736 | set_h48_pval_atomic( |
| 728 | _Atomic unsigned char *table, | 737 | wrapthread_atomic unsigned char *table, |
| 729 | uint64_t i, | 738 | uint64_t i, |
| 730 | uint8_t k, | 739 | uint8_t k, |
| 731 | uint8_t val | 740 | uint8_t val |
diff --git a/src/solvers/h48/gendata_types_macros.h b/src/solvers/h48/gendata_types_macros.h index 9be8e0f..e66dedb 100644 --- a/src/solvers/h48/gendata_types_macros.h +++ b/src/solvers/h48/gendata_types_macros.h | |||
| @@ -68,7 +68,7 @@ typedef struct { | |||
| 68 | tableinfo_t info; | 68 | tableinfo_t info; |
| 69 | uint64_t buf_size; | 69 | uint64_t buf_size; |
| 70 | unsigned char *buf; | 70 | unsigned char *buf; |
| 71 | _Atomic unsigned char *h48buf; | 71 | wrapthread_atomic unsigned char *h48buf; |
| 72 | uint32_t *cocsepdata; | 72 | uint32_t *cocsepdata; |
| 73 | uint64_t selfsim[COCSEP_CLASSES]; | 73 | uint64_t selfsim[COCSEP_CLASSES]; |
| 74 | cube_t crep[COCSEP_CLASSES]; | 74 | cube_t crep[COCSEP_CLASSES]; |
| @@ -85,12 +85,12 @@ typedef struct { | |||
| 85 | typedef struct { | 85 | typedef struct { |
| 86 | uint8_t depth; | 86 | uint8_t depth; |
| 87 | uint32_t *cocsepdata; | 87 | uint32_t *cocsepdata; |
| 88 | _Atomic unsigned char *table; | 88 | wrapthread_atomic unsigned char *table; |
| 89 | uint64_t *selfsim; | 89 | uint64_t *selfsim; |
| 90 | cube_t *crep; | 90 | cube_t *crep; |
| 91 | uint64_t start; | 91 | uint64_t start; |
| 92 | uint64_t end; | 92 | uint64_t end; |
| 93 | pthread_mutex_t *table_mutex[CHUNKS]; | 93 | wrapthread_define_struct_mutex_t(*table_mutex[CHUNKS]); |
| 94 | } h48h0k4_bfs_arg_t; | 94 | } h48h0k4_bfs_arg_t; |
| 95 | 95 | ||
| 96 | typedef struct { | 96 | typedef struct { |
| @@ -104,10 +104,10 @@ typedef struct { | |||
| 104 | uint64_t *selfsim; | 104 | uint64_t *selfsim; |
| 105 | cube_t *crep; | 105 | cube_t *crep; |
| 106 | h48map_t *shortcubes; | 106 | h48map_t *shortcubes; |
| 107 | pthread_mutex_t *shortcubes_mutex; | 107 | wrapthread_define_struct_mutex_t(*shortcubes_mutex); |
| 108 | pthread_mutex_t *table_mutex[CHUNKS]; | 108 | wrapthread_define_struct_mutex_t(*table_mutex[CHUNKS]); |
| 109 | uint64_t *next; | 109 | uint64_t *next; |
| 110 | _Atomic uint64_t *count; | 110 | wrapthread_atomic uint64_t *count; |
| 111 | } h48k2_dfs_arg_t; | 111 | } h48k2_dfs_arg_t; |
| 112 | 112 | ||
| 113 | typedef struct { | 113 | typedef struct { |
| @@ -118,6 +118,6 @@ typedef struct { | |||
| 118 | uint32_t *cocsepdata; | 118 | uint32_t *cocsepdata; |
| 119 | uint64_t *selfsim; | 119 | uint64_t *selfsim; |
| 120 | unsigned char *table; | 120 | unsigned char *table; |
| 121 | _Atomic unsigned char *table_atomic; | 121 | wrapthread_atomic unsigned char *table_atomic; |
| 122 | pthread_mutex_t **table_mutex; | 122 | wrapthread_define_struct_mutex_t(**table_mutex); |
| 123 | } gendata_h48_mark_t; | 123 | } gendata_h48_mark_t; |
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h index 50e4f99..bf10723 100644 --- a/src/solvers/h48/solve.h +++ b/src/solvers/h48/solve.h | |||
| @@ -43,9 +43,9 @@ typedef struct { | |||
| 43 | int ntasks; | 43 | int ntasks; |
| 44 | solve_h48_task_t *tasks; | 44 | solve_h48_task_t *tasks; |
| 45 | int thread_id; | 45 | int thread_id; |
| 46 | pthread_mutex_t *solutions_mutex; | 46 | wrapthread_define_struct_mutex_t(*solutions_mutex); |
| 47 | _Atomic int *status; | 47 | wrapthread_atomic int *status; |
| 48 | _Atomic bool thread_done; | 48 | wrapthread_atomic bool thread_done; |
| 49 | } dfsarg_solve_h48_t; | 49 | } dfsarg_solve_h48_t; |
| 50 | 50 | ||
| 51 | typedef struct { | 51 | typedef struct { |
| @@ -207,10 +207,10 @@ solve_h48_dfs(dfsarg_solve_h48_t arg[static 1]) | |||
| 207 | + arg->solution_moves->npremoves; | 207 | + arg->solution_moves->npremoves; |
| 208 | if (arg->target_depth != nm) | 208 | if (arg->target_depth != nm) |
| 209 | return 0; | 209 | return 0; |
| 210 | pthread_mutex_lock(arg->solutions_mutex); | 210 | wrapthread_mutex_lock(arg->solutions_mutex); |
| 211 | ret = appendsolution(arg->solution_moves, | 211 | ret = appendsolution(arg->solution_moves, |
| 212 | arg->solution_settings, arg->solution_list); | 212 | arg->solution_settings, arg->solution_list); |
| 213 | pthread_mutex_unlock(arg->solutions_mutex); | 213 | wrapthread_mutex_unlock(arg->solutions_mutex); |
| 214 | return ret; | 214 | return ret; |
| 215 | } | 215 | } |
| 216 | 216 | ||
| @@ -455,7 +455,7 @@ solve_h48( | |||
| 455 | { | 455 | { |
| 456 | int i, ntasks, eoesep_table_index; | 456 | int i, ntasks, eoesep_table_index; |
| 457 | bool td; | 457 | bool td; |
| 458 | _Atomic int status, prev_status; | 458 | wrapthread_atomic int status, prev_status; |
| 459 | size_t lastused; | 459 | size_t lastused; |
| 460 | int8_t d; | 460 | int8_t d; |
| 461 | dfsarg_solve_h48_t arg[THREADS]; | 461 | dfsarg_solve_h48_t arg[THREADS]; |
| @@ -471,8 +471,8 @@ solve_h48( | |||
| 471 | solution_moves_t solution_moves[THREADS]; | 471 | solution_moves_t solution_moves[THREADS]; |
| 472 | solution_settings_t settings; | 472 | solution_settings_t settings; |
| 473 | solution_list_t sollist; | 473 | solution_list_t sollist; |
| 474 | pthread_t thread[THREADS]; | 474 | wrapthread_define_var_thread_t(thread[THREADS]); |
| 475 | pthread_mutex_t solutions_mutex; | 475 | wrapthread_define_var_mutex_t(solutions_mutex); |
| 476 | 476 | ||
| 477 | if (!solution_list_init(&sollist, solutions_size, solutions)) | 477 | if (!solution_list_init(&sollist, solutions_size, solutions)) |
| 478 | goto solve_h48_error_solutions_buffer; | 478 | goto solve_h48_error_solutions_buffer; |
| @@ -541,7 +541,7 @@ solve_h48( | |||
| 541 | 541 | ||
| 542 | } | 542 | } |
| 543 | 543 | ||
| 544 | pthread_mutex_init(&solutions_mutex, NULL); | 544 | wrapthread_mutex_init(&solutions_mutex, NULL); |
| 545 | 545 | ||
| 546 | maketasks_arg = (dfsarg_solve_h48_maketasks_t) { | 546 | maketasks_arg = (dfsarg_solve_h48_maketasks_t) { |
| 547 | .cube = oc.cube, | 547 | .cube = oc.cube, |
| @@ -591,7 +591,7 @@ solve_h48( | |||
| 591 | for (i = 0; i < threads; i++) { | 591 | for (i = 0; i < threads; i++) { |
| 592 | arg[i].target_depth = d; | 592 | arg[i].target_depth = d; |
| 593 | arg[i].thread_done = false; | 593 | arg[i].thread_done = false; |
| 594 | pthread_create( | 594 | wrapthread_create( |
| 595 | &thread[i], NULL, solve_h48_runthread, &arg[i]); | 595 | &thread[i], NULL, solve_h48_runthread, &arg[i]); |
| 596 | } | 596 | } |
| 597 | 597 | ||
| @@ -601,10 +601,10 @@ solve_h48( | |||
| 601 | while (!td && status != NISSY_STATUS_STOP) { | 601 | while (!td && status != NISSY_STATUS_STOP) { |
| 602 | msleep(BASE_SLEEP_TIME); | 602 | msleep(BASE_SLEEP_TIME); |
| 603 | 603 | ||
| 604 | pthread_mutex_lock(&solutions_mutex); | 604 | wrapthread_mutex_lock(&solutions_mutex); |
| 605 | solve_h48_log_solutions(&sollist, lastused); | 605 | solve_h48_log_solutions(&sollist, lastused); |
| 606 | lastused = sollist.used; | 606 | lastused = sollist.used; |
| 607 | pthread_mutex_unlock(&solutions_mutex); | 607 | wrapthread_mutex_unlock(&solutions_mutex); |
| 608 | 608 | ||
| 609 | prev_status = status; | 609 | prev_status = status; |
| 610 | status = poll_status(poll_status_data); | 610 | status = poll_status(poll_status_data); |
| @@ -621,7 +621,7 @@ solve_h48( | |||
| 621 | } | 621 | } |
| 622 | 622 | ||
| 623 | for (i = 0; i < threads; i++) | 623 | for (i = 0; i < threads; i++) |
| 624 | pthread_join(thread[i], NULL); | 624 | wrapthread_join(thread[i], NULL); |
| 625 | 625 | ||
| 626 | solve_h48_log_solutions(&sollist, lastused); | 626 | solve_h48_log_solutions(&sollist, lastused); |
| 627 | lastused = sollist.used; | 627 | lastused = sollist.used; |
diff --git a/src/solvers/h48/utils.h b/src/solvers/h48/utils.h index b266c66..aa2ddde 100644 --- a/src/solvers/h48/utils.h +++ b/src/solvers/h48/utils.h | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | #if SIZE_MAX == UINT64_MAX | ||
| 2 | #define H48_HMAX UINT8_C(11) | ||
| 3 | #else | ||
| 4 | #define H48_HMAX UINT8_C(7) | ||
| 5 | #endif | ||
| 6 | |||
| 1 | long long parse_h48_hk( | 7 | long long parse_h48_hk( |
| 2 | const char *, uint8_t [static 1], uint8_t [static 1]); | 8 | const char *, uint8_t [static 1], uint8_t [static 1]); |
| 3 | STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); | 9 | STATIC long long dataid_h48(const char *, char [static NISSY_SIZE_DATAID]); |
| @@ -18,8 +24,9 @@ parse_h48_hk(const char *buf, uint8_t h[static 1], uint8_t k[static 1]) | |||
| 18 | buf++; | 24 | buf++; |
| 19 | 25 | ||
| 20 | *h = atoi(buf); | 26 | *h = atoi(buf); |
| 21 | if (*h > 11) { | 27 | if (*h > H48_HMAX) { |
| 22 | LOG("[H48] Invalid value %" PRIu8 " for parameter h\n", *h); | 28 | LOG("[H48] Invalid value %" PRIu8 " for parameter h (must be " |
| 29 | "at most %" PRIu8 ")\n", *h, H48_HMAX); | ||
| 23 | goto parse_h48_hk_error; | 30 | goto parse_h48_hk_error; |
| 24 | } | 31 | } |
| 25 | 32 | ||
