This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Using mpirun to save time on generating mesh with mshr

0 votes

Hello people,
I'd like to know whether it's possible to use mpirun to yield a faster mesh generation by using several physical cores of a computer, instead of just one core.
Here's a sample code:

 '''
Generates mesh. Test with time python mesh_sample.py and time mpirun -n 4 python mesh_sample.py to see whether we can time by using more than 1 core.
'''
from dolfin import *
from mshr import *

# Create the domain
cylinder = Cylinder(Point(0, 0, 0), Point(0, 0, -7), 8.0, 8.0)

# Create mesh out of the domain
mesh = generate_mesh(cylinder, 100)

# Make sure the mesh is ok by saving to file and plot using Paraview.
File('mesh_sample.pvd') << mesh

Running it with "time python mesh_sample.py" returns:

Generating mesh with CGAL 3D mesh generator

real    0m19.169s
user    0m19.040s
sys 0m0.127s

and the mesh is generated correctly (according to what I see with Paraview). Now, using "mpirun -n 4 mesh_sample.py" on a computer that has 4 physical cores, this returns:

Process 0: Generating mesh with CGAL 3D mesh generator

real    0m22.853s
user    1m29.350s
sys 0m1.987s

so this is slightly slower than not using mpirun. I also see that in this case, there are 4 files.vtu which makes me wonder whether each core was assigned a part of the mesh to generate. If so, then why would that be slower than using a single core to perform the job of the 4 cores?

It seems I'm doing something wrong if my goal is to use more than 1 core in order to generate a mesh. Can someone shed some light on what's going on and tell me/us whether there's a "fix" that would actually save time to generate the mesh compared to when using a single core?

asked May 1, 2017 by raboytnik FEniCS Novice (140 points)
...