Running multiple instances of gmsh in multiple python threads
I'm working on a larger pipeline where I need to mesh many objects individually. They have nothing to do with each other. The objects' files lie in separate folders. I'm using the python API and parsl
to parallelize the process.
However, when parsl starts multiple threads to run my gmsh code in, these gmsh instances seem to share the same memory, and the meshing seems to sometimes happen on the wrong file, from the wrong folder.
To test what's going on, I tried running:
print(gmsh.is_initialized())
gmsh.initialize()
print(gmsh.is_initialized())
print(gmsh.models.list())
On the working runs, this prints:
0
1
['']
But sometimes, it prints:
1
1
['liver_surface3_f0']
I guess the issue is the purely static interface of gmsh...
As a workaround, I attempted to reload gmsh:
import importlib.util
spec = importlib.util.find_spec("gmsh")
gmsh_local = importlib.util.module_from_spec(spec)
spec.loader.exec_module(gmsh_local)
This doesn't work either. The cleanest solution would be to use a class-based API that is not purely static methods, but gmsh only seems to have the fully static-method based API? Is there another way to create and use multiple "instances" of gmsh?