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