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; |
---|
36 | comm::MPIComm CXIOSManager::Comm_Client_Server; |
---|
37 | comm::MPIComm CXIOSManager::Comm_Server; |
---|
38 | |
---|
39 | boost::unordered_map<StdString, CXIOSManager::XIOSClient> CXIOSManager::Clients; |
---|
40 | |
---|
41 | ///-------------------------------------------------------------- |
---|
42 | |
---|
43 | void CXIOSManager::RunClientServer(comm::MPIComm comm_client_server) |
---|
44 | { |
---|
45 | using namespace comm; |
---|
46 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
47 | |
---|
48 | MPIComm world_comm = CMPIManager::GetCommWorld(); |
---|
49 | MPIGroup world_group = CMPIManager::GetGroupWorld(); |
---|
50 | |
---|
51 | if (CMPIManager::IsMaster(comm_client_server)) |
---|
52 | { |
---|
53 | std::cout << " *************************************** " << std::endl |
---|
54 | << " * XmlIOServer (Client/Server) * " << std::endl |
---|
55 | << " *************************************** " << std::endl; |
---|
56 | std::cout << " > Nombre de processus : " |
---|
57 | << CMPIManager::GetCommSize(comm_client_server) << std::endl; |
---|
58 | std::cout << " > Nombre de processus utilisés : " |
---|
59 | << (CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer()) << std::endl; |
---|
60 | std::cout << " > Nombre de clients : " |
---|
61 | << CXIOSManager::GetNbClient() << std::endl; |
---|
62 | std::cout << " > Nombre de serveurs : " |
---|
63 | << CXIOSManager::GetNbServer() << std::endl; |
---|
64 | |
---|
65 | BOOST_FOREACH(StdPairStrClient elem, CXIOSManager::Clients) |
---|
66 | std::cout << " - " << elem.first |
---|
67 | << " > nombre de clients : " << elem.second.nbClient |
---|
68 | << " , nombre de clients par serveur : " << elem.second.nbClientPServer |
---|
69 | << " , nombre de serveurs : " << elem.second.nbClient/elem.second.nbClientPServer |
---|
70 | << std::endl; |
---|
71 | |
---|
72 | std::cout << " *************************************** " << std::endl; |
---|
73 | } |
---|
74 | |
---|
75 | comm::CMPIManager::Barrier(); |
---|
76 | StdSize start = 0, end = 0; |
---|
77 | BOOST_FOREACH(StdPairStrClient elem, CXIOSManager::Clients) |
---|
78 | { |
---|
79 | MPIComm comm_client = 0, comm_client_grp = 0; comm_client_server = 0; |
---|
80 | |
---|
81 | int currentRank = CMPIManager::GetCommRank(); |
---|
82 | StdString clientName = elem.first; |
---|
83 | StdSize nbClient = elem.second.nbClient; |
---|
84 | StdSize nbClientPServer = elem.second.nbClientPServer; |
---|
85 | StdSize nbServer = elem.second.nbClient/elem.second.nbClientPServer; |
---|
86 | StdSize totalproc = nbClient + nbServer; |
---|
87 | |
---|
88 | for (StdSize i = 0; i<nbServer; i++) |
---|
89 | { |
---|
90 | end = start + nbClientPServer; |
---|
91 | // Pas encore implémenté (interface de gestion de groupe/communicateur buggée) |
---|
92 | start = start + nbClientPServer + 1; |
---|
93 | } |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | void CXIOSManager::RunClient(comm::MPIComm comm_client) |
---|
98 | { |
---|
99 | (CXIOSManager::Clients.begin()->second.entry)(comm_client, comm_client, comm_client); |
---|
100 | } |
---|
101 | |
---|
102 | //--------------------------------------------------------------- |
---|
103 | |
---|
104 | void CXIOSManager::AddClient(StdString clientName, StdSize nbClient, StdSize nbClientPServer, |
---|
105 | void (*entry_point)(comm::MPIComm, comm::MPIComm, comm::MPIComm)) |
---|
106 | { |
---|
107 | StdSize nbprocess = comm::CMPIManager::GetCommSize(comm::CMPIManager::GetCommWorld()); |
---|
108 | StdSize nbprocess_used = CXIOSManager::GetNbClient() + CXIOSManager::GetNbServer(); |
---|
109 | |
---|
110 | if (nbClient < nbClientPServer) |
---|
111 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
112 | << "nbClient < nbClientPServer"); |
---|
113 | if ((nbClient % nbClientPServer) != 0) |
---|
114 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
115 | << " (nbClient % nbClientPServer) != 0 !"); |
---|
116 | if ((nbprocess-nbprocess_used) < (nbClient + nbClient/nbClientPServer)) |
---|
117 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
118 | << " Pas assez de processus disponibles !"); |
---|
119 | if (CXIOSManager::Clients.find(clientName) != CXIOSManager::Clients.end()) |
---|
120 | ERROR("CXIOSManager::AddClient(clientName, nbClient, nbClientPServer, entry_point)", |
---|
121 | << " Un client portant le même nom existe déjà !"); |
---|
122 | |
---|
123 | XIOSClient client = {nbClient, nbClientPServer, entry_point }; |
---|
124 | CXIOSManager::Clients[clientName] = client; |
---|
125 | } |
---|
126 | |
---|
127 | //--------------------------------------------------------------- |
---|
128 | |
---|
129 | StdSize CXIOSManager::GetNbClient(void) |
---|
130 | { |
---|
131 | switch (CXIOSManager::Type) |
---|
132 | { |
---|
133 | case (CLIENT_SERVER): |
---|
134 | { |
---|
135 | StdSize retvalue = 0; |
---|
136 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
137 | BOOST_FOREACH(StdPairStrClient elem, CXIOSManager::Clients) |
---|
138 | retvalue += CXIOSManager::GetNbLocClient(elem.first); |
---|
139 | return (retvalue); |
---|
140 | } |
---|
141 | case (CLIENT): |
---|
142 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
143 | case (SERVER): |
---|
144 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Client_Server) - 1); |
---|
145 | default: |
---|
146 | return (0); |
---|
147 | } |
---|
148 | } |
---|
149 | |
---|
150 | StdSize CXIOSManager::GetNbLocClient(const StdString & clientName) |
---|
151 | { |
---|
152 | switch (CXIOSManager::Type) |
---|
153 | { |
---|
154 | case (CLIENT_SERVER): |
---|
155 | return (CXIOSManager::Clients[clientName].nbClient); |
---|
156 | case (CLIENT): |
---|
157 | case (SERVER): |
---|
158 | return (CXIOSManager::GetNbClient()); |
---|
159 | default: |
---|
160 | return (0); |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | StdSize CXIOSManager::GetNbServer(void) |
---|
165 | { |
---|
166 | switch (CXIOSManager::Type) |
---|
167 | { |
---|
168 | case (CLIENT_SERVER): |
---|
169 | { |
---|
170 | StdSize retvalue = 0; |
---|
171 | typedef std::pair<StdString, XIOSClient> StdPairStrClient; |
---|
172 | BOOST_FOREACH(StdPairStrClient elem, CXIOSManager::Clients) |
---|
173 | retvalue += CXIOSManager::GetNbLocServer(elem.first); |
---|
174 | return (retvalue); |
---|
175 | } |
---|
176 | case (CLIENT): |
---|
177 | return (comm::CMPIManager::GetCommSize(CXIOSManager::Comm_Server)); |
---|
178 | case (SERVER): |
---|
179 | return (1); |
---|
180 | default: |
---|
181 | return (0); |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | StdSize CXIOSManager::GetNbLocServer(const StdString & clientName) |
---|
186 | { |
---|
187 | switch (CXIOSManager::Type) |
---|
188 | { |
---|
189 | case (CLIENT_SERVER): |
---|
190 | return (CXIOSManager::Clients[clientName].nbClient / |
---|
191 | CXIOSManager::Clients[clientName].nbClientPServer); |
---|
192 | case (CLIENT): |
---|
193 | case (SERVER): |
---|
194 | return (CXIOSManager::GetNbServer()); |
---|
195 | default: |
---|
196 | return (0); |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | ///-------------------------------------------------------------- |
---|
201 | |
---|
202 | } // namespace xmlioserver |
---|