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 * \brief Set Number of Threads
*/ */
void SetNbThreads(in long nbThreads); void SetNbThreads(in long nbThreads);
/*!
* \brief Set Number of Threads for mesher
*/
void SetMesherNbThreads(in long nbThreads);
/*! /*!
* Get mesh description * Get mesh description

View File

@ -251,6 +251,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX; TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
int nbThreads = aMesh.GetNbThreads(); int nbThreads = aMesh.GetNbThreads();
auto begin = std::chrono::high_resolution_clock::now(); 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); smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
@ -309,8 +310,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
} }
if(aMesh.IsParallel()) 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, boost::asio::post(*(aMesh._pool), std::bind(compute_function, 1, smToCompute, computeEvent,
shapeSM, aShapeOnly, allowedSubShapes, shapeSM, aShapeOnly, allowedSubShapes,
aShapesId)); aShapesId));
@ -321,8 +320,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
shapeSM, aShapeOnly, allowedSubShapes, shapeSM, aShapeOnly, allowedSubShapes,
aShapesId); aShapesId);
if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE && if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape )))) ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
ret = false; ret = false;

View File

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

View File

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

View File

@ -7046,6 +7046,15 @@ void SMESH_Mesh_i::SetNbThreads(int nbThreads){
_impl->SetNbThreads(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); const bool theIsDump);
void SetNbThreads(int nbThreads); void SetNbThreads(int nbThreads);
void SetMesherNbThreads(int nbThreads);
/*! /*!
* \brief Finds concurrent sub-meshes * \brief Finds concurrent sub-meshes

View File

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