MPIRUN - writing out text in parallel

Hi Dokken,
Could you give me an example?
I tried to follow this example, but, I could not get it to work.

I wanted to get an average value of the stress and strain across the mesh.

The following is my attempt:

    localstrain = strainss.vector().get_local()
    localstress = stresses.vector().get_local()
    MPI.COMM_WORLD.barrier()
    localstrain = mesh.mpi_comm().allgather(localstrain)
    localstress = mesh.mpi_comm().allgather(localstress)
    MPI.COMM_WORLD.barrier()
    if MPI.COMM_WORLD.rank ==0:
        StrStrOutput.write("\n"+str(np.average(localstrain[0::9])/Volume)+"\t"+str(np.average(localstrain[4::9])/Volume)+"\t"+str(np.average(localstress[0::9])/Volume)+"\t"+str(np.average(localstress[4::9])/Volume))
        StrStrOutput.flush()