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