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

Problem with Parallel output of functions modified locally

+1 vote

Hi,

I am trying to output functions using MPI. The value in was updated by a user function before output. Seems as if the values at the border of two local meshes were not correct. A simple example to demonstrate this issue is given as follows -> test.py . I am using Fenics 1.5.

# test.py
from dolfin import *
import numpy
# Extrapolation needed to avoid errors beacuse each process looks for the point even if it does not own it
parameters["allow_extrapolation"]=True
mesh=UnitSquareMesh(10,10)
V=FunctionSpace(mesh,'CG',1)
U = Function(V)

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

#set values for local mesh
if MPI.rank(mpi_comm_world())==0: 
    vector = [-20.0]*size;
else:
    vector = [-10.0]*size;

#set local values to the U function
U.vector().set_local(numpy.array(vector))
File('mesh.xdmf') << U
plot(U)
interactive()

and run the code with:

mpirun -np 2 python test.py

I guess this could be due to the ghost values in the local vector? So any suggestions to solve this?

Thanks!

asked Jun 25, 2015 by qiangzini FEniCS Novice (760 points)

1 Answer

0 votes

You probably need to call update_ghost_values() on your Vector.
as_backend_type(U.vector()).update_ghost_values()

answered Jun 26, 2015 by chris_richardson FEniCS Expert (31,740 points)

Thanks. It works with python. I am primarily using C++ now, but seems as if as_backend_type is not declared. Is any similar functions in C++, or some header files to include?

Thanks.

...