Excessive memory use with Eigen when solving in for loop

Issue #1028 resolved
Chaffra Affouda created an issue

The simple nonlinear-poisson demo keeps using more RAM memory even after the equation has converged.

To reproduce please use the attached modified main.cpp. Build and run and look at the RAM memory increase (with system monitor on ubuntu) until the system runs out of RAM and potentially crashes.

Even tough the problem has converged, Eigen keeps using more RAM for subsequent solves. You do not see this if you use the PETSc backend. First, can anyone reproduce? I am running the latest dolfin master on Ubuntu 18.04. This is a problem because sometimes you want to use solve in a for loop and this was not happening with previous versions.

Any suggestion is appreciated, Thanks! Chaffra

Comments (5)

  1. Chaffra Affouda reporter

    The memory overrun does not happen in the python version of the demo as if the garbage collector is working. So this is a problem in c++. I suspect some memory is not being freed in the c++ example but I don't know where. Can anyone reproduce or suggest a way of debugging this?

    Here is a MWE in python:

    from dolfin import *
    # Sub domain for Dirichlet boundary condition
    class DirichletBoundary(SubDomain):
        def inside(self, x, on_boundary):
            return abs(x[0] - 1.0) < DOLFIN_EPS and on_boundary
    
    # Create mesh and define function space
    mesh = UnitSquareMesh(160, 160)
    V = FunctionSpace(mesh, "CG", 1)
    
    # Define boundary condition
    g = Constant(1.0)
    bc = DirichletBC(V, g, DirichletBoundary())
    
    # Define variational problem
    u = Function(V)
    v = TestFunction(V)
    f = Expression("x[0]*sin(x[1])", degree=2)
    F = inner((1 + u**2)*grad(u), grad(v))*dx - f*v*dx
    
    # Compute solution
    for i in range(0,100): #this leads to memory overrun in c++ demo version
        solve(F == 0, u, bc,
              solver_parameters={"newton_solver":{"relative_tolerance":1e-6,
                                        "absolute_tolerance": 1e-16,
                                        "error_on_nonconvergence": False,
                                        "maximum_iterations": 5}
              })
    
  2. Chaffra Affouda reporter

    The problem comes from the new implementation of EigenLUSolver. Can @mliertzer look into this? When I revert EigenLUSolver.h and EigenLUSolver.cpp to commit b243b33, there is no more memory overrun. I think the caching is not working as intended.

  3. Log in to comment