# Data output with parallel

I want to output the cell connectivity information, nodes coordinates, and calculated strain at each cell for post-processing. It turns out that those information are dependent on the number of cores used for mpirun. I have printed out the number of cells and nodes when reading mesh file in serial. But the number of cells and nodes outputted in those .txt files multiple cores are different from those printed out values from ‘print(mesh_from_file)’. Should I gather all the information to one processor and then save as the .txt files?

``````from __future__ import print_function
from dolfin import *
from ufl import nabla_div
from mpi4py import MPI
import numpy as np
import meshio
import gmsh
import sys

#Scaled variables

E = 2.5e11
nv = 0.27

lambda_ = E * nv / ((1 + nv) * (1 - 2 * nv))
mu = 0.5 * E / (1 + nv)

#generate mesh...

mesh = Mesh()
with XDMFFile("tetra_mesh.xdmf") as infile:

V = VectorFunctionSpace(mesh, 'P', 1)

# Define boundary condition
------------------------------------------------

# Define strain and stress

def epsilon(u):

def sigma(u):
return lambda_*nabla_div(u)*Identity(d) + 2*mu*epsilon(u)

# Define variational problem
u = TrialFunction(V)
d = u.geometric_dimension()  # space dimension
v = TestFunction(V)
f = Constant((0, 0, 0))

a = inner(sigma(u), epsilon(v))*dx
L = dot(f, v)*dx

# Compute solution
u = Function(V)
solve(a == L, u, bcs, solver_parameters = {'linear_solver':'mumps'})

strain = epsilon(u)

V_strain = TensorFunctionSpace(mesh, 'P', 1)

strain = project(strain, V_strain)

cells = mesh.cells()
mc_dof = V.tabulate_dof_coordinates()
mc_ms = mesh.coordinates()
num_cells = mesh.num_cells()

strain_at_centroid = []

# calculate strain_at_centroid ...

cells = mesh.cells()

np.savetxt('mesh_connectivity_S1V8_test1.txt', cells, fmt='%6i')
np.savetxt('nodes_coordinate_S1V8_test1.txt', mc_ms)
np.savetxt('strain_centroid_S1V8_test1.txt', strain_at_centroid)

XDMFFile('S1_V8_test1_results/displacement_test1.xdmf').write(u)

# Hold plot
``````

Regarding the difference between printing and saving as txt, I think you should not call `np.savetxt` from all the processors since all the processors will try to write to the same text file. You would want to gather the values to the root processor and save from only the root.