1 | #include "xios_manager.hpp" |
---|
2 | |
---|
3 | #include "tree_manager.hpp" |
---|
4 | #include "data_treatment.hpp" |
---|
5 | #include "nc4_data_output.hpp" |
---|
6 | #include "attribute_template_impl.hpp" |
---|
7 | #include "group_template_impl.hpp" |
---|
8 | |
---|
9 | namespace xmlioserver |
---|
10 | { |
---|
11 | /// ////////////////////// Définitions ////////////////////// /// |
---|
12 | |
---|
13 | void CXIOSManager::Initialise(XIOSType type, int * argc, char *** argv) |
---|
14 | { |
---|
15 | CXIOSManager::Type = type; |
---|
16 | if (type != CLIENT) |
---|
17 | { |
---|
18 | // Initialisation de la biliothÚque MPI si nécessaire |
---|
19 | comm::CMPIManager::Initialise(argc, argv); |
---|
20 | ExeName = StdString((*argv)[0]); |
---|
21 | for (int i = 1; i < *argc; i++) |
---|
22 | ExeOptions.push_back(StdString((*argv)[i])); |
---|
23 | } |
---|
24 | } |
---|
25 | |
---|
26 | void CXIOSManager::Finalize(void) |
---|
27 | { |
---|
28 | if (CXIOSManager::Type != CLIENT) |
---|
29 | |
---|
30 | { |
---|
31 | // Finalisation de la biliothÚque MPI si nécessaire |
---|
32 | comm::CMPIManager::Finalize(); |
---|
33 | } |
---|
34 | } |
---|
35 | |
---|
36 | ///------------------------------------------------------------- |
---|
37 | |
---|
38 | StdString CXIOSManager::ExeName("unknown"); |
---|
39 | std::vector<StdString> CXIOSManager::ExeOptions; |
---|
40 | |
---|
41 | CXIOSManager::XIOSType CXIOSManager::Type = CLIENT; |
---|
42 | CXIOSManager::XIOSStatus CXIOSManager::Status = LOC_UNUSED; |
---|
43 | |
---|
44 | StdString CXIOSManager::ClientName("unknown name"); |
---|
45 | comm::MPIComm CXIOSManager::Comm_Client_Server = -1; |
---|
46 | comm::MPIComm CXIOSManager::Comm_Server = -1; |
---|
47 | |
---|
48 | xios_map<StdString, CXIOSManager::XIOSClient> CXIOSManager::Clients; |
---|
49 | |
---|
50 | ///-------------------------------------------------------------- |
---|
51 | |
---|
52 | void CXIOSManager::RunServer |
---|
53 | (StdString clientName, comm::MPIComm comm_client_server, comm::MPIComm comm_server) |
---|
54 | { |
---|
55 | using namespace comm; |
---|
56 | CXIOSManager::Comm_Client_Server = comm_client_server; |
---|
57 | CXIOSManager::Comm_Server = comm_server; |
---|
58 | CXIOSManager::Status = LOC_SERVER; |
---|
59 | |
---|
60 | // Reconstruction de l'arborescence d'objet à l'aide des données envoyées par chacun des |
---|
61 | // clients associés à ce serveur. |
---|
62 | std::vector<boost::shared_ptr<CLinearBuffer> > clientBuffer; |
---|
63 | for (int i = 1; i < CMPIManager::GetCommSize(comm_client_server); i++) |
---|
64 | { |
---|
65 | while (!CMPIManager::HasReceivedData(comm_client_server, i)){} |
---|
66 | clientBuffer.push_back(CMPIManager::ReceiveLinearBuffer(comm_client_server, i)); |
---|
67 | } |
---|
68 | |
---|
69 | // La quasi-totalité de l'arborescence est obtenue depuis les informations |
---|
70 | // fournies par le client 1 du sous-groupe. |
---|
71 | StdString main_data_tree = clientBuffer[0]->getString(0); |
---|
72 | tree::CTreeManager::FromBinary(main_data_tree); |
---|
73 | |
---|
74 | // Obtention des sous-domaines clients. |
---|
75 | for (StdSize j = 1; j < clientBuffer.size(); j++) |
---|
76 | { |
---|
77 | main_data_tree = clientBuffer[j]->getString(0); |
---|
78 | tree::CTreeManager::DomainsFromBinary(main_data_tree); |
---|
79 | } |
---|
80 | |
---|
81 | StdOStringStream osss; |
---|
82 | osss << StdString("./def_server_next.") |
---|
83 | << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
84 | CTreeManager::PrintTreeToFile(osss.str()); |
---|
85 | |
---|
86 | { // Traitement de tous les contextes |
---|
87 | StdString currentContextId = CObjectFactory::GetCurrentContextId(); |
---|
88 | std::vector<boost::shared_ptr<CContext> > def_vector = |
---|
89 | CContext::GetContextGroup()->getChildList(); |
---|
90 | std::vector<boost::shared_ptr<CContext> >::iterator |
---|
91 | it = def_vector.begin(), end = def_vector.end(); |
---|
92 | |
---|
93 | //for (; it != end; it++ ) |
---|
94 | { |
---|
95 | boost::shared_ptr<CContext> context = *it; |
---|
96 | CTreeManager::SetCurrentContextId(context->getId()); |
---|
97 | boost::shared_ptr<data::CDataTreatment> dt(new data::CDataTreatment (context)); |
---|
98 | context->setDataTreatment(dt); |
---|
99 | dt->createDataOutput<io::CNc4DataOutput>(); |
---|
100 | } |
---|
101 | CTreeManager::SetCurrentContextId(currentContextId); |
---|
102 | } |
---|
103 | |
---|
104 | StdOStringStream oss; |
---|
105 | oss << StdString("./def_server_end.") |
---|
106 | << CMPIManager::GetCommRank(CMPIManager::GetCommWorld()); |
---|
107 | CTreeManager::PrintTreeToFile(oss.str()); |
---|
108 | |
---|
109 | } |
---|
110 | |
---|
111 | //-------------------------------------------------------------- |
---|
112 | |
---|
113 | void CXIOSManager::ShowInformation_CS(comm::MPIComm comm_client_server) |
---|
114 | { |
---|
115 | using namespace comm; |
---|
116 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
117 | if (CMPIManager::IsMaster(comm_client_server)) |
---|
118 | { |
---|
119 | std::cout << " *************************************** " << std::endl |
---|
120 | << " * XmlIOServer (Client/Server) * " << std::endl |
---|
121 | << " *************************************** " << std::endl; |
---|
122 | std::cout << " > Nombre de processus : " |
---|
123 | << CMPIManager::GetCommSize(comm_client_server) << std::endl; |
---|
124 | std::cout << " > Nombre de processus utilisés : " |
---|
125 | << (CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer()) << std::endl; |
---|
126 | std::cout << " > Nombre de clients : " |
---|
127 | << CXIOSManager::GetNbClient() << std::endl; |
---|
128 | std::cout << " > Nombre de serveurs : " |
---|
129 | << CXIOSManager::GetNbServer() << std::endl; |
---|
130 | |
---|
131 | xios_map<StdString, XIOSClient>::iterator |
---|
132 | iit = CXIOSManager::Clients.begin(), |
---|
133 | eend = CXIOSManager::Clients.end(); |
---|
134 | |
---|
135 | for (;iit != eend; iit++) |
---|
136 | { |
---|
137 | const StdPairStrClient & elem = *iit; |
---|
138 | std::cout << " - " << elem.first |
---|
139 | << " > nombre de clients : " |
---|
140 | << elem.second.nbClient |
---|
141 | << " , nombre de clients par serveur : " |
---|
142 | << elem.second.nbClientPServer |
---|
143 | << " , nombre de serveurs : " |
---|
144 | << elem.second.nbClient/elem.second.nbClientPServer |
---|
145 | << std::endl; |
---|
146 | } |
---|
147 | |
---|
148 | std::cout << " *************************************** " << std::endl; |
---|
149 | } |
---|
150 | |
---|
151 | comm::CMPIManager::Barrier(); |
---|
152 | |
---|
153 | } |
---|
154 | |
---|
155 | //-------------------------------------------------------------- |
---|
156 | |
---|
157 | void CXIOSManager::RunClientServer(comm::MPIComm comm_client_server) |
---|
158 | { |
---|
159 | using namespace comm; |
---|
160 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
161 | CXIOSManager::Comm_Client_Server = comm_client_server; |
---|
162 | CXIOSManager::Comm_Server = comm_client_server; |
---|
163 | |
---|
164 | CXIOSManager::ShowInformation_CS(comm_client_server); |
---|
165 | |
---|
166 | xios_map<StdString, XIOSClient>::iterator |
---|
167 | iit = CXIOSManager::Clients.begin(), |
---|
168 | eend = CXIOSManager::Clients.end(); |
---|
169 | |
---|
170 | StdSize start = 0, end = 0; |
---|
171 | |
---|
172 | bool isClient = true, isIncl = false, isIncl_ = false; |
---|
173 | MPIComm comm_client = 0, comm_client_grp = 0; comm_client_server = 0; |
---|
174 | |
---|
175 | for (;iit != eend; iit++) |
---|
176 | { |
---|
177 | const StdPairStrClient & elem = *iit; |
---|
178 | |
---|
179 | std::vector<int> clieindex, servindex ; |
---|
180 | StdSize currentRank = CMPIManager::GetCommRank(); |
---|
181 | StdString clientName = elem.first; |
---|
182 | StdSize nbClient = elem.second.nbClient; |
---|
183 | StdSize nbClientPServer = elem.second.nbClientPServer; |
---|
184 | StdSize nbServer = (elem.second.nbClient)/(elem.second.nbClientPServer); |
---|
185 | |
---|
186 | for (StdSize i = 0; i<nbServer; i++) |
---|
187 | { |
---|
188 | end = start + nbClientPServer; |
---|
189 | MPIComm comm_ = CMPIManager::CreateComm |
---|
190 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), start, end)); |
---|
191 | MPIComm comm__ = CMPIManager::CreateComm |
---|
192 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), start+1, end)); |
---|
193 | |
---|
194 | servindex.push_back(start); |
---|
195 | for (StdSize j = start+1; j <= end; j++) |
---|
196 | clieindex.push_back(j); |
---|
197 | |
---|
198 | if ((currentRank >= start) && (currentRank <= end)) |
---|
199 | { |
---|
200 | comm_client_server = comm_; |
---|
201 | comm_client_grp = comm__; |
---|
202 | isIncl = true; |
---|
203 | CXIOSManager::ClientName = clientName; |
---|
204 | CXIOSManager::Status = LOC_CLIENT; |
---|
205 | } |
---|
206 | if (currentRank == start) |
---|
207 | { |
---|
208 | isClient = false; isIncl_ = true; |
---|
209 | CXIOSManager::Comm_Client_Server = comm_; |
---|
210 | CXIOSManager::Status = LOC_SERVER; |
---|
211 | } |
---|
212 | if (clieindex.size() == nbClient) |
---|
213 | { |
---|
214 | MPIComm comm___ = CMPIManager::CreateComm |
---|
215 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), clieindex)); |
---|
216 | if (isIncl) comm_client = comm___; |
---|
217 | clieindex.clear(); |
---|
218 | isIncl = false; |
---|
219 | } |
---|
220 | |
---|
221 | start = start + nbClientPServer + 1; |
---|
222 | } |
---|
223 | MPIComm comm____ = CMPIManager::CreateComm |
---|
224 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), servindex)); |
---|
225 | if (isIncl_) CXIOSManager::Comm_Server = comm____; |
---|
226 | servindex.clear(); |
---|
227 | isIncl_ = false; |
---|
228 | } |
---|
229 | |
---|
230 | if (isClient && (CXIOSManager::Clients.find(CXIOSManager::ClientName) != |
---|
231 | CXIOSManager::Clients.end())) |
---|
232 | { |
---|
233 | CXIOSManager::Clients[CXIOSManager::ClientName].entry |
---|
234 | (comm_client, comm_client_grp, comm_client_server); |
---|
235 | } |
---|
236 | else if(CXIOSManager::Clients.find(CXIOSManager::ClientName) != |
---|
237 | CXIOSManager::Clients.end()) |
---|
238 | { |
---|
239 | CXIOSManager::RunServer(CXIOSManager::ClientName, |
---|
240 | CXIOSManager::Comm_Client_Server, |
---|
241 | CXIOSManager::Comm_Server); |
---|
242 | } |
---|
243 | } |
---|
244 | |
---|
245 | //--------------------------------------------------------------- |
---|
246 | |
---|
247 | void CXIOSManager::RunClient(bool launch, comm::MPIComm comm_client) |
---|
248 | { |
---|
249 | if (launch) |
---|
250 | { |
---|
251 | CXIOSManager::Status = LOC_CLIENT_SERVER; |
---|
252 | CXIOSManager::Comm_Server = comm_client; |
---|
253 | (CXIOSManager::Clients.begin()->second.entry) |
---|
254 | (comm_client, comm_client, comm_client); |
---|
255 | } |
---|
256 | else |
---|
257 | { |
---|
258 | CXIOSManager::Status = LOC_CLIENT; |
---|
259 | } |
---|
260 | } |
---|
261 | |
---|
262 | //--------------------------------------------------------------- |
---|
263 | |
---|
264 | void CXIOSManager::AddClient(StdString clientName, StdSize nbClient, StdSize nbClientPServer, |
---|
265 | void (*entry_point)(comm::MPIComm, comm::MPIComm, comm::MPIComm)) |
---|
266 | { |
---|
267 | StdSize nbprocess = comm::CMPIManager::GetCommSize(comm::CMPIManager::GetCommWorld()); |
---|
268 | StdSize nbprocess_used = CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer(); |
---|
269 | |
---|
270 | if (nbClient < nbClientPServer) |
---|
271 | ERROR("CXIOSManager::AddClient(...)", |
---|
272 | << "nbClient < nbClientPServer"); |
---|
273 | |
---|
274 | if ((nbClient % nbClientPServer) != 0) |
---|
275 | ERROR("CXIOSManager::AddClient(...)", |
---|
276 | << " (nbClient % nbClientPServer) != 0 !"); |
---|
277 | |
---|
278 | if ((nbprocess-nbprocess_used) < (nbClient + nbClient/nbClientPServer)) |
---|
279 | ERROR("CXIOSManager::AddClient(...)", |
---|
280 | << " Pas assez de processus disponibles !"); |
---|
281 | |
---|
282 | if (CXIOSManager::Clients.find(clientName) != CXIOSManager::Clients.end()) |
---|
283 | ERROR("CXIOSManager::AddClient(...)", |
---|
284 | << " Un client portant le même nom existe déjà !"); |
---|
285 | |
---|
286 | XIOSClient client = {nbClient, nbClientPServer, entry_point }; |
---|
287 | CXIOSManager::Clients[clientName] = client; |
---|
288 | } |
---|
289 | |
---|
290 | //--------------------------------------------------------------- |
---|
291 | |
---|
292 | StdSize CXIOSManager::GetNbClient(void) |
---|
293 | { |
---|
294 | switch (CXIOSManager::Type) |
---|
295 | { |
---|
296 | case (CLIENT_SERVER): |
---|
297 | { |
---|
298 | StdSize retvalue = 0; |
---|
299 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
300 | xios_map<StdString, XIOSClient>::iterator |
---|
301 | iit = CXIOSManager::Clients.begin(), |
---|
302 | eend = CXIOSManager::Clients.end(); |
---|
303 | |
---|
304 | for (;iit != eend; iit++) |
---|
305 | { |
---|
306 | const StdPairStrClient & elem = *iit; |
---|
307 | retvalue += CXIOSManager::GetNbLocClient(elem.first); |
---|
308 | } |
---|
309 | |
---|
310 | return (retvalue); |
---|
311 | } |
---|
312 | case (CLIENT): |
---|
313 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
314 | case (SERVER): |
---|
315 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Client_Server) - 1); |
---|
316 | default: |
---|
317 | return (0); |
---|
318 | } |
---|
319 | } |
---|
320 | |
---|
321 | //--------------------------------------------------------------- |
---|
322 | |
---|
323 | StdSize CXIOSManager::GetNbLocClient(const StdString & clientName) |
---|
324 | { |
---|
325 | switch (CXIOSManager::Type) |
---|
326 | { |
---|
327 | case (CLIENT_SERVER): |
---|
328 | return (CXIOSManager::Clients[clientName].nbClient); |
---|
329 | case (CLIENT): |
---|
330 | case (SERVER): |
---|
331 | return (CXIOSManager::GetNbClient()); |
---|
332 | default: |
---|
333 | return (0); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | //--------------------------------------------------------------- |
---|
338 | |
---|
339 | StdSize CXIOSManager::GetNbServer(void) |
---|
340 | { |
---|
341 | switch (CXIOSManager::Type) |
---|
342 | { |
---|
343 | case (CLIENT_SERVER): |
---|
344 | { |
---|
345 | StdSize retvalue = 0; |
---|
346 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
347 | |
---|
348 | xios_map<StdString, XIOSClient>::iterator |
---|
349 | iit = CXIOSManager::Clients.begin(), |
---|
350 | eend = CXIOSManager::Clients.end(); |
---|
351 | |
---|
352 | for (;iit != eend; iit++) |
---|
353 | { |
---|
354 | const StdPairStrClient & elem = *iit; |
---|
355 | retvalue += CXIOSManager::GetNbLocServer(elem.first); |
---|
356 | } |
---|
357 | |
---|
358 | return (retvalue); |
---|
359 | } |
---|
360 | case (CLIENT): |
---|
361 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
362 | case (SERVER): |
---|
363 | return (1); |
---|
364 | default: |
---|
365 | return (0); |
---|
366 | } |
---|
367 | } |
---|
368 | |
---|
369 | //--------------------------------------------------------------- |
---|
370 | |
---|
371 | StdSize CXIOSManager::GetNbLocServer(const StdString & clientName) |
---|
372 | { |
---|
373 | switch (CXIOSManager::Type) |
---|
374 | { |
---|
375 | case (CLIENT_SERVER): |
---|
376 | return (CXIOSManager::Clients[clientName].nbClient / |
---|
377 | CXIOSManager::Clients[clientName].nbClientPServer); |
---|
378 | case (CLIENT): |
---|
379 | case (SERVER): |
---|
380 | return (CXIOSManager::GetNbServer()); |
---|
381 | default: |
---|
382 | return (0); |
---|
383 | } |
---|
384 | } |
---|
385 | |
---|
386 | //--------------------------------------------------------------- |
---|
387 | |
---|
388 | CXIOSManager::XIOSType CXIOSManager::GetType(void) |
---|
389 | { |
---|
390 | return (CXIOSManager::Type); |
---|
391 | } |
---|
392 | |
---|
393 | //--------------------------------------------------------------- |
---|
394 | |
---|
395 | CXIOSManager::XIOSStatus CXIOSManager::GetStatus(void) |
---|
396 | { |
---|
397 | return (CXIOSManager::Status); |
---|
398 | } |
---|
399 | |
---|
400 | //--------------------------------------------------------------- |
---|
401 | |
---|
402 | StdString CXIOSManager::GetClientName(void) |
---|
403 | { |
---|
404 | return (CXIOSManager::ClientName); |
---|
405 | } |
---|
406 | |
---|
407 | ///-------------------------------------------------------------- |
---|
408 | |
---|
409 | } // namespace xmlioserver |
---|