How to merge partial results to a combined solution in mpirun

Hello to all,

I am preparing a text-book on Programming Methods, which includes chapters on mpi4py and elementary FEniCS.
I would like to present an example of the form

mpirun -n 4 python3 poisson.py

that distributes the computation to 4 processes, and then gathers the partial results together into a global one.

The equation is the standard

from dolfin import *
mesh = UnitSquareMesh(32, 32)
V = FunctionSpace(mesh, ‘CG’, 1)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
g = Expression('1 + x[0]x[0] + 2x[1]x[1]’, degree=2)
bc = DirichletBC(V, g, ‘on_boundary’)
a = inner(grad(u), grad(v))dx
L = f
v
dx
u = Function(V)
solve(a == L, u, bc)

I use FEniCS 2018.1.0, installed via the standard procedure on a virtual Ubuntu 18.04 envirionment on a Mac.

Preferably I would also like to plot the combined result with

from matplotlib.pyplot import show
plot(u, mode=“warp”)
show()

Thanks in advance

I would suggest writing the solution to a file and use an external program like paraview to inspect the result. The plotting functionality of fenics is very basic.