Salome HOME
Adding nnthreads as parameter for netgen
authorYoann Audouin <yoann.audouin@edf.fr>
Mon, 3 Oct 2022 13:46:12 +0000 (15:46 +0200)
committerYoann Audouin <yoann.audouin@edf.fr>
Mon, 3 Oct 2022 13:46:12 +0000 (15:46 +0200)
idl/NETGENPlugin_Algorithm.idl
src/NETGENPlugin/NETGENPluginBuilder.py
src/NETGENPlugin/NETGENPlugin_DriverParam.cxx
src/NETGENPlugin/NETGENPlugin_Hypothesis.cxx
src/NETGENPlugin/NETGENPlugin_Hypothesis.hxx
src/NETGENPlugin/NETGENPlugin_Hypothesis_i.cxx
src/NETGENPlugin/NETGENPlugin_Hypothesis_i.hxx
src/NETGENPlugin/NETGENPlugin_Mesher.cxx
src/NETGENPlugin/NETGENPlugin_NETGEN_3D_Remote.cxx

index 01b0d195044e2184de36b1a69acb084fb3a06114..b2d45fcd7a1df6eb20faf6ca8c7cc8f2618ae109 100644 (file)
@@ -147,6 +147,9 @@ module NETGENPlugin
     void    SetWorstElemMeasure(in short val );
     short   GetWorstElemMeasure();
 
+    void    SetNbThreads(in short val );
+    short   GetNbThreads();
+
     void    SetUseDelauney(in boolean toUse);
     boolean GetUseDelauney();
 
index 8079f01bfc9177c898bc3c5e9c71695444bcf794..162bb250b34080c32ac0793869080795743e3e27 100644 (file)
@@ -148,6 +148,12 @@ class NETGEN_Algorithm(Mesh_Algorithm):
         if self.Parameters(): self.params.SetGrowthRate(theRate)
         pass
 
+    ## Sets @c NbThreads parameter
+    #  @param theRate new value of the @c NbThreads parameter
+    def SetNbThreads(self, theNumber):
+        if self.Parameters(): self.params.SetNbThreads(theNumber)
+        pass
+
     ## Creates meshing hypothesis according to the chosen algorithm type
     #  and initializes it with default parameters
     #  @param which hypothesis type; can be either @ref SOLE (default) or @ref SIMPLE
