diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index e70b3d842..f420e4ff7 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -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 diff --git a/src/SMESH/SMESH_Gen.cxx b/src/SMESH/SMESH_Gen.cxx index 45a0049b4..fd053da69 100644 --- a/src/SMESH/SMESH_Gen.cxx +++ b/src/SMESH/SMESH_Gen.cxx @@ -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; diff --git a/src/SMESH/SMESH_Mesh.hxx b/src/SMESH/SMESH_Mesh.hxx index 29060a245..28a5b5a2b 100644 --- a/src/SMESH/SMESH_Mesh.hxx +++ b/src/SMESH/SMESH_Mesh.hxx @@ -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(); diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index a062e3d2f..a9fff0a6d 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -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 ); } diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index a7abda6db..3bd2f7fe7 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -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); +} + //============================================================================= /*! diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 25892ca9d..444c7b791 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -674,6 +674,7 @@ private: const bool theIsDump); void SetNbThreads(int nbThreads); + void SetMesherNbThreads(int nbThreads); /*! * \brief Finds concurrent sub-meshes diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index bb1361dac..3fad0860b 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -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)