1 | #include "axis.hpp" |
---|
2 | |
---|
3 | #include "attribute_template.hpp" |
---|
4 | #include "object_template.hpp" |
---|
5 | #include "group_template.hpp" |
---|
6 | #include "message.hpp" |
---|
7 | #include "type.hpp" |
---|
8 | #include "context.hpp" |
---|
9 | #include "context_client.hpp" |
---|
10 | #include "xios_spl.hpp" |
---|
11 | #include "inverse_axis.hpp" |
---|
12 | #include "zoom_axis.hpp" |
---|
13 | #include "interpolate_axis.hpp" |
---|
14 | #include "server_distribution_description.hpp" |
---|
15 | #include "client_server_mapping_distributed.hpp" |
---|
16 | |
---|
17 | namespace xios { |
---|
18 | |
---|
19 | /// ////////////////////// Définitions ////////////////////// /// |
---|
20 | |
---|
21 | CAxis::CAxis(void) |
---|
22 | : CObjectTemplate<CAxis>() |
---|
23 | , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject(), areClientAttributesChecked_(false) |
---|
24 | , isDistributed_(false), hasBounds_(false) |
---|
25 | , transformationMap_(), global_zoom_begin(0), global_zoom_size(0) |
---|
26 | { |
---|
27 | } |
---|
28 | |
---|
29 | CAxis::CAxis(const StdString & id) |
---|
30 | : CObjectTemplate<CAxis>(id) |
---|
31 | , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject(), areClientAttributesChecked_(false) |
---|
32 | , isDistributed_(false), hasBounds_(false) |
---|
33 | , transformationMap_(), global_zoom_begin(0), global_zoom_size(0) |
---|
34 | { |
---|
35 | } |
---|
36 | |
---|
37 | CAxis::~CAxis(void) |
---|
38 | { /* Ne rien faire de plus */ } |
---|
39 | |
---|
40 | ///--------------------------------------------------------------- |
---|
41 | |
---|
42 | const std::set<StdString> & CAxis::getRelFiles(void) const |
---|
43 | { |
---|
44 | return (this->relFiles); |
---|
45 | } |
---|
46 | |
---|
47 | bool CAxis::IsWritten(const StdString & filename) const |
---|
48 | { |
---|
49 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
50 | } |
---|
51 | |
---|
52 | bool CAxis::isDistributed(void) const |
---|
53 | { |
---|
54 | return isDistributed_; |
---|
55 | } |
---|
56 | |
---|
57 | void CAxis::addRelFile(const StdString & filename) |
---|
58 | { |
---|
59 | this->relFiles.insert(filename); |
---|
60 | } |
---|
61 | |
---|
62 | //---------------------------------------------------------------- |
---|
63 | |
---|
64 | StdString CAxis::GetName(void) { return (StdString("axis")); } |
---|
65 | StdString CAxis::GetDefName(void){ return (CAxis::GetName()); } |
---|
66 | ENodeType CAxis::GetType(void) { return (eAxis); } |
---|
67 | |
---|
68 | //---------------------------------------------------------------- |
---|
69 | |
---|
70 | CAxis* CAxis::createAxis() |
---|
71 | { |
---|
72 | CAxis* axis = CAxisGroup::get("axis_definition")->createChild(); |
---|
73 | return axis; |
---|
74 | } |
---|
75 | |
---|
76 | void CAxis::checkAttributes(void) |
---|
77 | { |
---|
78 | if (this->size.isEmpty()) |
---|
79 | ERROR("CAxis::checkAttributes(void)", |
---|
80 | << "Attribute <size> of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be specified"); |
---|
81 | StdSize size = this->size.getValue(); |
---|
82 | |
---|
83 | isDistributed_ = !this->ibegin.isEmpty() || !this->ni.isEmpty(); |
---|
84 | |
---|
85 | if (!this->ibegin.isEmpty()) |
---|
86 | { |
---|
87 | StdSize ibegin = this->ibegin.getValue(); |
---|
88 | if ((ibegin < 0) || (ibegin > size-1)) |
---|
89 | ERROR("CAxis::checkAttributes(void)", |
---|
90 | << "Attribute <ibegin> of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be non-negative and smaller than size-1"); |
---|
91 | } |
---|
92 | else this->ibegin.setValue(0); |
---|
93 | |
---|
94 | if (!this->ni.isEmpty()) |
---|
95 | { |
---|
96 | StdSize ni = this->ni.getValue(); |
---|
97 | if ((ni < 0) || (ni > size)) |
---|
98 | ERROR("CAxis::checkAttributes(void)", |
---|
99 | << "Attribute <ni> of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be non-negative and smaller than size"); |
---|
100 | } |
---|
101 | else this->ni.setValue(size); |
---|
102 | |
---|
103 | StdSize true_size = value.numElements(); |
---|
104 | if (this->ni.getValue() != true_size) |
---|
105 | ERROR("CAxis::checkAttributes(void)", |
---|
106 | << "The array \'value\' of axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] has a different size that the one defined by the \'size\' attribute"); |
---|
107 | |
---|
108 | this->checkData(); |
---|
109 | this->checkZoom(); |
---|
110 | this->checkMask(); |
---|
111 | this->checkBounds(); |
---|
112 | } |
---|
113 | |
---|
114 | void CAxis::checkData() |
---|
115 | { |
---|
116 | if (data_begin.isEmpty()) data_begin.setValue(0); |
---|
117 | if (!data_n.isEmpty() && data_n.getValue() <= 0) |
---|
118 | { |
---|
119 | ERROR("CAxis::checkData(void)", |
---|
120 | << "Data dimension is negative (data_n)."); |
---|
121 | } |
---|
122 | else if (data_n.isEmpty()) |
---|
123 | data_n.setValue(ni.getValue()); |
---|
124 | |
---|
125 | if (data_index.isEmpty()) |
---|
126 | { |
---|
127 | int dn = data_n.getValue(); |
---|
128 | data_index.resize(dn); |
---|
129 | for (int i = 0; i < dn; ++i) data_index(i) = (i+1); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | void CAxis::checkZoom(void) |
---|
134 | { |
---|
135 | if (0 == global_zoom_size) global_zoom_size = this->size.getValue(); |
---|
136 | } |
---|
137 | |
---|
138 | void CAxis::checkMask() |
---|
139 | { |
---|
140 | int begin_mask = 0, |
---|
141 | end_mask = ni.getValue()-1; |
---|
142 | |
---|
143 | if (!zoom_begin.isEmpty()) |
---|
144 | { |
---|
145 | int zoom_end = zoom_begin.getValue() + zoom_size.getValue() - 1; |
---|
146 | |
---|
147 | begin_mask = std::max(ibegin.getValue(), zoom_begin.getValue()); |
---|
148 | end_mask = std::min(ibegin.getValue() + ni.getValue()-1, zoom_end); |
---|
149 | |
---|
150 | begin_mask -= ibegin.getValue(); |
---|
151 | end_mask -= ibegin.getValue(); |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | if (!mask.isEmpty()) |
---|
156 | { |
---|
157 | if (mask.extent(0) != ni) |
---|
158 | ERROR("CAxis::checkMask(void)", |
---|
159 | << "the mask has not the same size than the local axis" << endl |
---|
160 | << "Local size is " << ni << "x" << endl |
---|
161 | << "Mask size is " << mask.extent(0) << "x"); |
---|
162 | for (int i = 0; i < ni; ++i) |
---|
163 | { |
---|
164 | if (i < begin_mask && i > end_mask) mask(i) = false; |
---|
165 | } |
---|
166 | } |
---|
167 | else // (!mask.hasValue()) |
---|
168 | { // Si aucun masque n'est défini, |
---|
169 | // on en crée un nouveau qui valide l'intégralité du domaine. |
---|
170 | mask.resize(ni); |
---|
171 | for (int i = 0; i < ni.getValue(); ++i) |
---|
172 | { |
---|
173 | if (i >= begin_mask && i <= end_mask) |
---|
174 | mask(i) = true; |
---|
175 | else mask(i) = false; |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | |
---|
180 | void CAxis::checkBounds() |
---|
181 | { |
---|
182 | if (!bounds.isEmpty()) |
---|
183 | { |
---|
184 | if (bounds.extent(0) != ni || bounds.extent(1) != 2) |
---|
185 | ERROR("CAxis::checkAttributes(void)", |
---|
186 | << "The bounds array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension axis size x 2" << endl |
---|
187 | << "Axis size is " << ni << endl |
---|
188 | << "Bounds size is "<< bounds.extent(0) << " x " << bounds.extent(1)); |
---|
189 | hasBounds_ = true; |
---|
190 | } |
---|
191 | else hasBounds_ = false; |
---|
192 | } |
---|
193 | |
---|
194 | |
---|
195 | bool CAxis::dispatchEvent(CEventServer& event) |
---|
196 | { |
---|
197 | if (SuperClass::dispatchEvent(event)) return true; |
---|
198 | else |
---|
199 | { |
---|
200 | switch(event.type) |
---|
201 | { |
---|
202 | case EVENT_ID_SERVER_ATTRIBUT : |
---|
203 | recvServerAttribut(event); |
---|
204 | return true; |
---|
205 | break; |
---|
206 | case EVENT_ID_INDEX: |
---|
207 | recvIndex(event); |
---|
208 | return true; |
---|
209 | break; |
---|
210 | case EVENT_ID_DISTRIBUTED_VALUE: |
---|
211 | recvDistributedValue(event); |
---|
212 | return true; |
---|
213 | break; |
---|
214 | case EVENT_ID_NON_DISTRIBUTED_VALUE: |
---|
215 | recvNonDistributedValue(event); |
---|
216 | return true; |
---|
217 | break; |
---|
218 | default : |
---|
219 | ERROR("bool CContext::dispatchEvent(CEventServer& event)", |
---|
220 | << "Unknown Event"); |
---|
221 | return false; |
---|
222 | } |
---|
223 | } |
---|
224 | } |
---|
225 | |
---|
226 | void CAxis::checkAttributesOnClient(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
227 | CServerDistributionDescription::ServerDistributionType distType) |
---|
228 | { |
---|
229 | if (this->areClientAttributesChecked_) return; |
---|
230 | |
---|
231 | this->checkAttributes(); |
---|
232 | |
---|
233 | this->areClientAttributesChecked_ = true; |
---|
234 | } |
---|
235 | |
---|
236 | // Send all checked attributes to server |
---|
237 | void CAxis::sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
238 | CServerDistributionDescription::ServerDistributionType distType) |
---|
239 | { |
---|
240 | if (!this->areClientAttributesChecked_) checkAttributesOnClient(globalDim, |
---|
241 | orderPositionInGrid, |
---|
242 | distType); |
---|
243 | CContext* context = CContext::getCurrent(); |
---|
244 | |
---|
245 | if (this->isChecked) return; |
---|
246 | if (context->hasClient) |
---|
247 | { |
---|
248 | sendServerAttribut(globalDim, orderPositionInGrid, distType); |
---|
249 | sendValue(); |
---|
250 | } |
---|
251 | |
---|
252 | this->isChecked = true; |
---|
253 | } |
---|
254 | |
---|
255 | void CAxis::sendValue() |
---|
256 | { |
---|
257 | if (ni.getValue() == size.getValue()) |
---|
258 | { |
---|
259 | sendNonDistributedValue(); |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | computeConnectedServer(); |
---|
264 | sendDistributedValue(); |
---|
265 | } |
---|
266 | } |
---|
267 | |
---|
268 | void CAxis::computeConnectedServer() |
---|
269 | { |
---|
270 | CContext* context = CContext::getCurrent(); |
---|
271 | CContextClient* client = context->client; |
---|
272 | int nbServer = client->serverSize; |
---|
273 | int range, clientSize = client->clientSize; |
---|
274 | |
---|
275 | CArray<size_t,1> globalIndexAxis(ni); |
---|
276 | size_t ibegin = this->ibegin.getValue(); |
---|
277 | int zoom_end = global_zoom_begin+global_zoom_size-1; |
---|
278 | std::vector<size_t> globalAxisZoom; |
---|
279 | for (size_t idx = 0; idx < ni; ++idx) |
---|
280 | { |
---|
281 | size_t globalIndex = ibegin + idx; |
---|
282 | globalIndexAxis(idx) = globalIndex; |
---|
283 | if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) globalAxisZoom.push_back(globalIndex); |
---|
284 | } |
---|
285 | |
---|
286 | std::vector<int> nGlobDomain(1); |
---|
287 | nGlobDomain[0] = size.getValue(); |
---|
288 | |
---|
289 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
290 | for (int i = 0; i < nGlobDomain.size(); ++i) globalSizeIndex *= nGlobDomain[i]; |
---|
291 | indexBegin = 0; |
---|
292 | for (int i = 0; i < clientSize; ++i) |
---|
293 | { |
---|
294 | range = globalSizeIndex / clientSize; |
---|
295 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
296 | if (i == client->clientRank) break; |
---|
297 | indexBegin += range; |
---|
298 | } |
---|
299 | indexEnd = indexBegin + range - 1; |
---|
300 | |
---|
301 | CServerDistributionDescription serverDescription(nGlobDomain); |
---|
302 | serverDescription.computeServerGlobalIndexInRange(nbServer, std::make_pair<size_t,size_t>(indexBegin, indexEnd)); |
---|
303 | CClientServerMappingDistributed clientServerMap(serverDescription.getGlobalIndexRange(), client->intraComm); |
---|
304 | clientServerMap.computeServerIndexMapping(globalIndexAxis); |
---|
305 | const std::map<int, std::vector<size_t> >& globalIndexAxisOnServer = clientServerMap.getGlobalIndexOnServer(); |
---|
306 | |
---|
307 | std::map<int, std::vector<size_t> >::const_iterator it = globalIndexAxisOnServer.begin(), |
---|
308 | ite = globalIndexAxisOnServer.end(); |
---|
309 | std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), |
---|
310 | iteVec = (globalAxisZoom).end(); |
---|
311 | indSrv_.clear(); |
---|
312 | for (; it != ite; ++it) |
---|
313 | { |
---|
314 | int rank = it->first; |
---|
315 | const std::vector<size_t>& globalIndexTmp = it->second; |
---|
316 | int nb = globalIndexTmp.size(); |
---|
317 | |
---|
318 | for (int i = 0; i < nb; ++i) |
---|
319 | { |
---|
320 | if (std::binary_search(itbVec, iteVec, globalIndexTmp[i])) |
---|
321 | { |
---|
322 | indSrv_[rank].push_back(globalIndexTmp[i]); |
---|
323 | } |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | connectedServerRank_.clear(); |
---|
328 | for (it = globalIndexAxisOnServer.begin(); it != ite; ++it) { |
---|
329 | connectedServerRank_.push_back(it->first); |
---|
330 | } |
---|
331 | |
---|
332 | if (!indSrv_.empty()) |
---|
333 | { |
---|
334 | connectedServerRank_.clear(); |
---|
335 | for (it = indSrv_.begin(); it != indSrv_.end(); ++it) |
---|
336 | connectedServerRank_.push_back(it->first); |
---|
337 | } |
---|
338 | nbConnectedClients_ = clientServerMap.computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
339 | |
---|
340 | } |
---|
341 | |
---|
342 | void CAxis::sendNonDistributedValue() |
---|
343 | { |
---|
344 | CContext* context = CContext::getCurrent(); |
---|
345 | CContextClient* client = context->client; |
---|
346 | CEventClient event(getType(),EVENT_ID_NON_DISTRIBUTED_VALUE); |
---|
347 | |
---|
348 | int zoom_end = global_zoom_begin+global_zoom_size-1; |
---|
349 | int nb =0; |
---|
350 | for (size_t idx = 0; idx < ni; ++idx) |
---|
351 | { |
---|
352 | size_t globalIndex = ibegin + idx; |
---|
353 | if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) ++nb; |
---|
354 | } |
---|
355 | |
---|
356 | CArray<double,1> val(nb); |
---|
357 | nb = 0; |
---|
358 | for (size_t idx = 0; idx < ni; ++idx) |
---|
359 | { |
---|
360 | size_t globalIndex = ibegin + idx; |
---|
361 | if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) |
---|
362 | { |
---|
363 | val(nb) = value(idx); |
---|
364 | ++nb; |
---|
365 | } |
---|
366 | } |
---|
367 | |
---|
368 | if (client->isServerLeader()) |
---|
369 | { |
---|
370 | std::list<CMessage> msgs; |
---|
371 | |
---|
372 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
373 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
374 | { |
---|
375 | // Use const int to ensure CMessage holds a copy of the value instead of just a reference |
---|
376 | msgs.push_back(CMessage()); |
---|
377 | CMessage& msg = msgs.back(); |
---|
378 | msg << this->getId(); |
---|
379 | msg << val; |
---|
380 | event.push(*itRank,1,msg); |
---|
381 | } |
---|
382 | client->sendEvent(event); |
---|
383 | } |
---|
384 | else client->sendEvent(event); |
---|
385 | } |
---|
386 | |
---|
387 | void CAxis::sendDistributedValue(void) |
---|
388 | { |
---|
389 | int ns, n, i, j, ind, nv, idx; |
---|
390 | CContext* context = CContext::getCurrent(); |
---|
391 | CContextClient* client=context->client; |
---|
392 | |
---|
393 | // send value for each connected server |
---|
394 | CEventClient eventIndex(getType(), EVENT_ID_INDEX); |
---|
395 | CEventClient eventVal(getType(), EVENT_ID_DISTRIBUTED_VALUE); |
---|
396 | |
---|
397 | list<CMessage> list_msgsIndex, list_msgsVal; |
---|
398 | list<CArray<int,1> > list_indi; |
---|
399 | list<CArray<double,1> > list_val; |
---|
400 | list<CArray<double,2> > list_bounds; |
---|
401 | |
---|
402 | std::map<int, std::vector<size_t> >::const_iterator it, iteMap; |
---|
403 | iteMap = indSrv_.end(); |
---|
404 | for (int k = 0; k < connectedServerRank_.size(); ++k) |
---|
405 | { |
---|
406 | int nbData = 0; |
---|
407 | int rank = connectedServerRank_[k]; |
---|
408 | it = indSrv_.find(rank); |
---|
409 | if (iteMap != it) |
---|
410 | nbData = it->second.size(); |
---|
411 | |
---|
412 | list_indi.push_back(CArray<int,1>(nbData)); |
---|
413 | list_val.push_back(CArray<double,1>(nbData)); |
---|
414 | |
---|
415 | if (hasBounds_) |
---|
416 | { |
---|
417 | list_bounds.push_back(CArray<double,2>(2,nbData)); |
---|
418 | } |
---|
419 | |
---|
420 | CArray<int,1>& indi = list_indi.back(); |
---|
421 | CArray<double,1>& val = list_val.back(); |
---|
422 | |
---|
423 | for (n = 0; n < nbData; ++n) |
---|
424 | { |
---|
425 | idx = static_cast<int>(it->second[n]); |
---|
426 | ind = idx - ibegin; |
---|
427 | |
---|
428 | val(n) = value(ind); |
---|
429 | indi(n) = idx; |
---|
430 | |
---|
431 | if (hasBounds_) |
---|
432 | { |
---|
433 | CArray<double,2>& boundsVal = list_bounds.back(); |
---|
434 | boundsVal(0, n) = bounds(0,n); |
---|
435 | boundsVal(1, n) = bounds(1,n); |
---|
436 | } |
---|
437 | } |
---|
438 | |
---|
439 | list_msgsIndex.push_back(CMessage()); |
---|
440 | list_msgsIndex.back() << this->getId() << list_indi.back(); |
---|
441 | |
---|
442 | list_msgsVal.push_back(CMessage()); |
---|
443 | list_msgsVal.back() << this->getId() << list_val.back(); |
---|
444 | |
---|
445 | if (hasBounds_) |
---|
446 | { |
---|
447 | list_msgsVal.back() << list_bounds.back(); |
---|
448 | } |
---|
449 | |
---|
450 | eventIndex.push(rank, nbConnectedClients_[rank], list_msgsIndex.back()); |
---|
451 | eventVal.push(rank, nbConnectedClients_[rank], list_msgsVal.back()); |
---|
452 | } |
---|
453 | |
---|
454 | client->sendEvent(eventIndex); |
---|
455 | client->sendEvent(eventVal); |
---|
456 | } |
---|
457 | |
---|
458 | void CAxis::recvIndex(CEventServer& event) |
---|
459 | { |
---|
460 | list<CEventServer::SSubEvent>::iterator it; |
---|
461 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
462 | { |
---|
463 | CBufferIn* buffer = it->buffer; |
---|
464 | string domainId; |
---|
465 | *buffer >> domainId; |
---|
466 | get(domainId)->recvIndex(it->rank, *buffer); |
---|
467 | } |
---|
468 | } |
---|
469 | |
---|
470 | void CAxis::recvIndex(int rank, CBufferIn& buffer) |
---|
471 | { |
---|
472 | buffer >> indiSrv_[rank]; |
---|
473 | } |
---|
474 | |
---|
475 | void CAxis::recvDistributedValue(CEventServer& event) |
---|
476 | { |
---|
477 | list<CEventServer::SSubEvent>::iterator it; |
---|
478 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
479 | { |
---|
480 | CBufferIn* buffer = it->buffer; |
---|
481 | string domainId; |
---|
482 | *buffer >> domainId; |
---|
483 | get(domainId)->recvDistributedValue(it->rank, *buffer); |
---|
484 | } |
---|
485 | } |
---|
486 | |
---|
487 | void CAxis::recvDistributedValue(int rank, CBufferIn& buffer) |
---|
488 | { |
---|
489 | CArray<int,1> &indi = indiSrv_[rank]; |
---|
490 | CArray<double,1> val; |
---|
491 | CArray<double,2> boundsVal; |
---|
492 | |
---|
493 | buffer >> val; |
---|
494 | if (hasBounds_) buffer >> boundsVal; |
---|
495 | |
---|
496 | int i, j, ind_srv; |
---|
497 | for (int ind = 0; ind < indi.numElements(); ++ind) |
---|
498 | { |
---|
499 | i = indi(ind); |
---|
500 | ind_srv = i - zoom_begin_srv; |
---|
501 | value_srv(ind_srv) = val(ind); |
---|
502 | if (hasBounds_) |
---|
503 | { |
---|
504 | bound_srv(0,ind_srv) = boundsVal(0, ind); |
---|
505 | bound_srv(1,ind_srv) = boundsVal(1, ind); |
---|
506 | } |
---|
507 | } |
---|
508 | } |
---|
509 | |
---|
510 | void CAxis::recvNonDistributedValue(CEventServer& event) |
---|
511 | { |
---|
512 | list<CEventServer::SSubEvent>::iterator it; |
---|
513 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
514 | { |
---|
515 | CBufferIn* buffer = it->buffer; |
---|
516 | string domainId; |
---|
517 | *buffer >> domainId; |
---|
518 | get(domainId)->recvNonDistributedValue(it->rank, *buffer); |
---|
519 | } |
---|
520 | } |
---|
521 | |
---|
522 | void CAxis::recvNonDistributedValue(int rank, CBufferIn& buffer) |
---|
523 | { |
---|
524 | CArray<double,1> val; |
---|
525 | buffer >> val; |
---|
526 | |
---|
527 | for (int ind = 0; ind < val.numElements(); ++ind) |
---|
528 | { |
---|
529 | value_srv(ind) = val(ind); |
---|
530 | if (hasBounds_) |
---|
531 | { |
---|
532 | bound_srv(0,ind) = bounds(0,ind); |
---|
533 | bound_srv(1,ind) = bounds(1,ind); |
---|
534 | } |
---|
535 | } |
---|
536 | } |
---|
537 | |
---|
538 | void CAxis::sendServerAttribut(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
539 | CServerDistributionDescription::ServerDistributionType distType) |
---|
540 | { |
---|
541 | CContext* context = CContext::getCurrent(); |
---|
542 | CContextClient* client = context->client; |
---|
543 | |
---|
544 | CServerDistributionDescription serverDescription(globalDim); |
---|
545 | |
---|
546 | int nbServer = client->serverSize; |
---|
547 | |
---|
548 | serverDescription.computeServerDistribution(nbServer, false, distType); |
---|
549 | std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); |
---|
550 | std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); |
---|
551 | |
---|
552 | CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT); |
---|
553 | if (client->isServerLeader()) |
---|
554 | { |
---|
555 | std::list<CMessage> msgs; |
---|
556 | |
---|
557 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
558 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
559 | { |
---|
560 | // Use const int to ensure CMessage holds a copy of the value instead of just a reference |
---|
561 | const int begin = serverIndexBegin[*itRank][orderPositionInGrid]; |
---|
562 | const int ni = serverDimensionSizes[*itRank][orderPositionInGrid]; |
---|
563 | const int end = begin + ni - 1; |
---|
564 | |
---|
565 | msgs.push_back(CMessage()); |
---|
566 | CMessage& msg = msgs.back(); |
---|
567 | msg << this->getId(); |
---|
568 | msg << ni << begin << end; |
---|
569 | msg << global_zoom_begin << global_zoom_size; |
---|
570 | |
---|
571 | event.push(*itRank,1,msg); |
---|
572 | } |
---|
573 | client->sendEvent(event); |
---|
574 | } |
---|
575 | else client->sendEvent(event); |
---|
576 | } |
---|
577 | |
---|
578 | void CAxis::recvServerAttribut(CEventServer& event) |
---|
579 | { |
---|
580 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
581 | string axisId; |
---|
582 | *buffer >> axisId; |
---|
583 | get(axisId)->recvServerAttribut(*buffer); |
---|
584 | } |
---|
585 | |
---|
586 | void CAxis::recvServerAttribut(CBufferIn& buffer) |
---|
587 | { |
---|
588 | int ni_srv, begin_srv, end_srv, global_zoom_begin_tmp, global_zoom_size_tmp; |
---|
589 | |
---|
590 | buffer>>ni_srv>>begin_srv>>end_srv>>global_zoom_begin_tmp>>global_zoom_size_tmp; |
---|
591 | global_zoom_begin = global_zoom_begin_tmp; |
---|
592 | global_zoom_size = global_zoom_size_tmp; |
---|
593 | int global_zoom_end = global_zoom_begin + global_zoom_size - 1; |
---|
594 | |
---|
595 | zoom_begin_srv = global_zoom_begin > begin_srv ? global_zoom_begin : begin_srv ; |
---|
596 | zoom_end_srv = global_zoom_end < end_srv ? global_zoom_end : end_srv ; |
---|
597 | zoom_size_srv = zoom_end_srv - zoom_begin_srv + 1; |
---|
598 | |
---|
599 | if (zoom_size_srv<=0) |
---|
600 | { |
---|
601 | zoom_begin_srv = 0; zoom_end_srv = 0; zoom_size_srv = 0; |
---|
602 | } |
---|
603 | |
---|
604 | if (size == ni) |
---|
605 | { |
---|
606 | zoom_begin_srv = global_zoom_begin; |
---|
607 | zoom_end_srv = global_zoom_end; //zoom_end; |
---|
608 | zoom_size_srv = zoom_end_srv - zoom_begin_srv + 1; |
---|
609 | } |
---|
610 | value_srv.resize(zoom_size_srv); |
---|
611 | bound_srv.resize(2,zoom_size_srv); |
---|
612 | } |
---|
613 | |
---|
614 | bool CAxis::hasTransformation() |
---|
615 | { |
---|
616 | return (!transformationMap_.empty()); |
---|
617 | } |
---|
618 | |
---|
619 | void CAxis::setTransformations(const TransMapTypes& axisTrans) |
---|
620 | { |
---|
621 | transformationMap_ = axisTrans; |
---|
622 | } |
---|
623 | |
---|
624 | CAxis::TransMapTypes CAxis::getAllTransformations(void) |
---|
625 | { |
---|
626 | return transformationMap_; |
---|
627 | } |
---|
628 | |
---|
629 | /*! |
---|
630 | Check the validity of all transformations applied on axis |
---|
631 | This functions is called AFTER all inherited attributes are solved |
---|
632 | */ |
---|
633 | void CAxis::checkTransformations() |
---|
634 | { |
---|
635 | TransMapTypes::const_iterator itb = transformationMap_.begin(), it, |
---|
636 | ite = transformationMap_.end(); |
---|
637 | for (it = itb; it != ite; ++it) |
---|
638 | { |
---|
639 | (it->second)->checkValid(this); |
---|
640 | } |
---|
641 | } |
---|
642 | |
---|
643 | void CAxis::solveInheritanceTransformation() |
---|
644 | { |
---|
645 | if (this->hasTransformation()) return; |
---|
646 | |
---|
647 | std::vector<CAxis*> refAxis; |
---|
648 | CAxis* refer_sptr; |
---|
649 | CAxis* refer_ptr = this; |
---|
650 | while (refer_ptr->hasDirectAxisReference()) |
---|
651 | { |
---|
652 | refAxis.push_back(refer_ptr); |
---|
653 | refer_sptr = refer_ptr->getDirectAxisReference(); |
---|
654 | refer_ptr = refer_sptr; |
---|
655 | if (refer_ptr->hasTransformation()) break; |
---|
656 | } |
---|
657 | |
---|
658 | if (refer_ptr->hasTransformation()) |
---|
659 | for (int idx = 0; idx < refAxis.size(); ++idx) |
---|
660 | refAxis[idx]->setTransformations(refer_ptr->getAllTransformations()); |
---|
661 | } |
---|
662 | |
---|
663 | void CAxis::parse(xml::CXMLNode & node) |
---|
664 | { |
---|
665 | SuperClass::parse(node); |
---|
666 | |
---|
667 | if (node.goToChildElement()) |
---|
668 | { |
---|
669 | StdString inverseAxisDefRoot("inverse_axis_definition"); |
---|
670 | StdString inverse("inverse_axis"); |
---|
671 | StdString zoomAxisDefRoot("zoom_axis_definition"); |
---|
672 | StdString zoom("zoom_axis"); |
---|
673 | StdString interpAxisDefRoot("interpolate_axis_definition"); |
---|
674 | StdString interp("interpolate_axis"); |
---|
675 | do |
---|
676 | { |
---|
677 | if (node.getElementName() == inverse) { |
---|
678 | CInverseAxis* tmp = (CInverseAxisGroup::get(inverseAxisDefRoot))->createChild(); |
---|
679 | tmp->parse(node); |
---|
680 | transformationMap_.push_back(std::make_pair(TRANS_INVERSE_AXIS,tmp)); |
---|
681 | } else if (node.getElementName() == zoom) { |
---|
682 | CZoomAxis* tmp = (CZoomAxisGroup::get(zoomAxisDefRoot))->createChild(); |
---|
683 | tmp->parse(node); |
---|
684 | transformationMap_.push_back(std::make_pair(TRANS_ZOOM_AXIS,tmp)); |
---|
685 | } |
---|
686 | else if (node.getElementName() == interp) { |
---|
687 | CInterpolateAxis* tmp = (CInterpolateAxisGroup::get(interpAxisDefRoot))->createChild(); |
---|
688 | tmp->parse(node); |
---|
689 | transformationMap_.push_back(std::make_pair(TRANS_INTERPOLATE_AXIS,tmp)); |
---|
690 | } |
---|
691 | } while (node.goToNextElement()) ; |
---|
692 | node.goToParentElement(); |
---|
693 | } |
---|
694 | } |
---|
695 | |
---|
696 | DEFINE_REF_FUNC(Axis,axis) |
---|
697 | |
---|
698 | ///--------------------------------------------------------------- |
---|
699 | |
---|
700 | } // namespace xios |
---|