#include <TopoDS_Iterator.hxx>
#include "memoire.h"
+#include <chrono>
#ifdef WIN32
#include <windows.h>
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() )
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() && shapeType != previousShapeType) {
+ 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:
case TopAbs_VERTEX:
file_name = "Mesh0D.med";
break;
+ case TopAbs_SOLID:
default:
file_name = "";
break;
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;
}
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();
+
return ret;
}
else
// the most complex shapes and collect sub-meshes with algos that
// DO support sub-meshes
// ================================================================
-
+ auto begin = std::chrono::high_resolution_clock::now();
list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim
// map to sort sm with same dim algos according to dim of
continue;
sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
setCurrentSubMesh( sm );
+ auto begin = std::chrono::high_resolution_clock::now();
sm->ComputeStateEngine( computeEvent );
+ auto end = std::chrono::high_resolution_clock::now();
+ auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
+ std::cout << "Time for seq:alldim:compute: " << elapsed.count()*1e-9 << std::endl;
+
setCurrentSubMesh( NULL );
sm->SetAllowedSubShapes( nullptr );
if ( aShapesId )
// mesh the rest sub-shapes starting from vertices
// -----------------------------------------------
ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes );
+ 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;
+
}
MEMOSTAT;
void SetNbThreads(int nbThreads){_NbThreads=nbThreads;};
void InitPoolThreads(){_pool = new ctpl::thread_pool(_NbThreads);};
+ void DeletePoolThreads(){delete _pool;};
bool IsParallel(){return _NbThreads > 0;}
//#define PRINT_WHO_COMPUTE_WHAT
#endif
-#define PRINT_WHO_COMPUTE_WHAT
+//#define PRINT_WHO_COMPUTE_WHAT
//=============================================================================
/*!
* \brief Allocate some memory at construction and release it at destruction.
break;
}
TopoDS_Shape shape = _subShape;
- algo->SubMeshesToCompute().assign( 1, this );
+ if(!_father->IsParallel())
+ algo->SubMeshesToCompute().assign( 1, this );
// check submeshes needed
// In parallel there would be no submesh to check
if (_father->HasShapeToMesh() && !_father->IsParallel()) {
geom = self.geom
return self.smeshpyD.Evaluate(self.mesh, geom)
+ def ParallelCompute(self, nbThreads, 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
+
+ Parameters:
+ nbThreads: Number of threads to use for a parallel computation
+ geom: geomtrical shape on which mesh data should be computed
+ discardModifs: if True and the mesh has been edited since
+ a last total re-compute and that may prevent successful partial re-compute,
+ then the mesh is cleaned before Compute()
+ refresh: if *True*, Object Browser is automatically updated (when running in GUI)
+
+ Returns:
+ True or False
+ """
+ if (nbThreads <= 1):
+ raise ValueError("nbThreads must be greater than 1")
+ self.mesh.SetNbThreads(nbThreads)
+ return self.Compute(geom=geom, discardModifs=discardModifs, refresh=refresh)
- def Compute(self, geom=0, discardModifs=False, refresh=False, nbThreads=0):
+ def Compute(self, geom=0, discardModifs=False, refresh=False):
"""
Compute the mesh and return the status of the computation
try:
if discardModifs and self.mesh.HasModificationsToDiscard(): # issue 0020693
self.mesh.Clear()
- # Setting parallel parameters
- self.mesh.SetNbThreads(nbThreads)
ok = self.smeshpyD.Compute(self.mesh, geom)
except SALOME.SALOME_Exception as ex:
print("Mesh computation failed, exception caught:")
// find non-auxiliary hypothesis
const SMESHDS_Hypothesis *theHyp = 0;
set< string > propagTypes;
- std::cout << "For shape " << aShape.HashCode(1) << " of type "<< aShape.ShapeType() <<
- "CheckHypothesis" << std::endl;
- for(auto hyp:hyps){
- SMESH_Comment hypStr;
- hypStr << hyp << " " << hyp->GetName() << " ";
- ((SMESHDS_Hypothesis*)hyp)->SaveTo( hypStr.Stream() );
- hypStr << " ";
- std::cout << hypStr << std::endl;
- }
+ //std::cout << "For shape " << aShape.HashCode(1) << " of type "<< aShape.ShapeType() <<
+ // "CheckHypothesis" << std::endl;
+ // for(auto hyp:hyps){
+ // SMESH_Comment hypStr;
+ // hypStr << hyp << " " << hyp->GetName() << " ";
+ // ((SMESHDS_Hypothesis*)hyp)->SaveTo( hypStr.Stream() );
+ // hypStr << " ";
+ // std::cout << hypStr << std::endl;
+ // }
list <const SMESHDS_Hypothesis * >::const_iterator h = hyps.begin();
for ( ; h != hyps.end(); ++h ) {
if ( static_cast<const SMESH_Hypothesis*>(*h)->IsAuxiliary() ) {
const SMDS_MeshNode * nLast = SMESH_Algo::VertexNode( VLast, meshDS );
if ( !nFirst || !nLast ){
theMesh.Unlock();
- std::cout << "exit no node" << std::endl;
+ //std::cout << "exit no node" << std::endl;
return error( COMPERR_BAD_INPUT_MESH, "No node on vertex");
}
// remove elements created by e.g. pattern mapping (PAL21999)
BRepAdaptor_Curve C3d( E );
if ( ! computeInternalParameters( theMesh, C3d, length, f, l, params, reversed, true )) {
theMesh.Unlock();
- std::cout << "exit Compute internal failed" << std::endl;
+ //std::cout << "exit Compute internal failed" << std::endl;
return false;
}
}
}
theMesh.Unlock();
- std::cout << "exit normal" << std::endl;
+ //std::cout << "exit normal" << std::endl;
return true;
}