For anyone out there looking for a may to save and write files in parallel I use PetscBinaryIO
now. Syntax goes like :
import PetscBinaryIO
from mpi4py.MPI import COMM_WORLD as comm
io = PetscBinaryIO.PetscBinaryIO(complexscalars=True)
solnAsPetscBiIOVec = function.vector.array_w.view(PetscBinaryIO.Vec)
io.writeBinaryFile(f"function_proc{comm.rank}of{comm.size}-C.dat",
[solnAsPetscBiIOVec])
function.vector[...] = io.readBinaryFile(f"file_proc{comm.rank}of{comm.size}-C.dat")
Be aware that in docker
you need to run the command export PYTHONPATH=/usr/local/petsc/lib/petsc/bin/:$PYTHONPATH
first or the above code will fail.
Obviously the files produced are discretisation and proc-dependant. In my experience though stuff goes well as long as every program reads them once.