Adding support of number of thread for the mesher

This commit is contained in:
Yoann Audouin 2022-09-13 14:17:43 +02:00
parent 7a915a21ea
commit 33f226d321
7 changed files with 28 additions and 6 deletions

View File

@ -903,6 +903,12 @@ module SMESH
* \brief Set Number of Threads
*/
void SetNbThreads(in long nbThreads);
/*!
* \brief Set Number of Threads for mesher
*/
void SetMesherNbThreads(in long nbThreads);
/*!
* Get mesh description

View File

@ -251,6 +251,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
int nbThreads = aMesh.GetNbThreads();
auto begin = std::chrono::high_resolution_clock::now();
std::cout << "Running mesh with threads: " << nbThreads << " mesher: " << aMesh.GetMesherNbThreads() << std::endl;
smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
@ -309,8 +310,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
}
if(aMesh.IsParallel())
{
std::cout << "Submitting thread function " << std::endl;
boost::asio::post(*(aMesh._pool), [](){std::cerr<< "In Here" << std::endl;});
boost::asio::post(*(aMesh._pool), std::bind(compute_function, 1, smToCompute, computeEvent,
shapeSM, aShapeOnly, allowedSubShapes,
aShapesId));
@ -321,8 +320,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
shapeSM, aShapeOnly, allowedSubShapes,
aShapesId);
if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
ret = false;

View File

@ -392,6 +392,9 @@ class SMESH_EXPORT SMESH_Mesh
int GetNbThreads(){return _NbThreads;};
void SetNbThreads(int nbThreads){_NbThreads=nbThreads;};
int GetMesherNbThreads(){return _MesherNbThreads;};
void SetMesherNbThreads(int nbThreads){_MesherNbThreads=nbThreads;};
void InitPoolThreads(){_pool = new boost::asio::thread_pool(_NbThreads);};
void DeletePoolThreads(){delete _pool;};
@ -453,6 +456,7 @@ protected:
// Mutex for multhitreading write in SMESH_Mesh
std::mutex _my_lock;
int _NbThreads=0;
int _MesherNbThreads=0;
protected:
SMESH_Mesh();

View File

@ -2212,7 +2212,8 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
"GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
"GetElemFaceNodes", "GetFaceNormal", "FindElementByNodes",
"IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
"Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder", "SetNbThreads"
"Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder",
"SetNbThreads", "SetMesherNbThreads"
,"" }; // <- mark of end
sameMethods.Insert( names );
}

View File

@ -7046,6 +7046,15 @@ void SMESH_Mesh_i::SetNbThreads(int nbThreads){
_impl->SetNbThreads(nbThreads);
}
//=============================================================================
/*!
* \brief Set the number of threads for the mesher for a parallel computation
*/
//=============================================================================
void SMESH_Mesh_i::SetMesherNbThreads(int nbThreads){
_impl->SetMesherNbThreads(nbThreads);
}
//=============================================================================
/*!

View File

@ -674,6 +674,7 @@ private:
const bool theIsDump);
void SetNbThreads(int nbThreads);
void SetMesherNbThreads(int nbThreads);
/*!
* \brief Finds concurrent sub-meshes

View File

@ -1863,7 +1863,7 @@ class Mesh(metaclass = MeshMeta):
geom = self.geom
return self.smeshpyD.Evaluate(self.mesh, geom)
def ParallelCompute(self, nbThreads, geom=0, discardModifs=False, refresh=False):
def ParallelCompute(self, nbThreads, mesherNbThreads=1, geom=0, discardModifs=False, refresh=False):
"""
Parallel computation of the mesh and return the status of the computation
The mesh must contains have be constructed using create_parallel_mesh
@ -1880,7 +1880,11 @@ class Mesh(metaclass = MeshMeta):
True or False
"""
if (nbThreads <= 1):
raise ValueError("nbThreads must be strictly greater than 1")
if (mesherNbThreads < 1):
raise ValueError("nbThreads must be greater than 1")
self.mesh.SetMesherNbThreads(mesherNbThreads)
self.mesh.SetNbThreads(nbThreads)
return self.Compute(geom=geom, discardModifs=discardModifs, refresh=refresh)