Hi,
I am trying to create a function that converts a large number of extrusions (14K) to meshes.
I managed to do that in realistic timing and get a ON_SimpleArray<ON_Mesh*>
after slicing the extrusions and convert them concurrently in the following way for each thread:
for (int i = 0; i < slicedObjectsAttributesChecked.Count(); i++)
{
CRhinoObjRef objRef = CRhinoObjRef(slicedObjectsAttributesChecked[i]);
const ON_Geometry* geometry = objRef.Geometry();
const ON_Extrusion* extrusionCast = ON_Extrusion::Cast(geometry);
if (nullptr != extrusionCast)
{
ON_Brep* brep = extrusionCast->BrepForm();
if (brep)
{
ON_SimpleArray<ON_Mesh*> list(brep->m_F.Count());
int meshCount = brep->CreateMesh(mp, list);
if (meshCount == brep->m_F.Count())
{
for (int i = 0; i < list.Count(); i++)
{
if (nullptr != list[i])
{
slicedMeshes.Append(list[i]);
}
}
}
progressBarPosition->fetch_add(1);//atomic variable for progress bar
delete brep;
continue;
}
}
}
It seemed to give correct results after an extensive set of tests. One thing however that seemed not to work well is that the time consumed to finish all the threads was increasing after each time I was calling the multithreaded conversion. The following shows the growth pattern in seconds:
1.45894
2.05183
4.96986
7.17207
9.13605
8.82918
9.21310
10.74482
9.30600
9.20454
9.02471
9.55440
9.16980
9.64565
9.86206
9.63683
9.59136
It seems that after reaching the 9 to 10 seconds (always for the same job of 14K extrusions) the time did not grow any further. My first thought was a probable memory leak but after many days of checking the code it seemed that this was not the case. I went a bit deeper and I realised that the function ON_Brep::CreateMesh()
is not thread safe:
*/
Description:
Calculates polygon mesh approximation of the brep
and appends one mesh for each face to the mesh_list[]
array.
Parameters:
mp - [in] meshing parameters
mesh_list - [out] meshes are appended to this array.
Returns:
Number of meshes appended to mesh_list[] array.
Note:
This function is not thread safe.
*/
int CreateMesh(
const ON_MeshParameters& mp,
ON_SimpleArray<ON_Mesh*>& mesh_list
) const;
- Could it be that this non thread safe function (used concurrently) was not deallocating the memory properly causing this time growth?
- Is there really any workaround to make it run concurrently?
- Is there any alternative option to convert lots of extrusions into ON_Mesh?
Thanks!