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::RunClientServer(comm::MPIComm comm_client_server) |
---|
52 | { |
---|
53 | using namespace comm; |
---|
54 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
55 | |
---|
56 | if (CMPIManager::IsMaster(comm_client_server)) |
---|
57 | { |
---|
58 | std::cout << " *************************************** " << std::endl |
---|
59 | << " * XmlIOServer (Client/Server) * " << std::endl |
---|
60 | << " *************************************** " << std::endl; |
---|
61 | std::cout << " > Nombre de processus : " |
---|
62 | << CMPIManager::GetCommSize(comm_client_server) << std::endl; |
---|
63 | std::cout << " > Nombre de processus utilisés : " |
---|
64 | << (CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer()) << std::endl; |
---|
65 | std::cout << " > Nombre de clients : " |
---|
66 | << CXIOSManager::GetNbClient() << std::endl; |
---|
67 | std::cout << " > Nombre de serveurs : " |
---|
68 | << CXIOSManager::GetNbServer() << std::endl; |
---|
69 | |
---|
70 | xios_map<StdString, XIOSClient>::iterator |
---|
71 | iit = CXIOSManager::Clients.begin(), |
---|
72 | eend = CXIOSManager::Clients.end(); |
---|
73 | |
---|
74 | for (;iit != eend; iit++) |
---|
75 | { |
---|
76 | const StdPairStrClient & elem = *iit; |
---|
77 | std::cout << " - " << elem.first |
---|
78 | << " > nombre de clients : " |
---|
79 | << elem.second.nbClient |
---|
80 | << " , nombre de clients par serveur : " |
---|
81 | << elem.second.nbClientPServer |
---|
82 | << " , nombre de serveurs : " |
---|
83 | << elem.second.nbClient/elem.second.nbClientPServer |
---|
84 | << std::endl; |
---|
85 | } |
---|
86 | |
---|
87 | std::cout << " *************************************** " << std::endl; |
---|
88 | } |
---|
89 | |
---|
90 | comm::CMPIManager::Barrier(); |
---|
91 | StdSize start = 0, end = 0; |
---|
92 | |
---|
93 | xios_map<StdString, XIOSClient>::iterator |
---|
94 | iit = CXIOSManager::Clients.begin(), |
---|
95 | eend = CXIOSManager::Clients.end(); |
---|
96 | |
---|
97 | bool isClient = true, isIncl = false; |
---|
98 | MPIComm comm_client = 0, comm_client_grp = 0; comm_client_server = 0; |
---|
99 | |
---|
100 | for (;iit != eend; iit++) |
---|
101 | { |
---|
102 | const StdPairStrClient & elem = *iit; |
---|
103 | |
---|
104 | std::vector<int> clieindex, servindex ; |
---|
105 | StdSize currentRank = CMPIManager::GetCommRank(); |
---|
106 | StdString clientName = elem.first; |
---|
107 | StdSize nbClient = elem.second.nbClient; |
---|
108 | StdSize nbClientPServer = elem.second.nbClientPServer; |
---|
109 | StdSize nbServer = (elem.second.nbClient)/(elem.second.nbClientPServer); |
---|
110 | |
---|
111 | for (StdSize i = 0; i<nbServer; i++) |
---|
112 | { |
---|
113 | end = start + nbClientPServer; |
---|
114 | MPIComm comm_ = CMPIManager::CreateComm |
---|
115 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), start, end)); |
---|
116 | MPIComm comm__ = CMPIManager::CreateComm |
---|
117 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), start+1, end)); |
---|
118 | |
---|
119 | servindex.push_back(start); |
---|
120 | for (StdSize j = start+1; j <= end; j++) |
---|
121 | clieindex.push_back(j); |
---|
122 | |
---|
123 | if ((currentRank >= start) && (currentRank <= end)) |
---|
124 | { |
---|
125 | comm_client_server = comm_; |
---|
126 | comm_client_grp = comm__; |
---|
127 | isIncl = true; |
---|
128 | CXIOSManager::ClientName = clientName; |
---|
129 | } |
---|
130 | if (currentRank == start) |
---|
131 | { |
---|
132 | isClient = false; |
---|
133 | CXIOSManager::Comm_Client_Server = comm_; |
---|
134 | } |
---|
135 | if (clieindex.size() == nbClient) |
---|
136 | { |
---|
137 | MPIComm comm___ = CMPIManager::CreateComm |
---|
138 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), clieindex)); |
---|
139 | if (isIncl) |
---|
140 | { |
---|
141 | comm_client = comm___; |
---|
142 | } |
---|
143 | clieindex.clear(); |
---|
144 | isIncl = false; |
---|
145 | } |
---|
146 | |
---|
147 | start = start + nbClientPServer + 1; |
---|
148 | } |
---|
149 | CXIOSManager::Comm_Server = CMPIManager::CreateComm |
---|
150 | (CMPIManager::CreateSubGroup(CMPIManager::GetGroupWorld(), servindex)); |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | if (isClient) |
---|
155 | { |
---|
156 | CXIOSManager::Clients[CXIOSManager::ClientName].entry |
---|
157 | (comm_client, comm_client_grp, comm_client_server); |
---|
158 | } |
---|
159 | else |
---|
160 | { |
---|
161 | CXIOSManager::RunServer(CXIOSManager::ClientName, |
---|
162 | CXIOSManager::Comm_Client_Server, |
---|
163 | CXIOSManager::Comm_Server); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | void CXIOSManager::RunClient(comm::MPIComm comm_client) |
---|
168 | { |
---|
169 | (CXIOSManager::Clients.begin()->second.entry)(comm_client, comm_client, comm_client); |
---|
170 | } |
---|
171 | |
---|
172 | //--------------------------------------------------------------- |
---|
173 | |
---|
174 | void CXIOSManager::AddClient(StdString clientName, StdSize nbClient, StdSize nbClientPServer, |
---|
175 | void (*entry_point)(comm::MPIComm, comm::MPIComm, comm::MPIComm)) |
---|
176 | { |
---|
177 | StdSize nbprocess = comm::CMPIManager::GetCommSize(comm::CMPIManager::GetCommWorld()); |
---|
178 | StdSize nbprocess_used = CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer(); |
---|
179 | |
---|
180 | if (nbClient < nbClientPServer) |
---|
181 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
182 | << "nbClient < nbClientPServer"); |
---|
183 | if ((nbClient % nbClientPServer) != 0) |
---|
184 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
185 | << " (nbClient % nbClientPServer) != 0 !"); |
---|
186 | if ((nbprocess-nbprocess_used) < (nbClient + nbClient/nbClientPServer)) |
---|
187 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
188 | << " Pas assez de processus disponibles !"); |
---|
189 | if (CXIOSManager::Clients.find(clientName) != CXIOSManager::Clients.end()) |
---|
190 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
191 | << " Un client portant le même nom existe déjà !"); |
---|
192 | |
---|
193 | XIOSClient client = {nbClient, nbClientPServer, entry_point }; |
---|
194 | CXIOSManager::Clients[clientName] = client; |
---|
195 | } |
---|
196 | |
---|
197 | //--------------------------------------------------------------- |
---|
198 | |
---|
199 | StdSize CXIOSManager::GetNbClient(void) |
---|
200 | { |
---|
201 | switch (CXIOSManager::Type) |
---|
202 | { |
---|
203 | case (CLIENT_SERVER): |
---|
204 | { |
---|
205 | StdSize retvalue = 0; |
---|
206 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
207 | xios_map<StdString, XIOSClient>::iterator |
---|
208 | iit = CXIOSManager::Clients.begin(), |
---|
209 | eend = CXIOSManager::Clients.end(); |
---|
210 | |
---|
211 | for (;iit != eend; iit++) |
---|
212 | { |
---|
213 | const StdPairStrClient & elem = *iit; |
---|
214 | retvalue += CXIOSManager::GetNbLocClient(elem.first); |
---|
215 | } |
---|
216 | |
---|
217 | return (retvalue); |
---|
218 | } |
---|
219 | case (CLIENT): |
---|
220 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
221 | case (SERVER): |
---|
222 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Client_Server) - 1); |
---|
223 | default: |
---|
224 | return (0); |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | StdSize CXIOSManager::GetNbLocClient(const StdString & clientName) |
---|
229 | { |
---|
230 | switch (CXIOSManager::Type) |
---|
231 | { |
---|
232 | case (CLIENT_SERVER): |
---|
233 | return (CXIOSManager::Clients[clientName].nbClient); |
---|
234 | case (CLIENT): |
---|
235 | case (SERVER): |
---|
236 | return (CXIOSManager::GetNbClient()); |
---|
237 | default: |
---|
238 | return (0); |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | StdSize CXIOSManager::GetNbServer(void) |
---|
243 | { |
---|
244 | switch (CXIOSManager::Type) |
---|
245 | { |
---|
246 | case (CLIENT_SERVER): |
---|
247 | { |
---|
248 | StdSize retvalue = 0; |
---|
249 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
250 | |
---|
251 | xios_map<StdString, XIOSClient>::iterator |
---|
252 | iit = CXIOSManager::Clients.begin(), |
---|
253 | eend = CXIOSManager::Clients.end(); |
---|
254 | |
---|
255 | for (;iit != eend; iit++) |
---|
256 | { |
---|
257 | const StdPairStrClient & elem = *iit; |
---|
258 | retvalue += CXIOSManager::GetNbLocServer(elem.first); |
---|
259 | } |
---|
260 | |
---|
261 | return (retvalue); |
---|
262 | } |
---|
263 | case (CLIENT): |
---|
264 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
265 | case (SERVER): |
---|
266 | return (1); |
---|
267 | default: |
---|
268 | return (0); |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | StdSize CXIOSManager::GetNbLocServer(const StdString & clientName) |
---|
273 | { |
---|
274 | switch (CXIOSManager::Type) |
---|
275 | { |
---|
276 | case (CLIENT_SERVER): |
---|
277 | return (CXIOSManager::Clients[clientName].nbClient / |
---|
278 | CXIOSManager::Clients[clientName].nbClientPServer); |
---|
279 | case (CLIENT): |
---|
280 | case (SERVER): |
---|
281 | return (CXIOSManager::GetNbServer()); |
---|
282 | default: |
---|
283 | return (0); |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | ///-------------------------------------------------------------- |
---|
288 | |
---|
289 | } // namespace xmlioserver |
---|