aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xbuild18
-rw-r--r--src/solvers/distribution.h6
-rw-r--r--src/solvers/h48/gendata_h48.h79
-rw-r--r--src/solvers/h48/gendata_types_macros.h16
-rw-r--r--src/solvers/h48/solve.h26
-rw-r--r--src/solvers/solutions_types_macros.h2
-rw-r--r--src/utils/utils.h1
-rw-r--r--src/utils/wrapthread.h37
-rw-r--r--test/test.h1
9 files changed, 121 insertions, 65 deletions
diff --git a/build b/build
index 310bd28..e689b19 100755
--- a/build
+++ b/build
@@ -117,15 +117,23 @@ parsesanitize() {
117 done 117 done
118} 118}
119 119
120maybe_pthread() {
121 if [ "$THREADS" -gt 1 ]; then
122 echo "-pthread"
123 else
124 echo ""
125 fi
126}
127
120# Build flags 128# Build flags
121CFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread" 129CFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L $(maybe_pthread)"
122PYCFLAGS="-std=c11 -fPIC -pthread" 130PYCFLAGS="-std=c11 -fPIC $(maybe_pthread)"
123[ "$ARCH" = "AVX2" ] && CFLAGS="$CFLAGS -mavx2" 131[ "$ARCH" = "AVX2" ] && CFLAGS="$CFLAGS -mavx2"
124WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function" 132WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function"
125OFLAGS="$OPTIMIZE" 133OFLAGS="$OPTIMIZE"
126DFLAGS="-DDEBUG -g3 $(parsesanitize "$SANITIZE")" 134DFLAGS="-DDEBUG -g3 $(parsesanitize "$SANITIZE")"
127MFLAGS="-DTHREADS=$THREADS -D$ARCH" 135MFLAGS="-DTHREADS=$THREADS -D$ARCH"
128CPPFLAGS="-std=c++20 -pthread" 136CPPFLAGS="-std=c++20 $(maybe_pthread)"
129 137
130# TODO: 138# TODO:
131# MEMORY64 is supported on Firefox (from version 134) and Chrome (from 133), 139# MEMORY64 is supported on Firefox (from version 134) and Chrome (from 133),
@@ -140,9 +148,9 @@ CPPFLAGS="-std=c++20 -pthread"
140# The options below have to be adjusted when native WASM_SIMD is implemented. 148# The options below have to be adjusted when native WASM_SIMD is implemented.
141 149
142# Build flags for emscripten (WASM target) 150# Build flags for emscripten (WASM target)
143WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread 151WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L $(maybe_pthread)
144 -mfpu=neon -mrelaxed-simd" 152 -mfpu=neon -mrelaxed-simd"
145WASMCPPFLAGS="-std=c++20 -pthread" 153WASMCPPFLAGS="-std=c++20 $(maybe_pthread)"
146WASMDBGFLAGS="-sASSERTIONS" 154WASMDBGFLAGS="-sASSERTIONS"
147WASMMFLAGS="-DTHREADS=$THREADS -DNEON" 155WASMMFLAGS="-DTHREADS=$THREADS -DNEON"
148WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE 156WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE
diff --git a/src/solvers/distribution.h b/src/solvers/distribution.h
index 27b72d7..4cb7157 100644
--- a/src/solvers/distribution.h
+++ b/src/solvers/distribution.h
@@ -43,7 +43,7 @@ getdistribution(
43 const tableinfo_t info[static 1] 43 const tableinfo_t info[static 1]
44) { 44) {
45 getdistribution_data_t targ[THREADS]; 45 getdistribution_data_t targ[THREADS];
46 pthread_t thread[THREADS]; 46 wrapthread_define_var_thread_t(thread[THREADS]);
47 uint8_t pval, k; 47 uint8_t pval, k;
48 uint64_t local_distr[THREADS][INFO_DISTRIBUTION_LEN]; 48 uint64_t local_distr[THREADS][INFO_DISTRIBUTION_LEN];
49 uint64_t i, j, nbytes, sz, epb; 49 uint64_t i, j, nbytes, sz, epb;
@@ -60,12 +60,12 @@ getdistribution(
60 .distr = local_distr[i], 60 .distr = local_distr[i],
61 .table = table, 61 .table = table,
62 }; 62 };
63 pthread_create(&thread[i], NULL, 63 wrapthread_create(&thread[i], NULL,
64 getdistribution_runthread, &targ[i]); 64 getdistribution_runthread, &targ[i]);
65 } 65 }
66 66
67 for (i = 0; i < THREADS; i++) 67 for (i = 0; i < THREADS; i++)
68 pthread_join(thread[i], NULL); 68 wrapthread_join(thread[i], NULL);
69 69
70 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); 70 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
71 for (i = 0; i < THREADS; i++) 71 for (i = 0; i < THREADS; i++)
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 *);
21STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t); 21STATIC_INLINE uint8_t get_h48_pval(const unsigned char *, uint64_t, uint8_t);
22STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t); 22STATIC_INLINE void set_h48_pval(unsigned char *, uint64_t, uint8_t, uint8_t);
23STATIC_INLINE uint8_t get_h48_pval_atomic( 23STATIC_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);
25STATIC_INLINE void set_h48_pval_atomic( 25STATIC_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
28STATIC long long 28STATIC long long
29gendata_h48_dispatch( 29gendata_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])
207STATIC void 207STATIC void
208gendata_h48h0k4(gendata_h48_arg_t arg[static 1]) 208gendata_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])
492STATIC void * 493STATIC void *
493gendata_h48k2_runthread(void *arg) 494gendata_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
607gendata_h48_mark_atomic(gendata_h48_mark_t arg[static 1]) 609gendata_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
627gendata_h48_mark(gendata_h48_mark_t arg[static 1]) 630gendata_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
644gendata_h48k2_dfs_stop(cube_t cube, int8_t d, h48k2_dfs_arg_t arg[static 1]) 648gendata_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
713STATIC_INLINE uint8_t 718STATIC_INLINE uint8_t
714get_h48_pval_atomic(_Atomic const unsigned char *table, uint64_t i, uint8_t k) 719get_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
726STATIC_INLINE void 735STATIC_INLINE void
727set_h48_pval_atomic( 736set_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 {
85typedef struct { 85typedef 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
96typedef struct { 96typedef 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
113typedef struct { 113typedef 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
51typedef struct { 51typedef 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/solutions_types_macros.h b/src/solvers/solutions_types_macros.h
index e57e039..c8efc0b 100644
--- a/src/solvers/solutions_types_macros.h
+++ b/src/solvers/solutions_types_macros.h
@@ -17,7 +17,7 @@ typedef struct {
17} solution_settings_t; 17} solution_settings_t;
18 18
19typedef struct { 19typedef struct {
20 _Atomic uint64_t nsols; 20 wrapthread_atomic uint64_t nsols;
21 uint8_t shortest_sol; 21 uint8_t shortest_sol;
22 size_t size; 22 size_t size;
23 size_t used; 23 size_t used;
diff --git a/src/utils/utils.h b/src/utils/utils.h
index d14b285..b2ab64d 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -2,3 +2,4 @@
2#include "constants.h" 2#include "constants.h"
3#include "math.h" 3#include "math.h"
4#include "sleep.h" 4#include "sleep.h"
5#include "wrapthread.h"
diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h
new file mode 100644
index 0000000..482b67f
--- /dev/null
+++ b/src/utils/wrapthread.h
@@ -0,0 +1,37 @@
1#if THREADS == 1
2
3#define wrapthread_atomic
4
5#define wrapthread_define_var_thread_t(x) char x; (void)(x)
6#define wrapthread_define_var_mutex_t(x) char x; (void)(x)
7#define wrapthread_define_struct_thread_t(x) char x
8#define wrapthread_define_struct_mutex_t(x) char x
9
10#define wrapthread_define_if_threads(T, x) T x; (void)(x)
11
12#define wrapthread_create(a, b, c, d) c(d)
13#define wrapthread_join(a, b)
14#define wrapthread_mutex_init(a, b)
15#define wrapthread_mutex_lock(a)
16#define wrapthread_mutex_unlock(a)
17
18#else
19
20#include <pthread.h>
21
22#define wrapthread_atomic _Atomic
23
24#define wrapthread_define_var_thread_t(x) pthread_t x
25#define wrapthread_define_var_mutex_t(x) pthread_mutex_t x
26#define wrapthread_define_struct_thread_t(x) pthread_t x
27#define wrapthread_define_struct_mutex_t(x) pthread_mutex_t x
28
29#define wrapthread_define_if_threads(T, x) T x
30
31#define wrapthread_create(a, b, c, d) pthread_create(a, b, c, d)
32#define wrapthread_join(a, b) pthread_join(a, b)
33#define wrapthread_mutex_init(a, b) pthread_mutex_init(a, b)
34#define wrapthread_mutex_lock(a) pthread_mutex_lock(a)
35#define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a)
36
37#endif
diff --git a/test/test.h b/test/test.h
index 6230f36..703447b 100644
--- a/test/test.h
+++ b/test/test.h
@@ -8,6 +8,7 @@
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
10 10
11#include "../src/utils/wrapthread.h"
11#include "../src/nissy.h" 12#include "../src/nissy.h"
12#include "../src/arch/arch.h" 13#include "../src/arch/arch.h"
13#include "../src/core/core_types.h" 14#include "../src/core/core_types.h"

Generated with cgit - Back to sebastiano.tronto.net