[266] | 1 | |
---|
[219] | 2 | #include "grid.hpp" |
---|
| 3 | |
---|
[352] | 4 | #include "attribute_template.hpp" |
---|
| 5 | #include "object_template.hpp" |
---|
| 6 | #include "group_template.hpp" |
---|
| 7 | #include "message.hpp" |
---|
[286] | 8 | #include <iostream> |
---|
[591] | 9 | #include "xios_spl.hpp" |
---|
[352] | 10 | #include "type.hpp" |
---|
| 11 | #include "context.hpp" |
---|
| 12 | #include "context_client.hpp" |
---|
[552] | 13 | #include "context_server.hpp" |
---|
[369] | 14 | #include "array_new.hpp" |
---|
[657] | 15 | #include "server_distribution_description.hpp" |
---|
[568] | 16 | #include "client_server_mapping_distributed.hpp" |
---|
[660] | 17 | #include "distribution_client.hpp" |
---|
| 18 | #include "grid_transformation.hpp" |
---|
[687] | 19 | #include "grid_generate.hpp" |
---|
[219] | 20 | |
---|
[335] | 21 | namespace xios { |
---|
[219] | 22 | |
---|
| 23 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 24 | |
---|
| 25 | CGrid::CGrid(void) |
---|
| 26 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
[650] | 27 | , isChecked(false), isDomainAxisChecked(false) |
---|
[676] | 28 | , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false) |
---|
| 29 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
| 30 | , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
| 31 | , globalDim_(), connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true), isCompressible_(false) |
---|
| 32 | , transformations_(0), isTransformed_(false) |
---|
[657] | 33 | , axisPositionInGrid_(), positionDimensionDistributed_(1) |
---|
[540] | 34 | { |
---|
| 35 | setVirtualDomainGroup(); |
---|
| 36 | setVirtualAxisGroup(); |
---|
| 37 | } |
---|
[219] | 38 | |
---|
[650] | 39 | CGrid::CGrid(const StdString& id) |
---|
[219] | 40 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
[650] | 41 | , isChecked(false), isDomainAxisChecked(false) |
---|
[676] | 42 | , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false) |
---|
| 43 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
| 44 | , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
| 45 | , globalDim_(), connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true), isCompressible_(false) |
---|
| 46 | , transformations_(0), isTransformed_(false) |
---|
[657] | 47 | , axisPositionInGrid_(), positionDimensionDistributed_(1) |
---|
[540] | 48 | { |
---|
| 49 | setVirtualDomainGroup(); |
---|
| 50 | setVirtualAxisGroup(); |
---|
| 51 | } |
---|
[219] | 52 | |
---|
| 53 | CGrid::~CGrid(void) |
---|
[509] | 54 | { |
---|
[551] | 55 | if (0 != clientDistribution_) delete clientDistribution_; |
---|
[552] | 56 | if (0 != serverDistribution_) delete serverDistribution_; |
---|
[656] | 57 | if (0 != clientServerMap_) delete clientServerMap_; |
---|
[620] | 58 | if (0 != transformations_) delete transformations_; |
---|
[219] | 59 | } |
---|
| 60 | |
---|
| 61 | ///--------------------------------------------------------------- |
---|
| 62 | |
---|
[650] | 63 | StdString CGrid::GetName(void) { return StdString("grid"); } |
---|
| 64 | StdString CGrid::GetDefName(void) { return CGrid::GetName(); } |
---|
| 65 | ENodeType CGrid::GetType(void) { return eGrid; } |
---|
[219] | 66 | |
---|
| 67 | |
---|
| 68 | StdSize CGrid::getDimension(void) const |
---|
| 69 | { |
---|
[650] | 70 | return globalDim_.size(); |
---|
[219] | 71 | } |
---|
| 72 | |
---|
| 73 | //--------------------------------------------------------------- |
---|
| 74 | |
---|
[286] | 75 | StdSize CGrid::getDataSize(void) const |
---|
| 76 | { |
---|
[586] | 77 | StdSize retvalue = 1; |
---|
[600] | 78 | if (!isScalarGrid()) |
---|
| 79 | { |
---|
| 80 | std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); |
---|
| 81 | for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; |
---|
| 82 | } |
---|
| 83 | return retvalue; |
---|
[286] | 84 | } |
---|
| 85 | |
---|
[731] | 86 | /*! |
---|
| 87 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 88 | * |
---|
| 89 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 90 | */ |
---|
| 91 | std::map<int, StdSize> CGrid::getAttributesBufferSize() |
---|
[509] | 92 | { |
---|
[731] | 93 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(); |
---|
[586] | 94 | |
---|
[731] | 95 | // The grid indexes require a similar size as the actual data |
---|
| 96 | std::map<int, StdSize> dataSizes = getDataBufferSize(); |
---|
| 97 | std::map<int, StdSize>::iterator it, itE = dataSizes.end(); |
---|
| 98 | for (it = dataSizes.begin(); it != itE; ++it) |
---|
[509] | 99 | { |
---|
[731] | 100 | it->second += 2 * sizeof(bool); |
---|
| 101 | if (it->second > attributesSizes[it->first]) |
---|
| 102 | attributesSizes[it->first] = it->second; |
---|
[586] | 103 | } |
---|
| 104 | |
---|
[731] | 105 | // Account for the axis attributes |
---|
| 106 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 107 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
[586] | 108 | { |
---|
[731] | 109 | std::map<int, StdSize> axisAttBuffSize = axisList[i]->getAttributesBufferSize(); |
---|
| 110 | for (it = axisAttBuffSize.begin(), itE = axisAttBuffSize.end(); it != itE; ++it) |
---|
[586] | 111 | { |
---|
[731] | 112 | if (it->second > attributesSizes[it->first]) |
---|
| 113 | attributesSizes[it->first] = it->second; |
---|
[586] | 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
[731] | 117 | // Account for the domain attributes |
---|
| 118 | std::vector<CDomain*> domList = getDomains(); |
---|
| 119 | for (size_t i = 0; i < domList.size(); ++i) |
---|
[657] | 120 | { |
---|
[731] | 121 | std::map<int, StdSize> domAttBuffSize = domList[i]->getAttributesBufferSize(); |
---|
| 122 | for (it = domAttBuffSize.begin(), itE = domAttBuffSize.end(); it != itE; ++it) |
---|
[657] | 123 | { |
---|
[731] | 124 | if (it->second > attributesSizes[it->first]) |
---|
| 125 | attributesSizes[it->first] = it->second; |
---|
[657] | 126 | } |
---|
| 127 | } |
---|
[731] | 128 | |
---|
| 129 | return attributesSizes; |
---|
| 130 | } |
---|
[657] | 131 | |
---|
[731] | 132 | /*! |
---|
| 133 | * Compute the minimum buffer size required to send the data to the server(s). |
---|
| 134 | * |
---|
| 135 | * \param id the id used to tag the data |
---|
| 136 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 137 | */ |
---|
| 138 | std::map<int, StdSize> CGrid::getDataBufferSize(const std::string& id /*= ""*/) |
---|
| 139 | { |
---|
| 140 | std::map<int, StdSize> dataSizes; |
---|
| 141 | const size_t extraSize = CEventClient::headerSize + (id.empty() ? getId() : id).size() + sizeof(size_t); |
---|
| 142 | |
---|
| 143 | std::map<int, size_t>::const_iterator itb = connectedDataSize_.begin(), it, itE = connectedDataSize_.end(); |
---|
| 144 | for (it = itb; it != itE; ++it) |
---|
| 145 | dataSizes.insert(std::make_pair(it->first, extraSize + CArray<double,1>::size(it->second))); |
---|
| 146 | |
---|
| 147 | return dataSizes; |
---|
[509] | 148 | } |
---|
| 149 | |
---|
[657] | 150 | void CGrid::checkAttributesAfterTransformation() |
---|
| 151 | { |
---|
| 152 | setDomainList(); |
---|
| 153 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 154 | if (!domListP.empty()) |
---|
| 155 | { |
---|
| 156 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 157 | { |
---|
| 158 | domListP[i]->checkAttributesOnClientAfterTransformation(); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | } |
---|
[509] | 162 | |
---|
[676] | 163 | //--------------------------------------------------------------- |
---|
| 164 | |
---|
| 165 | /*! |
---|
| 166 | * Test whether the data defined on the grid can be outputted in a compressed way. |
---|
[720] | 167 | * |
---|
[676] | 168 | * \return true if and only if a mask was defined for this grid |
---|
| 169 | */ |
---|
| 170 | bool CGrid::isCompressible(void) const |
---|
| 171 | { |
---|
| 172 | return isCompressible_; |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | //--------------------------------------------------------------- |
---|
| 176 | |
---|
| 177 | void CGrid::addRelFileCompressed(const StdString& filename) |
---|
| 178 | { |
---|
| 179 | this->relFilesCompressed.insert(filename); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | bool CGrid::isWrittenCompressed(const StdString& filename) const |
---|
| 183 | { |
---|
| 184 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | //--------------------------------------------------------------- |
---|
| 188 | |
---|
[509] | 189 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
[219] | 190 | { |
---|
[509] | 191 | if (this->isDomainAxisChecked) return; |
---|
[369] | 192 | |
---|
[584] | 193 | this->solveAxisRef(areAttributesChecked); |
---|
[509] | 194 | this->solveDomainRef(areAttributesChecked); |
---|
[657] | 195 | computeGridGlobalDimension(getDomains(), getAxis(), axis_domain_order); |
---|
[509] | 196 | this->isDomainAxisChecked = areAttributesChecked; |
---|
| 197 | } |
---|
| 198 | |
---|
[676] | 199 | void CGrid::checkEligibilityForCompressedOutput() |
---|
| 200 | { |
---|
| 201 | // We don't check if the mask is valid here, just if a mask has been defined at this point. |
---|
| 202 | isCompressible_ = !mask1.isEmpty() || !mask2.isEmpty() || !mask3.isEmpty(); |
---|
| 203 | } |
---|
| 204 | |
---|
[509] | 205 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
| 206 | { |
---|
[650] | 207 | CContext* context = CContext::getCurrent(); |
---|
| 208 | CContextClient* client=context->client; |
---|
[509] | 209 | |
---|
[600] | 210 | if (isScalarGrid()) |
---|
[586] | 211 | { |
---|
| 212 | if (context->hasClient) |
---|
| 213 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } |
---|
| 214 | |
---|
| 215 | if (this->isChecked) return; |
---|
| 216 | if (context->hasClient) |
---|
| 217 | { |
---|
| 218 | this->computeIndexScalarGrid(); |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | this->isChecked = true; |
---|
| 222 | return; |
---|
| 223 | } |
---|
| 224 | |
---|
[509] | 225 | if (context->hasClient) |
---|
[551] | 226 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } |
---|
[509] | 227 | |
---|
| 228 | if (this->isChecked) return; |
---|
| 229 | |
---|
| 230 | if (context->hasClient) |
---|
| 231 | { |
---|
[657] | 232 | this->checkAttributesAfterTransformation(); |
---|
| 233 | this->checkMask(); |
---|
[650] | 234 | this->computeIndex(); |
---|
[509] | 235 | } |
---|
| 236 | this->isChecked = true; |
---|
[219] | 237 | } |
---|
| 238 | |
---|
[415] | 239 | void CGrid::checkMask(void) |
---|
| 240 | { |
---|
| 241 | using namespace std; |
---|
[567] | 242 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 243 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 244 | int dim = domainP.size() * 2 + axisP.size(); |
---|
[415] | 245 | |
---|
[664] | 246 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
| 247 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->mask_1d); |
---|
[567] | 248 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 249 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
[415] | 250 | |
---|
[567] | 251 | switch (dim) { |
---|
| 252 | case 1: |
---|
[575] | 253 | checkGridMask(mask1, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 254 | break; |
---|
| 255 | case 2: |
---|
[575] | 256 | checkGridMask(mask2, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 257 | break; |
---|
| 258 | case 3: |
---|
[575] | 259 | checkGridMask(mask3, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 260 | break; |
---|
| 261 | // case 4: |
---|
[575] | 262 | // checkGridMask(mask4, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 263 | // break; |
---|
| 264 | // case 5: |
---|
[575] | 265 | // checkGridMask(mask5, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 266 | // break; |
---|
| 267 | // case 6: |
---|
[575] | 268 | // checkGridMask(mask6, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 269 | // break; |
---|
| 270 | // case 7: |
---|
[575] | 271 | // checkGridMask(mask7, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 272 | // break; |
---|
| 273 | default: |
---|
| 274 | break; |
---|
[415] | 275 | } |
---|
| 276 | } |
---|
[623] | 277 | |
---|
| 278 | void CGrid::modifyMask(const CArray<int,1>& indexToModify) |
---|
| 279 | { |
---|
| 280 | using namespace std; |
---|
| 281 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 282 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 283 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 284 | |
---|
| 285 | switch (dim) { |
---|
| 286 | case 1: |
---|
| 287 | modifyGridMask(mask1, indexToModify); |
---|
| 288 | break; |
---|
| 289 | case 2: |
---|
| 290 | modifyGridMask(mask2, indexToModify); |
---|
| 291 | break; |
---|
| 292 | case 3: |
---|
| 293 | modifyGridMask(mask3, indexToModify); |
---|
| 294 | break; |
---|
| 295 | |
---|
| 296 | default: |
---|
| 297 | break; |
---|
| 298 | } |
---|
| 299 | } |
---|
| 300 | |
---|
[219] | 301 | //--------------------------------------------------------------- |
---|
| 302 | |
---|
[509] | 303 | void CGrid::solveDomainRef(bool sendAtt) |
---|
[219] | 304 | { |
---|
[540] | 305 | setDomainList(); |
---|
[567] | 306 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 307 | if (!domListP.empty()) |
---|
[219] | 308 | { |
---|
[567] | 309 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 310 | { |
---|
| 311 | if (sendAtt) domListP[i]->sendCheckedAttributes(); |
---|
| 312 | else domListP[i]->checkAttributesOnClient(); |
---|
| 313 | } |
---|
[219] | 314 | } |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | //--------------------------------------------------------------- |
---|
| 318 | |
---|
[567] | 319 | void CGrid::solveAxisRef(bool sendAtt) |
---|
[219] | 320 | { |
---|
[540] | 321 | setAxisList(); |
---|
[567] | 322 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 323 | if (!axisListP.empty()) |
---|
[219] | 324 | { |
---|
[567] | 325 | int idx = 0; |
---|
[620] | 326 | axisPositionInGrid_.resize(0); |
---|
[575] | 327 | for (int i = 0; i < axis_domain_order.numElements(); ++i) |
---|
[568] | 328 | { |
---|
[575] | 329 | if (false == axis_domain_order(i)) |
---|
[568] | 330 | { |
---|
[620] | 331 | axisPositionInGrid_.push_back(idx); |
---|
[568] | 332 | ++idx; |
---|
| 333 | } |
---|
| 334 | else idx += 2; |
---|
| 335 | } |
---|
| 336 | |
---|
[567] | 337 | for (int i = 0; i < axisListP.size(); ++i) |
---|
[540] | 338 | { |
---|
[567] | 339 | if (sendAtt) |
---|
[620] | 340 | axisListP[i]->sendCheckedAttributes(globalDim_,axisPositionInGrid_[i]); |
---|
[567] | 341 | else |
---|
[620] | 342 | axisListP[i]->checkAttributesOnClient(globalDim_,axisPositionInGrid_[i]); |
---|
[567] | 343 | ++idx; |
---|
[540] | 344 | } |
---|
[219] | 345 | } |
---|
| 346 | } |
---|
| 347 | |
---|
[620] | 348 | std::vector<int> CGrid::getAxisPositionInGrid() const |
---|
| 349 | { |
---|
| 350 | return axisPositionInGrid_; |
---|
| 351 | } |
---|
| 352 | |
---|
[219] | 353 | //--------------------------------------------------------------- |
---|
| 354 | |
---|
| 355 | void CGrid::computeIndex(void) |
---|
[509] | 356 | { |
---|
[650] | 357 | CContext* context = CContext::getCurrent(); |
---|
| 358 | CContextClient* client = context->client; |
---|
[553] | 359 | |
---|
| 360 | // First of all, compute distribution on client side |
---|
[551] | 361 | clientDistribution_ = new CDistributionClient(client->clientRank, this); |
---|
[586] | 362 | // Get local data index on client |
---|
[668] | 363 | storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); |
---|
| 364 | int nbStoreIndex = storeIndex_client.numElements(); |
---|
| 365 | for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; |
---|
[586] | 366 | isDataDistributed_= clientDistribution_->isDataDistributed(); |
---|
| 367 | |
---|
| 368 | if (!doGridHaveDataDistributed()) |
---|
| 369 | { |
---|
| 370 | if (0 == client->clientRank) |
---|
| 371 | { |
---|
[668] | 372 | size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); |
---|
[586] | 373 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
| 374 | connectedDataSize_[rank] = ssize; |
---|
| 375 | } |
---|
| 376 | return; |
---|
| 377 | } |
---|
| 378 | |
---|
| 379 | // Compute mapping between client and server |
---|
[568] | 380 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 381 | int range, clientSize = client->clientSize; |
---|
| 382 | for (int i = 0; i < globalDim_.size(); ++i) globalSizeIndex *= globalDim_[i]; |
---|
| 383 | indexBegin = 0; |
---|
| 384 | for (int i = 0; i < clientSize; ++i) |
---|
| 385 | { |
---|
| 386 | range = globalSizeIndex / clientSize; |
---|
| 387 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 388 | if (i == client->clientRank) break; |
---|
| 389 | indexBegin += range; |
---|
| 390 | } |
---|
| 391 | indexEnd = indexBegin + range - 1; |
---|
[509] | 392 | |
---|
[553] | 393 | // Then compute distribution on server side |
---|
[657] | 394 | CServerDistributionDescription serverDistributionDescription(globalDim_); |
---|
| 395 | serverDistributionDescription.computeServerGlobalIndexInRange(client->serverSize, |
---|
| 396 | std::make_pair<size_t,size_t>(indexBegin, indexEnd), |
---|
| 397 | positionDimensionDistributed_); |
---|
[553] | 398 | |
---|
| 399 | // Finally, compute index mapping between client(s) and server(s) |
---|
[657] | 400 | clientServerMap_ = new CClientServerMappingDistributed(serverDistributionDescription.getGlobalIndexRange(), |
---|
[585] | 401 | client->intraComm, |
---|
| 402 | clientDistribution_->isDataDistributed()); |
---|
[568] | 403 | |
---|
[584] | 404 | clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex()); |
---|
[568] | 405 | const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); |
---|
[720] | 406 | |
---|
[668] | 407 | const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); |
---|
[584] | 408 | std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
| 409 | itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); |
---|
| 410 | iteGlobalMap = globalIndexOnServer.end(); |
---|
| 411 | |
---|
[668] | 412 | typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; |
---|
| 413 | std::vector<int>::iterator itVec; |
---|
| 414 | int nbGlobalIndex = globalIndexSendToServer.size(); |
---|
| 415 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 416 | { |
---|
| 417 | int serverRank = itGlobalMap->first; |
---|
| 418 | int indexSize = itGlobalMap->second.size(); |
---|
| 419 | std::vector<int> permutIndex(indexSize); |
---|
| 420 | XIOSAlgorithms::fillInIndex(indexSize, permutIndex); |
---|
[671] | 421 | XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(itGlobalMap->second, permutIndex); |
---|
[668] | 422 | BinarySearch binSearch(itGlobalMap->second); |
---|
| 423 | for (int i = 0; i < nbGlobalIndex; ++i) |
---|
| 424 | { |
---|
| 425 | if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexSendToServer[i], itVec)) |
---|
| 426 | { |
---|
| 427 | if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) |
---|
| 428 | connectedDataSize_[serverRank] = 1; |
---|
| 429 | else |
---|
| 430 | ++connectedDataSize_[serverRank]; |
---|
| 431 | } |
---|
| 432 | } |
---|
| 433 | } |
---|
[584] | 434 | |
---|
| 435 | connectedServerRank_.clear(); |
---|
[668] | 436 | for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { |
---|
[584] | 437 | connectedServerRank_.push_back(it->first); |
---|
[668] | 438 | } |
---|
| 439 | if (!connectedDataSize_.empty()) |
---|
| 440 | { |
---|
| 441 | connectedServerRank_.clear(); |
---|
| 442 | for (std::map<int,size_t>::const_iterator it = connectedDataSize_.begin(); it != connectedDataSize_.end(); ++it) |
---|
| 443 | connectedServerRank_.push_back(it->first); |
---|
| 444 | } |
---|
[584] | 445 | |
---|
[668] | 446 | nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
[219] | 447 | } |
---|
| 448 | |
---|
| 449 | //---------------------------------------------------------------- |
---|
| 450 | |
---|
[347] | 451 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[219] | 452 | { |
---|
[567] | 453 | std::vector<CDomain*> vecDom(1,domain); |
---|
| 454 | std::vector<CAxis*> vecAxis; |
---|
[622] | 455 | CArray<bool,1> axisDomainOrder; |
---|
| 456 | CGrid* grid = createGrid(vecDom, vecAxis, axisDomainOrder); |
---|
[540] | 457 | |
---|
[650] | 458 | return grid; |
---|
[219] | 459 | } |
---|
| 460 | |
---|
[347] | 461 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[219] | 462 | { |
---|
[540] | 463 | std::vector<CDomain*> vecDom(1,domain); |
---|
| 464 | std::vector<CAxis*> vecAxis(1,axis); |
---|
[622] | 465 | CArray<bool,1> axisDomainOrder; |
---|
| 466 | CGrid* grid = createGrid(vecDom, vecAxis, axisDomainOrder); |
---|
[567] | 467 | |
---|
[650] | 468 | return grid; |
---|
[219] | 469 | } |
---|
| 470 | |
---|
[622] | 471 | CGrid* CGrid::createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis, CArray<bool,1> axisDomainOrder) |
---|
[540] | 472 | { |
---|
| 473 | StdString new_id = StdString("__"); |
---|
| 474 | if (!domains.empty()) for (int i = 0; i < domains.size(); ++i) new_id += domains[i]->getId() + StdString("_"); |
---|
[650] | 475 | if (!axis.empty()) for (int i = 0; i < axis.size(); ++i) new_id += axis[i]->getId() + StdString("_"); |
---|
[586] | 476 | if (domains.empty() && axis.empty()) new_id += StdString("scalar_grid"); |
---|
[540] | 477 | new_id += StdString("_"); |
---|
| 478 | |
---|
[650] | 479 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id); |
---|
[540] | 480 | grid->setDomainList(domains); |
---|
| 481 | grid->setAxisList(axis); |
---|
[551] | 482 | |
---|
| 483 | //By default, domains are always the first ones of a grid |
---|
[622] | 484 | if (0 == axisDomainOrder.numElements()) |
---|
[551] | 485 | { |
---|
| 486 | int size = domains.size()+axis.size(); |
---|
[575] | 487 | grid->axis_domain_order.resize(size); |
---|
[551] | 488 | for (int i = 0; i < size; ++i) |
---|
| 489 | { |
---|
[575] | 490 | if (i < domains.size()) grid->axis_domain_order(i) = true; |
---|
| 491 | else grid->axis_domain_order(i) = false; |
---|
[551] | 492 | } |
---|
| 493 | } |
---|
[622] | 494 | else |
---|
| 495 | { |
---|
| 496 | grid->axis_domain_order.resize(axisDomainOrder.numElements()); |
---|
| 497 | grid->axis_domain_order = axisDomainOrder; |
---|
| 498 | } |
---|
[551] | 499 | |
---|
[587] | 500 | grid->computeGridGlobalDimension(domains, axis, grid->axis_domain_order); |
---|
[586] | 501 | |
---|
[650] | 502 | return grid; |
---|
[540] | 503 | } |
---|
| 504 | |
---|
| 505 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
| 506 | { |
---|
[650] | 507 | return this->vDomainGroup_; |
---|
[540] | 508 | } |
---|
| 509 | |
---|
| 510 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
| 511 | { |
---|
[650] | 512 | return this->vAxisGroup_; |
---|
[540] | 513 | } |
---|
| 514 | |
---|
[551] | 515 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, double* field) |
---|
| 516 | { |
---|
[650] | 517 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
[551] | 518 | StdSize numElements = stored.numElements(); |
---|
| 519 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 520 | { |
---|
[650] | 521 | field[out_i(n)] = stored(n); |
---|
[551] | 522 | } |
---|
| 523 | } |
---|
| 524 | |
---|
[599] | 525 | void CGrid::inputField(int rank, const double* const field, CArray<double,1>& stored) |
---|
| 526 | { |
---|
[650] | 527 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
[599] | 528 | StdSize numElements = stored.numElements(); |
---|
| 529 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 530 | { |
---|
[650] | 531 | stored(n) = field[out_i(n)]; |
---|
[599] | 532 | } |
---|
| 533 | } |
---|
| 534 | |
---|
[676] | 535 | void CGrid::outputCompressedField(int rank, const CArray<double,1>& stored, double* field) |
---|
| 536 | { |
---|
| 537 | const CArray<size_t,1>& out_i = compressedOutIndexFromClient[rank]; |
---|
| 538 | StdSize numElements = stored.numElements(); |
---|
| 539 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 540 | { |
---|
| 541 | field[out_i(n)] = stored(n); |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | |
---|
[219] | 545 | //---------------------------------------------------------------- |
---|
| 546 | |
---|
[650] | 547 | void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored) const |
---|
[219] | 548 | { |
---|
[650] | 549 | const StdSize size = storeIndex_client.numElements(); |
---|
[300] | 550 | |
---|
[650] | 551 | stored.resize(size); |
---|
| 552 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; |
---|
[219] | 553 | } |
---|
[509] | 554 | |
---|
[650] | 555 | void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data) const |
---|
[593] | 556 | { |
---|
[650] | 557 | const StdSize size = storeIndex_client.numElements(); |
---|
[593] | 558 | |
---|
[650] | 559 | for(StdSize i = 0; i < size; i++) data[storeIndex_client(i)] = stored(i); |
---|
[593] | 560 | } |
---|
| 561 | |
---|
[586] | 562 | void CGrid::computeIndexScalarGrid() |
---|
[300] | 563 | { |
---|
[586] | 564 | CContext* context = CContext::getCurrent(); |
---|
| 565 | CContextClient* client=context->client; |
---|
| 566 | |
---|
| 567 | storeIndex_client.resize(1); |
---|
| 568 | storeIndex_client[0] = 0; |
---|
| 569 | if (0 == client->clientRank) |
---|
| 570 | { |
---|
| 571 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
| 572 | connectedDataSize_[rank] = 1; |
---|
| 573 | } |
---|
| 574 | isDataDistributed_ = false; |
---|
| 575 | } |
---|
| 576 | |
---|
[676] | 577 | void CGrid::computeCompressedIndex() |
---|
| 578 | { |
---|
| 579 | compressedOutIndexFromClient = outIndexFromClient; |
---|
| 580 | |
---|
| 581 | std::map<size_t, size_t> indexes; |
---|
| 582 | |
---|
| 583 | { |
---|
| 584 | std::map<int, CArray<size_t,1> >::const_iterator it = compressedOutIndexFromClient.begin(); |
---|
| 585 | std::map<int, CArray<size_t,1> >::const_iterator itEnd = compressedOutIndexFromClient.end(); |
---|
| 586 | for (; it != itEnd; ++it) |
---|
| 587 | { |
---|
| 588 | for (int i = 0; i < it->second.numElements(); ++i) |
---|
| 589 | indexes.insert(std::make_pair(it->second(i), 0)); |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | { |
---|
| 594 | std::map<size_t, size_t>::iterator it = indexes.begin(); |
---|
| 595 | std::map<size_t, size_t>::iterator itEnd = indexes.end(); |
---|
| 596 | for (size_t i = 0; it != itEnd; ++it, ++i) |
---|
| 597 | it->second = i; |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | { |
---|
| 601 | std::map<int, CArray<size_t,1> >::iterator it = compressedOutIndexFromClient.begin(); |
---|
| 602 | std::map<int, CArray<size_t,1> >::iterator itEnd = compressedOutIndexFromClient.end(); |
---|
| 603 | for (; it != itEnd; ++it) |
---|
| 604 | { |
---|
| 605 | for (int i = 0; i < it->second.numElements(); ++i) |
---|
| 606 | it->second(i) = indexes[it->second(i)]; |
---|
| 607 | } |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | |
---|
[586] | 611 | void CGrid::sendIndexScalarGrid() |
---|
| 612 | { |
---|
[650] | 613 | CContext* context = CContext::getCurrent(); |
---|
| 614 | CContextClient* client = context->client; |
---|
[509] | 615 | |
---|
[650] | 616 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 617 | list<CMessage> listMsg; |
---|
| 618 | list<CArray<size_t,1> > listOutIndex; |
---|
| 619 | |
---|
[586] | 620 | if (0 == client->clientRank) |
---|
[551] | 621 | { |
---|
[586] | 622 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
[551] | 623 | { |
---|
[586] | 624 | int nb = 1; |
---|
[650] | 625 | storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(nb))); |
---|
| 626 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
| 627 | |
---|
| 628 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; |
---|
| 629 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
| 630 | |
---|
[586] | 631 | for (int k = 0; k < nb; ++k) |
---|
[567] | 632 | { |
---|
[586] | 633 | outGlobalIndexOnServer(k) = 0; |
---|
| 634 | outLocalIndexToServer(k) = 0; |
---|
[584] | 635 | } |
---|
[586] | 636 | |
---|
[650] | 637 | listMsg.push_back(CMessage()); |
---|
[676] | 638 | listMsg.back() << getId( )<< isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[586] | 639 | |
---|
[650] | 640 | event.push(rank, 1, listMsg.back()); |
---|
| 641 | } |
---|
[586] | 642 | |
---|
| 643 | client->sendEvent(event); |
---|
[584] | 644 | } |
---|
[586] | 645 | else |
---|
| 646 | client->sendEvent(event); |
---|
| 647 | } |
---|
[551] | 648 | |
---|
[586] | 649 | void CGrid::sendIndex(void) |
---|
| 650 | { |
---|
[650] | 651 | CContext* context = CContext::getCurrent(); |
---|
| 652 | CContextClient* client = context->client; |
---|
[586] | 653 | |
---|
[650] | 654 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 655 | int rank; |
---|
| 656 | list<CMessage> listMsg; |
---|
| 657 | list<CArray<size_t,1> > listOutIndex; |
---|
[586] | 658 | const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); |
---|
[668] | 659 | const std::vector<int>& localIndexSendToServer = clientDistribution_->getLocalDataIndexSendToServer(); |
---|
| 660 | const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); |
---|
[586] | 661 | |
---|
[584] | 662 | if (!doGridHaveDataDistributed()) |
---|
| 663 | { |
---|
[585] | 664 | if (0 == client->clientRank) |
---|
| 665 | { |
---|
[668] | 666 | CArray<size_t,1> outGlobalIndexOnServer(globalIndexSendToServer.size()); |
---|
| 667 | for (int idx = 0; idx < globalIndexSendToServer.size();++idx) |
---|
| 668 | outGlobalIndexOnServer(idx) = globalIndexSendToServer[idx]; |
---|
[650] | 669 | |
---|
[668] | 670 | CArray<int,1> outLocalIndexToServer(localIndexSendToServer.size()); |
---|
| 671 | for (int idx = 0; idx < localIndexSendToServer.size();++idx) |
---|
| 672 | outLocalIndexToServer(idx) = localIndexSendToServer[idx]; |
---|
| 673 | |
---|
[585] | 674 | for (rank = 0; rank < client->serverSize; ++rank) |
---|
| 675 | { |
---|
[650] | 676 | storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 677 | listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
[585] | 678 | |
---|
[650] | 679 | listMsg.push_back(CMessage()); |
---|
[676] | 680 | listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[585] | 681 | |
---|
[650] | 682 | event.push(rank, 1, listMsg.back()); |
---|
[585] | 683 | } |
---|
[650] | 684 | |
---|
[585] | 685 | client->sendEvent(event); |
---|
| 686 | } |
---|
| 687 | else |
---|
| 688 | client->sendEvent(event); |
---|
[551] | 689 | } |
---|
[567] | 690 | else |
---|
[300] | 691 | { |
---|
[586] | 692 | std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
| 693 | itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); |
---|
| 694 | iteGlobalMap = globalIndexOnServer.end(); |
---|
| 695 | |
---|
[668] | 696 | int nbGlobalIndex = globalIndexSendToServer.size(); |
---|
[586] | 697 | std::map<int,std::vector<int> >localIndexTmp; |
---|
| 698 | std::map<int,std::vector<size_t> > globalIndexTmp; |
---|
[650] | 699 | |
---|
[668] | 700 | typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; |
---|
| 701 | std::vector<int>::iterator itVec; |
---|
[586] | 702 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 703 | { |
---|
| 704 | int serverRank = itGlobalMap->first; |
---|
[668] | 705 | int indexSize = itGlobalMap->second.size(); |
---|
| 706 | std::vector<int> permutIndex(indexSize); |
---|
| 707 | XIOSAlgorithms::fillInIndex(indexSize, permutIndex); |
---|
[671] | 708 | XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(itGlobalMap->second, permutIndex); |
---|
[668] | 709 | BinarySearch binSearch(itGlobalMap->second); |
---|
| 710 | |
---|
[586] | 711 | for (int i = 0; i < nbGlobalIndex; ++i) |
---|
| 712 | { |
---|
[668] | 713 | if (binSearch.search(permutIndex.begin(), permutIndex.end(), globalIndexSendToServer[i], itVec)) |
---|
[586] | 714 | { |
---|
[668] | 715 | globalIndexTmp[serverRank].push_back(globalIndexSendToServer[i]); |
---|
| 716 | localIndexTmp[serverRank].push_back(localIndexSendToServer[i]); |
---|
[586] | 717 | } |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | |
---|
[584] | 721 | for (int ns = 0; ns < connectedServerRank_.size(); ++ns) |
---|
[567] | 722 | { |
---|
[584] | 723 | rank = connectedServerRank_[ns]; |
---|
| 724 | int nb = 0; |
---|
| 725 | if (globalIndexTmp.end() != globalIndexTmp.find(rank)) |
---|
| 726 | nb = globalIndexTmp[rank].size(); |
---|
[509] | 727 | |
---|
[650] | 728 | storeIndex_toSrv.insert(make_pair(rank, CArray<int,1>(nb))); |
---|
| 729 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
| 730 | |
---|
| 731 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; |
---|
| 732 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
| 733 | |
---|
[567] | 734 | for (int k = 0; k < nb; ++k) |
---|
| 735 | { |
---|
[584] | 736 | outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); |
---|
| 737 | outLocalIndexToServer(k) = localIndexTmp[rank].at(k); |
---|
[567] | 738 | } |
---|
[509] | 739 | |
---|
[650] | 740 | listMsg.push_back(CMessage()); |
---|
[676] | 741 | listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[509] | 742 | |
---|
[650] | 743 | event.push(rank, nbSenders[rank], listMsg.back()); |
---|
[567] | 744 | } |
---|
[584] | 745 | |
---|
[567] | 746 | client->sendEvent(event); |
---|
[300] | 747 | } |
---|
| 748 | } |
---|
[509] | 749 | |
---|
[300] | 750 | void CGrid::recvIndex(CEventServer& event) |
---|
| 751 | { |
---|
[598] | 752 | string gridId; |
---|
| 753 | vector<int> ranks; |
---|
| 754 | vector<CBufferIn*> buffers; |
---|
| 755 | |
---|
| 756 | list<CEventServer::SSubEvent>::iterator it; |
---|
[650] | 757 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 758 | { |
---|
[598] | 759 | ranks.push_back(it->rank); |
---|
| 760 | CBufferIn* buffer = it->buffer; |
---|
| 761 | *buffer >> gridId; |
---|
| 762 | buffers.push_back(buffer); |
---|
[300] | 763 | } |
---|
[650] | 764 | get(gridId)->recvIndex(ranks, buffers); |
---|
[300] | 765 | } |
---|
[509] | 766 | |
---|
[567] | 767 | void CGrid::computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 768 | const std::vector<CAxis*>& axis, |
---|
| 769 | const CArray<bool,1>& axisDomainOrder) |
---|
| 770 | { |
---|
| 771 | globalDim_.resize(domains.size()*2+axis.size()); |
---|
| 772 | int idx = 0, idxDomain = 0, idxAxis = 0; |
---|
| 773 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 774 | { |
---|
| 775 | if (axisDomainOrder(i)) |
---|
| 776 | { |
---|
[657] | 777 | if (!(domains[idxDomain]->type.isEmpty()) && (domains[idxDomain]->type==CDomain::type_attr::unstructured)) |
---|
| 778 | { |
---|
| 779 | positionDimensionDistributed_ = idx; |
---|
| 780 | } |
---|
| 781 | else |
---|
| 782 | { |
---|
| 783 | positionDimensionDistributed_ = idx +1; |
---|
| 784 | } |
---|
| 785 | |
---|
[567] | 786 | globalDim_[idx] = domains[idxDomain]->ni_glo.getValue(); |
---|
| 787 | globalDim_[idx+1] = domains[idxDomain]->nj_glo.getValue(); |
---|
[657] | 788 | |
---|
[567] | 789 | ++idxDomain; |
---|
| 790 | idx += 2; |
---|
| 791 | } |
---|
| 792 | else |
---|
| 793 | { |
---|
[666] | 794 | globalDim_[idx] = axis[idxAxis]->n_glo.getValue(); |
---|
[567] | 795 | ++idxAxis; |
---|
| 796 | ++idx; |
---|
| 797 | } |
---|
| 798 | } |
---|
| 799 | } |
---|
| 800 | |
---|
| 801 | std::vector<int> CGrid::getGlobalDimension() |
---|
| 802 | { |
---|
| 803 | return globalDim_; |
---|
| 804 | } |
---|
| 805 | |
---|
[600] | 806 | bool CGrid::isScalarGrid() const |
---|
| 807 | { |
---|
| 808 | return (axisList_.empty() && domList_.empty()); |
---|
| 809 | } |
---|
| 810 | |
---|
[567] | 811 | /*! |
---|
| 812 | Verify whether one server need to write data |
---|
| 813 | There are some cases on which one server has nodata to write. For example, when we |
---|
[650] | 814 | just only want to zoom on a domain. |
---|
[567] | 815 | */ |
---|
| 816 | bool CGrid::doGridHaveDataToWrite() |
---|
| 817 | { |
---|
[624] | 818 | return (0 != writtenDataSize_); |
---|
[567] | 819 | } |
---|
| 820 | |
---|
| 821 | /*! |
---|
| 822 | Return size of data which is written on each server |
---|
| 823 | Whatever dimension of a grid, data which are written on server must be presented as |
---|
[650] | 824 | an one dimension array. |
---|
| 825 | \return size of data written on server |
---|
[567] | 826 | */ |
---|
| 827 | size_t CGrid::getWrittenDataSize() const |
---|
| 828 | { |
---|
| 829 | return writtenDataSize_; |
---|
| 830 | } |
---|
| 831 | |
---|
[676] | 832 | /*! |
---|
| 833 | Returns the number of indexes written by each server. |
---|
| 834 | \return the number of indexes written by each server |
---|
| 835 | */ |
---|
| 836 | int CGrid::getNumberWrittenIndexes() const |
---|
| 837 | { |
---|
| 838 | return numberWrittenIndexes_; |
---|
| 839 | } |
---|
| 840 | |
---|
| 841 | /*! |
---|
| 842 | Returns the total number of indexes written by the servers. |
---|
| 843 | \return the total number of indexes written by the servers |
---|
| 844 | */ |
---|
| 845 | int CGrid::getTotalNumberWrittenIndexes() const |
---|
| 846 | { |
---|
| 847 | return totalNumberWrittenIndexes_; |
---|
| 848 | } |
---|
| 849 | |
---|
| 850 | /*! |
---|
| 851 | Returns the offset of indexes written by each server. |
---|
| 852 | \return the offset of indexes written by each server |
---|
| 853 | */ |
---|
| 854 | int CGrid::getOffsetWrittenIndexes() const |
---|
| 855 | { |
---|
| 856 | return offsetWrittenIndexes_; |
---|
| 857 | } |
---|
| 858 | |
---|
[567] | 859 | const CDistributionServer* CGrid::getDistributionServer() const |
---|
| 860 | { |
---|
| 861 | return serverDistribution_; |
---|
| 862 | } |
---|
| 863 | |
---|
[620] | 864 | const CDistributionClient* CGrid::getDistributionClient() const |
---|
| 865 | { |
---|
| 866 | return clientDistribution_; |
---|
| 867 | } |
---|
| 868 | |
---|
[567] | 869 | bool CGrid::doGridHaveDataDistributed() |
---|
| 870 | { |
---|
[600] | 871 | if (isScalarGrid()) return false; |
---|
[586] | 872 | else |
---|
| 873 | return isDataDistributed_; |
---|
[567] | 874 | } |
---|
| 875 | |
---|
[598] | 876 | void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
[300] | 877 | { |
---|
[598] | 878 | CContext* context = CContext::getCurrent(); |
---|
| 879 | CContextServer* server = context->server; |
---|
[676] | 880 | numberWrittenIndexes_ = totalNumberWrittenIndexes_ = offsetWrittenIndexes_ = 0; |
---|
[586] | 881 | |
---|
[598] | 882 | for (int n = 0; n < ranks.size(); n++) |
---|
[586] | 883 | { |
---|
[598] | 884 | int rank = ranks[n]; |
---|
| 885 | CBufferIn& buffer = *buffers[n]; |
---|
[586] | 886 | |
---|
[676] | 887 | buffer >> isDataDistributed_ >> isCompressible_; |
---|
[598] | 888 | size_t dataSize = 0; |
---|
[586] | 889 | |
---|
[600] | 890 | if (isScalarGrid()) |
---|
[598] | 891 | { |
---|
[676] | 892 | writtenDataSize_ = numberWrittenIndexes_ = totalNumberWrittenIndexes_ = 1; |
---|
[598] | 893 | CArray<size_t,1> outIndex; |
---|
| 894 | buffer >> outIndex; |
---|
[650] | 895 | outIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
[598] | 896 | std::vector<int> nZoomBegin(1,0), nZoomSize(1,1), nGlob(1,1), nZoomBeginGlobal(1,0); |
---|
| 897 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 898 | nZoomBeginGlobal, nGlob); |
---|
| 899 | return; |
---|
| 900 | } |
---|
| 901 | |
---|
| 902 | if (0 == serverDistribution_) |
---|
| 903 | { |
---|
| 904 | int idx = 0, numElement = axis_domain_order.numElements(); |
---|
| 905 | int ssize = numElement; |
---|
| 906 | std::vector<int> indexMap(numElement); |
---|
| 907 | for (int i = 0; i < numElement; ++i) |
---|
| 908 | { |
---|
| 909 | indexMap[i] = idx; |
---|
| 910 | if (true == axis_domain_order(i)) |
---|
| 911 | { |
---|
[567] | 912 | ++ssize; |
---|
| 913 | idx += 2; |
---|
[598] | 914 | } |
---|
| 915 | else |
---|
| 916 | ++idx; |
---|
| 917 | } |
---|
[552] | 918 | |
---|
[598] | 919 | int axisId = 0, domainId = 0; |
---|
| 920 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 921 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 922 | std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize), nZoomBeginGlobal(ssize); |
---|
| 923 | for (int i = 0; i < numElement; ++i) |
---|
| 924 | { |
---|
| 925 | if (axis_domain_order(i)) |
---|
| 926 | { |
---|
| 927 | nZoomBegin[indexMap[i]] = domainList[domainId]->zoom_ibegin_srv; |
---|
| 928 | nZoomSize[indexMap[i]] = domainList[domainId]->zoom_ni_srv; |
---|
[631] | 929 | nZoomBeginGlobal[indexMap[i]] = domainList[domainId]->global_zoom_ibegin; |
---|
[598] | 930 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
[552] | 931 | |
---|
[598] | 932 | nZoomBegin[indexMap[i] + 1] = domainList[domainId]->zoom_jbegin_srv; |
---|
| 933 | nZoomSize[indexMap[i] + 1] = domainList[domainId]->zoom_nj_srv; |
---|
[631] | 934 | nZoomBeginGlobal[indexMap[i] + 1] = domainList[domainId]->global_zoom_jbegin; |
---|
[598] | 935 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
[552] | 936 | ++domainId; |
---|
[598] | 937 | } |
---|
| 938 | else |
---|
| 939 | { |
---|
[567] | 940 | nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin_srv; |
---|
| 941 | nZoomSize[indexMap[i]] = axisList[axisId]->zoom_size_srv; |
---|
[623] | 942 | nZoomBeginGlobal[indexMap[i]] = axisList[axisId]->global_zoom_begin; |
---|
[666] | 943 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
[552] | 944 | ++axisId; |
---|
[598] | 945 | } |
---|
| 946 | } |
---|
| 947 | dataSize = 1; |
---|
| 948 | for (int i = 0; i < nZoomSize.size(); ++i) |
---|
| 949 | dataSize *= nZoomSize[i]; |
---|
[567] | 950 | |
---|
[598] | 951 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 952 | nZoomBeginGlobal, nGlob); |
---|
| 953 | } |
---|
[552] | 954 | |
---|
[598] | 955 | CArray<size_t,1> outIndex; |
---|
| 956 | buffer >> outIndex; |
---|
| 957 | if (isDataDistributed_) |
---|
| 958 | serverDistribution_->computeLocalIndex(outIndex); |
---|
| 959 | else |
---|
| 960 | { |
---|
| 961 | dataSize = outIndex.numElements(); |
---|
| 962 | for (int i = 0; i < outIndex.numElements(); ++i) outIndex(i) = i; |
---|
| 963 | } |
---|
| 964 | writtenDataSize_ += dataSize; |
---|
[586] | 965 | |
---|
[650] | 966 | outIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
[598] | 967 | connectedDataSize_[rank] = outIndex.numElements(); |
---|
[676] | 968 | numberWrittenIndexes_ += outIndex.numElements(); |
---|
[598] | 969 | } |
---|
| 970 | |
---|
[676] | 971 | if (isDataDistributed_) |
---|
| 972 | { |
---|
| 973 | MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
| 974 | MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
| 975 | offsetWrittenIndexes_ -= numberWrittenIndexes_; |
---|
| 976 | } |
---|
| 977 | else |
---|
| 978 | totalNumberWrittenIndexes_ = numberWrittenIndexes_; |
---|
| 979 | |
---|
[598] | 980 | nbSenders = CClientServerMappingDistributed::computeConnectedClients(context->client->serverSize, context->client->clientSize, context->client->intraComm, ranks); |
---|
[300] | 981 | } |
---|
| 982 | |
---|
[540] | 983 | /*! |
---|
| 984 | \brief Dispatch event received from client |
---|
| 985 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 986 | its event type. A new event type should be added in the switch list to make sure |
---|
| 987 | it processed on server side. |
---|
| 988 | \param [in] event: Received message |
---|
| 989 | */ |
---|
[300] | 990 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
| 991 | { |
---|
[509] | 992 | |
---|
[650] | 993 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 994 | else |
---|
| 995 | { |
---|
| 996 | switch(event.type) |
---|
| 997 | { |
---|
| 998 | case EVENT_ID_INDEX : |
---|
[650] | 999 | recvIndex(event); |
---|
| 1000 | return true; |
---|
| 1001 | break; |
---|
[509] | 1002 | |
---|
[540] | 1003 | case EVENT_ID_ADD_DOMAIN : |
---|
[650] | 1004 | recvAddDomain(event); |
---|
| 1005 | return true; |
---|
| 1006 | break; |
---|
[540] | 1007 | |
---|
| 1008 | case EVENT_ID_ADD_AXIS : |
---|
[650] | 1009 | recvAddAxis(event); |
---|
| 1010 | return true; |
---|
| 1011 | break; |
---|
[300] | 1012 | default : |
---|
| 1013 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
[650] | 1014 | << "Unknown Event"); |
---|
| 1015 | return false; |
---|
[300] | 1016 | } |
---|
| 1017 | } |
---|
| 1018 | } |
---|
| 1019 | |
---|
[219] | 1020 | ///--------------------------------------------------------------- |
---|
| 1021 | |
---|
[540] | 1022 | CDomain* CGrid::addDomain(const std::string& id) |
---|
| 1023 | { |
---|
[650] | 1024 | return vDomainGroup_->createChild(id); |
---|
[540] | 1025 | } |
---|
| 1026 | |
---|
| 1027 | CAxis* CGrid::addAxis(const std::string& id) |
---|
| 1028 | { |
---|
[650] | 1029 | return vAxisGroup_->createChild(id); |
---|
[540] | 1030 | } |
---|
| 1031 | |
---|
| 1032 | //! Change virtual field group to a new one |
---|
| 1033 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
| 1034 | { |
---|
| 1035 | this->vDomainGroup_ = newVDomainGroup; |
---|
| 1036 | } |
---|
| 1037 | |
---|
| 1038 | //! Change virtual variable group to new one |
---|
| 1039 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
| 1040 | { |
---|
| 1041 | this->vAxisGroup_ = newVAxisGroup; |
---|
| 1042 | } |
---|
| 1043 | |
---|
| 1044 | //---------------------------------------------------------------- |
---|
| 1045 | //! Create virtual field group, which is done normally on initializing file |
---|
| 1046 | void CGrid::setVirtualDomainGroup(void) |
---|
| 1047 | { |
---|
| 1048 | this->setVirtualDomainGroup(CDomainGroup::create()); |
---|
| 1049 | } |
---|
| 1050 | |
---|
| 1051 | //! Create virtual variable group, which is done normally on initializing file |
---|
| 1052 | void CGrid::setVirtualAxisGroup(void) |
---|
| 1053 | { |
---|
| 1054 | this->setVirtualAxisGroup(CAxisGroup::create()); |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | /*! |
---|
| 1058 | \brief Send a message to create a domain on server side |
---|
| 1059 | \param[in] id String identity of domain that will be created on server |
---|
| 1060 | */ |
---|
| 1061 | void CGrid::sendAddDomain(const string& id) |
---|
| 1062 | { |
---|
[650] | 1063 | CContext* context=CContext::getCurrent(); |
---|
[540] | 1064 | |
---|
| 1065 | if (! context->hasServer ) |
---|
| 1066 | { |
---|
[650] | 1067 | CContextClient* client=context->client; |
---|
[540] | 1068 | |
---|
[650] | 1069 | CEventClient event(this->getType(),EVENT_ID_ADD_DOMAIN); |
---|
[540] | 1070 | if (client->isServerLeader()) |
---|
| 1071 | { |
---|
[650] | 1072 | CMessage msg; |
---|
| 1073 | msg<<this->getId(); |
---|
| 1074 | msg<<id; |
---|
[595] | 1075 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1076 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1077 | event.push(*itRank,1,msg); |
---|
[650] | 1078 | client->sendEvent(event); |
---|
[540] | 1079 | } |
---|
[650] | 1080 | else client->sendEvent(event); |
---|
[540] | 1081 | } |
---|
| 1082 | } |
---|
| 1083 | |
---|
| 1084 | /*! |
---|
| 1085 | \brief Send a message to create an axis on server side |
---|
| 1086 | \param[in] id String identity of axis that will be created on server |
---|
| 1087 | */ |
---|
| 1088 | void CGrid::sendAddAxis(const string& id) |
---|
| 1089 | { |
---|
[650] | 1090 | CContext* context=CContext::getCurrent(); |
---|
[540] | 1091 | |
---|
| 1092 | if (! context->hasServer ) |
---|
| 1093 | { |
---|
[650] | 1094 | CContextClient* client=context->client; |
---|
[540] | 1095 | |
---|
[650] | 1096 | CEventClient event(this->getType(),EVENT_ID_ADD_AXIS); |
---|
[540] | 1097 | if (client->isServerLeader()) |
---|
| 1098 | { |
---|
[650] | 1099 | CMessage msg; |
---|
| 1100 | msg<<this->getId(); |
---|
| 1101 | msg<<id; |
---|
[595] | 1102 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1103 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1104 | event.push(*itRank,1,msg); |
---|
[650] | 1105 | client->sendEvent(event); |
---|
[540] | 1106 | } |
---|
[650] | 1107 | else client->sendEvent(event); |
---|
[540] | 1108 | } |
---|
| 1109 | } |
---|
| 1110 | |
---|
| 1111 | /*! |
---|
| 1112 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 1113 | \param[in] event Received event |
---|
| 1114 | */ |
---|
| 1115 | void CGrid::recvAddDomain(CEventServer& event) |
---|
| 1116 | { |
---|
| 1117 | |
---|
[650] | 1118 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 1119 | string id; |
---|
[650] | 1120 | *buffer >> id; |
---|
| 1121 | get(id)->recvAddDomain(*buffer); |
---|
[540] | 1122 | } |
---|
| 1123 | |
---|
| 1124 | /*! |
---|
| 1125 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 1126 | \param[in] buffer Buffer containing message |
---|
| 1127 | */ |
---|
| 1128 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
| 1129 | { |
---|
[650] | 1130 | string id; |
---|
| 1131 | buffer >> id; |
---|
| 1132 | addDomain(id); |
---|
[540] | 1133 | } |
---|
| 1134 | |
---|
| 1135 | /*! |
---|
| 1136 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 1137 | \param[in] event Received event |
---|
| 1138 | */ |
---|
| 1139 | void CGrid::recvAddAxis(CEventServer& event) |
---|
| 1140 | { |
---|
| 1141 | |
---|
[650] | 1142 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 1143 | string id; |
---|
[650] | 1144 | *buffer >> id; |
---|
| 1145 | get(id)->recvAddAxis(*buffer); |
---|
[540] | 1146 | } |
---|
| 1147 | |
---|
| 1148 | /*! |
---|
| 1149 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 1150 | \param[in] buffer Buffer containing message |
---|
| 1151 | */ |
---|
| 1152 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
| 1153 | { |
---|
[650] | 1154 | string id; |
---|
| 1155 | buffer >> id; |
---|
| 1156 | addAxis(id); |
---|
[540] | 1157 | } |
---|
| 1158 | |
---|
[551] | 1159 | /*! |
---|
| 1160 | \brief Solve domain and axis references |
---|
| 1161 | As field, domain and axis can refer to other domains or axis. In order to inherit correctly |
---|
| 1162 | all attributes from their parents, they should be processed with this function |
---|
| 1163 | \param[in] apply inherit all attributes of parents (true) |
---|
| 1164 | */ |
---|
[540] | 1165 | void CGrid::solveDomainAxisRefInheritance(bool apply) |
---|
| 1166 | { |
---|
| 1167 | CContext* context = CContext::getCurrent(); |
---|
| 1168 | unsigned int vecSize, i; |
---|
| 1169 | std::vector<StdString>::iterator it, itE; |
---|
| 1170 | setDomainList(); |
---|
| 1171 | it = domList_.begin(); itE = domList_.end(); |
---|
| 1172 | for (; it != itE; ++it) |
---|
| 1173 | { |
---|
| 1174 | CDomain* pDom = CDomain::get(*it); |
---|
| 1175 | if (context->hasClient) |
---|
| 1176 | { |
---|
| 1177 | pDom->solveRefInheritance(apply); |
---|
| 1178 | pDom->solveBaseReference(); |
---|
[687] | 1179 | pDom->solveSrcInheritance(); |
---|
[631] | 1180 | pDom->solveInheritanceTransformation(); |
---|
[540] | 1181 | if ((!pDom->domain_ref.isEmpty()) && (pDom->name.isEmpty())) |
---|
| 1182 | pDom->name.setValue(pDom->getBaseDomainReference()->getId()); |
---|
| 1183 | } |
---|
| 1184 | } |
---|
| 1185 | |
---|
| 1186 | setAxisList(); |
---|
| 1187 | it = axisList_.begin(); itE = axisList_.end(); |
---|
| 1188 | for (; it != itE; ++it) |
---|
| 1189 | { |
---|
| 1190 | CAxis* pAxis = CAxis::get(*it); |
---|
| 1191 | if (context->hasClient) |
---|
| 1192 | { |
---|
| 1193 | pAxis->solveRefInheritance(apply); |
---|
| 1194 | pAxis->solveBaseReference(); |
---|
[619] | 1195 | pAxis->solveInheritanceTransformation(); |
---|
[540] | 1196 | if ((!pAxis->axis_ref.isEmpty()) && (pAxis->name.isEmpty())) |
---|
| 1197 | pAxis->name.setValue(pAxis->getBaseAxisReference()->getId()); |
---|
| 1198 | } |
---|
| 1199 | } |
---|
| 1200 | } |
---|
| 1201 | |
---|
[619] | 1202 | bool CGrid::isTransformed() |
---|
| 1203 | { |
---|
| 1204 | return isTransformed_; |
---|
| 1205 | } |
---|
| 1206 | |
---|
| 1207 | void CGrid::setTransformed() |
---|
| 1208 | { |
---|
| 1209 | isTransformed_ = true; |
---|
| 1210 | } |
---|
| 1211 | |
---|
[620] | 1212 | CGridTransformation* CGrid::getTransformations() |
---|
[619] | 1213 | { |
---|
[620] | 1214 | return transformations_; |
---|
[619] | 1215 | } |
---|
| 1216 | |
---|
[687] | 1217 | /*! |
---|
| 1218 | Complete all the necessary (and lacking) attributes of a grid |
---|
| 1219 | This function is similar to gridTransformation but works only (till now) on generate_rectilinear_domain transformation |
---|
| 1220 | */ |
---|
| 1221 | void CGrid::completeGrid(CGrid* transformGridSrc) |
---|
| 1222 | { |
---|
| 1223 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
| 1224 | { |
---|
| 1225 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 1226 | << "Two grids have different dimension size" |
---|
| 1227 | << "Dimension of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 1228 | << "Dimension of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
| 1229 | } |
---|
| 1230 | else |
---|
| 1231 | { |
---|
| 1232 | int ssize = axis_domain_order.numElements(); |
---|
| 1233 | for (int i = 0; i < ssize; ++i) |
---|
| 1234 | if (axis_domain_order(i) != (transformGridSrc->axis_domain_order)(i)) |
---|
| 1235 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 1236 | << "Grids " << this->getId() << " and " << transformGridSrc->getId() |
---|
| 1237 | << " don't have elements in the same order"); |
---|
| 1238 | } |
---|
| 1239 | |
---|
| 1240 | CGridGenerate gridGenerate(this, transformGridSrc); |
---|
| 1241 | gridGenerate.completeGrid(); |
---|
| 1242 | } |
---|
| 1243 | |
---|
[632] | 1244 | void CGrid::transformGrid(CGrid* transformGridSrc) |
---|
[619] | 1245 | { |
---|
[632] | 1246 | if (isTransformed()) return; |
---|
| 1247 | setTransformed(); |
---|
| 1248 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
[619] | 1249 | { |
---|
[632] | 1250 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[619] | 1251 | << "Two grids have different dimension size" |
---|
[650] | 1252 | << "Dimension of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 1253 | << "Dimension of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[619] | 1254 | } |
---|
| 1255 | else |
---|
| 1256 | { |
---|
| 1257 | int ssize = axis_domain_order.numElements(); |
---|
| 1258 | for (int i = 0; i < ssize; ++i) |
---|
[632] | 1259 | if (axis_domain_order(i) != (transformGridSrc->axis_domain_order)(i)) |
---|
| 1260 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[650] | 1261 | << "Grids " << this->getId() << " and " << transformGridSrc->getId() |
---|
[619] | 1262 | << " don't have elements in the same order"); |
---|
| 1263 | } |
---|
| 1264 | |
---|
[632] | 1265 | transformations_ = new CGridTransformation(this, transformGridSrc); |
---|
[622] | 1266 | transformations_->computeAll(); |
---|
[623] | 1267 | |
---|
| 1268 | // Ok, now need to compute index of grid source |
---|
[632] | 1269 | transformGridSrc->checkMaskIndex(false); |
---|
[619] | 1270 | } |
---|
| 1271 | |
---|
[551] | 1272 | /*! |
---|
| 1273 | \brief Get the list of domain pointers |
---|
| 1274 | \return list of domain pointers |
---|
| 1275 | */ |
---|
[540] | 1276 | std::vector<CDomain*> CGrid::getDomains() |
---|
| 1277 | { |
---|
| 1278 | std::vector<CDomain*> domList; |
---|
| 1279 | if (!domList_.empty()) |
---|
| 1280 | { |
---|
| 1281 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
| 1282 | } |
---|
| 1283 | return domList; |
---|
| 1284 | } |
---|
| 1285 | |
---|
[551] | 1286 | /*! |
---|
| 1287 | \brief Get the list of axis pointers |
---|
| 1288 | \return list of axis pointers |
---|
| 1289 | */ |
---|
[540] | 1290 | std::vector<CAxis*> CGrid::getAxis() |
---|
| 1291 | { |
---|
| 1292 | std::vector<CAxis*> aList; |
---|
| 1293 | if (!axisList_.empty()) |
---|
| 1294 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
| 1295 | |
---|
| 1296 | return aList; |
---|
| 1297 | } |
---|
| 1298 | |
---|
[551] | 1299 | /*! |
---|
| 1300 | \brief Set domain(s) of a grid from a list |
---|
| 1301 | \param[in] domains list of domains |
---|
| 1302 | */ |
---|
[540] | 1303 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
| 1304 | { |
---|
| 1305 | if (isDomListSet) return; |
---|
| 1306 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 1307 | if (!domains.empty() && domList.empty()) domList = domains; |
---|
| 1308 | if (!domList.empty()) |
---|
| 1309 | { |
---|
| 1310 | int sizeDom = domList.size(); |
---|
| 1311 | domList_.resize(sizeDom); |
---|
[650] | 1312 | for (int i = 0; i < sizeDom; ++i) |
---|
[540] | 1313 | { |
---|
| 1314 | domList_[i] = domList[i]->getId(); |
---|
| 1315 | } |
---|
| 1316 | isDomListSet = true; |
---|
| 1317 | } |
---|
| 1318 | |
---|
| 1319 | } |
---|
| 1320 | |
---|
[551] | 1321 | /*! |
---|
| 1322 | \brief Set axis(s) of a grid from a list |
---|
| 1323 | \param[in] axis list of axis |
---|
| 1324 | */ |
---|
[540] | 1325 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
| 1326 | { |
---|
| 1327 | if (isAxisListSet) return; |
---|
| 1328 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 1329 | if (!axis.empty() && aList.empty()) aList = axis; |
---|
| 1330 | if (!aList.empty()) |
---|
| 1331 | { |
---|
| 1332 | int sizeAxis = aList.size(); |
---|
| 1333 | axisList_.resize(sizeAxis); |
---|
| 1334 | for (int i = 0; i < sizeAxis; ++i) |
---|
| 1335 | { |
---|
| 1336 | axisList_[i] = aList[i]->getId(); |
---|
| 1337 | } |
---|
| 1338 | isAxisListSet = true; |
---|
| 1339 | } |
---|
| 1340 | } |
---|
| 1341 | |
---|
[551] | 1342 | /*! |
---|
| 1343 | \brief Get list of id of domains |
---|
| 1344 | \return id list of domains |
---|
| 1345 | */ |
---|
[540] | 1346 | std::vector<StdString> CGrid::getDomainList() |
---|
| 1347 | { |
---|
| 1348 | setDomainList(); |
---|
| 1349 | return domList_; |
---|
| 1350 | } |
---|
| 1351 | |
---|
[551] | 1352 | /*! |
---|
| 1353 | \brief Get list of id of axis |
---|
| 1354 | \return id list of axis |
---|
| 1355 | */ |
---|
[540] | 1356 | std::vector<StdString> CGrid::getAxisList() |
---|
| 1357 | { |
---|
| 1358 | setAxisList(); |
---|
| 1359 | return axisList_; |
---|
| 1360 | } |
---|
| 1361 | |
---|
| 1362 | void CGrid::sendAllDomains() |
---|
| 1363 | { |
---|
| 1364 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 1365 | int dSize = domList.size(); |
---|
| 1366 | for (int i = 0; i < dSize; ++i) |
---|
| 1367 | { |
---|
| 1368 | sendAddDomain(domList[i]->getId()); |
---|
| 1369 | domList[i]->sendAllAttributesToServer(); |
---|
| 1370 | } |
---|
| 1371 | } |
---|
| 1372 | |
---|
| 1373 | void CGrid::sendAllAxis() |
---|
| 1374 | { |
---|
| 1375 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 1376 | int aSize = aList.size(); |
---|
| 1377 | |
---|
| 1378 | for (int i = 0; i < aSize; ++i) |
---|
| 1379 | { |
---|
| 1380 | sendAddAxis(aList[i]->getId()); |
---|
| 1381 | aList[i]->sendAllAttributesToServer(); |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | |
---|
[650] | 1385 | void CGrid::parse(xml::CXMLNode& node) |
---|
[540] | 1386 | { |
---|
| 1387 | SuperClass::parse(node); |
---|
[567] | 1388 | |
---|
[551] | 1389 | // List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) |
---|
| 1390 | std::vector<bool> order; |
---|
[540] | 1391 | |
---|
| 1392 | if (node.goToChildElement()) |
---|
| 1393 | { |
---|
| 1394 | StdString domainName("domain"); |
---|
| 1395 | StdString axisName("axis"); |
---|
| 1396 | do |
---|
| 1397 | { |
---|
| 1398 | if (node.getElementName() == domainName) { |
---|
[551] | 1399 | order.push_back(true); |
---|
[540] | 1400 | this->getVirtualDomainGroup()->parseChild(node); |
---|
| 1401 | } |
---|
| 1402 | if (node.getElementName() == axisName) { |
---|
[551] | 1403 | order.push_back(false); |
---|
[540] | 1404 | this->getVirtualAxisGroup()->parseChild(node); |
---|
| 1405 | } |
---|
[650] | 1406 | } while (node.goToNextElement()); |
---|
[540] | 1407 | node.goToParentElement(); |
---|
| 1408 | } |
---|
| 1409 | |
---|
[551] | 1410 | if (!order.empty()) |
---|
[540] | 1411 | { |
---|
[551] | 1412 | int sizeOrd = order.size(); |
---|
[575] | 1413 | axis_domain_order.resize(sizeOrd); |
---|
[540] | 1414 | for (int i = 0; i < sizeOrd; ++i) |
---|
| 1415 | { |
---|
[575] | 1416 | axis_domain_order(i) = order[i]; |
---|
[540] | 1417 | } |
---|
| 1418 | } |
---|
| 1419 | |
---|
| 1420 | setDomainList(); |
---|
| 1421 | setAxisList(); |
---|
| 1422 | } |
---|
[335] | 1423 | } // namespace xios |
---|