1 | #include "server.hpp" |
---|
2 | |
---|
3 | #include "tree_manager.hpp" |
---|
4 | #include "duration.hpp" |
---|
5 | #include "data_treatment.hpp" |
---|
6 | #include "group_template_impl.hpp" |
---|
7 | |
---|
8 | namespace xmlioserver { |
---|
9 | namespace comm { |
---|
10 | |
---|
11 | /// ////////////////////// Définitions ////////////////////// /// |
---|
12 | |
---|
13 | CServer::CServer(MPIComm comm_client_server) |
---|
14 | : blist(comm_client_server) |
---|
15 | { /* Ne rien faire de plus */ } |
---|
16 | |
---|
17 | CServer::~CServer(void) |
---|
18 | { /* Ne rien faire de plus */ } |
---|
19 | |
---|
20 | ///-------------------------------------------------------------- |
---|
21 | |
---|
22 | boost::shared_ptr<CServer> CServer::Server; |
---|
23 | |
---|
24 | ///-------------------------------------------------------------- |
---|
25 | |
---|
26 | const CBufferList & CServer::getBufferList(void) const |
---|
27 | { |
---|
28 | return (this->blist); |
---|
29 | } |
---|
30 | |
---|
31 | ///-------------------------------------------------------------- |
---|
32 | |
---|
33 | boost::shared_ptr<CServer> CServer::CreateServer(MPIComm comm_client_server) |
---|
34 | { |
---|
35 | if (CServer::Server.get() == NULL) |
---|
36 | CServer::Server = boost::shared_ptr<CServer>(new CServer(comm_client_server)); |
---|
37 | return (CServer::GetServer()); |
---|
38 | } |
---|
39 | |
---|
40 | ///-------------------------------------------------------------- |
---|
41 | |
---|
42 | boost::shared_ptr<CServer> CServer::GetServer(void) |
---|
43 | { |
---|
44 | return (CServer::Server); |
---|
45 | } |
---|
46 | |
---|
47 | //--------------------------------------------------------------- |
---|
48 | |
---|
49 | void CServer::run(void) |
---|
50 | { |
---|
51 | while (this->blist.recvRequests()) |
---|
52 | { |
---|
53 | long int managerId = -1, methodId = -1, nbargs = -1; |
---|
54 | long int managerId_= -1, methodId_ = -1, nbargs_ = -1; |
---|
55 | std::vector<CLinearBuffer> lbuffer; |
---|
56 | this->blist.getRequests(lbuffer); |
---|
57 | |
---|
58 | for (StdSize i = 0; i < lbuffer.size(); i++) |
---|
59 | { |
---|
60 | lbuffer[i].getRequestInfos(0, managerId, methodId, nbargs); |
---|
61 | if (((managerId_ != managerId) || (methodId_ != methodId) || (nbargs_ != nbargs)) && (i != 0 )) |
---|
62 | { |
---|
63 | //std::cout << managerId_ << "<->" << managerId << std::endl |
---|
64 | // << methodId_ << "<->" << methodId << std::endl |
---|
65 | // << nbargs_ << "<->" << nbargs << std::endl; |
---|
66 | ERROR("CServer::run(void)", << "[" << i << "] Les requêtes ne sont pas synchronisées !"); |
---|
67 | } |
---|
68 | managerId_ = managerId; |
---|
69 | methodId_ = methodId; |
---|
70 | nbargs_ = nbargs; |
---|
71 | } |
---|
72 | |
---|
73 | if (managerId == 0) |
---|
74 | { |
---|
75 | switch(methodId) |
---|
76 | { |
---|
77 | case (0) : |
---|
78 | this->initialize(); |
---|
79 | continue; |
---|
80 | case (1) : |
---|
81 | this->finalize(); |
---|
82 | return; |
---|
83 | default : |
---|
84 | ERROR("CServer::run(void)", |
---|
85 | << "[ managerId = " << managerId << ", " |
---|
86 | << "[ methodId = " << methodId << ", " |
---|
87 | << "[ nbargs = " << nbargs << "] " |
---|
88 | << " Methode inconnue !"); |
---|
89 | } |
---|
90 | } |
---|
91 | if (managerId == 1) |
---|
92 | { |
---|
93 | switch(methodId) |
---|
94 | { |
---|
95 | case (0) : |
---|
96 | this->setContext(lbuffer); |
---|
97 | continue; |
---|
98 | case (1) : |
---|
99 | this->updateCalendar(lbuffer); |
---|
100 | continue; |
---|
101 | case (2) : |
---|
102 | this->setTimestep(lbuffer); |
---|
103 | continue; |
---|
104 | default : |
---|
105 | ERROR("CServer::run(void)", |
---|
106 | << "[ managerId = " << managerId << ", " |
---|
107 | << "[ methodId = " << methodId << ", " |
---|
108 | << "[ nbargs = " << nbargs << "] " |
---|
109 | << " Methode inconnue !"); |
---|
110 | } |
---|
111 | } |
---|
112 | if (managerId == 2) |
---|
113 | { |
---|
114 | switch(methodId) |
---|
115 | { |
---|
116 | case (0) : |
---|
117 | this->writeData(lbuffer, 4); |
---|
118 | continue; |
---|
119 | case (1) : |
---|
120 | this->writeData(lbuffer, 8); |
---|
121 | continue; |
---|
122 | default : |
---|
123 | ERROR("CServer::run(void)", |
---|
124 | << "[ managerId = " << managerId << ", " |
---|
125 | << "[ methodId = " << methodId << ", " |
---|
126 | << "[ nbargs = " << nbargs << "] " |
---|
127 | << " Methode inconnue !"); |
---|
128 | } |
---|
129 | } |
---|
130 | ERROR("CServer::run(void)", |
---|
131 | << "[ managerId = " << managerId << ", " |
---|
132 | << "[ methodId = " << methodId << ", " |
---|
133 | << "[ nbargs = " << nbargs << "] " |
---|
134 | << " Methode inconnue !"); |
---|
135 | } |
---|
136 | } |
---|
137 | |
---|
138 | //-------------------------------------------------------------- |
---|
139 | |
---|
140 | void CServer::initialize(void) // manager 0, method 0 |
---|
141 | { |
---|
142 | std::cout << "initialize" << std::endl; |
---|
143 | } |
---|
144 | |
---|
145 | //-------------------------------------------------------------- |
---|
146 | |
---|
147 | void CServer::finalize(void) // manager 0, method 1 |
---|
148 | { |
---|
149 | std::cout << "finalize" << std::endl; |
---|
150 | comm::CMPIManager::Barrier(); |
---|
151 | } |
---|
152 | |
---|
153 | //-------------------------------------------------------------- |
---|
154 | |
---|
155 | void CServer::setTimestep(const std::vector<CLinearBuffer> & buffer)// manager 1, method 2 |
---|
156 | { |
---|
157 | boost::shared_ptr<CContext> context = |
---|
158 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
159 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
160 | |
---|
161 | StdString durationstr; |
---|
162 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
163 | { |
---|
164 | StdString durationstr_ = buffer[i].getString(3); |
---|
165 | if (durationstr.compare(durationstr_) != 0 && (i != 0)) |
---|
166 | { |
---|
167 | ERROR("CServer::setTimestep(const std::vector<CLinearBuffer> & buffer)", |
---|
168 | << "[ durationstr 1 = " << durationstr << ", " |
---|
169 | << "[ durationstr 2 = " << durationstr_ << "] " |
---|
170 | << " Modification de timestep désynchronisé !"); |
---|
171 | } |
---|
172 | else durationstr = durationstr_; |
---|
173 | |
---|
174 | } |
---|
175 | std::cout << "setTimestep called " << durationstr << std::endl; |
---|
176 | dtreat->set_timestep(date::CDuration::FromString(durationstr)); |
---|
177 | } |
---|
178 | |
---|
179 | //-------------------------------------------------------------- |
---|
180 | |
---|
181 | void CServer::setContext(const std::vector<CLinearBuffer> & buffer) // manager 1, method 0 |
---|
182 | { |
---|
183 | StdString contextId; |
---|
184 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
185 | { |
---|
186 | StdString contextId_ = buffer[i].getString(3); |
---|
187 | if (contextId.compare(contextId_) != 0 && (i != 0)) |
---|
188 | { |
---|
189 | ERROR("CServer::setContext(const std::vector<CLinearBuffer> & buffer)", |
---|
190 | << "[ contextId 1 = " << contextId << ", " |
---|
191 | << "[ contextId 2 = " << contextId_ << "] " |
---|
192 | << " Changement de contexte désynchronisé !"); |
---|
193 | } |
---|
194 | else contextId = contextId_; |
---|
195 | |
---|
196 | } |
---|
197 | std::cout << "setContext called " << contextId << std::endl; |
---|
198 | CTreeManager::SetCurrentContextId(contextId); |
---|
199 | } |
---|
200 | |
---|
201 | //-------------------------------------------------------------- |
---|
202 | |
---|
203 | void CServer::updateCalendar(const std::vector<CLinearBuffer> & buffer) // manager 1, method 1 |
---|
204 | { |
---|
205 | boost::shared_ptr<CContext> context = |
---|
206 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
207 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
208 | |
---|
209 | int timestep = -1; |
---|
210 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
211 | { |
---|
212 | int timestep_ = buffer[i].getInt(3); |
---|
213 | if ((timestep_ != timestep) && (i != 0)) |
---|
214 | { |
---|
215 | ERROR("CServer::updateCalendar(const std::vector<CLinearBuffer> & buffer)", |
---|
216 | << "[ timestep 1 = " << timestep << ", " |
---|
217 | << "[ timestep 2 = " << timestep_ << "] " |
---|
218 | << " Mise à jour du calendrier désynchronisée !"); |
---|
219 | } |
---|
220 | else timestep = timestep_; |
---|
221 | } |
---|
222 | std::cout << "updateCalendar called " << timestep <<std::endl; |
---|
223 | dtreat->update_calendar(timestep); |
---|
224 | } |
---|
225 | |
---|
226 | //-------------------------------------------------------------- |
---|
227 | |
---|
228 | void CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec) // manager 2, method 0 - 1 |
---|
229 | { |
---|
230 | boost::shared_ptr<CContext> context = |
---|
231 | CObjectFactory::GetObject<CContext>(CObjectFactory::GetCurrentContextId()); |
---|
232 | boost::shared_ptr<data::CDataTreatment> dtreat = context->getDataTreatment(); |
---|
233 | |
---|
234 | StdString fieldId, fileId; |
---|
235 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
236 | { |
---|
237 | StdString fieldId_ = buffer[i].getString(3); |
---|
238 | StdString fileId_ = buffer[i].getString(4); |
---|
239 | |
---|
240 | if (fieldId.compare(fieldId_) != 0 && (i != 0)) |
---|
241 | { |
---|
242 | ERROR("CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec)", |
---|
243 | << "[fieldId 1 = " << fieldId << ", " |
---|
244 | << " fieldId 2 = " << fieldId_ << "] " |
---|
245 | << " Ecriture des données désynchronisée !"); |
---|
246 | } |
---|
247 | else fieldId = fieldId_; |
---|
248 | |
---|
249 | if (fileId.compare(fileId_) != 0 && (i != 0)) |
---|
250 | { |
---|
251 | ERROR("CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec)", |
---|
252 | << "[fileId 1 = " << fileId << ", " |
---|
253 | << " fileId 2 = " << fileId_ << "] " |
---|
254 | << " Ecriture des données désynchronisée !"); |
---|
255 | } |
---|
256 | else fileId = fileId_; |
---|
257 | } |
---|
258 | |
---|
259 | if (prec == 4) |
---|
260 | { |
---|
261 | std::deque<ARRAY(float, 1)> dataArray(buffer.size()); |
---|
262 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
263 | dataArray[i] = buffer[i].getFloatArray(5); |
---|
264 | std::cout << "writeData called (float) " << fieldId << ", " << dataArray[0] << std::endl; |
---|
265 | // Jamais atteint car les données sont transférées en tant que double |
---|
266 | return; |
---|
267 | } |
---|
268 | else if (prec == 8) |
---|
269 | { |
---|
270 | std::deque<ARRAY(double, 1)> dataArray(buffer.size()); |
---|
271 | for (StdSize i = 0; i < buffer.size(); i++) |
---|
272 | dataArray[i] = buffer[i].getDoubleArray(5); |
---|
273 | std::cout << "writeData called (double) " << fieldId << ", " << dataArray[0] << std::endl; |
---|
274 | dtreat->write_data(fieldId, fileId, dataArray); |
---|
275 | return; |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | ERROR("CServer::writeData(const std::vector<CLinearBuffer> & buffer, int prec)", |
---|
280 | << " Précision des données invalide !"); |
---|
281 | } |
---|
282 | } |
---|
283 | |
---|
284 | ///-------------------------------------------------------------- |
---|
285 | |
---|
286 | |
---|
287 | } // namespace comm |
---|
288 | } // namespace xmlioserver |
---|