From 49ba6be0c237d1fa714f59cd24e998b92db13236 Mon Sep 17 00:00:00 2001 From: Yoann Audouin Date: Tue, 13 Sep 2022 14:17:43 +0200 Subject: [PATCH] Adding support of number of thread for the mesher --- idl/SMESH_Mesh.idl | 6 ++++++ src/SMESH/SMESH_Gen.cxx | 5 +---- src/SMESH/SMESH_Mesh.hxx | 4 ++++ src/SMESH_I/SMESH_2smeshpy.cxx | 3 ++- src/SMESH_I/SMESH_Mesh_i.cxx | 9 +++++++++ src/SMESH_I/SMESH_Mesh_i.hxx | 1 + src/SMESH_SWIG/smeshBuilder.py | 6 +++++- 7 files changed, 28 insertions(+), 6 deletions(-) diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index 0abc234b6..adfe5f782 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 b7433ae70..b0210005f 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 533b5648f..a0ef3ae87 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 1a0c6c2d2..187a2667e 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -2211,7 +2211,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 2bf934ce9..7dc45b405 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -7044,6 +7044,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 9685061d6..cee8e4b98 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 ef57b606c..74b1f6735 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -1842,7 +1842,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 @@ -1859,7 +1859,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) -- 2.39.2