Parallel Processing

from dolfin import *
import numpy
from mpi4py import MPI
import matplotlib.pyplot as plt
comm = MPI.COMM_WORLD
rank = comm.Get_rank()



parameters["allow_extrapolation"]=True
mesh=UnitSquareMesh(10,10)
V=FunctionSpace(mesh,'CG',1)
U = Function(V)

size = (U.vector().local_size())
print ( size)
vector = []

if rank ==0: 
    vector = [-20.0]*size;
else:
    vector = [-10.0]*size;


U.vector().set_local(numpy.array(vector))
plot(U)
plt.savefig("plotting_example.png")

While plotting the result after using the command
mpirun -np 2 python3 parallel_processing_plotting.py

I am left with the following resultplotting_example
`

which only plots half of the result. What is the mistake that has been committed in the code which has to be rectified to get the proper result which plots the whole figure ?

I would not use the matplotlib backend for plotting in parallel. I would suggest writing your function to either pvd (File("output.pvd")<< u) or usingXDMFFile.

1 Like

Thank You
It Works!!