Hi, consider
from mpi4py import MPI as pyMPI
import numpy as np
def mpi4py_comm(comm):
'''Get mpi4py communicator'''
try:
return comm.tompi4py()
except AttributeError:
return comm
def peval(f, x):
'''Parallel synced eval'''
try:
yloc = f(x)
except RuntimeError:
yloc = np.inf*np.ones(f.value_shape())
comm = mpi4py_comm(f.function_space().mesh().mpi_comm())
yglob = np.zeros_like(yloc)
comm.Allreduce(yloc, yglob, op=pyMPI.MIN)
return yglob
# -------------------------------------------------------------------
if __name__ == '__main__':
from dolfin import (UnitSquareMesh, Function, FunctionSpace, interpolate,
Expression, VectorFunctionSpace)
mesh = UnitSquareMesh(32, 32)
V = VectorFunctionSpace(mesh, 'CG', 1)
f_ = Expression(('x[0]+x[1]', 'x[0]'), degree=1)
f = interpolate(f_, V)
x = np.array([0.5, 0.5])
assert(np.linalg.norm(f_(x) - peval(f, x)) < 1E-13)