1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : SMESH_ParallelMesh.hxx
24 // Author : Yoann AUDOUIN, EDF
27 #ifndef _SMESH_PARALLELMESH_HXX_
28 #define _SMESH_PARALLELMESH_HXX_
30 #include "SMESH_Mesh.hxx"
33 #include <boost/asio.hpp>
36 #include "SMESH_Gen.hxx"
37 #include "SMESH_subMesh.hxx"
40 #include <boost/filesystem.hpp>
42 enum ParallelismMethod {MultiThread, MultiNode};
44 class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
47 SMESH_ParallelMesh(int theLocalId,
49 bool theIsEmbeddedMode,
50 SMESHDS_Document* theDocument);
52 ~SMESH_ParallelMesh();
56 void Lock() override {_my_lock.lock();};
57 void Unlock() override {_my_lock.unlock();};
58 // We need to recreate the pool afterthe join
59 void wait() override {_pool->join(); DeletePoolThreads(); InitPoolThreads(); };
64 void InitPoolThreads() {_pool = new boost::asio::thread_pool(GetPoolNbThreads());};
65 boost::asio::thread_pool* GetPool() {return _pool;};
66 void DeletePoolThreads() {delete _pool;};
68 void InitPoolThreads() {};
69 void* GetPool() {return NULL;};
70 void DeletePoolThreads(){};
73 int GetPoolNbThreads();
76 bool keepingTmpFolfer();
77 void CreateTmpFolder();
78 void DeleteTmpFolder();
79 boost::filesystem::path GetTmpFolder() {return tmp_folder;};
83 bool IsParallel() override {return true;};
84 int GetParallelElement() override;
87 // Parallelims paramaters
88 int GetParallelismMethod() {return _method;};
89 void SetParallelismMethod(int aMethod) {_method = aMethod;};
91 int GetParallelismDimension() {return _paraDim;};
92 void SetParallelismDimension(int aDim) {_paraDim = aDim;};
94 // Mutlithreading parameters
95 int GetNbThreads() {return _NbThreads;};
96 void SetNbThreads(long nbThreads);
98 // Multinode parameters
99 std::string GetResource() {return _resource;};
100 void SetResource(std::string aResource) {_resource = aResource;};
102 int GetNbProc() {return _nbProc;};
103 void SetNbProc(long nbProc) {_nbProc = nbProc;};
105 int GetNbProcPerNode() {return _nbProcPerNode;};
106 void SetNbProcPerNode(long nbProcPerNodes) {_nbProcPerNode = nbProcPerNodes;};
108 int GetNbNode() {return _nbNode;};
109 void SetNbNode(long nbNodes) {_nbNode = nbNodes;};
111 std::string GetWcKey() {return _wcKey;};
112 void SetWcKey(std::string wcKey) {_wcKey = wcKey;};
114 std::string GetWalltime() {return _walltime;};
115 void SetWalltime(std::string walltime) {_walltime = walltime;};
117 // Parallel computation
118 bool ComputeSubMeshes(
121 const TopoDS_Shape & aShape,
122 const ::MeshDimension aDim,
123 TSetOfInt* aShapesId /*=0*/,
124 TopTools_IndexedMapOfShape* allowedSubShapes,
125 SMESH_subMesh::compute_event &computeEvent,
126 const bool includeSelf,
127 const bool complexShapeFirst,
128 const bool aShapeOnly) override;
131 SMESH_ParallelMesh():SMESH_Mesh() {};
132 SMESH_ParallelMesh(const SMESH_ParallelMesh& aMesh):SMESH_Mesh(aMesh) {};
134 // Mutex for multhitreading write in SMESH_Mesh
136 boost::mutex _my_lock;
137 // thread pool for computation
138 boost::asio::thread_pool * _pool = nullptr;
140 boost::filesystem::path tmp_folder;
141 int _method = ParallelismMethod::MultiThread;
144 int _NbThreads = std::thread::hardware_concurrency();
147 int _nbProcPerNode = 1;
149 std::string _resource = "";
150 std::string _wcKey = "P11N0:SALOME";
151 std::string _walltime = "01:00:00";