Segmentation fault when using class derived from Expression with multiple threads

Bug #1047820 reported by James Maddison
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
DOLFIN
Confirmed
Undecided
Unassigned

Bug Description

The following example leads to a segmentation fault:

#!/usr/bin/env python
from dolfin import *
parameters["num_threads"] = 2
class TestExpression(Expression):
    def eval(self, value, x):
      value[:] = 1.0
      return
    def value_shape(self):
      return tuple()
mesh = Rectangle(0.0, 0.0, 1.0, 1.0, 10, 10)
space = FunctionSpace(mesh, "CG", 1)
test = TestFunction(space)
trial = TrialFunction(space)
mass = assemble(inner(test, trial) * dx)
rhs = assemble(inner(test, TestExpression()) * dx)
F = Function(space)
solve(mass, F.vector(), rhs)
print assemble(F * dx)

If TestExpression() is replaced with Constant(1.0) or Expression("1.0") then the test runs without error.

Revision history for this message
Lawrence Mitchell (wence) wrote :

Probably because eval() is being called from inside a threaded region, but doesn't grab the python GIL

Revision history for this message
Johan Hake (johan-hake) wrote :

Lawrence is right. We do not grab the GIL.

I have no experience with GIL, but a naive fix could be to add a function in the Python interface of DOLFIN to grab and release the GIL. These could then be called when threaded assemble is used.

Revision history for this message
Johan Hake (johan-hake) wrote :

As a workaround you can always use compiled expressions, which should be thread safe for most use cases.

Johannes Ring (johannr)
Changed in dolfin:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.