aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2026-03-01 16:26:58 +0000
committerSebastiano Tronto <sebastiano@tronto.net>2026-03-01 16:26:58 +0000
commite68606ff95db6e31585706278b034250555bbe14 (patch)
treeeae492e7fc24cca2c051a2e75de996555ae1b19f
parentdff3a040637f2985b5b5e369148a993183964096 (diff)
downloadnissy-core-e68606ff95db6e31585706278b034250555bbe14.tar.gz
nissy-core-e68606ff95db6e31585706278b034250555bbe14.zip
C11 threads?
-rw-r--r--build.bat2
-rw-r--r--src/solvers/distribution.h4
-rw-r--r--src/solvers/h48/distribution_h48.h4
-rw-r--r--src/solvers/h48/gendata_h48.h8
-rw-r--r--src/solvers/h48/solve.h6
-rw-r--r--src/utils/wrapthread.h33
6 files changed, 38 insertions, 19 deletions
diff --git a/build.bat b/build.bat
index 909ff01..91cc4db 100644
--- a/build.bat
+++ b/build.bat
@@ -10,7 +10,7 @@ if [%1]==[/d] (
10SET CC=clang 10SET CC=clang
11SET CXX=clang++ 11SET CXX=clang++
12SET ARCH=PORTABLE 12SET ARCH=PORTABLE
13SET THREADS=1 13SET THREADS=16
14SET SANITIZE= 14SET SANITIZE=
15 15
16:: TODO depends on ARCH variable 16:: TODO depends on ARCH variable
diff --git a/src/solvers/distribution.h b/src/solvers/distribution.h
index e9302da..7adc964 100644
--- a/src/solvers/distribution.h
+++ b/src/solvers/distribution.h
@@ -60,12 +60,12 @@ getdistribution(
60 .distr = local_distr[i], 60 .distr = local_distr[i],
61 .table = table, 61 .table = table,
62 }; 62 };
63 wrapthread_create(&thread[i], NULL, 63 wrapthread_create(&thread[i],
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 wrapthread_join(thread[i], NULL); 68 wrapthread_join(thread[i]);
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/distribution_h48.h b/src/solvers/h48/distribution_h48.h
index 93a6933..6d50ae5 100644
--- a/src/solvers/h48/distribution_h48.h
+++ b/src/solvers/h48/distribution_h48.h
@@ -58,12 +58,12 @@ getdistribution_h48(
58 .distr = local_distr[i], 58 .distr = local_distr[i],
59 .table = table, 59 .table = table,
60 }; 60 };
61 wrapthread_create(&thread[i], NULL, 61 wrapthread_create(&thread[i],
62 getdistribution_h48_runthread, &targ[i]); 62 getdistribution_h48_runthread, &targ[i]);
63 } 63 }
64 64
65 for (i = 0; i < THREADS; i++) 65 for (i = 0; i < THREADS; i++)
66 wrapthread_join(thread[i], NULL); 66 wrapthread_join(thread[i]);
67 67
68 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t)); 68 memset(distr, 0, INFO_DISTRIBUTION_LEN * sizeof(uint64_t));
69 for (i = 0; i < THREADS; i++) 69 for (i = 0; i < THREADS; i++)
diff --git a/src/solvers/h48/gendata_h48.h b/src/solvers/h48/gendata_h48.h
index ef8a854..a5bb331 100644
--- a/src/solvers/h48/gendata_h48.h
+++ b/src/solvers/h48/gendata_h48.h
@@ -230,9 +230,9 @@ gendata_h48_maintable(gendata_h48_arg_t arg[static 1])
230 230
231 inext = 0; 231 inext = 0;
232 count = 0; 232 count = 0;
233 wrapthread_mutex_init(&shortcubes_mutex, NULL); 233 wrapthread_mutex_init(&shortcubes_mutex);
234 for (i = 0; i < CHUNKS; i++) 234 for (i = 0; i < CHUNKS; i++)
235 wrapthread_mutex_init(&table_mutex[i], NULL); 235 wrapthread_mutex_init(&table_mutex[i]);
236 for (i = 0; i < THREADS; i++) { 236 for (i = 0; i < THREADS; i++) {
237 dfsarg[i] = (h48_dfs_arg_t){ 237 dfsarg[i] = (h48_dfs_arg_t){
238 .h = arg->h, 238 .h = arg->h,
@@ -251,7 +251,7 @@ gendata_h48_maintable(gendata_h48_arg_t arg[static 1])
251 dfsarg[i].table_mutex[ii] = &table_mutex[ii]; 251 dfsarg[i].table_mutex[ii] = &table_mutex[ii];
252 252
253 wrapthread_create( 253 wrapthread_create(
254 &thread[i], NULL, gendata_h48_runthread, &dfsarg[i]); 254 &thread[i], gendata_h48_runthread, &dfsarg[i]);
255 } 255 }
256 256
257 if (NISSY_CANSLEEP) { 257 if (NISSY_CANSLEEP) {
@@ -281,7 +281,7 @@ gendata_h48_maintable(gendata_h48_arg_t arg[static 1])
281 } 281 }
282 282
283 for (i = 0; i < THREADS; i++) 283 for (i = 0; i < THREADS; i++)
284 wrapthread_join(thread[i], NULL); 284 wrapthread_join(thread[i]);
285 285
286 h48map_destroy(&shortcubes); 286 h48map_destroy(&shortcubes);
287 287
diff --git a/src/solvers/h48/solve.h b/src/solvers/h48/solve.h
index 15ac6ea..19aaf79 100644
--- a/src/solvers/h48/solve.h
+++ b/src/solvers/h48/solve.h
@@ -638,7 +638,7 @@ solve_h48(
638 638
639 } 639 }
640 640
641 wrapthread_mutex_init(&solutions_mutex, NULL); 641 wrapthread_mutex_init(&solutions_mutex);
642 642
643 mtarg = (dfsarg_solve_h48_maketasks_t) { 643 mtarg = (dfsarg_solve_h48_maketasks_t) {
644 .cube = oc.cube, 644 .cube = oc.cube,
@@ -689,7 +689,7 @@ solve_h48(
689 arg[i].target_depth = d; 689 arg[i].target_depth = d;
690 arg[i].thread_done = false; 690 arg[i].thread_done = false;
691 wrapthread_create( 691 wrapthread_create(
692 &thread[i], NULL, solve_h48_runthread, &arg[i]); 692 &thread[i], solve_h48_runthread, &arg[i]);
693 } 693 }
694 694
695 /* Log solutions and handle pause / stop / resume */ 695 /* Log solutions and handle pause / stop / resume */
@@ -718,7 +718,7 @@ solve_h48(
718 } 718 }
719 719
720 for (i = 0; i < threads; i++) 720 for (i = 0; i < threads; i++)
721 wrapthread_join(thread[i], NULL); 721 wrapthread_join(thread[i]);
722 722
723 solve_h48_log_solutions(&sollist, lastused); 723 solve_h48_log_solutions(&sollist, lastused);
724 lastused = sollist.used; 724 lastused = sollist.used;
diff --git a/src/utils/wrapthread.h b/src/utils/wrapthread.h
index 28654fe..d5de155 100644
--- a/src/utils/wrapthread.h
+++ b/src/utils/wrapthread.h
@@ -9,13 +9,32 @@
9 9
10#define wrapthread_define_if_threads(T, x) T x; (void)(x) 10#define wrapthread_define_if_threads(T, x) T x; (void)(x)
11 11
12#define wrapthread_create(a, b, c, d) c(d) 12#define wrapthread_create(t, f, arg) f(arg)
13#define wrapthread_join(a, b) 13#define wrapthread_join(a)
14#define wrapthread_mutex_init(a, b) 14#define wrapthread_mutex_init(a)
15#define wrapthread_mutex_lock(a) 15#define wrapthread_mutex_lock(a)
16#define wrapthread_mutex_unlock(a) 16#define wrapthread_mutex_unlock(a)
17 17
18#else 18#elif defined(_WIN32)
19
20#include <threads.h>
21
22#define wrapthread_atomic _Atomic
23
24#define wrapthread_define_var_thread_t(x) thrd_t x
25#define wrapthread_define_var_mutex_t(x) mtx_t x
26#define wrapthread_define_struct_thread_t(x) thrd_t x
27#define wrapthread_define_struct_mutex_t(x) mtx_t x
28
29#define wrapthread_define_if_threads(T, x) T x
30
31#define wrapthread_create(a, f, arg) thrd_create(a, (int(*)(void *))f, arg)
32#define wrapthread_join(a) thrd_join(a, NULL)
33#define wrapthread_mutex_init(a) mtx_init(a, mtx_plain)
34#define wrapthread_mutex_lock(a) mtx_lock(a)
35#define wrapthread_mutex_unlock(a) mtx_unlock(a)
36
37#elif defined(__unix__)
19 38
20#include <pthread.h> 39#include <pthread.h>
21 40
@@ -28,9 +47,9 @@
28 47
29#define wrapthread_define_if_threads(T, x) T x 48#define wrapthread_define_if_threads(T, x) T x
30 49
31#define wrapthread_create(a, b, c, d) pthread_create(a, b, c, d) 50#define wrapthread_create(a, f, arg) pthread_create(a, NULL, f, arg)
32#define wrapthread_join(a, b) pthread_join(a, b) 51#define wrapthread_join(a) pthread_join(a, NULL)
33#define wrapthread_mutex_init(a, b) pthread_mutex_init(a, b) 52#define wrapthread_mutex_init(a) pthread_mutex_init(a, NULL)
34#define wrapthread_mutex_lock(a) pthread_mutex_lock(a) 53#define wrapthread_mutex_lock(a) pthread_mutex_lock(a)
35#define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a) 54#define wrapthread_mutex_unlock(a) pthread_mutex_unlock(a)
36 55

Generated with cgit - Back to sebastiano.tronto.net