Salome HOME
Adding Multinode method for smesh parallelism + cleanup and doc
[modules/smesh.git] / src / SMESH / SMESH_ParallelMesh.hxx
1 // Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  File   : SMESH_ParallelMesh.hxx
24 //  Author : Yoann AUDOUIN, EDF
25 //  Module : SMESH
26 //
27 #ifndef _SMESH_PARALLELMESH_HXX_
28 #define _SMESH_PARALLELMESH_HXX_
29
30 #include "SMESH_Mesh.hxx"
31
32 #ifndef WIN32
33 #include <boost/asio.hpp>
34 #endif
35
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_subMesh.hxx"
38
39 enum ParallelismMethod {MultiThread, MultiNode};
40
41 class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
42 {
43  public:
44   SMESH_ParallelMesh(int               theLocalId,
45                        SMESH_Gen*        theGen,
46                        bool              theIsEmbeddedMode,
47                        SMESHDS_Document* theDocument);
48
49   virtual ~SMESH_ParallelMesh();
50
51   // Locking mechanism
52   void Lock() override {_my_lock.lock();};
53   void Unlock() override {_my_lock.unlock();};
54   // We need to recreate the pool afterthe join
55   void wait() override {_pool->join(); DeletePoolThreads(); InitPoolThreads(); };
56
57   // Thread Pool
58   void InitPoolThreads() {_pool = new boost::asio::thread_pool(GetPoolNbThreads());};
59   void DeletePoolThreads() {delete _pool;};
60   boost::asio::thread_pool* GetPool() {return _pool;};
61   int GetPoolNbThreads();
62
63   // Temporary folder
64   void CreateTmpFolder();
65   void DeleteTmpFolder();
66   boost::filesystem::path GetTmpFolder() {return tmp_folder;};
67
68   //
69   bool IsParallel() override {return true;};
70
71   // Parallelims paramaters
72   int GetParallelismMethod() {return _method;};
73   void SetParallelismMethod(int aMethod) {_method = aMethod;};
74
75   // Mutlithreading parameters
76   int GetNbThreads() {return _NbThreads;};
77   void SetNbThreads(long nbThreads);
78
79   // Multinode parameters
80   std::string GetResource() {return _resource;};
81   void SetResource(std::string aResource) {_resource = aResource;};
82
83   int GetNbProc() {return _nbProc;};
84   void SetNbProc(long nbProc) {_nbProc = nbProc;};
85
86   int GetNbProcPerNode() {return _nbProcPerNode;};
87   void SetNbProcPerNode(long nbProcPerNodes) {_nbProcPerNode = nbProcPerNodes;};
88
89   int GetNbNode() {return _nbNode;};
90   void SetNbNode(long nbNodes) {_nbNode = nbNodes;};
91
92   std::string GetWcKey() {return _wcKey;};
93   void SetWcKey(std::string wcKey) {_wcKey = wcKey;};
94
95   // Parallel computation
96   bool ComputeSubMeshes(
97             SMESH_Gen* gen,
98             SMESH_Mesh & aMesh,
99             const TopoDS_Shape & aShape,
100             const ::MeshDimension       aDim,
101             TSetOfInt*                  aShapesId /*=0*/,
102             TopTools_IndexedMapOfShape* allowedSubShapes,
103             SMESH_subMesh::compute_event &computeEvent,
104             const bool includeSelf,
105             const bool complexShapeFirst,
106             const bool   aShapeOnly) override;
107
108  protected:
109   SMESH_ParallelMesh():SMESH_Mesh() {};
110   SMESH_ParallelMesh(const SMESH_ParallelMesh& aMesh):SMESH_Mesh(aMesh) {};
111  private:
112   // Mutex for multhitreading write in SMESH_Mesh
113 #ifndef WIN32
114   boost::mutex _my_lock;
115 #endif
116   boost::filesystem::path tmp_folder;
117   // thread pool for computation
118   boost::asio::thread_pool *     _pool = nullptr;
119
120   int _method = ParallelismMethod::MultiThread;
121
122   int _NbThreads = std::thread::hardware_concurrency();
123
124   int _nbProc = 1;
125   int _nbProcPerNode = 1;
126   int _nbNode = 1;
127   std::string _resource = "";
128   std::string _wcKey = "P11N0:SALOME";
129 };
130 #endif