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