]> SALOME platform Git repositories - plugins/blsurfplugin.git/commitdiff
Salome HOME
Adding multithread computation (available since MeshGems-2.4-2) cbr/enable_multithreading
authorChristophe Bourcier <christophe.bourcier@cea.fr>
Thu, 19 Jan 2017 13:41:14 +0000 (14:41 +0100)
committerChristophe Bourcier <christophe.bourcier@cea.fr>
Thu, 19 Jan 2017 13:41:14 +0000 (14:41 +0100)
By default, 4 threads are used (same default as in CADSurf).

12 files changed:
idl/BLSURFPlugin_Algorithm.idl
src/BLSURFPlugin/BLSURFPluginBuilder.py
src/BLSURFPlugin/BLSURFPlugin_BLSURF.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis.hxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.cxx
src/BLSURFPlugin/BLSURFPlugin_Hypothesis_i.hxx
src/GUI/BLSURFPlugin_msg_en.ts
src/GUI/BLSURFPlugin_msg_fr.ts
src/GUI/BLSURFPlugin_msg_ja.ts
tests/CMakeLists.txt
tests/test_cadsurf_multithread.py [new file with mode: 0644]

index 545282aee6ebfc91b702cb8c3d49413a837b9a69..141982f352e57f2a8264ef0fdb289ec0c316b168 100644 (file)
@@ -353,6 +353,15 @@ module BLSURFPlugin
     void SetMaxNumberOfPointsPerPatch( in long nb ) raises (SALOME::SALOME_Exception);
     long GetMaxNumberOfPointsPerPatch();
 
