Reading a function in parallel efficiently

Hi everyone,

I am currently saving an HDF5 file with some results, and then running another script which reads those results. The problem is that the mesh is being split correctly, but the Function is loaded entirely. Here is a (more or less) MWE:

from dolfin import *
mesh = library.loadRelevantMesh()
V = VectorFunctionSpace(mesh, 'CG', 1)
def getF():
    rr = HDF5File(MPI.comm_world, "function.h5", "r")
    f = Function(V), "f")
return f
f = getF()

print("HDF5 reading: ", mesh.coordinates().shape, f0.vector().size())

Running this in parallel shows that the mesh changes size in each node but the functions remains the same. Any hints on how to load only the local portion of the function would be very appreciated.


The call f0.vector().size() always returns the global size. You may be looking for f0.vector().local_size() instead.

Hadn’t seen the method, thanks for the quick fix!