diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-12 09:36:36 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-08-12 09:36:36 +0100 |
| commit | 50bd8f0f568120e554d416f474cc72247d0b3240 (patch) | |
| tree | 236b8ebed5af17f8220981deffd69b97f0d08fe7 | |
| parent | 315d0f118f3d5ec2578249182f7b0eebf99d2943 (diff) | |
| parent | b36ed11e322152ff9ab813af78a08c35b42d5f94 (diff) | |
| download | nissy-core-50bd8f0f568120e554d416f474cc72247d0b3240.tar.gz nissy-core-50bd8f0f568120e554d416f474cc72247d0b3240.zip | |
Merge branch 'master' of https://github.com/sebastianotronto/nissy-core into windows
Diffstat (limited to '')
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | README.md | 4 | ||||
| -rwxr-xr-x | build | 20 | ||||
| -rw-r--r-- | cpp/nissy.cpp | 3 | ||||
| -rw-r--r-- | python/examples/move.py | 7 | ||||
| -rw-r--r-- | python/examples/solve.py | 11 | ||||
| -rw-r--r-- | python/examples/variations.py | 5 | ||||
| -rw-r--r-- | python/nissy_module.c | 6 | ||||
| -rw-r--r-- | src/solvers/distribution.h | 6 | ||||
| -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 | ||||
| -rw-r--r-- | src/solvers/solutions_types_macros.h | 2 | ||||
| -rw-r--r-- | src/utils/utils.h | 1 | ||||
| -rw-r--r-- | src/utils/wrapthread.h | 37 | ||||
| -rw-r--r-- | test/150_variations/variations.c | 2 | ||||
| -rw-r--r-- | test/test.h | 1 |
18 files changed, 154 insertions, 84 deletions
| @@ -36,6 +36,7 @@ tools/results | |||
| 36 | *.a | 36 | *.a |
| 37 | *.o | 37 | *.o |
| 38 | *.so | 38 | *.so |
| 39 | */*.so | ||
| 39 | *.s | 40 | *.s |
| 40 | *.pyd | 41 | *.pyd |
| 41 | *.dll | 42 | *.dll |
| @@ -224,8 +224,8 @@ $ ./build python | |||
| 224 | And to import it | 224 | And to import it |
| 225 | 225 | ||
| 226 | ``` | 226 | ``` |
| 227 | $ python # In the main folder | 227 | $ python # In the main folder or in the python subfolder |
| 228 | >>> import nissy_python_module as nissy # In the python shell | 228 | >>> import nissy # In the python shell |
| 229 | ``` | 229 | ``` |
| 230 | 230 | ||
| 231 | From here you can call the library functions directly, for example: | 231 | From here you can call the library functions directly, for example: |
| @@ -117,15 +117,23 @@ parsesanitize() { | |||
| 117 | done | 117 | done |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | maybe_pthread() { | ||
| 121 | if [ "$THREADS" -gt 1 ]; then | ||
| 122 | echo "-pthread" | ||
| 123 | else | ||
| 124 | echo "" | ||
| 125 | fi | ||
| 126 | } | ||
| 127 | |||
| 120 | # Build flags | 128 | # Build flags |
| 121 | CFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread" | 129 | CFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L $(maybe_pthread)" |
| 122 | PYCFLAGS="-std=c11 -fPIC -pthread" | 130 | PYCFLAGS="-std=c11 -fPIC $(maybe_pthread)" |
| 123 | [ "$ARCH" = "AVX2" ] && CFLAGS="$CFLAGS -mavx2" | 131 | [ "$ARCH" = "AVX2" ] && CFLAGS="$CFLAGS -mavx2" |
| 124 | WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function" | 132 | WFLAGS="-pedantic -Wall -Wextra -Wno-unused-parameter -Wno-unused-function" |
| 125 | OFLAGS="$OPTIMIZE" | 133 | OFLAGS="$OPTIMIZE" |
| 126 | DFLAGS="-DDEBUG -g3 $(parsesanitize "$SANITIZE")" | 134 | DFLAGS="-DDEBUG -g3 $(parsesanitize "$SANITIZE")" |
| 127 | MFLAGS="-DTHREADS=$THREADS -D$ARCH" | 135 | MFLAGS="-DTHREADS=$THREADS -D$ARCH" |
| 128 | CPPFLAGS="-std=c++20 -pthread" | 136 | CPPFLAGS="-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) |
| 143 | WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L -pthread | 151 | WASMCFLAGS="-std=c11 -fPIC -D_POSIX_C_SOURCE=199309L $(maybe_pthread) |
| 144 | -mfpu=neon -mrelaxed-simd" | 152 | -mfpu=neon -mrelaxed-simd" |
| 145 | WASMCPPFLAGS="-std=c++20 -pthread" | 153 | WASMCPPFLAGS="-std=c++20 $(maybe_pthread)" |
| 146 | WASMDBGFLAGS="-sASSERTIONS" | 154 | WASMDBGFLAGS="-sASSERTIONS" |
| 147 | WASMMFLAGS="-DTHREADS=$THREADS -DNEON" | 155 | WASMMFLAGS="-DTHREADS=$THREADS -DNEON" |
| 148 | WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE | 156 | WASMLINKFLAGS="--no-entry -sEXPORT_NAME='Nissy' -sMODULARIZE |
| @@ -272,7 +280,7 @@ build_python() { | |||
| 272 | fi | 280 | fi |
| 273 | build_nissy || exit 1 | 281 | build_nissy || exit 1 |
| 274 | run $CC $PYCFLAGS $WFLAGS $PYTHON3_INCLUDES $OFLAGS -shared \ | 282 | run $CC $PYCFLAGS $WFLAGS $PYTHON3_INCLUDES $OFLAGS -shared \ |
| 275 | -o nissy_python_module.so nissy.o python/nissy_module.c | 283 | -o python/nissy.so nissy.o python/nissy_module.c |
| 276 | } | 284 | } |
| 277 | 285 | ||
| 278 | build_cpp() { | 286 | build_cpp() { |
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp index 6ca4884..91690fa 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp | |||
| @@ -12,7 +12,8 @@ extern "C" { | |||
| 12 | long long nissy_inverse(const char *, char *); | 12 | long long nissy_inverse(const char *, char *); |
| 13 | long long nissy_applymoves(const char *, const char *, char *); | 13 | long long nissy_applymoves(const char *, const char *, char *); |
| 14 | long long nissy_applytrans(const char *, const char *, char *); | 14 | long long nissy_applytrans(const char *, const char *, char *); |
| 15 | long long nissy_variations(const char *, const char *, size_t, char*); | 15 | long long nissy_variations(const char *, const char *, |
| 16 | unsigned long long, char*); | ||
| 16 | long long nissy_getcube(long long, long long, long long, long long, | 17 | long long nissy_getcube(long long, long long, long long, long long, |
| 17 | long long, const char *, char *); | 18 | long long, const char *, char *); |
| 18 | long long nissy_solverinfo(const char *, char *); | 19 | long long nissy_solverinfo(const char *, char *); |
diff --git a/python/examples/move.py b/python/examples/move.py index 9c7a756..0ed879b 100644 --- a/python/examples/move.py +++ b/python/examples/move.py | |||
| @@ -1,10 +1,13 @@ | |||
| 1 | # Small example of nissy_python_module usage | 1 | # Small example of nissy Python module usage |
| 2 | # See the solve.py example for more details on how this works | 2 | # See the solve.py example for more details on how this works |
| 3 | 3 | ||
| 4 | import os, sys | 4 | import os, sys |
| 5 | 5 | ||
| 6 | # Assume we are eithe rin the top-level directory of the nissy-core repo, | ||
| 7 | # or in the python subdirectory | ||
| 6 | sys.path.append(os.getcwd()) | 8 | sys.path.append(os.getcwd()) |
| 7 | import nissy_python_module as nissy | 9 | sys.path.append(os.getcwd() + os.path.sep + "python") |
| 10 | import nissy | ||
| 8 | 11 | ||
| 9 | cube = nissy.applymoves(nissy.solved_cube, "R' U' F"); | 12 | cube = nissy.applymoves(nissy.solved_cube, "R' U' F"); |
| 10 | print("Cube after the moves R' U' F:") | 13 | print("Cube after the moves R' U' F:") |
diff --git a/python/examples/solve.py b/python/examples/solve.py index e3752fe..d77dd74 100644 --- a/python/examples/solve.py +++ b/python/examples/solve.py | |||
| @@ -1,14 +1,15 @@ | |||
| 1 | # Small example of nissy_python_module usage | 1 | # Small example of nissy Python module usage |
| 2 | 2 | ||
| 3 | # Compile the python module with "make python", then run this from the main | 3 | # Run "./build python", then run this from either the top-level directory |
| 4 | # folder containing nissy_python_module.so | 4 | # of the nissy-core repo or from the python subdirectory. |
| 5 | 5 | ||
| 6 | # Append the main folder to the python path so we can load the module | 6 | # Append the directories to the python path so we can load the module |
| 7 | import sys, os | 7 | import sys, os |
| 8 | sys.path.append(os.getcwd()) | 8 | sys.path.append(os.getcwd()) |
| 9 | sys.path.append(os.getcwd() + os.path.sep + "python") | ||
| 9 | 10 | ||
| 10 | # Import with a nicer name | 11 | # Import with a nicer name |
| 11 | import nissy_python_module as nissy | 12 | import nissy |
| 12 | 13 | ||
| 13 | # Choose the solver you prefer | 14 | # Choose the solver you prefer |
| 14 | solver = "h48h0k4" | 15 | solver = "h48h0k4" |
diff --git a/python/examples/variations.py b/python/examples/variations.py index 1a9d5bb..2507e6e 100644 --- a/python/examples/variations.py +++ b/python/examples/variations.py | |||
| @@ -1,9 +1,10 @@ | |||
| 1 | # Small example of nissy_python_module usage | 1 | # Small example of nissy Python module usage |
| 2 | # See the solve.py example for more details on how this works | 2 | # See the solve.py example for more details on how this works |
| 3 | 3 | ||
| 4 | import sys, os | 4 | import sys, os |
| 5 | sys.path.append(os.getcwd()) | 5 | sys.path.append(os.getcwd()) |
| 6 | import nissy_python_module as nissy | 6 | sys.path.append(os.getcwd() + os.path.sep + "python") |
| 7 | import nissy | ||
| 7 | 8 | ||
| 8 | moves = "R U' Bw2 M D' x' F B(E2 F D B' Lw2 U2 U' S2 B)" | 9 | moves = "R U' Bw2 M D' x' F B(E2 F D B' Lw2 U2 U' S2 B)" |
| 9 | 10 | ||
diff --git a/python/nissy_module.c b/python/nissy_module.c index 88109d3..bff4ead 100644 --- a/python/nissy_module.c +++ b/python/nissy_module.c | |||
| @@ -431,7 +431,7 @@ static PyMethodDef nissy_methods[] = { | |||
| 431 | { NULL, NULL, 0, NULL } | 431 | { NULL, NULL, 0, NULL } |
| 432 | }; | 432 | }; |
| 433 | 433 | ||
| 434 | static struct PyModuleDef nissy_python_module = { | 434 | static struct PyModuleDef nissy = { |
| 435 | .m_base = PyModuleDef_HEAD_INIT, | 435 | .m_base = PyModuleDef_HEAD_INIT, |
| 436 | .m_name = "nissy", | 436 | .m_name = "nissy", |
| 437 | .m_doc = "python module for libnissy", | 437 | .m_doc = "python module for libnissy", |
| @@ -449,11 +449,11 @@ log_stdout(const char *str, void *unused) | |||
| 449 | fprintf(stderr, "%s", str); | 449 | fprintf(stderr, "%s", str); |
| 450 | } | 450 | } |
| 451 | 451 | ||
| 452 | PyMODINIT_FUNC PyInit_nissy_python_module(void) { | 452 | PyMODINIT_FUNC PyInit_nissy(void) { |
| 453 | PyObject *module; | 453 | PyObject *module; |
| 454 | 454 | ||
| 455 | nissy_setlogger(log_stdout, NULL); | 455 | nissy_setlogger(log_stdout, NULL); |
| 456 | module = PyModule_Create(&nissy_python_module); | 456 | module = PyModule_Create(&nissy); |
| 457 | 457 | ||
| 458 | PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE); | 458 | PyModule_AddStringConstant(module, "solved_cube", NISSY_SOLVED_CUBE); |
| 459 | PyModule_AddIntConstant(module, "nissflag_normal", NISSY_NISSFLAG_NORMAL); | 459 | PyModule_AddIntConstant(module, "nissflag_normal", NISSY_NISSFLAG_NORMAL); |
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 *); | |||
| 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 | ||
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 | ||
| 19 | typedef struct { | 19 | typedef 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/150_variations/variations.c b/test/150_variations/variations.c index 2c08607..f9bb603 100644 --- a/test/150_variations/variations.c +++ b/test/150_variations/variations.c | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | #include "../test.h" | 1 | #include "../test.h" |
| 2 | 2 | ||
| 3 | long long nissy_variations( | 3 | long long nissy_variations( |
| 4 | const char *, const char *, long long unsigned, char *); | 4 | const char *, const char *, unsigned long long, char *); |
| 5 | 5 | ||
| 6 | void run(void) { | 6 | void run(void) { |
| 7 | long long err; | 7 | long long err; |
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" |
