Running in parallel using MPI

Hello. I am trying to run in parallel using < mpirun -n 2 python3 Beam.py >. However, it gives this error:
Process 0: *** Warning: XML file ‘beammesh.xml’ is very large. XML files are parsed in serial, which is not scalable. Use XMDF/HDF5 for scalable IO in parallel
Process 1: Solving linear variational problem.
Process 0: Solving linear variational problem.


Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.


mpirun noticed that process rank 0 with PID 0 on node euler exited on signal 9 (Killed).

And, this is how I defined the mesh:

from dolfin import *
from mshr import *
import sympy
mesh = Mesh('beammesh.xml')

How can I execute parallel running properly? Thank you.

As the message says, you should use the XDMF file format to read in the mesh, as described in for instance:

or

I converted the mesh to xdmf file. How will I use it? It gives an error:

Traceback (most recent call last):
File “Beam.py”, line 17, in
mesh = Mesh(‘mesh.xdmf’)
RuntimeError:

*** Error: Unable to open file.
*** Reason: Unknown file type (“.xdmf”) for file “mesh.xdmf”.
*** Where: This error was encountered inside File.cpp.
*** Process: 1


*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: unknown

This is how I defined the mesh:

from dolfin import *
from mshr import *
import sympy
mesh = Mesh('mesh.xdmf')  
boundaries = MeshFunction("size_t", mesh, "facet_mesh.xdmf")

See for instance Need help converting GMSH to FEniCS - #17 by dokken

Now, I get this error:
Traceback (most recent call last):
File “Beam.py”, line 23, in
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
AttributeError: module ‘mshr.cpp’ has no attribute ‘mesh’
Traceback (most recent call last):
File “Beam.py”, line 23, in
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
AttributeError: module ‘mshr.cpp’ has no attribute ‘mesh’

This is how I defined the mesh:

from dolfin import *
from mshr import *
import sympy
import meshio
mesh = Mesh()
mvc = MeshValueCollection("size_t", mesh, mesh.topology().dim())
with XDMFFile("mesh.xdmf") as infile:
   infile.read(mesh)
   infile.read(mvc, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, mvc)

mvc = MeshValueCollection("size_t", mesh, mesh.topology().dim()-1)
with XDMFFile("mf.xdmf") as infile:
    infile.read(mvc, "name_to_read")
mf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
ds_custom = Measure("ds", domain=mesh, subdomain_data=mf)

I would suggest removing this import.
Wildcard imports from multiple libraries are considered as bad practice, see for instance using wildcard imports (from … import *) — Python Anti-Patterns documentation

1 Like

Yes, that solved the problem. However, I have a problem with using the mesh named cf. When I use cf instead of mesh, it gives error. This is a part of my original code:

# mesh
from dolfin import *
import sympy
mesh = Mesh()
mvc = MeshValueCollection("size_t", mesh, mesh.topology().dim())
with XDMFFile("mesh.xdmf") as infile:
   infile.read(mesh)
   infile.read(mvc, "name_to_read")
cf = cpp.mesh.MeshFunctionSizet(mesh, MVC)
# Define Space
V = FunctionSpace(mesh, 'CG', 1)
W = VectorFunctionSpace(mesh, 'CG', 1)
WW = FunctionSpace(mesh, 'DG', 0)
p, q = TrialFunction(V), TestFunction(V)
u, v = TrialFunction(W), TestFunction(W)
# Boundary conditions
leftsup = CompiledSubDomain("((0 <= x[0] <= 0.5) && (0 <= x[1] <= 0.5))")
rightsup = CompiledSubDomain("((39.5 <= x[0] <= 40.0) && (0 <= x[1] <= 0.5))")
leftload = CompiledSubDomain("((9.5 <= x[0] <= 10.5) && (3.5 <= x[1] <= 4.0))")
rightload = CompiledSubDomain("((29.5 <= x[0] <= 30.5) && (3.5 <= x[1] <= 4.0))")

load = Expression("t", t = 0.0, degree=1)
def Crack(x):
    return (19.99 < x[0] < 20.01) and (-0.0001 < x[1] < 0.4)

bcleftsup= DirichletBC(W, Constant((0.0,0.0)), leftsup, method="pointwise")
bcrightsup= DirichletBC(W, Constant((0.0,0.0)), rightsup, method="pointwise")
bcleftload = DirichletBC(W.sub(1), load, leftload, method="pointwise")
bcrightload = DirichletBC(W.sub(1), load, rightload, method="pointwise")

bc_u = [bcleftsup, bcrightsup, bcleftload, bcrightload]
bc_phi = [DirichletBC(V, Constant(1.0), Crack)]
boundaries = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundaries.set_all(0)
leftload.mark(boundaries,1)
rightload.mark(boundaries,2)

plot(boundaries, interactive=True)

ds = Measure("ds")(subdomain_data=boundaries)
n = FacetNormal(mesh)

I define the boundaries in the code, I am using just one file for the mesh.
Thank you.

cf is not a mesh, it is a marker for the cells in your mesh (called mesh)

I used mesh as in the previous post and not cf but the program shuts down with a message:
Process 1: Solving linear variational problem.
Process 0: Solving linear variational problem.
Primary job terminated normally, but 1 process returned
a non-zero exit code. Per user-direction, the job has been aborted.
mpirun noticed that process rank 0 with PID 0 on node euler exited on signal 9 (Killed).

As I do not have access to your mesh, I cannot give any further help.

here it should be

cf = cpp.mesh.MeshFunctionSizet(mesh, mvc)
1 Like

The xdmf file only contains this:

<Xdmf Version="3.0"><Domain><Grid Name="Grid"><Geometry GeometryType="XY"><DataItem DataType="Float" Dimensions="1891323 2" Format="HDF" Precision="8">mesh.h5:/data0</DataItem></Geometry><Topology TopologyType="Triangle" NumberOfElements="3778214" NodesPerElement="3"><DataItem DataType="Int" Dimensions="3778214 3" Format="HDF" Precision="4">mesh.h5:/data1</DataItem></Topology><Attribute Name="name_to_read" AttributeType="Scalar" Center="Cell"><DataItem DataType="Int" Dimensions="3778214" Format="HDF" Precision="4">mesh.h5:/data2</DataItem></Attribute></Grid></Domain></Xdmf>

So, when I use h5 file instead of xdmf file, it gives this error:
Traceback (most recent call last):
File “Beam.py”, line 20, in
infile.read(mesh)
RuntimeError:
*** Error: Unable to recognise cell type.
*** Reason: Unknown value “”.
*** Where: This error was encountered inside XDMFFile.cpp.
*** Process: 0


*** DOLFIN version: 2019.2.0.dev0
*** Git changeset: unknown

You need to supply the h5 and xdmf file (or how you have created the mesh) for anyone to being able to help you.

1 Like