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