Register geom elements generated in mutliprocessing?

Hello,
I am strugling to use mutliprocessing with salome, and some developer help would be highly appreciated. I need to create several objects in geom but it takes a lot of time, each geometric object is 100% independent of each other, they do not share anything in commun, for each of them i have a list of vertexes and I want to create an object using MakeInterpol and the list of vertexes.
for simplicity, i created a dummy testing case where i create random positions for vertexes and the vertexes in sequential (using list coomprehension) and then I would like to create spheres in the each of this vertexes.
so the script looks like this:


listOfPosition=[[random.random(),random.random(),random.random()] for i in range(100)]
listOfVertexes=[geompy.MakeVertex(p[0], p[1], p[2]) for p in listOfPosition]
listOfSpheres_=[geompy.MakeSpherePntR(v, 100) for v in listOfVertexes]


def create_sphere(vertex):
    return geompy.MakeSpherePntR(vertex, 100)

with Pool(processes=4) as pool:  # Adjust number of processes as needed
    listOfSpheres = pool.map(create_sphere, listOfVertexes)



geompy.addToStudy(geompy.MakeCompound(listOfSpheres_),"")
geompy.addToStudy(geompy.MakeCompound(listOfSpheres),"")

as it can be seen, I am ‘creating’ two times the spheres, in a list coomprehension (ie., listOfSpheres_) and in multiprocessing (ie., listOfSpheres)
the thing is that this runs without errors until the geompy.MakeCompound() where it fails for the list created in parallel (ie., listOfSpheres). the thing is, when I print the content of listOfSpheres it is same type as the one made in list coomprehension. is there any way I can ‘continue’ with the one made with multiprocessing? any extra step so i can use listOfSpheres normally?
the error I am getting is the following:

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/home/franco/Desktop/blalba.py", line 52, in <module>
    geompy.addToStudy(geompy.MakeCompound(listOfSpheres),"")
  File "/home/franco/Programs/Salome/SALOME-9.14.0/BINARIES-CO7/GEOM/lib/python3.9/site-packages/salome/salome/geom/geomBuilder.py", line 368, in OpenCallClose
    res = theFunction(self, *args, **kwargs)
  File "/home/franco/Programs/Salome/SALOME-9.14.0/BINARIES-CO7/GEOM/lib/python3.9/site-packages/salome/salome/geom/geomBuilder.py", line 5122, in MakeCompound
    anObj = self.ShapesOp.MakeCompound(ToList(theShapes))
  File "/home/franco/Programs/Salome/SALOME-9.14.0/BINARIES-CO7/GEOM/lib/python3.9/site-packages/salome/GEOM_Gen_idl.py", line 1814, in MakeCompound
    return self._obj.invoke("MakeCompound", _0_GEOM.GEOM_IShapesOperations._d_MakeCompound, args)
omniORB.CORBA._omni_sys_exc: CORBA.OBJECT_NOT_EXIST(omniORB.OBJECT_NOT_EXIST_NoMatch, CORBA.COMPLETED_NO)

thanks in advance

Hello,

in the past I trued using multithreading to read multiple SMESH meshes using CORBA interface and what I got was only segfaults. I never understood what went wrong.

I played with your example and I created the geomBuilder instance inside the function, as well as trying to save the IOR of the created objects (using CORBA orb.object_to_string and then fetching the objects with string_to_object) but even that failed. Like you I always get the OBJECT_NOT_EXIST error, meaning that the CORBA instance exists, but the actual object tied to it never existed.

I do not know enough why it does not work or where it goes wrong. Maybe it’s a garbage collection issue and the objects are not properly stored on the CORBA server side. Which is funny, as the point of CORBA is to be able to communicate with different processes. Using addToStudy inside the function also does nothing.

Sorry, I do not have an answer but just wanted to chime in that I too tried to do something similar in the past.

1 Like

Hello gregor,
thanks for your kind answer, happy to see that I am not alone with this issue at least…
saddly, the python multiprocessing is something obscure for me, and well COBRA thingies even more… I tested without luck, I imagine that there should be a step to ‘repatriate’ everything to the main study, but dont know how. the main issue is that it is super salome specific, as this issue Printing output in python GUI sometimes in python console, sometimes in terminal issue with qdialog from pyqt - #2 by franco.ota
if one goes to ask in the wild to ‘classic’ users that are way more experience than one in python the ‘salome layer’ makes it difficult to get help with…

1 Like