index 73699088d894fec7c41856d3b1b25f5f52fc5c50..c61b04c658a0e2b684404d8fe44475d720c08fdf 100644 (file)
@@ -59,6 +59,7 @@ void printNetgenParams(netgen_params& aParams){
   std::cout << "checkoverlap: " << aParams.checkoverlap << std::endl;
   std::cout << "checkchartboundary: " << aParams.checkchartboundary << std::endl;
   std::cout << "closeedgefac: " << aParams.closeedgefac << std::endl;
+  std::cout << "nbThreadMesher: " << aParams.nbThreads << std::endl;
   std::cout << "has_local_size: " << aParams.has_local_size << std::endl;
   std::cout << "meshsizefilename: " << aParams.meshsizefilename << std::endl;
   std::cout << "has_maxelementvolume_hyp: " << aParams.has_maxelementvolume_hyp << std::endl;
@@ -119,6 +120,8 @@ void importNetgenParams(const std::string param_file, netgen_params& aParams){
   std::getline(myfile, line);
   aParams.closeedgefac = std::stoi(line);
   std::getline(myfile, line);
+  aParams.nbThreads = std::stoi(line);
+  std::getline(myfile, line);
   aParams.has_local_size = std::stoi(line);
   std::getline(myfile, line);
   aParams.meshsizefilename = line;
@@ -160,6 +163,7 @@ void exportNetgenParams(const std::string param_file, netgen_params& aParams){
   myfile << aParams.checkoverlap << std::endl;
   myfile << aParams.checkchartboundary << std::endl;
   myfile << aParams.closeedgefac << std::endl;
+  myfile << aParams.nbThreads << std::endl;
   myfile << aParams.has_local_size << std::endl;
   myfile << aParams.meshsizefilename << std::endl;
   myfile << aParams.has_maxelementvolume_hyp << std::endl;
index 28c9c6e87cee225d9056d64c79df44cd6cce7350..2113c960133b61c3d1b0ba854888838041dba562 100644 (file)
@@ -58,6 +58,7 @@ NETGENPlugin_Hypothesis::NETGENPlugin_Hypothesis (int hypId, SMESH_Gen * gen)
     _nbVolOptSteps      (GetDefaultNbVolOptSteps()),
     _elemSizeWeight     (GetDefaultElemSizeWeight()),
     _worstElemMeasure   (GetDefaultWorstElemMeasure()),
+    _nbThreads          (GetDefaultNbThreads()),
     _surfaceCurvature   (GetDefaultSurfaceCurvature()),
     _useDelauney        (GetDefaultUseDelauney()),
     _checkOverlapping   (GetDefaultCheckOverlapping()),
@@ -84,7 +85,7 @@ void NETGENPlugin_Hypothesis::SetMaxSize(double theSize)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
@@ -98,7 +99,7 @@ void NETGENPlugin_Hypothesis::SetMinSize(double theSize)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
@@ -112,7 +113,7 @@ void NETGENPlugin_Hypothesis::SetSecondOrder(bool theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
@@ -126,7 +127,7 @@ void NETGENPlugin_Hypothesis::SetOptimize(bool theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
@@ -172,7 +173,7 @@ void NETGENPlugin_Hypothesis::SetFineness(Fineness theFineness)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
@@ -187,7 +188,7 @@ void NETGENPlugin_Hypothesis::SetGrowthRate(double theRate)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
@@ -202,7 +203,7 @@ void NETGENPlugin_Hypothesis::SetNbSegPerEdge(double theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
@@ -217,7 +218,7 @@ void NETGENPlugin_Hypothesis::SetNbSegPerRadius(double theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetChordalErrorEnabled(bool theVal)
@@ -231,7 +232,7 @@ void NETGENPlugin_Hypothesis::SetChordalErrorEnabled(bool theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetChordalError(double theVal)
@@ -245,7 +246,7 @@ void NETGENPlugin_Hypothesis::SetChordalError(double theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetLocalSizeOnEntry(const std::string& entry, double localSize)
@@ -273,7 +274,7 @@ double NETGENPlugin_Hypothesis::GetLocalSizeOnEntry(const std::string& entry)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
@@ -284,7 +285,7 @@ void NETGENPlugin_Hypothesis::UnsetLocalSizeOnEntry(const std::string& entry)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
@@ -298,7 +299,7 @@ void NETGENPlugin_Hypothesis::SetMeshSizeFile(const std::string& fileName)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
@@ -312,7 +313,7 @@ void NETGENPlugin_Hypothesis::SetQuadAllowed(bool theVal)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 void NETGENPlugin_Hypothesis::SetSurfaceCurvature(bool theVal)
@@ -340,7 +341,7 @@ void NETGENPlugin_Hypothesis::SetFuseEdges(bool theVal)
 
 //=======================================================================
 //function : SetNbSurfOptSteps
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetNbSurfOptSteps( int theVal )
@@ -354,7 +355,7 @@ void NETGENPlugin_Hypothesis::SetNbSurfOptSteps( int theVal )
 
 //=======================================================================
 //function : SetNbVolOptSteps
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetNbVolOptSteps( int theVal )
@@ -368,7 +369,7 @@ void NETGENPlugin_Hypothesis::SetNbVolOptSteps( int theVal )
 
 //=======================================================================
 //function : SetElemSizeWeight
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetElemSizeWeight( double theVal )
@@ -382,7 +383,7 @@ void NETGENPlugin_Hypothesis::SetElemSizeWeight( double theVal )
 
 //=======================================================================
 //function : SetWorstElemMeasure
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetWorstElemMeasure( int theVal )
@@ -396,7 +397,7 @@ void NETGENPlugin_Hypothesis::SetWorstElemMeasure( int theVal )
 
 //=======================================================================
 //function : SetUseDelauney
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetUseDelauney( bool theVal )
@@ -410,7 +411,7 @@ void NETGENPlugin_Hypothesis::SetUseDelauney( bool theVal )
 
 //=======================================================================
 //function : SetCheckOverlapping
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetCheckOverlapping( bool theVal )
@@ -424,7 +425,7 @@ void NETGENPlugin_Hypothesis::SetCheckOverlapping( bool theVal )
 
 //=======================================================================
 //function : SetCheckChartBoundary
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis::SetCheckChartBoundary( bool theVal )
@@ -436,6 +437,20 @@ void NETGENPlugin_Hypothesis::SetCheckChartBoundary( bool theVal )
   }
 }
 
+//=======================================================================
+//function : SetNbThreads
+//purpose  :
+//=======================================================================
+
+void NETGENPlugin_Hypothesis::SetNbThreads( int theVal )
+{
+  if (theVal != _nbThreads)
+  {
+    _nbThreads = theVal;
+    NotifySubMeshesHypothesisModification();
+  }
+}
+
 //=============================================================================
 /*!
  *
@@ -485,7 +500,7 @@ ostream & NETGENPlugin_Hypothesis::SaveTo(ostream & save)
 
 //=============================================================================
 /*!
- *  
+ *
  */
 //=============================================================================
 istream & NETGENPlugin_Hypothesis::LoadFrom(istream & load)
index 133b774bf22c6aa30bb5b560277b2b17112456fa..e12b9ed30712efb14da4fa165610e9a57ca0a470 100644 (file)
@@ -35,6 +35,7 @@
 #include "Utils_SALOME_Exception.hxx"
 
 #include <map>
+#include <thread>
 
 //  Parameters for work of NETGEN
 //
@@ -125,6 +126,9 @@ public:
   void   SetCheckChartBoundary( bool toCheck );
   bool   GetCheckChartBoundary() const { return _checkChartBoundary; }
 
+  void   SetNbThreads( int val );
+  int    GetNbThreads() const { return _nbThreads; }
+
   // the default values (taken from NETGEN 4.5 sources)
 
   static Fineness GetDefaultFineness()          { return Moderate; }
@@ -145,6 +149,7 @@ public:
   static bool     GetDefaultCheckOverlapping()  { return true; }
   static bool     GetDefaultCheckChartBoundary(){ return true; }
   static bool     GetDefaultFuseEdges()         { return true; }
+  static int      GetDefaultNbThreads()         { return std::thread::hardware_concurrency(); }
 
   // Persistence
   virtual std::ostream & SaveTo  (std::ostream & save);
@@ -197,6 +202,9 @@ private:
   //bool          _blockFilling; -- not used by netgen
   // (SALOME additions)
   bool          _fuseEdges;
+
+  // Parallelism parameters
+  int _nbThreads;
 };
 
 #endif
index fd4c4fd9ed14f5828b45c49976434f86cb592bed..3af6b67991f0f3f73aaa450ac0e1ca02586faff4 100644 (file)
@@ -60,7 +60,7 @@ bool NETGENPlugin_Hypothesis_i::isToSetParameter<double>(double curValue,
 NETGENPlugin_Hypothesis_i::
 NETGENPlugin_Hypothesis_i (PortableServer::POA_ptr thePOA,
                            ::SMESH_Gen*            theGenImpl)
-  : SALOME::GenericObj_i( thePOA ), 
+  : SALOME::GenericObj_i( thePOA ),
     SMESH_Hypothesis_i( thePOA ),
     mySetMethodFlags(0)
 {
@@ -471,7 +471,7 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::GetFuseEdges()
 
 //=======================================================================
 //function : SetNbSurfOptSteps
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetNbSurfOptSteps(CORBA::Short nb )
@@ -495,7 +495,7 @@ CORBA::Short NETGENPlugin_Hypothesis_i::GetNbSurfOptSteps()
 
 //=======================================================================
 //function : SetNbVolOptSteps
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetNbVolOptSteps(CORBA::Short nb )
@@ -520,7 +520,7 @@ CORBA::Short NETGENPlugin_Hypothesis_i::GetNbVolOptSteps()
 
 //=======================================================================
 //function : SetElemSizeWeight
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetElemSizeWeight(CORBA::Double size )
@@ -544,7 +544,7 @@ CORBA::Double NETGENPlugin_Hypothesis_i::GetElemSizeWeight()
 
 //=======================================================================
 //function : SetWorstElemMeasure
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetWorstElemMeasure(CORBA::Short val )
@@ -558,7 +558,7 @@ void NETGENPlugin_Hypothesis_i::SetWorstElemMeasure(CORBA::Short val )
 
 //=======================================================================
 //function : GetWorstElemMeasure
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Short NETGENPlugin_Hypothesis_i::GetWorstElemMeasure()
@@ -566,9 +566,33 @@ CORBA::Short NETGENPlugin_Hypothesis_i::GetWorstElemMeasure()
   return (CORBA::Short) GetImpl()->GetWorstElemMeasure();
 }
 
+//=======================================================================
+//function : SetNbThreads
+//purpose  :
+//=======================================================================
+
+void NETGENPlugin_Hypothesis_i::SetNbThreads(CORBA::Short val )
+{
+  if ( GetNbThreads() != val )
+  {
+    this->GetImpl()->SetNbThreads( val );
+    SMESH::TPythonDump() << _this() << ".SetNbThreads( " << SMESH::TVar(val) << " )";
+  }
+}
+
+//=======================================================================
+//function : GetNbThreads
+//purpose  :
+//=======================================================================
+
+CORBA::Short NETGENPlugin_Hypothesis_i::GetNbThreads()
+{
+  return (CORBA::Short) GetImpl()->GetNbThreads();
+}
+
 //=======================================================================
 //function : SetUseDelauney
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetUseDelauney(CORBA::Boolean toUse)
@@ -582,7 +606,7 @@ void NETGENPlugin_Hypothesis_i::SetUseDelauney(CORBA::Boolean toUse)
 
 //=======================================================================
 //function : GetUseDelauney
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseDelauney()
@@ -592,7 +616,7 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::GetUseDelauney()
 
 //=======================================================================
 //function : SetCheckOverlapping
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetCheckOverlapping(CORBA::Boolean toCheck )
@@ -606,7 +630,7 @@ void NETGENPlugin_Hypothesis_i::SetCheckOverlapping(CORBA::Boolean toCheck )
 
 //=======================================================================
 //function : GetCheckOverlapping
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 CORBA::Boolean NETGENPlugin_Hypothesis_i::GetCheckOverlapping()
@@ -616,7 +640,7 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::GetCheckOverlapping()
 
 //=======================================================================
 //function : SetCheckChartBoundary
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 void NETGENPlugin_Hypothesis_i::SetCheckChartBoundary(CORBA::Boolean toCheck )
@@ -652,13 +676,13 @@ CORBA::Boolean NETGENPlugin_Hypothesis_i::GetCheckChartBoundary()
 
 //================================================================================
 /*!
- * \brief Verify whether hypothesis supports given entity type 
+ * \brief Verify whether hypothesis supports given entity type
   * \param type - dimension (see SMESH::Dimension enumeration)
   * \retval CORBA::Boolean - TRUE if dimension is supported, FALSE otherwise
- * 
+ *
  * Verify whether hypothesis supports given entity type (see SMESH::Dimension enumeration)
  */
-//================================================================================  
+//================================================================================
 CORBA::Boolean NETGENPlugin_Hypothesis_i::IsDimSupported( SMESH::Dimension type )
 {
   return type == SMESH::DIM_3D;
index 3f9535782d721ef67311e9db4c030ac28579a824..5d728f084fb4e5de66e6d2ef7128169639a35aad 100644 (file)
@@ -113,6 +113,9 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Hypothesis_i:
   void    SetWorstElemMeasure(CORBA::Short val );
   CORBA::Short GetWorstElemMeasure();
 
+  void    SetNbThreads(CORBA::Short val );
+  CORBA::Short GetNbThreads();
+
   void    SetUseDelauney(CORBA::Boolean toUse);
   CORBA::Boolean GetUseDelauney();
 
@@ -125,7 +128,7 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_Hypothesis_i:
   // Get implementation
   ::NETGENPlugin_Hypothesis* GetImpl();
 
-  // Verify whether hypothesis supports given entity type 
+  // Verify whether hypothesis supports given entity type
   CORBA::Boolean IsDimSupported( SMESH::Dimension type );
 
 
index 168cf5541da3a6998781674222c946cf47f861b3..615c970fea997620e02ea70b6410ee34289539e3 100644 (file)
@@ -602,14 +602,13 @@ void NETGENPlugin_Mesher::SetDefaultParameters()
 
 #ifdef NETGEN_V6
 
-  mparams.nthreads = std::thread::hardware_concurrency();
+  mparams.nthreads = NETGENPlugin_Hypothesis::GetDefaultNbThreads();
 
   if ( getenv( "SALOME_NETGEN_DISABLE_MULTITHREADING" ))
   {
     mparams.nthreads = 1;
     mparams.parallel_meshing = false;
   }
-
 #endif
 }
 
@@ -655,6 +654,7 @@ void NETGENPlugin_Mesher::SetParameters(const NETGENPlugin_Hypothesis* hyp)
 #ifdef NETGEN_V6
     // std::string
     mparams.meshsizefilename = hyp->GetMeshSizeFile();
+    mparams.nthreads = hyp->GetNbThreads();
 #else
     // const char*
     mparams.meshsizefilename= hyp->GetMeshSizeFile().empty() ? 0 : hyp->GetMeshSizeFile().c_str();
index f05293ae379077eec46850ca0cdcfe8cc2fa67a0..bc81359fa0edc2c5aa078e0ec05e2b7d2c581333 100644 (file)
@@ -127,13 +127,11 @@ void NETGENPlugin_NETGEN_3D_Remote::fillParameters(const NETGENPlugin_Hypothesis
 #ifdef NETGEN_V6
   // std::string
   aParams.meshsizefilename = hyp->GetMeshSizeFile();
+  aParams.closeedgefac = 2;
+  aParams.nbThreads = hyp->GetNbThreads();
 #else
   // const char*
   aParams.meshsizefilename = hyp->GetMeshSizeFile();
-#endif
-#ifdef NETGEN_V6
-  aParams.closeedgefac = 2;
-#else
   aParams.closeedgefac = 0;
 #endif
 }