multi threading on python
when I run a file in Gmsh's GUI I can use all 16 treads available to me from my CPU and the run time for a certain large step file to be meshed with a 2D mesh is 49.25s but when I run the same file using python i can only use one thread and my CPU time is 756.22s. attached below is my python file.
import gmsh
import sys
import threading
gmsh.initialize()
gmsh.option.setNumber("General.NumThreads",16)# for parallel 3D meshing
gmsh.model.occ.synchronize()
print("nt:", gmsh.option.getNumber("General.NumThreads"))
gmsh.model.mesh.MshFileVersion=2.2
gmsh.model.add("test.msh")
#file='test.step'
print("importing geometry")
v = gmsh.model.occ.importShapes(file, format="step")
gmsh.model.occ.synchronize()
gmsh.option.setNumber("Mesh.MeshSizeMin", mmin)
gmsh.option.setNumber("Mesh.MeshSizeMax", mmax)
print("meshing")
gmsh.model.occ.synchronize()
gmsh.model.mesh.generate(2)
print("save file")
gmsh.write("ballpass_mesh.msh2")
print("done")
# Launch the GUI to see the results:
if '-nopopup' not in sys.argv:
gmsh.fltk.run()
gmsh.finalize()
the code just imports a step file as defined by the user and creates a 2D mesh based on the min and max edge lengths also defined by the user. This mesh is then output as a msh (version 2) file to be read by a MATLAB function later.