[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) |
---|
[887] | 28 | , vDomainGroup_(), domList_(), isDomListSet(false) |
---|
| 29 | , vAxisGroup_(), axisList_(), isAxisListSet(false) |
---|
| 30 | , vScalarGroup_(), scalarList_(), isScalarListSet(false) |
---|
[676] | 31 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
| 32 | , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
| 33 | , globalDim_(), connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true), isCompressible_(false) |
---|
| 34 | , transformations_(0), isTransformed_(false) |
---|
[775] | 35 | , axisPositionInGrid_(), positionDimensionDistributed_(1), hasDomainAxisBaseRef_(false) |
---|
[890] | 36 | , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_() |
---|
[540] | 37 | { |
---|
| 38 | setVirtualDomainGroup(); |
---|
| 39 | setVirtualAxisGroup(); |
---|
[887] | 40 | setVirtualScalarGroup(); |
---|
[540] | 41 | } |
---|
[219] | 42 | |
---|
[650] | 43 | CGrid::CGrid(const StdString& id) |
---|
[219] | 44 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
[650] | 45 | , isChecked(false), isDomainAxisChecked(false) |
---|
[887] | 46 | , vDomainGroup_(), domList_(), isDomListSet(false) |
---|
| 47 | , vAxisGroup_(), axisList_(), isAxisListSet(false) |
---|
| 48 | , vScalarGroup_(), scalarList_(), isScalarListSet(false) |
---|
[676] | 49 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
| 50 | , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
| 51 | , globalDim_(), connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true), isCompressible_(false) |
---|
| 52 | , transformations_(0), isTransformed_(false) |
---|
[775] | 53 | , axisPositionInGrid_(), positionDimensionDistributed_(1), hasDomainAxisBaseRef_(false) |
---|
[890] | 54 | , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_() |
---|
[540] | 55 | { |
---|
| 56 | setVirtualDomainGroup(); |
---|
| 57 | setVirtualAxisGroup(); |
---|
[887] | 58 | setVirtualScalarGroup(); |
---|
[540] | 59 | } |
---|
[219] | 60 | |
---|
| 61 | CGrid::~CGrid(void) |
---|
[509] | 62 | { |
---|
[551] | 63 | if (0 != clientDistribution_) delete clientDistribution_; |
---|
[552] | 64 | if (0 != serverDistribution_) delete serverDistribution_; |
---|
[656] | 65 | if (0 != clientServerMap_) delete clientServerMap_; |
---|
[620] | 66 | if (0 != transformations_) delete transformations_; |
---|
[219] | 67 | } |
---|
| 68 | |
---|
| 69 | ///--------------------------------------------------------------- |
---|
| 70 | |
---|
[650] | 71 | StdString CGrid::GetName(void) { return StdString("grid"); } |
---|
| 72 | StdString CGrid::GetDefName(void) { return CGrid::GetName(); } |
---|
| 73 | ENodeType CGrid::GetType(void) { return eGrid; } |
---|
[219] | 74 | |
---|
| 75 | |
---|
| 76 | StdSize CGrid::getDimension(void) const |
---|
| 77 | { |
---|
[650] | 78 | return globalDim_.size(); |
---|
[219] | 79 | } |
---|
| 80 | |
---|
| 81 | //--------------------------------------------------------------- |
---|
| 82 | |
---|
[286] | 83 | StdSize CGrid::getDataSize(void) const |
---|
| 84 | { |
---|
[586] | 85 | StdSize retvalue = 1; |
---|
[600] | 86 | if (!isScalarGrid()) |
---|
| 87 | { |
---|
| 88 | std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); |
---|
| 89 | for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; |
---|
| 90 | } |
---|
| 91 | return retvalue; |
---|
[286] | 92 | } |
---|
| 93 | |
---|
[731] | 94 | /*! |
---|
| 95 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 96 | * |
---|
| 97 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 98 | */ |
---|
| 99 | std::map<int, StdSize> CGrid::getAttributesBufferSize() |
---|
[509] | 100 | { |
---|
[731] | 101 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(); |
---|
[586] | 102 | |
---|
[731] | 103 | // The grid indexes require a similar size as the actual data |
---|
| 104 | std::map<int, StdSize> dataSizes = getDataBufferSize(); |
---|
| 105 | std::map<int, StdSize>::iterator it, itE = dataSizes.end(); |
---|
| 106 | for (it = dataSizes.begin(); it != itE; ++it) |
---|
[509] | 107 | { |
---|
[731] | 108 | it->second += 2 * sizeof(bool); |
---|
| 109 | if (it->second > attributesSizes[it->first]) |
---|
| 110 | attributesSizes[it->first] = it->second; |
---|
[586] | 111 | } |
---|
| 112 | |
---|
[731] | 113 | // Account for the axis attributes |
---|
| 114 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 115 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
[586] | 116 | { |
---|
[731] | 117 | std::map<int, StdSize> axisAttBuffSize = axisList[i]->getAttributesBufferSize(); |
---|
| 118 | for (it = axisAttBuffSize.begin(), itE = axisAttBuffSize.end(); it != itE; ++it) |
---|
[586] | 119 | { |
---|
[731] | 120 | if (it->second > attributesSizes[it->first]) |
---|
| 121 | attributesSizes[it->first] = it->second; |
---|
[586] | 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[731] | 125 | // Account for the domain attributes |
---|
| 126 | std::vector<CDomain*> domList = getDomains(); |
---|
| 127 | for (size_t i = 0; i < domList.size(); ++i) |
---|
[657] | 128 | { |
---|
[731] | 129 | std::map<int, StdSize> domAttBuffSize = domList[i]->getAttributesBufferSize(); |
---|
| 130 | for (it = domAttBuffSize.begin(), itE = domAttBuffSize.end(); it != itE; ++it) |
---|
[657] | 131 | { |
---|
[731] | 132 | if (it->second > attributesSizes[it->first]) |
---|
| 133 | attributesSizes[it->first] = it->second; |
---|
[657] | 134 | } |
---|
| 135 | } |
---|
[742] | 136 | |
---|
[731] | 137 | return attributesSizes; |
---|
| 138 | } |
---|
[657] | 139 | |
---|
[731] | 140 | /*! |
---|
| 141 | * Compute the minimum buffer size required to send the data to the server(s). |
---|
| 142 | * |
---|
| 143 | * \param id the id used to tag the data |
---|
| 144 | * \return A map associating the server rank with its minimum buffer size. |
---|
| 145 | */ |
---|
| 146 | std::map<int, StdSize> CGrid::getDataBufferSize(const std::string& id /*= ""*/) |
---|
| 147 | { |
---|
| 148 | std::map<int, StdSize> dataSizes; |
---|
[739] | 149 | // The record index is sometimes sent along with the data but we always |
---|
| 150 | // include it in the size calculation for the sake of simplicity |
---|
| 151 | const size_t extraSize = CEventClient::headerSize + (id.empty() ? getId() : id).size() + 2 * sizeof(size_t); |
---|
[731] | 152 | |
---|
[764] | 153 | std::map<int, size_t>::const_iterator itEnd = connectedDataSize_.end(); |
---|
| 154 | for (size_t k = 0; k < connectedServerRank_.size(); ++k) |
---|
| 155 | { |
---|
| 156 | int rank = connectedServerRank_[k]; |
---|
| 157 | std::map<int, size_t>::const_iterator it = connectedDataSize_.find(rank); |
---|
| 158 | size_t count = (it != itEnd) ? it->second : 0; |
---|
[731] | 159 | |
---|
[764] | 160 | dataSizes.insert(std::make_pair(rank, extraSize + CArray<double,1>::size(count))); |
---|
| 161 | } |
---|
| 162 | |
---|
[731] | 163 | return dataSizes; |
---|
[509] | 164 | } |
---|
| 165 | |
---|
[657] | 166 | void CGrid::checkAttributesAfterTransformation() |
---|
| 167 | { |
---|
| 168 | setDomainList(); |
---|
| 169 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 170 | if (!domListP.empty()) |
---|
| 171 | { |
---|
| 172 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 173 | { |
---|
| 174 | domListP[i]->checkAttributesOnClientAfterTransformation(); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | } |
---|
[509] | 178 | |
---|
[676] | 179 | //--------------------------------------------------------------- |
---|
| 180 | |
---|
| 181 | /*! |
---|
| 182 | * Test whether the data defined on the grid can be outputted in a compressed way. |
---|
[720] | 183 | * |
---|
[676] | 184 | * \return true if and only if a mask was defined for this grid |
---|
| 185 | */ |
---|
| 186 | bool CGrid::isCompressible(void) const |
---|
| 187 | { |
---|
| 188 | return isCompressible_; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | //--------------------------------------------------------------- |
---|
| 192 | |
---|
| 193 | void CGrid::addRelFileCompressed(const StdString& filename) |
---|
| 194 | { |
---|
| 195 | this->relFilesCompressed.insert(filename); |
---|
| 196 | } |
---|
| 197 | |
---|
| 198 | bool CGrid::isWrittenCompressed(const StdString& filename) const |
---|
| 199 | { |
---|
| 200 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | //--------------------------------------------------------------- |
---|
| 204 | |
---|
[509] | 205 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
[219] | 206 | { |
---|
[509] | 207 | if (this->isDomainAxisChecked) return; |
---|
[369] | 208 | |
---|
[887] | 209 | this->solveScalarRef(areAttributesChecked); |
---|
[584] | 210 | this->solveAxisRef(areAttributesChecked); |
---|
[509] | 211 | this->solveDomainRef(areAttributesChecked); |
---|
[887] | 212 | computeGridGlobalDimension(getDomains(), getAxis(), getScalars(), axis_domain_order); |
---|
[509] | 213 | this->isDomainAxisChecked = areAttributesChecked; |
---|
| 214 | } |
---|
| 215 | |
---|
[775] | 216 | void CGrid::solveDomainAxisBaseRef() |
---|
| 217 | { |
---|
| 218 | if (this->hasDomainAxisBaseRef_) return; |
---|
[887] | 219 | // Account for the scalar attributes |
---|
| 220 | std::vector<CScalar*> scalarList = getScalars(); |
---|
| 221 | for (size_t i = 0; i < scalarList.size(); ++i) |
---|
| 222 | { |
---|
| 223 | scalarList[i]->setAttributesReference(); |
---|
| 224 | } |
---|
| 225 | |
---|
[775] | 226 | // Account for the axis attributes |
---|
| 227 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 228 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
| 229 | { |
---|
[777] | 230 | axisList[i]->setAttributesReference(); |
---|
[775] | 231 | } |
---|
| 232 | |
---|
| 233 | // Account for the domain attributes |
---|
| 234 | std::vector<CDomain*> domList = getDomains(); |
---|
| 235 | for (size_t i = 0; i < domList.size(); ++i) |
---|
| 236 | { |
---|
[777] | 237 | domList[i]->setAttributesReference(); |
---|
[775] | 238 | } |
---|
[887] | 239 | |
---|
[775] | 240 | this->hasDomainAxisBaseRef_ = true; |
---|
| 241 | } |
---|
| 242 | |
---|
[676] | 243 | void CGrid::checkEligibilityForCompressedOutput() |
---|
| 244 | { |
---|
| 245 | // We don't check if the mask is valid here, just if a mask has been defined at this point. |
---|
[817] | 246 | isCompressible_ = !mask_1d.isEmpty() || !mask_2d.isEmpty() || !mask_3d.isEmpty(); |
---|
[676] | 247 | } |
---|
| 248 | |
---|
[509] | 249 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
| 250 | { |
---|
[650] | 251 | CContext* context = CContext::getCurrent(); |
---|
| 252 | CContextClient* client=context->client; |
---|
[509] | 253 | |
---|
[600] | 254 | if (isScalarGrid()) |
---|
[586] | 255 | { |
---|
| 256 | if (context->hasClient) |
---|
| 257 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } |
---|
| 258 | |
---|
| 259 | if (this->isChecked) return; |
---|
| 260 | if (context->hasClient) |
---|
| 261 | { |
---|
| 262 | this->computeIndexScalarGrid(); |
---|
| 263 | } |
---|
| 264 | |
---|
| 265 | this->isChecked = true; |
---|
| 266 | return; |
---|
| 267 | } |
---|
| 268 | |
---|
[509] | 269 | if (context->hasClient) |
---|
[551] | 270 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } |
---|
[509] | 271 | |
---|
| 272 | if (this->isChecked) return; |
---|
| 273 | |
---|
| 274 | if (context->hasClient) |
---|
| 275 | { |
---|
[657] | 276 | this->checkAttributesAfterTransformation(); |
---|
| 277 | this->checkMask(); |
---|
[650] | 278 | this->computeIndex(); |
---|
[509] | 279 | } |
---|
| 280 | this->isChecked = true; |
---|
[219] | 281 | } |
---|
| 282 | |
---|
[821] | 283 | void CGrid::createMask(void) |
---|
| 284 | { |
---|
| 285 | using namespace std; |
---|
| 286 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 287 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 288 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 289 | |
---|
| 290 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
| 291 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->mask_1d); |
---|
| 292 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 293 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
| 294 | |
---|
| 295 | switch (dim) { |
---|
| 296 | case 1: |
---|
| 297 | checkGridMask(mask_1d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 298 | break; |
---|
| 299 | case 2: |
---|
| 300 | checkGridMask(mask_2d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 301 | break; |
---|
| 302 | case 3: |
---|
| 303 | checkGridMask(mask_3d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 304 | break; |
---|
| 305 | default: |
---|
| 306 | break; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | |
---|
[415] | 310 | void CGrid::checkMask(void) |
---|
| 311 | { |
---|
| 312 | using namespace std; |
---|
[567] | 313 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 314 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 315 | int dim = domainP.size() * 2 + axisP.size(); |
---|
[415] | 316 | |
---|
[664] | 317 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
| 318 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->mask_1d); |
---|
[567] | 319 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 320 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
[415] | 321 | |
---|
[567] | 322 | switch (dim) { |
---|
| 323 | case 1: |
---|
[817] | 324 | checkGridMask(mask_1d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 325 | break; |
---|
| 326 | case 2: |
---|
[817] | 327 | checkGridMask(mask_2d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 328 | break; |
---|
| 329 | case 3: |
---|
[817] | 330 | checkGridMask(mask_3d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 331 | break; |
---|
| 332 | // case 4: |
---|
[575] | 333 | // checkGridMask(mask4, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 334 | // break; |
---|
| 335 | // case 5: |
---|
[575] | 336 | // checkGridMask(mask5, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 337 | // break; |
---|
| 338 | // case 6: |
---|
[575] | 339 | // checkGridMask(mask6, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 340 | // break; |
---|
| 341 | // case 7: |
---|
[575] | 342 | // checkGridMask(mask7, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 343 | // break; |
---|
| 344 | default: |
---|
| 345 | break; |
---|
[415] | 346 | } |
---|
| 347 | } |
---|
[623] | 348 | |
---|
| 349 | void CGrid::modifyMask(const CArray<int,1>& indexToModify) |
---|
| 350 | { |
---|
| 351 | using namespace std; |
---|
| 352 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 353 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 354 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 355 | |
---|
| 356 | switch (dim) { |
---|
| 357 | case 1: |
---|
[817] | 358 | modifyGridMask(mask_1d, indexToModify); |
---|
[623] | 359 | break; |
---|
| 360 | case 2: |
---|
[817] | 361 | modifyGridMask(mask_2d, indexToModify); |
---|
[623] | 362 | break; |
---|
| 363 | case 3: |
---|
[817] | 364 | modifyGridMask(mask_3d, indexToModify); |
---|
[623] | 365 | break; |
---|
| 366 | |
---|
| 367 | default: |
---|
| 368 | break; |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | |
---|
[219] | 372 | //--------------------------------------------------------------- |
---|
| 373 | |
---|
[509] | 374 | void CGrid::solveDomainRef(bool sendAtt) |
---|
[219] | 375 | { |
---|
[540] | 376 | setDomainList(); |
---|
[567] | 377 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 378 | if (!domListP.empty()) |
---|
[219] | 379 | { |
---|
[567] | 380 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 381 | { |
---|
| 382 | if (sendAtt) domListP[i]->sendCheckedAttributes(); |
---|
| 383 | else domListP[i]->checkAttributesOnClient(); |
---|
| 384 | } |
---|
[219] | 385 | } |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | //--------------------------------------------------------------- |
---|
| 389 | |
---|
[567] | 390 | void CGrid::solveAxisRef(bool sendAtt) |
---|
[219] | 391 | { |
---|
[540] | 392 | setAxisList(); |
---|
[567] | 393 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 394 | if (!axisListP.empty()) |
---|
[219] | 395 | { |
---|
[567] | 396 | int idx = 0; |
---|
[620] | 397 | axisPositionInGrid_.resize(0); |
---|
[575] | 398 | for (int i = 0; i < axis_domain_order.numElements(); ++i) |
---|
[568] | 399 | { |
---|
[887] | 400 | int elementDimension = axis_domain_order(i); |
---|
| 401 | if (1 == elementDimension) |
---|
[568] | 402 | { |
---|
[620] | 403 | axisPositionInGrid_.push_back(idx); |
---|
[568] | 404 | ++idx; |
---|
| 405 | } |
---|
[887] | 406 | else if (2 == elementDimension) idx += 2; |
---|
[568] | 407 | } |
---|
| 408 | |
---|
[567] | 409 | for (int i = 0; i < axisListP.size(); ++i) |
---|
[540] | 410 | { |
---|
[567] | 411 | if (sendAtt) |
---|
[620] | 412 | axisListP[i]->sendCheckedAttributes(globalDim_,axisPositionInGrid_[i]); |
---|
[567] | 413 | else |
---|
[742] | 414 | axisListP[i]->checkAttributesOnClient(); |
---|
[540] | 415 | } |
---|
[219] | 416 | } |
---|
| 417 | } |
---|
| 418 | |
---|
[887] | 419 | //--------------------------------------------------------------- |
---|
| 420 | |
---|
| 421 | void CGrid::solveScalarRef(bool sendAtt) |
---|
| 422 | { |
---|
| 423 | setScalarList(); |
---|
| 424 | std::vector<CScalar*> scalarListP = this->getScalars(); |
---|
| 425 | if (!scalarListP.empty()) |
---|
| 426 | { |
---|
| 427 | for (int i = 0; i < scalarListP.size(); ++i) |
---|
| 428 | { |
---|
| 429 | /*Nothing to do for now */ |
---|
| 430 | // if (sendAtt) scalarListP[i]->sendCheckedAttributes(); |
---|
| 431 | // else scalarListP[i]->checkAttributesOnClient(); |
---|
| 432 | } |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
[620] | 436 | std::vector<int> CGrid::getAxisPositionInGrid() const |
---|
| 437 | { |
---|
| 438 | return axisPositionInGrid_; |
---|
| 439 | } |
---|
| 440 | |
---|
[219] | 441 | //--------------------------------------------------------------- |
---|
| 442 | |
---|
[865] | 443 | /*! |
---|
| 444 | Compute the global index of grid to send to server as well as the connected server of the current client. |
---|
| 445 | First of all, from the local data on each element of grid, we can calculate their local index which also allows us to know |
---|
| 446 | their global index. We can have a map of global index of grid and local index that each client holds |
---|
| 447 | Then, each client holds a piece of information about the distribution of servers, which permits to compute the connected server(s) |
---|
| 448 | of the current client. |
---|
| 449 | */ |
---|
[219] | 450 | void CGrid::computeIndex(void) |
---|
[509] | 451 | { |
---|
[650] | 452 | CContext* context = CContext::getCurrent(); |
---|
| 453 | CContextClient* client = context->client; |
---|
[553] | 454 | |
---|
| 455 | // First of all, compute distribution on client side |
---|
[551] | 456 | clientDistribution_ = new CDistributionClient(client->clientRank, this); |
---|
[586] | 457 | // Get local data index on client |
---|
[668] | 458 | storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); |
---|
| 459 | int nbStoreIndex = storeIndex_client.numElements(); |
---|
| 460 | for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; |
---|
[586] | 461 | isDataDistributed_= clientDistribution_->isDataDistributed(); |
---|
| 462 | |
---|
| 463 | if (!doGridHaveDataDistributed()) |
---|
| 464 | { |
---|
| 465 | if (0 == client->clientRank) |
---|
| 466 | { |
---|
[668] | 467 | size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); |
---|
[586] | 468 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
| 469 | connectedDataSize_[rank] = ssize; |
---|
| 470 | } |
---|
| 471 | return; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | // Compute mapping between client and server |
---|
[865] | 475 | std::vector<boost::unordered_map<size_t,std::vector<int> > > indexServerOnElement; |
---|
[815] | 476 | CServerDistributionDescription serverDistributionDescription(globalDim_, client->serverSize); |
---|
[865] | 477 | serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, |
---|
| 478 | client->clientRank, |
---|
| 479 | client->clientSize, |
---|
| 480 | axis_domain_order, |
---|
| 481 | positionDimensionDistributed_); |
---|
| 482 | computeIndexByElement(indexServerOnElement, globalIndexOnServer_); |
---|
[553] | 483 | |
---|
[831] | 484 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); |
---|
| 485 | CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; |
---|
[829] | 486 | CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
[865] | 487 | itGlobalMap = itbGlobalMap = globalIndexOnServer_.begin(); |
---|
| 488 | iteGlobalMap = globalIndexOnServer_.end(); |
---|
[584] | 489 | |
---|
[668] | 490 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 491 | { |
---|
| 492 | int serverRank = itGlobalMap->first; |
---|
| 493 | int indexSize = itGlobalMap->second.size(); |
---|
[831] | 494 | const std::vector<size_t>& indexVec = itGlobalMap->second; |
---|
| 495 | for (int idx = 0; idx < indexSize; ++idx) |
---|
[668] | 496 | { |
---|
[831] | 497 | itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); |
---|
| 498 | if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) |
---|
| 499 | { |
---|
| 500 | if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) |
---|
| 501 | connectedDataSize_[serverRank] = 1; |
---|
| 502 | else |
---|
| 503 | ++connectedDataSize_[serverRank]; |
---|
| 504 | } |
---|
[668] | 505 | } |
---|
| 506 | } |
---|
[584] | 507 | |
---|
| 508 | connectedServerRank_.clear(); |
---|
[829] | 509 | for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { |
---|
| 510 | connectedServerRank_.push_back(itGlobalMap->first); |
---|
[668] | 511 | } |
---|
[584] | 512 | |
---|
[668] | 513 | nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
[219] | 514 | } |
---|
| 515 | |
---|
[865] | 516 | /*! |
---|
| 517 | Compute the global of (client) grid to send to server with the global index of each element of grid |
---|
| 518 | Each element of grid has its own global index associated to a groups of server. We only search for the global index of each element whose |
---|
| 519 | server is the same, then calculate the global index of grid. This way can reduce so much the time for executing DHT, which only needs to run |
---|
| 520 | on each element whose size is much smaller than one of whole grid. |
---|
| 521 | \param [in] indexServerOnElement global index of each element and the rank of server associated with these index |
---|
| 522 | \param [out] globalIndexOnServer global index of grid and its corresponding rank of server. |
---|
| 523 | */ |
---|
| 524 | void CGrid::computeIndexByElement(const std::vector<boost::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
| 525 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer) |
---|
| 526 | { |
---|
| 527 | CContext* context = CContext::getCurrent(); |
---|
| 528 | CContextClient* client = context->client; |
---|
| 529 | int serverSize = client->serverSize; |
---|
| 530 | std::vector<CDomain*> domList = getDomains(); |
---|
| 531 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 532 | |
---|
| 533 | // Some pre-calculations of global index on each element of current grid. |
---|
| 534 | int nbElement = axis_domain_order.numElements(); |
---|
| 535 | std::vector<CArray<size_t,1> > globalIndexElement(nbElement); |
---|
[887] | 536 | int domainIdx = 0, axisIdx = 0, scalarIdx = 0; |
---|
[865] | 537 | std::vector<size_t> elementNGlobal(nbElement); |
---|
| 538 | elementNGlobal[0] = 1; |
---|
| 539 | size_t globalSize = 1; |
---|
| 540 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 541 | { |
---|
| 542 | elementNGlobal[idx] = globalSize; |
---|
| 543 | size_t elementSize; |
---|
| 544 | size_t elementGlobalSize = 1; |
---|
[887] | 545 | if (2 == axis_domain_order(idx)) |
---|
[865] | 546 | { |
---|
| 547 | elementSize = domList[domainIdx]->i_index.numElements(); |
---|
| 548 | globalIndexElement[idx].resize(elementSize); |
---|
| 549 | for (int jdx = 0; jdx < elementSize; ++jdx) |
---|
| 550 | { |
---|
| 551 | globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); |
---|
| 552 | } |
---|
| 553 | elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); |
---|
| 554 | ++domainIdx; |
---|
| 555 | } |
---|
[887] | 556 | else if (1 == axis_domain_order(idx)) |
---|
[865] | 557 | { |
---|
| 558 | elementSize = axisList[axisIdx]->index.numElements(); |
---|
| 559 | globalIndexElement[idx].resize(elementSize); |
---|
| 560 | for (int jdx = 0; jdx < elementSize; ++jdx) |
---|
| 561 | { |
---|
| 562 | globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); |
---|
| 563 | } |
---|
| 564 | elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); |
---|
| 565 | ++axisIdx; |
---|
| 566 | } |
---|
[887] | 567 | else |
---|
| 568 | { |
---|
| 569 | globalIndexElement[idx].resize(1); |
---|
| 570 | globalIndexElement[idx](0) = 0; |
---|
| 571 | elementGlobalSize = 1; |
---|
| 572 | } |
---|
[865] | 573 | globalSize *= elementGlobalSize; |
---|
| 574 | } |
---|
| 575 | |
---|
| 576 | std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); |
---|
| 577 | std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); |
---|
| 578 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 579 | { |
---|
| 580 | std::vector<int> nbIndexOnServer(serverSize,0); |
---|
| 581 | const boost::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; |
---|
| 582 | const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; |
---|
| 583 | CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); |
---|
| 584 | clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); |
---|
| 585 | const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); |
---|
| 586 | CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), |
---|
| 587 | ite = globalIndexElementOnServerMap.end(), it; |
---|
| 588 | for (it = itb; it != ite; ++it) |
---|
| 589 | { |
---|
| 590 | const std::vector<int>& tmp = it->second; |
---|
| 591 | for (int i = 0; i < tmp.size(); ++i) |
---|
| 592 | { |
---|
| 593 | ++nbIndexOnServer[tmp[i]]; |
---|
| 594 | } |
---|
| 595 | } |
---|
| 596 | |
---|
| 597 | for (int i = 0; i < serverSize; ++i) |
---|
| 598 | { |
---|
| 599 | if (0 != nbIndexOnServer[i]) |
---|
| 600 | { |
---|
| 601 | globalElementIndexOnServer[idx][i].resize(nbIndexOnServer[i]); |
---|
| 602 | nbIndexOnServer[i] = 0; |
---|
| 603 | elementOnServer[idx][i] = true; |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | |
---|
| 607 | for (it = itb; it != ite; ++it) |
---|
| 608 | { |
---|
| 609 | const std::vector<int>& tmp = it->second; |
---|
| 610 | for (int i = 0; i < tmp.size(); ++i) |
---|
| 611 | { |
---|
| 612 | globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer[tmp[i]]] = it->first; |
---|
| 613 | ++nbIndexOnServer[tmp[i]]; |
---|
| 614 | } |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | // Determine server which contain global source index |
---|
| 619 | std::vector<bool> intersectedProc(serverSize, true); |
---|
| 620 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 621 | { |
---|
| 622 | std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), |
---|
| 623 | intersectedProc.begin(), intersectedProc.begin(), |
---|
| 624 | std::logical_and<bool>()); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | std::vector<int> srcRank; |
---|
| 628 | for (int idx = 0; idx < serverSize; ++idx) |
---|
| 629 | { |
---|
| 630 | if (intersectedProc[idx]) srcRank.push_back(idx); |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | // Compute the global index of grid from global index of each element. |
---|
| 634 | for (int i = 0; i < srcRank.size(); ++i) |
---|
| 635 | { |
---|
| 636 | size_t ssize = 1; |
---|
| 637 | int rankSrc = srcRank[i]; |
---|
| 638 | std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); |
---|
| 639 | std::vector<size_t> currentIndex(nbElement,0); |
---|
| 640 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 641 | { |
---|
| 642 | ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); |
---|
| 643 | globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); |
---|
| 644 | } |
---|
| 645 | globalIndexOnServer[rankSrc].resize(ssize); |
---|
| 646 | |
---|
| 647 | std::vector<int> idxLoop(nbElement,0); |
---|
| 648 | int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); |
---|
| 649 | size_t idx = 0; |
---|
| 650 | while (idx < ssize) |
---|
| 651 | { |
---|
| 652 | for (int ind = 0; ind < nbElement; ++ind) |
---|
| 653 | { |
---|
| 654 | if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) |
---|
| 655 | { |
---|
| 656 | idxLoop[ind] = 0; |
---|
| 657 | ++idxLoop[ind+1]; |
---|
| 658 | } |
---|
| 659 | |
---|
| 660 | currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | for (int ind = 0; ind < innnerLoopSize; ++ind) |
---|
| 664 | { |
---|
| 665 | currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; |
---|
| 666 | size_t globalSrcIndex = 0; |
---|
| 667 | for (int idxElement = 0; idxElement < nbElement; ++idxElement) |
---|
| 668 | { |
---|
| 669 | globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; |
---|
| 670 | } |
---|
| 671 | globalIndexOnServer[rankSrc][idx] = globalSrcIndex; |
---|
| 672 | ++idx; |
---|
| 673 | ++idxLoop[0]; |
---|
| 674 | } |
---|
| 675 | } |
---|
| 676 | } |
---|
| 677 | } |
---|
[219] | 678 | //---------------------------------------------------------------- |
---|
| 679 | |
---|
[347] | 680 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[219] | 681 | { |
---|
[745] | 682 | std::vector<CDomain*> vecDom(1, domain); |
---|
[567] | 683 | std::vector<CAxis*> vecAxis; |
---|
[540] | 684 | |
---|
[745] | 685 | return createGrid(vecDom, vecAxis); |
---|
[219] | 686 | } |
---|
| 687 | |
---|
[347] | 688 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[219] | 689 | { |
---|
[745] | 690 | std::vector<CDomain*> vecDom(1, domain); |
---|
| 691 | std::vector<CAxis*> vecAxis(1, axis); |
---|
[567] | 692 | |
---|
[745] | 693 | return createGrid(vecDom, vecAxis); |
---|
[219] | 694 | } |
---|
| 695 | |
---|
[745] | 696 | CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 697 | const CArray<int,1>& axisDomainOrder) |
---|
[540] | 698 | { |
---|
[887] | 699 | std::vector<CScalar*> vecScalar; |
---|
| 700 | return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); |
---|
[745] | 701 | } |
---|
[540] | 702 | |
---|
[887] | 703 | CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 704 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
| 705 | { |
---|
| 706 | return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); |
---|
| 707 | } |
---|
| 708 | |
---|
[745] | 709 | CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 710 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
[745] | 711 | { |
---|
[887] | 712 | if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 713 | ERROR("CGrid* CGrid::createGrid(...)", |
---|
| 714 | << "The size of axisDomainOrder (" << axisDomainOrder.numElements() |
---|
| 715 | << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); |
---|
| 716 | |
---|
| 717 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); |
---|
[540] | 718 | grid->setDomainList(domains); |
---|
| 719 | grid->setAxisList(axis); |
---|
[887] | 720 | grid->setScalarList(scalars); |
---|
[551] | 721 | |
---|
[745] | 722 | // By default, domains are always the first elements of a grid |
---|
[622] | 723 | if (0 == axisDomainOrder.numElements()) |
---|
[551] | 724 | { |
---|
[887] | 725 | int size = domains.size() + axis.size() + scalars.size(); |
---|
| 726 | int nb = 0; |
---|
[575] | 727 | grid->axis_domain_order.resize(size); |
---|
[551] | 728 | for (int i = 0; i < size; ++i) |
---|
| 729 | { |
---|
[887] | 730 | if (i < domains.size()) { |
---|
| 731 | grid->axis_domain_order(i) = 2; |
---|
| 732 | |
---|
| 733 | } |
---|
| 734 | else if ((scalars.size() < (size-nb)) < size) { |
---|
| 735 | grid->axis_domain_order(i) = 1; |
---|
| 736 | } |
---|
| 737 | else |
---|
| 738 | grid->axis_domain_order(i) = 0; |
---|
| 739 | ++nb; |
---|
[551] | 740 | } |
---|
| 741 | } |
---|
[622] | 742 | else |
---|
| 743 | { |
---|
| 744 | grid->axis_domain_order.resize(axisDomainOrder.numElements()); |
---|
| 745 | grid->axis_domain_order = axisDomainOrder; |
---|
| 746 | } |
---|
[551] | 747 | |
---|
[742] | 748 | grid->solveDomainAxisRefInheritance(true); |
---|
| 749 | |
---|
[650] | 750 | return grid; |
---|
[540] | 751 | } |
---|
| 752 | |
---|
[823] | 753 | CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc) |
---|
| 754 | { |
---|
[887] | 755 | std::vector<CDomain*> domainSrcTmp = gridSrc->getDomains(), domainSrc; |
---|
[823] | 756 | std::vector<CAxis*> axisSrcTmp = gridSrc->getAxis(), axisSrc; |
---|
[887] | 757 | std::vector<CScalar*> scalarSrcTmp = gridSrc->getScalars(), scalarSrc; |
---|
| 758 | |
---|
| 759 | for (int idx = 0; idx < domainSrcTmp.size(); ++idx) |
---|
| 760 | { |
---|
| 761 | CDomain* domain = CDomain::createDomain(); |
---|
| 762 | domain->duplicateAttributes(domainSrcTmp[idx]); |
---|
| 763 | domain->duplicateTransformation(domainSrcTmp[idx]); |
---|
| 764 | domain->solveRefInheritance(true); |
---|
| 765 | domain->solveInheritanceTransformation(); |
---|
| 766 | domainSrc.push_back(domain); |
---|
| 767 | } |
---|
| 768 | |
---|
[823] | 769 | for (int idx = 0; idx < axisSrcTmp.size(); ++idx) |
---|
| 770 | { |
---|
| 771 | CAxis* axis = CAxis::createAxis(); |
---|
| 772 | axis->duplicateAttributes(axisSrcTmp[idx]); |
---|
| 773 | axis->duplicateTransformation(axisSrcTmp[idx]); |
---|
| 774 | axis->solveRefInheritance(true); |
---|
| 775 | axis->solveInheritanceTransformation(); |
---|
| 776 | axisSrc.push_back(axis); |
---|
| 777 | } |
---|
| 778 | |
---|
[887] | 779 | for (int idx = 0; idx < scalarSrcTmp.size(); ++idx) |
---|
[823] | 780 | { |
---|
[887] | 781 | CScalar* scalar = CScalar::createScalar(); |
---|
| 782 | scalar->duplicateAttributes(scalarSrcTmp[idx]); |
---|
| 783 | scalar->duplicateTransformation(scalarSrcTmp[idx]); |
---|
| 784 | scalar->solveRefInheritance(true); |
---|
| 785 | scalar->solveInheritanceTransformation(); |
---|
| 786 | scalarSrc.push_back(scalar); |
---|
[823] | 787 | } |
---|
| 788 | |
---|
[887] | 789 | CGrid* grid = CGrid::createGrid(idNewGrid, domainSrc, axisSrc, scalarSrc, gridSrc->axis_domain_order); |
---|
[823] | 790 | |
---|
| 791 | return grid; |
---|
| 792 | } |
---|
| 793 | |
---|
[745] | 794 | StdString CGrid::generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 795 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
[745] | 796 | { |
---|
[887] | 797 | if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 798 | ERROR("CGrid* CGrid::generateId(...)", |
---|
| 799 | << "The size of axisDomainOrder (" << axisDomainOrder.numElements() |
---|
| 800 | << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); |
---|
| 801 | |
---|
| 802 | std::ostringstream id; |
---|
| 803 | |
---|
[887] | 804 | if (domains.empty() && axis.empty() && !scalars.empty()) |
---|
| 805 | id << "__scalar_"; |
---|
| 806 | |
---|
| 807 | if (0 != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 808 | { |
---|
| 809 | id << "__grid"; |
---|
| 810 | |
---|
| 811 | if (0 == axisDomainOrder.numElements()) |
---|
| 812 | { |
---|
| 813 | for (size_t i = 0; i < domains.size(); ++i) id << "_" << domains[i]->getId(); |
---|
| 814 | for (size_t i = 0; i < axis.size(); ++i) id << "_" << axis[i]->getId(); |
---|
[887] | 815 | for (size_t i = 0; i < scalars.size(); ++i) id << "_" << scalars[i]->getId(); |
---|
[745] | 816 | } |
---|
| 817 | else |
---|
| 818 | { |
---|
[887] | 819 | size_t iDomain = 0, iAxis = 0, iScalar = 0; |
---|
[745] | 820 | for (size_t i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 821 | { |
---|
[887] | 822 | if (2 == axisDomainOrder(i)) |
---|
[745] | 823 | id << "_" << domains[iDomain++]->getId(); |
---|
[887] | 824 | else if (1 == axisDomainOrder(i)) |
---|
| 825 | id << "_" << axis[iAxis++]->getId(); |
---|
[745] | 826 | else |
---|
[887] | 827 | id << "_" << scalars[iScalar++]->getId(); |
---|
[745] | 828 | } |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | id << "__"; |
---|
| 832 | } |
---|
| 833 | |
---|
| 834 | return id.str(); |
---|
| 835 | } |
---|
| 836 | |
---|
[823] | 837 | StdString CGrid::generateId(const CGrid* gridSrc, const CGrid* gridDest) |
---|
| 838 | { |
---|
| 839 | StdString idSrc = gridSrc->getId(); |
---|
| 840 | StdString idDest = gridDest->getId(); |
---|
| 841 | |
---|
| 842 | std::ostringstream id; |
---|
| 843 | id << idSrc << "__" << idDest; |
---|
| 844 | |
---|
| 845 | return id.str(); |
---|
| 846 | } |
---|
| 847 | |
---|
[745] | 848 | //---------------------------------------------------------------- |
---|
| 849 | |
---|
[540] | 850 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
| 851 | { |
---|
[650] | 852 | return this->vDomainGroup_; |
---|
[540] | 853 | } |
---|
| 854 | |
---|
| 855 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
| 856 | { |
---|
[650] | 857 | return this->vAxisGroup_; |
---|
[540] | 858 | } |
---|
| 859 | |
---|
[887] | 860 | CScalarGroup* CGrid::getVirtualScalarGroup() const |
---|
| 861 | { |
---|
| 862 | return this->vScalarGroup_; |
---|
| 863 | } |
---|
| 864 | |
---|
[551] | 865 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, double* field) |
---|
| 866 | { |
---|
[650] | 867 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
[551] | 868 | StdSize numElements = stored.numElements(); |
---|
| 869 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 870 | { |
---|
[650] | 871 | field[out_i(n)] = stored(n); |
---|
[551] | 872 | } |
---|
| 873 | } |
---|
| 874 | |
---|
[599] | 875 | void CGrid::inputField(int rank, const double* const field, CArray<double,1>& stored) |
---|
| 876 | { |
---|
[650] | 877 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
[599] | 878 | StdSize numElements = stored.numElements(); |
---|
| 879 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 880 | { |
---|
[650] | 881 | stored(n) = field[out_i(n)]; |
---|
[599] | 882 | } |
---|
| 883 | } |
---|
| 884 | |
---|
[676] | 885 | void CGrid::outputCompressedField(int rank, const CArray<double,1>& stored, double* field) |
---|
| 886 | { |
---|
| 887 | const CArray<size_t,1>& out_i = compressedOutIndexFromClient[rank]; |
---|
| 888 | StdSize numElements = stored.numElements(); |
---|
| 889 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 890 | { |
---|
| 891 | field[out_i(n)] = stored(n); |
---|
| 892 | } |
---|
| 893 | } |
---|
| 894 | |
---|
[219] | 895 | //---------------------------------------------------------------- |
---|
| 896 | |
---|
[650] | 897 | void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored) const |
---|
[219] | 898 | { |
---|
[650] | 899 | const StdSize size = storeIndex_client.numElements(); |
---|
[300] | 900 | |
---|
[650] | 901 | stored.resize(size); |
---|
| 902 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; |
---|
[219] | 903 | } |
---|
[509] | 904 | |
---|
[650] | 905 | void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data) const |
---|
[593] | 906 | { |
---|
[650] | 907 | const StdSize size = storeIndex_client.numElements(); |
---|
[593] | 908 | |
---|
[650] | 909 | for(StdSize i = 0; i < size; i++) data[storeIndex_client(i)] = stored(i); |
---|
[593] | 910 | } |
---|
| 911 | |
---|
[586] | 912 | void CGrid::computeIndexScalarGrid() |
---|
[300] | 913 | { |
---|
[586] | 914 | CContext* context = CContext::getCurrent(); |
---|
| 915 | CContextClient* client=context->client; |
---|
| 916 | |
---|
| 917 | storeIndex_client.resize(1); |
---|
[857] | 918 | storeIndex_client(0) = 0; |
---|
[586] | 919 | if (0 == client->clientRank) |
---|
| 920 | { |
---|
| 921 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
| 922 | connectedDataSize_[rank] = 1; |
---|
| 923 | } |
---|
| 924 | isDataDistributed_ = false; |
---|
| 925 | } |
---|
| 926 | |
---|
[676] | 927 | void CGrid::computeCompressedIndex() |
---|
| 928 | { |
---|
| 929 | compressedOutIndexFromClient = outIndexFromClient; |
---|
| 930 | |
---|
| 931 | std::map<size_t, size_t> indexes; |
---|
| 932 | |
---|
| 933 | { |
---|
| 934 | std::map<int, CArray<size_t,1> >::const_iterator it = compressedOutIndexFromClient.begin(); |
---|
| 935 | std::map<int, CArray<size_t,1> >::const_iterator itEnd = compressedOutIndexFromClient.end(); |
---|
| 936 | for (; it != itEnd; ++it) |
---|
| 937 | { |
---|
| 938 | for (int i = 0; i < it->second.numElements(); ++i) |
---|
| 939 | indexes.insert(std::make_pair(it->second(i), 0)); |
---|
| 940 | } |
---|
| 941 | } |
---|
| 942 | |
---|
| 943 | { |
---|
| 944 | std::map<size_t, size_t>::iterator it = indexes.begin(); |
---|
| 945 | std::map<size_t, size_t>::iterator itEnd = indexes.end(); |
---|
| 946 | for (size_t i = 0; it != itEnd; ++it, ++i) |
---|
| 947 | it->second = i; |
---|
| 948 | } |
---|
| 949 | |
---|
| 950 | { |
---|
| 951 | std::map<int, CArray<size_t,1> >::iterator it = compressedOutIndexFromClient.begin(); |
---|
| 952 | std::map<int, CArray<size_t,1> >::iterator itEnd = compressedOutIndexFromClient.end(); |
---|
| 953 | for (; it != itEnd; ++it) |
---|
| 954 | { |
---|
| 955 | for (int i = 0; i < it->second.numElements(); ++i) |
---|
| 956 | it->second(i) = indexes[it->second(i)]; |
---|
| 957 | } |
---|
| 958 | } |
---|
| 959 | } |
---|
| 960 | |
---|
[586] | 961 | void CGrid::sendIndexScalarGrid() |
---|
| 962 | { |
---|
[650] | 963 | CContext* context = CContext::getCurrent(); |
---|
| 964 | CContextClient* client = context->client; |
---|
[509] | 965 | |
---|
[650] | 966 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 967 | list<CMessage> listMsg; |
---|
| 968 | list<CArray<size_t,1> > listOutIndex; |
---|
| 969 | |
---|
[586] | 970 | if (0 == client->clientRank) |
---|
[551] | 971 | { |
---|
[586] | 972 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
[551] | 973 | { |
---|
[586] | 974 | int nb = 1; |
---|
[650] | 975 | storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(nb))); |
---|
| 976 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
| 977 | |
---|
| 978 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; |
---|
| 979 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
| 980 | |
---|
[586] | 981 | for (int k = 0; k < nb; ++k) |
---|
[567] | 982 | { |
---|
[586] | 983 | outGlobalIndexOnServer(k) = 0; |
---|
| 984 | outLocalIndexToServer(k) = 0; |
---|
[584] | 985 | } |
---|
[586] | 986 | |
---|
[650] | 987 | listMsg.push_back(CMessage()); |
---|
[676] | 988 | listMsg.back() << getId( )<< isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[586] | 989 | |
---|
[650] | 990 | event.push(rank, 1, listMsg.back()); |
---|
| 991 | } |
---|
[586] | 992 | |
---|
| 993 | client->sendEvent(event); |
---|
[584] | 994 | } |
---|
[586] | 995 | else |
---|
| 996 | client->sendEvent(event); |
---|
| 997 | } |
---|
[551] | 998 | |
---|
[586] | 999 | void CGrid::sendIndex(void) |
---|
| 1000 | { |
---|
[650] | 1001 | CContext* context = CContext::getCurrent(); |
---|
| 1002 | CContextClient* client = context->client; |
---|
[586] | 1003 | |
---|
[650] | 1004 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 1005 | int rank; |
---|
| 1006 | list<CMessage> listMsg; |
---|
| 1007 | list<CArray<size_t,1> > listOutIndex; |
---|
[831] | 1008 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); |
---|
| 1009 | CDistributionClient::GlobalLocalDataMap::const_iterator itIndex = globalLocalIndexSendToServer.begin(), |
---|
| 1010 | iteIndex = globalLocalIndexSendToServer.end(); |
---|
[586] | 1011 | |
---|
[584] | 1012 | if (!doGridHaveDataDistributed()) |
---|
| 1013 | { |
---|
[585] | 1014 | if (0 == client->clientRank) |
---|
| 1015 | { |
---|
[831] | 1016 | int indexSize = globalLocalIndexSendToServer.size(); |
---|
| 1017 | CArray<size_t,1> outGlobalIndexOnServer(indexSize); |
---|
| 1018 | CArray<int,1> outLocalIndexToServer(indexSize); |
---|
| 1019 | for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) |
---|
| 1020 | { |
---|
| 1021 | outGlobalIndexOnServer(idx) = itIndex->first; |
---|
| 1022 | outLocalIndexToServer(idx) = itIndex->second; |
---|
| 1023 | } |
---|
[650] | 1024 | |
---|
[585] | 1025 | for (rank = 0; rank < client->serverSize; ++rank) |
---|
| 1026 | { |
---|
[650] | 1027 | storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1028 | listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
[585] | 1029 | |
---|
[650] | 1030 | listMsg.push_back(CMessage()); |
---|
[676] | 1031 | listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[585] | 1032 | |
---|
[650] | 1033 | event.push(rank, 1, listMsg.back()); |
---|
[585] | 1034 | } |
---|
[650] | 1035 | |
---|
[585] | 1036 | client->sendEvent(event); |
---|
| 1037 | } |
---|
| 1038 | else |
---|
| 1039 | client->sendEvent(event); |
---|
[551] | 1040 | } |
---|
[567] | 1041 | else |
---|
[300] | 1042 | { |
---|
[831] | 1043 | CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; |
---|
[865] | 1044 | itGlobalMap = globalIndexOnServer_.begin(); |
---|
| 1045 | iteGlobalMap = globalIndexOnServer_.end(); |
---|
[586] | 1046 | |
---|
| 1047 | std::map<int,std::vector<int> >localIndexTmp; |
---|
| 1048 | std::map<int,std::vector<size_t> > globalIndexTmp; |
---|
| 1049 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 1050 | { |
---|
| 1051 | int serverRank = itGlobalMap->first; |
---|
[668] | 1052 | int indexSize = itGlobalMap->second.size(); |
---|
[831] | 1053 | const std::vector<size_t>& indexVec = itGlobalMap->second; |
---|
| 1054 | for (int idx = 0; idx < indexSize; ++idx) |
---|
[586] | 1055 | { |
---|
[831] | 1056 | itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); |
---|
| 1057 | if (iteIndex != itIndex) |
---|
[586] | 1058 | { |
---|
[831] | 1059 | globalIndexTmp[serverRank].push_back(itIndex->first); |
---|
| 1060 | localIndexTmp[serverRank].push_back(itIndex->second); |
---|
[586] | 1061 | } |
---|
| 1062 | } |
---|
| 1063 | } |
---|
| 1064 | |
---|
[584] | 1065 | for (int ns = 0; ns < connectedServerRank_.size(); ++ns) |
---|
[567] | 1066 | { |
---|
[584] | 1067 | rank = connectedServerRank_[ns]; |
---|
| 1068 | int nb = 0; |
---|
| 1069 | if (globalIndexTmp.end() != globalIndexTmp.find(rank)) |
---|
| 1070 | nb = globalIndexTmp[rank].size(); |
---|
[509] | 1071 | |
---|
[650] | 1072 | storeIndex_toSrv.insert(make_pair(rank, CArray<int,1>(nb))); |
---|
| 1073 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
| 1074 | |
---|
| 1075 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; |
---|
| 1076 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
| 1077 | |
---|
[567] | 1078 | for (int k = 0; k < nb; ++k) |
---|
| 1079 | { |
---|
[584] | 1080 | outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); |
---|
| 1081 | outLocalIndexToServer(k) = localIndexTmp[rank].at(k); |
---|
[567] | 1082 | } |
---|
[509] | 1083 | |
---|
[650] | 1084 | listMsg.push_back(CMessage()); |
---|
[676] | 1085 | listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[509] | 1086 | |
---|
[650] | 1087 | event.push(rank, nbSenders[rank], listMsg.back()); |
---|
[567] | 1088 | } |
---|
[584] | 1089 | |
---|
[567] | 1090 | client->sendEvent(event); |
---|
[300] | 1091 | } |
---|
| 1092 | } |
---|
[509] | 1093 | |
---|
[300] | 1094 | void CGrid::recvIndex(CEventServer& event) |
---|
| 1095 | { |
---|
[598] | 1096 | string gridId; |
---|
| 1097 | vector<int> ranks; |
---|
| 1098 | vector<CBufferIn*> buffers; |
---|
| 1099 | |
---|
| 1100 | list<CEventServer::SSubEvent>::iterator it; |
---|
[650] | 1101 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 1102 | { |
---|
[598] | 1103 | ranks.push_back(it->rank); |
---|
| 1104 | CBufferIn* buffer = it->buffer; |
---|
| 1105 | *buffer >> gridId; |
---|
| 1106 | buffers.push_back(buffer); |
---|
[300] | 1107 | } |
---|
[650] | 1108 | get(gridId)->recvIndex(ranks, buffers); |
---|
[300] | 1109 | } |
---|
[509] | 1110 | |
---|
[567] | 1111 | void CGrid::computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 1112 | const std::vector<CAxis*>& axis, |
---|
[887] | 1113 | const std::vector<CScalar*>& scalars, |
---|
| 1114 | const CArray<int,1>& axisDomainOrder) |
---|
[567] | 1115 | { |
---|
[887] | 1116 | globalDim_.resize(domains.size()*2+axis.size()+scalars.size()); |
---|
| 1117 | int idx = 0, idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[567] | 1118 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 1119 | { |
---|
[887] | 1120 | if (2 == axisDomainOrder(i)) |
---|
[567] | 1121 | { |
---|
[657] | 1122 | if (!(domains[idxDomain]->type.isEmpty()) && (domains[idxDomain]->type==CDomain::type_attr::unstructured)) |
---|
| 1123 | { |
---|
| 1124 | positionDimensionDistributed_ = idx; |
---|
| 1125 | } |
---|
| 1126 | else |
---|
| 1127 | { |
---|
| 1128 | positionDimensionDistributed_ = idx +1; |
---|
| 1129 | } |
---|
| 1130 | |
---|
[567] | 1131 | globalDim_[idx] = domains[idxDomain]->ni_glo.getValue(); |
---|
| 1132 | globalDim_[idx+1] = domains[idxDomain]->nj_glo.getValue(); |
---|
[657] | 1133 | |
---|
[567] | 1134 | ++idxDomain; |
---|
| 1135 | idx += 2; |
---|
| 1136 | } |
---|
[887] | 1137 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 1138 | { |
---|
[666] | 1139 | globalDim_[idx] = axis[idxAxis]->n_glo.getValue(); |
---|
[567] | 1140 | ++idxAxis; |
---|
| 1141 | ++idx; |
---|
| 1142 | } |
---|
[887] | 1143 | else |
---|
| 1144 | { |
---|
| 1145 | globalDim_[idx] = 1; |
---|
| 1146 | ++idxScalar; |
---|
| 1147 | ++idx; |
---|
| 1148 | } |
---|
[567] | 1149 | } |
---|
| 1150 | } |
---|
| 1151 | |
---|
| 1152 | std::vector<int> CGrid::getGlobalDimension() |
---|
| 1153 | { |
---|
| 1154 | return globalDim_; |
---|
| 1155 | } |
---|
| 1156 | |
---|
[600] | 1157 | bool CGrid::isScalarGrid() const |
---|
| 1158 | { |
---|
| 1159 | return (axisList_.empty() && domList_.empty()); |
---|
| 1160 | } |
---|
| 1161 | |
---|
[567] | 1162 | /*! |
---|
| 1163 | Verify whether one server need to write data |
---|
| 1164 | There are some cases on which one server has nodata to write. For example, when we |
---|
[650] | 1165 | just only want to zoom on a domain. |
---|
[567] | 1166 | */ |
---|
| 1167 | bool CGrid::doGridHaveDataToWrite() |
---|
| 1168 | { |
---|
[624] | 1169 | return (0 != writtenDataSize_); |
---|
[567] | 1170 | } |
---|
| 1171 | |
---|
| 1172 | /*! |
---|
| 1173 | Return size of data which is written on each server |
---|
| 1174 | Whatever dimension of a grid, data which are written on server must be presented as |
---|
[650] | 1175 | an one dimension array. |
---|
| 1176 | \return size of data written on server |
---|
[567] | 1177 | */ |
---|
| 1178 | size_t CGrid::getWrittenDataSize() const |
---|
| 1179 | { |
---|
| 1180 | return writtenDataSize_; |
---|
| 1181 | } |
---|
| 1182 | |
---|
[676] | 1183 | /*! |
---|
| 1184 | Returns the number of indexes written by each server. |
---|
| 1185 | \return the number of indexes written by each server |
---|
| 1186 | */ |
---|
| 1187 | int CGrid::getNumberWrittenIndexes() const |
---|
| 1188 | { |
---|
| 1189 | return numberWrittenIndexes_; |
---|
| 1190 | } |
---|
| 1191 | |
---|
| 1192 | /*! |
---|
| 1193 | Returns the total number of indexes written by the servers. |
---|
| 1194 | \return the total number of indexes written by the servers |
---|
| 1195 | */ |
---|
| 1196 | int CGrid::getTotalNumberWrittenIndexes() const |
---|
| 1197 | { |
---|
| 1198 | return totalNumberWrittenIndexes_; |
---|
| 1199 | } |
---|
| 1200 | |
---|
| 1201 | /*! |
---|
| 1202 | Returns the offset of indexes written by each server. |
---|
| 1203 | \return the offset of indexes written by each server |
---|
| 1204 | */ |
---|
| 1205 | int CGrid::getOffsetWrittenIndexes() const |
---|
| 1206 | { |
---|
| 1207 | return offsetWrittenIndexes_; |
---|
| 1208 | } |
---|
| 1209 | |
---|
[834] | 1210 | CDistributionServer* CGrid::getDistributionServer() |
---|
[567] | 1211 | { |
---|
| 1212 | return serverDistribution_; |
---|
| 1213 | } |
---|
| 1214 | |
---|
[834] | 1215 | CDistributionClient* CGrid::getDistributionClient() |
---|
[620] | 1216 | { |
---|
| 1217 | return clientDistribution_; |
---|
| 1218 | } |
---|
| 1219 | |
---|
[567] | 1220 | bool CGrid::doGridHaveDataDistributed() |
---|
| 1221 | { |
---|
[600] | 1222 | if (isScalarGrid()) return false; |
---|
[586] | 1223 | else |
---|
| 1224 | return isDataDistributed_; |
---|
[567] | 1225 | } |
---|
| 1226 | |
---|
[598] | 1227 | void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
[300] | 1228 | { |
---|
[598] | 1229 | CContext* context = CContext::getCurrent(); |
---|
| 1230 | CContextServer* server = context->server; |
---|
[676] | 1231 | numberWrittenIndexes_ = totalNumberWrittenIndexes_ = offsetWrittenIndexes_ = 0; |
---|
[803] | 1232 | connectedServerRank_ = ranks; |
---|
[586] | 1233 | |
---|
[598] | 1234 | for (int n = 0; n < ranks.size(); n++) |
---|
[586] | 1235 | { |
---|
[598] | 1236 | int rank = ranks[n]; |
---|
| 1237 | CBufferIn& buffer = *buffers[n]; |
---|
[586] | 1238 | |
---|
[676] | 1239 | buffer >> isDataDistributed_ >> isCompressible_; |
---|
[598] | 1240 | size_t dataSize = 0; |
---|
[586] | 1241 | |
---|
[600] | 1242 | if (isScalarGrid()) |
---|
[598] | 1243 | { |
---|
[676] | 1244 | writtenDataSize_ = numberWrittenIndexes_ = totalNumberWrittenIndexes_ = 1; |
---|
[598] | 1245 | CArray<size_t,1> outIndex; |
---|
| 1246 | buffer >> outIndex; |
---|
[650] | 1247 | outIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
[598] | 1248 | std::vector<int> nZoomBegin(1,0), nZoomSize(1,1), nGlob(1,1), nZoomBeginGlobal(1,0); |
---|
| 1249 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 1250 | nZoomBeginGlobal, nGlob); |
---|
| 1251 | return; |
---|
| 1252 | } |
---|
| 1253 | |
---|
| 1254 | if (0 == serverDistribution_) |
---|
| 1255 | { |
---|
| 1256 | int idx = 0, numElement = axis_domain_order.numElements(); |
---|
| 1257 | int ssize = numElement; |
---|
| 1258 | std::vector<int> indexMap(numElement); |
---|
| 1259 | for (int i = 0; i < numElement; ++i) |
---|
| 1260 | { |
---|
| 1261 | indexMap[i] = idx; |
---|
[887] | 1262 | if (2 == axis_domain_order(i)) |
---|
[598] | 1263 | { |
---|
[567] | 1264 | ++ssize; |
---|
| 1265 | idx += 2; |
---|
[598] | 1266 | } |
---|
| 1267 | else |
---|
| 1268 | ++idx; |
---|
| 1269 | } |
---|
[552] | 1270 | |
---|
[887] | 1271 | int axisId = 0, domainId = 0, scalarId = 0; |
---|
[598] | 1272 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 1273 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 1274 | std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize), nZoomBeginGlobal(ssize); |
---|
| 1275 | for (int i = 0; i < numElement; ++i) |
---|
| 1276 | { |
---|
[887] | 1277 | if (2 == axis_domain_order(i)) //domain |
---|
[598] | 1278 | { |
---|
| 1279 | nZoomBegin[indexMap[i]] = domainList[domainId]->zoom_ibegin_srv; |
---|
| 1280 | nZoomSize[indexMap[i]] = domainList[domainId]->zoom_ni_srv; |
---|
[631] | 1281 | nZoomBeginGlobal[indexMap[i]] = domainList[domainId]->global_zoom_ibegin; |
---|
[598] | 1282 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
[552] | 1283 | |
---|
[598] | 1284 | nZoomBegin[indexMap[i] + 1] = domainList[domainId]->zoom_jbegin_srv; |
---|
| 1285 | nZoomSize[indexMap[i] + 1] = domainList[domainId]->zoom_nj_srv; |
---|
[631] | 1286 | nZoomBeginGlobal[indexMap[i] + 1] = domainList[domainId]->global_zoom_jbegin; |
---|
[598] | 1287 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
[552] | 1288 | ++domainId; |
---|
[598] | 1289 | } |
---|
[887] | 1290 | else if (1 == axis_domain_order(i)) // axis |
---|
[598] | 1291 | { |
---|
[567] | 1292 | nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin_srv; |
---|
| 1293 | nZoomSize[indexMap[i]] = axisList[axisId]->zoom_size_srv; |
---|
[623] | 1294 | nZoomBeginGlobal[indexMap[i]] = axisList[axisId]->global_zoom_begin; |
---|
[666] | 1295 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
[552] | 1296 | ++axisId; |
---|
[598] | 1297 | } |
---|
[887] | 1298 | else // scalar |
---|
| 1299 | { |
---|
| 1300 | nZoomBegin[indexMap[i]] = 0; |
---|
| 1301 | nZoomSize[indexMap[i]] = 1; |
---|
| 1302 | nZoomBeginGlobal[indexMap[i]] = 0; |
---|
| 1303 | nGlob[indexMap[i]] = 1; |
---|
| 1304 | ++scalarId; |
---|
| 1305 | } |
---|
[598] | 1306 | } |
---|
| 1307 | dataSize = 1; |
---|
| 1308 | for (int i = 0; i < nZoomSize.size(); ++i) |
---|
| 1309 | dataSize *= nZoomSize[i]; |
---|
[567] | 1310 | |
---|
[598] | 1311 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 1312 | nZoomBeginGlobal, nGlob); |
---|
| 1313 | } |
---|
[552] | 1314 | |
---|
[598] | 1315 | CArray<size_t,1> outIndex; |
---|
| 1316 | buffer >> outIndex; |
---|
| 1317 | if (isDataDistributed_) |
---|
| 1318 | serverDistribution_->computeLocalIndex(outIndex); |
---|
| 1319 | else |
---|
| 1320 | { |
---|
| 1321 | dataSize = outIndex.numElements(); |
---|
| 1322 | for (int i = 0; i < outIndex.numElements(); ++i) outIndex(i) = i; |
---|
| 1323 | } |
---|
| 1324 | writtenDataSize_ += dataSize; |
---|
[586] | 1325 | |
---|
[650] | 1326 | outIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
[598] | 1327 | connectedDataSize_[rank] = outIndex.numElements(); |
---|
[676] | 1328 | numberWrittenIndexes_ += outIndex.numElements(); |
---|
[598] | 1329 | } |
---|
| 1330 | |
---|
[676] | 1331 | if (isDataDistributed_) |
---|
| 1332 | { |
---|
| 1333 | MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
| 1334 | MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
| 1335 | offsetWrittenIndexes_ -= numberWrittenIndexes_; |
---|
| 1336 | } |
---|
| 1337 | else |
---|
| 1338 | totalNumberWrittenIndexes_ = numberWrittenIndexes_; |
---|
| 1339 | |
---|
[598] | 1340 | nbSenders = CClientServerMappingDistributed::computeConnectedClients(context->client->serverSize, context->client->clientSize, context->client->intraComm, ranks); |
---|
[300] | 1341 | } |
---|
| 1342 | |
---|
[540] | 1343 | /*! |
---|
| 1344 | \brief Dispatch event received from client |
---|
| 1345 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 1346 | its event type. A new event type should be added in the switch list to make sure |
---|
| 1347 | it processed on server side. |
---|
| 1348 | \param [in] event: Received message |
---|
| 1349 | */ |
---|
[300] | 1350 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
| 1351 | { |
---|
[509] | 1352 | |
---|
[650] | 1353 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 1354 | else |
---|
| 1355 | { |
---|
| 1356 | switch(event.type) |
---|
| 1357 | { |
---|
| 1358 | case EVENT_ID_INDEX : |
---|
[650] | 1359 | recvIndex(event); |
---|
| 1360 | return true; |
---|
| 1361 | break; |
---|
[509] | 1362 | |
---|
[540] | 1363 | case EVENT_ID_ADD_DOMAIN : |
---|
[650] | 1364 | recvAddDomain(event); |
---|
| 1365 | return true; |
---|
| 1366 | break; |
---|
[540] | 1367 | |
---|
| 1368 | case EVENT_ID_ADD_AXIS : |
---|
[650] | 1369 | recvAddAxis(event); |
---|
| 1370 | return true; |
---|
| 1371 | break; |
---|
[887] | 1372 | |
---|
| 1373 | case EVENT_ID_ADD_SCALAR : |
---|
| 1374 | recvAddScalar(event); |
---|
| 1375 | return true; |
---|
| 1376 | break; |
---|
[300] | 1377 | default : |
---|
| 1378 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
[650] | 1379 | << "Unknown Event"); |
---|
| 1380 | return false; |
---|
[300] | 1381 | } |
---|
| 1382 | } |
---|
| 1383 | } |
---|
| 1384 | |
---|
[219] | 1385 | ///--------------------------------------------------------------- |
---|
| 1386 | |
---|
[540] | 1387 | CDomain* CGrid::addDomain(const std::string& id) |
---|
| 1388 | { |
---|
[887] | 1389 | order_.push_back(2); |
---|
[835] | 1390 | axis_domain_order.resize(order_.size()); |
---|
| 1391 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
[650] | 1392 | return vDomainGroup_->createChild(id); |
---|
[540] | 1393 | } |
---|
| 1394 | |
---|
| 1395 | CAxis* CGrid::addAxis(const std::string& id) |
---|
| 1396 | { |
---|
[887] | 1397 | order_.push_back(1); |
---|
[835] | 1398 | axis_domain_order.resize(order_.size()); |
---|
| 1399 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
[650] | 1400 | return vAxisGroup_->createChild(id); |
---|
[540] | 1401 | } |
---|
| 1402 | |
---|
[887] | 1403 | CScalar* CGrid::addScalar(const std::string& id) |
---|
| 1404 | { |
---|
| 1405 | order_.push_back(0); |
---|
| 1406 | axis_domain_order.resize(order_.size()); |
---|
| 1407 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
| 1408 | return vScalarGroup_->createChild(id); |
---|
| 1409 | } |
---|
| 1410 | |
---|
[540] | 1411 | //! Change virtual field group to a new one |
---|
| 1412 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
| 1413 | { |
---|
| 1414 | this->vDomainGroup_ = newVDomainGroup; |
---|
| 1415 | } |
---|
| 1416 | |
---|
| 1417 | //! Change virtual variable group to new one |
---|
| 1418 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
| 1419 | { |
---|
| 1420 | this->vAxisGroup_ = newVAxisGroup; |
---|
| 1421 | } |
---|
| 1422 | |
---|
[887] | 1423 | //! Change virtual variable group to new one |
---|
| 1424 | void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) |
---|
| 1425 | { |
---|
| 1426 | this->vScalarGroup_ = newVScalarGroup; |
---|
| 1427 | } |
---|
| 1428 | |
---|
[540] | 1429 | //---------------------------------------------------------------- |
---|
| 1430 | //! Create virtual field group, which is done normally on initializing file |
---|
| 1431 | void CGrid::setVirtualDomainGroup(void) |
---|
| 1432 | { |
---|
| 1433 | this->setVirtualDomainGroup(CDomainGroup::create()); |
---|
| 1434 | } |
---|
| 1435 | |
---|
| 1436 | //! Create virtual variable group, which is done normally on initializing file |
---|
| 1437 | void CGrid::setVirtualAxisGroup(void) |
---|
| 1438 | { |
---|
| 1439 | this->setVirtualAxisGroup(CAxisGroup::create()); |
---|
| 1440 | } |
---|
| 1441 | |
---|
[887] | 1442 | //! Create virtual variable group, which is done normally on initializing file |
---|
| 1443 | void CGrid::setVirtualScalarGroup(void) |
---|
| 1444 | { |
---|
| 1445 | this->setVirtualScalarGroup(CScalarGroup::create()); |
---|
| 1446 | } |
---|
| 1447 | |
---|
[540] | 1448 | /*! |
---|
| 1449 | \brief Send a message to create a domain on server side |
---|
| 1450 | \param[in] id String identity of domain that will be created on server |
---|
| 1451 | */ |
---|
| 1452 | void CGrid::sendAddDomain(const string& id) |
---|
| 1453 | { |
---|
[650] | 1454 | CContext* context=CContext::getCurrent(); |
---|
[540] | 1455 | |
---|
| 1456 | if (! context->hasServer ) |
---|
| 1457 | { |
---|
[650] | 1458 | CContextClient* client=context->client; |
---|
[540] | 1459 | |
---|
[650] | 1460 | CEventClient event(this->getType(),EVENT_ID_ADD_DOMAIN); |
---|
[540] | 1461 | if (client->isServerLeader()) |
---|
| 1462 | { |
---|
[650] | 1463 | CMessage msg; |
---|
| 1464 | msg<<this->getId(); |
---|
| 1465 | msg<<id; |
---|
[595] | 1466 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1467 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1468 | event.push(*itRank,1,msg); |
---|
[650] | 1469 | client->sendEvent(event); |
---|
[540] | 1470 | } |
---|
[650] | 1471 | else client->sendEvent(event); |
---|
[540] | 1472 | } |
---|
| 1473 | } |
---|
| 1474 | |
---|
| 1475 | /*! |
---|
| 1476 | \brief Send a message to create an axis on server side |
---|
| 1477 | \param[in] id String identity of axis that will be created on server |
---|
| 1478 | */ |
---|
| 1479 | void CGrid::sendAddAxis(const string& id) |
---|
| 1480 | { |
---|
[650] | 1481 | CContext* context=CContext::getCurrent(); |
---|
[540] | 1482 | |
---|
| 1483 | if (! context->hasServer ) |
---|
| 1484 | { |
---|
[650] | 1485 | CContextClient* client=context->client; |
---|
[540] | 1486 | |
---|
[650] | 1487 | CEventClient event(this->getType(),EVENT_ID_ADD_AXIS); |
---|
[540] | 1488 | if (client->isServerLeader()) |
---|
| 1489 | { |
---|
[650] | 1490 | CMessage msg; |
---|
| 1491 | msg<<this->getId(); |
---|
| 1492 | msg<<id; |
---|
[595] | 1493 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1494 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1495 | event.push(*itRank,1,msg); |
---|
[650] | 1496 | client->sendEvent(event); |
---|
[540] | 1497 | } |
---|
[650] | 1498 | else client->sendEvent(event); |
---|
[540] | 1499 | } |
---|
| 1500 | } |
---|
| 1501 | |
---|
| 1502 | /*! |
---|
[887] | 1503 | \brief Send a message to create a scalar on server side |
---|
| 1504 | \param[in] id String identity of scalar that will be created on server |
---|
| 1505 | */ |
---|
| 1506 | void CGrid::sendAddScalar(const string& id) |
---|
| 1507 | { |
---|
| 1508 | CContext* context=CContext::getCurrent(); |
---|
| 1509 | |
---|
| 1510 | if (! context->hasServer ) |
---|
| 1511 | { |
---|
| 1512 | CContextClient* client=context->client; |
---|
| 1513 | |
---|
| 1514 | CEventClient event(this->getType(),EVENT_ID_ADD_SCALAR); |
---|
| 1515 | if (client->isServerLeader()) |
---|
| 1516 | { |
---|
| 1517 | CMessage msg; |
---|
| 1518 | msg<<this->getId(); |
---|
| 1519 | msg<<id; |
---|
| 1520 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1521 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1522 | event.push(*itRank,1,msg); |
---|
| 1523 | client->sendEvent(event); |
---|
| 1524 | } |
---|
| 1525 | else client->sendEvent(event); |
---|
| 1526 | } |
---|
| 1527 | } |
---|
| 1528 | |
---|
| 1529 | /*! |
---|
[540] | 1530 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 1531 | \param[in] event Received event |
---|
| 1532 | */ |
---|
| 1533 | void CGrid::recvAddDomain(CEventServer& event) |
---|
| 1534 | { |
---|
| 1535 | |
---|
[650] | 1536 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 1537 | string id; |
---|
[650] | 1538 | *buffer >> id; |
---|
| 1539 | get(id)->recvAddDomain(*buffer); |
---|
[540] | 1540 | } |
---|
| 1541 | |
---|
| 1542 | /*! |
---|
| 1543 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 1544 | \param[in] buffer Buffer containing message |
---|
| 1545 | */ |
---|
| 1546 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
| 1547 | { |
---|
[650] | 1548 | string id; |
---|
| 1549 | buffer >> id; |
---|
| 1550 | addDomain(id); |
---|
[540] | 1551 | } |
---|
| 1552 | |
---|
| 1553 | /*! |
---|
| 1554 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 1555 | \param[in] event Received event |
---|
| 1556 | */ |
---|
| 1557 | void CGrid::recvAddAxis(CEventServer& event) |
---|
| 1558 | { |
---|
| 1559 | |
---|
[650] | 1560 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 1561 | string id; |
---|
[650] | 1562 | *buffer >> id; |
---|
| 1563 | get(id)->recvAddAxis(*buffer); |
---|
[540] | 1564 | } |
---|
| 1565 | |
---|
| 1566 | /*! |
---|
| 1567 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 1568 | \param[in] buffer Buffer containing message |
---|
| 1569 | */ |
---|
| 1570 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
| 1571 | { |
---|
[650] | 1572 | string id; |
---|
| 1573 | buffer >> id; |
---|
| 1574 | addAxis(id); |
---|
[540] | 1575 | } |
---|
| 1576 | |
---|
[887] | 1577 | /*! |
---|
| 1578 | \brief Receive a message annoucing the creation of an scalar on server side |
---|
| 1579 | \param[in] event Received event |
---|
| 1580 | */ |
---|
| 1581 | void CGrid::recvAddScalar(CEventServer& event) |
---|
| 1582 | { |
---|
| 1583 | |
---|
| 1584 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 1585 | string id; |
---|
| 1586 | *buffer >> id; |
---|
| 1587 | get(id)->recvAddScalar(*buffer); |
---|
| 1588 | } |
---|
| 1589 | |
---|
| 1590 | /*! |
---|
| 1591 | \brief Receive a message annoucing the creation of an scalar on server side |
---|
| 1592 | \param[in] buffer Buffer containing message |
---|
| 1593 | */ |
---|
| 1594 | void CGrid::recvAddScalar(CBufferIn& buffer) |
---|
| 1595 | { |
---|
| 1596 | string id; |
---|
| 1597 | buffer >> id; |
---|
| 1598 | addScalar(id); |
---|
| 1599 | } |
---|
| 1600 | |
---|
[551] | 1601 | /*! |
---|
| 1602 | \brief Solve domain and axis references |
---|
| 1603 | As field, domain and axis can refer to other domains or axis. In order to inherit correctly |
---|
| 1604 | all attributes from their parents, they should be processed with this function |
---|
| 1605 | \param[in] apply inherit all attributes of parents (true) |
---|
| 1606 | */ |
---|
[540] | 1607 | void CGrid::solveDomainAxisRefInheritance(bool apply) |
---|
| 1608 | { |
---|
| 1609 | CContext* context = CContext::getCurrent(); |
---|
| 1610 | unsigned int vecSize, i; |
---|
| 1611 | std::vector<StdString>::iterator it, itE; |
---|
| 1612 | setDomainList(); |
---|
| 1613 | it = domList_.begin(); itE = domList_.end(); |
---|
| 1614 | for (; it != itE; ++it) |
---|
| 1615 | { |
---|
| 1616 | CDomain* pDom = CDomain::get(*it); |
---|
| 1617 | if (context->hasClient) |
---|
| 1618 | { |
---|
| 1619 | pDom->solveRefInheritance(apply); |
---|
[631] | 1620 | pDom->solveInheritanceTransformation(); |
---|
[540] | 1621 | } |
---|
| 1622 | } |
---|
| 1623 | |
---|
| 1624 | setAxisList(); |
---|
| 1625 | it = axisList_.begin(); itE = axisList_.end(); |
---|
| 1626 | for (; it != itE; ++it) |
---|
| 1627 | { |
---|
| 1628 | CAxis* pAxis = CAxis::get(*it); |
---|
| 1629 | if (context->hasClient) |
---|
| 1630 | { |
---|
| 1631 | pAxis->solveRefInheritance(apply); |
---|
[619] | 1632 | pAxis->solveInheritanceTransformation(); |
---|
[540] | 1633 | } |
---|
| 1634 | } |
---|
[887] | 1635 | |
---|
| 1636 | setScalarList(); |
---|
| 1637 | it = scalarList_.begin(); itE = scalarList_.end(); |
---|
| 1638 | for (; it != itE; ++it) |
---|
| 1639 | { |
---|
| 1640 | CScalar* pScalar = CScalar::get(*it); |
---|
| 1641 | if (context->hasClient) |
---|
| 1642 | { |
---|
| 1643 | pScalar->solveRefInheritance(apply); |
---|
| 1644 | pScalar->solveInheritanceTransformation(); |
---|
| 1645 | } |
---|
| 1646 | } |
---|
[540] | 1647 | } |
---|
| 1648 | |
---|
[619] | 1649 | bool CGrid::isTransformed() |
---|
| 1650 | { |
---|
| 1651 | return isTransformed_; |
---|
| 1652 | } |
---|
| 1653 | |
---|
| 1654 | void CGrid::setTransformed() |
---|
| 1655 | { |
---|
| 1656 | isTransformed_ = true; |
---|
| 1657 | } |
---|
| 1658 | |
---|
[620] | 1659 | CGridTransformation* CGrid::getTransformations() |
---|
[619] | 1660 | { |
---|
[620] | 1661 | return transformations_; |
---|
[619] | 1662 | } |
---|
| 1663 | |
---|
[823] | 1664 | void CGrid::addTransGridSource(CGrid* gridSrc) |
---|
| 1665 | { |
---|
| 1666 | if (gridSrc_.end() == gridSrc_.find(gridSrc)) |
---|
| 1667 | gridSrc_.insert(make_pair(gridSrc,make_pair(false,""))); |
---|
| 1668 | } |
---|
| 1669 | |
---|
| 1670 | std::map<CGrid*,std::pair<bool,StdString> >& CGrid::getTransGridSource() |
---|
| 1671 | { |
---|
| 1672 | return gridSrc_; |
---|
| 1673 | } |
---|
| 1674 | |
---|
[687] | 1675 | /*! |
---|
| 1676 | Complete all the necessary (and lacking) attributes of a grid |
---|
| 1677 | This function is similar to gridTransformation but works only (till now) on generate_rectilinear_domain transformation |
---|
| 1678 | */ |
---|
| 1679 | void CGrid::completeGrid(CGrid* transformGridSrc) |
---|
| 1680 | { |
---|
[775] | 1681 | if (0 != transformGridSrc) |
---|
[687] | 1682 | { |
---|
[775] | 1683 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
| 1684 | { |
---|
| 1685 | ERROR("CGrid::completeGrid(CGrid* transformGridSrc)", |
---|
| 1686 | << "Two grids have different dimension size" |
---|
| 1687 | << "Dimension of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 1688 | << "Dimension of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
| 1689 | } |
---|
| 1690 | else |
---|
| 1691 | { |
---|
[887] | 1692 | // int ssize = axis_domain_order.numElements(); |
---|
| 1693 | // for (int i = 0; i < ssize; ++i) |
---|
| 1694 | // if (axis_domain_order(i) != (transformGridSrc->axis_domain_order)(i)) |
---|
| 1695 | // ERROR("CGrid::completeGrid(CGrid* transformGridSrc)", |
---|
| 1696 | // << "Grids " << this->getId() << " and " << transformGridSrc->getId() |
---|
| 1697 | // << " don't have elements in the same order"); |
---|
[775] | 1698 | } |
---|
[687] | 1699 | } |
---|
| 1700 | |
---|
[890] | 1701 | if (isGenerated()) return; |
---|
| 1702 | setGenerated(); |
---|
| 1703 | |
---|
[687] | 1704 | CGridGenerate gridGenerate(this, transformGridSrc); |
---|
| 1705 | gridGenerate.completeGrid(); |
---|
| 1706 | } |
---|
| 1707 | |
---|
[890] | 1708 | bool CGrid::isGenerated() |
---|
| 1709 | { |
---|
| 1710 | return isGenerated_; |
---|
| 1711 | } |
---|
| 1712 | |
---|
| 1713 | void CGrid::setGenerated() |
---|
| 1714 | { |
---|
| 1715 | isGenerated_ = true; |
---|
| 1716 | } |
---|
| 1717 | |
---|
[632] | 1718 | void CGrid::transformGrid(CGrid* transformGridSrc) |
---|
[619] | 1719 | { |
---|
[746] | 1720 | if (!transformGridSrc) |
---|
| 1721 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 1722 | << "Impossible to transform grid '" << getId() << "', the source grid is null."); |
---|
| 1723 | |
---|
[632] | 1724 | if (isTransformed()) return; |
---|
| 1725 | setTransformed(); |
---|
| 1726 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
[619] | 1727 | { |
---|
[632] | 1728 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[619] | 1729 | << "Two grids have different dimension size" |
---|
[650] | 1730 | << "Dimension of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 1731 | << "Dimension of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[619] | 1732 | } |
---|
| 1733 | else |
---|
| 1734 | { |
---|
[887] | 1735 | // int ssize = axis_domain_order.numElements(); |
---|
| 1736 | // for (int i = 0; i < ssize; ++i) |
---|
| 1737 | // if (axis_domain_order(i) != (transformGridSrc->axis_domain_order)(i)) |
---|
| 1738 | // ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 1739 | // << "Grids " << this->getId() << " and " << transformGridSrc->getId() |
---|
| 1740 | // << " don't have elements in the same order"); |
---|
[619] | 1741 | } |
---|
| 1742 | |
---|
[632] | 1743 | transformations_ = new CGridTransformation(this, transformGridSrc); |
---|
[622] | 1744 | transformations_->computeAll(); |
---|
[824] | 1745 | if (0 < transformations_->getNbAlgo()) hasTransform_ = true; |
---|
[623] | 1746 | |
---|
| 1747 | // Ok, now need to compute index of grid source |
---|
[632] | 1748 | transformGridSrc->checkMaskIndex(false); |
---|
[619] | 1749 | } |
---|
| 1750 | |
---|
[824] | 1751 | bool CGrid::hasTransform() |
---|
| 1752 | { |
---|
| 1753 | return hasTransform_; |
---|
| 1754 | } |
---|
| 1755 | |
---|
[551] | 1756 | /*! |
---|
| 1757 | \brief Get the list of domain pointers |
---|
| 1758 | \return list of domain pointers |
---|
| 1759 | */ |
---|
[540] | 1760 | std::vector<CDomain*> CGrid::getDomains() |
---|
| 1761 | { |
---|
| 1762 | std::vector<CDomain*> domList; |
---|
| 1763 | if (!domList_.empty()) |
---|
| 1764 | { |
---|
| 1765 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
| 1766 | } |
---|
| 1767 | return domList; |
---|
| 1768 | } |
---|
| 1769 | |
---|
[551] | 1770 | /*! |
---|
| 1771 | \brief Get the list of axis pointers |
---|
| 1772 | \return list of axis pointers |
---|
| 1773 | */ |
---|
[540] | 1774 | std::vector<CAxis*> CGrid::getAxis() |
---|
| 1775 | { |
---|
| 1776 | std::vector<CAxis*> aList; |
---|
| 1777 | if (!axisList_.empty()) |
---|
| 1778 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
| 1779 | |
---|
| 1780 | return aList; |
---|
| 1781 | } |
---|
| 1782 | |
---|
[551] | 1783 | /*! |
---|
[887] | 1784 | \brief Get the list of axis pointers |
---|
| 1785 | \return list of axis pointers |
---|
| 1786 | */ |
---|
| 1787 | std::vector<CScalar*> CGrid::getScalars() |
---|
| 1788 | { |
---|
| 1789 | std::vector<CScalar*> sList; |
---|
| 1790 | if (!scalarList_.empty()) |
---|
| 1791 | for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); |
---|
| 1792 | |
---|
| 1793 | return sList; |
---|
| 1794 | } |
---|
| 1795 | |
---|
| 1796 | /*! |
---|
[551] | 1797 | \brief Set domain(s) of a grid from a list |
---|
| 1798 | \param[in] domains list of domains |
---|
| 1799 | */ |
---|
[540] | 1800 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
| 1801 | { |
---|
| 1802 | if (isDomListSet) return; |
---|
| 1803 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
[742] | 1804 | if (!domains.empty() && domList.empty()) |
---|
| 1805 | { |
---|
| 1806 | for (int i = 0; i < domains.size(); ++i) |
---|
| 1807 | this->getVirtualDomainGroup()->addChild(domains[i]); |
---|
| 1808 | domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 1809 | } |
---|
| 1810 | |
---|
[540] | 1811 | if (!domList.empty()) |
---|
| 1812 | { |
---|
| 1813 | int sizeDom = domList.size(); |
---|
| 1814 | domList_.resize(sizeDom); |
---|
[650] | 1815 | for (int i = 0; i < sizeDom; ++i) |
---|
[540] | 1816 | { |
---|
| 1817 | domList_[i] = domList[i]->getId(); |
---|
| 1818 | } |
---|
| 1819 | isDomListSet = true; |
---|
| 1820 | } |
---|
| 1821 | |
---|
| 1822 | } |
---|
| 1823 | |
---|
[551] | 1824 | /*! |
---|
| 1825 | \brief Set axis(s) of a grid from a list |
---|
| 1826 | \param[in] axis list of axis |
---|
| 1827 | */ |
---|
[540] | 1828 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
| 1829 | { |
---|
| 1830 | if (isAxisListSet) return; |
---|
| 1831 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
[742] | 1832 | if (!axis.empty() && aList.empty()) |
---|
| 1833 | { |
---|
| 1834 | for (int i = 0; i < axis.size(); ++i) |
---|
| 1835 | this->getVirtualAxisGroup()->addChild(axis[i]); |
---|
| 1836 | aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 1837 | } |
---|
| 1838 | |
---|
[540] | 1839 | if (!aList.empty()) |
---|
| 1840 | { |
---|
| 1841 | int sizeAxis = aList.size(); |
---|
| 1842 | axisList_.resize(sizeAxis); |
---|
| 1843 | for (int i = 0; i < sizeAxis; ++i) |
---|
| 1844 | { |
---|
| 1845 | axisList_[i] = aList[i]->getId(); |
---|
| 1846 | } |
---|
| 1847 | isAxisListSet = true; |
---|
| 1848 | } |
---|
| 1849 | } |
---|
| 1850 | |
---|
[551] | 1851 | /*! |
---|
[887] | 1852 | \brief Set scalar(s) of a grid from a list |
---|
| 1853 | \param[in] scalars list of scalars |
---|
| 1854 | */ |
---|
| 1855 | void CGrid::setScalarList(const std::vector<CScalar*> scalars) |
---|
| 1856 | { |
---|
| 1857 | if (isScalarListSet) return; |
---|
| 1858 | std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 1859 | if (!scalars.empty() && sList.empty()) |
---|
| 1860 | { |
---|
| 1861 | for (int i = 0; i < scalars.size(); ++i) |
---|
| 1862 | this->getVirtualScalarGroup()->addChild(scalars[i]); |
---|
| 1863 | sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 1864 | } |
---|
| 1865 | |
---|
| 1866 | if (!sList.empty()) |
---|
| 1867 | { |
---|
| 1868 | int sizeScalar = sList.size(); |
---|
| 1869 | scalarList_.resize(sizeScalar); |
---|
| 1870 | for (int i = 0; i < sizeScalar; ++i) |
---|
| 1871 | { |
---|
| 1872 | scalarList_[i] = sList[i]->getId(); |
---|
| 1873 | } |
---|
| 1874 | isScalarListSet = true; |
---|
| 1875 | } |
---|
| 1876 | } |
---|
| 1877 | |
---|
| 1878 | /*! |
---|
[551] | 1879 | \brief Get list of id of domains |
---|
| 1880 | \return id list of domains |
---|
| 1881 | */ |
---|
[540] | 1882 | std::vector<StdString> CGrid::getDomainList() |
---|
| 1883 | { |
---|
| 1884 | setDomainList(); |
---|
| 1885 | return domList_; |
---|
| 1886 | } |
---|
| 1887 | |
---|
[551] | 1888 | /*! |
---|
| 1889 | \brief Get list of id of axis |
---|
| 1890 | \return id list of axis |
---|
| 1891 | */ |
---|
[540] | 1892 | std::vector<StdString> CGrid::getAxisList() |
---|
| 1893 | { |
---|
| 1894 | setAxisList(); |
---|
| 1895 | return axisList_; |
---|
| 1896 | } |
---|
| 1897 | |
---|
[887] | 1898 | /*! |
---|
| 1899 | \brief Get list of id of scalar |
---|
| 1900 | \return id list of scalar |
---|
| 1901 | */ |
---|
| 1902 | std::vector<StdString> CGrid::getScalarList() |
---|
| 1903 | { |
---|
| 1904 | setScalarList(); |
---|
| 1905 | return scalarList_; |
---|
| 1906 | } |
---|
| 1907 | |
---|
| 1908 | /*! |
---|
| 1909 | Send all attributes of domains from client to server |
---|
| 1910 | */ |
---|
[540] | 1911 | void CGrid::sendAllDomains() |
---|
| 1912 | { |
---|
| 1913 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 1914 | int dSize = domList.size(); |
---|
| 1915 | for (int i = 0; i < dSize; ++i) |
---|
| 1916 | { |
---|
| 1917 | sendAddDomain(domList[i]->getId()); |
---|
| 1918 | domList[i]->sendAllAttributesToServer(); |
---|
| 1919 | } |
---|
| 1920 | } |
---|
| 1921 | |
---|
[887] | 1922 | /*! |
---|
| 1923 | Send all attributes of axis from client to server |
---|
| 1924 | */ |
---|
[540] | 1925 | void CGrid::sendAllAxis() |
---|
| 1926 | { |
---|
| 1927 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 1928 | int aSize = aList.size(); |
---|
| 1929 | |
---|
| 1930 | for (int i = 0; i < aSize; ++i) |
---|
| 1931 | { |
---|
| 1932 | sendAddAxis(aList[i]->getId()); |
---|
| 1933 | aList[i]->sendAllAttributesToServer(); |
---|
| 1934 | } |
---|
| 1935 | } |
---|
| 1936 | |
---|
[887] | 1937 | /*! |
---|
| 1938 | Send all attributes of scalars from client to server |
---|
| 1939 | */ |
---|
| 1940 | void CGrid::sendAllScalars() |
---|
| 1941 | { |
---|
| 1942 | std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 1943 | int sSize = sList.size(); |
---|
| 1944 | |
---|
| 1945 | for (int i = 0; i < sSize; ++i) |
---|
| 1946 | { |
---|
| 1947 | sendAddScalar(sList[i]->getId()); |
---|
| 1948 | sList[i]->sendAllAttributesToServer(); |
---|
| 1949 | } |
---|
| 1950 | } |
---|
| 1951 | |
---|
| 1952 | /*! |
---|
| 1953 | Parse a grid, for now, it contains only domain, axis and scalar |
---|
| 1954 | */ |
---|
[650] | 1955 | void CGrid::parse(xml::CXMLNode& node) |
---|
[540] | 1956 | { |
---|
| 1957 | SuperClass::parse(node); |
---|
[567] | 1958 | |
---|
[540] | 1959 | if (node.goToChildElement()) |
---|
| 1960 | { |
---|
| 1961 | StdString domainName("domain"); |
---|
| 1962 | StdString axisName("axis"); |
---|
[887] | 1963 | StdString scalarName("scalar"); |
---|
[540] | 1964 | do |
---|
| 1965 | { |
---|
| 1966 | if (node.getElementName() == domainName) { |
---|
[887] | 1967 | order_.push_back(2); |
---|
[540] | 1968 | this->getVirtualDomainGroup()->parseChild(node); |
---|
| 1969 | } |
---|
| 1970 | if (node.getElementName() == axisName) { |
---|
[887] | 1971 | order_.push_back(1); |
---|
[540] | 1972 | this->getVirtualAxisGroup()->parseChild(node); |
---|
| 1973 | } |
---|
[887] | 1974 | if (node.getElementName() == scalarName) { |
---|
| 1975 | order_.push_back(0); |
---|
| 1976 | this->getVirtualScalarGroup()->parseChild(node); |
---|
| 1977 | } |
---|
[650] | 1978 | } while (node.goToNextElement()); |
---|
[540] | 1979 | node.goToParentElement(); |
---|
| 1980 | } |
---|
| 1981 | |
---|
[835] | 1982 | if (!order_.empty()) |
---|
[540] | 1983 | { |
---|
[835] | 1984 | int sizeOrd = order_.size(); |
---|
[575] | 1985 | axis_domain_order.resize(sizeOrd); |
---|
[540] | 1986 | for (int i = 0; i < sizeOrd; ++i) |
---|
| 1987 | { |
---|
[835] | 1988 | axis_domain_order(i) = order_[i]; |
---|
[540] | 1989 | } |
---|
| 1990 | } |
---|
| 1991 | |
---|
| 1992 | setDomainList(); |
---|
| 1993 | setAxisList(); |
---|
[887] | 1994 | setScalarList(); |
---|
[540] | 1995 | } |
---|
[335] | 1996 | } // namespace xios |
---|