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;};
85 // Parallelims paramaters
86 int GetParallelismMethod() {return _method;};
87 void SetParallelismMethod(int aMethod) {_method = aMethod;};
89 // Mutlithreading parameters
90 int GetNbThreads() {return _NbThreads;};
91 void SetNbThreads(long nbThreads);
93 // Multinode parameters
94 std::string GetResource() {return _resource;};
95 void SetResource(std::string aResource) {_resource = aResource;};
97 int GetNbProc() {return _nbProc;};
98 void SetNbProc(long nbProc) {_nbProc = nbProc;};
100 int GetNbProcPerNode() {return _nbProcPerNode;};
101 void SetNbProcPerNode(long nbProcPerNodes) {_nbProcPerNode = nbProcPerNodes;};
103 int GetNbNode() {return _nbNode;};
104 void SetNbNode(long nbNodes) {_nbNode = nbNodes;};
106 std::string GetWcKey() {return _wcKey;};
107 void SetWcKey(std::string wcKey) {_wcKey = wcKey;};
109 std::string GetWalltime() {return _walltime;};
110 void SetWalltime(std::string walltime) {_walltime = walltime;};
112 // Parallel computation
113 bool ComputeSubMeshes(
116 const TopoDS_Shape & aShape,
117 const ::MeshDimension aDim,
118 TSetOfInt* aShapesId /*=0*/,
119 TopTools_IndexedMapOfShape* allowedSubShapes,
120 SMESH_subMesh::compute_event &computeEvent,
121 const bool includeSelf,
122 const bool complexShapeFirst,
123 const bool aShapeOnly) override;
126 SMESH_ParallelMesh():SMESH_Mesh() {};
127 SMESH_ParallelMesh(const SMESH_ParallelMesh& aMesh):SMESH_Mesh(aMesh) {};
129 // Mutex for multhitreading write in SMESH_Mesh
131 boost::mutex _my_lock;
132 // thread pool for computation
133 boost::asio::thread_pool * _pool = nullptr;
135 boost::filesystem::path tmp_folder;
136 int _method = ParallelismMethod::MultiThread;
138 int _NbThreads = std::thread::hardware_concurrency();
141 int _nbProcPerNode = 1;
143 std::string _resource = "";
144 std::string _wcKey = "P11N0:SALOME";
145 std::string _walltime = "01:00:00";