From: Yoann Audouin Date: Tue, 17 Jan 2023 09:41:00 +0000 (+0100) Subject: Adding structure for parallelism parameters X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fyan%2Fparallel_mesh_cleanup;p=modules%2Fsmesh.git Adding structure for parallelism parameters --- diff --git a/doc/examples/creating_parallel_mesh.py b/doc/examples/creating_parallel_mesh.py index 9cfc0ee80..ae7a22c0d 100644 --- a/doc/examples/creating_parallel_mesh.py +++ b/doc/examples/creating_parallel_mesh.py @@ -100,7 +100,10 @@ def run_test(nbox=2, boxsize=100): par_mesh = smesh.ParallelMesh(geom, name="par_mesh") par_mesh.AddGlobalHypothesis(netgen_parameters) - par_mesh.SetNbThreads(6) + param = par_mesh.GetParallelismSettings() + param.SetNbThreads(6) + + assert param.GetNbThreads() == 6, param.GetNbThreads() start = time.monotonic() is_done = seq_mesh.Compute() diff --git a/doc/gui/input/parallel_compute.rst b/doc/gui/input/parallel_compute.rst index 82d1abfb9..fecbf2fea 100644 --- a/doc/gui/input/parallel_compute.rst +++ b/doc/gui/input/parallel_compute.rst @@ -59,7 +59,8 @@ You follow the same principle as the creation of a sequential Mesh. #. Set the parameters for the parallelisation: .. code-block:: python - par_mesh.SetNbThreads()Compute() + param = par_mesh.GetParallelismSettings() + param.SetNbThreads(6) #. Compute the mesh: .. code-block:: python diff --git a/idl/SMESH_Mesh.idl b/idl/SMESH_Mesh.idl index d4bc7fb57..88152274e 100644 --- a/idl/SMESH_Mesh.idl +++ b/idl/SMESH_Mesh.idl @@ -904,6 +904,11 @@ module SMESH */ void SetNbThreads(in long nbThreads); /*! + /*! + * \brief Get Number of Threads + */ + long GetNbThreads(); + /*! /*! * Get mesh description diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index 7d4bcb418..d101f14dc 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -7037,6 +7037,15 @@ void SMESH_Mesh_i::SetNbThreads(CORBA::Long nbThreads){ _impl->SetNbThreads(nbThreads); } +//============================================================================= +/*! + * \brief Get the number of threads for a parallel computation + */ +//============================================================================= +CORBA::Long SMESH_Mesh_i::GetNbThreads(){ + return _impl->GetNbThreads(); +} + //============================================================================= /*! diff --git a/src/SMESH_I/SMESH_Mesh_i.hxx b/src/SMESH_I/SMESH_Mesh_i.hxx index 45928272d..d9a82e3c6 100644 --- a/src/SMESH_I/SMESH_Mesh_i.hxx +++ b/src/SMESH_I/SMESH_Mesh_i.hxx @@ -673,7 +673,11 @@ private: SMESH::submesh_array_array& theSubMeshOrder, const bool theIsDump); + /*! + * Parallelims informations + */ void SetNbThreads(CORBA::Long nbThreads); + CORBA::Long GetNbThreads(); /*! * \brief Finds concurrent sub-meshes diff --git a/src/SMESH_SWIG/smeshBuilder.py b/src/SMESH_SWIG/smeshBuilder.py index f00c62083..8d0a81ac5 100644 --- a/src/SMESH_SWIG/smeshBuilder.py +++ b/src/SMESH_SWIG/smeshBuilder.py @@ -7583,12 +7583,41 @@ def _split_geom(geompyD, geom): return all_faces, solids -class ParallelMesh(Mesh): +class ParallelismSettings: """ - Surcharge on Mesh for parallel computation of a mesh + Defines the parameters for the parallelism of ParallelMesh """ + def __init__(self, mesh): + """ + Construsctor + Parameters: + mesh: Instance of ParallelMesh + """ + if not(isinstance(mesh, ParallelMesh)): + raise ValueError("mesh should be a ParallelMesh") + self._mesh = mesh + + def SetNbThreads(self, nbThreads): + """ + Set the number of threads for multithreading + """ + if nbThreads < 1: + raise ValueError("Number of threads must be stricly greater than 1") + + self._mesh.mesh.SetNbThreads(nbThreads) + + def GetNbThreads(self): + """ + Get Number of threads + """ + return self._mesh.mesh.GetNbThreads() + +class ParallelMesh(Mesh): + """ + Surcharge on Mesh for parallel computation of a mesh + """ def __init__(self, smeshpyD, geompyD, geom, split_geom=True, name=0): """ Create a parallel mesh. @@ -7598,7 +7627,7 @@ class ParallelMesh(Mesh): geompyD: instance of geomBuilder geom: geometrical object for meshing split_geom: If true will divide geometry on solids and 1D/2D - coumpund and create the associated submeshes + coumpound and create the associated submeshes name: the name for the new mesh. Returns: @@ -7628,10 +7657,20 @@ class ParallelMesh(Mesh): algo3d = self.Tetrahedron(geom=solid, algo="NETGEN_3D_Remote") self._algo3d.append(algo3d) + self._param = ParallelismSettings(self) + + + def GetParallelismSettings(self): + """ + Return class to set parameters for the parallelism + """ + return self._param def AddGlobalHypothesis(self, hyp): """ - Assign a hypothesis + Split hypothesis to apply it to all the submeshes: + - the 1D+2D + - each of the 3D solids Parameters: hyp: a hypothesis to assign @@ -7648,18 +7687,6 @@ class ParallelMesh(Mesh): param3d = algo3d.Parameters() _copy_netgen_param(3, param3d, hyp) - def SetNbThreads(self, nbThreads): - """ - Define the number of threads for meshing - - Parameters: - nbThreads: Number of threads - """ - - if nbThreads < 1: - raise ValueError("Number of threads must be stricly greater than 1") - - self.mesh.SetNbThreads(nbThreads) pass # End of ParallelMesh