]> SALOME platform Git repositories - modules/smesh.git/blobdiff - src/SMESH/SMESH_Gen.cxx
Salome HOME
Revert "Merge branch 'yan/parallel_mesh2'"
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
index 0b5dc1385ac471f4323f34249b7d24cfc074225e..ef42e33e05069ebd2b649227a67b2525c28ac5c6 100644 (file)
@@ -30,7 +30,6 @@
 
 #include "SMESH_Gen.hxx"
 
-#include "DriverMesh.hxx"
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
@@ -56,8 +55,6 @@
 #include <Basics_Utils.hxx>
 
 using namespace std;
-#include <boost/filesystem.hpp>
-namespace fs = boost::filesystem;
 
 // Environment variable separator
 #ifdef WIN32
@@ -158,41 +155,6 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
   return aMesh;
 }
 
-//=============================================================================
-/*
- * Parallel compute of a submesh
- * This function is used to pass to thread_pool
- */
-//=============================================================================
-const std::function<void(int,
-                         SMESH_subMesh*,
-                         SMESH_subMesh::compute_event,
-                         SMESH_subMesh*,
-                         bool,
-                         TopTools_IndexedMapOfShape *,
-                         TSetOfInt*)>
-     parallel_compute([&] (int id,
-                          SMESH_subMesh* sm,
-                          SMESH_subMesh::compute_event event,
-                          SMESH_subMesh *shapeSM,
-                          bool aShapeOnly,
-                          TopTools_IndexedMapOfShape *allowedSubShapes,
-                          TSetOfInt*                  aShapesId) -> void
-{
-    if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
-  {
-    sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
-    //setCurrentSubMesh( sm );
-    sm->ComputeStateEngine(event);
-    //setCurrentSubMesh( nullptr );
-    sm->SetAllowedSubShapes( nullptr );
-  }
-
-  if ( aShapesId )
-    aShapesId->insert( sm->GetId() );
-
-});
-
 //=============================================================================
 /*
  * Compute a mesh
@@ -220,11 +182,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
   const bool complexShapeFirst = true;
   const int  globalAlgoDim = 100;
 
-  // Pool of thread for computation
-  if (!_pool){
-    _pool = new ctpl::thread_pool(2);
-  }
-
   SMESH_subMeshIteratorPtr smIt;
 
   // Fix of Issue 22150. Due to !BLSURF->OnlyUnaryInput(), BLSURF computes edges
@@ -245,9 +202,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
     // Mesh all the sub-shapes starting from vertices
     // ===============================================
 
-    TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
     smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
-    std::vector<std::future<void>> pending;
     while ( smIt->more() )
     {
       SMESH_subMesh* smToCompute = smIt->next();
@@ -258,39 +213,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
       if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
         continue;
 
-      //DEBUG std::cout << "Shape Type" << shapeType << " previous" << previousShapeType << std::endl;
-      if (shapeType != previousShapeType) {
-        // Waiting for all thread for the previous type to end
-        for(auto it =std::begin(pending); it != std::end(pending); ++it){
-          std::cout << "Waiting" << std::endl;
-          it->wait();
-        }
-        std::string file_name;
-        switch(previousShapeType){
-          case TopAbs_FACE:
-            file_name = "Mesh2D.med";
-            break;
-          case TopAbs_EDGE:
-            file_name = "Mesh1D.med";
-            break;
-          case TopAbs_VERTEX:
-            file_name = "Mesh0D.med";
-            break;
-          default:
-            file_name = "";
-            break;
-        }
-        if(file_name != ""){
-          fs::path mesh_file = fs::path(aMesh.tmp_folder) / fs::path(file_name);
-          // TODO: change mesh name
-          export_mesh(mesh_file.string(), aMesh, "Maillage_1");
-
-        }
-        //Resetting threaded pool info
-        previousShapeType = shapeType;
-        pending.clear();
-      }
-
       // check for preview dimension limitations
       if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
       {
@@ -299,18 +221,25 @@ bool SMESH_Gen::Compute(SMESH_Mesh &                aMesh,
         smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
         continue;
       }
-      pending.push_back(_pool->push(parallel_compute, smToCompute, computeEvent,
-                           shapeSM, aShapeOnly, allowedSubShapes,
-                           aShapesId));
-      //DEBUG std::cout << "Launched " << smToCompute << " shape type " << shapeType << std::endl;
-
 
-    }
+      if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
+      {
+        if (_compute_canceled)
+          return false;
+        smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
+        setCurrentSubMesh( smToCompute );
+        smToCompute->ComputeStateEngine( computeEvent );
+        setCurrentSubMesh( nullptr );
+        smToCompute->SetAllowedSubShapes( nullptr );
+      }
 
-    for(auto it =std::begin(pending); it != std::end(pending); ++it){
-      it->wait();
+      // we check all the sub-meshes here and detect if any of them failed to compute
+      if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
+          ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
+        ret = false;
+      else if ( aShapesId )
+        aShapesId->insert( smToCompute->GetId() );
     }
-    pending.clear();
     //aMesh.GetMeshDS()->Modified();
     return ret;
   }
@@ -674,7 +603,7 @@ bool SMESH_Gen::Evaluate(SMESH_Mesh &          aMesh,
       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
       const int aShapeDim = GetShapeDim( aSubShape );
       if ( aShapeDim < 1 ) break;
-
+      
       SMESH_Algo* algo = GetAlgo( smToCompute );
       if ( algo && !algo->NeedDiscreteBoundary() ) {
         if ( algo->SupportSubmeshes() ) {