-
- TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
- std::vector<std::future<void>> pending;
- int nbThreads = aMesh.GetNbThreads();
- auto begin = std::chrono::high_resolution_clock::now();
-
-
- smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
- while ( smIt->more() )
- {
- SMESH_subMesh* smToCompute = smIt->next();
-
- // do not mesh vertices of a pseudo shape
- const TopoDS_Shape& shape = smToCompute->GetSubShape();
- const TopAbs_ShapeEnum shapeType = shape.ShapeType();
- if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
- continue;
- if(shapeType==TopAbs_FACE||shapeType==TopAbs_EDGE)
- aMesh.SetNbThreads(0);
- else
- aMesh.SetNbThreads(nbThreads);
- //DEBUG std::cout << "Shape Type" << shapeType << " previous" << previousShapeType << std::endl;
- if ((aMesh.IsParallel()||nbThreads!=0) && shapeType != previousShapeType) {
- // Waiting for all threads for the previous type to end
- for(auto &it: pending){
- 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;
- case TopAbs_SOLID:
- 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 )
- {
- // clear compute state not to show previous compute errors
- // if preview invoked less dimension less than previous
- smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
- continue;
- }
- if(aMesh.IsParallel())
- {
- pending.push_back(aMesh._pool->push(compute_function, smToCompute, computeEvent,
- shapeSM, aShapeOnly, allowedSubShapes,
- aShapesId));
- } else {
- auto begin2 = std::chrono::high_resolution_clock::now();
-
- compute_function(1 ,smToCompute, computeEvent,
- shapeSM, aShapeOnly, allowedSubShapes,
- aShapesId);
-
-
-
- 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() );
- }
- }
-
- // TODO: Check error handling in parallel mode
- if(aMesh.IsParallel()){
- // Waiting for the thread for Solids to finish
- for(auto &it:pending){
- it.wait();
- }
- pending.clear();
- }
-
- aMesh.GetMeshDS()->Modified();
- auto end = std::chrono::high_resolution_clock::now();
- auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
- std::cout << "Time for All: " << elapsed.count()*1e-9 << std::endl;
-
- // Pool of thread for computation
- if(aMesh.IsParallel())
- aMesh.DeletePoolThreads();