Salome HOME
Back to WIN32
[modules/smesh.git] / src / SMESH / SMESH_ParallelMesh.hxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, 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 #include "SMESH_Gen.hxx"
33 #include "SMESH_subMesh.hxx"
34
35 class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
36 {
37  public:
38   SMESH_ParallelMesh(int               theLocalId,
39                        SMESH_Gen*        theGen,
40                        bool              theIsEmbeddedMode,
41                        SMESHDS_Document* theDocument);
42
43   virtual ~SMESH_ParallelMesh();
44
45 #ifndef WIN32
46   void Lock() override {_my_lock.lock();};
47   void Unlock() override {_my_lock.unlock();};
48
49   int GetNbThreads() override{return _NbThreads;};
50   void SetNbThreads(long nbThreads) override{_NbThreads=nbThreads;};
51
52   void InitPoolThreads() override {_pool = new boost::asio::thread_pool(_NbThreads);};
53   void DeletePoolThreads() override {delete _pool;};
54
55   void wait() override {_pool->join(); DeletePoolThreads(); InitPoolThreads(); };
56
57   bool IsParallel() override {return _NbThreads > 0;};
58
59   void CreateTmpFolder();
60   void DeleteTmpFolder();
61
62   boost::filesystem::path GetTmpFolder() override {return tmp_folder;};
63   boost::asio::thread_pool* GetPool() override {return _pool;};
64 #else
65   void Lock() override {};
66   void Unlock() override {};
67
68   int GetNbThreads() override {return 0;};
69   void SetNbThreads(long nbThreads) {(void) nbThreads;};
70
71   void InitPoolThreads() override {};
72   void DeletePoolThreads() override {};
73   void wait() override {};
74
75   bool IsParallel() override {return false;};
76
77   void CreateTmpFolder();
78   void DeleteTmpFolder();
79 #endif
80
81   bool ComputeSubMeshes(
82             SMESH_Gen* gen,
83             SMESH_Mesh & aMesh,
84             const TopoDS_Shape & aShape,
85             const ::MeshDimension       aDim,
86             TSetOfInt*                  aShapesId /*=0*/,
87             TopTools_IndexedMapOfShape* allowedSubShapes,
88             SMESH_subMesh::compute_event &computeEvent,
89             const bool includeSelf,
90             const bool complexShapeFirst,
91             const bool   aShapeOnly) override;
92
93  protected:
94   SMESH_ParallelMesh():SMESH_Mesh() {};
95   SMESH_ParallelMesh(const SMESH_ParallelMesh& aMesh):SMESH_Mesh(aMesh) {};
96  private:
97 #ifndef WIN32
98   boost::filesystem::path tmp_folder;
99   boost::asio::thread_pool *     _pool = nullptr; //thread pool for computation
100 #endif
101 };
102 #endif