]> SALOME platform Git repositories - modules/smesh.git/commitdiff
Salome HOME
Adding support of number of thread for the mesher
authorYoann Audouin <yoann.audouin@edf.fr>
Tue, 13 Sep 2022 12:17:43 +0000 (14:17 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Tue, 18 Oct 2022 13:01:44 +0000 (15:01 +0200)
idl/SMESH_Mesh.idl
src/SMESH/SMESH_Gen.cxx
src/SMESH/SMESH_Mesh.hxx
src/SMESH_I/SMESH_2smeshpy.cxx
src/SMESH_I/SMESH_Mesh_i.cxx
src/SMESH_I/SMESH_Mesh_i.hxx
src/SMESH_SWIG/smeshBuilder.py

index e70b3d842d1a74650d9ab25266dfa5221a98e0f3..f420e4ff7fdabebbe0470673973cda00e2d88541 100644 (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
index 45a0049b45c474f3449e37da3c31261c340f93b4..fd053da6909ba75845098e05e3aac33bd7d86f76 100644 (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;
index 29060a2453b8231654ffec58356b0a84fa13287a..28a5b5a2b0a51492f3e85dc8c0d3e76614b30529 100644 (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();
index a062e3d2fb179d91de3cf1d850d6f9a6085f6ae2..a9fff0a6d6add7fdcb61761d2fcd42316a3c6aeb 100644 (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 );
   }
index a7abda6dbd11366647ecf8b19a85da36d967f795..3bd2f7fe74587a973b563c0d2701d30001eb9701 100644 (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);
+}
+
 
 //=============================================================================
 /*!
index 25892ca9d9fcf21fc72ca0e3b2bf496eb54e5280..444c7b7910d12d345c6c54966da06022e0d7284b 100644 (file)
@@ -674,6 +674,7 @@ private:
                         const bool                  theIsDump);
 
   void SetNbThreads(int nbThreads);
+  void SetMesherNbThreads(int nbThreads);
 
   /*!
    * \brief Finds concurrent sub-meshes
index bb1361dacf9ad351c89c7ffc8b7bf47596ec799d..3fad0860b408892876a38ad7a10c09456ff0081d 100644 (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)