[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" |
---|
[1340] | 20 | #include "server.hpp" |
---|
[219] | 21 | |
---|
[335] | 22 | namespace xios { |
---|
[219] | 23 | |
---|
[742] | 24 | /// ////////////////////// Dfinitions ////////////////////// /// |
---|
[219] | 25 | |
---|
| 26 | CGrid::CGrid(void) |
---|
| 27 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
[650] | 28 | , isChecked(false), isDomainAxisChecked(false) |
---|
[887] | 29 | , vDomainGroup_(), domList_(), isDomListSet(false) |
---|
| 30 | , vAxisGroup_(), axisList_(), isAxisListSet(false) |
---|
| 31 | , vScalarGroup_(), scalarList_(), isScalarListSet(false) |
---|
[676] | 32 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
| 33 | , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
[1330] | 34 | , connectedDataSize_(), connectedServerRank_(), connectedServerRankRead_(), connectedDataSizeRead_() |
---|
| 35 | , isDataDistributed_(true), isCompressible_(false) |
---|
[676] | 36 | , transformations_(0), isTransformed_(false) |
---|
[1158] | 37 | , axisPositionInGrid_(), hasDomainAxisBaseRef_(false) |
---|
[890] | 38 | , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_() |
---|
[1129] | 39 | , computedWrittenIndex_(false) |
---|
[1294] | 40 | , clients() |
---|
[2131] | 41 | , nTiles_(0) |
---|
| 42 | , isTiled_(false), isTiledOnly_(false) |
---|
| 43 | , storeTileIndex() |
---|
[540] | 44 | { |
---|
[957] | 45 | setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group")); |
---|
| 46 | setVirtualAxisGroup(CAxisGroup::create(getId() + "_virtual_axis_group")); |
---|
| 47 | setVirtualScalarGroup(CScalarGroup::create(getId() + "_virtual_scalar_group")); |
---|
[540] | 48 | } |
---|
[219] | 49 | |
---|
[650] | 50 | CGrid::CGrid(const StdString& id) |
---|
[219] | 51 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
[650] | 52 | , isChecked(false), isDomainAxisChecked(false) |
---|
[887] | 53 | , vDomainGroup_(), domList_(), isDomListSet(false) |
---|
| 54 | , vAxisGroup_(), axisList_(), isAxisListSet(false) |
---|
| 55 | , vScalarGroup_(), scalarList_(), isScalarListSet(false) |
---|
[676] | 56 | , clientDistribution_(0), isIndexSent(false) , serverDistribution_(0), clientServerMap_(0) |
---|
| 57 | , writtenDataSize_(0), numberWrittenIndexes_(0), totalNumberWrittenIndexes_(0), offsetWrittenIndexes_(0) |
---|
[1330] | 58 | , connectedDataSize_(), connectedServerRank_(), connectedServerRankRead_(), connectedDataSizeRead_() |
---|
| 59 | , isDataDistributed_(true), isCompressible_(false) |
---|
[676] | 60 | , transformations_(0), isTransformed_(false) |
---|
[1158] | 61 | , axisPositionInGrid_(), hasDomainAxisBaseRef_(false) |
---|
[890] | 62 | , gridSrc_(), hasTransform_(false), isGenerated_(false), order_(), globalIndexOnServer_() |
---|
[1129] | 63 | , computedWrittenIndex_(false) |
---|
[1294] | 64 | , clients() |
---|
[2131] | 65 | , nTiles_(0) |
---|
| 66 | , isTiled_(false), isTiledOnly_(false) |
---|
| 67 | , storeTileIndex() |
---|
[540] | 68 | { |
---|
[957] | 69 | setVirtualDomainGroup(CDomainGroup::create(getId() + "_virtual_domain_group")); |
---|
| 70 | setVirtualAxisGroup(CAxisGroup::create(getId() + "_virtual_axis_group")); |
---|
| 71 | setVirtualScalarGroup(CScalarGroup::create(getId() + "_virtual_scalar_group")); |
---|
[540] | 72 | } |
---|
[219] | 73 | |
---|
| 74 | CGrid::~CGrid(void) |
---|
[509] | 75 | { |
---|
[551] | 76 | if (0 != clientDistribution_) delete clientDistribution_; |
---|
[552] | 77 | if (0 != serverDistribution_) delete serverDistribution_; |
---|
[656] | 78 | if (0 != clientServerMap_) delete clientServerMap_; |
---|
[620] | 79 | if (0 != transformations_) delete transformations_; |
---|
[219] | 80 | } |
---|
| 81 | |
---|
| 82 | ///--------------------------------------------------------------- |
---|
| 83 | |
---|
[650] | 84 | StdString CGrid::GetName(void) { return StdString("grid"); } |
---|
| 85 | StdString CGrid::GetDefName(void) { return CGrid::GetName(); } |
---|
| 86 | ENodeType CGrid::GetType(void) { return eGrid; } |
---|
[219] | 87 | |
---|
| 88 | |
---|
[1158] | 89 | StdSize CGrid::getDimension(void) |
---|
[1622] | 90 | TRY |
---|
[219] | 91 | { |
---|
[1158] | 92 | return getGlobalDimension().size(); |
---|
[219] | 93 | } |
---|
[1622] | 94 | CATCH_DUMP_ATTR |
---|
[219] | 95 | |
---|
| 96 | //--------------------------------------------------------------- |
---|
| 97 | |
---|
[286] | 98 | StdSize CGrid::getDataSize(void) const |
---|
[1622] | 99 | TRY |
---|
[286] | 100 | { |
---|
[586] | 101 | StdSize retvalue = 1; |
---|
[600] | 102 | if (!isScalarGrid()) |
---|
| 103 | { |
---|
| 104 | std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); |
---|
[1250] | 105 | for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; |
---|
[600] | 106 | } |
---|
| 107 | return retvalue; |
---|
[286] | 108 | } |
---|
[1622] | 109 | CATCH |
---|
[286] | 110 | |
---|
[2131] | 111 | //--------------------------------------------------------------- |
---|
[731] | 112 | /*! |
---|
[2131] | 113 | * Returns size of tile data |
---|
| 114 | */ |
---|
| 115 | |
---|
| 116 | StdSize CGrid::getTileDataSize(int tileId) |
---|
| 117 | TRY |
---|
| 118 | { |
---|
| 119 | StdSize tileGridSize =1 ; |
---|
| 120 | int numElement = axis_domain_order.numElements(); |
---|
| 121 | |
---|
| 122 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 123 | std::vector<CDomain*> domainListP = this->getDomains(); |
---|
| 124 | |
---|
| 125 | int axisIndex = 0, domIndex = 0; |
---|
| 126 | for (int idx = 0; idx < numElement; ++idx) |
---|
| 127 | { |
---|
| 128 | int eleDim = axis_domain_order(idx); |
---|
| 129 | if (2 == eleDim) |
---|
| 130 | { |
---|
| 131 | tileGridSize *= domainListP[domIndex]->tile_data_ni(tileId); |
---|
| 132 | tileGridSize *= domainListP[domIndex]->tile_data_nj(tileId); |
---|
| 133 | ++domIndex; |
---|
| 134 | } |
---|
| 135 | else if (1 == eleDim) |
---|
| 136 | { |
---|
| 137 | tileGridSize *= axisListP[axisIndex]->n.getValue(); |
---|
| 138 | ++axisIndex; |
---|
| 139 | } |
---|
| 140 | } // loop over grid elements |
---|
| 141 | return tileGridSize; |
---|
| 142 | } |
---|
| 143 | CATCH |
---|
| 144 | |
---|
| 145 | //--------------------------------------------------------------- |
---|
| 146 | /*! |
---|
| 147 | * Returns tile size |
---|
| 148 | */ |
---|
| 149 | |
---|
| 150 | StdSize CGrid::getTileSize(int tileId) |
---|
| 151 | TRY |
---|
| 152 | { |
---|
| 153 | StdSize tileGridSize =1 ; |
---|
| 154 | int numElement = axis_domain_order.numElements(); |
---|
| 155 | |
---|
| 156 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 157 | std::vector<CDomain*> domainListP = this->getDomains(); |
---|
| 158 | |
---|
| 159 | int axisIndex = 0, domIndex = 0; |
---|
| 160 | for (int idx = 0; idx < numElement; ++idx) |
---|
| 161 | { |
---|
| 162 | int eleDim = axis_domain_order(idx); |
---|
| 163 | if (2 == eleDim) |
---|
| 164 | { |
---|
| 165 | tileGridSize *= domainListP[domIndex]->tile_ni(tileId); |
---|
| 166 | tileGridSize *= domainListP[domIndex]->tile_nj(tileId); |
---|
| 167 | ++domIndex; |
---|
| 168 | } |
---|
| 169 | else if (1 == eleDim)// So it's an axis |
---|
| 170 | { |
---|
| 171 | tileGridSize *= axisListP[axisIndex]->n.getValue(); |
---|
| 172 | ++axisIndex; |
---|
| 173 | } |
---|
| 174 | } // loop over grid elements |
---|
| 175 | return tileGridSize; |
---|
| 176 | } |
---|
| 177 | CATCH |
---|
| 178 | |
---|
| 179 | //--------------------------------------------------------------- |
---|
| 180 | |
---|
| 181 | /*! |
---|
[731] | 182 | * Compute the minimum buffer size required to send the attributes to the server(s). |
---|
| 183 | * |
---|
| 184 | * \return A map associating the server rank with its minimum buffer size. |
---|
[1099] | 185 | * TODO: Refactor code |
---|
[731] | 186 | */ |
---|
[1330] | 187 | std::map<int, StdSize> CGrid::getAttributesBufferSize(CContextClient* client, bool bufferForWriting) |
---|
[1622] | 188 | TRY |
---|
[509] | 189 | { |
---|
[1330] | 190 | std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(client); |
---|
[586] | 191 | |
---|
[731] | 192 | // The grid indexes require a similar size as the actual data |
---|
[1330] | 193 | std::map<int, StdSize> dataSizes = getDataBufferSize(client, "", bufferForWriting); |
---|
[1371] | 194 | std::map<int, StdSize>::iterator it, itE = dataSizes.end(); |
---|
| 195 | for (it = dataSizes.begin(); it != itE; ++it) |
---|
| 196 | { |
---|
| 197 | it->second += 2 * sizeof(bool); |
---|
| 198 | if (it->second > attributesSizes[it->first]) |
---|
| 199 | attributesSizes[it->first] = it->second; |
---|
| 200 | } |
---|
[1236] | 201 | |
---|
[731] | 202 | // Account for the axis attributes |
---|
| 203 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 204 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
[586] | 205 | { |
---|
[1371] | 206 | std::map<int, StdSize> axisAttBuffSize = axisList[i]->getAttributesBufferSize(client, getGlobalDimension(),axisPositionInGrid_[i]); |
---|
[731] | 207 | for (it = axisAttBuffSize.begin(), itE = axisAttBuffSize.end(); it != itE; ++it) |
---|
[586] | 208 | { |
---|
[1371] | 209 | it->second += 2 * sizeof(bool); |
---|
[731] | 210 | if (it->second > attributesSizes[it->first]) |
---|
| 211 | attributesSizes[it->first] = it->second; |
---|
[586] | 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
[731] | 215 | // Account for the domain attributes |
---|
| 216 | std::vector<CDomain*> domList = getDomains(); |
---|
| 217 | for (size_t i = 0; i < domList.size(); ++i) |
---|
[657] | 218 | { |
---|
[1236] | 219 | std::map<int, StdSize> domAttBuffSize = domList[i]->getAttributesBufferSize(client); |
---|
[731] | 220 | for (it = domAttBuffSize.begin(), itE = domAttBuffSize.end(); it != itE; ++it) |
---|
[657] | 221 | { |
---|
[1371] | 222 | it->second += 2 * sizeof(bool); |
---|
[731] | 223 | if (it->second > attributesSizes[it->first]) |
---|
| 224 | attributesSizes[it->first] = it->second; |
---|
[657] | 225 | } |
---|
| 226 | } |
---|
[742] | 227 | |
---|
[731] | 228 | return attributesSizes; |
---|
[1236] | 229 | } |
---|
[1622] | 230 | CATCH_DUMP_ATTR |
---|
[657] | 231 | |
---|
[731] | 232 | /*! |
---|
[1263] | 233 | * Compute the minimum buffer size required to send the data. |
---|
| 234 | * \param client contextClient used to determine the size of connected receivers |
---|
[731] | 235 | * \param id the id used to tag the data |
---|
[1330] | 236 | * \param bufferForWriting flag indicating if a buffer is used to send data for writing |
---|
[1263] | 237 | * \return A map associating the sender rank with its minimum buffer size. |
---|
[731] | 238 | */ |
---|
[1330] | 239 | std::map<int, StdSize> CGrid::getDataBufferSize(CContextClient* client, const std::string& id /*= ""*/, bool bufferForWriting /*= "false"*/) |
---|
[1622] | 240 | TRY |
---|
[1099] | 241 | { |
---|
[739] | 242 | // The record index is sometimes sent along with the data but we always |
---|
| 243 | // include it in the size calculation for the sake of simplicity |
---|
[1232] | 244 | const size_t extraSize = CEventClient::headerSize + (id.empty() ? getId() : id).size() |
---|
| 245 | + 2 * sizeof(size_t) |
---|
| 246 | + sizeof(size_t); |
---|
[1236] | 247 | |
---|
| 248 | std::map<int, StdSize> dataSizes; |
---|
[1263] | 249 | int receiverSize = client->serverSize; |
---|
[1330] | 250 | std::map<int,size_t>& dataSizeMap = bufferForWriting ? connectedDataSize_[receiverSize]: connectedDataSizeRead_; |
---|
| 251 | std::vector<int>& connectedServerRanks = bufferForWriting ? connectedServerRank_[receiverSize] : connectedServerRankRead_; |
---|
| 252 | |
---|
| 253 | std::map<int, size_t>::const_iterator itEnd = dataSizeMap.end(); |
---|
| 254 | for (size_t k = 0; k < connectedServerRanks.size(); ++k) |
---|
[764] | 255 | { |
---|
[1330] | 256 | int rank = connectedServerRanks[k]; |
---|
| 257 | std::map<int, size_t>::const_iterator it = dataSizeMap.find(rank); |
---|
[1236] | 258 | size_t count = (it != itEnd) ? it->second : 0; |
---|
[731] | 259 | |
---|
[1236] | 260 | dataSizes.insert(std::make_pair(rank, extraSize + CArray<double,1>::size(count))); |
---|
[764] | 261 | } |
---|
| 262 | |
---|
[731] | 263 | return dataSizes; |
---|
[509] | 264 | } |
---|
[1622] | 265 | CATCH_DUMP_ATTR |
---|
[509] | 266 | |
---|
[1215] | 267 | size_t CGrid::getGlobalWrittenSize(void) |
---|
[1622] | 268 | TRY |
---|
[1215] | 269 | { |
---|
| 270 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 271 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 272 | |
---|
| 273 | size_t globalGridSize=1 ; |
---|
| 274 | for (std::vector<CDomain*>::iterator it=domainP.begin(); it!=domainP.end();++it) globalGridSize*=(*it)->getGlobalWrittenSize() ; |
---|
| 275 | for (std::vector<CAxis*>::iterator it=axisP.begin(); it!=axisP.end();++it) globalGridSize*=(*it)->getGlobalWrittenSize() ; |
---|
| 276 | return globalGridSize ; |
---|
| 277 | } |
---|
[1622] | 278 | CATCH_DUMP_ATTR |
---|
[1215] | 279 | |
---|
[657] | 280 | void CGrid::checkAttributesAfterTransformation() |
---|
[1622] | 281 | TRY |
---|
[657] | 282 | { |
---|
[927] | 283 | setAxisList(); |
---|
| 284 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 285 | if (!axisListP.empty()) |
---|
| 286 | { |
---|
| 287 | int idx = 0; |
---|
| 288 | axisPositionInGrid_.resize(0); |
---|
| 289 | for (int i = 0; i < axis_domain_order.numElements(); ++i) |
---|
| 290 | { |
---|
| 291 | int elementDimension = axis_domain_order(i); |
---|
| 292 | if (1 == elementDimension) |
---|
| 293 | { |
---|
| 294 | axisPositionInGrid_.push_back(idx); |
---|
| 295 | ++idx; |
---|
| 296 | } |
---|
| 297 | else if (2 == elementDimension) idx += 2; |
---|
| 298 | } |
---|
| 299 | |
---|
| 300 | for (int i = 0; i < axisListP.size(); ++i) |
---|
| 301 | { |
---|
[1158] | 302 | axisListP[i]->checkAttributesOnClientAfterTransformation(getGlobalDimension(),axisPositionInGrid_[i]); |
---|
[927] | 303 | } |
---|
| 304 | } |
---|
| 305 | |
---|
| 306 | setDomainList(); |
---|
| 307 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 308 | if (!domListP.empty()) |
---|
| 309 | { |
---|
| 310 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 311 | { |
---|
| 312 | domListP[i]->checkAttributesOnClientAfterTransformation(); |
---|
| 313 | } |
---|
| 314 | } |
---|
[657] | 315 | } |
---|
[1622] | 316 | CATCH_DUMP_ATTR |
---|
[509] | 317 | |
---|
[676] | 318 | //--------------------------------------------------------------- |
---|
| 319 | |
---|
| 320 | /*! |
---|
| 321 | * Test whether the data defined on the grid can be outputted in a compressed way. |
---|
[720] | 322 | * |
---|
[676] | 323 | * \return true if and only if a mask was defined for this grid |
---|
| 324 | */ |
---|
| 325 | bool CGrid::isCompressible(void) const |
---|
[1622] | 326 | TRY |
---|
[676] | 327 | { |
---|
| 328 | return isCompressible_; |
---|
| 329 | } |
---|
[1622] | 330 | CATCH |
---|
[676] | 331 | |
---|
| 332 | //--------------------------------------------------------------- |
---|
| 333 | |
---|
| 334 | void CGrid::addRelFileCompressed(const StdString& filename) |
---|
[1622] | 335 | TRY |
---|
[676] | 336 | { |
---|
| 337 | this->relFilesCompressed.insert(filename); |
---|
| 338 | } |
---|
[1622] | 339 | CATCH_DUMP_ATTR |
---|
[676] | 340 | |
---|
| 341 | bool CGrid::isWrittenCompressed(const StdString& filename) const |
---|
[1622] | 342 | TRY |
---|
[676] | 343 | { |
---|
| 344 | return (this->relFilesCompressed.find(filename) != this->relFilesCompressed.end()); |
---|
| 345 | } |
---|
[1622] | 346 | CATCH |
---|
[676] | 347 | |
---|
| 348 | //--------------------------------------------------------------- |
---|
[1236] | 349 | /* |
---|
| 350 | Find all reference of grid's components and inherite attributes if necessary |
---|
| 351 | */ |
---|
[509] | 352 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
[1622] | 353 | TRY |
---|
[219] | 354 | { |
---|
[509] | 355 | if (this->isDomainAxisChecked) return; |
---|
[369] | 356 | |
---|
[887] | 357 | this->solveScalarRef(areAttributesChecked); |
---|
[584] | 358 | this->solveAxisRef(areAttributesChecked); |
---|
[1158] | 359 | this->solveDomainRef(areAttributesChecked); |
---|
[509] | 360 | this->isDomainAxisChecked = areAttributesChecked; |
---|
| 361 | } |
---|
[1622] | 362 | CATCH_DUMP_ATTR |
---|
[509] | 363 | |
---|
[1236] | 364 | /* |
---|
| 365 | Go up hierachy reference and fill in the base reference with attributes of the children |
---|
| 366 | This function should be only used after reading component's attributes from file |
---|
| 367 | */ |
---|
[775] | 368 | void CGrid::solveDomainAxisBaseRef() |
---|
[1622] | 369 | TRY |
---|
[775] | 370 | { |
---|
| 371 | if (this->hasDomainAxisBaseRef_) return; |
---|
[887] | 372 | // Account for the scalar attributes |
---|
| 373 | std::vector<CScalar*> scalarList = getScalars(); |
---|
| 374 | for (size_t i = 0; i < scalarList.size(); ++i) |
---|
| 375 | { |
---|
| 376 | scalarList[i]->setAttributesReference(); |
---|
| 377 | } |
---|
| 378 | |
---|
[775] | 379 | // Account for the axis attributes |
---|
| 380 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 381 | for (size_t i = 0; i < axisList.size(); ++i) |
---|
| 382 | { |
---|
[777] | 383 | axisList[i]->setAttributesReference(); |
---|
[775] | 384 | } |
---|
| 385 | |
---|
| 386 | // Account for the domain attributes |
---|
| 387 | std::vector<CDomain*> domList = getDomains(); |
---|
| 388 | for (size_t i = 0; i < domList.size(); ++i) |
---|
| 389 | { |
---|
[777] | 390 | domList[i]->setAttributesReference(); |
---|
[775] | 391 | } |
---|
[887] | 392 | |
---|
[775] | 393 | this->hasDomainAxisBaseRef_ = true; |
---|
| 394 | } |
---|
[1622] | 395 | CATCH_DUMP_ATTR |
---|
[775] | 396 | |
---|
[676] | 397 | void CGrid::checkEligibilityForCompressedOutput() |
---|
[1622] | 398 | TRY |
---|
[676] | 399 | { |
---|
| 400 | // We don't check if the mask is valid here, just if a mask has been defined at this point. |
---|
[817] | 401 | isCompressible_ = !mask_1d.isEmpty() || !mask_2d.isEmpty() || !mask_3d.isEmpty(); |
---|
[676] | 402 | } |
---|
[1622] | 403 | CATCH_DUMP_ATTR |
---|
[676] | 404 | |
---|
[509] | 405 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
[1622] | 406 | TRY |
---|
[509] | 407 | { |
---|
[650] | 408 | CContext* context = CContext::getCurrent(); |
---|
[1030] | 409 | int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1; |
---|
| 410 | nbSrvPools = 1; |
---|
[1099] | 411 | for (int p = 0; p < nbSrvPools; ++p) |
---|
[1202] | 412 | { |
---|
| 413 | if (context->hasClient && this->isChecked && doSendingIndex && !isIndexSent) |
---|
| 414 | { |
---|
| 415 | if (isScalarGrid()) |
---|
| 416 | sendIndexScalarGrid(); |
---|
| 417 | else |
---|
| 418 | sendIndex(); |
---|
| 419 | this->isIndexSent = true; |
---|
[1027] | 420 | } |
---|
| 421 | |
---|
[1202] | 422 | // Not sure about this |
---|
| 423 | //if (!(this->hasTransform() && !this->isTransformed())) |
---|
| 424 | // this->isChecked = true; |
---|
| 425 | //return; |
---|
[1030] | 426 | } |
---|
| 427 | |
---|
| 428 | if (this->isChecked) return; |
---|
| 429 | this->checkAttributesAfterTransformation(); |
---|
[1099] | 430 | |
---|
| 431 | // TODO: Transfer grid attributes |
---|
[1250] | 432 | //if (!context->hasClient && context->hasServer) this->createMask(); |
---|
[1030] | 433 | this->computeIndex(); |
---|
[1027] | 434 | |
---|
[1030] | 435 | if (!(this->hasTransform() && !this->isTransformed())) |
---|
| 436 | this->isChecked = true; |
---|
[1009] | 437 | |
---|
[1030] | 438 | if (!(this->hasTransform() && (!this->isGenerated()))) |
---|
| 439 | this->isChecked = true; |
---|
[219] | 440 | } |
---|
[1622] | 441 | CATCH_DUMP_ATTR |
---|
[1637] | 442 | bool CGrid::hasMask() const |
---|
| 443 | TRY |
---|
| 444 | { |
---|
| 445 | return (!mask_1d.isEmpty() || !mask_2d.isEmpty() || !mask_3d.isEmpty() || |
---|
| 446 | !mask_4d.isEmpty() || !mask_5d.isEmpty() || !mask_6d.isEmpty() || !mask_7d.isEmpty()); |
---|
| 447 | } |
---|
| 448 | CATCH |
---|
[219] | 449 | |
---|
[1236] | 450 | /* |
---|
| 451 | Create mask of grid from mask of its components |
---|
| 452 | */ |
---|
[821] | 453 | void CGrid::createMask(void) |
---|
[1622] | 454 | TRY |
---|
[821] | 455 | { |
---|
| 456 | using namespace std; |
---|
| 457 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 458 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 459 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 460 | |
---|
| 461 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
[1311] | 462 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->domainMask); |
---|
[821] | 463 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 464 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
| 465 | |
---|
| 466 | switch (dim) { |
---|
| 467 | case 1: |
---|
| 468 | checkGridMask(mask_1d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 469 | break; |
---|
| 470 | case 2: |
---|
| 471 | checkGridMask(mask_2d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 472 | break; |
---|
| 473 | case 3: |
---|
| 474 | checkGridMask(mask_3d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 475 | break; |
---|
[968] | 476 | case 4: |
---|
| 477 | checkGridMask(mask_4d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 478 | break; |
---|
| 479 | case 5: |
---|
| 480 | checkGridMask(mask_5d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 481 | break; |
---|
| 482 | case 6: |
---|
| 483 | checkGridMask(mask_6d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 484 | break; |
---|
| 485 | case 7: |
---|
| 486 | checkGridMask(mask_7d, domainMasks, axisMasks, axis_domain_order, true); |
---|
| 487 | break; |
---|
[821] | 488 | default: |
---|
| 489 | break; |
---|
| 490 | } |
---|
| 491 | } |
---|
[1622] | 492 | CATCH_DUMP_ATTR |
---|
[821] | 493 | |
---|
[1236] | 494 | /* |
---|
| 495 | Check validity of grid's mask by using the masks of its components |
---|
| 496 | */ |
---|
[415] | 497 | void CGrid::checkMask(void) |
---|
[1622] | 498 | TRY |
---|
[415] | 499 | { |
---|
| 500 | using namespace std; |
---|
[567] | 501 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 502 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 503 | int dim = domainP.size() * 2 + axisP.size(); |
---|
[415] | 504 | |
---|
[664] | 505 | std::vector<CArray<bool,1>* > domainMasks(domainP.size()); |
---|
[1311] | 506 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->domainMask); |
---|
[567] | 507 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 508 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
[415] | 509 | |
---|
[567] | 510 | switch (dim) { |
---|
| 511 | case 1: |
---|
[817] | 512 | checkGridMask(mask_1d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 513 | break; |
---|
| 514 | case 2: |
---|
[817] | 515 | checkGridMask(mask_2d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 516 | break; |
---|
| 517 | case 3: |
---|
[817] | 518 | checkGridMask(mask_3d, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 519 | break; |
---|
[932] | 520 | case 4: |
---|
| 521 | checkGridMask(mask_4d, domainMasks, axisMasks, axis_domain_order); |
---|
| 522 | break; |
---|
| 523 | case 5: |
---|
| 524 | checkGridMask(mask_5d, domainMasks, axisMasks, axis_domain_order); |
---|
| 525 | break; |
---|
| 526 | case 6: |
---|
| 527 | checkGridMask(mask_6d, domainMasks, axisMasks, axis_domain_order); |
---|
| 528 | break; |
---|
| 529 | case 7: |
---|
| 530 | checkGridMask(mask_7d, domainMasks, axisMasks, axis_domain_order); |
---|
| 531 | break; |
---|
[567] | 532 | default: |
---|
| 533 | break; |
---|
[415] | 534 | } |
---|
| 535 | } |
---|
[1622] | 536 | CATCH_DUMP_ATTR |
---|
[623] | 537 | |
---|
[1236] | 538 | /* |
---|
| 539 | Modify value of mask in a certain index |
---|
| 540 | This function can be used to correct the mask of grid after being constructed with createMask |
---|
| 541 | \param [in] indexToModify |
---|
| 542 | \param [in] modifyValue |
---|
| 543 | */ |
---|
[1129] | 544 | void CGrid::modifyMask(const CArray<int,1>& indexToModify, bool modifyValue) |
---|
[1622] | 545 | TRY |
---|
[623] | 546 | { |
---|
| 547 | using namespace std; |
---|
| 548 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
[1158] | 549 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[623] | 550 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 551 | |
---|
| 552 | switch (dim) { |
---|
[1250] | 553 | case 0: |
---|
| 554 | modifyGridMask(mask_0d, indexToModify, modifyValue); |
---|
| 555 | break; |
---|
[623] | 556 | case 1: |
---|
[1129] | 557 | modifyGridMask(mask_1d, indexToModify, modifyValue); |
---|
[623] | 558 | break; |
---|
| 559 | case 2: |
---|
[1129] | 560 | modifyGridMask(mask_2d, indexToModify, modifyValue); |
---|
[623] | 561 | break; |
---|
| 562 | case 3: |
---|
[1129] | 563 | modifyGridMask(mask_3d, indexToModify, modifyValue); |
---|
[623] | 564 | break; |
---|
[932] | 565 | case 4: |
---|
[1129] | 566 | modifyGridMask(mask_4d, indexToModify, modifyValue); |
---|
[932] | 567 | break; |
---|
| 568 | case 5: |
---|
[1129] | 569 | modifyGridMask(mask_5d, indexToModify, modifyValue); |
---|
[932] | 570 | break; |
---|
| 571 | case 6: |
---|
[1129] | 572 | modifyGridMask(mask_6d, indexToModify, modifyValue); |
---|
[932] | 573 | break; |
---|
| 574 | case 7: |
---|
[1129] | 575 | modifyGridMask(mask_7d, indexToModify, modifyValue); |
---|
[932] | 576 | break; |
---|
[623] | 577 | default: |
---|
| 578 | break; |
---|
| 579 | } |
---|
| 580 | } |
---|
[1622] | 581 | CATCH_DUMP_ATTR |
---|
[623] | 582 | |
---|
[1236] | 583 | /* |
---|
| 584 | Change the mask size. This function is used on reconstructing mask in server side |
---|
| 585 | \param [in] newDimensionSize |
---|
| 586 | \param [in] newValue |
---|
| 587 | */ |
---|
[1129] | 588 | void CGrid::modifyMaskSize(const std::vector<int>& newDimensionSize, bool newValue) |
---|
[1622] | 589 | TRY |
---|
[1129] | 590 | { |
---|
| 591 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
[1136] | 592 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
[1129] | 593 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 594 | |
---|
| 595 | switch (dim) { |
---|
[1250] | 596 | case 0: |
---|
| 597 | modifyGridMaskSize(mask_0d, newDimensionSize, newValue); |
---|
| 598 | break; |
---|
[1129] | 599 | case 1: |
---|
| 600 | modifyGridMaskSize(mask_1d, newDimensionSize, newValue); |
---|
| 601 | break; |
---|
| 602 | case 2: |
---|
| 603 | modifyGridMaskSize(mask_2d, newDimensionSize, newValue); |
---|
| 604 | break; |
---|
| 605 | case 3: |
---|
| 606 | modifyGridMaskSize(mask_3d, newDimensionSize, newValue); |
---|
| 607 | break; |
---|
| 608 | case 4: |
---|
| 609 | modifyGridMaskSize(mask_4d, newDimensionSize, newValue); |
---|
| 610 | break; |
---|
| 611 | case 5: |
---|
| 612 | modifyGridMaskSize(mask_5d, newDimensionSize, newValue); |
---|
| 613 | break; |
---|
| 614 | case 6: |
---|
| 615 | modifyGridMaskSize(mask_6d, newDimensionSize, newValue); |
---|
| 616 | break; |
---|
| 617 | case 7: |
---|
| 618 | modifyGridMaskSize(mask_7d, newDimensionSize, newValue); |
---|
| 619 | break; |
---|
| 620 | default: |
---|
| 621 | break; |
---|
| 622 | } |
---|
| 623 | } |
---|
[1622] | 624 | CATCH_DUMP_ATTR |
---|
[1129] | 625 | |
---|
[219] | 626 | //--------------------------------------------------------------- |
---|
| 627 | |
---|
[509] | 628 | void CGrid::solveDomainRef(bool sendAtt) |
---|
[1622] | 629 | TRY |
---|
[219] | 630 | { |
---|
[540] | 631 | setDomainList(); |
---|
[567] | 632 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 633 | if (!domListP.empty()) |
---|
[219] | 634 | { |
---|
[567] | 635 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 636 | { |
---|
| 637 | if (sendAtt) domListP[i]->sendCheckedAttributes(); |
---|
| 638 | else domListP[i]->checkAttributesOnClient(); |
---|
[2131] | 639 | if (domListP[i]->isTiled()) this->isTiled_ = true; |
---|
| 640 | if (domListP[i]->isTiledOnly()) this->isTiledOnly_ = true; |
---|
[567] | 641 | } |
---|
[219] | 642 | } |
---|
| 643 | } |
---|
[1622] | 644 | CATCH_DUMP_ATTR |
---|
[219] | 645 | |
---|
| 646 | //--------------------------------------------------------------- |
---|
| 647 | |
---|
[567] | 648 | void CGrid::solveAxisRef(bool sendAtt) |
---|
[1622] | 649 | TRY |
---|
[219] | 650 | { |
---|
[540] | 651 | setAxisList(); |
---|
[567] | 652 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 653 | if (!axisListP.empty()) |
---|
[219] | 654 | { |
---|
[567] | 655 | int idx = 0; |
---|
[620] | 656 | axisPositionInGrid_.resize(0); |
---|
[575] | 657 | for (int i = 0; i < axis_domain_order.numElements(); ++i) |
---|
[568] | 658 | { |
---|
[887] | 659 | int elementDimension = axis_domain_order(i); |
---|
| 660 | if (1 == elementDimension) |
---|
[568] | 661 | { |
---|
[620] | 662 | axisPositionInGrid_.push_back(idx); |
---|
[568] | 663 | ++idx; |
---|
| 664 | } |
---|
[887] | 665 | else if (2 == elementDimension) idx += 2; |
---|
[568] | 666 | } |
---|
| 667 | |
---|
[567] | 668 | for (int i = 0; i < axisListP.size(); ++i) |
---|
[540] | 669 | { |
---|
[567] | 670 | if (sendAtt) |
---|
[1158] | 671 | axisListP[i]->sendCheckedAttributes(getGlobalDimension(),axisPositionInGrid_[i]); |
---|
[567] | 672 | else |
---|
[742] | 673 | axisListP[i]->checkAttributesOnClient(); |
---|
[540] | 674 | } |
---|
[219] | 675 | } |
---|
| 676 | } |
---|
[1622] | 677 | CATCH_DUMP_ATTR |
---|
[219] | 678 | |
---|
[887] | 679 | //--------------------------------------------------------------- |
---|
| 680 | |
---|
| 681 | void CGrid::solveScalarRef(bool sendAtt) |
---|
[1622] | 682 | TRY |
---|
[887] | 683 | { |
---|
| 684 | setScalarList(); |
---|
| 685 | std::vector<CScalar*> scalarListP = this->getScalars(); |
---|
| 686 | if (!scalarListP.empty()) |
---|
| 687 | { |
---|
| 688 | for (int i = 0; i < scalarListP.size(); ++i) |
---|
| 689 | { |
---|
| 690 | /*Nothing to do for now */ |
---|
| 691 | // if (sendAtt) scalarListP[i]->sendCheckedAttributes(); |
---|
| 692 | // else scalarListP[i]->checkAttributesOnClient(); |
---|
| 693 | } |
---|
| 694 | } |
---|
| 695 | } |
---|
[1622] | 696 | CATCH_DUMP_ATTR |
---|
[887] | 697 | |
---|
[1144] | 698 | /*! |
---|
| 699 | Compute the index to for write data into a file |
---|
| 700 | */ |
---|
[1129] | 701 | void CGrid::computeWrittenIndex() |
---|
[1622] | 702 | TRY |
---|
[1129] | 703 | { |
---|
| 704 | if (computedWrittenIndex_) return; |
---|
| 705 | computedWrittenIndex_ = true; |
---|
| 706 | |
---|
[1202] | 707 | if (isScalarGrid()) |
---|
| 708 | { |
---|
| 709 | size_t nbWritten = 1; |
---|
| 710 | int writtenIndex = 0; |
---|
| 711 | |
---|
| 712 | localIndexToWriteOnClient.resize(nbWritten); |
---|
| 713 | localIndexToWriteOnServer.resize(nbWritten); |
---|
| 714 | localIndexToWriteOnServer(0) = writtenIndex; |
---|
| 715 | localIndexToWriteOnClient(0) = writtenIndex; |
---|
| 716 | |
---|
| 717 | return; |
---|
| 718 | } |
---|
| 719 | |
---|
[1129] | 720 | size_t nbWritten = 0, indGlo; |
---|
| 721 | CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution_->getGlobalDataIndexOnClient(); |
---|
| 722 | CDistributionClient::GlobalLocalDataMap::const_iterator itb = globalDataIndex.begin(), |
---|
| 723 | ite = globalDataIndex.end(), it; |
---|
| 724 | const CDistributionServer::GlobalLocalMap& globalLocalIndex = serverDistribution_->getGlobalLocalIndex(); |
---|
| 725 | CDistributionServer::GlobalLocalMap::const_iterator itSrvb = globalLocalIndex.begin(), |
---|
| 726 | itSrve = globalLocalIndex.end(), itSrv; |
---|
| 727 | for (it = itb; it != ite; ++it) |
---|
| 728 | { |
---|
| 729 | indGlo = it->first; |
---|
| 730 | if (globalLocalIndex.end() != globalLocalIndex.find(indGlo)) ++nbWritten; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | localIndexToWriteOnClient.resize(nbWritten); |
---|
| 734 | localIndexToWriteOnServer.resize(nbWritten); |
---|
[1144] | 735 | |
---|
[1143] | 736 | { |
---|
| 737 | numberWrittenIndexes_ = nbWritten; |
---|
| 738 | if (isDataDistributed_) |
---|
| 739 | { |
---|
| 740 | CContextServer* server = CContext::getCurrent()->server; |
---|
[1639] | 741 | MPI_Allreduce(&numberWrittenIndexes_, &totalNumberWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
| 742 | MPI_Scan(&numberWrittenIndexes_, &offsetWrittenIndexes_, 1, MPI_INT, MPI_SUM, server->intraComm); |
---|
[1143] | 743 | offsetWrittenIndexes_ -= numberWrittenIndexes_; |
---|
| 744 | } |
---|
| 745 | else |
---|
| 746 | totalNumberWrittenIndexes_ = numberWrittenIndexes_; |
---|
| 747 | } |
---|
| 748 | |
---|
[1129] | 749 | nbWritten = 0; |
---|
| 750 | for (it = itb; it != ite; ++it) |
---|
| 751 | { |
---|
| 752 | indGlo = it->first; |
---|
| 753 | itSrv = globalLocalIndex.find(indGlo); |
---|
| 754 | if (itSrve != itSrv) |
---|
| 755 | { |
---|
| 756 | localIndexToWriteOnServer(nbWritten) = itSrv->second; |
---|
| 757 | localIndexToWriteOnClient(nbWritten) = it->second; |
---|
| 758 | ++nbWritten; |
---|
| 759 | } |
---|
| 760 | } |
---|
| 761 | } |
---|
[1622] | 762 | CATCH_DUMP_ATTR |
---|
[1129] | 763 | |
---|
[219] | 764 | //--------------------------------------------------------------- |
---|
| 765 | |
---|
[1236] | 766 | /* |
---|
[1294] | 767 | Compute the global index and its local index taking account mask and data index. |
---|
| 768 | These global indexes will be used to compute the connection of this client (sender) to its servers (receivers) |
---|
[1236] | 769 | (via function computeConnectedClient) |
---|
[1294] | 770 | These global indexes also correspond to data sent to servers (if any) |
---|
[1236] | 771 | */ |
---|
[1023] | 772 | void CGrid::computeClientIndex() |
---|
[1622] | 773 | TRY |
---|
[1023] | 774 | { |
---|
| 775 | CContext* context = CContext::getCurrent(); |
---|
| 776 | |
---|
[1637] | 777 | CContextClient* client = context->client; |
---|
[1263] | 778 | int rank = client->clientRank; |
---|
| 779 | |
---|
| 780 | clientDistribution_ = new CDistributionClient(rank, this); |
---|
| 781 | // Get local data index on client |
---|
[1637] | 782 | int nbStoreIndex = clientDistribution_->getLocalDataIndexOnClient().size(); |
---|
| 783 | int nbStoreGridMask = clientDistribution_->getLocalMaskIndexOnClient().size(); |
---|
| 784 | // nbStoreGridMask = nbStoreIndex if grid mask is defined, and 0 otherwise |
---|
| 785 | storeIndex_client.resize(nbStoreIndex); |
---|
| 786 | storeMask_client.resize(nbStoreGridMask); |
---|
[1263] | 787 | for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; |
---|
[1637] | 788 | for (int idx = 0; idx < nbStoreGridMask; ++idx) storeMask_client(idx) = (clientDistribution_->getLocalMaskIndexOnClient())[idx]; |
---|
[1263] | 789 | |
---|
| 790 | if (0 == serverDistribution_) isDataDistributed_= clientDistribution_->isDataDistributed(); |
---|
| 791 | else |
---|
[1027] | 792 | { |
---|
[1263] | 793 | // Mapping global index received from clients to the storeIndex_client |
---|
| 794 | CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution_->getGlobalDataIndexOnClient(); |
---|
| 795 | CDistributionClient::GlobalLocalDataMap::const_iterator itGloe = globalDataIndex.end(); |
---|
| 796 | map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClient.begin(), |
---|
| 797 | ite = outGlobalIndexFromClient.end(), it; |
---|
[1023] | 798 | |
---|
[1263] | 799 | for (it = itb; it != ite; ++it) |
---|
| 800 | { |
---|
| 801 | int rank = it->first; |
---|
| 802 | CArray<size_t,1>& globalIndex = outGlobalIndexFromClient[rank]; |
---|
| 803 | outLocalIndexStoreOnClient.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); |
---|
| 804 | CArray<size_t,1>& localIndex = outLocalIndexStoreOnClient[rank]; |
---|
| 805 | size_t nbIndex = 0; |
---|
| 806 | |
---|
| 807 | // Keep this code for this moment but it should be removed (or moved to DEBUG) to improve performance |
---|
| 808 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
[1129] | 809 | { |
---|
[1263] | 810 | if (itGloe != globalDataIndex.find(globalIndex(idx))) |
---|
[1129] | 811 | { |
---|
[1263] | 812 | ++nbIndex; |
---|
[1129] | 813 | } |
---|
[1263] | 814 | } |
---|
[1129] | 815 | |
---|
[1263] | 816 | if (doGridHaveDataDistributed(client) && (nbIndex != localIndex.numElements())) |
---|
| 817 | ERROR("void CGrid::computeClientIndex()", |
---|
| 818 | << "Number of local index on client is different from number of received global index" |
---|
| 819 | << "Rank of sent client " << rank <<"." |
---|
| 820 | << "Number of local index " << nbIndex << ". " |
---|
| 821 | << "Number of received global index " << localIndex.numElements() << "."); |
---|
[1129] | 822 | |
---|
[1263] | 823 | nbIndex = 0; |
---|
| 824 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 825 | { |
---|
| 826 | if (itGloe != globalDataIndex.find(globalIndex(idx))) |
---|
[1129] | 827 | { |
---|
[1263] | 828 | localIndex(idx) = globalDataIndex[globalIndex(idx)]; |
---|
[1129] | 829 | } |
---|
[1263] | 830 | } |
---|
[1129] | 831 | } |
---|
[1030] | 832 | } |
---|
[1023] | 833 | } |
---|
[1622] | 834 | CATCH_DUMP_ATTR |
---|
[1023] | 835 | |
---|
[2131] | 836 | //--------------------------------------------------------------- |
---|
| 837 | |
---|
| 838 | /* |
---|
| 839 | Compute the global index and its local index taking account mask and data index. |
---|
| 840 | These global indexes will be used to compute the connection of this client (sender) to its servers (receivers) |
---|
| 841 | (via function computeConnectedClient) |
---|
| 842 | These global indexes also correspond to data sent to servers (if any) |
---|
| 843 | */ |
---|
| 844 | void CGrid::computeClientIndexTiled() |
---|
| 845 | TRY |
---|
| 846 | { |
---|
| 847 | CContext* context = CContext::getCurrent(); |
---|
| 848 | |
---|
| 849 | CContextClient* client = context->client; |
---|
| 850 | int rank = client->clientRank; |
---|
| 851 | |
---|
| 852 | clientDistributionTiled_ = new CDistributionClient(rank, this, true); |
---|
| 853 | // Get local data index on client |
---|
| 854 | int nbStoreIndex = clientDistributionTiled_->getLocalDataIndexOnClient().size(); |
---|
| 855 | int nbStoreGridMask = clientDistributionTiled_->getLocalMaskIndexOnClient().size(); |
---|
| 856 | // nbStoreGridMask = nbStoreIndex if grid mask is defined, and 0 otherwise |
---|
| 857 | storeIndexTiled_client.resize(nbStoreIndex); |
---|
| 858 | storeMaskTiled_client.resize(nbStoreGridMask); |
---|
| 859 | for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndexTiled_client(idx) = (clientDistributionTiled_->getLocalDataIndexOnClient())[idx]; |
---|
| 860 | for (int idx = 0; idx < nbStoreGridMask; ++idx) storeMaskTiled_client(idx) = (clientDistributionTiled_->getLocalMaskIndexOnClient())[idx]; |
---|
| 861 | |
---|
| 862 | if (0 == serverDistribution_) isDataDistributed_= clientDistributionTiled_->isDataDistributed(); |
---|
| 863 | else |
---|
| 864 | { |
---|
| 865 | // Mapping global index received from clients to the storeIndex_client |
---|
| 866 | CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistributionTiled_->getGlobalDataIndexOnClient(); |
---|
| 867 | CDistributionClient::GlobalLocalDataMap::const_iterator itGloe = globalDataIndex.end(); |
---|
| 868 | map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClientTiled.begin(), |
---|
| 869 | ite = outGlobalIndexFromClientTiled.end(), it; |
---|
| 870 | |
---|
| 871 | for (it = itb; it != ite; ++it) |
---|
| 872 | { |
---|
| 873 | int rank = it->first; |
---|
| 874 | CArray<size_t,1>& globalIndex = outGlobalIndexFromClientTiled[rank]; |
---|
| 875 | outLocalIndexStoreOnClientTiled.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); |
---|
| 876 | CArray<size_t,1>& localIndex = outLocalIndexStoreOnClientTiled[rank]; |
---|
| 877 | size_t nbIndex = 0; |
---|
| 878 | |
---|
| 879 | // Keep this code for this moment but it should be removed (or moved to DEBUG) to improve performance |
---|
| 880 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 881 | { |
---|
| 882 | if (itGloe != globalDataIndex.find(globalIndex(idx))) |
---|
| 883 | { |
---|
| 884 | ++nbIndex; |
---|
| 885 | } |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | if (doGridHaveDataDistributed(client) && (nbIndex != localIndex.numElements())) |
---|
| 889 | ERROR("void CGrid::computeClientIndex()", |
---|
| 890 | << "Number of local index on client is different from number of received global index" |
---|
| 891 | << "Rank of sent client " << rank <<"." |
---|
| 892 | << "Number of local index " << nbIndex << ". " |
---|
| 893 | << "Number of received global index " << localIndex.numElements() << "."); |
---|
| 894 | |
---|
| 895 | nbIndex = 0; |
---|
| 896 | for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) |
---|
| 897 | { |
---|
| 898 | if (itGloe != globalDataIndex.find(globalIndex(idx))) |
---|
| 899 | { |
---|
| 900 | localIndex(idx) = globalDataIndex[globalIndex(idx)]; |
---|
| 901 | } |
---|
| 902 | } |
---|
| 903 | } |
---|
| 904 | } |
---|
| 905 | } |
---|
| 906 | CATCH_DUMP_ATTR |
---|
| 907 | |
---|
[1136] | 908 | /*! |
---|
[1263] | 909 | Compute connected receivers and indexes to be sent to these receivers. |
---|
[1136] | 910 | */ |
---|
[1023] | 911 | void CGrid::computeConnectedClients() |
---|
[1622] | 912 | TRY |
---|
[1023] | 913 | { |
---|
| 914 | CContext* context = CContext::getCurrent(); |
---|
[1263] | 915 | int nbSrvPools = (context->clientPrimServer.size() == 0) ? 1 : context->clientPrimServer.size(); |
---|
[1236] | 916 | connectedServerRank_.clear(); |
---|
| 917 | connectedDataSize_.clear(); |
---|
| 918 | globalIndexOnServer_.clear(); |
---|
| 919 | nbSenders.clear(); |
---|
[1099] | 920 | |
---|
| 921 | for (int p = 0; p < nbSrvPools; ++p) |
---|
[1027] | 922 | { |
---|
[1263] | 923 | CContextClient* client = (context->clientPrimServer.size() == 0) ? context->client : context->clientPrimServer[p]; |
---|
| 924 | int receiverSize = client->serverSize; |
---|
| 925 | // connectedServerRank_[client].clear(); |
---|
[1023] | 926 | |
---|
[1263] | 927 | if (connectedServerRank_.find(receiverSize) == connectedServerRank_.end()) |
---|
[1027] | 928 | { |
---|
[1263] | 929 | if (!doGridHaveDataDistributed(client)) |
---|
| 930 | { |
---|
| 931 | if (client->isServerLeader()) |
---|
[1027] | 932 | { |
---|
[1263] | 933 | size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); |
---|
| 934 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 935 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 936 | { |
---|
| 937 | connectedServerRank_[receiverSize].push_back(*itRank); |
---|
| 938 | connectedDataSize_[receiverSize][*itRank] = ssize; |
---|
| 939 | } |
---|
[1027] | 940 | } |
---|
[1263] | 941 | return; |
---|
| 942 | } |
---|
[1023] | 943 | |
---|
[1263] | 944 | // Compute mapping between client and server |
---|
[1542] | 945 | std::vector<std::unordered_map<size_t,std::vector<int> > > indexServerOnElement; |
---|
[1263] | 946 | CServerDistributionDescription serverDistributionDescription(getGlobalDimension(), client->serverSize); |
---|
| 947 | std::vector<int> serverZeroIndex = serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, |
---|
| 948 | client->clientRank, |
---|
| 949 | client->clientSize, |
---|
| 950 | axis_domain_order, |
---|
| 951 | getDistributedDimension()); |
---|
[1232] | 952 | |
---|
[1263] | 953 | // Even if servers have no index, they must received something from client |
---|
| 954 | // We only use several client to send "empty" message to these servers |
---|
| 955 | std::list<int> serverZeroIndexLeader; |
---|
| 956 | std::list<int> serverZeroIndexNotLeader; |
---|
| 957 | CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); |
---|
| 958 | for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 959 | *it = serverZeroIndex[*it]; |
---|
[1232] | 960 | |
---|
[1263] | 961 | if (globalIndexOnServer_.find(receiverSize) == globalIndexOnServer_.end()) |
---|
| 962 | computeIndexByElement(indexServerOnElement, client, globalIndexOnServer_[receiverSize]); |
---|
[1023] | 963 | |
---|
[1263] | 964 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); |
---|
| 965 | CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; |
---|
| 966 | CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
| 967 | itbGlobalMap = globalIndexOnServer_[receiverSize].begin(); |
---|
| 968 | iteGlobalMap = globalIndexOnServer_[receiverSize].end(); |
---|
[1023] | 969 | |
---|
[1263] | 970 | for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
[1027] | 971 | { |
---|
[1263] | 972 | int serverRank = itGlobalMap->first; |
---|
| 973 | int indexSize = itGlobalMap->second.size(); |
---|
| 974 | const std::vector<size_t>& indexVec = itGlobalMap->second; |
---|
| 975 | for (int idx = 0; idx < indexSize; ++idx) |
---|
| 976 | { |
---|
| 977 | itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); |
---|
| 978 | if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) |
---|
| 979 | { |
---|
| 980 | if (connectedDataSize_[receiverSize].end() == connectedDataSize_[receiverSize].find(serverRank)) |
---|
| 981 | connectedDataSize_[receiverSize][serverRank] = 1; |
---|
| 982 | else |
---|
| 983 | ++connectedDataSize_[receiverSize][serverRank]; |
---|
| 984 | } |
---|
| 985 | } |
---|
[1027] | 986 | } |
---|
[1023] | 987 | |
---|
[1263] | 988 | // Connected servers which really have index |
---|
| 989 | for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { |
---|
| 990 | connectedServerRank_[receiverSize].push_back(itGlobalMap->first); |
---|
| 991 | } |
---|
[1027] | 992 | |
---|
[1263] | 993 | // Connected servers which have no index at all |
---|
| 994 | for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) |
---|
| 995 | connectedServerRank_[receiverSize].push_back(*it); |
---|
[1232] | 996 | |
---|
[1263] | 997 | // Even if a client has no index, it must connect to at least one server and |
---|
| 998 | // send an "empty" data to this server |
---|
| 999 | if (connectedServerRank_[receiverSize].empty()) |
---|
| 1000 | connectedServerRank_[receiverSize].push_back(client->clientRank % client->serverSize); |
---|
[1235] | 1001 | |
---|
[1637] | 1002 | // Now check if all servers have data to receive. If not, master client will send empty data. |
---|
| 1003 | // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. |
---|
| 1004 | std::vector<int> counts (client->clientSize); |
---|
| 1005 | std::vector<int> displs (client->clientSize); |
---|
| 1006 | displs[0] = 0; |
---|
| 1007 | int localCount = connectedServerRank_[receiverSize].size() ; |
---|
[1639] | 1008 | MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ; |
---|
[1637] | 1009 | for (int i = 0; i < client->clientSize-1; ++i) |
---|
| 1010 | { |
---|
| 1011 | displs[i+1] = displs[i] + counts[i]; |
---|
| 1012 | } |
---|
| 1013 | std::vector<int> allConnectedServers(displs[client->clientSize-1]+counts[client->clientSize-1]); |
---|
[1639] | 1014 | MPI_Gatherv(&(connectedServerRank_[receiverSize])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm); |
---|
[1637] | 1015 | |
---|
| 1016 | if ((allConnectedServers.size() != receiverSize) && (client->clientRank == 0)) |
---|
| 1017 | { |
---|
| 1018 | std::vector<bool> isSrvConnected (receiverSize, false); |
---|
| 1019 | for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; |
---|
| 1020 | for (int i = 0; i < receiverSize; ++i) |
---|
| 1021 | { |
---|
| 1022 | if (!isSrvConnected[i]) connectedServerRank_[receiverSize].push_back(i); |
---|
| 1023 | } |
---|
| 1024 | } |
---|
| 1025 | |
---|
[1263] | 1026 | nbSenders[receiverSize] = clientServerMap_->computeConnectedClients(receiverSize, client->clientSize, client->intraComm, connectedServerRank_[receiverSize]); |
---|
| 1027 | } |
---|
[1023] | 1028 | } |
---|
| 1029 | } |
---|
[1622] | 1030 | CATCH_DUMP_ATTR |
---|
[1023] | 1031 | |
---|
[865] | 1032 | /*! |
---|
| 1033 | Compute the global index of grid to send to server as well as the connected server of the current client. |
---|
| 1034 | First of all, from the local data on each element of grid, we can calculate their local index which also allows us to know |
---|
| 1035 | their global index. We can have a map of global index of grid and local index that each client holds |
---|
| 1036 | Then, each client holds a piece of information about the distribution of servers, which permits to compute the connected server(s) |
---|
| 1037 | of the current client. |
---|
| 1038 | */ |
---|
[219] | 1039 | void CGrid::computeIndex(void) |
---|
[1622] | 1040 | TRY |
---|
[509] | 1041 | { |
---|
[650] | 1042 | CContext* context = CContext::getCurrent(); |
---|
[1202] | 1043 | if (isScalarGrid()) |
---|
[1054] | 1044 | { |
---|
[1202] | 1045 | computeClientIndexScalarGrid(); |
---|
| 1046 | if (context->hasClient) |
---|
| 1047 | { |
---|
| 1048 | computeConnectedClientsScalarGrid(); |
---|
| 1049 | } |
---|
[1054] | 1050 | } |
---|
[1202] | 1051 | else |
---|
| 1052 | { |
---|
[2131] | 1053 | if (this->isTiled_) |
---|
| 1054 | { |
---|
| 1055 | computeClientIndexTiled(); |
---|
| 1056 | if (!this->isTiledOnly_) |
---|
| 1057 | computeClientIndex(); |
---|
| 1058 | } |
---|
| 1059 | else |
---|
| 1060 | computeClientIndex(); |
---|
| 1061 | |
---|
| 1062 | if (this->isTiled_) computeTileIndex(); |
---|
[1202] | 1063 | if (context->hasClient) |
---|
| 1064 | { |
---|
| 1065 | computeConnectedClients(); |
---|
| 1066 | } |
---|
| 1067 | } |
---|
[1340] | 1068 | if (CServer::serverLevel==2) |
---|
| 1069 | { |
---|
| 1070 | computeWrittenIndex() ; |
---|
| 1071 | if (serverDistribution_!=0) serverDistribution_->partialClear() ; |
---|
| 1072 | if (clientDistribution_!=0) clientDistribution_->partialClear() ; |
---|
| 1073 | outGlobalIndexFromClient.clear() ; |
---|
| 1074 | } |
---|
[219] | 1075 | } |
---|
[1622] | 1076 | CATCH_DUMP_ATTR |
---|
[219] | 1077 | |
---|
[865] | 1078 | /*! |
---|
| 1079 | Compute the global of (client) grid to send to server with the global index of each element of grid |
---|
| 1080 | 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 |
---|
| 1081 | 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 |
---|
| 1082 | on each element whose size is much smaller than one of whole grid. |
---|
| 1083 | \param [in] indexServerOnElement global index of each element and the rank of server associated with these index |
---|
[1263] | 1084 | \param [in] client contextClient |
---|
[865] | 1085 | \param [out] globalIndexOnServer global index of grid and its corresponding rank of server. |
---|
| 1086 | */ |
---|
[1542] | 1087 | void CGrid::computeIndexByElement(const std::vector<std::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, |
---|
[1263] | 1088 | const CContextClient* client, |
---|
[865] | 1089 | CClientServerMapping::GlobalIndexMap& globalIndexOnServer) |
---|
[1622] | 1090 | TRY |
---|
[865] | 1091 | { |
---|
[1263] | 1092 | int serverSize = client->serverSize; |
---|
| 1093 | |
---|
| 1094 | std::vector<CDomain*> domList = getDomains(); |
---|
| 1095 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 1096 | |
---|
| 1097 | // Some pre-calculations of global index on each element of current grid. |
---|
| 1098 | int nbElement = axis_domain_order.numElements(); |
---|
| 1099 | std::vector<CArray<size_t,1> > globalIndexElement(nbElement); |
---|
| 1100 | int domainIdx = 0, axisIdx = 0, scalarIdx = 0; |
---|
| 1101 | std::vector<size_t> elementNGlobal(nbElement); |
---|
| 1102 | elementNGlobal[0] = 1; |
---|
| 1103 | size_t globalSize = 1; |
---|
| 1104 | for (int idx = 0; idx < nbElement; ++idx) |
---|
[1009] | 1105 | { |
---|
[1263] | 1106 | elementNGlobal[idx] = globalSize; |
---|
| 1107 | size_t elementSize; |
---|
| 1108 | size_t elementGlobalSize = 1; |
---|
| 1109 | if (2 == axis_domain_order(idx)) // This is domain |
---|
[865] | 1110 | { |
---|
[1263] | 1111 | elementSize = domList[domainIdx]->i_index.numElements(); |
---|
| 1112 | globalIndexElement[idx].resize(elementSize); |
---|
| 1113 | for (int jdx = 0; jdx < elementSize; ++jdx) |
---|
[865] | 1114 | { |
---|
[1263] | 1115 | globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); |
---|
[865] | 1116 | } |
---|
[1263] | 1117 | elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); |
---|
| 1118 | ++domainIdx; |
---|
| 1119 | } |
---|
| 1120 | else if (1 == axis_domain_order(idx)) // This is axis |
---|
| 1121 | { |
---|
| 1122 | elementSize = axisList[axisIdx]->index.numElements(); |
---|
| 1123 | globalIndexElement[idx].resize(elementSize); |
---|
| 1124 | for (int jdx = 0; jdx < elementSize; ++jdx) |
---|
[865] | 1125 | { |
---|
[1263] | 1126 | globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); |
---|
[865] | 1127 | } |
---|
[1263] | 1128 | elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); |
---|
| 1129 | ++axisIdx; |
---|
[865] | 1130 | } |
---|
[1263] | 1131 | else // Of course, this is scalar |
---|
| 1132 | { |
---|
| 1133 | globalIndexElement[idx].resize(1); |
---|
| 1134 | globalIndexElement[idx](0) = 0; |
---|
| 1135 | elementGlobalSize = 1; |
---|
| 1136 | } |
---|
| 1137 | globalSize *= elementGlobalSize; |
---|
| 1138 | } |
---|
[865] | 1139 | |
---|
[1263] | 1140 | std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); |
---|
[1542] | 1141 | std::vector<std::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); |
---|
[1263] | 1142 | CArray<int,1> nbIndexOnServer(serverSize); // Number of distributed global index held by each client for each server |
---|
| 1143 | // Number of temporary distributed global index held by each client for each server |
---|
| 1144 | // We have this variable for the case of non-distributed element (often axis) to check the duplicate server rank |
---|
| 1145 | CArray<int,1> nbIndexOnServerTmp(serverSize); |
---|
| 1146 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 1147 | { |
---|
| 1148 | nbIndexOnServer = 0; |
---|
[1542] | 1149 | const std::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; |
---|
[1263] | 1150 | const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; |
---|
| 1151 | CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); |
---|
| 1152 | clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); |
---|
| 1153 | const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); |
---|
| 1154 | CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), |
---|
| 1155 | ite = globalIndexElementOnServerMap.end(), it; |
---|
| 1156 | for (it = itb; it != ite; ++it) |
---|
[865] | 1157 | { |
---|
[1263] | 1158 | const std::vector<int>& tmp = it->second; |
---|
| 1159 | nbIndexOnServerTmp = 0; |
---|
| 1160 | for (int i = 0; i < tmp.size(); ++i) |
---|
[865] | 1161 | { |
---|
[1263] | 1162 | if (0 == nbIndexOnServerTmp(tmp[i])) ++nbIndexOnServerTmp(tmp[i]); |
---|
[865] | 1163 | } |
---|
[1263] | 1164 | nbIndexOnServer += nbIndexOnServerTmp; |
---|
| 1165 | } |
---|
[865] | 1166 | |
---|
[1263] | 1167 | for (int i = 0; i < serverSize; ++i) |
---|
| 1168 | { |
---|
| 1169 | if (0 != nbIndexOnServer(i)) |
---|
[865] | 1170 | { |
---|
[1263] | 1171 | globalElementIndexOnServer[idx][i].resize(nbIndexOnServer(i)); |
---|
| 1172 | elementOnServer[idx][i] = true; |
---|
[865] | 1173 | } |
---|
[1263] | 1174 | } |
---|
[865] | 1175 | |
---|
[1263] | 1176 | nbIndexOnServer = 0; |
---|
| 1177 | for (size_t j = 0; j < globalIndexElementOnServerMap.size(); ++j) |
---|
| 1178 | { |
---|
| 1179 | it = globalIndexElementOnServerMap.find(globalIndexElementOnClient(j)); |
---|
| 1180 | if (it != ite) |
---|
[1054] | 1181 | { |
---|
[1263] | 1182 | const std::vector<int>& tmp = it->second; |
---|
| 1183 | nbIndexOnServerTmp = 0; |
---|
| 1184 | for (int i = 0; i < tmp.size(); ++i) |
---|
[865] | 1185 | { |
---|
[1263] | 1186 | if (0 == nbIndexOnServerTmp(tmp[i])) |
---|
[914] | 1187 | { |
---|
[1263] | 1188 | globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer(tmp[i])] = it->first; |
---|
| 1189 | ++nbIndexOnServerTmp(tmp[i]); |
---|
[914] | 1190 | } |
---|
[865] | 1191 | } |
---|
[1263] | 1192 | nbIndexOnServer += nbIndexOnServerTmp; |
---|
[865] | 1193 | } |
---|
[1054] | 1194 | } |
---|
[1263] | 1195 | } |
---|
[865] | 1196 | |
---|
[1263] | 1197 | // Determine server which contain global source index |
---|
| 1198 | std::vector<bool> intersectedProc(serverSize, true); |
---|
| 1199 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 1200 | { |
---|
| 1201 | std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), |
---|
| 1202 | intersectedProc.begin(), intersectedProc.begin(), |
---|
| 1203 | std::logical_and<bool>()); |
---|
| 1204 | } |
---|
| 1205 | |
---|
| 1206 | std::vector<int> srcRank; |
---|
| 1207 | for (int idx = 0; idx < serverSize; ++idx) |
---|
| 1208 | { |
---|
| 1209 | if (intersectedProc[idx]) srcRank.push_back(idx); |
---|
| 1210 | } |
---|
| 1211 | |
---|
| 1212 | // Compute the global index of grid from global index of each element. |
---|
| 1213 | for (int i = 0; i < srcRank.size(); ++i) |
---|
| 1214 | { |
---|
| 1215 | size_t ssize = 1; |
---|
| 1216 | int rankSrc = srcRank[i]; |
---|
| 1217 | std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); |
---|
| 1218 | std::vector<size_t> currentIndex(nbElement,0); |
---|
[865] | 1219 | for (int idx = 0; idx < nbElement; ++idx) |
---|
| 1220 | { |
---|
[1263] | 1221 | ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); |
---|
| 1222 | globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); |
---|
[865] | 1223 | } |
---|
[1263] | 1224 | globalIndexOnServer[rankSrc].resize(ssize); |
---|
[865] | 1225 | |
---|
[1263] | 1226 | std::vector<int> idxLoop(nbElement,0); |
---|
| 1227 | int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); |
---|
| 1228 | size_t idx = 0; |
---|
| 1229 | while (idx < ssize) |
---|
[865] | 1230 | { |
---|
[1263] | 1231 | for (int ind = 0; ind < nbElement; ++ind) |
---|
| 1232 | { |
---|
| 1233 | if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) |
---|
| 1234 | { |
---|
| 1235 | idxLoop[ind] = 0; |
---|
| 1236 | ++idxLoop[ind+1]; |
---|
| 1237 | } |
---|
[1009] | 1238 | |
---|
[1263] | 1239 | currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; |
---|
[865] | 1240 | } |
---|
| 1241 | |
---|
[1263] | 1242 | for (int ind = 0; ind < innnerLoopSize; ++ind) |
---|
[865] | 1243 | { |
---|
[1263] | 1244 | currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; |
---|
| 1245 | size_t globalSrcIndex = 0; |
---|
| 1246 | for (int idxElement = 0; idxElement < nbElement; ++idxElement) |
---|
[865] | 1247 | { |
---|
[1263] | 1248 | globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; |
---|
[865] | 1249 | } |
---|
[1263] | 1250 | globalIndexOnServer[rankSrc][idx] = globalSrcIndex; |
---|
| 1251 | ++idx; |
---|
| 1252 | ++idxLoop[0]; |
---|
[865] | 1253 | } |
---|
| 1254 | } |
---|
[1158] | 1255 | } |
---|
[865] | 1256 | } |
---|
[1622] | 1257 | CATCH_DUMP_ATTR |
---|
[2131] | 1258 | |
---|
| 1259 | //--------------------------------------------------------------- |
---|
| 1260 | |
---|
| 1261 | /* |
---|
| 1262 | */ |
---|
| 1263 | void CGrid::computeTileIndex() |
---|
| 1264 | TRY |
---|
| 1265 | { |
---|
| 1266 | int numElement = axis_domain_order.numElements(); |
---|
| 1267 | storeTileIndex.resize(nTiles_); |
---|
| 1268 | |
---|
| 1269 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 1270 | std::vector<CDomain*> domainListP = this->getDomains(); |
---|
| 1271 | |
---|
| 1272 | // First, allocate storeTileIndex[0..ntiles] |
---|
| 1273 | for (int iTile = 0; iTile < nTiles_; ++iTile) |
---|
| 1274 | { |
---|
| 1275 | int tileGridSize = 1; |
---|
| 1276 | int axisIndex = 0, domIndex = 0; |
---|
| 1277 | for (int idx = 0; idx < numElement; ++idx) |
---|
| 1278 | { |
---|
| 1279 | int eleDim = axis_domain_order(idx); |
---|
| 1280 | if (2 == eleDim) |
---|
| 1281 | { |
---|
| 1282 | tileGridSize *= domainListP[domIndex]->getTileDataISize(iTile); |
---|
| 1283 | tileGridSize *= domainListP[domIndex]->getTileDataJSize(iTile); |
---|
| 1284 | ++domIndex; |
---|
| 1285 | } |
---|
| 1286 | else if (1 == eleDim)// So it's an axis |
---|
| 1287 | { |
---|
| 1288 | tileGridSize *= axisListP[axisIndex]->n.getValue(); |
---|
| 1289 | ++axisIndex; |
---|
| 1290 | } |
---|
| 1291 | } // loop over grid elements |
---|
| 1292 | storeTileIndex[iTile].resize(tileGridSize); |
---|
| 1293 | storeTileIndex[iTile] = -1; |
---|
| 1294 | } // loop over tiles |
---|
| 1295 | |
---|
| 1296 | // Now fill in storeTileIndex |
---|
| 1297 | // Currently assuming two possible situations : (1) domain x axis or (2) domain |
---|
| 1298 | std::vector<int> tileIndexCount (nTiles_,0); |
---|
| 1299 | int axisSize = 1; |
---|
| 1300 | if (axisListP.size() != 0) axisSize = axisListP[0]->n.getValue(); |
---|
| 1301 | int ni = domainListP[0]->ni.getValue(); |
---|
| 1302 | int nj = domainListP[0]->nj.getValue(); |
---|
| 1303 | |
---|
| 1304 | for (int idxAxis = 0; idxAxis < axisSize; ++idxAxis) |
---|
| 1305 | { |
---|
| 1306 | for (int jIdxDom = 0; jIdxDom < nj; ++jIdxDom) |
---|
| 1307 | { |
---|
| 1308 | for (int iIdxDom = 0; iIdxDom < ni; ++iIdxDom) |
---|
| 1309 | { |
---|
| 1310 | int tile = domainListP[0]->getTileId(iIdxDom, jIdxDom); |
---|
| 1311 | int tileOffset = domainListP[0]->tile_data_ibegin(tile); // only sign of offset matters |
---|
| 1312 | |
---|
| 1313 | // case 1: data size corresponds to tile size |
---|
| 1314 | if (tileOffset == 0) |
---|
| 1315 | { |
---|
| 1316 | storeTileIndex[tile](tileIndexCount[tile]) = idxAxis*nj*ni + jIdxDom * ni + iIdxDom; |
---|
| 1317 | ++tileIndexCount[tile]; |
---|
| 1318 | } |
---|
| 1319 | // case 2: masked data |
---|
| 1320 | else if (tileOffset > 0) |
---|
| 1321 | { |
---|
| 1322 | int iBegin = domainListP[0]->tile_ibegin(tile) + domainListP[0]->tile_data_ibegin(tile); // tile data relative to domain |
---|
| 1323 | int jBegin = domainListP[0]->tile_jbegin(tile) + domainListP[0]->tile_data_jbegin(tile); // tile data relative to domain |
---|
| 1324 | int iEnd = iBegin + domainListP[0]->tile_data_ni(tile); |
---|
| 1325 | int jEnd = jBegin + domainListP[0]->tile_data_nj(tile); |
---|
| 1326 | if ((jIdxDom >= jBegin) && (jIdxDom < jEnd) && (iIdxDom >= iBegin) && (iIdxDom < iEnd)) |
---|
| 1327 | { |
---|
| 1328 | storeTileIndex[tile](tileIndexCount[tile]) = idxAxis*nj*ni + jIdxDom * ni + iIdxDom; |
---|
| 1329 | } |
---|
| 1330 | ++tileIndexCount[tile]; |
---|
| 1331 | } |
---|
| 1332 | // case 3: ghost zones |
---|
| 1333 | else |
---|
| 1334 | { |
---|
| 1335 | int tileDataNi = domainListP[0]->tile_data_ni(tile); |
---|
| 1336 | int tileDataNj = domainListP[0]->tile_data_nj(tile); |
---|
| 1337 | int tileDomSize = tileDataNi * tileDataNj; |
---|
| 1338 | int tileNi = domainListP[0]->tile_ni(tile); |
---|
| 1339 | int iBegin = domainListP[0]->tile_data_ibegin(tile); |
---|
| 1340 | int jBegin = domainListP[0]->tile_data_jbegin(tile); |
---|
| 1341 | |
---|
| 1342 | // add the ghost zone at the beginning of a domain tile |
---|
| 1343 | if (tileIndexCount[tile] % tileDomSize == 0) |
---|
| 1344 | tileIndexCount[tile] += (abs(jBegin)*tileDataNi + abs(iBegin)); |
---|
| 1345 | |
---|
| 1346 | storeTileIndex[tile](tileIndexCount[tile]) = idxAxis*nj*ni + jIdxDom*ni + iIdxDom; |
---|
| 1347 | |
---|
| 1348 | // add two ghost zones at the right end of a tile |
---|
| 1349 | if ( (iIdxDom+1) % tileNi == 0 ) |
---|
| 1350 | tileIndexCount[tile] += (2*abs(iBegin)); |
---|
| 1351 | |
---|
| 1352 | // add ghost zone at the end of a domain tile |
---|
| 1353 | if ((tileIndexCount[tile] + abs(jBegin)*tileDataNi-abs(iBegin) + 1) % tileDomSize == 0) |
---|
| 1354 | tileIndexCount[tile] += (abs(jBegin)*tileDataNi -abs(iBegin)); |
---|
| 1355 | |
---|
| 1356 | ++tileIndexCount[tile]; |
---|
| 1357 | } |
---|
| 1358 | } // loop over domain first dimension |
---|
| 1359 | } // loop over domain second dimension |
---|
| 1360 | } // loop over axis dimension |
---|
| 1361 | |
---|
| 1362 | } |
---|
| 1363 | CATCH_DUMP_ATTR |
---|
| 1364 | |
---|
[1622] | 1365 | //---------------------------------------------------------------- |
---|
[219] | 1366 | |
---|
[347] | 1367 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[1622] | 1368 | TRY |
---|
[219] | 1369 | { |
---|
[745] | 1370 | std::vector<CDomain*> vecDom(1, domain); |
---|
[567] | 1371 | std::vector<CAxis*> vecAxis; |
---|
[540] | 1372 | |
---|
[745] | 1373 | return createGrid(vecDom, vecAxis); |
---|
[219] | 1374 | } |
---|
[1622] | 1375 | CATCH |
---|
[219] | 1376 | |
---|
[347] | 1377 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[1622] | 1378 | TRY |
---|
| 1379 | { |
---|
[745] | 1380 | std::vector<CDomain*> vecDom(1, domain); |
---|
| 1381 | std::vector<CAxis*> vecAxis(1, axis); |
---|
[567] | 1382 | |
---|
[745] | 1383 | return createGrid(vecDom, vecAxis); |
---|
[219] | 1384 | } |
---|
[1622] | 1385 | CATCH |
---|
[219] | 1386 | |
---|
[745] | 1387 | CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 1388 | const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 1389 | TRY |
---|
[540] | 1390 | { |
---|
[887] | 1391 | std::vector<CScalar*> vecScalar; |
---|
| 1392 | return createGrid(generateId(domains, axis, vecScalar, axisDomainOrder), domains, axis, vecScalar, axisDomainOrder); |
---|
[745] | 1393 | } |
---|
[1622] | 1394 | CATCH |
---|
[540] | 1395 | |
---|
[887] | 1396 | CGrid* CGrid::createGrid(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
| 1397 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 1398 | TRY |
---|
[887] | 1399 | { |
---|
| 1400 | return createGrid(generateId(domains, axis, scalars, axisDomainOrder), domains, axis, scalars, axisDomainOrder); |
---|
| 1401 | } |
---|
[1622] | 1402 | CATCH |
---|
[887] | 1403 | |
---|
[745] | 1404 | CGrid* CGrid::createGrid(StdString id, const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 1405 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 1406 | TRY |
---|
[745] | 1407 | { |
---|
[887] | 1408 | if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 1409 | ERROR("CGrid* CGrid::createGrid(...)", |
---|
| 1410 | << "The size of axisDomainOrder (" << axisDomainOrder.numElements() |
---|
| 1411 | << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); |
---|
| 1412 | |
---|
| 1413 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(id); |
---|
[540] | 1414 | grid->setDomainList(domains); |
---|
| 1415 | grid->setAxisList(axis); |
---|
[887] | 1416 | grid->setScalarList(scalars); |
---|
[551] | 1417 | |
---|
[745] | 1418 | // By default, domains are always the first elements of a grid |
---|
[622] | 1419 | if (0 == axisDomainOrder.numElements()) |
---|
[551] | 1420 | { |
---|
[887] | 1421 | int size = domains.size() + axis.size() + scalars.size(); |
---|
| 1422 | int nb = 0; |
---|
[575] | 1423 | grid->axis_domain_order.resize(size); |
---|
[551] | 1424 | for (int i = 0; i < size; ++i) |
---|
| 1425 | { |
---|
[887] | 1426 | if (i < domains.size()) { |
---|
| 1427 | grid->axis_domain_order(i) = 2; |
---|
| 1428 | |
---|
| 1429 | } |
---|
| 1430 | else if ((scalars.size() < (size-nb)) < size) { |
---|
| 1431 | grid->axis_domain_order(i) = 1; |
---|
| 1432 | } |
---|
| 1433 | else |
---|
| 1434 | grid->axis_domain_order(i) = 0; |
---|
| 1435 | ++nb; |
---|
[551] | 1436 | } |
---|
| 1437 | } |
---|
[622] | 1438 | else |
---|
| 1439 | { |
---|
| 1440 | grid->axis_domain_order.resize(axisDomainOrder.numElements()); |
---|
| 1441 | grid->axis_domain_order = axisDomainOrder; |
---|
| 1442 | } |
---|
[551] | 1443 | |
---|
[742] | 1444 | grid->solveDomainAxisRefInheritance(true); |
---|
| 1445 | |
---|
[650] | 1446 | return grid; |
---|
[540] | 1447 | } |
---|
[1622] | 1448 | CATCH |
---|
[540] | 1449 | |
---|
[823] | 1450 | CGrid* CGrid::cloneGrid(const StdString& idNewGrid, CGrid* gridSrc) |
---|
[1622] | 1451 | TRY |
---|
[823] | 1452 | { |
---|
[887] | 1453 | std::vector<CDomain*> domainSrcTmp = gridSrc->getDomains(), domainSrc; |
---|
[823] | 1454 | std::vector<CAxis*> axisSrcTmp = gridSrc->getAxis(), axisSrc; |
---|
[887] | 1455 | std::vector<CScalar*> scalarSrcTmp = gridSrc->getScalars(), scalarSrc; |
---|
| 1456 | |
---|
| 1457 | for (int idx = 0; idx < domainSrcTmp.size(); ++idx) |
---|
| 1458 | { |
---|
| 1459 | CDomain* domain = CDomain::createDomain(); |
---|
| 1460 | domain->duplicateAttributes(domainSrcTmp[idx]); |
---|
| 1461 | domain->duplicateTransformation(domainSrcTmp[idx]); |
---|
| 1462 | domain->solveRefInheritance(true); |
---|
| 1463 | domain->solveInheritanceTransformation(); |
---|
| 1464 | domainSrc.push_back(domain); |
---|
| 1465 | } |
---|
| 1466 | |
---|
[823] | 1467 | for (int idx = 0; idx < axisSrcTmp.size(); ++idx) |
---|
| 1468 | { |
---|
| 1469 | CAxis* axis = CAxis::createAxis(); |
---|
| 1470 | axis->duplicateAttributes(axisSrcTmp[idx]); |
---|
| 1471 | axis->duplicateTransformation(axisSrcTmp[idx]); |
---|
| 1472 | axis->solveRefInheritance(true); |
---|
| 1473 | axis->solveInheritanceTransformation(); |
---|
| 1474 | axisSrc.push_back(axis); |
---|
| 1475 | } |
---|
| 1476 | |
---|
[887] | 1477 | for (int idx = 0; idx < scalarSrcTmp.size(); ++idx) |
---|
[823] | 1478 | { |
---|
[887] | 1479 | CScalar* scalar = CScalar::createScalar(); |
---|
| 1480 | scalar->duplicateAttributes(scalarSrcTmp[idx]); |
---|
| 1481 | scalar->duplicateTransformation(scalarSrcTmp[idx]); |
---|
| 1482 | scalar->solveRefInheritance(true); |
---|
| 1483 | scalar->solveInheritanceTransformation(); |
---|
| 1484 | scalarSrc.push_back(scalar); |
---|
[823] | 1485 | } |
---|
| 1486 | |
---|
[887] | 1487 | CGrid* grid = CGrid::createGrid(idNewGrid, domainSrc, axisSrc, scalarSrc, gridSrc->axis_domain_order); |
---|
[823] | 1488 | |
---|
| 1489 | return grid; |
---|
| 1490 | } |
---|
[1622] | 1491 | CATCH |
---|
[823] | 1492 | |
---|
[745] | 1493 | StdString CGrid::generateId(const std::vector<CDomain*>& domains, const std::vector<CAxis*>& axis, |
---|
[887] | 1494 | const std::vector<CScalar*>& scalars, const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 1495 | TRY |
---|
[745] | 1496 | { |
---|
[887] | 1497 | if (axisDomainOrder.numElements() > 0 && axisDomainOrder.numElements() != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 1498 | ERROR("CGrid* CGrid::generateId(...)", |
---|
| 1499 | << "The size of axisDomainOrder (" << axisDomainOrder.numElements() |
---|
| 1500 | << ") is not coherent with the number of elements (" << domains.size() + axis.size() <<")."); |
---|
| 1501 | |
---|
| 1502 | std::ostringstream id; |
---|
| 1503 | |
---|
[887] | 1504 | if (domains.empty() && axis.empty() && !scalars.empty()) |
---|
| 1505 | id << "__scalar_"; |
---|
| 1506 | |
---|
| 1507 | if (0 != (domains.size() + axis.size() + scalars.size())) |
---|
[745] | 1508 | { |
---|
| 1509 | id << "__grid"; |
---|
| 1510 | |
---|
| 1511 | if (0 == axisDomainOrder.numElements()) |
---|
| 1512 | { |
---|
| 1513 | for (size_t i = 0; i < domains.size(); ++i) id << "_" << domains[i]->getId(); |
---|
| 1514 | for (size_t i = 0; i < axis.size(); ++i) id << "_" << axis[i]->getId(); |
---|
[887] | 1515 | for (size_t i = 0; i < scalars.size(); ++i) id << "_" << scalars[i]->getId(); |
---|
[745] | 1516 | } |
---|
| 1517 | else |
---|
| 1518 | { |
---|
[887] | 1519 | size_t iDomain = 0, iAxis = 0, iScalar = 0; |
---|
[745] | 1520 | for (size_t i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 1521 | { |
---|
[887] | 1522 | if (2 == axisDomainOrder(i)) |
---|
[745] | 1523 | id << "_" << domains[iDomain++]->getId(); |
---|
[887] | 1524 | else if (1 == axisDomainOrder(i)) |
---|
| 1525 | id << "_" << axis[iAxis++]->getId(); |
---|
[745] | 1526 | else |
---|
[887] | 1527 | id << "_" << scalars[iScalar++]->getId(); |
---|
[745] | 1528 | } |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | id << "__"; |
---|
| 1532 | } |
---|
| 1533 | |
---|
| 1534 | return id.str(); |
---|
| 1535 | } |
---|
[1622] | 1536 | CATCH |
---|
[745] | 1537 | |
---|
[823] | 1538 | StdString CGrid::generateId(const CGrid* gridSrc, const CGrid* gridDest) |
---|
[1622] | 1539 | TRY |
---|
[823] | 1540 | { |
---|
| 1541 | StdString idSrc = gridSrc->getId(); |
---|
| 1542 | StdString idDest = gridDest->getId(); |
---|
| 1543 | |
---|
| 1544 | std::ostringstream id; |
---|
| 1545 | id << idSrc << "__" << idDest; |
---|
| 1546 | |
---|
| 1547 | return id.str(); |
---|
| 1548 | } |
---|
[1622] | 1549 | CATCH |
---|
[823] | 1550 | |
---|
[745] | 1551 | //---------------------------------------------------------------- |
---|
| 1552 | |
---|
[540] | 1553 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
[1622] | 1554 | TRY |
---|
[540] | 1555 | { |
---|
[650] | 1556 | return this->vDomainGroup_; |
---|
[540] | 1557 | } |
---|
[1622] | 1558 | CATCH |
---|
[540] | 1559 | |
---|
| 1560 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
[1622] | 1561 | TRY |
---|
[540] | 1562 | { |
---|
[650] | 1563 | return this->vAxisGroup_; |
---|
[540] | 1564 | } |
---|
[1622] | 1565 | CATCH |
---|
[540] | 1566 | |
---|
[887] | 1567 | CScalarGroup* CGrid::getVirtualScalarGroup() const |
---|
[1622] | 1568 | TRY |
---|
[887] | 1569 | { |
---|
| 1570 | return this->vScalarGroup_; |
---|
| 1571 | } |
---|
[1622] | 1572 | CATCH |
---|
[887] | 1573 | |
---|
[1158] | 1574 | /* |
---|
| 1575 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, double* field) |
---|
| 1576 | { |
---|
| 1577 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
| 1578 | StdSize numElements = stored.numElements(); |
---|
| 1579 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 1580 | { |
---|
| 1581 | field[out_i(n)] = stored(n); |
---|
| 1582 | } |
---|
| 1583 | } |
---|
| 1584 | |
---|
| 1585 | void CGrid::inputField(int rank, const double* const field, CArray<double,1>& stored) |
---|
| 1586 | { |
---|
| 1587 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
| 1588 | StdSize numElements = stored.numElements(); |
---|
| 1589 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 1590 | { |
---|
| 1591 | stored(n) = field[out_i(n)]; |
---|
| 1592 | } |
---|
| 1593 | } |
---|
| 1594 | |
---|
| 1595 | void CGrid::outputCompressedField(int rank, const CArray<double,1>& stored, double* field) |
---|
| 1596 | { |
---|
| 1597 | const CArray<size_t,1>& out_i = compressedOutIndexFromClient[rank]; |
---|
| 1598 | StdSize numElements = stored.numElements(); |
---|
| 1599 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 1600 | { |
---|
| 1601 | field[out_i(n)] = stored(n); |
---|
| 1602 | } |
---|
| 1603 | } |
---|
| 1604 | */ |
---|
| 1605 | //---------------------------------------------------------------- |
---|
| 1606 | |
---|
[650] | 1607 | void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored) const |
---|
[1622] | 1608 | TRY |
---|
[219] | 1609 | { |
---|
[650] | 1610 | const StdSize size = storeIndex_client.numElements(); |
---|
[300] | 1611 | |
---|
[650] | 1612 | stored.resize(size); |
---|
| 1613 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; |
---|
[219] | 1614 | } |
---|
[1622] | 1615 | CATCH |
---|
[509] | 1616 | |
---|
[650] | 1617 | void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data) const |
---|
[1622] | 1618 | TRY |
---|
[593] | 1619 | { |
---|
[1030] | 1620 | const StdSize size = storeIndex_client.numElements(); |
---|
[593] | 1621 | |
---|
[1030] | 1622 | for(StdSize i = 0; i < size; i++) data[storeIndex_client(i)] = stored(i); |
---|
[593] | 1623 | } |
---|
[1622] | 1624 | CATCH |
---|
[593] | 1625 | |
---|
[2131] | 1626 | void CGrid::maskField_arr(const double* const data, CArray<double, 1>& stored, bool isTiled) const |
---|
| 1627 | TRY |
---|
[1637] | 1628 | { |
---|
[2131] | 1629 | const CArray<int, 1>& storeIndex_clientP = isTiled ? storeIndexTiled_client : storeIndex_client; |
---|
| 1630 | const CArray<bool, 1>& storeMask_clientP = isTiled ? storeMaskTiled_client : storeMask_client; |
---|
| 1631 | const StdSize size = storeIndex_clientP.numElements(); |
---|
[1637] | 1632 | stored.resize(size); |
---|
| 1633 | const double nanValue = std::numeric_limits<double>::quiet_NaN(); |
---|
| 1634 | |
---|
[2131] | 1635 | if (storeMask_clientP.numElements() != 0) |
---|
| 1636 | for(StdSize i = 0; i < size; i++) stored(i) = (storeMask_clientP(i)) ? data[storeIndex_clientP(i)] : nanValue; |
---|
[1637] | 1637 | else |
---|
[2131] | 1638 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_clientP(i)]; |
---|
[1637] | 1639 | } |
---|
[2131] | 1640 | CATCH |
---|
[1637] | 1641 | |
---|
[2131] | 1642 | void CGrid::copyTile_arr(const double* const tileData, CArray<double, 1>& stored, int tileId) |
---|
| 1643 | TRY |
---|
| 1644 | { |
---|
| 1645 | StdSize tileSize = this->getTileSize(tileId); |
---|
| 1646 | const StdSize tileDataSize = this->getTileDataSize(tileId); |
---|
| 1647 | |
---|
| 1648 | // case 1: data correspond in size to a tile |
---|
| 1649 | if (tileSize == tileDataSize) |
---|
| 1650 | { |
---|
| 1651 | for(StdSize i = 0; i < tileDataSize; i++) |
---|
| 1652 | stored(storeTileIndex[tileId](i)) = tileData[i]; |
---|
| 1653 | } |
---|
| 1654 | // case 2: masked data |
---|
| 1655 | else if (tileSize > tileDataSize) |
---|
| 1656 | { |
---|
| 1657 | int tileDataCount = 0; |
---|
| 1658 | for(StdSize i = 0; i < tileSize; i++) |
---|
| 1659 | if (storeTileIndex[tileId](i) >= 0) |
---|
| 1660 | { |
---|
| 1661 | stored(storeTileIndex[tileId](i)) = tileData[tileDataCount]; |
---|
| 1662 | ++tileDataCount; |
---|
| 1663 | } |
---|
| 1664 | } |
---|
| 1665 | // case 3: ghost zones |
---|
| 1666 | else |
---|
| 1667 | { |
---|
| 1668 | for(StdSize i = 0; i < tileDataSize; i++) |
---|
| 1669 | if (storeTileIndex[tileId](i) >= 0) |
---|
| 1670 | { |
---|
| 1671 | stored(storeTileIndex[tileId](i)) = tileData[i]; |
---|
| 1672 | } |
---|
| 1673 | |
---|
| 1674 | } |
---|
| 1675 | } |
---|
| 1676 | CATCH |
---|
| 1677 | |
---|
[1250] | 1678 | void CGrid::uncompressField_arr(const double* const data, CArray<double, 1>& out) const |
---|
[1622] | 1679 | TRY |
---|
[1250] | 1680 | { |
---|
| 1681 | const std::vector<int>& localMaskedDataIndex = clientDistribution_->getLocalMaskedDataIndexOnClient(); |
---|
| 1682 | const int size = localMaskedDataIndex.size(); |
---|
| 1683 | for(int i = 0; i < size; ++i) out(localMaskedDataIndex[i]) = data[i]; |
---|
| 1684 | } |
---|
[1622] | 1685 | CATCH |
---|
[1250] | 1686 | |
---|
[1202] | 1687 | void CGrid::computeClientIndexScalarGrid() |
---|
[1622] | 1688 | TRY |
---|
[300] | 1689 | { |
---|
[1144] | 1690 | CContext* context = CContext::getCurrent(); |
---|
[1202] | 1691 | { |
---|
[1263] | 1692 | CContextClient* client = context->client; |
---|
[1202] | 1693 | |
---|
[1250] | 1694 | int rank = client->clientRank; |
---|
| 1695 | |
---|
| 1696 | clientDistribution_ = new CDistributionClient(rank, this); |
---|
| 1697 | |
---|
[1202] | 1698 | storeIndex_client.resize(1); |
---|
| 1699 | storeIndex_client(0) = 0; |
---|
| 1700 | |
---|
| 1701 | if (0 != serverDistribution_) |
---|
| 1702 | { |
---|
| 1703 | map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClient.begin(), |
---|
| 1704 | ite = outGlobalIndexFromClient.end(), it; |
---|
| 1705 | for (it = itb; it != ite; ++it) |
---|
| 1706 | { |
---|
| 1707 | int rank = it->first; |
---|
| 1708 | CArray<size_t,1>& globalIndex = outGlobalIndexFromClient[rank]; |
---|
| 1709 | outLocalIndexStoreOnClient.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); |
---|
| 1710 | CArray<size_t,1>& localIndex = outLocalIndexStoreOnClient[rank]; |
---|
| 1711 | if (1 != globalIndex.numElements()) |
---|
| 1712 | ERROR("void CGrid::computeClientIndexScalarGrid()", |
---|
| 1713 | << "Something wrong happened. " |
---|
| 1714 | << "Number of received global index on scalar grid should equal to 1" |
---|
| 1715 | << "Number of received global index " << globalIndex.numElements() << "."); |
---|
| 1716 | |
---|
| 1717 | localIndex(0) = globalIndex(0); |
---|
| 1718 | } |
---|
| 1719 | } |
---|
| 1720 | } |
---|
| 1721 | } |
---|
[1622] | 1722 | CATCH_DUMP_ATTR |
---|
[1202] | 1723 | |
---|
| 1724 | void CGrid::computeConnectedClientsScalarGrid() |
---|
[1622] | 1725 | TRY |
---|
[1202] | 1726 | { |
---|
| 1727 | CContext* context = CContext::getCurrent(); |
---|
[1263] | 1728 | int nbSrvPools = (context->clientPrimServer.size()==0) ? 1 : context->clientPrimServer.size(); |
---|
[1236] | 1729 | connectedServerRank_.clear(); |
---|
| 1730 | connectedDataSize_.clear(); |
---|
| 1731 | nbSenders.clear(); |
---|
[1099] | 1732 | |
---|
| 1733 | for (int p = 0; p < nbSrvPools; ++p) |
---|
[1009] | 1734 | { |
---|
[1263] | 1735 | CContextClient* client = (context->clientPrimServer.size()==0) ? context->client : context->clientPrimServer[p]; |
---|
| 1736 | int receiverSize = client->serverSize; |
---|
[586] | 1737 | |
---|
[1263] | 1738 | // connectedServerRank_[client].clear(); |
---|
[926] | 1739 | |
---|
[1263] | 1740 | if (connectedServerRank_.find(receiverSize)==connectedServerRank_.end()) |
---|
[926] | 1741 | { |
---|
[1263] | 1742 | if (client->isServerLeader()) |
---|
[1009] | 1743 | { |
---|
[1263] | 1744 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1745 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1746 | { |
---|
| 1747 | int rank = *itRank; |
---|
| 1748 | int nb = 1; |
---|
| 1749 | connectedServerRank_[receiverSize].push_back(rank); |
---|
| 1750 | connectedDataSize_[receiverSize][rank] = nb; |
---|
| 1751 | nbSenders[receiverSize][rank] = nb; |
---|
| 1752 | } |
---|
[1009] | 1753 | } |
---|
[1263] | 1754 | else |
---|
[1202] | 1755 | { |
---|
[1263] | 1756 | const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 1757 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1758 | { |
---|
| 1759 | int rank = *itRank; |
---|
| 1760 | int nb = 1; |
---|
| 1761 | connectedServerRank_[receiverSize].push_back(rank); |
---|
| 1762 | connectedDataSize_[receiverSize][rank] = nb; |
---|
| 1763 | nbSenders[receiverSize][rank] = nb; |
---|
| 1764 | } |
---|
| 1765 | } |
---|
[1202] | 1766 | } |
---|
[1009] | 1767 | isDataDistributed_ = false; |
---|
[586] | 1768 | } |
---|
| 1769 | } |
---|
[1622] | 1770 | CATCH_DUMP_ATTR |
---|
[586] | 1771 | |
---|
| 1772 | void CGrid::sendIndexScalarGrid() |
---|
[1622] | 1773 | TRY |
---|
[586] | 1774 | { |
---|
[650] | 1775 | CContext* context = CContext::getCurrent(); |
---|
[1236] | 1776 | storeIndex_toSrv.clear(); |
---|
[1353] | 1777 | std::list<CContextClient*>::iterator it; |
---|
[1236] | 1778 | |
---|
[1294] | 1779 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
[1009] | 1780 | { |
---|
[1294] | 1781 | CContextClient* client = *it; |
---|
[1263] | 1782 | int receiverSize = client->serverSize; |
---|
[509] | 1783 | |
---|
[1009] | 1784 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 1785 | list<CMessage> listMsg; |
---|
| 1786 | list<CArray<size_t,1> > listOutIndex; |
---|
[650] | 1787 | |
---|
[1009] | 1788 | if (client->isServerLeader()) |
---|
[551] | 1789 | { |
---|
[1009] | 1790 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1791 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1792 | { |
---|
| 1793 | int rank = *itRank; |
---|
| 1794 | int nb = 1; |
---|
[1236] | 1795 | storeIndex_toSrv[client].insert(std::make_pair(rank, CArray<int,1>(nb))); |
---|
[1009] | 1796 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
[650] | 1797 | |
---|
[1236] | 1798 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[client][rank]; |
---|
[1009] | 1799 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
[650] | 1800 | |
---|
[1009] | 1801 | for (int k = 0; k < nb; ++k) |
---|
| 1802 | { |
---|
| 1803 | outGlobalIndexOnServer(k) = 0; |
---|
| 1804 | outLocalIndexToServer(k) = 0; |
---|
| 1805 | } |
---|
[586] | 1806 | |
---|
[1236] | 1807 | if (context->hasClient && !context->hasServer) |
---|
| 1808 | storeIndex_fromSrv.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1809 | |
---|
[1009] | 1810 | listMsg.push_back(CMessage()); |
---|
| 1811 | listMsg.back() << getId( )<< isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[586] | 1812 | |
---|
[1009] | 1813 | event.push(rank, 1, listMsg.back()); |
---|
| 1814 | } |
---|
| 1815 | client->sendEvent(event); |
---|
[650] | 1816 | } |
---|
[1009] | 1817 | else |
---|
[1021] | 1818 | { |
---|
| 1819 | const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 1820 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1821 | { |
---|
| 1822 | int rank = *itRank; |
---|
[1236] | 1823 | int nb = 1; |
---|
[1238] | 1824 | CArray<int, 1> outLocalIndexToServer(nb); |
---|
[1021] | 1825 | for (int k = 0; k < nb; ++k) |
---|
| 1826 | { |
---|
| 1827 | outLocalIndexToServer(k) = 0; |
---|
| 1828 | } |
---|
[1236] | 1829 | |
---|
| 1830 | if (context->hasClient && !context->hasServer) |
---|
| 1831 | storeIndex_fromSrv.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
[1021] | 1832 | } |
---|
[1009] | 1833 | client->sendEvent(event); |
---|
[1021] | 1834 | } |
---|
[584] | 1835 | } |
---|
[586] | 1836 | } |
---|
[1622] | 1837 | CATCH_DUMP_ATTR |
---|
[551] | 1838 | |
---|
[586] | 1839 | void CGrid::sendIndex(void) |
---|
[1622] | 1840 | TRY |
---|
[586] | 1841 | { |
---|
[650] | 1842 | CContext* context = CContext::getCurrent(); |
---|
[1236] | 1843 | storeIndex_toSrv.clear(); |
---|
[1353] | 1844 | std::list<CContextClient*>::iterator it; |
---|
[1294] | 1845 | |
---|
| 1846 | for (it=clients.begin(); it!=clients.end(); ++it) |
---|
[1009] | 1847 | { |
---|
[1294] | 1848 | CContextClient* client = *it; |
---|
[1263] | 1849 | int receiverSize = client->serverSize; |
---|
[586] | 1850 | |
---|
[1009] | 1851 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 1852 | int rank; |
---|
| 1853 | list<CMessage> listMsg; |
---|
| 1854 | list<CArray<size_t,1> > listOutIndex; |
---|
| 1855 | const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); |
---|
[1030] | 1856 | CDistributionClient::GlobalLocalDataMap::const_iterator itbIndex = globalLocalIndexSendToServer.begin(), itIndex, |
---|
| 1857 | iteIndex = globalLocalIndexSendToServer.end(); |
---|
| 1858 | itIndex = itbIndex; |
---|
[586] | 1859 | |
---|
[1235] | 1860 | if (!doGridHaveDataDistributed(client)) |
---|
[585] | 1861 | { |
---|
[1009] | 1862 | if (client->isServerLeader()) |
---|
[831] | 1863 | { |
---|
[1009] | 1864 | int indexSize = globalLocalIndexSendToServer.size(); |
---|
| 1865 | CArray<size_t,1> outGlobalIndexOnServer(indexSize); |
---|
| 1866 | CArray<int,1> outLocalIndexToServer(indexSize); |
---|
| 1867 | for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) |
---|
| 1868 | { |
---|
| 1869 | outGlobalIndexOnServer(idx) = itIndex->first; |
---|
| 1870 | outLocalIndexToServer(idx) = itIndex->second; |
---|
| 1871 | } |
---|
[650] | 1872 | |
---|
[1009] | 1873 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 1874 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1875 | { |
---|
[1236] | 1876 | storeIndex_toSrv[client].insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1877 | if (context->hasClient && !context->hasServer) |
---|
| 1878 | storeIndex_fromSrv.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1879 | |
---|
[1009] | 1880 | listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
[585] | 1881 | |
---|
[1009] | 1882 | listMsg.push_back(CMessage()); |
---|
| 1883 | listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
[585] | 1884 | |
---|
[1009] | 1885 | event.push(*itRank, 1, listMsg.back()); |
---|
| 1886 | } |
---|
| 1887 | client->sendEvent(event); |
---|
[585] | 1888 | } |
---|
[1009] | 1889 | else |
---|
[1021] | 1890 | { |
---|
| 1891 | int indexSize = globalLocalIndexSendToServer.size(); |
---|
| 1892 | CArray<int,1> outLocalIndexToServer(indexSize); |
---|
| 1893 | for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) |
---|
| 1894 | { |
---|
| 1895 | outLocalIndexToServer(idx) = itIndex->second; |
---|
| 1896 | } |
---|
| 1897 | |
---|
| 1898 | const std::list<int>& ranks = client->getRanksServerNotLeader(); |
---|
| 1899 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 1900 | { |
---|
| 1901 | storeIndex_fromSrv.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 1902 | } |
---|
| 1903 | client->sendEvent(event); |
---|
| 1904 | } |
---|
[585] | 1905 | } |
---|
| 1906 | else |
---|
[1009] | 1907 | { |
---|
[1129] | 1908 | CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; |
---|
[1263] | 1909 | itGlobalMap = globalIndexOnServer_[receiverSize].begin(); |
---|
| 1910 | iteGlobalMap = globalIndexOnServer_[receiverSize].end(); |
---|
[1129] | 1911 | |
---|
[1009] | 1912 | std::map<int,std::vector<int> >localIndexTmp; |
---|
| 1913 | std::map<int,std::vector<size_t> > globalIndexTmp; |
---|
[1129] | 1914 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
[586] | 1915 | { |
---|
[1129] | 1916 | int serverRank = itGlobalMap->first; |
---|
| 1917 | int indexSize = itGlobalMap->second.size(); |
---|
[1009] | 1918 | const std::vector<size_t>& indexVec = itGlobalMap->second; |
---|
| 1919 | for (int idx = 0; idx < indexSize; ++idx) |
---|
[586] | 1920 | { |
---|
[1009] | 1921 | itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); |
---|
| 1922 | if (iteIndex != itIndex) |
---|
[1129] | 1923 | { |
---|
| 1924 | globalIndexTmp[serverRank].push_back(itIndex->first); |
---|
| 1925 | localIndexTmp[serverRank].push_back(itIndex->second); |
---|
[1009] | 1926 | } |
---|
[586] | 1927 | } |
---|
| 1928 | } |
---|
| 1929 | |
---|
[1263] | 1930 | for (int ns = 0; ns < connectedServerRank_[receiverSize].size(); ++ns) |
---|
[1009] | 1931 | { |
---|
[1263] | 1932 | rank = connectedServerRank_[receiverSize][ns]; |
---|
[1009] | 1933 | int nb = 0; |
---|
| 1934 | if (globalIndexTmp.end() != globalIndexTmp.find(rank)) |
---|
| 1935 | nb = globalIndexTmp[rank].size(); |
---|
[509] | 1936 | |
---|
[1236] | 1937 | storeIndex_toSrv[client].insert(make_pair(rank, CArray<int,1>(nb))); |
---|
[1009] | 1938 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
[650] | 1939 | |
---|
[1236] | 1940 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[client][rank]; |
---|
[1009] | 1941 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
[650] | 1942 | |
---|
[1009] | 1943 | for (int k = 0; k < nb; ++k) |
---|
| 1944 | { |
---|
| 1945 | outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); |
---|
| 1946 | outLocalIndexToServer(k) = localIndexTmp[rank].at(k); |
---|
| 1947 | } |
---|
| 1948 | |
---|
[1021] | 1949 | storeIndex_fromSrv.insert(make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
[1009] | 1950 | listMsg.push_back(CMessage()); |
---|
| 1951 | listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); |
---|
| 1952 | |
---|
[1263] | 1953 | event.push(rank, nbSenders[receiverSize][rank], listMsg.back()); |
---|
[567] | 1954 | } |
---|
[509] | 1955 | |
---|
[1009] | 1956 | client->sendEvent(event); |
---|
[567] | 1957 | } |
---|
[300] | 1958 | } |
---|
| 1959 | } |
---|
[1622] | 1960 | CATCH_DUMP_ATTR |
---|
[509] | 1961 | |
---|
[300] | 1962 | void CGrid::recvIndex(CEventServer& event) |
---|
[1622] | 1963 | TRY |
---|
[300] | 1964 | { |
---|
[598] | 1965 | string gridId; |
---|
| 1966 | vector<int> ranks; |
---|
| 1967 | vector<CBufferIn*> buffers; |
---|
| 1968 | |
---|
| 1969 | list<CEventServer::SSubEvent>::iterator it; |
---|
[650] | 1970 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 1971 | { |
---|
[598] | 1972 | ranks.push_back(it->rank); |
---|
| 1973 | CBufferIn* buffer = it->buffer; |
---|
| 1974 | *buffer >> gridId; |
---|
| 1975 | buffers.push_back(buffer); |
---|
[300] | 1976 | } |
---|
[650] | 1977 | get(gridId)->recvIndex(ranks, buffers); |
---|
[300] | 1978 | } |
---|
[1622] | 1979 | CATCH |
---|
[509] | 1980 | |
---|
[967] | 1981 | void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
[1622] | 1982 | TRY |
---|
[967] | 1983 | { |
---|
| 1984 | CContext* context = CContext::getCurrent(); |
---|
[1330] | 1985 | connectedServerRankRead_ = ranks; |
---|
[1099] | 1986 | |
---|
[1030] | 1987 | int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1; |
---|
[1144] | 1988 | nbSrvPools = 1; |
---|
[1236] | 1989 | nbReadSenders.clear(); |
---|
[1054] | 1990 | for (int p = 0; p < nbSrvPools; ++p) |
---|
[967] | 1991 | { |
---|
[1054] | 1992 | CContextServer* server = (!context->hasClient) ? context->server : context->serverPrimServer[p]; |
---|
[1239] | 1993 | CContextClient* client = context->client; //(!context->hasClient) ? context->client : context->clientPrimServer[p]; |
---|
[1136] | 1994 | |
---|
[1129] | 1995 | int idx = 0, numElement = axis_domain_order.numElements(); |
---|
| 1996 | int ssize = numElement; |
---|
| 1997 | std::vector<int> indexMap(numElement); |
---|
| 1998 | for (int i = 0; i < numElement; ++i) |
---|
| 1999 | { |
---|
| 2000 | indexMap[i] = idx; |
---|
| 2001 | if (2 == axis_domain_order(i)) |
---|
| 2002 | { |
---|
| 2003 | ++ssize; |
---|
| 2004 | idx += 2; |
---|
| 2005 | } |
---|
| 2006 | else |
---|
| 2007 | ++idx; |
---|
| 2008 | } |
---|
| 2009 | |
---|
[1027] | 2010 | for (int n = 0; n < ranks.size(); n++) |
---|
| 2011 | { |
---|
| 2012 | int rank = ranks[n]; |
---|
| 2013 | CBufferIn& buffer = *buffers[n]; |
---|
[967] | 2014 | |
---|
[1027] | 2015 | buffer >> isDataDistributed_ >> isCompressible_; |
---|
| 2016 | size_t dataSize = 0; |
---|
| 2017 | |
---|
| 2018 | if (0 == serverDistribution_) |
---|
[967] | 2019 | { |
---|
[1027] | 2020 | int axisId = 0, domainId = 0, scalarId = 0, globalSize = 1; |
---|
| 2021 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 2022 | std::vector<CAxis*> axisList = getAxis(); |
---|
[1559] | 2023 | std::vector<int> nBegin(ssize), nSize(ssize), nGlob(ssize), nBeginGlobal(ssize), nGlobElement(numElement); |
---|
| 2024 | std::vector<CArray<int,1> > globalIndex(numElement); |
---|
[1027] | 2025 | for (int i = 0; i < numElement; ++i) |
---|
[967] | 2026 | { |
---|
[1027] | 2027 | nGlobElement[i] = globalSize; |
---|
| 2028 | if (2 == axis_domain_order(i)) //domain |
---|
| 2029 | { |
---|
[1559] | 2030 | nBegin[indexMap[i]] = domainList[domainId]->ibegin; |
---|
| 2031 | nSize[indexMap[i]] = domainList[domainId]->ni; |
---|
| 2032 | nBeginGlobal[indexMap[i]] = 0; |
---|
[1099] | 2033 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
[967] | 2034 | |
---|
[1559] | 2035 | nBegin[indexMap[i] + 1] = domainList[domainId]->jbegin; |
---|
| 2036 | nSize[indexMap[i] + 1] = domainList[domainId]->nj; |
---|
| 2037 | nBeginGlobal[indexMap[i] + 1] = 0; |
---|
[1099] | 2038 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
[1023] | 2039 | |
---|
[1202] | 2040 | { |
---|
| 2041 | int count = 0; |
---|
[1559] | 2042 | globalIndex[i].resize(nSize[indexMap[i]]*nSize[indexMap[i]+1]); |
---|
| 2043 | for (int jdx = 0; jdx < nSize[indexMap[i]+1]; ++jdx) |
---|
| 2044 | for (int idx = 0; idx < nSize[indexMap[i]]; ++idx) |
---|
[1202] | 2045 | { |
---|
[1559] | 2046 | globalIndex[i](count) = (nBegin[indexMap[i]] + idx) + (nBegin[indexMap[i]+1] + jdx) * nGlob[indexMap[i]]; |
---|
[1202] | 2047 | ++count; |
---|
| 2048 | } |
---|
| 2049 | } |
---|
| 2050 | |
---|
[1027] | 2051 | ++domainId; |
---|
| 2052 | } |
---|
| 2053 | else if (1 == axis_domain_order(i)) // axis |
---|
[1023] | 2054 | { |
---|
[1559] | 2055 | nBegin[indexMap[i]] = axisList[axisId]->begin; |
---|
| 2056 | nSize[indexMap[i]] = axisList[axisId]->n; |
---|
| 2057 | nBeginGlobal[indexMap[i]] = 0; |
---|
[1202] | 2058 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
[1559] | 2059 | globalIndex[i].resize(nSize[indexMap[i]]); |
---|
| 2060 | for (int idx = 0; idx < nSize[indexMap[i]]; ++idx) |
---|
| 2061 | globalIndex[i](idx) = nBegin[indexMap[i]] + idx; |
---|
[1202] | 2062 | |
---|
[1027] | 2063 | ++axisId; |
---|
[1023] | 2064 | } |
---|
[1027] | 2065 | else // scalar |
---|
[1129] | 2066 | { |
---|
[1559] | 2067 | nBegin[indexMap[i]] = 0; |
---|
| 2068 | nSize[indexMap[i]] = 1; |
---|
| 2069 | nBeginGlobal[indexMap[i]] = 0; |
---|
[1099] | 2070 | nGlob[indexMap[i]] = 1; |
---|
[1559] | 2071 | globalIndex[i].resize(1); |
---|
| 2072 | globalIndex[i](0) = 0; |
---|
[1027] | 2073 | ++scalarId; |
---|
| 2074 | } |
---|
| 2075 | } |
---|
| 2076 | dataSize = 1; |
---|
[1023] | 2077 | |
---|
[1559] | 2078 | for (int i = 0; i < nSize.size(); ++i) |
---|
| 2079 | dataSize *= nSize[i]; |
---|
[1202] | 2080 | serverDistribution_ = new CDistributionServer(server->intraCommRank, |
---|
[1559] | 2081 | globalIndex, axis_domain_order, |
---|
| 2082 | nBegin, nSize, nBeginGlobal, nGlob); |
---|
[967] | 2083 | } |
---|
| 2084 | |
---|
[1027] | 2085 | CArray<size_t,1> outIndex; |
---|
| 2086 | buffer >> outIndex; |
---|
[1330] | 2087 | outGlobalIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
| 2088 | connectedDataSizeRead_[rank] = outIndex.numElements(); |
---|
[1099] | 2089 | |
---|
[1235] | 2090 | if (doGridHaveDataDistributed(client)) |
---|
[1099] | 2091 | {} |
---|
[1027] | 2092 | else |
---|
[1023] | 2093 | { |
---|
[1054] | 2094 | // THE PROBLEM HERE IS THAT DATA CAN BE NONDISTRIBUTED ON CLIENT AND DISTRIBUTED ON SERVER |
---|
| 2095 | // BELOW IS THE TEMPORARY FIX only for a single type of element (domain, asix, scalar) |
---|
[1099] | 2096 | dataSize = serverDistribution_->getGridSize(); |
---|
[1023] | 2097 | } |
---|
[1027] | 2098 | writtenDataSize_ += dataSize; |
---|
[967] | 2099 | } |
---|
| 2100 | |
---|
[1027] | 2101 | |
---|
[1129] | 2102 | // Compute mask of the current grid |
---|
| 2103 | { |
---|
| 2104 | int axisId = 0, domainId = 0, scalarId = 0, globalSize = 1; |
---|
| 2105 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 2106 | std::vector<CAxis*> axisList = getAxis(); |
---|
[1136] | 2107 | int dimSize = 2 * domainList.size() + axisList.size(); |
---|
| 2108 | std::vector<int> nBegin(dimSize), nSize(dimSize), nGlob(dimSize), nBeginGlobal(dimSize); |
---|
[1129] | 2109 | for (int i = 0; i < numElement; ++i) |
---|
| 2110 | { |
---|
| 2111 | if (2 == axis_domain_order(i)) //domain |
---|
| 2112 | { |
---|
| 2113 | nBegin[indexMap[i]] = domainList[domainId]->ibegin; |
---|
| 2114 | nSize[indexMap[i]] = domainList[domainId]->ni; |
---|
| 2115 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2116 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
| 2117 | |
---|
| 2118 | nBegin[indexMap[i] + 1] = domainList[domainId]->jbegin; |
---|
| 2119 | nSize[indexMap[i] + 1] = domainList[domainId]->nj; |
---|
| 2120 | nBeginGlobal[indexMap[i] + 1] = 0; |
---|
| 2121 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
| 2122 | |
---|
| 2123 | ++domainId; |
---|
| 2124 | } |
---|
| 2125 | else if (1 == axis_domain_order(i)) // axis |
---|
| 2126 | { |
---|
| 2127 | nBegin[indexMap[i]] = axisList[axisId]->begin; |
---|
| 2128 | nSize[indexMap[i]] = axisList[axisId]->n; |
---|
| 2129 | nBeginGlobal[indexMap[i]] = 0; |
---|
| 2130 | nGlob[indexMap[i]] = axisList[axisId]->n_glo; |
---|
| 2131 | ++axisId; |
---|
| 2132 | } |
---|
| 2133 | else // scalar |
---|
[1250] | 2134 | { |
---|
[1129] | 2135 | } |
---|
| 2136 | } |
---|
| 2137 | |
---|
[1250] | 2138 | if (nSize.empty()) // Scalar grid |
---|
| 2139 | { |
---|
| 2140 | nBegin.push_back(0); |
---|
| 2141 | nSize.push_back(1); |
---|
| 2142 | nBeginGlobal.push_back(0); |
---|
| 2143 | nGlob.push_back(1); |
---|
| 2144 | } |
---|
[1129] | 2145 | } |
---|
| 2146 | |
---|
[1144] | 2147 | if (isScalarGrid()) return; |
---|
[1027] | 2148 | |
---|
[1236] | 2149 | nbReadSenders[client] = CClientServerMappingDistributed::computeConnectedClients(context->client->serverSize, context->client->clientSize, context->client->intraComm, ranks); |
---|
[967] | 2150 | } |
---|
| 2151 | } |
---|
[1622] | 2152 | CATCH_DUMP_ATTR |
---|
[967] | 2153 | |
---|
[1158] | 2154 | /* |
---|
| 2155 | Compute on the fly the global dimension of a grid with its elements |
---|
| 2156 | \param[in/out] globalDim global dimension of grid |
---|
| 2157 | \param[in] domains list of its domains |
---|
| 2158 | \param[in] axiss list of its axis |
---|
| 2159 | \param[in] scalars list of its scalars |
---|
| 2160 | \param[in] axisDomainOrder the order of element in a grid (e.g: scalar then axis) |
---|
| 2161 | \return The dimension of which we do distribution (often for server) |
---|
| 2162 | */ |
---|
| 2163 | int CGrid::computeGridGlobalDimension(std::vector<int>& globalDim, |
---|
| 2164 | const std::vector<CDomain*> domains, |
---|
| 2165 | const std::vector<CAxis*> axis, |
---|
| 2166 | const std::vector<CScalar*> scalars, |
---|
| 2167 | const CArray<int,1>& axisDomainOrder) |
---|
[1622] | 2168 | TRY |
---|
| 2169 | { |
---|
[1311] | 2170 | // globalDim.resize(domains.size()*2+axis.size()+scalars.size()); |
---|
| 2171 | globalDim.resize(domains.size()*2+axis.size()); |
---|
[1158] | 2172 | int positionDimensionDistributed = 1; |
---|
[887] | 2173 | int idx = 0, idxDomain = 0, idxAxis = 0, idxScalar = 0; |
---|
[567] | 2174 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 2175 | { |
---|
[887] | 2176 | if (2 == axisDomainOrder(i)) |
---|
[567] | 2177 | { |
---|
[657] | 2178 | if (!(domains[idxDomain]->type.isEmpty()) && (domains[idxDomain]->type==CDomain::type_attr::unstructured)) |
---|
| 2179 | { |
---|
[1158] | 2180 | positionDimensionDistributed = idx; |
---|
[657] | 2181 | } |
---|
| 2182 | else |
---|
| 2183 | { |
---|
[1158] | 2184 | positionDimensionDistributed = idx +1; |
---|
[657] | 2185 | } |
---|
| 2186 | |
---|
[1158] | 2187 | globalDim[idx] = domains[idxDomain]->ni_glo.getValue(); |
---|
| 2188 | globalDim[idx+1] = domains[idxDomain]->nj_glo.getValue(); |
---|
[657] | 2189 | |
---|
[567] | 2190 | ++idxDomain; |
---|
| 2191 | idx += 2; |
---|
| 2192 | } |
---|
[887] | 2193 | else if (1 == axisDomainOrder(i)) |
---|
[567] | 2194 | { |
---|
[1158] | 2195 | globalDim[idx] = axis[idxAxis]->n_glo.getValue(); |
---|
[567] | 2196 | ++idxAxis; |
---|
| 2197 | ++idx; |
---|
| 2198 | } |
---|
[887] | 2199 | else |
---|
| 2200 | { |
---|
[1311] | 2201 | // globalDim[idx] = 1; |
---|
[887] | 2202 | ++idxScalar; |
---|
[1311] | 2203 | // ++idx; |
---|
[887] | 2204 | } |
---|
[567] | 2205 | } |
---|
[1158] | 2206 | |
---|
| 2207 | return positionDimensionDistributed; |
---|
[567] | 2208 | } |
---|
[1622] | 2209 | CATCH_DUMP_ATTR |
---|
[567] | 2210 | |
---|
[1158] | 2211 | // Retrieve the global dimension of grid |
---|
[567] | 2212 | std::vector<int> CGrid::getGlobalDimension() |
---|
[1622] | 2213 | TRY |
---|
[567] | 2214 | { |
---|
[1158] | 2215 | std::vector<int> globalDim; |
---|
| 2216 | computeGridGlobalDimension(globalDim, getDomains(), getAxis(), getScalars(), axis_domain_order); |
---|
| 2217 | |
---|
| 2218 | return globalDim; |
---|
[567] | 2219 | } |
---|
[1622] | 2220 | CATCH_DUMP_ATTR |
---|
[567] | 2221 | |
---|
[1158] | 2222 | // Retrieve dimension on which we do distribution (Very often, it should be 2nd dimension) |
---|
| 2223 | int CGrid::getDistributedDimension() |
---|
[1622] | 2224 | TRY |
---|
[1158] | 2225 | { |
---|
| 2226 | std::vector<int> globalDim; |
---|
| 2227 | return computeGridGlobalDimension(globalDim, getDomains(), getAxis(), getScalars(), axis_domain_order); |
---|
| 2228 | } |
---|
[1622] | 2229 | CATCH_DUMP_ATTR |
---|
[1158] | 2230 | |
---|
[600] | 2231 | bool CGrid::isScalarGrid() const |
---|
[1622] | 2232 | TRY |
---|
[600] | 2233 | { |
---|
| 2234 | return (axisList_.empty() && domList_.empty()); |
---|
| 2235 | } |
---|
[1622] | 2236 | CATCH |
---|
[600] | 2237 | |
---|
[567] | 2238 | /*! |
---|
| 2239 | Verify whether one server need to write data |
---|
| 2240 | There are some cases on which one server has nodata to write. For example, when we |
---|
[650] | 2241 | just only want to zoom on a domain. |
---|
[567] | 2242 | */ |
---|
| 2243 | bool CGrid::doGridHaveDataToWrite() |
---|
[1622] | 2244 | TRY |
---|
[567] | 2245 | { |
---|
[624] | 2246 | return (0 != writtenDataSize_); |
---|
[567] | 2247 | } |
---|
[1622] | 2248 | CATCH_DUMP_ATTR |
---|
[567] | 2249 | |
---|
| 2250 | /*! |
---|
| 2251 | Return size of data which is written on each server |
---|
| 2252 | Whatever dimension of a grid, data which are written on server must be presented as |
---|
[650] | 2253 | an one dimension array. |
---|
| 2254 | \return size of data written on server |
---|
[567] | 2255 | */ |
---|
| 2256 | size_t CGrid::getWrittenDataSize() const |
---|
[1622] | 2257 | TRY |
---|
[567] | 2258 | { |
---|
| 2259 | return writtenDataSize_; |
---|
| 2260 | } |
---|
[1622] | 2261 | CATCH |
---|
[567] | 2262 | |
---|
[676] | 2263 | /*! |
---|
| 2264 | Returns the number of indexes written by each server. |
---|
| 2265 | \return the number of indexes written by each server |
---|
| 2266 | */ |
---|
| 2267 | int CGrid::getNumberWrittenIndexes() const |
---|
[1622] | 2268 | TRY |
---|
[676] | 2269 | { |
---|
| 2270 | return numberWrittenIndexes_; |
---|
| 2271 | } |
---|
[1622] | 2272 | CATCH |
---|
[676] | 2273 | |
---|
| 2274 | /*! |
---|
| 2275 | Returns the total number of indexes written by the servers. |
---|
| 2276 | \return the total number of indexes written by the servers |
---|
| 2277 | */ |
---|
| 2278 | int CGrid::getTotalNumberWrittenIndexes() const |
---|
[1622] | 2279 | TRY |
---|
[676] | 2280 | { |
---|
| 2281 | return totalNumberWrittenIndexes_; |
---|
| 2282 | } |
---|
[1622] | 2283 | CATCH |
---|
[676] | 2284 | |
---|
| 2285 | /*! |
---|
| 2286 | Returns the offset of indexes written by each server. |
---|
| 2287 | \return the offset of indexes written by each server |
---|
| 2288 | */ |
---|
| 2289 | int CGrid::getOffsetWrittenIndexes() const |
---|
[1622] | 2290 | TRY |
---|
[676] | 2291 | { |
---|
| 2292 | return offsetWrittenIndexes_; |
---|
| 2293 | } |
---|
[1622] | 2294 | CATCH |
---|
[676] | 2295 | |
---|
[834] | 2296 | CDistributionServer* CGrid::getDistributionServer() |
---|
[1622] | 2297 | TRY |
---|
[567] | 2298 | { |
---|
| 2299 | return serverDistribution_; |
---|
| 2300 | } |
---|
[1622] | 2301 | CATCH_DUMP_ATTR |
---|
[567] | 2302 | |
---|
[834] | 2303 | CDistributionClient* CGrid::getDistributionClient() |
---|
[1622] | 2304 | TRY |
---|
[620] | 2305 | { |
---|
| 2306 | return clientDistribution_; |
---|
| 2307 | } |
---|
[1622] | 2308 | CATCH_DUMP_ATTR |
---|
[620] | 2309 | |
---|
[1235] | 2310 | bool CGrid::doGridHaveDataDistributed(CContextClient* client) |
---|
[1622] | 2311 | TRY |
---|
[567] | 2312 | { |
---|
[600] | 2313 | if (isScalarGrid()) return false; |
---|
[1235] | 2314 | else if (0 != client) |
---|
| 2315 | { |
---|
| 2316 | return (isDataDistributed_ || (1 != client->clientSize) || (1 != client->serverSize)); |
---|
| 2317 | } |
---|
[586] | 2318 | else |
---|
[1235] | 2319 | return isDataDistributed_; |
---|
[567] | 2320 | } |
---|
[1622] | 2321 | CATCH_DUMP_ATTR |
---|
[567] | 2322 | |
---|
[540] | 2323 | /*! |
---|
| 2324 | \brief Dispatch event received from client |
---|
| 2325 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 2326 | its event type. A new event type should be added in the switch list to make sure |
---|
| 2327 | it processed on server side. |
---|
| 2328 | \param [in] event: Received message |
---|
| 2329 | */ |
---|
[300] | 2330 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
[1622] | 2331 | TRY |
---|
[300] | 2332 | { |
---|
[509] | 2333 | |
---|
[650] | 2334 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 2335 | else |
---|
| 2336 | { |
---|
| 2337 | switch(event.type) |
---|
| 2338 | { |
---|
| 2339 | case EVENT_ID_INDEX : |
---|
[650] | 2340 | recvIndex(event); |
---|
| 2341 | return true; |
---|
| 2342 | break; |
---|
[509] | 2343 | |
---|
[540] | 2344 | case EVENT_ID_ADD_DOMAIN : |
---|
[650] | 2345 | recvAddDomain(event); |
---|
| 2346 | return true; |
---|
| 2347 | break; |
---|
[540] | 2348 | |
---|
| 2349 | case EVENT_ID_ADD_AXIS : |
---|
[650] | 2350 | recvAddAxis(event); |
---|
| 2351 | return true; |
---|
| 2352 | break; |
---|
[887] | 2353 | |
---|
| 2354 | case EVENT_ID_ADD_SCALAR : |
---|
| 2355 | recvAddScalar(event); |
---|
| 2356 | return true; |
---|
| 2357 | break; |
---|
[300] | 2358 | default : |
---|
| 2359 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
[650] | 2360 | << "Unknown Event"); |
---|
| 2361 | return false; |
---|
[300] | 2362 | } |
---|
| 2363 | } |
---|
| 2364 | } |
---|
[1622] | 2365 | CATCH |
---|
[300] | 2366 | |
---|
[219] | 2367 | ///--------------------------------------------------------------- |
---|
| 2368 | |
---|
[540] | 2369 | CDomain* CGrid::addDomain(const std::string& id) |
---|
[1622] | 2370 | TRY |
---|
[540] | 2371 | { |
---|
[887] | 2372 | order_.push_back(2); |
---|
[835] | 2373 | axis_domain_order.resize(order_.size()); |
---|
| 2374 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
[650] | 2375 | return vDomainGroup_->createChild(id); |
---|
[540] | 2376 | } |
---|
[1622] | 2377 | CATCH_DUMP_ATTR |
---|
[540] | 2378 | |
---|
| 2379 | CAxis* CGrid::addAxis(const std::string& id) |
---|
[1622] | 2380 | TRY |
---|
[540] | 2381 | { |
---|
[887] | 2382 | order_.push_back(1); |
---|
[835] | 2383 | axis_domain_order.resize(order_.size()); |
---|
| 2384 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
[650] | 2385 | return vAxisGroup_->createChild(id); |
---|
[540] | 2386 | } |
---|
[1622] | 2387 | CATCH_DUMP_ATTR |
---|
[540] | 2388 | |
---|
[887] | 2389 | CScalar* CGrid::addScalar(const std::string& id) |
---|
[1622] | 2390 | TRY |
---|
[887] | 2391 | { |
---|
| 2392 | order_.push_back(0); |
---|
| 2393 | axis_domain_order.resize(order_.size()); |
---|
| 2394 | for (int idx = 0; idx < order_.size(); ++idx) axis_domain_order(idx)=order_[idx]; |
---|
| 2395 | return vScalarGroup_->createChild(id); |
---|
| 2396 | } |
---|
[1622] | 2397 | CATCH_DUMP_ATTR |
---|
[887] | 2398 | |
---|
[540] | 2399 | //! Change virtual field group to a new one |
---|
| 2400 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
[1622] | 2401 | TRY |
---|
[540] | 2402 | { |
---|
| 2403 | this->vDomainGroup_ = newVDomainGroup; |
---|
| 2404 | } |
---|
[1622] | 2405 | CATCH_DUMP_ATTR |
---|
[540] | 2406 | |
---|
| 2407 | //! Change virtual variable group to new one |
---|
| 2408 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
[1622] | 2409 | TRY |
---|
[540] | 2410 | { |
---|
| 2411 | this->vAxisGroup_ = newVAxisGroup; |
---|
| 2412 | } |
---|
[1622] | 2413 | CATCH_DUMP_ATTR |
---|
[540] | 2414 | |
---|
[887] | 2415 | //! Change virtual variable group to new one |
---|
| 2416 | void CGrid::setVirtualScalarGroup(CScalarGroup* newVScalarGroup) |
---|
[1622] | 2417 | TRY |
---|
[887] | 2418 | { |
---|
| 2419 | this->vScalarGroup_ = newVScalarGroup; |
---|
| 2420 | } |
---|
[1622] | 2421 | CATCH_DUMP_ATTR |
---|
[887] | 2422 | |
---|
[540] | 2423 | /*! |
---|
| 2424 | \brief Send a message to create a domain on server side |
---|
| 2425 | \param[in] id String identity of domain that will be created on server |
---|
| 2426 | */ |
---|
| 2427 | void CGrid::sendAddDomain(const string& id) |
---|
[1622] | 2428 | TRY |
---|
| 2429 | { |
---|
[987] | 2430 | sendAddItem(id, (int)EVENT_ID_ADD_DOMAIN); |
---|
[540] | 2431 | } |
---|
[1622] | 2432 | CATCH_DUMP_ATTR |
---|
[540] | 2433 | |
---|
| 2434 | /*! |
---|
| 2435 | \brief Send a message to create an axis on server side |
---|
| 2436 | \param[in] id String identity of axis that will be created on server |
---|
| 2437 | */ |
---|
| 2438 | void CGrid::sendAddAxis(const string& id) |
---|
[1622] | 2439 | TRY |
---|
[540] | 2440 | { |
---|
[987] | 2441 | sendAddItem(id, (int)EVENT_ID_ADD_AXIS); |
---|
[540] | 2442 | } |
---|
[1622] | 2443 | CATCH_DUMP_ATTR |
---|
[540] | 2444 | |
---|
| 2445 | /*! |
---|
[887] | 2446 | \brief Send a message to create a scalar on server side |
---|
| 2447 | \param[in] id String identity of scalar that will be created on server |
---|
| 2448 | */ |
---|
| 2449 | void CGrid::sendAddScalar(const string& id) |
---|
[1622] | 2450 | TRY |
---|
[887] | 2451 | { |
---|
[987] | 2452 | sendAddItem(id, (int)EVENT_ID_ADD_SCALAR); |
---|
[887] | 2453 | } |
---|
[1622] | 2454 | CATCH_DUMP_ATTR |
---|
[887] | 2455 | |
---|
| 2456 | /*! |
---|
[540] | 2457 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 2458 | \param[in] event Received event |
---|
| 2459 | */ |
---|
| 2460 | void CGrid::recvAddDomain(CEventServer& event) |
---|
[1622] | 2461 | TRY |
---|
[540] | 2462 | { |
---|
| 2463 | |
---|
[650] | 2464 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 2465 | string id; |
---|
[650] | 2466 | *buffer >> id; |
---|
| 2467 | get(id)->recvAddDomain(*buffer); |
---|
[540] | 2468 | } |
---|
[1622] | 2469 | CATCH |
---|
[540] | 2470 | |
---|
| 2471 | /*! |
---|
| 2472 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 2473 | \param[in] buffer Buffer containing message |
---|
| 2474 | */ |
---|
| 2475 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
[1622] | 2476 | TRY |
---|
[540] | 2477 | { |
---|
[650] | 2478 | string id; |
---|
| 2479 | buffer >> id; |
---|
| 2480 | addDomain(id); |
---|
[540] | 2481 | } |
---|
[1622] | 2482 | CATCH_DUMP_ATTR |
---|
[540] | 2483 | |
---|
| 2484 | /*! |
---|
| 2485 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 2486 | \param[in] event Received event |
---|
| 2487 | */ |
---|
| 2488 | void CGrid::recvAddAxis(CEventServer& event) |
---|
[1622] | 2489 | TRY |
---|
[540] | 2490 | { |
---|
| 2491 | |
---|
[650] | 2492 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 2493 | string id; |
---|
[650] | 2494 | *buffer >> id; |
---|
| 2495 | get(id)->recvAddAxis(*buffer); |
---|
[540] | 2496 | } |
---|
[1622] | 2497 | CATCH |
---|
[540] | 2498 | |
---|
| 2499 | /*! |
---|
| 2500 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 2501 | \param[in] buffer Buffer containing message |
---|
| 2502 | */ |
---|
| 2503 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
[1622] | 2504 | TRY |
---|
[540] | 2505 | { |
---|
[650] | 2506 | string id; |
---|
| 2507 | buffer >> id; |
---|
| 2508 | addAxis(id); |
---|
[540] | 2509 | } |
---|
[1622] | 2510 | CATCH_DUMP_ATTR |
---|
[540] | 2511 | |
---|
[887] | 2512 | /*! |
---|
| 2513 | \brief Receive a message annoucing the creation of an scalar on server side |
---|
| 2514 | \param[in] event Received event |
---|
| 2515 | */ |
---|
| 2516 | void CGrid::recvAddScalar(CEventServer& event) |
---|
[1622] | 2517 | TRY |
---|
[887] | 2518 | { |
---|
| 2519 | |
---|
| 2520 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
| 2521 | string id; |
---|
| 2522 | *buffer >> id; |
---|
| 2523 | get(id)->recvAddScalar(*buffer); |
---|
| 2524 | } |
---|
[1622] | 2525 | CATCH |
---|
[887] | 2526 | |
---|
| 2527 | /*! |
---|
| 2528 | \brief Receive a message annoucing the creation of an scalar on server side |
---|
| 2529 | \param[in] buffer Buffer containing message |
---|
| 2530 | */ |
---|
| 2531 | void CGrid::recvAddScalar(CBufferIn& buffer) |
---|
[1622] | 2532 | TRY |
---|
[887] | 2533 | { |
---|
| 2534 | string id; |
---|
| 2535 | buffer >> id; |
---|
| 2536 | addScalar(id); |
---|
| 2537 | } |
---|
[1622] | 2538 | CATCH_DUMP_ATTR |
---|
[887] | 2539 | |
---|
[551] | 2540 | /*! |
---|
| 2541 | \brief Solve domain and axis references |
---|
| 2542 | As field, domain and axis can refer to other domains or axis. In order to inherit correctly |
---|
| 2543 | all attributes from their parents, they should be processed with this function |
---|
| 2544 | \param[in] apply inherit all attributes of parents (true) |
---|
| 2545 | */ |
---|
[540] | 2546 | void CGrid::solveDomainAxisRefInheritance(bool apply) |
---|
[1622] | 2547 | TRY |
---|
[540] | 2548 | { |
---|
| 2549 | CContext* context = CContext::getCurrent(); |
---|
| 2550 | unsigned int vecSize, i; |
---|
| 2551 | std::vector<StdString>::iterator it, itE; |
---|
| 2552 | setDomainList(); |
---|
| 2553 | it = domList_.begin(); itE = domList_.end(); |
---|
| 2554 | for (; it != itE; ++it) |
---|
| 2555 | { |
---|
| 2556 | CDomain* pDom = CDomain::get(*it); |
---|
[1144] | 2557 | if (context->hasClient && !context->hasServer) |
---|
[540] | 2558 | { |
---|
| 2559 | pDom->solveRefInheritance(apply); |
---|
[631] | 2560 | pDom->solveInheritanceTransformation(); |
---|
[2131] | 2561 | if (!pDom->ntiles.isEmpty() && pDom->ntiles.getValue()>0) nTiles_=pDom->ntiles.getValue(); |
---|
[540] | 2562 | } |
---|
| 2563 | } |
---|
| 2564 | |
---|
| 2565 | setAxisList(); |
---|
| 2566 | it = axisList_.begin(); itE = axisList_.end(); |
---|
| 2567 | for (; it != itE; ++it) |
---|
| 2568 | { |
---|
| 2569 | CAxis* pAxis = CAxis::get(*it); |
---|
[1077] | 2570 | if (context->hasClient && !context->hasServer) |
---|
[540] | 2571 | { |
---|
| 2572 | pAxis->solveRefInheritance(apply); |
---|
[619] | 2573 | pAxis->solveInheritanceTransformation(); |
---|
[540] | 2574 | } |
---|
| 2575 | } |
---|
[887] | 2576 | |
---|
| 2577 | setScalarList(); |
---|
| 2578 | it = scalarList_.begin(); itE = scalarList_.end(); |
---|
| 2579 | for (; it != itE; ++it) |
---|
| 2580 | { |
---|
| 2581 | CScalar* pScalar = CScalar::get(*it); |
---|
[1077] | 2582 | if (context->hasClient && !context->hasServer) |
---|
[887] | 2583 | { |
---|
| 2584 | pScalar->solveRefInheritance(apply); |
---|
| 2585 | pScalar->solveInheritanceTransformation(); |
---|
| 2586 | } |
---|
| 2587 | } |
---|
[540] | 2588 | } |
---|
[1622] | 2589 | CATCH_DUMP_ATTR |
---|
[540] | 2590 | |
---|
[2131] | 2591 | int CGrid::getNTiles() |
---|
| 2592 | TRY |
---|
| 2593 | { |
---|
| 2594 | return nTiles_; |
---|
| 2595 | } |
---|
| 2596 | CATCH_DUMP_ATTR |
---|
| 2597 | |
---|
| 2598 | bool CGrid::isTiled(void) const |
---|
| 2599 | TRY |
---|
| 2600 | { |
---|
| 2601 | return isTiled_; |
---|
| 2602 | } |
---|
| 2603 | CATCH |
---|
| 2604 | |
---|
| 2605 | bool CGrid::isTiledOnly(void) const |
---|
| 2606 | TRY |
---|
| 2607 | { |
---|
| 2608 | return isTiledOnly_; |
---|
| 2609 | } |
---|
| 2610 | CATCH |
---|
| 2611 | |
---|
[619] | 2612 | bool CGrid::isTransformed() |
---|
[1622] | 2613 | TRY |
---|
[619] | 2614 | { |
---|
| 2615 | return isTransformed_; |
---|
| 2616 | } |
---|
[1622] | 2617 | CATCH_DUMP_ATTR |
---|
[619] | 2618 | |
---|
| 2619 | void CGrid::setTransformed() |
---|
[1622] | 2620 | TRY |
---|
[619] | 2621 | { |
---|
| 2622 | isTransformed_ = true; |
---|
| 2623 | } |
---|
[1622] | 2624 | CATCH_DUMP_ATTR |
---|
[619] | 2625 | |
---|
[620] | 2626 | CGridTransformation* CGrid::getTransformations() |
---|
[1622] | 2627 | TRY |
---|
[619] | 2628 | { |
---|
[620] | 2629 | return transformations_; |
---|
[619] | 2630 | } |
---|
[1622] | 2631 | CATCH_DUMP_ATTR |
---|
[619] | 2632 | |
---|
[823] | 2633 | void CGrid::addTransGridSource(CGrid* gridSrc) |
---|
[1622] | 2634 | TRY |
---|
[823] | 2635 | { |
---|
| 2636 | if (gridSrc_.end() == gridSrc_.find(gridSrc)) |
---|
| 2637 | gridSrc_.insert(make_pair(gridSrc,make_pair(false,""))); |
---|
| 2638 | } |
---|
[1622] | 2639 | CATCH_DUMP_ATTR |
---|
[823] | 2640 | |
---|
| 2641 | std::map<CGrid*,std::pair<bool,StdString> >& CGrid::getTransGridSource() |
---|
[1622] | 2642 | TRY |
---|
[823] | 2643 | { |
---|
| 2644 | return gridSrc_; |
---|
| 2645 | } |
---|
[1622] | 2646 | CATCH_DUMP_ATTR |
---|
[823] | 2647 | |
---|
[687] | 2648 | /*! |
---|
| 2649 | Complete all the necessary (and lacking) attributes of a grid |
---|
| 2650 | This function is similar to gridTransformation but works only (till now) on generate_rectilinear_domain transformation |
---|
| 2651 | */ |
---|
| 2652 | void CGrid::completeGrid(CGrid* transformGridSrc) |
---|
[1622] | 2653 | TRY |
---|
[687] | 2654 | { |
---|
[775] | 2655 | if (0 != transformGridSrc) |
---|
[687] | 2656 | { |
---|
[775] | 2657 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
| 2658 | { |
---|
| 2659 | ERROR("CGrid::completeGrid(CGrid* transformGridSrc)", |
---|
[940] | 2660 | << "Two grids have different number of elements. " << std::endl |
---|
| 2661 | << "Number of element of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 2662 | << "Number of element of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[775] | 2663 | } |
---|
[687] | 2664 | } |
---|
| 2665 | |
---|
[890] | 2666 | if (isGenerated()) return; |
---|
| 2667 | setGenerated(); |
---|
| 2668 | |
---|
[687] | 2669 | CGridGenerate gridGenerate(this, transformGridSrc); |
---|
| 2670 | gridGenerate.completeGrid(); |
---|
| 2671 | } |
---|
[1622] | 2672 | CATCH_DUMP_ATTR |
---|
[687] | 2673 | |
---|
[890] | 2674 | bool CGrid::isGenerated() |
---|
[1622] | 2675 | TRY |
---|
[890] | 2676 | { |
---|
| 2677 | return isGenerated_; |
---|
| 2678 | } |
---|
[1622] | 2679 | CATCH |
---|
[890] | 2680 | |
---|
| 2681 | void CGrid::setGenerated() |
---|
[1622] | 2682 | TRY |
---|
[890] | 2683 | { |
---|
| 2684 | isGenerated_ = true; |
---|
| 2685 | } |
---|
[1622] | 2686 | CATCH_DUMP_ATTR |
---|
[890] | 2687 | |
---|
[632] | 2688 | void CGrid::transformGrid(CGrid* transformGridSrc) |
---|
[1622] | 2689 | TRY |
---|
[619] | 2690 | { |
---|
[746] | 2691 | if (!transformGridSrc) |
---|
| 2692 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
| 2693 | << "Impossible to transform grid '" << getId() << "', the source grid is null."); |
---|
| 2694 | |
---|
[632] | 2695 | if (isTransformed()) return; |
---|
| 2696 | setTransformed(); |
---|
| 2697 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
[619] | 2698 | { |
---|
[632] | 2699 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[940] | 2700 | << "Two grids have different number of elements. " << std::endl |
---|
| 2701 | << "Number of element of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 2702 | << "Number of element of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[619] | 2703 | } |
---|
| 2704 | else |
---|
| 2705 | { |
---|
| 2706 | } |
---|
| 2707 | |
---|
[632] | 2708 | transformations_ = new CGridTransformation(this, transformGridSrc); |
---|
[622] | 2709 | transformations_->computeAll(); |
---|
[824] | 2710 | if (0 < transformations_->getNbAlgo()) hasTransform_ = true; |
---|
[623] | 2711 | |
---|
| 2712 | // Ok, now need to compute index of grid source |
---|
[632] | 2713 | transformGridSrc->checkMaskIndex(false); |
---|
[619] | 2714 | } |
---|
[1622] | 2715 | CATCH_DUMP_ATTR |
---|
[619] | 2716 | |
---|
[824] | 2717 | bool CGrid::hasTransform() |
---|
[1622] | 2718 | TRY |
---|
[824] | 2719 | { |
---|
[914] | 2720 | if (hasTransform_) return hasTransform_; |
---|
| 2721 | |
---|
| 2722 | std::vector<CDomain*> domList = getDomains(); |
---|
| 2723 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 2724 | std::vector<CScalar*> scalarList = getScalars(); |
---|
| 2725 | |
---|
| 2726 | for (int idx = 0; idx < domList.size(); ++idx) hasTransform_ |= domList[idx]->hasTransformation(); |
---|
| 2727 | for (int idx = 0; idx < axisList.size(); ++idx) hasTransform_ |= axisList[idx]->hasTransformation(); |
---|
| 2728 | for (int idx = 0; idx < scalarList.size(); ++idx) hasTransform_ |= scalarList[idx]->hasTransformation(); |
---|
| 2729 | |
---|
[824] | 2730 | return hasTransform_; |
---|
| 2731 | } |
---|
[1622] | 2732 | CATCH_DUMP_ATTR |
---|
[824] | 2733 | |
---|
[551] | 2734 | /*! |
---|
| 2735 | \brief Get the list of domain pointers |
---|
| 2736 | \return list of domain pointers |
---|
| 2737 | */ |
---|
[540] | 2738 | std::vector<CDomain*> CGrid::getDomains() |
---|
[1622] | 2739 | TRY |
---|
[540] | 2740 | { |
---|
| 2741 | std::vector<CDomain*> domList; |
---|
| 2742 | if (!domList_.empty()) |
---|
| 2743 | { |
---|
| 2744 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
| 2745 | } |
---|
| 2746 | return domList; |
---|
| 2747 | } |
---|
[1622] | 2748 | CATCH_DUMP_ATTR |
---|
[540] | 2749 | |
---|
[551] | 2750 | /*! |
---|
| 2751 | \brief Get the list of axis pointers |
---|
| 2752 | \return list of axis pointers |
---|
| 2753 | */ |
---|
[540] | 2754 | std::vector<CAxis*> CGrid::getAxis() |
---|
[1622] | 2755 | TRY |
---|
[540] | 2756 | { |
---|
| 2757 | std::vector<CAxis*> aList; |
---|
| 2758 | if (!axisList_.empty()) |
---|
| 2759 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
| 2760 | |
---|
| 2761 | return aList; |
---|
| 2762 | } |
---|
[1622] | 2763 | CATCH_DUMP_ATTR |
---|
[540] | 2764 | |
---|
[551] | 2765 | /*! |
---|
[887] | 2766 | \brief Get the list of axis pointers |
---|
| 2767 | \return list of axis pointers |
---|
| 2768 | */ |
---|
| 2769 | std::vector<CScalar*> CGrid::getScalars() |
---|
[1622] | 2770 | TRY |
---|
[887] | 2771 | { |
---|
| 2772 | std::vector<CScalar*> sList; |
---|
| 2773 | if (!scalarList_.empty()) |
---|
| 2774 | for (int i =0; i < scalarList_.size(); ++i) sList.push_back(CScalar::get(scalarList_[i])); |
---|
| 2775 | |
---|
| 2776 | return sList; |
---|
| 2777 | } |
---|
[1622] | 2778 | CATCH_DUMP_ATTR |
---|
[887] | 2779 | |
---|
| 2780 | /*! |
---|
[943] | 2781 | \brief Get domain pointer with index |
---|
| 2782 | \return domain pointer |
---|
| 2783 | */ |
---|
| 2784 | CDomain* CGrid::getDomain(int domainIndex) |
---|
[1622] | 2785 | TRY |
---|
[943] | 2786 | { |
---|
| 2787 | std::vector<CDomain*> domainListP = this->getDomains(); |
---|
| 2788 | if (domainListP.empty()) |
---|
| 2789 | { |
---|
| 2790 | ERROR("CGrid::getDomain(int domainIndex)", |
---|
| 2791 | << "No domain associated to this grid. " << std::endl |
---|
| 2792 | << "Grid id = " << this->getId()); |
---|
| 2793 | } |
---|
| 2794 | |
---|
| 2795 | if (domainIndex >= domainListP.size() || (domainIndex < 0)) |
---|
| 2796 | ERROR("CGrid::getDomain(int domainIndex)", |
---|
| 2797 | << "Domain with the index doesn't exist " << std::endl |
---|
| 2798 | << "Grid id = " << this->getId() << std::endl |
---|
| 2799 | << "Grid has only " << domainListP.size() << " domain but domain index required is " << domainIndex << std::endl); |
---|
| 2800 | |
---|
| 2801 | return domainListP[domainIndex]; |
---|
| 2802 | } |
---|
[1622] | 2803 | CATCH_DUMP_ATTR |
---|
[943] | 2804 | |
---|
| 2805 | /*! |
---|
| 2806 | \brief Get the axis pointer with index |
---|
| 2807 | \return axis pointer |
---|
| 2808 | */ |
---|
| 2809 | CAxis* CGrid::getAxis(int axisIndex) |
---|
[1622] | 2810 | TRY |
---|
[943] | 2811 | { |
---|
| 2812 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 2813 | if (axisListP.empty()) |
---|
| 2814 | { |
---|
| 2815 | ERROR("CGrid::getDomain(int axisIndex)", |
---|
| 2816 | << "No axis associated to this grid. " << std::endl |
---|
| 2817 | << "Grid id = " << this->getId()); |
---|
| 2818 | } |
---|
| 2819 | |
---|
| 2820 | if (axisIndex >= axisListP.size() || (axisIndex < 0)) |
---|
| 2821 | ERROR("CGrid::getDomain(int axisIndex)", |
---|
| 2822 | << "Domain with the index doesn't exist " << std::endl |
---|
| 2823 | << "Grid id = " << this->getId() << std::endl |
---|
| 2824 | << "Grid has only " << axisListP.size() << " axis but axis index required is " << axisIndex << std::endl); |
---|
| 2825 | |
---|
| 2826 | return axisListP[axisIndex]; |
---|
| 2827 | } |
---|
[1622] | 2828 | CATCH_DUMP_ATTR |
---|
[943] | 2829 | |
---|
| 2830 | /*! |
---|
| 2831 | \brief Get the a scalar pointer |
---|
| 2832 | \return scalar pointer |
---|
| 2833 | */ |
---|
| 2834 | CScalar* CGrid::getScalar(int scalarIndex) |
---|
[1622] | 2835 | TRY |
---|
[943] | 2836 | { |
---|
| 2837 | std::vector<CScalar*> scalarListP = this->getScalars(); |
---|
| 2838 | if (scalarListP.empty()) |
---|
| 2839 | { |
---|
| 2840 | ERROR("CGrid::getScalar(int scalarIndex)", |
---|
| 2841 | << "No scalar associated to this grid. " << std::endl |
---|
| 2842 | << "Grid id = " << this->getId()); |
---|
| 2843 | } |
---|
| 2844 | |
---|
| 2845 | if (scalarIndex >= scalarListP.size() || (scalarIndex < 0)) |
---|
| 2846 | ERROR("CGrid::getScalar(int scalarIndex)", |
---|
| 2847 | << "Scalar with the index doesn't exist " << std::endl |
---|
| 2848 | << "Grid id = " << this->getId() << std::endl |
---|
| 2849 | << "Grid has only " << scalarListP.size() << " scalar but scalar index required is " << scalarIndex << std::endl); |
---|
| 2850 | |
---|
| 2851 | return scalarListP[scalarIndex]; |
---|
| 2852 | } |
---|
[1622] | 2853 | CATCH_DUMP_ATTR |
---|
[943] | 2854 | |
---|
| 2855 | /*! |
---|
[551] | 2856 | \brief Set domain(s) of a grid from a list |
---|
| 2857 | \param[in] domains list of domains |
---|
| 2858 | */ |
---|
[540] | 2859 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
[1622] | 2860 | TRY |
---|
[540] | 2861 | { |
---|
| 2862 | if (isDomListSet) return; |
---|
| 2863 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
[742] | 2864 | if (!domains.empty() && domList.empty()) |
---|
| 2865 | { |
---|
| 2866 | for (int i = 0; i < domains.size(); ++i) |
---|
| 2867 | this->getVirtualDomainGroup()->addChild(domains[i]); |
---|
| 2868 | domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 2869 | } |
---|
| 2870 | |
---|
[540] | 2871 | if (!domList.empty()) |
---|
| 2872 | { |
---|
| 2873 | int sizeDom = domList.size(); |
---|
| 2874 | domList_.resize(sizeDom); |
---|
[650] | 2875 | for (int i = 0; i < sizeDom; ++i) |
---|
[540] | 2876 | { |
---|
| 2877 | domList_[i] = domList[i]->getId(); |
---|
| 2878 | } |
---|
| 2879 | isDomListSet = true; |
---|
| 2880 | } |
---|
| 2881 | } |
---|
[1622] | 2882 | CATCH_DUMP_ATTR |
---|
[540] | 2883 | |
---|
[551] | 2884 | /*! |
---|
| 2885 | \brief Set axis(s) of a grid from a list |
---|
| 2886 | \param[in] axis list of axis |
---|
| 2887 | */ |
---|
[540] | 2888 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
[1622] | 2889 | TRY |
---|
[540] | 2890 | { |
---|
| 2891 | if (isAxisListSet) return; |
---|
| 2892 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
[742] | 2893 | if (!axis.empty() && aList.empty()) |
---|
| 2894 | { |
---|
| 2895 | for (int i = 0; i < axis.size(); ++i) |
---|
| 2896 | this->getVirtualAxisGroup()->addChild(axis[i]); |
---|
| 2897 | aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 2898 | } |
---|
| 2899 | |
---|
[540] | 2900 | if (!aList.empty()) |
---|
| 2901 | { |
---|
| 2902 | int sizeAxis = aList.size(); |
---|
| 2903 | axisList_.resize(sizeAxis); |
---|
| 2904 | for (int i = 0; i < sizeAxis; ++i) |
---|
| 2905 | { |
---|
| 2906 | axisList_[i] = aList[i]->getId(); |
---|
| 2907 | } |
---|
| 2908 | isAxisListSet = true; |
---|
| 2909 | } |
---|
| 2910 | } |
---|
[1622] | 2911 | CATCH_DUMP_ATTR |
---|
[540] | 2912 | |
---|
[551] | 2913 | /*! |
---|
[887] | 2914 | \brief Set scalar(s) of a grid from a list |
---|
| 2915 | \param[in] scalars list of scalars |
---|
| 2916 | */ |
---|
| 2917 | void CGrid::setScalarList(const std::vector<CScalar*> scalars) |
---|
[1622] | 2918 | TRY |
---|
[887] | 2919 | { |
---|
| 2920 | if (isScalarListSet) return; |
---|
| 2921 | std::vector<CScalar*> sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 2922 | if (!scalars.empty() && sList.empty()) |
---|
| 2923 | { |
---|
| 2924 | for (int i = 0; i < scalars.size(); ++i) |
---|
| 2925 | this->getVirtualScalarGroup()->addChild(scalars[i]); |
---|
| 2926 | sList = this->getVirtualScalarGroup()->getAllChildren(); |
---|
| 2927 | } |
---|
| 2928 | |
---|
| 2929 | if (!sList.empty()) |
---|
| 2930 | { |
---|
| 2931 | int sizeScalar = sList.size(); |
---|
| 2932 | scalarList_.resize(sizeScalar); |
---|
| 2933 | for (int i = 0; i < sizeScalar; ++i) |
---|
| 2934 | { |
---|
| 2935 | scalarList_[i] = sList[i]->getId(); |
---|
| 2936 | } |
---|
| 2937 | isScalarListSet = true; |
---|
| 2938 | } |
---|
| 2939 | } |
---|
[1622] | 2940 | CATCH_DUMP_ATTR |
---|
[887] | 2941 | |
---|
| 2942 | /*! |
---|
[551] | 2943 | \brief Get list of id of domains |
---|
| 2944 | \return id list of domains |
---|
| 2945 | */ |
---|
[540] | 2946 | std::vector<StdString> CGrid::getDomainList() |
---|
[1622] | 2947 | TRY |
---|
[540] | 2948 | { |
---|
| 2949 | setDomainList(); |
---|
| 2950 | return domList_; |
---|
| 2951 | } |
---|
[1622] | 2952 | CATCH |
---|
[540] | 2953 | |
---|
[551] | 2954 | /*! |
---|
| 2955 | \brief Get list of id of axis |
---|
| 2956 | \return id list of axis |
---|
| 2957 | */ |
---|
[540] | 2958 | std::vector<StdString> CGrid::getAxisList() |
---|
[1622] | 2959 | TRY |
---|
[540] | 2960 | { |
---|
| 2961 | setAxisList(); |
---|
| 2962 | return axisList_; |
---|
| 2963 | } |
---|
[1622] | 2964 | CATCH |
---|
[540] | 2965 | |
---|
[887] | 2966 | /*! |
---|
| 2967 | \brief Get list of id of scalar |
---|
| 2968 | \return id list of scalar |
---|
| 2969 | */ |
---|
| 2970 | std::vector<StdString> CGrid::getScalarList() |
---|
[1622] | 2971 | TRY |
---|
[887] | 2972 | { |
---|
| 2973 | setScalarList(); |
---|
| 2974 | return scalarList_; |
---|
| 2975 | } |
---|
[1622] | 2976 | CATCH |
---|
[887] | 2977 | |
---|
| 2978 | /*! |
---|
[1927] | 2979 | Send all attributes of grid and all domain, axis, scalar from client to server |
---|
[887] | 2980 | */ |
---|
[540] | 2981 | |
---|
[1927] | 2982 | void CGrid::sendGrid(void) |
---|
[1622] | 2983 | TRY |
---|
[540] | 2984 | { |
---|
[1927] | 2985 | this->sendAllAttributesToServer(); |
---|
| 2986 | auto domainList=getDomains() ; |
---|
| 2987 | auto axisList=getAxis() ; |
---|
| 2988 | auto scalarList=getScalars() ; |
---|
| 2989 | int domainIdx = 0, axisIdx = 0, scalarIdx = 0; |
---|
| 2990 | |
---|
| 2991 | for (int idx = 0; idx < axis_domain_order.numElements(); ++idx) |
---|
[540] | 2992 | { |
---|
[1927] | 2993 | if (2 == axis_domain_order(idx)) // This is domain |
---|
| 2994 | { |
---|
| 2995 | sendAddDomain(domainList[domainIdx]->getId()) ; |
---|
| 2996 | domainList[domainIdx]->sendAllAttributesToServer(); |
---|
| 2997 | domainIdx++ ; |
---|
| 2998 | } |
---|
| 2999 | else if (1 == axis_domain_order(idx)) // This is axis |
---|
| 3000 | { |
---|
| 3001 | sendAddAxis(axisList[axisIdx]->getId()) ; |
---|
| 3002 | axisList[axisIdx]->sendAllAttributesToServer(); |
---|
| 3003 | axisIdx++ ; |
---|
| 3004 | } |
---|
| 3005 | else // Of course, this is scalar |
---|
| 3006 | { |
---|
| 3007 | sendAddScalar(scalarList[scalarIdx]->getId()) ; |
---|
| 3008 | scalarList[scalarIdx]->sendAllAttributesToServer(); |
---|
| 3009 | scalarIdx++ ; |
---|
| 3010 | } |
---|
[540] | 3011 | } |
---|
| 3012 | } |
---|
[1622] | 3013 | CATCH_DUMP_ATTR |
---|
[540] | 3014 | |
---|
[1294] | 3015 | void CGrid::setContextClient(CContextClient* contextClient) |
---|
[1622] | 3016 | TRY |
---|
[1294] | 3017 | { |
---|
[1353] | 3018 | if (clientsSet.find(contextClient)==clientsSet.end()) |
---|
| 3019 | { |
---|
| 3020 | clients.push_back(contextClient) ; |
---|
| 3021 | clientsSet.insert(contextClient); |
---|
| 3022 | } |
---|
[1345] | 3023 | for (int i=0; i<this->getDomains().size(); i++) |
---|
| 3024 | this->getDomains()[i]->setContextClient(contextClient); |
---|
| 3025 | for (int i=0; i<this->getAxis().size(); i++) |
---|
| 3026 | this->getAxis()[i]->setContextClient(contextClient); |
---|
[1294] | 3027 | } |
---|
[1622] | 3028 | CATCH_DUMP_ATTR |
---|
[1294] | 3029 | |
---|
[887] | 3030 | /*! |
---|
| 3031 | Parse a grid, for now, it contains only domain, axis and scalar |
---|
| 3032 | */ |
---|
[650] | 3033 | void CGrid::parse(xml::CXMLNode& node) |
---|
[1622] | 3034 | TRY |
---|
[540] | 3035 | { |
---|
| 3036 | SuperClass::parse(node); |
---|
[567] | 3037 | |
---|
[540] | 3038 | if (node.goToChildElement()) |
---|
| 3039 | { |
---|
| 3040 | StdString domainName("domain"); |
---|
| 3041 | StdString axisName("axis"); |
---|
[887] | 3042 | StdString scalarName("scalar"); |
---|
[540] | 3043 | do |
---|
| 3044 | { |
---|
| 3045 | if (node.getElementName() == domainName) { |
---|
[887] | 3046 | order_.push_back(2); |
---|
[540] | 3047 | this->getVirtualDomainGroup()->parseChild(node); |
---|
| 3048 | } |
---|
| 3049 | if (node.getElementName() == axisName) { |
---|
[887] | 3050 | order_.push_back(1); |
---|
[540] | 3051 | this->getVirtualAxisGroup()->parseChild(node); |
---|
| 3052 | } |
---|
[887] | 3053 | if (node.getElementName() == scalarName) { |
---|
| 3054 | order_.push_back(0); |
---|
| 3055 | this->getVirtualScalarGroup()->parseChild(node); |
---|
| 3056 | } |
---|
[650] | 3057 | } while (node.goToNextElement()); |
---|
[540] | 3058 | node.goToParentElement(); |
---|
| 3059 | } |
---|
| 3060 | |
---|
[835] | 3061 | if (!order_.empty()) |
---|
[540] | 3062 | { |
---|
[835] | 3063 | int sizeOrd = order_.size(); |
---|
[575] | 3064 | axis_domain_order.resize(sizeOrd); |
---|
[540] | 3065 | for (int i = 0; i < sizeOrd; ++i) |
---|
| 3066 | { |
---|
[835] | 3067 | axis_domain_order(i) = order_[i]; |
---|
[540] | 3068 | } |
---|
| 3069 | } |
---|
| 3070 | |
---|
| 3071 | setDomainList(); |
---|
| 3072 | setAxisList(); |
---|
[887] | 3073 | setScalarList(); |
---|
[540] | 3074 | } |
---|
[1622] | 3075 | CATCH_DUMP_ATTR |
---|
| 3076 | |
---|
[335] | 3077 | } // namespace xios |
---|