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