Skip to content

Commit aa7ea82

Browse files
authored
Merge pull request #14 from jcapriot/GIL_release
Explicitly release the GIL on calls to the pardiso
2 parents adc2117 + 2c66ce6 commit aa7ea82

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

pydiso/mkl_solver.pyx

+28-20
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ cdef extern from 'mkl.h':
5959

6060

6161
#call pardiso (pt, maxfct, mnum, mtype, phase, n, a, ia, ja, perm, nrhs, iparm, msglvl, b, x, error)
62-
cdef int mkl_progress(int *thread, int* step, char* stage, int stage_len):
63-
print(thread[0], step[0], stage, stage_len)
62+
cdef int mkl_progress(int *thread, int* step, char* stage, int stage_len) nogil:
63+
# must be a nogil process to pass to mkl pardiso progress reporting
64+
with gil:
65+
# must reacquire the gil to print out back to python.
66+
print(thread[0], step[0], stage, stage_len)
6467
return 0
6568

6669
cdef int mkl_no_progress(int *thread, int* step, char* stage, int stage_len) nogil:
@@ -515,20 +518,21 @@ cdef class MKLPardisoSolver:
515518
cdef long_t phase64=-1, nrhs64=0, error64=0
516519

517520
if self._initialized():
518-
PyThread_acquire_lock(self.lock, 1)
519-
if self._is_32:
520-
pardiso(
521-
self.handle, &self._par.maxfct, &self._par.mnum, &self._par.mtype,
522-
&phase, &self._par.n, NULL, NULL, NULL, NULL, &nrhs, self._par.iparm,
523-
&self._par.msglvl, NULL, NULL, &error
524-
)
525-
else:
526-
pardiso_64(
527-
self.handle, &self._par64.maxfct, &self._par64.mnum, &self._par64.mtype,
528-
&phase64, &self._par64.n, NULL, NULL, NULL, NULL, &nrhs64,
529-
self._par64.iparm, &self._par64.msglvl, NULL, NULL, &error64
530-
)
531-
PyThread_release_lock(self.lock)
521+
with nogil:
522+
PyThread_acquire_lock(self.lock, 1)
523+
if self._is_32:
524+
pardiso(
525+
self.handle, &self._par.maxfct, &self._par.mnum, &self._par.mtype,
526+
&phase, &self._par.n, NULL, NULL, NULL, NULL, &nrhs, self._par.iparm,
527+
&self._par.msglvl, NULL, NULL, &error
528+
)
529+
else:
530+
pardiso_64(
531+
self.handle, &self._par64.maxfct, &self._par64.mnum, &self._par64.mtype,
532+
&phase64, &self._par64.n, NULL, NULL, NULL, NULL, &nrhs64,
533+
self._par64.iparm, &self._par64.msglvl, NULL, NULL, &error64
534+
)
535+
PyThread_release_lock(self.lock)
532536
err = error or error64
533537
if err!=0:
534538
raise PardisoError("Memory release error "+_err_messages[err])
@@ -541,15 +545,17 @@ cdef class MKLPardisoSolver:
541545

542546
cdef _analyze(self):
543547
#phase = 11
544-
err = self._run_pardiso(11)
548+
with nogil:
549+
err = self._run_pardiso(11)
545550
if err!=0:
546551
raise PardisoError("Analysis step error, "+_err_messages[err])
547552

548553
cdef _factor(self):
549554
#phase = 22
550555
self._factored = False
551556

552-
err = self._run_pardiso(22)
557+
with nogil:
558+
err = self._run_pardiso(22)
553559

554560
if err!=0:
555561
raise PardisoError("Factor step error, "+_err_messages[err])
@@ -561,12 +567,14 @@ cdef class MKLPardisoSolver:
561567
if(not self._factored):
562568
raise PardisoError("Cannot solve without a previous factorization.")
563569

564-
err = self._run_pardiso(33, b, x, nrhs_in)
570+
with nogil:
571+
err = self._run_pardiso(33, b, x, nrhs_in)
572+
565573
if err!=0:
566574
raise PardisoError("Solve step error, "+_err_messages[err])
567575

568576
@cython.boundscheck(False)
569-
cdef int _run_pardiso(self, int_t phase, void* b=NULL, void* x=NULL, int_t nrhs=0) nogil:
577+
cdef int _run_pardiso(self, int_t phase, void* b=NULL, void* x=NULL, int_t nrhs=0) noexcept nogil:
570578
cdef int_t error=0
571579
cdef long_t error64=0, phase64=phase, nrhs64=nrhs
572580

0 commit comments

Comments
 (0)