From normal to parallel

Hi all,
I am solving a fem problem in which there are three variable fields involved and in which the initial conditions are determined by another routine. This routine saves the three fields (and the mesh) with:

#mesh
savemesh1=File(name_dir1+'mesh.xml')
savemesh1.write(mesh)
#fields number 1
save_u=HDF5File(MPI.comm_world,name_dir1+'u/start'+".h5","w")
save_u.write(u,'/f')
save_u.close()
# the same for the other three fields...

I reload the mesh and the field on the other code using:

mesh=Mesh(name_simulation+'/evol files/mesh.xml')

restart_u=HDF5File(MPI.comm_world,name_simulation+'/evol files/u/start.h5',"r")
restart_u.read(u,'/f')
restart_u.read(upre,'/f')
restart_u.read(u_iter,'/f')
restart_u.read(u_step_pre,'/f')

the second code works normally, but in parallel I think that every processors reads all of the mesh/ fields.

How can I fix this problem?

Thanks for the attention

Please make a reproducible example,
and make sure to print
mesh.mpi_comm().rank
For the mesh once you have read it in.

thanks, i’ll try.
Code 1:

from dolfin import *
from mshr import*
mesh=Mesh('testmesh.xml')  
savemesh1=File('u/mesh.xml')
savemesh1.write(mesh)
Space2D2=VectorFunctionSpace(mesh,'P',1,2)
ex=Expression(("2*x[0]","3*x[1]"),degree=1)
u=interpolate(ex,Space2D2)
save_u=HDF5File(MPI.comm_world,'u/start'+".h5","w")
save_u.write(u,'/f')
save_u.close()
savefile1=XDMFFile('uprv/start.xdmf')
savefile1.parameters['flush_output']=True
u.rename('u','displacement')
savefile1.write(u,0)

code 2:

from dolfin import *
from mshr import*
import numpy as np
mesh=Mesh('u/mesh.xml') 
Space2D2=VectorFunctionSpace(mesh,'P',1,2)
u=Function(Space2D2)
restart_u=HDF5File(MPI.comm_world,'u/start'+".h5","r")
restart_u.read(u,'/f')

def boundary_left(x): return abs(x[0]) < tollb
def boundary_right(x):return abs(x[0]-lpx) < tollb
t=0
tv=[]
savefile1=XDMFFile('uprv/u.xdmf')
while t<3:
    ex=Expression(("2*x[0]","3*x[1]"),degree=1)
    de_u=(1/100)*interpolate(ex,Space2D2)
    u=project(u+de_u,Space2D2)
    save_u=HDF5File(MPI.comm_world,'u/'+str(t)+".h5","w")
    save_u.write(u,'/f')
    save_u.close()
    tv.append(t)
    u.rename('u','displacement')
    savefile1.write(u,t)
    np.savetxt('u/t.txt', tv, fmt='%f')
    t+=0.1

full codes include “projection”, TAO and SNES solvers