This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Function eval in parallel

+10 votes

Hi,

Consider the following code:

from dolfin import *

mesh = UnitIntervalMesh(100)
inside = (0.9,)

V = FunctionSpace(mesh, "CG", 1)
f = interpolate(Constant(1), V)

print "Value of f at %s: %s" % (inside, f(inside))

On one process, this works fine:

[pef@aislinn:/tmp]$ python eval.py 
Computed bounding box tree with 199 nodes for 100 entities.
Value of f at (0.9,): 1.0

But on two processes, one process succeeds and the other fails:

[pef@aislinn:/tmp]$ mpiexec -n 2 python eval.py 
Process 0: Number of global vertices: 101
Process 0: Number of global cells: 100
Process 1: Computed bounding box tree with 99 nodes for 50 entities.
Process 0: Computed bounding box tree with 99 nodes for 50 entities.
Value of f at (0.9,): 1.0
Traceback (most recent call last):
  File "eval.py", line 9, in <module>
    print "Value of f at %s: %s" % (inside, f(inside))
  File "/usr/lib/python2.7/dist-packages/dolfin/functions/function.py", line 587, in __call__
    self.eval(values, x)
RuntimeError: 

*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
***     fenics@fenicsproject.org
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error:   Unable to evaluate function at point.
*** Reason:  The point is not inside the domain. Consider setting "allow_extrapolation" to allow extrapolation.
*** Where:   This error was encountered inside Function.cpp.
*** Process: 1
*** -------------------------------------------------------------------------

My question: what's the recommended way of handling this? Is there any parallel-safe way of evaluating functions at points? (I know I could check for this case manually with MPI, but I'm hoping there's a cleaner way than making the user take care of it.) If there's nothing currently in the code, what do you think of a parallel=True flag to function evaluation that would check if it belonged to any process, not just this one?

asked Oct 14, 2013 by pfarrell FEniCS Novice (520 points)

2 Answers

0 votes

There is nothing that provides this functionality inside Function.__call__. The latter is a convenience method only provided in Python. I do not see any immediate problems with such a functionality if it was implemented inside that method.

I suggest you send an email to the list and propose the syntax and behavior there.

answered Oct 15, 2013 by johanhake FEniCS Expert (22,480 points)
0 votes

Use the Probe implemented here:
https://github.com/mikaem/fenicstools/wiki

A simple example of use can be found here:
http://hplgit.github.io/fenics-mixed/doc/pub/sphinx-basicstrap/index.html
under
"How to interface a C++/DOLFIN code from Python"

answered Oct 21, 2013 by Kent-Andre Mardal FEniCS Expert (14,380 points)
...