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