Skip to content

Commit

Permalink
split __dealloc__ into a dealloc and a __del__ method for safety
Browse files Browse the repository at this point in the history
  • Loading branch information
jcapriot committed Feb 29, 2024
1 parent d762962 commit 5fa9ade
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pydiso/mkl_solver.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ cdef class MKLPardisoSolver:
cdef object _data_type
cdef object _Adata #a reference to make sure the pointer "a" doesn't get destroyed

def __cinit__(self, *args, **kwargs):
# allocate the lock
self.lock = PyThread_allocate_lock()

def __init__(self, A, matrix_type=None, factor=True, verbose=False):
'''ParidsoSolver(A, matrix_type=None, factor=True, verbose=False)
An interface to the intel MKL pardiso sparse matrix solver.
Expand Down Expand Up @@ -302,9 +306,6 @@ cdef class MKLPardisoSolver:
raise PardisoError("Unrecognized integer length")
self._initialized = True

# allocate the lock
self.lock = PyThread_allocate_lock()

if verbose:
#for reporting factorization progress via python's `print`
mkl_set_progress(mkl_progress)
Expand Down Expand Up @@ -496,7 +497,7 @@ cdef class MKLPardisoSolver:
self._Adata = np.ascontiguousarray(data)
self.a = np.PyArray_DATA(data)

def __dealloc__(self):
def __del__(self):
# Need to call pardiso with phase=-1 to release memory
cdef MKL_INT phase=-1, nrhs=0, error=0
cdef MKL_INT64 phase64=-1, nrhs64=0, error64=0
Expand All @@ -519,10 +520,12 @@ cdef class MKLPardisoSolver:
err = error or error64
if err!=0:
raise PardisoError("Memmory release error "+_err_messages[err])
#dealloc lock
if self.lock is not NULL:
PyThread_free_lock(self.lock)
self.lock = NULL
self._initialized = False


def __dealloc__(self):
#dealloc lock
PyThread_free_lock(self.lock)

cdef _analyze(self):
#phase = 11
Expand Down

0 comments on commit 5fa9ade

Please sign in to comment.