Opened 5 months ago

Last modified 5 months ago

#26349 new defect

Memory leaks with matrix multiplication over GF(2)

Reported by: gh-antoine06 Owned by:
Priority: major Milestone: sage-8.4
Component: linear algebra Keywords: memory leaks
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description (last modified by tmonteil)

As reported on this ask question:

n = 8
X = zero_vector(GF(2), n)
M = zero_matrix(GF(2), n, n)

for _ in range(10000000):
    Y = M * X

leads to:

m4ri_mm_malloc: malloc returned NULL
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-04da27075a1c> in <module>()
      5 for _ in range(Integer(10000000)):
----> 6     Y = M * X

/opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Matrix.__mul__ (build/cythonized/sage/structure/element.c:23537)()
   3666             return (<Matrix>left)._matrix_times_matrix_(<Matrix>right)
   3667         if BOTH_ARE_ELEMENT(cl):
-> 3668             return coercion_model.bin_op(left, right, mul)
   3670         cdef long value

/opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/structure/coerce.pyx in sage.structure.coerce.CoercionModel_cache_maps.bin_op (build/cythonized/sage/structure/coerce.c:9757)()
   1173             action = self.get_action(xp, yp, op, x, y)
   1174             if action is not None:
-> 1175                 return (<Action>action)._call_(x, y)
   1177         try:

/opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/matrix/action.pyx in sage.matrix.action.MatrixVectorAction._call_ (build/cythonized/sage/matrix/action.c:5997)()
    325             else:
    326                 v = v.dense_vector()
--> 327         return A._matrix_times_vector_(v)

/opt/sagemath/sage-source/local/lib/python2.7/site-packages/sage/matrix/matrix_mod2_dense.pyx in sage.matrix.matrix_mod2_dense.Matrix_mod2_dense._matrix_times_vector_ (build/cythonized/sage/matrix/matrix_mod2_dense.c:6487)()
    573             return
    574         cdef Vector_mod2_dense c = Vector_mod2_dense.__new__(Vector_mod2_dense)
--> 575         sig_str("matrix allocation failed")
    576         c._init(self._nrows, VS)
    577         c._entries = mzd_init(1, self._nrows)

RuntimeError: matrix allocation failed

Change History (2)

comment:1 Changed 5 months ago by tmonteil

  • Description modified (diff)

comment:2 Changed 5 months ago by nbruin

It would seem the memory management on these objects is rather fundamentally broken. Also with lines like Y= M+M or Y=X+X I am seeing similar leaking behaviour.

Note: See TracTickets for help on using tickets.