Version: 9.16.0
SMESH_ParallelMesh.hxx
Go to the documentation of this file.
1// Copyright (C) 2007-2026 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#ifdef WIN32
39#include <thread>
40#include <boost/filesystem.hpp>
41#endif
43
45{
46 public:
47 SMESH_ParallelMesh(int theLocalId,
48 SMESH_Gen* theGen,
49 bool theIsEmbeddedMode,
50 SMESHDS_Document* theDocument);
51
53
54 // Locking mechanism
55 #ifndef WIN32
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(); };
60 #endif
61
62 // Thread Pool
63#ifndef WIN32
64 void InitPoolThreads() {_pool = new boost::asio::thread_pool(GetPoolNbThreads());};
65 boost::asio::thread_pool* GetPool() {return _pool;};
66 void DeletePoolThreads() {delete _pool;};
67#else
68 void InitPoolThreads() {};
69 void* GetPool() {return NULL;};
70 void DeletePoolThreads(){};
71#endif
72
73 int GetPoolNbThreads();
74
75 // Temporary folder
76 bool keepingTmpFolfer();
77 void CreateTmpFolder();
78 void DeleteTmpFolder();
79 boost::filesystem::path GetTmpFolder() {return tmp_folder;};
80 void cleanup();
81
82 //
83 bool IsParallel() override {return true;};
84 int GetParallelElement() override;
85 int GetDumpElement();
86
87 // Parallelims parameters
88 int GetParallelismMethod() {return _method;};
89 void SetParallelismMethod(int aMethod) {_method = aMethod;};
90
91 int GetParallelismDimension() {return _paraDim;};
92 void SetParallelismDimension(int aDim) {_paraDim = aDim;};
93
94 // Multithreading parameters
95 int GetNbThreads() {return _NbThreads;};
96 void SetNbThreads(long nbThreads);
97
98 // Multinode parameters
99 std::string GetResource() {return _resource;};
100 void SetResource(std::string aResource) {_resource = aResource;};
101
102 int GetNbProc() {return _nbProc;};
103 void SetNbProc(long nbProc) {_nbProc = nbProc;};
104
105 int GetNbProcPerNode() {return _nbProcPerNode;};
106 void SetNbProcPerNode(long nbProcPerNodes) {_nbProcPerNode = nbProcPerNodes;};
107
108 int GetNbNode() {return _nbNode;};
109 void SetNbNode(long nbNodes) {_nbNode = nbNodes;};
110
111 std::string GetWcKey() {return _wcKey;};
112 void SetWcKey(std::string wcKey) {_wcKey = wcKey;};
113
114 std::string GetWalltime() {return _walltime;};
115 void SetWalltime(std::string walltime) {_walltime = walltime;};
116
117 // Parallel computation
118 bool ComputeSubMeshes(
119 SMESH_Gen* gen,
120 SMESH_Mesh & aMesh,
121 const TopoDS_Shape & aShape,
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;
129
130 protected:
133 private:
134 // Mutex for multhitreading write in SMESH_Mesh
135#ifndef WIN32
136 boost::mutex _my_lock;
137 // thread pool for computation
138 boost::asio::thread_pool * _pool = nullptr;
139#endif
140 boost::filesystem::path tmp_folder;
142 int _paraDim = 3;
143
144 int _NbThreads = std::thread::hardware_concurrency();
145
146 int _nbProc = 1;
147 int _nbProcPerNode = 1;
148 int _nbNode = 1;
149 std::string _resource = "";
150 std::string _wcKey = "P11N0:SALOME";
151 std::string _walltime = "01:00:00";
152};
153#endif
std::set< int > TSetOfInt
Definition: SMESH_Gen.hxx:65
MeshDimension
Definition: SMESH_Hypothesis.hxx:40
ParallelismMethod
Definition: SMESH_ParallelMesh.hxx:42
@ MultiNode
Definition: SMESH_ParallelMesh.hxx:42
@ MultiThread
Definition: SMESH_ParallelMesh.hxx:42
#define SMESH_EXPORT
Definition: SMESH_SMESH.hxx:37
Definition: SMESHDS_Document.hxx:38
Definition: SMESH_Gen.hxx:68
Definition: SMESH_Mesh.hxx:80
virtual bool ComputeSubMeshes(SMESH_Gen *gen, SMESH_Mesh &aMesh, const TopoDS_Shape &aShape, const ::MeshDimension aDim, TSetOfInt *aShapesId, TopTools_IndexedMapOfShape *allowedSubShapes, SMESH_subMesh::compute_event &computeEvent, const bool includeSelf, const bool complexShapeFirst, const bool aShapeOnly)
Definition: SMESH_Mesh.hxx:410
virtual int GetParallelElement()
Definition: SMESH_Mesh.hxx:408
Definition: SMESH_ParallelMesh.hxx:45
void wait() override
Definition: SMESH_ParallelMesh.hxx:59
void SetNbProcPerNode(long nbProcPerNodes)
Definition: SMESH_ParallelMesh.hxx:106
void SetResource(std::string aResource)
Definition: SMESH_ParallelMesh.hxx:100
int GetParallelismDimension()
Definition: SMESH_ParallelMesh.hxx:91
void SetWcKey(std::string wcKey)
Definition: SMESH_ParallelMesh.hxx:112
void SetNbProc(long nbProc)
Definition: SMESH_ParallelMesh.hxx:103
int GetNbThreads()
Definition: SMESH_ParallelMesh.hxx:95
int GetNbProcPerNode()
Definition: SMESH_ParallelMesh.hxx:105
boost::filesystem::path tmp_folder
Definition: SMESH_ParallelMesh.hxx:140
boost::mutex _my_lock
Definition: SMESH_ParallelMesh.hxx:136
bool IsParallel() override
Definition: SMESH_ParallelMesh.hxx:83
SMESH_ParallelMesh(const SMESH_ParallelMesh &aMesh)
Definition: SMESH_ParallelMesh.hxx:132
int GetNbProc()
Definition: SMESH_ParallelMesh.hxx:102
boost::asio::thread_pool * GetPool()
Definition: SMESH_ParallelMesh.hxx:65
boost::filesystem::path GetTmpFolder()
Definition: SMESH_ParallelMesh.hxx:79
int GetNbNode()
Definition: SMESH_ParallelMesh.hxx:108
SMESH_ParallelMesh()
Definition: SMESH_ParallelMesh.hxx:131
void InitPoolThreads()
Definition: SMESH_ParallelMesh.hxx:64
void SetWalltime(std::string walltime)
Definition: SMESH_ParallelMesh.hxx:115
void SetNbNode(long nbNodes)
Definition: SMESH_ParallelMesh.hxx:109
std::string GetResource()
Definition: SMESH_ParallelMesh.hxx:99
std::string GetWalltime()
Definition: SMESH_ParallelMesh.hxx:114
void SetParallelismDimension(int aDim)
Definition: SMESH_ParallelMesh.hxx:92
std::string GetWcKey()
Definition: SMESH_ParallelMesh.hxx:111
void Lock() override
Definition: SMESH_ParallelMesh.hxx:56
void DeletePoolThreads()
Definition: SMESH_ParallelMesh.hxx:66
void Unlock() override
Definition: SMESH_ParallelMesh.hxx:57
void SetParallelismMethod(int aMethod)
Definition: SMESH_ParallelMesh.hxx:89
int GetParallelismMethod()
Definition: SMESH_ParallelMesh.hxx:88
compute_event
Definition: SMESH_subMesh.hxx:116