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