aboutsummaryrefslogtreecommitdiff
path: root/python/nissy_module.c
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2024-12-14 11:59:22 +0100
committerSebastiano Tronto <sebastiano@tronto.net>2024-12-14 11:59:22 +0100
commit4a88a686d5e08404080ed6954b70c0db252aa220 (patch)
treec1fb469d5a2a68c8e4651ad7837d3dd6fe2ff93e /python/nissy_module.c
parent9ac266c76f39620d8343e46ca41cb09d1534384c (diff)
downloadnissy-core-4a88a686d5e08404080ed6954b70c0db252aa220.tar.gz
nissy-core-4a88a686d5e08404080ed6954b70c0db252aa220.zip
Allow choosing number of threads when calling solve()
Diffstat (limited to '')
-rw-r--r--python/nissy_module.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/python/nissy_module.c b/python/nissy_module.c
index 2357b90..947d06f 100644
--- a/python/nissy_module.c
+++ b/python/nissy_module.c
@@ -306,7 +306,8 @@ checkdata(PyObject *self, PyObject *args)
306} 306}
307 307
308PyDoc_STRVAR(solve_doc, 308PyDoc_STRVAR(solve_doc,
309"solve(cube, solver, nissflag, minmoves, maxmoves, maxsolutions, optimal, data)\n" 309"solve(cube, solver, nissflag, minmoves, maxmoves, maxsolutions,"
310" optimal, threads, data)\n"
310"--\n\n" 311"--\n\n"
311"Solves the given 'cube' with the given 'solver' and other parameters." 312"Solves the given 'cube' with the given 'solver' and other parameters."
312"See the documentation for libnissy (in nissy.h) for details.\n" 313"See the documentation for libnissy (in nissy.h) for details.\n"
@@ -319,6 +320,7 @@ PyDoc_STRVAR(solve_doc,
319" - maxsolution: the maximum number of solutions to return\n" 320" - maxsolution: the maximum number of solutions to return\n"
320" - optimal: the largest number of moves from the shortest solution" 321" - optimal: the largest number of moves from the shortest solution"
321"(set to -1 to ignore)\n" 322"(set to -1 to ignore)\n"
323" - threads: the number of threads to use (0 for default)\n"
322" - data: a bytearray containing the data for the solver\n" 324" - data: a bytearray containing the data for the solver\n"
323"\n" 325"\n"
324"Returns: a list with the solutions found\n" 326"Returns: a list with the solutions found\n"
@@ -328,20 +330,20 @@ solve(PyObject *self, PyObject *args)
328{ 330{
329 long long result; 331 long long result;
330 unsigned nissflag, minmoves, maxmoves, maxsolutions; 332 unsigned nissflag, minmoves, maxmoves, maxsolutions;
331 int optimal, i, j, k; 333 int optimal, i, j, k, threads;
332 const char *cube, *solver; 334 const char *cube, *solver;
333 char solutions[MAX_SOLUTIONS_SIZE]; 335 char solutions[MAX_SOLUTIONS_SIZE];
334 long long stats[NISSY_SIZE_SOLVE_STATS]; 336 long long stats[NISSY_SIZE_SOLVE_STATS];
335 PyByteArrayObject *data; 337 PyByteArrayObject *data;
336 PyObject *list, *item; 338 PyObject *list, *item;
337 339
338 if (!PyArg_ParseTuple(args, "ssIIIIiY", &cube, &solver, &nissflag, 340 if (!PyArg_ParseTuple(args, "ssIIIIiiY", &cube, &solver, &nissflag,
339 &minmoves, &maxmoves, &maxsolutions, &optimal, &data)) 341 &minmoves, &maxmoves, &maxsolutions, &optimal, &threads, &data))
340 return NULL; 342 return NULL;
341 343
342 Py_BEGIN_ALLOW_THREADS 344 Py_BEGIN_ALLOW_THREADS
343 result = nissy_solve(cube, solver, nissflag, minmoves, maxmoves, 345 result = nissy_solve(cube, solver, nissflag, minmoves, maxmoves,
344 maxsolutions, optimal, data->ob_alloc, data->ob_bytes, 346 maxsolutions, optimal, threads, data->ob_alloc, data->ob_bytes,
345 MAX_SOLUTIONS_SIZE, solutions, stats); 347 MAX_SOLUTIONS_SIZE, solutions, stats);
346 Py_END_ALLOW_THREADS 348 Py_END_ALLOW_THREADS
347 349

Generated with cgit - Back to sebastiano.tronto.net