+
+    /*!
+     * Set max_number_of_threads parameter
+     *
+     * Set the maximum of threads to use for multithreading mesh computation.
+     */
+    void SetMaxNumberOfThreads( in long nb ) raises (SALOME::SALOME_Exception);
+    long GetMaxNumberOfThreads();
+
     /*!
      * Set respect_geometry parameter
      *
index 8fcb6e959f06c583b2db517920f118b91b07c6ee..af4e99d7f139edaf2f92aa711c5a5906fc7831c2 100644 (file)
@@ -251,6 +251,13 @@ class BLSURF_Algorithm(Mesh_Algorithm):
   def SetMaxNumberOfPointsPerPatch( self, nb ):
     self.Parameters().SetMaxNumberOfPointsPerPatch( nb )
 
+  ## Set max_number_of_threads parameter
+  #
+  #  Set the maximum of threads to use for multithreading mesh computation
+  #
+  def SetMaxNumberOfThreads( self, nb ):
+    self.Parameters().SetMaxNumberOfThreads( nb )
+
   ## Set respect_geometry parameter
   #  
   #  This patch independent option can be deactivated to allow MeshGems-CADSurf
index 3679c02ea2958662d6e1c0237573a1666e54d6e5..0cb1a1be5e9713c98dc4e11008d3040021d5e7fb 100644 (file)
@@ -1918,6 +1918,9 @@ bool BLSURFPlugin_BLSURF::compute(SMESH_Mesh&         aMesh,
   cad_t *c     = cad_new(ctx);
   dcad_t *dcad = dcad_new(c);
 
+  // To enable multithreading
+  cad_set_thread_safety(c, 1);
+
   /* Now fill the CAD object with data from your CAD
    * environement. This is the most complex part of a successfull
    * integration.
index 6790461b07dc37b911f0b4f2766d45d463ec8d57..818b5893b67858503253069c83c613bc95e7225c 100644 (file)
@@ -121,6 +121,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
       };
 
   const char* intOptionNames[] = {          "max_number_of_points_per_patch",           // default = 100000
+                                            "max_number_of_threads",                    // default = 4
                                             "" // mark of end
       };
   const char* doubleOptionNames[] = {       // "surface_intersections_processing_max_cost",// default = 15
@@ -206,6 +207,7 @@ BLSURFPlugin_Hypothesis::BLSURFPlugin_Hypothesis(int hypId, int studyId, SMESH_G
   _defaultOptionValues["enforce_cad_edge_sizes"                 ] = "no";
   _defaultOptionValues["jacobian_rectification_respect_geometry"] = "yes";
   _defaultOptionValues["max_number_of_points_per_patch"         ] = "0";
+  _defaultOptionValues["max_number_of_threads"                  ] = "4";
   _defaultOptionValues["rectify_jacobian"                       ] = "yes";
   _defaultOptionValues["respect_geometry"                       ] = "yes";
   _defaultOptionValues["tiny_edge_avoid_surface_intersections"  ] = "yes";
@@ -555,6 +557,25 @@ int BLSURFPlugin_Hypothesis::GetMaxNumberOfPointsPerPatch()
 }
 //=============================================================================
 
+void BLSURFPlugin_Hypothesis::SetMaxNumberOfThreads( int nb )
+  throw (std::invalid_argument)
+{
+  if ( nb < 0 )
+    throw std::invalid_argument( SMESH_Comment("Invalid number of threads: ") << nb );
+
+  if ( GetMaxNumberOfThreads() != nb )
+  {
+    SetOptionValue("max_number_of_threads", SMESH_Comment( nb ));
+    NotifySubMeshesHypothesisModification();
+  }
+}
+//=============================================================================
+int BLSURFPlugin_Hypothesis::GetMaxNumberOfThreads()
+{
+  return ToInt( GetOptionValue("max_number_of_threads", GET_DEFAULT()));
+}
+//=============================================================================
+
 void BLSURFPlugin_Hypothesis::SetRespectGeometry( bool toRespect )
 {
   if ( GetRespectGeometry() != toRespect )
index 2f5299b477399ca10ef2f442e0e6214c2e6ccb64..1ed967509cced5dac13ff85be47495ffa52197f7 100644 (file)
@@ -163,6 +163,9 @@ public:
   void SetMaxNumberOfPointsPerPatch( int nb ) throw (std::invalid_argument);
   int  GetMaxNumberOfPointsPerPatch();
 
+  void SetMaxNumberOfThreads( int nb ) throw (std::invalid_argument);
+  int  GetMaxNumberOfThreads();
+
   void SetRespectGeometry( bool toRespect );
   bool GetRespectGeometry();
 
index 395ef2e8e660ae8d4575117dcfe60ed1e61e2c04..b8c667791af542d4a017701d079c014984ee08e4 100644 (file)
@@ -854,6 +854,28 @@ CORBA::Long BLSURFPlugin_Hypothesis_i::GetMaxNumberOfPointsPerPatch()
 }
 //=============================================================================
 
+void BLSURFPlugin_Hypothesis_i::SetMaxNumberOfThreads( CORBA::Long nb ) throw (SALOME::SALOME_Exception)
+{
+  if ( GetMaxNumberOfThreads() != nb )
+  {
+    try {
+      this->GetImpl()->SetMaxNumberOfThreads(nb);
+
+    } catch (const std::invalid_argument& ex) {
+      THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+    } catch (SALOME_Exception& ex) {
+      THROW_SALOME_CORBA_EXCEPTION( ex.what() ,SALOME::BAD_PARAM );
+    }
+    SMESH::TPythonDump() << _this() << ".SetMaxNumberOfThreads( " << nb << " )";
+  }
+}
+//=============================================================================
+CORBA::Long BLSURFPlugin_Hypothesis_i::GetMaxNumberOfThreads()
+{
+  return this->GetImpl()->GetMaxNumberOfThreads();
+}
+//=============================================================================
+
 void BLSURFPlugin_Hypothesis_i::SetRespectGeometry( CORBA::Boolean toRespect )
 {
   if ( GetRespectGeometry() != toRespect )
@@ -1193,6 +1215,9 @@ void BLSURFPlugin_Hypothesis_i::SetOptionValue(const char* optionName, const cha
     else if ( name == "max_number_of_points_per_patch" )
       SetMaxNumberOfPointsPerPatch( GetImpl()->ToInt( optionValue ));
 
+    else if ( name == "max_number_of_threads" )
+      SetMaxNumberOfThreads( GetImpl()->ToInt( optionValue ));
+
     else if ( name == "rectify_jacobian" )
       SetJacobianRectification( GetImpl()->ToBool( optionValue ));
 
index d711253a26e25d75eda4bbfb519e5469f1f1dc7a..6a55caa6fbb9e138f357a1e8af09adf0b8add43a 100644 (file)
@@ -144,6 +144,9 @@ public:
   void SetMaxNumberOfPointsPerPatch( CORBA::Long nb ) throw (SALOME::SALOME_Exception);
   CORBA::Long GetMaxNumberOfPointsPerPatch();
 
+  void SetMaxNumberOfThreads( CORBA::Long nb ) throw (SALOME::SALOME_Exception);
+  CORBA::Long GetMaxNumberOfThreads();
+
   void SetRespectGeometry( CORBA::Boolean toRespect );
   CORBA::Boolean GetRespectGeometry();
 
index caa0fa060fb1baf60cef9755a1c9e46707d8ae1b..a866bd44436f473df5c9fc16f9328f4f54997df7 100644 (file)
@@ -629,6 +629,10 @@ The smaller this distance is, the closer the mesh is to the exact surface (only
         <source>max_number_of_points_per_patch</source>
         <translation>Maximal number of points per patch</translation>
     </message>
+    <message>
+        <source>max_number_of_threads</source>
+        <translation>Maximal number of threads</translation>
+    </message>
     <message>
         <source>rectify_jacobian</source>
         <translation>Rectify Jacobian</translation>
index f93cdd530590ecc720ef146b836cc81f55f7047e..259cd865f945076c030af8e4c2deec9c463e7b11 100755 (executable)
@@ -629,6 +629,10 @@ Plus la distance est petite, plus le maillage sera proche de la surface (disponi
         <source>max_number_of_points_per_patch</source>
         <translation>Nombre de points maximal par patch</translation>
     </message>
+    <message>
+        <source>max_number_of_threads</source>
+        <translation>Nombre de threads maximal</translation>
+    </message>
     <message>
         <source>rectify_jacobian</source>
         <translation>Ajustement du Jacobien</translation>
index 37bc0e12e5f89fe1b7b15be50c11d926f4696bda..96534dd5317050158d1ace4cde26852002ddc581 100644 (file)
       <source>max_number_of_points_per_patch</source>
       <translation>1パッチの最大点数</translation>
     </message>
+    <message>
+      <source>max_number_of_threads</source>
+      <translation type="unfinished">Maximal number of threads</translation>
+    </message>
     <message>
       <source>rectify_jacobian</source>
       <translation>ヤコビアンの修正</translation>
index b663c637da3e12d26cbd017ff870c9d15282bb41..07dec0091c8f7dd487c6f1567e050e4e2b6031cf 100755 (executable)
@@ -18,6 +18,7 @@
 #
 
 SET(BLSURFPLUGIN_TEST_FILES
+  test_cadsurf_multithread.py
   test_enforced_internal_vertex.py
   test_enforced_vertex.py
   test_periodicity_2D_precad.py
diff --git a/tests/test_cadsurf_multithread.py b/tests/test_cadsurf_multithread.py
new file mode 100644 (file)
index 0000000..62e8f0a
--- /dev/null
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+
+import os
+import sys
+import salome
+import time
+
+salome.salome_init()
+theStudy = salome.myStudy
+
+###
+### GEOM component
+###
+
+import GEOM
+from salome.geom import geomBuilder
+import math
+import SALOMEDS
+
+
+geompy = geomBuilder.New(theStudy)
+
+O = geompy.MakeVertex(0, 0, 0)
+OX = geompy.MakeVectorDXDYDZ(1, 0, 0)
+OY = geompy.MakeVectorDXDYDZ(0, 1, 0)
+OZ = geompy.MakeVectorDXDYDZ(0, 0, 1)
+flight_solid_brep_1 = geompy.ImportBREP(os.path.join(os.getenv("DATA_DIR"),"Shapes/Brep/flight_solid.brep" ))
+geompy.addToStudy( O, 'O' )
+geompy.addToStudy( OX, 'OX' )
+geompy.addToStudy( OY, 'OY' )
+geompy.addToStudy( OZ, 'OZ' )
+geompy.addToStudy( flight_solid_brep_1, 'flight_solid.brep_1' )
+
+###
+### SMESH component
+###
+
+import  SMESH, SALOMEDS
+from salome.smesh import smeshBuilder
+
+smesh = smeshBuilder.New(theStudy)
+
+Mesh_1 = smesh.Mesh(flight_solid_brep_1)
+MG_CADSurf = Mesh_1.Triangle(algo=smeshBuilder.MG_CADSurf)
+MG_CADSurf_Parameters_1 = MG_CADSurf.Parameters()
+MG_CADSurf_Parameters_1.SetPhySize( 1 )
+MG_CADSurf_Parameters_1.SetMaxSize( 1 )
+MG_CADSurf_Parameters_1.SetGradation( 1.05 )
+MG_CADSurf_Parameters_1.SetAngleMesh( 1 )
+MG_CADSurf_Parameters_1.SetChordalError( 2.40018 )
+# 4 procs are used by default
+# => No need to set an option
+
+time0 = time.time()
+isDone = Mesh_1.Compute()
+time1 = time.time()
+
+time_multithread = time1-time0
+
+print "Time in 4 proc: %.3s"%(time_multithread)
+
+Mesh_2 = smesh.Mesh(flight_solid_brep_1)
+MG_CADSurf = Mesh_2.Triangle(algo=smeshBuilder.MG_CADSurf)
+MG_CADSurf_Parameters_2 = MG_CADSurf.Parameters()
+MG_CADSurf_Parameters_2.SetPhySize( 1 )
+MG_CADSurf_Parameters_2.SetMaxSize( 1 )
+MG_CADSurf_Parameters_2.SetGradation( 1.05 )
+MG_CADSurf_Parameters_2.SetAngleMesh( 1 )
+MG_CADSurf_Parameters_2.SetChordalError( 2.40018 )
+# Use only one thread
+MG_CADSurf_Parameters_2.SetMaxNumberOfThreads( 1 )
+
+time2 = time.time()
+isDone = Mesh_2.Compute()
+time3 = time.time()
+
+time_singlethread = time3-time2
+print "Time in 1 proc: %.3s"%(time_singlethread)
+
+assert time_multithread < time_singlethread/2.
+
+if salome.sg.hasDesktop():
+  salome.sg.updateObjBrowser(True)