[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" |
---|
[676] | 10 | #include "context_server.hpp" |
---|
[591] | 11 | #include "xios_spl.hpp" |
---|
[630] | 12 | #include "inverse_axis.hpp" |
---|
| 13 | #include "zoom_axis.hpp" |
---|
| 14 | #include "interpolate_axis.hpp" |
---|
[633] | 15 | #include "server_distribution_description.hpp" |
---|
| 16 | #include "client_server_mapping_distributed.hpp" |
---|
[676] | 17 | #include "distribution_client.hpp" |
---|
[219] | 18 | |
---|
[335] | 19 | namespace xios { |
---|
[540] | 20 | |
---|
[219] | 21 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 22 | |
---|
| 23 | CAxis::CAxis(void) |
---|
| 24 | : CObjectTemplate<CAxis>() |
---|
[771] | 25 | , CAxisAttributes(), isChecked(false), relFiles(), areClientAttributesChecked_(false) |
---|
[927] | 26 | , isClientAfterTransformationChecked(false) |
---|
[676] | 27 | , isDistributed_(false), hasBounds_(false), isCompressible_(false) |
---|
| 28 | , numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
[821] | 29 | , transformationMap_(), hasValue(false) |
---|
[621] | 30 | { |
---|
| 31 | } |
---|
[219] | 32 | |
---|
| 33 | CAxis::CAxis(const StdString & id) |
---|
| 34 | : CObjectTemplate<CAxis>(id) |
---|
[771] | 35 | , CAxisAttributes(), isChecked(false), relFiles(), areClientAttributesChecked_(false) |
---|
[927] | 36 | , isClientAfterTransformationChecked(false) |
---|
[676] | 37 | , isDistributed_(false), hasBounds_(false), isCompressible_(false) |
---|
| 38 | , numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
[821] | 39 | , transformationMap_(), hasValue(false) |
---|
[621] | 40 | { |
---|
| 41 | } |
---|
[219] | 42 | |
---|
| 43 | CAxis::~CAxis(void) |
---|
| 44 | { /* Ne rien faire de plus */ } |
---|
| 45 | |
---|
[836] | 46 | std::map<StdString, ETranformationType> CAxis::transformationMapList_ = std::map<StdString, ETranformationType>(); |
---|
| 47 | bool CAxis::dummyTransformationMapList_ = CAxis::initializeTransformationMap(CAxis::transformationMapList_); |
---|
| 48 | bool CAxis::initializeTransformationMap(std::map<StdString, ETranformationType>& m) |
---|
| 49 | { |
---|
| 50 | m["zoom_axis"] = TRANS_ZOOM_AXIS; |
---|
| 51 | m["interpolate_axis"] = TRANS_INTERPOLATE_AXIS; |
---|
| 52 | m["inverse_axis"] = TRANS_INVERSE_AXIS; |
---|
[895] | 53 | m["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_AXIS; |
---|
| 54 | m["extract_domain"] = TRANS_EXTRACT_DOMAIN_TO_AXIS; |
---|
[836] | 55 | } |
---|
| 56 | |
---|
[219] | 57 | ///--------------------------------------------------------------- |
---|
| 58 | |
---|
| 59 | const std::set<StdString> & CAxis::getRelFiles(void) const |
---|
| 60 | { |
---|
| 61 | return (this->relFiles); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | bool CAxis::IsWritten(const StdString & filename) const |
---|
| 65 | { |
---|
| 66 | return (this->relFiles.find(filename) != this->relFiles.end()); |
---|
| 67 | } |
---|
| 68 | |
---|
[676] | 69 | bool CAxis::isWrittenCompressed(const StdString& filename) const |
---|
| 70 | { |
---|
| 71 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 72 | } |
---|
| 73 | |
---|
[594] | 74 | bool CAxis::isDistributed(void) const |
---|
| 75 | { |
---|
| 76 | return isDistributed_; |
---|
| 77 | } |
---|
| 78 | |
---|
[676] | 79 | /*! |
---|
| 80 | * Test whether the data defined on the axis can be outputted in a compressed way. |
---|
[742] | 81 | * |
---|
[676] | 82 | * \return true if and only if a mask was defined for this axis |
---|
| 83 | */ |
---|
| 84 | bool CAxis::isCompressible(void) const |
---|
| 85 | { |
---|
| 86 | return isCompressible_; |
---|
| 87 | } |
---|
| 88 | |
---|
[219] | 89 | void CAxis::addRelFile(const StdString & filename) |
---|
| 90 | { |
---|
| 91 | this->relFiles.insert(filename); |
---|
| 92 | } |
---|
| 93 | |
---|
[676] | 94 | void CAxis::addRelFileCompressed(const StdString& filename) |
---|
| 95 | { |
---|
| 96 | this->relFilesCompressed.insert(filename); |
---|
| 97 | } |
---|
| 98 | |
---|
[219] | 99 | //---------------------------------------------------------------- |
---|
| 100 | |
---|
[676] | 101 | const std::vector<int>& CAxis::getIndexesToWrite(void) const |
---|
| 102 | { |
---|
| 103 | return indexesToWrite; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | /*! |
---|
| 107 | Returns the number of indexes written by each server. |
---|
| 108 | \return the number of indexes written by each server |
---|
| 109 | */ |
---|
| 110 | int CAxis::getNumberWrittenIndexes() const |
---|
| 111 | { |
---|
| 112 | return numberWrittenIndexes_; |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | /*! |
---|
| 116 | Returns the total number of indexes written by the servers. |
---|
| 117 | \return the total number of indexes written by the servers |
---|
| 118 | */ |
---|
| 119 | int CAxis::getTotalNumberWrittenIndexes() const |
---|
| 120 | { |
---|
| 121 | return totalNumberWrittenIndexes_; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | /*! |
---|
| 125 | Returns the offset of indexes written by each server. |
---|
| 126 | \return the offset of indexes written by each server |
---|
| 127 | */ |
---|
| 128 | int CAxis::getOffsetWrittenIndexes() const |
---|
| 129 | { |
---|
| 130 | return offsetWrittenIndexes_; |
---|
| 131 | } |
---|
| 132 | |
---|
[1025] | 133 | /*! |
---|
| 134 | Returns the start of indexes written by each server. |
---|
| 135 | \return the start of indexes written by each server |
---|
| 136 | */ |
---|
| 137 | int CAxis::getStartWriteIndex() const |
---|
| 138 | { |
---|
| 139 | return start_write_index_; |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | /*! |
---|
| 143 | Returns the count of indexes written by each server. |
---|
| 144 | \return the count of indexes written by each server |
---|
| 145 | */ |
---|
| 146 | int CAxis::getCountWriteIndex() const |
---|
| 147 | { |
---|
| 148 | return count_write_index_; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | /*! |
---|
| 152 | Returns the local data written by each server. |
---|
| 153 | */ |
---|
| 154 | int CAxis::getLocalWriteSize() const |
---|
| 155 | { |
---|
| 156 | return local_write_size_; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | /*! |
---|
| 160 | Returns the global data written by all server. |
---|
| 161 | */ |
---|
| 162 | int CAxis::getGlobalWriteSize() const |
---|
| 163 | { |
---|
| 164 | return global_write_size_; |
---|
| 165 | } |
---|
| 166 | |
---|
[676] | 167 | //---------------------------------------------------------------- |
---|
| 168 | |
---|
[731] | 169 | /*! |
---|
| 170 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 171 | * |
---|
| 172 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 173 | */ |
---|
| 174 | std::map<int, StdSize> CAxis::getAttributesBufferSize() |
---|
| 175 | { |
---|
| 176 | CContextClient* client = CContext::getCurrent()->client; |
---|
| 177 | |
---|
| 178 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(); |
---|
| 179 | |
---|
| 180 | bool isNonDistributed = (n == n_glo); |
---|
| 181 | |
---|
| 182 | if (client->isServerLeader()) |
---|
| 183 | { |
---|
| 184 | // size estimation for sendServerAttribut |
---|
| 185 | size_t size = 6 * sizeof(size_t); |
---|
| 186 | // size estimation for sendNonDistributedValue |
---|
| 187 | if (isNonDistributed) |
---|
| 188 | size = std::max(size, CArray<double,1>::size(n_glo) + (isCompressible_ ? CArray<int,1>::size(n_glo) : 0)); |
---|
| 189 | size += CEventClient::headerSize + getId().size() + sizeof(size_t); |
---|
| 190 | |
---|
| 191 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 192 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 193 | { |
---|
| 194 | if (size > attributesSizes[*itRank]) |
---|
| 195 | attributesSizes[*itRank] = size; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | |
---|
| 199 | if (!isNonDistributed) |
---|
| 200 | { |
---|
| 201 | // size estimation for sendDistributedValue |
---|
[1025] | 202 | boost::unordered_map<int, vector<size_t> >::const_iterator it, ite = indSrv_.end(); |
---|
[731] | 203 | for (it = indSrv_.begin(); it != ite; ++it) |
---|
| 204 | { |
---|
| 205 | size_t sizeIndexEvent = CArray<int,1>::size(it->second.size()); |
---|
| 206 | if (isCompressible_) |
---|
| 207 | sizeIndexEvent += CArray<int,1>::size(indWrittenSrv_[it->first].size()); |
---|
| 208 | |
---|
| 209 | size_t sizeValEvent = CArray<double,1>::size(it->second.size()); |
---|
| 210 | if (hasBounds_) |
---|
[754] | 211 | sizeValEvent += CArray<double,2>::size(2 * it->second.size()); |
---|
[731] | 212 | |
---|
| 213 | size_t size = CEventClient::headerSize + getId().size() + sizeof(size_t) + std::max(sizeIndexEvent, sizeValEvent); |
---|
| 214 | if (size > attributesSizes[it->first]) |
---|
| 215 | attributesSizes[it->first] = size; |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | return attributesSizes; |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | //---------------------------------------------------------------- |
---|
| 223 | |
---|
[219] | 224 | StdString CAxis::GetName(void) { return (StdString("axis")); } |
---|
| 225 | StdString CAxis::GetDefName(void){ return (CAxis::GetName()); } |
---|
| 226 | ENodeType CAxis::GetType(void) { return (eAxis); } |
---|
| 227 | |
---|
| 228 | //---------------------------------------------------------------- |
---|
| 229 | |
---|
[622] | 230 | CAxis* CAxis::createAxis() |
---|
| 231 | { |
---|
| 232 | CAxis* axis = CAxisGroup::get("axis_definition")->createChild(); |
---|
| 233 | return axis; |
---|
| 234 | } |
---|
| 235 | |
---|
[775] | 236 | void CAxis::fillInValues(const CArray<double,1>& values) |
---|
| 237 | { |
---|
| 238 | this->value = values; |
---|
| 239 | } |
---|
| 240 | |
---|
[219] | 241 | void CAxis::checkAttributes(void) |
---|
| 242 | { |
---|
[666] | 243 | if (this->n_glo.isEmpty()) |
---|
[679] | 244 | ERROR("CAxis::checkAttributes(void)", |
---|
| 245 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 246 | << "The axis is wrongly defined, attribute 'n_glo' must be specified"); |
---|
[666] | 247 | StdSize size = this->n_glo.getValue(); |
---|
[540] | 248 | |
---|
[970] | 249 | if (!this->index.isEmpty()) |
---|
[551] | 250 | { |
---|
[970] | 251 | if (n.isEmpty()) n = index.numElements(); |
---|
| 252 | |
---|
| 253 | // It's not so correct but if begin is not the first value of index |
---|
| 254 | // then data on the local axis has user-defined distribution. In this case, begin has no meaning. |
---|
| 255 | if (begin.isEmpty()) begin = index(0); |
---|
[551] | 256 | } |
---|
[970] | 257 | else |
---|
| 258 | { |
---|
| 259 | if (!this->begin.isEmpty()) |
---|
| 260 | { |
---|
| 261 | if (begin < 0 || begin > size - 1) |
---|
| 262 | ERROR("CAxis::checkAttributes(void)", |
---|
| 263 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 264 | << "The axis is wrongly defined, attribute 'begin' (" << begin.getValue() << ") must be non-negative and smaller than size-1 (" << size - 1 << ")."); |
---|
| 265 | } |
---|
| 266 | else this->begin.setValue(0); |
---|
[551] | 267 | |
---|
[970] | 268 | if (!this->n.isEmpty()) |
---|
| 269 | { |
---|
| 270 | if (n < 0 || n > size) |
---|
| 271 | ERROR("CAxis::checkAttributes(void)", |
---|
| 272 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 273 | << "The axis is wrongly defined, attribute 'n' (" << n.getValue() << ") must be non-negative and smaller than size (" << size << ")."); |
---|
| 274 | } |
---|
| 275 | else this->n.setValue(size); |
---|
| 276 | |
---|
| 277 | { |
---|
| 278 | index.resize(n); |
---|
| 279 | for (int i = 0; i < n; ++i) index(i) = i+begin; |
---|
| 280 | } |
---|
[551] | 281 | } |
---|
[624] | 282 | |
---|
[816] | 283 | if (!this->value.isEmpty()) |
---|
| 284 | { |
---|
| 285 | StdSize true_size = value.numElements(); |
---|
| 286 | if (this->n.getValue() != true_size) |
---|
| 287 | ERROR("CAxis::checkAttributes(void)", |
---|
| 288 | << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " |
---|
| 289 | << "The axis is wrongly defined, attribute 'value' has a different size (" << true_size << ") than the one defined by the \'size\' attribute (" << n.getValue() << ")."); |
---|
| 290 | this->hasValue = true; |
---|
| 291 | } |
---|
[219] | 292 | |
---|
[551] | 293 | this->checkData(); |
---|
[633] | 294 | this->checkZoom(); |
---|
[551] | 295 | this->checkMask(); |
---|
[633] | 296 | this->checkBounds(); |
---|
[970] | 297 | |
---|
| 298 | isDistributed_ = (!this->begin.isEmpty() && !this->n.isEmpty() && (this->begin + this->n < this->n_glo)) || |
---|
| 299 | (!this->n.isEmpty() && (this->n != this->n_glo)); |
---|
[219] | 300 | } |
---|
| 301 | |
---|
[551] | 302 | void CAxis::checkData() |
---|
| 303 | { |
---|
| 304 | if (data_begin.isEmpty()) data_begin.setValue(0); |
---|
[679] | 305 | |
---|
| 306 | if (data_n.isEmpty()) |
---|
[551] | 307 | { |
---|
[679] | 308 | data_n.setValue(n); |
---|
| 309 | } |
---|
| 310 | else if (data_n.getValue() < 0) |
---|
| 311 | { |
---|
[551] | 312 | ERROR("CAxis::checkData(void)", |
---|
[679] | 313 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 314 | << "The data size should be strictly positive ('data_n' = " << data_n.getValue() << ")."); |
---|
[551] | 315 | } |
---|
| 316 | |
---|
| 317 | if (data_index.isEmpty()) |
---|
| 318 | { |
---|
[679] | 319 | data_index.resize(data_n); |
---|
| 320 | for (int i = 0; i < data_n; ++i) data_index(i) = i; |
---|
[551] | 321 | } |
---|
| 322 | } |
---|
| 323 | |
---|
[631] | 324 | void CAxis::checkZoom(void) |
---|
| 325 | { |
---|
[821] | 326 | if (global_zoom_begin.isEmpty()) global_zoom_begin.setValue(0); |
---|
| 327 | if (global_zoom_n.isEmpty()) global_zoom_n.setValue(n_glo.getValue()); |
---|
[1025] | 328 | if (zoom_index.isEmpty()) |
---|
| 329 | { |
---|
| 330 | zoom_index.setValue(index.getValue()); |
---|
| 331 | } |
---|
[631] | 332 | } |
---|
[567] | 333 | |
---|
[551] | 334 | void CAxis::checkMask() |
---|
| 335 | { |
---|
| 336 | if (!mask.isEmpty()) |
---|
| 337 | { |
---|
[666] | 338 | if (mask.extent(0) != n) |
---|
[679] | 339 | ERROR("CAxis::checkMask(void)", |
---|
| 340 | << "[ id = " << this->getId() << " , context = '" << CObjectFactory::GetCurrentContextId() << " ] " |
---|
| 341 | << "The mask does not have the same size as the local domain." << std::endl |
---|
| 342 | << "Local size is " << n.getValue() << "." << std::endl |
---|
| 343 | << "Mask size is " << mask.extent(0) << "."); |
---|
[551] | 344 | } |
---|
[679] | 345 | else // (mask.isEmpty()) |
---|
| 346 | { // If no mask was defined, we create a default one without any masked point. |
---|
[666] | 347 | mask.resize(n); |
---|
[679] | 348 | for (int i = 0; i < n; ++i) |
---|
[551] | 349 | { |
---|
[666] | 350 | mask(i) = true; |
---|
[551] | 351 | } |
---|
| 352 | } |
---|
| 353 | } |
---|
| 354 | |
---|
[633] | 355 | void CAxis::checkBounds() |
---|
| 356 | { |
---|
| 357 | if (!bounds.isEmpty()) |
---|
| 358 | { |
---|
[713] | 359 | if (bounds.extent(0) != 2 || bounds.extent(1) != n) |
---|
| 360 | ERROR("CAxis::checkAttributes(void)", |
---|
| 361 | << "The bounds array of the axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] must be of dimension 2 x axis size." << std::endl |
---|
| 362 | << "Axis size is " << n.getValue() << "." << std::endl |
---|
| 363 | << "Bounds size is "<< bounds.extent(0) << " x " << bounds.extent(1) << "."); |
---|
[633] | 364 | hasBounds_ = true; |
---|
| 365 | } |
---|
| 366 | else hasBounds_ = false; |
---|
| 367 | } |
---|
| 368 | |
---|
[676] | 369 | void CAxis::checkEligibilityForCompressedOutput() |
---|
| 370 | { |
---|
| 371 | // We don't check if the mask is valid here, just if a mask has been defined at this point. |
---|
| 372 | isCompressible_ = !mask.isEmpty(); |
---|
| 373 | } |
---|
[633] | 374 | |
---|
[567] | 375 | bool CAxis::dispatchEvent(CEventServer& event) |
---|
| 376 | { |
---|
[595] | 377 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[567] | 378 | else |
---|
| 379 | { |
---|
| 380 | switch(event.type) |
---|
| 381 | { |
---|
[1025] | 382 | // case EVENT_ID_SERVER_ATTRIBUT : |
---|
| 383 | // recvServerAttribut(event); |
---|
| 384 | // return true; |
---|
| 385 | // break; |
---|
| 386 | // case EVENT_ID_INDEX: |
---|
| 387 | // recvIndex(event); |
---|
| 388 | // return true; |
---|
| 389 | // break; |
---|
| 390 | case EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES: |
---|
| 391 | recvNonDistributedAttributes(event); |
---|
[633] | 392 | return true; |
---|
| 393 | break; |
---|
[1025] | 394 | case EVENT_ID_DISTRIBUTED_ATTRIBUTES: |
---|
| 395 | recvDistributedAttributes(event); |
---|
[633] | 396 | return true; |
---|
| 397 | break; |
---|
[567] | 398 | default : |
---|
[679] | 399 | ERROR("bool CAxis::dispatchEvent(CEventServer& event)", |
---|
[595] | 400 | << "Unknown Event"); |
---|
| 401 | return false; |
---|
[567] | 402 | } |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | |
---|
[742] | 406 | void CAxis::checkAttributesOnClient() |
---|
[567] | 407 | { |
---|
| 408 | if (this->areClientAttributesChecked_) return; |
---|
[595] | 409 | |
---|
[567] | 410 | this->checkAttributes(); |
---|
| 411 | |
---|
| 412 | this->areClientAttributesChecked_ = true; |
---|
| 413 | } |
---|
| 414 | |
---|
[927] | 415 | void CAxis::checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 416 | CServerDistributionDescription::ServerDistributionType distType) |
---|
| 417 | { |
---|
| 418 | CContext* context=CContext::getCurrent() ; |
---|
| 419 | |
---|
| 420 | if (this->isClientAfterTransformationChecked) return; |
---|
| 421 | if (context->hasClient) |
---|
| 422 | { |
---|
[1025] | 423 | if (index.numElements() != n_glo.getValue()) computeConnectedServer(globalDim, orderPositionInGrid, distType); |
---|
[927] | 424 | } |
---|
| 425 | |
---|
| 426 | this->isClientAfterTransformationChecked = true; |
---|
| 427 | } |
---|
| 428 | |
---|
[567] | 429 | // Send all checked attributes to server |
---|
| 430 | void CAxis::sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 431 | CServerDistributionDescription::ServerDistributionType distType) |
---|
| 432 | { |
---|
[742] | 433 | if (!this->areClientAttributesChecked_) checkAttributesOnClient(); |
---|
[927] | 434 | if (!this->isClientAfterTransformationChecked) checkAttributesOnClientAfterTransformation(globalDim, orderPositionInGrid, distType); |
---|
[595] | 435 | CContext* context = CContext::getCurrent(); |
---|
[567] | 436 | |
---|
| 437 | if (this->isChecked) return; |
---|
[1025] | 438 | if (context->hasClient) sendAttributes(); |
---|
[567] | 439 | |
---|
| 440 | this->isChecked = true; |
---|
| 441 | } |
---|
| 442 | |
---|
[1025] | 443 | void CAxis::sendAttributes() |
---|
[633] | 444 | { |
---|
[1025] | 445 | if (index.numElements() == n_glo.getValue()) |
---|
| 446 | sendNonDistributedAttributes(); |
---|
[633] | 447 | else |
---|
[1025] | 448 | sendDistributedAttributes(); |
---|
[633] | 449 | } |
---|
| 450 | |
---|
[815] | 451 | void CAxis::computeConnectedServer(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 452 | CServerDistributionDescription::ServerDistributionType distType) |
---|
[633] | 453 | { |
---|
| 454 | CContext* context = CContext::getCurrent(); |
---|
[1027] | 455 | int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; |
---|
| 456 | for (int i = 0; i < nbSrvPools; ++i) |
---|
[667] | 457 | { |
---|
[1027] | 458 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[i] : context->client; |
---|
| 459 | int nbServer = client->serverSize; |
---|
| 460 | int range, clientSize = client->clientSize; |
---|
| 461 | int rank = client->clientRank; |
---|
[667] | 462 | |
---|
[1027] | 463 | // size_t ni = this->n.getValue(); |
---|
| 464 | // size_t ibegin = this->begin.getValue(); |
---|
| 465 | // size_t zoom_end = global_zoom_begin+global_zoom_n-1; |
---|
| 466 | // size_t nZoomCount = 0; |
---|
| 467 | size_t nbIndex = index.numElements(); |
---|
| 468 | for (size_t idx = 0; idx < nbIndex; ++idx) |
---|
| 469 | { |
---|
| 470 | globalLocalIndexMap_[index(idx)] = idx; |
---|
| 471 | // size_t globalIndex = index(idx); |
---|
| 472 | // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) ++nZoomCount; |
---|
| 473 | } |
---|
[633] | 474 | |
---|
[1027] | 475 | // CArray<size_t,1> globalIndexAxis(nbIndex); |
---|
| 476 | // std::vector<size_t> globalAxisZoom(nZoomCount); |
---|
| 477 | // nZoomCount = 0; |
---|
| 478 | // for (size_t idx = 0; idx < nbIndex; ++idx) |
---|
| 479 | // { |
---|
| 480 | // size_t globalIndex = index(idx); |
---|
| 481 | // globalIndexAxis(idx) = globalIndex; |
---|
| 482 | // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) |
---|
| 483 | // { |
---|
| 484 | // globalAxisZoom[nZoomCount] = globalIndex; |
---|
| 485 | // ++nZoomCount; |
---|
| 486 | // } |
---|
| 487 | // } |
---|
[676] | 488 | |
---|
[1027] | 489 | // std::set<int> writtenInd; |
---|
| 490 | // if (isCompressible_) |
---|
| 491 | // { |
---|
| 492 | // for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 493 | // { |
---|
| 494 | // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); |
---|
[676] | 495 | |
---|
[1027] | 496 | // if (ind >= 0 && ind < ni && mask(ind)) |
---|
| 497 | // { |
---|
| 498 | // ind += ibegin; |
---|
| 499 | // if (ind >= global_zoom_begin && ind <= zoom_end) |
---|
| 500 | // writtenInd.insert(ind); |
---|
| 501 | // } |
---|
| 502 | // } |
---|
| 503 | // } |
---|
[633] | 504 | |
---|
[1027] | 505 | CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer, distType); |
---|
| 506 | int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); |
---|
| 507 | CClientServerMapping::GlobalIndexMap globalIndexAxisOnServer; |
---|
| 508 | if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* |
---|
[815] | 509 | { |
---|
[1027] | 510 | std::vector<int> nGlobAxis(1); |
---|
| 511 | nGlobAxis[0] = n_glo.getValue(); |
---|
| 512 | |
---|
| 513 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 514 | for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; |
---|
| 515 | indexBegin = 0; |
---|
| 516 | if (globalSizeIndex <= clientSize) |
---|
| 517 | { |
---|
| 518 | indexBegin = rank%globalSizeIndex; |
---|
| 519 | indexEnd = indexBegin; |
---|
| 520 | } |
---|
| 521 | else |
---|
| 522 | { |
---|
| 523 | for (int i = 0; i < clientSize; ++i) |
---|
| 524 | { |
---|
| 525 | range = globalSizeIndex / clientSize; |
---|
| 526 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 527 | if (i == client->clientRank) break; |
---|
| 528 | indexBegin += range; |
---|
| 529 | } |
---|
| 530 | indexEnd = indexBegin + range - 1; |
---|
| 531 | } |
---|
| 532 | |
---|
| 533 | CArray<size_t,1> globalIndex(index.numElements()); |
---|
| 534 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 535 | globalIndex(idx) = index(idx); |
---|
| 536 | |
---|
| 537 | CServerDistributionDescription serverDescription(nGlobAxis, nbServer); |
---|
| 538 | serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd)); |
---|
| 539 | CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); |
---|
| 540 | clientServerMap->computeServerIndexMapping(globalIndex); |
---|
| 541 | globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); |
---|
| 542 | delete clientServerMap; |
---|
[815] | 543 | } |
---|
[906] | 544 | else |
---|
| 545 | { |
---|
[1027] | 546 | std::vector<size_t> globalIndexServer(n_glo.getValue()); |
---|
| 547 | for (size_t idx = 0; idx < n_glo.getValue(); ++idx) |
---|
[906] | 548 | { |
---|
[1027] | 549 | globalIndexServer[idx] = idx; |
---|
[906] | 550 | } |
---|
[815] | 551 | |
---|
[1027] | 552 | for (int idx = 0; idx < nbServer; ++idx) |
---|
| 553 | { |
---|
| 554 | globalIndexAxisOnServer[idx] = globalIndexServer; |
---|
| 555 | } |
---|
[815] | 556 | } |
---|
| 557 | |
---|
[1027] | 558 | indSrv_.swap(globalIndexAxisOnServer); |
---|
[633] | 559 | |
---|
[1027] | 560 | // CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexAxisOnServer.begin(), |
---|
| 561 | // ite = globalIndexAxisOnServer.end(); |
---|
| 562 | CClientServerMapping::GlobalIndexMap::const_iterator it = indSrv_.begin(), |
---|
| 563 | ite = indSrv_.end(); |
---|
| 564 | // std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), |
---|
| 565 | // iteVec = (globalAxisZoom).end(); |
---|
| 566 | // indSrv_.clear(); |
---|
| 567 | // indWrittenSrv_.clear(); |
---|
| 568 | // for (; it != ite; ++it) |
---|
| 569 | // { |
---|
| 570 | // int rank = it->first; |
---|
| 571 | // const std::vector<size_t>& globalIndexTmp = it->second; |
---|
| 572 | // int nb = globalIndexTmp.size(); |
---|
[633] | 573 | |
---|
[1027] | 574 | // for (int i = 0; i < nb; ++i) |
---|
| 575 | // { |
---|
| 576 | // if (std::binary_search(itbVec, iteVec, globalIndexTmp[i])) |
---|
| 577 | // { |
---|
| 578 | // indSrv_[rank].push_back(globalIndexTmp[i]); |
---|
| 579 | // } |
---|
[676] | 580 | |
---|
[1027] | 581 | // if (writtenInd.count(globalIndexTmp[i])) |
---|
| 582 | // { |
---|
| 583 | // indWrittenSrv_[rank].push_back(globalIndexTmp[i]); |
---|
| 584 | // } |
---|
| 585 | // } |
---|
| 586 | // } |
---|
[633] | 587 | |
---|
[1027] | 588 | connectedServerRank_.clear(); |
---|
| 589 | for (it = indSrv_.begin(); it != ite; ++it) { |
---|
| 590 | connectedServerRank_.push_back(it->first); |
---|
| 591 | } |
---|
[1025] | 592 | |
---|
[1027] | 593 | // if (!indSrv_.empty()) |
---|
| 594 | // { |
---|
| 595 | // std::map<int, vector<size_t> >::const_iterator itIndSrv = indSrv_.begin(), |
---|
| 596 | // iteIndSrv = indSrv_.end(); |
---|
| 597 | // connectedServerRank_.clear(); |
---|
| 598 | // for (; itIndSrv != iteIndSrv; ++itIndSrv) |
---|
| 599 | // connectedServerRank_.push_back(itIndSrv->first); |
---|
| 600 | // } |
---|
| 601 | nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
[633] | 602 | } |
---|
| 603 | } |
---|
| 604 | |
---|
| 605 | |
---|
[1025] | 606 | // void CAxis::computeConnectedServer(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 607 | // CServerDistributionDescription::ServerDistributionType distType) |
---|
| 608 | // { |
---|
| 609 | // CContext* context = CContext::getCurrent(); |
---|
| 610 | // CContextClient* client = (0 != context->clientPrimServer) ? context->clientPrimServer : context->client; |
---|
| 611 | // int nbServer = client->serverSize; |
---|
| 612 | // int range, clientSize = client->clientSize; |
---|
| 613 | // int rank = client->clientRank; |
---|
[633] | 614 | |
---|
[1025] | 615 | // size_t ni = this->n.getValue(); |
---|
| 616 | // size_t ibegin = this->begin.getValue(); |
---|
| 617 | // size_t zoom_end = global_zoom_begin+global_zoom_n-1; |
---|
| 618 | // size_t nZoomCount = 0; |
---|
| 619 | // size_t nbIndex = index.numElements(); |
---|
| 620 | // for (size_t idx = 0; idx < nbIndex; ++idx) |
---|
| 621 | // { |
---|
| 622 | // size_t globalIndex = index(idx); |
---|
| 623 | // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) ++nZoomCount; |
---|
| 624 | // } |
---|
[676] | 625 | |
---|
[1025] | 626 | // CArray<size_t,1> globalIndexAxis(nbIndex); |
---|
| 627 | // std::vector<size_t> globalAxisZoom(nZoomCount); |
---|
| 628 | // nZoomCount = 0; |
---|
| 629 | // for (size_t idx = 0; idx < nbIndex; ++idx) |
---|
| 630 | // { |
---|
| 631 | // size_t globalIndex = index(idx); |
---|
| 632 | // globalIndexAxis(idx) = globalIndex; |
---|
| 633 | // if (globalIndex >= global_zoom_begin && globalIndex <= zoom_end) |
---|
| 634 | // { |
---|
| 635 | // globalAxisZoom[nZoomCount] = globalIndex; |
---|
| 636 | // ++nZoomCount; |
---|
| 637 | // } |
---|
| 638 | // } |
---|
[676] | 639 | |
---|
[1025] | 640 | // std::set<int> writtenInd; |
---|
| 641 | // if (isCompressible_) |
---|
| 642 | // { |
---|
| 643 | // for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 644 | // { |
---|
| 645 | // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); |
---|
| 646 | |
---|
| 647 | // if (ind >= 0 && ind < ni && mask(ind)) |
---|
| 648 | // { |
---|
| 649 | // ind += ibegin; |
---|
| 650 | // if (ind >= global_zoom_begin && ind <= zoom_end) |
---|
| 651 | // writtenInd.insert(ind); |
---|
| 652 | // } |
---|
| 653 | // } |
---|
| 654 | // } |
---|
| 655 | |
---|
| 656 | // CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer); |
---|
| 657 | // int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); |
---|
| 658 | // CClientServerMapping::GlobalIndexMap globalIndexAxisOnServer; |
---|
| 659 | // if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* |
---|
| 660 | // { |
---|
| 661 | // std::vector<int> nGlobAxis(1); |
---|
| 662 | // nGlobAxis[0] = n_glo.getValue(); |
---|
| 663 | |
---|
| 664 | // size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 665 | // for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; |
---|
| 666 | // indexBegin = 0; |
---|
| 667 | // if (globalSizeIndex <= clientSize) |
---|
| 668 | // { |
---|
| 669 | // indexBegin = rank%globalSizeIndex; |
---|
| 670 | // indexEnd = indexBegin; |
---|
| 671 | // } |
---|
| 672 | // else |
---|
| 673 | // { |
---|
| 674 | // for (int i = 0; i < clientSize; ++i) |
---|
| 675 | // { |
---|
| 676 | // range = globalSizeIndex / clientSize; |
---|
| 677 | // if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 678 | // if (i == client->clientRank) break; |
---|
| 679 | // indexBegin += range; |
---|
| 680 | // } |
---|
| 681 | // indexEnd = indexBegin + range - 1; |
---|
| 682 | // } |
---|
| 683 | |
---|
| 684 | // CServerDistributionDescription serverDescription(nGlobAxis, nbServer); |
---|
| 685 | // serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t,size_t>(indexBegin, indexEnd)); |
---|
| 686 | // CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); |
---|
| 687 | // clientServerMap->computeServerIndexMapping(globalIndexAxis); |
---|
| 688 | // globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); |
---|
| 689 | // delete clientServerMap; |
---|
| 690 | // } |
---|
| 691 | // else |
---|
| 692 | // { |
---|
| 693 | // std::vector<size_t> globalIndexServer(n_glo.getValue()); |
---|
| 694 | // for (size_t idx = 0; idx < n_glo.getValue(); ++idx) |
---|
| 695 | // { |
---|
| 696 | // globalIndexServer[idx] = idx; |
---|
| 697 | // } |
---|
| 698 | |
---|
| 699 | // for (int idx = 0; idx < nbServer; ++idx) |
---|
| 700 | // { |
---|
| 701 | // globalIndexAxisOnServer[idx] = globalIndexServer; |
---|
| 702 | // } |
---|
| 703 | // } |
---|
| 704 | |
---|
| 705 | // CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexAxisOnServer.begin(), |
---|
| 706 | // ite = globalIndexAxisOnServer.end(); |
---|
| 707 | // std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), |
---|
| 708 | // iteVec = (globalAxisZoom).end(); |
---|
| 709 | // indSrv_.clear(); |
---|
| 710 | // indWrittenSrv_.clear(); |
---|
| 711 | // for (; it != ite; ++it) |
---|
| 712 | // { |
---|
| 713 | // int rank = it->first; |
---|
| 714 | // const std::vector<size_t>& globalIndexTmp = it->second; |
---|
| 715 | // int nb = globalIndexTmp.size(); |
---|
| 716 | |
---|
| 717 | // for (int i = 0; i < nb; ++i) |
---|
| 718 | // { |
---|
| 719 | // if (std::binary_search(itbVec, iteVec, globalIndexTmp[i])) |
---|
| 720 | // { |
---|
| 721 | // indSrv_[rank].push_back(globalIndexTmp[i]); |
---|
| 722 | // } |
---|
| 723 | |
---|
| 724 | // if (writtenInd.count(globalIndexTmp[i])) |
---|
| 725 | // { |
---|
| 726 | // indWrittenSrv_[rank].push_back(globalIndexTmp[i]); |
---|
| 727 | // } |
---|
| 728 | // } |
---|
| 729 | // } |
---|
| 730 | |
---|
| 731 | // connectedServerRank_.clear(); |
---|
| 732 | // for (it = globalIndexAxisOnServer.begin(); it != ite; ++it) { |
---|
| 733 | // connectedServerRank_.push_back(it->first); |
---|
| 734 | // } |
---|
| 735 | |
---|
| 736 | // if (!indSrv_.empty()) |
---|
| 737 | // { |
---|
| 738 | // std::map<int, vector<size_t> >::const_iterator itIndSrv = indSrv_.begin(), |
---|
| 739 | // iteIndSrv = indSrv_.end(); |
---|
| 740 | // connectedServerRank_.clear(); |
---|
| 741 | // for (; itIndSrv != iteIndSrv; ++itIndSrv) |
---|
| 742 | // connectedServerRank_.push_back(itIndSrv->first); |
---|
| 743 | // } |
---|
| 744 | // nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
| 745 | // } |
---|
| 746 | |
---|
| 747 | void CAxis::sendNonDistributedAttributes() |
---|
| 748 | { |
---|
| 749 | CContext* context = CContext::getCurrent(); |
---|
[1027] | 750 | int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; |
---|
[1025] | 751 | |
---|
[1027] | 752 | for (int i = 0; i < nbSrvPools; ++i) |
---|
| 753 | { |
---|
| 754 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[i] : context->client; |
---|
[1025] | 755 | |
---|
[1027] | 756 | CEventClient event(getType(), EVENT_ID_NON_DISTRIBUTED_ATTRIBUTES); |
---|
| 757 | size_t nbIndex = index.numElements(); |
---|
| 758 | size_t nbDataIndex = 0; |
---|
[633] | 759 | |
---|
[1027] | 760 | for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
[676] | 761 | { |
---|
[1027] | 762 | int ind = data_index(idx); |
---|
| 763 | if (ind >= 0 && ind < nbIndex) ++nbDataIndex; |
---|
| 764 | } |
---|
[676] | 765 | |
---|
[1027] | 766 | CArray<int,1> dataIndex(nbDataIndex); |
---|
| 767 | nbDataIndex = 0; |
---|
| 768 | for (int idx = 0; idx < data_index.numElements(); ++idx) |
---|
| 769 | { |
---|
| 770 | int ind = data_index(idx); |
---|
| 771 | if (ind >= 0 && ind < nbIndex) |
---|
| 772 | { |
---|
| 773 | dataIndex(nbDataIndex) = ind; |
---|
| 774 | ++nbDataIndex; |
---|
| 775 | } |
---|
| 776 | } |
---|
[633] | 777 | |
---|
[1027] | 778 | if (client->isServerLeader()) |
---|
[633] | 779 | { |
---|
[1027] | 780 | std::list<CMessage> msgs; |
---|
[1025] | 781 | |
---|
[1027] | 782 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 783 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 784 | { |
---|
| 785 | msgs.push_back(CMessage()); |
---|
| 786 | CMessage& msg = msgs.back(); |
---|
| 787 | msg << this->getId(); |
---|
| 788 | msg << index.getValue() << dataIndex << zoom_index.getValue() << mask.getValue(); |
---|
| 789 | msg << hasValue; |
---|
| 790 | if (hasValue) msg << value.getValue(); |
---|
| 791 | |
---|
| 792 | msg << hasBounds_; |
---|
| 793 | if (hasBounds_) msg << bounds.getValue(); |
---|
| 794 | |
---|
| 795 | event.push(*itRank, 1, msg); |
---|
| 796 | } |
---|
| 797 | client->sendEvent(event); |
---|
[633] | 798 | } |
---|
[1027] | 799 | else client->sendEvent(event); |
---|
[633] | 800 | } |
---|
| 801 | } |
---|
| 802 | |
---|
[1025] | 803 | void CAxis::recvNonDistributedAttributes(CEventServer& event) |
---|
[633] | 804 | { |
---|
[1025] | 805 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 806 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 807 | { |
---|
| 808 | CBufferIn* buffer = it->buffer; |
---|
| 809 | string axisId; |
---|
| 810 | *buffer >> axisId; |
---|
| 811 | get(axisId)->recvNonDistributedAttributes(it->rank, *buffer); |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | void CAxis::recvNonDistributedAttributes(int rank, CBufferIn& buffer) |
---|
| 816 | { |
---|
| 817 | CArray<int,1> tmp_index, tmp_data_index, tmp_zoom_index; |
---|
| 818 | CArray<bool,1> tmp_mask; |
---|
| 819 | CArray<double,1> tmp_val; |
---|
| 820 | CArray<double,2> tmp_bnds; |
---|
| 821 | |
---|
| 822 | buffer >> tmp_index; |
---|
| 823 | index.reference(tmp_index); |
---|
| 824 | buffer >> tmp_data_index; |
---|
| 825 | data_index.reference(tmp_data_index); |
---|
| 826 | buffer >> tmp_zoom_index; |
---|
| 827 | zoom_index.reference(tmp_zoom_index); |
---|
| 828 | buffer >> tmp_mask; |
---|
| 829 | mask.reference(tmp_mask); |
---|
| 830 | buffer >> hasValue; |
---|
| 831 | if (hasValue) |
---|
| 832 | { |
---|
| 833 | buffer >> tmp_val; |
---|
| 834 | value.reference(tmp_val); |
---|
| 835 | } |
---|
| 836 | |
---|
| 837 | buffer >> hasBounds_; |
---|
| 838 | if (hasBounds_) |
---|
| 839 | { |
---|
| 840 | buffer >> tmp_bnds; |
---|
| 841 | bounds.reference(tmp_bnds); |
---|
| 842 | } |
---|
| 843 | |
---|
| 844 | { |
---|
| 845 | count_write_index_ = zoom_index.numElements(); |
---|
| 846 | start_write_index_ = 0; |
---|
| 847 | local_write_size_ = count_write_index_; |
---|
| 848 | global_write_size_ = count_write_index_; |
---|
| 849 | } |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | void CAxis::sendDistributedAttributes(void) |
---|
| 853 | { |
---|
[633] | 854 | int ns, n, i, j, ind, nv, idx; |
---|
| 855 | CContext* context = CContext::getCurrent(); |
---|
[1027] | 856 | int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; |
---|
[633] | 857 | |
---|
[1027] | 858 | for (int i = 0; i < nbSrvPools; ++i) |
---|
[1025] | 859 | { |
---|
[1027] | 860 | CContextClient* client = (0 != context->clientPrimServer.size()) ? context->clientPrimServer[i] : context->client; |
---|
[1025] | 861 | |
---|
[1027] | 862 | CEventClient eventData(getType(), EVENT_ID_DISTRIBUTED_ATTRIBUTES); |
---|
[633] | 863 | |
---|
[1027] | 864 | list<CMessage> listData; |
---|
| 865 | list<CArray<int,1> > list_indi, list_dataInd, list_zoomInd; |
---|
| 866 | list<CArray<bool,1> > list_mask; |
---|
| 867 | list<CArray<double,1> > list_val; |
---|
| 868 | list<CArray<double,2> > list_bounds; |
---|
[633] | 869 | |
---|
[1027] | 870 | int nbIndex = index.numElements(); |
---|
| 871 | CArray<int,1> dataIndex(nbIndex); |
---|
| 872 | dataIndex = -1; |
---|
| 873 | for (int inx = 0; inx < data_index.numElements(); ++inx) |
---|
[633] | 874 | { |
---|
[1027] | 875 | if (0 <= data_index(inx) && data_index(inx) < nbIndex) |
---|
| 876 | dataIndex(inx) = data_index(inx); |
---|
[633] | 877 | } |
---|
| 878 | |
---|
[1027] | 879 | boost::unordered_map<int, std::vector<size_t> >::const_iterator it, iteMap; |
---|
| 880 | iteMap = indSrv_.end(); |
---|
| 881 | for (int k = 0; k < connectedServerRank_.size(); ++k) |
---|
[633] | 882 | { |
---|
[1027] | 883 | int nbData = 0; |
---|
| 884 | int rank = connectedServerRank_[k]; |
---|
| 885 | int nbSendingClient = nbConnectedClients_[rank]; |
---|
| 886 | it = indSrv_.find(rank); |
---|
| 887 | if (iteMap != it) |
---|
| 888 | nbData = it->second.size(); |
---|
[633] | 889 | |
---|
[1027] | 890 | list_indi.push_back(CArray<int,1>(nbData)); |
---|
| 891 | list_dataInd.push_back(CArray<int,1>(nbData)); |
---|
| 892 | list_zoomInd.push_back(CArray<int,1>(nbData)); |
---|
| 893 | list_mask.push_back(CArray<bool,1>(nbData)); |
---|
[1025] | 894 | |
---|
[1027] | 895 | |
---|
[1025] | 896 | if (hasValue) |
---|
[1027] | 897 | list_val.push_back(CArray<double,1>(nbData)); |
---|
| 898 | |
---|
| 899 | if (hasBounds_) |
---|
[1025] | 900 | { |
---|
[1027] | 901 | list_bounds.push_back(CArray<double,2>(2,nbData)); |
---|
[1025] | 902 | } |
---|
| 903 | |
---|
[1027] | 904 | CArray<int,1>& indi = list_indi.back(); |
---|
| 905 | CArray<int,1>& dataIndi = list_dataInd.back(); |
---|
| 906 | CArray<int,1>& zoomIndi = list_zoomInd.back(); |
---|
| 907 | CArray<bool,1>& maskIndi = list_mask.back(); |
---|
| 908 | |
---|
| 909 | for (n = 0; n < nbData; ++n) |
---|
[633] | 910 | { |
---|
[1027] | 911 | idx = static_cast<int>(it->second[n]); |
---|
| 912 | indi(n) = idx; |
---|
| 913 | |
---|
| 914 | ind = globalLocalIndexMap_[idx]; |
---|
| 915 | dataIndi(n) = dataIndex(ind); |
---|
| 916 | maskIndi(n) = mask(ind); |
---|
| 917 | zoomIndi(n) = zoom_index(ind); |
---|
| 918 | |
---|
| 919 | if (hasValue) |
---|
| 920 | { |
---|
| 921 | CArray<double,1>& val = list_val.back(); |
---|
| 922 | val(n) = value(ind); |
---|
| 923 | } |
---|
| 924 | |
---|
| 925 | if (hasBounds_) |
---|
| 926 | { |
---|
| 927 | CArray<double,2>& boundsVal = list_bounds.back(); |
---|
| 928 | boundsVal(0, n) = bounds(0,n); |
---|
| 929 | boundsVal(1, n) = bounds(1,n); |
---|
| 930 | } |
---|
[633] | 931 | } |
---|
[1027] | 932 | |
---|
| 933 | listData.push_back(CMessage()); |
---|
| 934 | listData.back() << this->getId() |
---|
| 935 | << list_indi.back() << list_dataInd.back() << list_zoomInd.back() << list_mask.back() |
---|
| 936 | << hasValue; |
---|
| 937 | if (hasValue) |
---|
| 938 | listData.back() << list_val.back(); |
---|
| 939 | listData.back() << hasBounds_; |
---|
| 940 | if (hasBounds_) |
---|
| 941 | listData.back() << list_bounds.back(); |
---|
| 942 | |
---|
| 943 | eventData.push(rank, nbConnectedClients_[rank], listData.back()); |
---|
[633] | 944 | } |
---|
| 945 | |
---|
[1027] | 946 | client->sendEvent(eventData); |
---|
[633] | 947 | } |
---|
| 948 | } |
---|
| 949 | |
---|
[1025] | 950 | void CAxis::recvDistributedAttributes(CEventServer& event) |
---|
[633] | 951 | { |
---|
[1025] | 952 | string axisId; |
---|
| 953 | vector<int> ranks; |
---|
| 954 | vector<CBufferIn*> buffers; |
---|
[676] | 955 | |
---|
[633] | 956 | list<CEventServer::SSubEvent>::iterator it; |
---|
| 957 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
| 958 | { |
---|
[1025] | 959 | ranks.push_back(it->rank); |
---|
[633] | 960 | CBufferIn* buffer = it->buffer; |
---|
[676] | 961 | *buffer >> axisId; |
---|
[1025] | 962 | buffers.push_back(buffer); |
---|
[633] | 963 | } |
---|
[1025] | 964 | get(axisId)->recvDistributedAttributes(ranks, buffers); |
---|
[633] | 965 | } |
---|
| 966 | |
---|
[1025] | 967 | void CAxis::recvDistributedAttributes(vector<int>& ranks, vector<CBufferIn*> buffers) |
---|
[633] | 968 | { |
---|
[1025] | 969 | int nbReceived = ranks.size(); |
---|
| 970 | vector<CArray<int,1> > vec_indi(nbReceived), vec_dataInd(nbReceived), vec_zoomInd(nbReceived); |
---|
| 971 | vector<CArray<bool,1> > vec_mask(nbReceived); |
---|
| 972 | vector<CArray<double,1> > vec_val(nbReceived); |
---|
| 973 | vector<CArray<double,2> > vec_bounds(nbReceived); |
---|
| 974 | |
---|
| 975 | for (int idx = 0; idx < nbReceived; ++idx) |
---|
| 976 | { |
---|
| 977 | CBufferIn& buffer = *buffers[idx]; |
---|
| 978 | buffer >> vec_indi[idx]; |
---|
| 979 | buffer >> vec_dataInd[idx]; |
---|
| 980 | buffer >> vec_zoomInd[idx]; |
---|
| 981 | buffer >> vec_mask[idx]; |
---|
[676] | 982 | |
---|
[1025] | 983 | buffer >> hasValue; |
---|
| 984 | if (hasValue) |
---|
| 985 | buffer >> vec_val[idx]; |
---|
| 986 | buffer >> hasBounds_; |
---|
| 987 | if (hasBounds_) |
---|
| 988 | buffer >> vec_bounds[idx]; |
---|
[676] | 989 | } |
---|
[633] | 990 | |
---|
[1025] | 991 | int nbData = 0; |
---|
| 992 | for (int idx = 0; idx < nbReceived; ++idx) |
---|
[633] | 993 | { |
---|
[1025] | 994 | nbData += vec_indi[idx].numElements(); |
---|
[633] | 995 | } |
---|
[1025] | 996 | |
---|
| 997 | index.resize(nbData); |
---|
| 998 | CArray<int,1> nonCompressedData(nbData); |
---|
| 999 | mask.resize(nbData); |
---|
| 1000 | if (hasValue) |
---|
| 1001 | value.resize(nbData); |
---|
| 1002 | if (hasBounds_) |
---|
| 1003 | bounds.resize(2,nbData); |
---|
[633] | 1004 | |
---|
[1025] | 1005 | nbData = 0; |
---|
| 1006 | for (int idx = 0; idx < nbReceived; ++idx) |
---|
[633] | 1007 | { |
---|
[1025] | 1008 | CArray<int,1>& indi = vec_indi[idx]; |
---|
| 1009 | CArray<int,1>& dataIndi = vec_dataInd[idx]; |
---|
| 1010 | CArray<bool,1>& maskIndi = vec_mask[idx]; |
---|
| 1011 | int nb = indi.numElements(); |
---|
| 1012 | for (int n = 0; n < nb; ++n) |
---|
[633] | 1013 | { |
---|
[1025] | 1014 | index(nbData) = indi(n); |
---|
| 1015 | nonCompressedData(nbData) = (0 <= dataIndi(n)) ? nbData : -1; |
---|
| 1016 | mask(nbData) = maskIndi(n); |
---|
| 1017 | if (hasValue) |
---|
| 1018 | value(nbData) = vec_val[idx](n); |
---|
| 1019 | if (hasBounds_) |
---|
| 1020 | { |
---|
| 1021 | bounds(0,nbData) = vec_bounds[idx](0,n); |
---|
| 1022 | bounds(1,nbData) = vec_bounds[idx](1,n); |
---|
| 1023 | } |
---|
| 1024 | ++nbData; |
---|
[633] | 1025 | } |
---|
| 1026 | } |
---|
| 1027 | |
---|
[1025] | 1028 | int nbIndex = index.numElements(); |
---|
| 1029 | int nbCompressedData = 0; |
---|
| 1030 | for (int idx = 0; idx < nonCompressedData.numElements(); ++idx) |
---|
| 1031 | { |
---|
| 1032 | if (0 <= nonCompressedData(idx) && nonCompressedData(idx) < nbIndex) |
---|
| 1033 | ++nbCompressedData; |
---|
| 1034 | } |
---|
[676] | 1035 | |
---|
[1025] | 1036 | data_index.resize(nbCompressedData); |
---|
| 1037 | nbCompressedData = 0; |
---|
| 1038 | for (int idx = 0; idx < nonCompressedData.numElements(); ++idx) |
---|
[633] | 1039 | { |
---|
[1025] | 1040 | if (0 <= nonCompressedData(idx) && nonCompressedData(idx) < nbIndex) |
---|
| 1041 | { |
---|
| 1042 | data_index(nbCompressedData) = nonCompressedData(idx); |
---|
| 1043 | ++nbCompressedData; |
---|
| 1044 | } |
---|
[633] | 1045 | } |
---|
[676] | 1046 | |
---|
[1025] | 1047 | int nbZoomIndex = 0; |
---|
| 1048 | for (int idx = 0; idx < nbReceived; ++idx) |
---|
[676] | 1049 | { |
---|
[1025] | 1050 | nbZoomIndex += vec_zoomInd[idx].numElements(); |
---|
[676] | 1051 | } |
---|
[633] | 1052 | |
---|
[1025] | 1053 | zoom_index.resize(nbZoomIndex); |
---|
| 1054 | nbZoomIndex = 0; |
---|
| 1055 | CArray<int,1>& zoom_Index_Tmp = this->zoom_index; |
---|
| 1056 | for (int idx = 0; idx < nbReceived; ++idx) |
---|
| 1057 | { |
---|
| 1058 | CArray<int,1> tmp = zoom_Index_Tmp(Range(nbZoomIndex, nbZoomIndex + vec_zoomInd[idx].numElements()-1)); |
---|
| 1059 | tmp = vec_zoomInd[idx]; |
---|
[633] | 1060 | |
---|
[1025] | 1061 | nbZoomIndex += vec_zoomInd[idx].numElements(); |
---|
[633] | 1062 | } |
---|
[676] | 1063 | |
---|
[1025] | 1064 | |
---|
[676] | 1065 | { |
---|
[1025] | 1066 | CContextServer* server = CContext::getCurrent()->server; |
---|
| 1067 | count_write_index_ = zoom_index.numElements(); |
---|
| 1068 | MPI_Scan(&count_write_index_, &start_write_index_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
| 1069 | global_write_size_ = start_write_index_; |
---|
| 1070 | start_write_index_ -= count_write_index_; |
---|
| 1071 | local_write_size_ = count_write_index_; |
---|
[676] | 1072 | } |
---|
[633] | 1073 | } |
---|
| 1074 | |
---|
[987] | 1075 | // void CAxis::sendServerAttribut(const std::vector<int>& globalDim, int orderPositionInGrid, |
---|
| 1076 | // CServerDistributionDescription::ServerDistributionType distType) |
---|
| 1077 | // { |
---|
| 1078 | // CContext* context = CContext::getCurrent(); |
---|
| 1079 | |
---|
[1025] | 1080 | // CContextClient* contextClientTmp = (0 != context->clientPrimServer) ? context->clientPrimServer |
---|
| 1081 | // : context->client; |
---|
| 1082 | |
---|
| 1083 | |
---|
| 1084 | // int nbServer = contextClientTmp->serverSize; |
---|
| 1085 | |
---|
[987] | 1086 | // CServerDistributionDescription serverDescription(globalDim, nbServer); |
---|
| 1087 | // serverDescription.computeServerDistribution(); |
---|
| 1088 | |
---|
| 1089 | // std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); |
---|
| 1090 | // std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); |
---|
| 1091 | |
---|
[1025] | 1092 | // globalDimGrid.resize(globalDim.size()); |
---|
| 1093 | // for (int idx = 0; idx < globalDim.size(); ++idx) globalDimGrid(idx) = globalDim[idx]; |
---|
| 1094 | |
---|
[987] | 1095 | // CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT); |
---|
[1025] | 1096 | // if (contextClientTmp->isServerLeader()) |
---|
[987] | 1097 | // { |
---|
| 1098 | // std::list<CMessage> msgs; |
---|
| 1099 | |
---|
[1025] | 1100 | // const std::list<int>& ranks = contextClientTmp->getRanksServerLeader(); |
---|
[987] | 1101 | // for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1102 | // { |
---|
| 1103 | // // Use const int to ensure CMessage holds a copy of the value instead of just a reference |
---|
| 1104 | // const int begin = serverIndexBegin[*itRank][orderPositionInGrid]; |
---|
| 1105 | // const int ni = serverDimensionSizes[*itRank][orderPositionInGrid]; |
---|
| 1106 | // const int end = begin + ni - 1; |
---|
| 1107 | |
---|
| 1108 | // msgs.push_back(CMessage()); |
---|
| 1109 | // CMessage& msg = msgs.back(); |
---|
| 1110 | // msg << this->getId(); |
---|
| 1111 | // msg << ni << begin << end; |
---|
| 1112 | // msg << global_zoom_begin.getValue() << global_zoom_n.getValue(); |
---|
| 1113 | // msg << isCompressible_; |
---|
[1025] | 1114 | // msg << orderPositionInGrid; |
---|
| 1115 | // msg << globalDimGrid; |
---|
[987] | 1116 | |
---|
| 1117 | // event.push(*itRank,1,msg); |
---|
| 1118 | // } |
---|
[1025] | 1119 | // contextClientTmp->sendEvent(event); |
---|
[987] | 1120 | // } |
---|
[1025] | 1121 | // else contextClientTmp->sendEvent(event); |
---|
[987] | 1122 | // } |
---|
| 1123 | |
---|
[1025] | 1124 | // void CAxis::recvServerAttribut(CEventServer& event) |
---|
| 1125 | // { |
---|
| 1126 | // CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 1127 | // string axisId; |
---|
| 1128 | // *buffer >> axisId; |
---|
| 1129 | // get(axisId)->recvServerAttribut(*buffer); |
---|
[567] | 1130 | |
---|
[1025] | 1131 | // CContext* context = CContext::getCurrent(); |
---|
| 1132 | // if (context->hasClient && context->hasServer) |
---|
| 1133 | // { |
---|
| 1134 | // std::vector<int> globalDim(get(axisId)->globalDimGrid.numElements()); |
---|
| 1135 | // for (int idx = 0; idx < globalDim.size(); ++idx) globalDim[idx] = get(axisId)->globalDimGrid(idx); |
---|
| 1136 | // get(axisId)->sendServerAttribut(globalDim, get(axisId)->orderPosInGrid, |
---|
| 1137 | // CServerDistributionDescription::BAND_DISTRIBUTION); |
---|
| 1138 | // } |
---|
| 1139 | // } |
---|
[987] | 1140 | |
---|
[1025] | 1141 | // void CAxis::recvServerAttribut(CBufferIn& buffer) |
---|
| 1142 | // { |
---|
| 1143 | // int ni_srv, begin_srv, end_srv, global_zoom_begin_tmp, global_zoom_n_tmp; |
---|
[567] | 1144 | |
---|
[1025] | 1145 | // buffer >> ni_srv >> begin_srv >> end_srv; |
---|
| 1146 | // buffer >> global_zoom_begin_tmp >> global_zoom_n_tmp; |
---|
| 1147 | // buffer >> isCompressible_; |
---|
| 1148 | // buffer >> orderPosInGrid; |
---|
| 1149 | // buffer >> globalDimGrid; |
---|
[567] | 1150 | |
---|
[1025] | 1151 | // global_zoom_begin = global_zoom_begin_tmp; |
---|
| 1152 | // global_zoom_n = global_zoom_n_tmp; |
---|
| 1153 | // int global_zoom_end = global_zoom_begin + global_zoom_n - 1; |
---|
[987] | 1154 | |
---|
[1025] | 1155 | // zoom_begin_srv = global_zoom_begin > begin_srv ? global_zoom_begin : begin_srv ; |
---|
| 1156 | // zoom_end_srv = global_zoom_end < end_srv ? global_zoom_end : end_srv ; |
---|
| 1157 | // zoom_size_srv = zoom_end_srv - zoom_begin_srv + 1; |
---|
[567] | 1158 | |
---|
[1025] | 1159 | // if (zoom_size_srv<=0) |
---|
| 1160 | // { |
---|
| 1161 | // zoom_begin_srv = 0; zoom_end_srv = 0; zoom_size_srv = 0; |
---|
| 1162 | // } |
---|
[567] | 1163 | |
---|
[1025] | 1164 | // if (n_glo == n) |
---|
| 1165 | // { |
---|
| 1166 | // zoom_begin_srv = global_zoom_begin; |
---|
| 1167 | // zoom_end_srv = global_zoom_end; //zoom_end; |
---|
| 1168 | // zoom_size_srv = zoom_end_srv - zoom_begin_srv + 1; |
---|
| 1169 | // } |
---|
| 1170 | // if (hasValue) |
---|
| 1171 | // { |
---|
| 1172 | // value_srv.resize(zoom_size_srv); |
---|
| 1173 | // if (hasBounds_) bound_srv.resize(2,zoom_size_srv); |
---|
| 1174 | // } |
---|
| 1175 | // } |
---|
[586] | 1176 | |
---|
[836] | 1177 | CTransformation<CAxis>* CAxis::addTransformation(ETranformationType transType, const StdString& id) |
---|
| 1178 | { |
---|
| 1179 | transformationMap_.push_back(std::make_pair(transType, CTransformation<CAxis>::createTransformation(transType,id))); |
---|
| 1180 | return transformationMap_.back().second; |
---|
| 1181 | } |
---|
| 1182 | |
---|
[619] | 1183 | bool CAxis::hasTransformation() |
---|
| 1184 | { |
---|
[621] | 1185 | return (!transformationMap_.empty()); |
---|
[619] | 1186 | } |
---|
| 1187 | |
---|
[621] | 1188 | void CAxis::setTransformations(const TransMapTypes& axisTrans) |
---|
[619] | 1189 | { |
---|
[621] | 1190 | transformationMap_ = axisTrans; |
---|
[619] | 1191 | } |
---|
| 1192 | |
---|
[621] | 1193 | CAxis::TransMapTypes CAxis::getAllTransformations(void) |
---|
[620] | 1194 | { |
---|
[621] | 1195 | return transformationMap_; |
---|
| 1196 | } |
---|
[620] | 1197 | |
---|
[823] | 1198 | void CAxis::duplicateTransformation(CAxis* src) |
---|
| 1199 | { |
---|
| 1200 | if (src->hasTransformation()) |
---|
| 1201 | { |
---|
| 1202 | this->setTransformations(src->getAllTransformations()); |
---|
| 1203 | } |
---|
| 1204 | } |
---|
| 1205 | |
---|
[747] | 1206 | /*! |
---|
| 1207 | * Go through the hierarchy to find the axis from which the transformations must be inherited |
---|
| 1208 | */ |
---|
[619] | 1209 | void CAxis::solveInheritanceTransformation() |
---|
| 1210 | { |
---|
[747] | 1211 | if (hasTransformation() || !hasDirectAxisReference()) |
---|
| 1212 | return; |
---|
[619] | 1213 | |
---|
[747] | 1214 | CAxis* axis = this; |
---|
[619] | 1215 | std::vector<CAxis*> refAxis; |
---|
[747] | 1216 | while (!axis->hasTransformation() && axis->hasDirectAxisReference()) |
---|
[619] | 1217 | { |
---|
[747] | 1218 | refAxis.push_back(axis); |
---|
| 1219 | axis = axis->getDirectAxisReference(); |
---|
[619] | 1220 | } |
---|
| 1221 | |
---|
[747] | 1222 | if (axis->hasTransformation()) |
---|
| 1223 | for (size_t i = 0; i < refAxis.size(); ++i) |
---|
| 1224 | refAxis[i]->setTransformations(axis->getAllTransformations()); |
---|
[619] | 1225 | } |
---|
| 1226 | |
---|
| 1227 | void CAxis::parse(xml::CXMLNode & node) |
---|
| 1228 | { |
---|
| 1229 | SuperClass::parse(node); |
---|
| 1230 | |
---|
| 1231 | if (node.goToChildElement()) |
---|
| 1232 | { |
---|
[836] | 1233 | StdString nodeElementName; |
---|
[619] | 1234 | do |
---|
| 1235 | { |
---|
[784] | 1236 | StdString nodeId(""); |
---|
| 1237 | if (node.getAttributes().end() != node.getAttributes().find("id")) |
---|
| 1238 | { nodeId = node.getAttributes()["id"]; } |
---|
| 1239 | |
---|
[836] | 1240 | nodeElementName = node.getElementName(); |
---|
| 1241 | std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it; |
---|
| 1242 | it = transformationMapList_.find(nodeElementName); |
---|
| 1243 | if (ite != it) |
---|
| 1244 | { |
---|
| 1245 | transformationMap_.push_back(std::make_pair(it->second, CTransformation<CAxis>::createTransformation(it->second, |
---|
| 1246 | nodeId, |
---|
| 1247 | &node))); |
---|
[786] | 1248 | } |
---|
[968] | 1249 | else |
---|
| 1250 | { |
---|
| 1251 | ERROR("void CAxis::parse(xml::CXMLNode & node)", |
---|
| 1252 | << "The transformation " << nodeElementName << " has not been supported yet."); |
---|
| 1253 | } |
---|
[619] | 1254 | } while (node.goToNextElement()) ; |
---|
| 1255 | node.goToParentElement(); |
---|
| 1256 | } |
---|
| 1257 | } |
---|
| 1258 | |
---|
[620] | 1259 | DEFINE_REF_FUNC(Axis,axis) |
---|
[619] | 1260 | |
---|
[219] | 1261 | ///--------------------------------------------------------------- |
---|
| 1262 | |
---|
[335] | 1263 | } // namespace xios |
---|