1 | #include "xios_manager.hpp" |
---|
2 | |
---|
3 | namespace xmlioserver |
---|
4 | { |
---|
5 | /// ////////////////////// Définitions ////////////////////// /// |
---|
6 | void CXIOSManager::Initialise(XIOSType type, int * argc, char *** argv) |
---|
7 | { |
---|
8 | CXIOSManager::Type = type; |
---|
9 | if (type != CLIENT) |
---|
10 | { |
---|
11 | // Initialisation de la biliothÚque MPI si nécessaire |
---|
12 | comm::CMPIManager::Initialise(argc, argv); |
---|
13 | ExeName = StdString((*argv)[0]); |
---|
14 | for (int i = 1; i < *argc; i++) |
---|
15 | ExeOptions.push_back(StdString((*argv)[i])); |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | void CXIOSManager::Finalize(void) |
---|
20 | { |
---|
21 | if (CXIOSManager::Type != CLIENT) |
---|
22 | { |
---|
23 | // Finalisation de la biliothÚque MPI si nécessaire |
---|
24 | comm::CMPIManager::Finalize(); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | ///------------------------------------------------------------- |
---|
29 | |
---|
30 | StdString CXIOSManager::ExeName("unknown"); |
---|
31 | std::vector<StdString> CXIOSManager::ExeOptions; |
---|
32 | |
---|
33 | CXIOSManager::XIOSType CXIOSManager::Type = CLIENT; |
---|
34 | |
---|
35 | StdString CXIOSManager::ClientName("unknown name"); |
---|
36 | comm::MPIComm CXIOSManager::Comm_Client_Server = -1; |
---|
37 | comm::MPIComm CXIOSManager::Comm_Server = -1; |
---|
38 | |
---|
39 | xios_map<StdString, CXIOSManager::XIOSClient> CXIOSManager::Clients; |
---|
40 | |
---|
41 | ///-------------------------------------------------------------- |
---|
42 | |
---|
43 | void CXIOSManager::RunServer |
---|
44 | (StdString clientName, comm::MPIComm comm_client_server, comm::MPIComm comm_server) |
---|
45 | { |
---|
46 | |
---|
47 | } |
---|
48 | |
---|
49 | //-------------------------------------------------------------- |
---|
50 | |
---|
51 | void CXIOSManager::ShowInformation_CS(comm::MPIComm comm_client_server) |
---|
52 | { |
---|
53 | using namespace comm; |
---|
54 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
55 | if (CMPIManager::IsMaster(comm_client_server)) |
---|
56 | { |
---|
57 | std::cout << " *************************************** " << std::endl |
---|
58 | << " * XmlIOServer (Client/Server) * " << std::endl |
---|
59 | << " *************************************** " << std::endl; |
---|
60 | std::cout << " > Nombre de processus : " |
---|
61 | << CMPIManager::GetCommSize(comm_client_server) << std::endl; |
---|
62 | std::cout << " > Nombre de processus utilisés : " |
---|
63 | << (CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer()) << std::endl; |
---|
64 | std::cout << " > Nombre de clients : " |
---|
65 | << CXIOSManager::GetNbClient() << std::endl; |
---|
66 | std::cout << " > Nombre de serveurs : " |
---|
67 | << CXIOSManager::GetNbServer() << std::endl; |
---|
68 | |
---|
69 | xios_map<StdString, XIOSClient>::iterator |
---|
70 | iit = CXIOSManager::Clients.begin(), |
---|
71 | eend = CXIOSManager::Clients.end(); |
---|
72 | |
---|
73 | for (;iit != eend; iit++) |
---|
74 | { |
---|
75 | const StdPairStrClient & elem = *iit; |
---|
76 | std::cout << " - " << elem.first |
---|
77 | << " > nombre de clients : " |
---|
78 | << elem.second.nbClient |
---|
79 | << " , nombre de clients par serveur : " |
---|
80 | << elem.second.nbClientPServer |
---|
81 | << " , nombre de serveurs : " |
---|
82 | << elem.second.nbClient/elem.second.nbClientPServer |
---|
83 | << std::endl; |
---|
84 | } |
---|
85 | |
---|
86 | std::cout << " *************************************** " << std::endl; |
---|
87 | } |
---|
88 | |
---|
89 | comm::CMPIManager::Barrier(); |
---|
90 | |
---|
91 | } |
---|
92 | |
---|
93 | //-------------------------------------------------------------- |
---|
94 | |
---|
95 | void CXIOSManager::RunClientServer(comm::MPIComm comm_client_server) |
---|
96 | { |
---|
97 | using namespace comm; |
---|
98 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
99 | |
---|
100 | CXIOSManager::ShowInformation_CS(comm_client_server); |
---|
101 | |
---|
102 | xios_map<StdString, XIOSClient>::iterator |
---|
103 | iit = CXIOSManager::Clients.begin(), |
---|
104 | eend = CXIOSManager::Clients.end(); |
---|
105 | |
---|
106 | StdSize start = 0, end = 0; |
---|
107 | |
---|
108 | bool isClient = true, isIncl = false, isIncl_ = false; |
---|
109 | MPIComm comm_client = 0, comm_client_grp = 0; comm_client_server = 0; |
---|
110 | |
---|
111 | for (;iit != eend; iit++) |
---|
112 | { |
---|
113 | const StdPairStrClient & elem = *iit; |
---|
114 | |
---|
115 | std::vector<int> clieindex, servindex ; |
---|
116 | StdSize currentRank = CMPIManager::GetCommRank(); |
---|
117 | StdString clientName = elem.first; |
---|
118 | StdSize nbClient = elem.second.nbClient; |
---|
119 | StdSize nbClientPServer = elem.second.nbClientPServer; |
---|
120 | StdSize nbServer = (elem.second.nbClient)/(elem.second.nbClientPServer); |
---|
121 | |
---|
122 | for (StdSize i = 0; i<nbServer; i++) |
---|
123 | { |
---|
124 | end = start + nbClientPServer; |
---|
125 | MPIComm comm_ = CMPIManager::CreateComm |
---|
126 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), start, end)); |
---|
127 | MPIComm comm__ = CMPIManager::CreateComm |
---|
128 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), start+1, end)); |
---|
129 | |
---|
130 | servindex.push_back(start); |
---|
131 | for (StdSize j = start+1; j <= end; j++) |
---|
132 | clieindex.push_back(j); |
---|
133 | |
---|
134 | if ((currentRank >= start) && (currentRank <= end)) |
---|
135 | { |
---|
136 | comm_client_server = comm_; |
---|
137 | comm_client_grp = comm__; |
---|
138 | isIncl = true; |
---|
139 | CXIOSManager::ClientName = clientName; |
---|
140 | } |
---|
141 | if (currentRank == start) |
---|
142 | { |
---|
143 | isClient = false; isIncl_ = true; |
---|
144 | CXIOSManager::Comm_Client_Server = comm_; |
---|
145 | } |
---|
146 | if (clieindex.size() == nbClient) |
---|
147 | { |
---|
148 | MPIComm comm___ = CMPIManager::CreateComm |
---|
149 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), clieindex)); |
---|
150 | if (isIncl) comm_client = comm___; |
---|
151 | clieindex.clear(); |
---|
152 | isIncl = false; |
---|
153 | } |
---|
154 | |
---|
155 | start = start + nbClientPServer + 1; |
---|
156 | } |
---|
157 | MPIComm comm____ = CMPIManager::CreateComm |
---|
158 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), servindex)); |
---|
159 | if (isIncl_) CXIOSManager::Comm_Server = comm____; |
---|
160 | servindex.clear(); |
---|
161 | isIncl_ = false; |
---|
162 | } |
---|
163 | |
---|
164 | if (isClient && (CXIOSManager::Clients.find(CXIOSManager::ClientName) != |
---|
165 | CXIOSManager::Clients.end())) |
---|
166 | { |
---|
167 | CXIOSManager::Clients[CXIOSManager::ClientName].entry |
---|
168 | (comm_client, comm_client_grp, comm_client_server); |
---|
169 | } |
---|
170 | else if(CXIOSManager::Clients.find(CXIOSManager::ClientName) != |
---|
171 | CXIOSManager::Clients.end()) |
---|
172 | { |
---|
173 | CXIOSManager::RunServer(CXIOSManager::ClientName, |
---|
174 | CXIOSManager::Comm_Client_Server, |
---|
175 | CXIOSManager::Comm_Server); |
---|
176 | } |
---|
177 | } |
---|
178 | |
---|
179 | //--------------------------------------------------------------- |
---|
180 | |
---|
181 | void CXIOSManager::RunClient(comm::MPIComm comm_client) |
---|
182 | { |
---|
183 | (CXIOSManager::Clients.begin()->second.entry)(comm_client, comm_client, comm_client); |
---|
184 | } |
---|
185 | |
---|
186 | //--------------------------------------------------------------- |
---|
187 | |
---|
188 | void CXIOSManager::AddClient(StdString clientName, StdSize nbClient, StdSize nbClientPServer, |
---|
189 | void (*entry_point)(comm::MPIComm, comm::MPIComm, comm::MPIComm)) |
---|
190 | { |
---|
191 | StdSize nbprocess = comm::CMPIManager::GetCommSize(comm::CMPIManager::GetCommWorld()); |
---|
192 | StdSize nbprocess_used = CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer(); |
---|
193 | |
---|
194 | if (nbClient < nbClientPServer) |
---|
195 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
196 | << "nbClient < nbClientPServer"); |
---|
197 | if ((nbClient % nbClientPServer) != 0) |
---|
198 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
199 | << " (nbClient % nbClientPServer) != 0 !"); |
---|
200 | if ((nbprocess-nbprocess_used) < (nbClient + nbClient/nbClientPServer)) |
---|
201 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
202 | << " Pas assez de processus disponibles !"); |
---|
203 | if (CXIOSManager::Clients.find(clientName) != CXIOSManager::Clients.end()) |
---|
204 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
205 | << " Un client portant le même nom existe déjà !"); |
---|
206 | |
---|
207 | XIOSClient client = {nbClient, nbClientPServer, entry_point }; |
---|
208 | CXIOSManager::Clients[clientName] = client; |
---|
209 | } |
---|
210 | |
---|
211 | //--------------------------------------------------------------- |
---|
212 | |
---|
213 | StdSize CXIOSManager::GetNbClient(void) |
---|
214 | { |
---|
215 | switch (CXIOSManager::Type) |
---|
216 | { |
---|
217 | case (CLIENT_SERVER): |
---|
218 | { |
---|
219 | StdSize retvalue = 0; |
---|
220 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
221 | xios_map<StdString, XIOSClient>::iterator |
---|
222 | iit = CXIOSManager::Clients.begin(), |
---|
223 | eend = CXIOSManager::Clients.end(); |
---|
224 | |
---|
225 | for (;iit != eend; iit++) |
---|
226 | { |
---|
227 | const StdPairStrClient & elem = *iit; |
---|
228 | retvalue += CXIOSManager::GetNbLocClient(elem.first); |
---|
229 | } |
---|
230 | |
---|
231 | return (retvalue); |
---|
232 | } |
---|
233 | case (CLIENT): |
---|
234 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
235 | case (SERVER): |
---|
236 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Client_Server) - 1); |
---|
237 | default: |
---|
238 | return (0); |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | //--------------------------------------------------------------- |
---|
243 | |
---|
244 | StdSize CXIOSManager::GetNbLocClient(const StdString & clientName) |
---|
245 | { |
---|
246 | switch (CXIOSManager::Type) |
---|
247 | { |
---|
248 | case (CLIENT_SERVER): |
---|
249 | return (CXIOSManager::Clients[clientName].nbClient); |
---|
250 | case (CLIENT): |
---|
251 | case (SERVER): |
---|
252 | return (CXIOSManager::GetNbClient()); |
---|
253 | default: |
---|
254 | return (0); |
---|
255 | } |
---|
256 | } |
---|
257 | |
---|
258 | //--------------------------------------------------------------- |
---|
259 | |
---|
260 | StdSize CXIOSManager::GetNbServer(void) |
---|
261 | { |
---|
262 | switch (CXIOSManager::Type) |
---|
263 | { |
---|
264 | case (CLIENT_SERVER): |
---|
265 | { |
---|
266 | StdSize retvalue = 0; |
---|
267 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
268 | |
---|
269 | xios_map<StdString, XIOSClient>::iterator |
---|
270 | iit = CXIOSManager::Clients.begin(), |
---|
271 | eend = CXIOSManager::Clients.end(); |
---|
272 | |
---|
273 | for (;iit != eend; iit++) |
---|
274 | { |
---|
275 | const StdPairStrClient & elem = *iit; |
---|
276 | retvalue += CXIOSManager::GetNbLocServer(elem.first); |
---|
277 | } |
---|
278 | |
---|
279 | return (retvalue); |
---|
280 | } |
---|
281 | case (CLIENT): |
---|
282 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
283 | case (SERVER): |
---|
284 | return (1); |
---|
285 | default: |
---|
286 | return (0); |
---|
287 | } |
---|
288 | } |
---|
289 | |
---|
290 | //--------------------------------------------------------------- |
---|
291 | |
---|
292 | StdSize CXIOSManager::GetNbLocServer(const StdString & clientName) |
---|
293 | { |
---|
294 | switch (CXIOSManager::Type) |
---|
295 | { |
---|
296 | case (CLIENT_SERVER): |
---|
297 | return (CXIOSManager::Clients[clientName].nbClient / |
---|
298 | CXIOSManager::Clients[clientName].nbClientPServer); |
---|
299 | case (CLIENT): |
---|
300 | case (SERVER): |
---|
301 | return (CXIOSManager::GetNbServer()); |
---|
302 | default: |
---|
303 | return (0); |
---|
304 | } |
---|
305 | } |
---|
306 | |
---|
307 | ///-------------------------------------------------------------- |
---|
308 | |
---|
309 | } // namespace xmlioserver |
---|