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"
39 enum ParallelismMethod {MultiThread, MultiNode};
41 class SMESH_EXPORT SMESH_ParallelMesh: public SMESH_Mesh
44 SMESH_ParallelMesh(int theLocalId,
46 bool theIsEmbeddedMode,
47 SMESHDS_Document* theDocument);
49 virtual ~SMESH_ParallelMesh();
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(); };
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();
64 void CreateTmpFolder();
65 void DeleteTmpFolder();
66 boost::filesystem::path GetTmpFolder() {return tmp_folder;};
69 bool IsParallel() override {return true;};
71 // Parallelims paramaters
72 int GetParallelismMethod() {return _method;};
73 void SetParallelismMethod(int aMethod) {_method = aMethod;};
75 // Mutlithreading parameters
76 int GetNbThreads() {return _NbThreads;};
77 void SetNbThreads(long nbThreads);
79 // Multinode parameters
80 std::string GetResource() {return _resource;};
81 void SetResource(std::string aResource) {_resource = aResource;};
83 int GetNbProc() {return _nbProc;};
84 void SetNbProc(long nbProc) {_nbProc = nbProc;};
86 int GetNbProcPerNode() {return _nbProcPerNode;};
87 void SetNbProcPerNode(long nbProcPerNodes) {_nbProcPerNode = nbProcPerNodes;};
89 int GetNbNode() {return _nbNode;};
90 void SetNbNode(long nbNodes) {_nbNode = nbNodes;};
92 std::string GetWcKey() {return _wcKey;};
93 void SetWcKey(std::string wcKey) {_wcKey = wcKey;};
95 // Parallel computation
96 bool ComputeSubMeshes(
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;
109 SMESH_ParallelMesh():SMESH_Mesh() {};
110 SMESH_ParallelMesh(const SMESH_ParallelMesh& aMesh):SMESH_Mesh(aMesh) {};
112 // Mutex for multhitreading write in SMESH_Mesh
114 boost::mutex _my_lock;
116 boost::filesystem::path tmp_folder;
117 // thread pool for computation
118 boost::asio::thread_pool * _pool = nullptr;
120 int _method = ParallelismMethod::MultiThread;
122 int _NbThreads = std::thread::hardware_concurrency();
125 int _nbProcPerNode = 1;
127 std::string _resource = "";
128 std::string _wcKey = "P11N0:SALOME";