[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" |
---|
[219] | 19 | |
---|
[335] | 20 | namespace xios { |
---|
[219] | 21 | |
---|
| 22 | /// ////////////////////// Définitions ////////////////////// /// |
---|
| 23 | |
---|
| 24 | CGrid::CGrid(void) |
---|
| 25 | : CObjectTemplate<CGrid>(), CGridAttributes() |
---|
[650] | 26 | , isChecked(false), isDomainAxisChecked(false) |
---|
[551] | 27 | , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) |
---|
[657] | 28 | , serverDistribution_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() |
---|
[620] | 29 | , connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true), transformations_(0), isTransformed_(false) |
---|
[657] | 30 | , axisPositionInGrid_(), positionDimensionDistributed_(1) |
---|
[540] | 31 | { |
---|
| 32 | setVirtualDomainGroup(); |
---|
| 33 | setVirtualAxisGroup(); |
---|
| 34 | } |
---|
[219] | 35 | |
---|
[650] | 36 | CGrid::CGrid(const StdString& id) |
---|
[219] | 37 | : CObjectTemplate<CGrid>(id), CGridAttributes() |
---|
[650] | 38 | , isChecked(false), isDomainAxisChecked(false) |
---|
[551] | 39 | , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) |
---|
[657] | 40 | , serverDistribution_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() |
---|
[620] | 41 | , connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true), transformations_(0), isTransformed_(false) |
---|
[657] | 42 | , axisPositionInGrid_(), positionDimensionDistributed_(1) |
---|
[540] | 43 | { |
---|
| 44 | setVirtualDomainGroup(); |
---|
| 45 | setVirtualAxisGroup(); |
---|
| 46 | } |
---|
[219] | 47 | |
---|
| 48 | CGrid::~CGrid(void) |
---|
[509] | 49 | { |
---|
[551] | 50 | if (0 != clientDistribution_) delete clientDistribution_; |
---|
[552] | 51 | if (0 != serverDistribution_) delete serverDistribution_; |
---|
[656] | 52 | if (0 != clientServerMap_) delete clientServerMap_; |
---|
[620] | 53 | if (0 != transformations_) delete transformations_; |
---|
[219] | 54 | } |
---|
| 55 | |
---|
| 56 | ///--------------------------------------------------------------- |
---|
| 57 | |
---|
[650] | 58 | StdString CGrid::GetName(void) { return StdString("grid"); } |
---|
| 59 | StdString CGrid::GetDefName(void) { return CGrid::GetName(); } |
---|
| 60 | ENodeType CGrid::GetType(void) { return eGrid; } |
---|
[219] | 61 | |
---|
| 62 | |
---|
| 63 | StdSize CGrid::getDimension(void) const |
---|
| 64 | { |
---|
[650] | 65 | return globalDim_.size(); |
---|
[219] | 66 | } |
---|
| 67 | |
---|
| 68 | //--------------------------------------------------------------- |
---|
| 69 | |
---|
[286] | 70 | StdSize CGrid::getDataSize(void) const |
---|
| 71 | { |
---|
[586] | 72 | StdSize retvalue = 1; |
---|
[600] | 73 | if (!isScalarGrid()) |
---|
| 74 | { |
---|
| 75 | std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); |
---|
| 76 | for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; |
---|
| 77 | } |
---|
| 78 | return retvalue; |
---|
[286] | 79 | } |
---|
| 80 | |
---|
[509] | 81 | std::map<int, StdSize> CGrid::getConnectedServerDataSize() |
---|
| 82 | { |
---|
[551] | 83 | double secureFactor = 2.5 * sizeof(double) * CXios::bufferServerFactorSize; |
---|
[586] | 84 | StdSize retVal = 1; |
---|
[509] | 85 | std::map<int, StdSize> ret; |
---|
[586] | 86 | std::map<int, size_t >::const_iterator itb = connectedDataSize_.begin(), it, itE = connectedDataSize_.end(); |
---|
| 87 | |
---|
[600] | 88 | if (isScalarGrid()) |
---|
[509] | 89 | { |
---|
[586] | 90 | for (it = itb; it != itE; ++it) |
---|
| 91 | { |
---|
| 92 | retVal *= secureFactor; |
---|
| 93 | ret.insert(std::make_pair(it->first, retVal)); |
---|
| 94 | } |
---|
| 95 | return ret; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | for (it = itb; it != itE; ++it) |
---|
| 99 | { |
---|
[584] | 100 | retVal = it->second; |
---|
[551] | 101 | retVal *= secureFactor; |
---|
| 102 | ret.insert(std::make_pair<int,StdSize>(it->first, retVal)); |
---|
[509] | 103 | } |
---|
[551] | 104 | |
---|
[586] | 105 | if (connectedDataSize_.empty()) |
---|
| 106 | { |
---|
| 107 | for (int i = 0; i < connectedServerRank_.size(); ++i) |
---|
| 108 | { |
---|
| 109 | retVal = 1; |
---|
| 110 | retVal *= secureFactor; |
---|
| 111 | ret.insert(std::make_pair<int,StdSize>(connectedServerRank_[i], retVal)); |
---|
| 112 | } |
---|
| 113 | } |
---|
| 114 | |
---|
[657] | 115 | // In some cases in which domain is masked, we need to count for connected server for longitude and latitude |
---|
| 116 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 117 | if (!domListP.empty()) |
---|
| 118 | { |
---|
| 119 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 120 | { |
---|
| 121 | const std::map<int, vector<size_t> >& indexDomainServer = domListP[i]->getIndexServer(); |
---|
| 122 | std::map<int, vector<size_t> >::const_iterator itDom = indexDomainServer.begin(), iteDom = indexDomainServer.end(); |
---|
| 123 | for (; itDom != iteDom; ++itDom) |
---|
| 124 | { |
---|
| 125 | if (ret.end() == ret.find(itDom->first)) |
---|
| 126 | { |
---|
| 127 | retVal = (itDom->second).size(); |
---|
| 128 | retVal *= secureFactor; |
---|
| 129 | ret.insert(std::make_pair<int,StdSize>(itDom->first, retVal)); |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | } |
---|
| 134 | |
---|
[509] | 135 | return ret; |
---|
| 136 | } |
---|
| 137 | |
---|
[657] | 138 | void CGrid::checkAttributesAfterTransformation() |
---|
| 139 | { |
---|
| 140 | setDomainList(); |
---|
| 141 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 142 | if (!domListP.empty()) |
---|
| 143 | { |
---|
| 144 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 145 | { |
---|
| 146 | domListP[i]->checkAttributesOnClientAfterTransformation(); |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | } |
---|
[509] | 150 | |
---|
| 151 | void CGrid::solveDomainAxisRef(bool areAttributesChecked) |
---|
[219] | 152 | { |
---|
[509] | 153 | if (this->isDomainAxisChecked) return; |
---|
[369] | 154 | |
---|
[584] | 155 | this->solveAxisRef(areAttributesChecked); |
---|
[509] | 156 | this->solveDomainRef(areAttributesChecked); |
---|
[657] | 157 | computeGridGlobalDimension(getDomains(), getAxis(), axis_domain_order); |
---|
[509] | 158 | this->isDomainAxisChecked = areAttributesChecked; |
---|
| 159 | } |
---|
| 160 | |
---|
| 161 | void CGrid::checkMaskIndex(bool doSendingIndex) |
---|
| 162 | { |
---|
[650] | 163 | CContext* context = CContext::getCurrent(); |
---|
| 164 | CContextClient* client=context->client; |
---|
[509] | 165 | |
---|
[600] | 166 | if (isScalarGrid()) |
---|
[586] | 167 | { |
---|
| 168 | if (context->hasClient) |
---|
| 169 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } |
---|
| 170 | |
---|
| 171 | if (this->isChecked) return; |
---|
| 172 | if (context->hasClient) |
---|
| 173 | { |
---|
| 174 | this->computeIndexScalarGrid(); |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | this->isChecked = true; |
---|
| 178 | return; |
---|
| 179 | } |
---|
| 180 | |
---|
[509] | 181 | if (context->hasClient) |
---|
[551] | 182 | if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } |
---|
[509] | 183 | |
---|
| 184 | if (this->isChecked) return; |
---|
| 185 | |
---|
| 186 | if (context->hasClient) |
---|
| 187 | { |
---|
[657] | 188 | this->checkAttributesAfterTransformation(); |
---|
| 189 | this->checkMask(); |
---|
[650] | 190 | this->computeIndex(); |
---|
[509] | 191 | } |
---|
| 192 | this->isChecked = true; |
---|
[219] | 193 | } |
---|
| 194 | |
---|
[415] | 195 | void CGrid::checkMask(void) |
---|
| 196 | { |
---|
| 197 | using namespace std; |
---|
[567] | 198 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 199 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 200 | int dim = domainP.size() * 2 + axisP.size(); |
---|
[415] | 201 | |
---|
[567] | 202 | std::vector<CArray<bool,2>* > domainMasks(domainP.size()); |
---|
| 203 | for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->mask); |
---|
| 204 | std::vector<CArray<bool,1>* > axisMasks(axisP.size()); |
---|
| 205 | for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); |
---|
[415] | 206 | |
---|
[567] | 207 | switch (dim) { |
---|
| 208 | case 1: |
---|
[575] | 209 | checkGridMask(mask1, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 210 | break; |
---|
| 211 | case 2: |
---|
[575] | 212 | checkGridMask(mask2, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 213 | break; |
---|
| 214 | case 3: |
---|
[575] | 215 | checkGridMask(mask3, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 216 | break; |
---|
| 217 | // case 4: |
---|
[575] | 218 | // checkGridMask(mask4, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 219 | // break; |
---|
| 220 | // case 5: |
---|
[575] | 221 | // checkGridMask(mask5, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 222 | // break; |
---|
| 223 | // case 6: |
---|
[575] | 224 | // checkGridMask(mask6, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 225 | // break; |
---|
| 226 | // case 7: |
---|
[575] | 227 | // checkGridMask(mask7, domainMasks, axisMasks, axis_domain_order); |
---|
[567] | 228 | // break; |
---|
| 229 | default: |
---|
| 230 | break; |
---|
[415] | 231 | } |
---|
| 232 | } |
---|
[623] | 233 | |
---|
| 234 | void CGrid::modifyMask(const CArray<int,1>& indexToModify) |
---|
| 235 | { |
---|
| 236 | using namespace std; |
---|
| 237 | std::vector<CDomain*> domainP = this->getDomains(); |
---|
| 238 | std::vector<CAxis*> axisP = this->getAxis(); |
---|
| 239 | int dim = domainP.size() * 2 + axisP.size(); |
---|
| 240 | |
---|
| 241 | switch (dim) { |
---|
| 242 | case 1: |
---|
| 243 | modifyGridMask(mask1, indexToModify); |
---|
| 244 | break; |
---|
| 245 | case 2: |
---|
| 246 | modifyGridMask(mask2, indexToModify); |
---|
| 247 | break; |
---|
| 248 | case 3: |
---|
| 249 | modifyGridMask(mask3, indexToModify); |
---|
| 250 | break; |
---|
| 251 | |
---|
| 252 | default: |
---|
| 253 | break; |
---|
| 254 | } |
---|
| 255 | } |
---|
| 256 | |
---|
[219] | 257 | //--------------------------------------------------------------- |
---|
| 258 | |
---|
[509] | 259 | void CGrid::solveDomainRef(bool sendAtt) |
---|
[219] | 260 | { |
---|
[540] | 261 | setDomainList(); |
---|
[567] | 262 | std::vector<CDomain*> domListP = this->getDomains(); |
---|
| 263 | if (!domListP.empty()) |
---|
[219] | 264 | { |
---|
[567] | 265 | for (int i = 0; i < domListP.size(); ++i) |
---|
| 266 | { |
---|
| 267 | if (sendAtt) domListP[i]->sendCheckedAttributes(); |
---|
| 268 | else domListP[i]->checkAttributesOnClient(); |
---|
| 269 | } |
---|
[219] | 270 | } |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | //--------------------------------------------------------------- |
---|
| 274 | |
---|
[567] | 275 | void CGrid::solveAxisRef(bool sendAtt) |
---|
[219] | 276 | { |
---|
[540] | 277 | setAxisList(); |
---|
[567] | 278 | std::vector<CAxis*> axisListP = this->getAxis(); |
---|
| 279 | if (!axisListP.empty()) |
---|
[219] | 280 | { |
---|
[567] | 281 | int idx = 0; |
---|
[620] | 282 | axisPositionInGrid_.resize(0); |
---|
[575] | 283 | for (int i = 0; i < axis_domain_order.numElements(); ++i) |
---|
[568] | 284 | { |
---|
[575] | 285 | if (false == axis_domain_order(i)) |
---|
[568] | 286 | { |
---|
[620] | 287 | axisPositionInGrid_.push_back(idx); |
---|
[568] | 288 | ++idx; |
---|
| 289 | } |
---|
| 290 | else idx += 2; |
---|
| 291 | } |
---|
| 292 | |
---|
[567] | 293 | for (int i = 0; i < axisListP.size(); ++i) |
---|
[540] | 294 | { |
---|
[567] | 295 | if (sendAtt) |
---|
[620] | 296 | axisListP[i]->sendCheckedAttributes(globalDim_,axisPositionInGrid_[i]); |
---|
[567] | 297 | else |
---|
[620] | 298 | axisListP[i]->checkAttributesOnClient(globalDim_,axisPositionInGrid_[i]); |
---|
[567] | 299 | ++idx; |
---|
[540] | 300 | } |
---|
[219] | 301 | } |
---|
| 302 | } |
---|
| 303 | |
---|
[620] | 304 | std::vector<int> CGrid::getAxisPositionInGrid() const |
---|
| 305 | { |
---|
| 306 | return axisPositionInGrid_; |
---|
| 307 | } |
---|
| 308 | |
---|
[219] | 309 | //--------------------------------------------------------------- |
---|
| 310 | |
---|
| 311 | void CGrid::computeIndex(void) |
---|
[509] | 312 | { |
---|
[650] | 313 | CContext* context = CContext::getCurrent(); |
---|
| 314 | CContextClient* client = context->client; |
---|
[553] | 315 | |
---|
| 316 | // First of all, compute distribution on client side |
---|
[551] | 317 | clientDistribution_ = new CDistributionClient(client->clientRank, this); |
---|
[586] | 318 | // Get local data index on client |
---|
| 319 | storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); |
---|
| 320 | storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); |
---|
| 321 | isDataDistributed_= clientDistribution_->isDataDistributed(); |
---|
| 322 | |
---|
| 323 | if (!doGridHaveDataDistributed()) |
---|
| 324 | { |
---|
| 325 | if (0 == client->clientRank) |
---|
| 326 | { |
---|
| 327 | size_t ssize = clientDistribution_->getLocalDataIndexOnClient().numElements(); |
---|
| 328 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
| 329 | connectedDataSize_[rank] = ssize; |
---|
| 330 | } |
---|
| 331 | return; |
---|
| 332 | } |
---|
| 333 | |
---|
| 334 | // Compute mapping between client and server |
---|
[568] | 335 | size_t globalSizeIndex = 1, indexBegin, indexEnd; |
---|
| 336 | int range, clientSize = client->clientSize; |
---|
| 337 | for (int i = 0; i < globalDim_.size(); ++i) globalSizeIndex *= globalDim_[i]; |
---|
| 338 | indexBegin = 0; |
---|
| 339 | for (int i = 0; i < clientSize; ++i) |
---|
| 340 | { |
---|
| 341 | range = globalSizeIndex / clientSize; |
---|
| 342 | if (i < (globalSizeIndex%clientSize)) ++range; |
---|
| 343 | if (i == client->clientRank) break; |
---|
| 344 | indexBegin += range; |
---|
| 345 | } |
---|
| 346 | indexEnd = indexBegin + range - 1; |
---|
[509] | 347 | |
---|
[553] | 348 | // Then compute distribution on server side |
---|
[657] | 349 | CServerDistributionDescription serverDistributionDescription(globalDim_); |
---|
| 350 | serverDistributionDescription.computeServerGlobalIndexInRange(client->serverSize, |
---|
| 351 | std::make_pair<size_t,size_t>(indexBegin, indexEnd), |
---|
| 352 | positionDimensionDistributed_); |
---|
[553] | 353 | |
---|
| 354 | // Finally, compute index mapping between client(s) and server(s) |
---|
[657] | 355 | clientServerMap_ = new CClientServerMappingDistributed(serverDistributionDescription.getGlobalIndexRange(), |
---|
[585] | 356 | client->intraComm, |
---|
| 357 | clientDistribution_->isDataDistributed()); |
---|
[568] | 358 | |
---|
[584] | 359 | clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex()); |
---|
[568] | 360 | const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); |
---|
[584] | 361 | const CArray<size_t,1>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); |
---|
| 362 | std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
| 363 | itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); |
---|
| 364 | iteGlobalMap = globalIndexOnServer.end(); |
---|
| 365 | |
---|
| 366 | int nbGlobalIndex = globalIndexSendToServer.numElements(); |
---|
| 367 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 368 | { |
---|
| 369 | int serverRank = itGlobalMap->first; |
---|
| 370 | std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), itVecGlobal, |
---|
| 371 | iteVecGlobal = (itGlobalMap->second).end(); |
---|
| 372 | for (int i = 0; i < nbGlobalIndex; ++i) |
---|
| 373 | { |
---|
| 374 | if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i))) |
---|
| 375 | { |
---|
| 376 | if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) |
---|
[590] | 377 | connectedDataSize_[serverRank] = 1; |
---|
[584] | 378 | else |
---|
| 379 | ++connectedDataSize_[serverRank]; |
---|
| 380 | } |
---|
| 381 | } |
---|
| 382 | } |
---|
| 383 | |
---|
| 384 | connectedServerRank_.clear(); |
---|
| 385 | for (std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) { |
---|
| 386 | connectedServerRank_.push_back(it->first); |
---|
| 387 | } |
---|
| 388 | if (!connectedDataSize_.empty()) |
---|
| 389 | { |
---|
| 390 | connectedServerRank_.clear(); |
---|
| 391 | for (std::map<int,size_t>::const_iterator it = connectedDataSize_.begin(); it != connectedDataSize_.end(); ++it) |
---|
| 392 | connectedServerRank_.push_back(it->first); |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); |
---|
[219] | 396 | } |
---|
| 397 | |
---|
| 398 | //---------------------------------------------------------------- |
---|
| 399 | |
---|
[347] | 400 | CGrid* CGrid::createGrid(CDomain* domain) |
---|
[219] | 401 | { |
---|
[567] | 402 | std::vector<CDomain*> vecDom(1,domain); |
---|
| 403 | std::vector<CAxis*> vecAxis; |
---|
[622] | 404 | CArray<bool,1> axisDomainOrder; |
---|
| 405 | CGrid* grid = createGrid(vecDom, vecAxis, axisDomainOrder); |
---|
[540] | 406 | |
---|
[650] | 407 | return grid; |
---|
[219] | 408 | } |
---|
| 409 | |
---|
[347] | 410 | CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) |
---|
[219] | 411 | { |
---|
[540] | 412 | std::vector<CDomain*> vecDom(1,domain); |
---|
| 413 | std::vector<CAxis*> vecAxis(1,axis); |
---|
[622] | 414 | CArray<bool,1> axisDomainOrder; |
---|
| 415 | CGrid* grid = createGrid(vecDom, vecAxis, axisDomainOrder); |
---|
[567] | 416 | |
---|
[650] | 417 | return grid; |
---|
[219] | 418 | } |
---|
| 419 | |
---|
[622] | 420 | CGrid* CGrid::createGrid(std::vector<CDomain*> domains, std::vector<CAxis*> axis, CArray<bool,1> axisDomainOrder) |
---|
[540] | 421 | { |
---|
| 422 | StdString new_id = StdString("__"); |
---|
| 423 | if (!domains.empty()) for (int i = 0; i < domains.size(); ++i) new_id += domains[i]->getId() + StdString("_"); |
---|
[650] | 424 | if (!axis.empty()) for (int i = 0; i < axis.size(); ++i) new_id += axis[i]->getId() + StdString("_"); |
---|
[586] | 425 | if (domains.empty() && axis.empty()) new_id += StdString("scalar_grid"); |
---|
[540] | 426 | new_id += StdString("_"); |
---|
| 427 | |
---|
[650] | 428 | CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id); |
---|
[540] | 429 | grid->setDomainList(domains); |
---|
| 430 | grid->setAxisList(axis); |
---|
[551] | 431 | |
---|
| 432 | //By default, domains are always the first ones of a grid |
---|
[622] | 433 | if (0 == axisDomainOrder.numElements()) |
---|
[551] | 434 | { |
---|
| 435 | int size = domains.size()+axis.size(); |
---|
[575] | 436 | grid->axis_domain_order.resize(size); |
---|
[551] | 437 | for (int i = 0; i < size; ++i) |
---|
| 438 | { |
---|
[575] | 439 | if (i < domains.size()) grid->axis_domain_order(i) = true; |
---|
| 440 | else grid->axis_domain_order(i) = false; |
---|
[551] | 441 | } |
---|
| 442 | } |
---|
[622] | 443 | else |
---|
| 444 | { |
---|
| 445 | grid->axis_domain_order.resize(axisDomainOrder.numElements()); |
---|
| 446 | grid->axis_domain_order = axisDomainOrder; |
---|
| 447 | } |
---|
[551] | 448 | |
---|
[587] | 449 | grid->computeGridGlobalDimension(domains, axis, grid->axis_domain_order); |
---|
[586] | 450 | |
---|
[650] | 451 | return grid; |
---|
[540] | 452 | } |
---|
| 453 | |
---|
| 454 | CDomainGroup* CGrid::getVirtualDomainGroup() const |
---|
| 455 | { |
---|
[650] | 456 | return this->vDomainGroup_; |
---|
[540] | 457 | } |
---|
| 458 | |
---|
| 459 | CAxisGroup* CGrid::getVirtualAxisGroup() const |
---|
| 460 | { |
---|
[650] | 461 | return this->vAxisGroup_; |
---|
[540] | 462 | } |
---|
| 463 | |
---|
[551] | 464 | void CGrid::outputField(int rank, const CArray<double, 1>& stored, double* field) |
---|
| 465 | { |
---|
[650] | 466 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
[551] | 467 | StdSize numElements = stored.numElements(); |
---|
| 468 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 469 | { |
---|
[650] | 470 | field[out_i(n)] = stored(n); |
---|
[551] | 471 | } |
---|
| 472 | } |
---|
| 473 | |
---|
[599] | 474 | void CGrid::inputField(int rank, const double* const field, CArray<double,1>& stored) |
---|
| 475 | { |
---|
[650] | 476 | const CArray<size_t,1>& out_i = outIndexFromClient[rank]; |
---|
[599] | 477 | StdSize numElements = stored.numElements(); |
---|
| 478 | for (StdSize n = 0; n < numElements; ++n) |
---|
| 479 | { |
---|
[650] | 480 | stored(n) = field[out_i(n)]; |
---|
[599] | 481 | } |
---|
| 482 | } |
---|
| 483 | |
---|
[219] | 484 | //---------------------------------------------------------------- |
---|
| 485 | |
---|
[650] | 486 | void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored) const |
---|
[219] | 487 | { |
---|
[650] | 488 | const StdSize size = storeIndex_client.numElements(); |
---|
[300] | 489 | |
---|
[650] | 490 | stored.resize(size); |
---|
| 491 | for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; |
---|
[219] | 492 | } |
---|
[509] | 493 | |
---|
[650] | 494 | void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data) const |
---|
[593] | 495 | { |
---|
[650] | 496 | const StdSize size = storeIndex_client.numElements(); |
---|
[593] | 497 | |
---|
[650] | 498 | for(StdSize i = 0; i < size; i++) data[storeIndex_client(i)] = stored(i); |
---|
[593] | 499 | } |
---|
| 500 | |
---|
[586] | 501 | void CGrid::computeIndexScalarGrid() |
---|
[300] | 502 | { |
---|
[586] | 503 | CContext* context = CContext::getCurrent(); |
---|
| 504 | CContextClient* client=context->client; |
---|
| 505 | |
---|
| 506 | storeIndex_client.resize(1); |
---|
| 507 | storeIndex_client[0] = 0; |
---|
| 508 | if (0 == client->clientRank) |
---|
| 509 | { |
---|
| 510 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
| 511 | connectedDataSize_[rank] = 1; |
---|
| 512 | } |
---|
| 513 | isDataDistributed_ = false; |
---|
| 514 | } |
---|
| 515 | |
---|
| 516 | void CGrid::sendIndexScalarGrid() |
---|
| 517 | { |
---|
[650] | 518 | CContext* context = CContext::getCurrent(); |
---|
| 519 | CContextClient* client = context->client; |
---|
[509] | 520 | |
---|
[650] | 521 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 522 | list<CMessage> listMsg; |
---|
| 523 | list<CArray<size_t,1> > listOutIndex; |
---|
| 524 | |
---|
[586] | 525 | if (0 == client->clientRank) |
---|
[551] | 526 | { |
---|
[586] | 527 | for (int rank = 0; rank < client->serverSize; ++rank) |
---|
[551] | 528 | { |
---|
[586] | 529 | int nb = 1; |
---|
[650] | 530 | storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(nb))); |
---|
| 531 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
| 532 | |
---|
| 533 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; |
---|
| 534 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
| 535 | |
---|
[586] | 536 | for (int k = 0; k < nb; ++k) |
---|
[567] | 537 | { |
---|
[586] | 538 | outGlobalIndexOnServer(k) = 0; |
---|
| 539 | outLocalIndexToServer(k) = 0; |
---|
[584] | 540 | } |
---|
[586] | 541 | |
---|
[650] | 542 | listMsg.push_back(CMessage()); |
---|
| 543 | listMsg.back() << getId( )<< isDataDistributed_ << listOutIndex.back(); |
---|
[586] | 544 | |
---|
[650] | 545 | event.push(rank, 1, listMsg.back()); |
---|
| 546 | } |
---|
[586] | 547 | |
---|
| 548 | client->sendEvent(event); |
---|
[584] | 549 | } |
---|
[586] | 550 | else |
---|
| 551 | client->sendEvent(event); |
---|
| 552 | } |
---|
[551] | 553 | |
---|
[586] | 554 | void CGrid::sendIndex(void) |
---|
| 555 | { |
---|
[650] | 556 | CContext* context = CContext::getCurrent(); |
---|
| 557 | CContextClient* client = context->client; |
---|
[586] | 558 | |
---|
[650] | 559 | CEventClient event(getType(), EVENT_ID_INDEX); |
---|
| 560 | int rank; |
---|
| 561 | list<CMessage> listMsg; |
---|
| 562 | list<CArray<size_t,1> > listOutIndex; |
---|
[586] | 563 | const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); |
---|
| 564 | const CArray<int,1>& localIndexSendToServer = clientDistribution_->getLocalDataIndexSendToServer(); |
---|
| 565 | const CArray<size_t,1>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); |
---|
| 566 | |
---|
[584] | 567 | if (!doGridHaveDataDistributed()) |
---|
| 568 | { |
---|
[585] | 569 | if (0 == client->clientRank) |
---|
| 570 | { |
---|
[650] | 571 | const CArray<size_t, 1>& outGlobalIndexOnServer = globalIndexSendToServer; |
---|
| 572 | const CArray<int,1>& outLocalIndexToServer = localIndexSendToServer; |
---|
| 573 | |
---|
[585] | 574 | for (rank = 0; rank < client->serverSize; ++rank) |
---|
| 575 | { |
---|
[650] | 576 | storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer))); |
---|
| 577 | listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); |
---|
[585] | 578 | |
---|
[650] | 579 | listMsg.push_back(CMessage()); |
---|
| 580 | listMsg.back() << getId() << isDataDistributed_ << listOutIndex.back(); |
---|
[585] | 581 | |
---|
[650] | 582 | event.push(rank, 1, listMsg.back()); |
---|
[585] | 583 | } |
---|
[650] | 584 | |
---|
[585] | 585 | client->sendEvent(event); |
---|
| 586 | } |
---|
| 587 | else |
---|
| 588 | client->sendEvent(event); |
---|
[551] | 589 | } |
---|
[567] | 590 | else |
---|
[300] | 591 | { |
---|
[586] | 592 | std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; |
---|
| 593 | itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); |
---|
| 594 | iteGlobalMap = globalIndexOnServer.end(); |
---|
| 595 | |
---|
| 596 | int nbGlobalIndex = globalIndexSendToServer.numElements(); |
---|
| 597 | std::map<int,std::vector<int> >localIndexTmp; |
---|
| 598 | std::map<int,std::vector<size_t> > globalIndexTmp; |
---|
[650] | 599 | |
---|
[586] | 600 | for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) |
---|
| 601 | { |
---|
| 602 | int serverRank = itGlobalMap->first; |
---|
| 603 | std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), |
---|
| 604 | iteVecGlobal = (itGlobalMap->second).end(); |
---|
| 605 | for (int i = 0; i < nbGlobalIndex; ++i) |
---|
| 606 | { |
---|
| 607 | if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i))) |
---|
| 608 | { |
---|
| 609 | globalIndexTmp[serverRank].push_back(globalIndexSendToServer(i)); |
---|
| 610 | localIndexTmp[serverRank].push_back(localIndexSendToServer(i)); |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | } |
---|
| 614 | |
---|
[584] | 615 | for (int ns = 0; ns < connectedServerRank_.size(); ++ns) |
---|
[567] | 616 | { |
---|
[584] | 617 | rank = connectedServerRank_[ns]; |
---|
| 618 | int nb = 0; |
---|
| 619 | if (globalIndexTmp.end() != globalIndexTmp.find(rank)) |
---|
| 620 | nb = globalIndexTmp[rank].size(); |
---|
[509] | 621 | |
---|
[650] | 622 | storeIndex_toSrv.insert(make_pair(rank, CArray<int,1>(nb))); |
---|
| 623 | listOutIndex.push_back(CArray<size_t,1>(nb)); |
---|
| 624 | |
---|
| 625 | CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; |
---|
| 626 | CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); |
---|
| 627 | |
---|
[567] | 628 | for (int k = 0; k < nb; ++k) |
---|
| 629 | { |
---|
[584] | 630 | outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); |
---|
| 631 | outLocalIndexToServer(k) = localIndexTmp[rank].at(k); |
---|
[567] | 632 | } |
---|
[509] | 633 | |
---|
[650] | 634 | listMsg.push_back(CMessage()); |
---|
| 635 | listMsg.back() << getId() << isDataDistributed_ << listOutIndex.back(); |
---|
[509] | 636 | |
---|
[650] | 637 | event.push(rank, nbSenders[rank], listMsg.back()); |
---|
[567] | 638 | } |
---|
[584] | 639 | |
---|
[567] | 640 | client->sendEvent(event); |
---|
[300] | 641 | } |
---|
| 642 | } |
---|
[509] | 643 | |
---|
[300] | 644 | void CGrid::recvIndex(CEventServer& event) |
---|
| 645 | { |
---|
[598] | 646 | string gridId; |
---|
| 647 | vector<int> ranks; |
---|
| 648 | vector<CBufferIn*> buffers; |
---|
| 649 | |
---|
| 650 | list<CEventServer::SSubEvent>::iterator it; |
---|
[650] | 651 | for (it = event.subEvents.begin(); it != event.subEvents.end(); ++it) |
---|
[300] | 652 | { |
---|
[598] | 653 | ranks.push_back(it->rank); |
---|
| 654 | CBufferIn* buffer = it->buffer; |
---|
| 655 | *buffer >> gridId; |
---|
| 656 | buffers.push_back(buffer); |
---|
[300] | 657 | } |
---|
[650] | 658 | get(gridId)->recvIndex(ranks, buffers); |
---|
[300] | 659 | } |
---|
[509] | 660 | |
---|
[567] | 661 | void CGrid::computeGridGlobalDimension(const std::vector<CDomain*>& domains, |
---|
| 662 | const std::vector<CAxis*>& axis, |
---|
| 663 | const CArray<bool,1>& axisDomainOrder) |
---|
| 664 | { |
---|
| 665 | globalDim_.resize(domains.size()*2+axis.size()); |
---|
| 666 | int idx = 0, idxDomain = 0, idxAxis = 0; |
---|
| 667 | for (int i = 0; i < axisDomainOrder.numElements(); ++i) |
---|
| 668 | { |
---|
| 669 | if (axisDomainOrder(i)) |
---|
| 670 | { |
---|
[657] | 671 | if (!(domains[idxDomain]->type.isEmpty()) && (domains[idxDomain]->type==CDomain::type_attr::unstructured)) |
---|
| 672 | { |
---|
| 673 | positionDimensionDistributed_ = idx; |
---|
| 674 | } |
---|
| 675 | else |
---|
| 676 | { |
---|
| 677 | positionDimensionDistributed_ = idx +1; |
---|
| 678 | } |
---|
| 679 | |
---|
[567] | 680 | globalDim_[idx] = domains[idxDomain]->ni_glo.getValue(); |
---|
| 681 | globalDim_[idx+1] = domains[idxDomain]->nj_glo.getValue(); |
---|
[657] | 682 | |
---|
[567] | 683 | ++idxDomain; |
---|
| 684 | idx += 2; |
---|
| 685 | } |
---|
| 686 | else |
---|
| 687 | { |
---|
| 688 | globalDim_[idx] = axis[idxAxis]->size.getValue(); |
---|
| 689 | ++idxAxis; |
---|
| 690 | ++idx; |
---|
| 691 | } |
---|
| 692 | } |
---|
| 693 | } |
---|
| 694 | |
---|
| 695 | std::vector<int> CGrid::getGlobalDimension() |
---|
| 696 | { |
---|
| 697 | return globalDim_; |
---|
| 698 | } |
---|
| 699 | |
---|
[600] | 700 | bool CGrid::isScalarGrid() const |
---|
| 701 | { |
---|
| 702 | return (axisList_.empty() && domList_.empty()); |
---|
| 703 | } |
---|
| 704 | |
---|
[567] | 705 | /*! |
---|
| 706 | Verify whether one server need to write data |
---|
| 707 | There are some cases on which one server has nodata to write. For example, when we |
---|
[650] | 708 | just only want to zoom on a domain. |
---|
[567] | 709 | */ |
---|
| 710 | bool CGrid::doGridHaveDataToWrite() |
---|
| 711 | { |
---|
[624] | 712 | return (0 != writtenDataSize_); |
---|
[567] | 713 | } |
---|
| 714 | |
---|
| 715 | /*! |
---|
| 716 | Return size of data which is written on each server |
---|
| 717 | Whatever dimension of a grid, data which are written on server must be presented as |
---|
[650] | 718 | an one dimension array. |
---|
| 719 | \return size of data written on server |
---|
[567] | 720 | */ |
---|
| 721 | size_t CGrid::getWrittenDataSize() const |
---|
| 722 | { |
---|
| 723 | return writtenDataSize_; |
---|
| 724 | } |
---|
| 725 | |
---|
| 726 | const CDistributionServer* CGrid::getDistributionServer() const |
---|
| 727 | { |
---|
| 728 | return serverDistribution_; |
---|
| 729 | } |
---|
| 730 | |
---|
[620] | 731 | const CDistributionClient* CGrid::getDistributionClient() const |
---|
| 732 | { |
---|
| 733 | return clientDistribution_; |
---|
| 734 | } |
---|
| 735 | |
---|
[567] | 736 | bool CGrid::doGridHaveDataDistributed() |
---|
| 737 | { |
---|
[600] | 738 | if (isScalarGrid()) return false; |
---|
[586] | 739 | else |
---|
| 740 | return isDataDistributed_; |
---|
[567] | 741 | } |
---|
| 742 | |
---|
[598] | 743 | void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers) |
---|
[300] | 744 | { |
---|
[598] | 745 | CContext* context = CContext::getCurrent(); |
---|
| 746 | CContextServer* server = context->server; |
---|
[586] | 747 | |
---|
[598] | 748 | for (int n = 0; n < ranks.size(); n++) |
---|
[586] | 749 | { |
---|
[598] | 750 | int rank = ranks[n]; |
---|
| 751 | CBufferIn& buffer = *buffers[n]; |
---|
[586] | 752 | |
---|
[598] | 753 | buffer >> isDataDistributed_; |
---|
| 754 | size_t dataSize = 0; |
---|
[586] | 755 | |
---|
[600] | 756 | if (isScalarGrid()) |
---|
[598] | 757 | { |
---|
| 758 | writtenDataSize_ = 1; |
---|
| 759 | CArray<size_t,1> outIndex; |
---|
| 760 | buffer >> outIndex; |
---|
[650] | 761 | outIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
[598] | 762 | std::vector<int> nZoomBegin(1,0), nZoomSize(1,1), nGlob(1,1), nZoomBeginGlobal(1,0); |
---|
| 763 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 764 | nZoomBeginGlobal, nGlob); |
---|
| 765 | return; |
---|
| 766 | } |
---|
| 767 | |
---|
| 768 | if (0 == serverDistribution_) |
---|
| 769 | { |
---|
| 770 | int idx = 0, numElement = axis_domain_order.numElements(); |
---|
| 771 | int ssize = numElement; |
---|
| 772 | std::vector<int> indexMap(numElement); |
---|
| 773 | for (int i = 0; i < numElement; ++i) |
---|
| 774 | { |
---|
| 775 | indexMap[i] = idx; |
---|
| 776 | if (true == axis_domain_order(i)) |
---|
| 777 | { |
---|
[567] | 778 | ++ssize; |
---|
| 779 | idx += 2; |
---|
[598] | 780 | } |
---|
| 781 | else |
---|
| 782 | ++idx; |
---|
| 783 | } |
---|
[552] | 784 | |
---|
[598] | 785 | int axisId = 0, domainId = 0; |
---|
| 786 | std::vector<CDomain*> domainList = getDomains(); |
---|
| 787 | std::vector<CAxis*> axisList = getAxis(); |
---|
| 788 | std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize), nZoomBeginGlobal(ssize); |
---|
| 789 | for (int i = 0; i < numElement; ++i) |
---|
| 790 | { |
---|
| 791 | if (axis_domain_order(i)) |
---|
| 792 | { |
---|
| 793 | nZoomBegin[indexMap[i]] = domainList[domainId]->zoom_ibegin_srv; |
---|
| 794 | nZoomSize[indexMap[i]] = domainList[domainId]->zoom_ni_srv; |
---|
[631] | 795 | nZoomBeginGlobal[indexMap[i]] = domainList[domainId]->global_zoom_ibegin; |
---|
[598] | 796 | nGlob[indexMap[i]] = domainList[domainId]->ni_glo; |
---|
[552] | 797 | |
---|
[598] | 798 | nZoomBegin[indexMap[i] + 1] = domainList[domainId]->zoom_jbegin_srv; |
---|
| 799 | nZoomSize[indexMap[i] + 1] = domainList[domainId]->zoom_nj_srv; |
---|
[631] | 800 | nZoomBeginGlobal[indexMap[i] + 1] = domainList[domainId]->global_zoom_jbegin; |
---|
[598] | 801 | nGlob[indexMap[i] + 1] = domainList[domainId]->nj_glo; |
---|
[552] | 802 | ++domainId; |
---|
[598] | 803 | } |
---|
| 804 | else |
---|
| 805 | { |
---|
[567] | 806 | nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin_srv; |
---|
| 807 | nZoomSize[indexMap[i]] = axisList[axisId]->zoom_size_srv; |
---|
[623] | 808 | nZoomBeginGlobal[indexMap[i]] = axisList[axisId]->global_zoom_begin; |
---|
[598] | 809 | nGlob[indexMap[i]] = axisList[axisId]->size; |
---|
[552] | 810 | ++axisId; |
---|
[598] | 811 | } |
---|
| 812 | } |
---|
| 813 | dataSize = 1; |
---|
| 814 | for (int i = 0; i < nZoomSize.size(); ++i) |
---|
| 815 | dataSize *= nZoomSize[i]; |
---|
[567] | 816 | |
---|
[598] | 817 | serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, |
---|
| 818 | nZoomBeginGlobal, nGlob); |
---|
| 819 | } |
---|
[552] | 820 | |
---|
[598] | 821 | CArray<size_t,1> outIndex; |
---|
| 822 | buffer >> outIndex; |
---|
| 823 | if (isDataDistributed_) |
---|
| 824 | serverDistribution_->computeLocalIndex(outIndex); |
---|
| 825 | else |
---|
| 826 | { |
---|
| 827 | dataSize = outIndex.numElements(); |
---|
| 828 | for (int i = 0; i < outIndex.numElements(); ++i) outIndex(i) = i; |
---|
| 829 | } |
---|
| 830 | writtenDataSize_ += dataSize; |
---|
[586] | 831 | |
---|
[650] | 832 | outIndexFromClient.insert(std::make_pair(rank, outIndex)); |
---|
[598] | 833 | connectedDataSize_[rank] = outIndex.numElements(); |
---|
| 834 | } |
---|
| 835 | |
---|
| 836 | nbSenders = CClientServerMappingDistributed::computeConnectedClients(context->client->serverSize, context->client->clientSize, context->client->intraComm, ranks); |
---|
[300] | 837 | } |
---|
| 838 | |
---|
[540] | 839 | /*! |
---|
| 840 | \brief Dispatch event received from client |
---|
| 841 | Whenever a message is received in buffer of server, it will be processed depending on |
---|
| 842 | its event type. A new event type should be added in the switch list to make sure |
---|
| 843 | it processed on server side. |
---|
| 844 | \param [in] event: Received message |
---|
| 845 | */ |
---|
[300] | 846 | bool CGrid::dispatchEvent(CEventServer& event) |
---|
| 847 | { |
---|
[509] | 848 | |
---|
[650] | 849 | if (SuperClass::dispatchEvent(event)) return true; |
---|
[300] | 850 | else |
---|
| 851 | { |
---|
| 852 | switch(event.type) |
---|
| 853 | { |
---|
| 854 | case EVENT_ID_INDEX : |
---|
[650] | 855 | recvIndex(event); |
---|
| 856 | return true; |
---|
| 857 | break; |
---|
[509] | 858 | |
---|
[540] | 859 | case EVENT_ID_ADD_DOMAIN : |
---|
[650] | 860 | recvAddDomain(event); |
---|
| 861 | return true; |
---|
| 862 | break; |
---|
[540] | 863 | |
---|
| 864 | case EVENT_ID_ADD_AXIS : |
---|
[650] | 865 | recvAddAxis(event); |
---|
| 866 | return true; |
---|
| 867 | break; |
---|
[300] | 868 | default : |
---|
| 869 | ERROR("bool CDomain::dispatchEvent(CEventServer& event)", |
---|
[650] | 870 | << "Unknown Event"); |
---|
| 871 | return false; |
---|
[300] | 872 | } |
---|
| 873 | } |
---|
| 874 | } |
---|
| 875 | |
---|
[219] | 876 | ///--------------------------------------------------------------- |
---|
| 877 | |
---|
[540] | 878 | CDomain* CGrid::addDomain(const std::string& id) |
---|
| 879 | { |
---|
[650] | 880 | return vDomainGroup_->createChild(id); |
---|
[540] | 881 | } |
---|
| 882 | |
---|
| 883 | CAxis* CGrid::addAxis(const std::string& id) |
---|
| 884 | { |
---|
[650] | 885 | return vAxisGroup_->createChild(id); |
---|
[540] | 886 | } |
---|
| 887 | |
---|
| 888 | //! Change virtual field group to a new one |
---|
| 889 | void CGrid::setVirtualDomainGroup(CDomainGroup* newVDomainGroup) |
---|
| 890 | { |
---|
| 891 | this->vDomainGroup_ = newVDomainGroup; |
---|
| 892 | } |
---|
| 893 | |
---|
| 894 | //! Change virtual variable group to new one |
---|
| 895 | void CGrid::setVirtualAxisGroup(CAxisGroup* newVAxisGroup) |
---|
| 896 | { |
---|
| 897 | this->vAxisGroup_ = newVAxisGroup; |
---|
| 898 | } |
---|
| 899 | |
---|
| 900 | //---------------------------------------------------------------- |
---|
| 901 | //! Create virtual field group, which is done normally on initializing file |
---|
| 902 | void CGrid::setVirtualDomainGroup(void) |
---|
| 903 | { |
---|
| 904 | this->setVirtualDomainGroup(CDomainGroup::create()); |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | //! Create virtual variable group, which is done normally on initializing file |
---|
| 908 | void CGrid::setVirtualAxisGroup(void) |
---|
| 909 | { |
---|
| 910 | this->setVirtualAxisGroup(CAxisGroup::create()); |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | /*! |
---|
| 914 | \brief Send a message to create a domain on server side |
---|
| 915 | \param[in] id String identity of domain that will be created on server |
---|
| 916 | */ |
---|
| 917 | void CGrid::sendAddDomain(const string& id) |
---|
| 918 | { |
---|
[650] | 919 | CContext* context=CContext::getCurrent(); |
---|
[540] | 920 | |
---|
| 921 | if (! context->hasServer ) |
---|
| 922 | { |
---|
[650] | 923 | CContextClient* client=context->client; |
---|
[540] | 924 | |
---|
[650] | 925 | CEventClient event(this->getType(),EVENT_ID_ADD_DOMAIN); |
---|
[540] | 926 | if (client->isServerLeader()) |
---|
| 927 | { |
---|
[650] | 928 | CMessage msg; |
---|
| 929 | msg<<this->getId(); |
---|
| 930 | msg<<id; |
---|
[595] | 931 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 932 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 933 | event.push(*itRank,1,msg); |
---|
[650] | 934 | client->sendEvent(event); |
---|
[540] | 935 | } |
---|
[650] | 936 | else client->sendEvent(event); |
---|
[540] | 937 | } |
---|
| 938 | } |
---|
| 939 | |
---|
| 940 | /*! |
---|
| 941 | \brief Send a message to create an axis on server side |
---|
| 942 | \param[in] id String identity of axis that will be created on server |
---|
| 943 | */ |
---|
| 944 | void CGrid::sendAddAxis(const string& id) |
---|
| 945 | { |
---|
[650] | 946 | CContext* context=CContext::getCurrent(); |
---|
[540] | 947 | |
---|
| 948 | if (! context->hasServer ) |
---|
| 949 | { |
---|
[650] | 950 | CContextClient* client=context->client; |
---|
[540] | 951 | |
---|
[650] | 952 | CEventClient event(this->getType(),EVENT_ID_ADD_AXIS); |
---|
[540] | 953 | if (client->isServerLeader()) |
---|
| 954 | { |
---|
[650] | 955 | CMessage msg; |
---|
| 956 | msg<<this->getId(); |
---|
| 957 | msg<<id; |
---|
[595] | 958 | const std::list<int>& ranks = client->getRanksServerLeader(); |
---|
| 959 | for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) |
---|
| 960 | event.push(*itRank,1,msg); |
---|
[650] | 961 | client->sendEvent(event); |
---|
[540] | 962 | } |
---|
[650] | 963 | else client->sendEvent(event); |
---|
[540] | 964 | } |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | /*! |
---|
| 968 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 969 | \param[in] event Received event |
---|
| 970 | */ |
---|
| 971 | void CGrid::recvAddDomain(CEventServer& event) |
---|
| 972 | { |
---|
| 973 | |
---|
[650] | 974 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 975 | string id; |
---|
[650] | 976 | *buffer >> id; |
---|
| 977 | get(id)->recvAddDomain(*buffer); |
---|
[540] | 978 | } |
---|
| 979 | |
---|
| 980 | /*! |
---|
| 981 | \brief Receive a message annoucing the creation of a domain on server side |
---|
| 982 | \param[in] buffer Buffer containing message |
---|
| 983 | */ |
---|
| 984 | void CGrid::recvAddDomain(CBufferIn& buffer) |
---|
| 985 | { |
---|
[650] | 986 | string id; |
---|
| 987 | buffer >> id; |
---|
| 988 | addDomain(id); |
---|
[540] | 989 | } |
---|
| 990 | |
---|
| 991 | /*! |
---|
| 992 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 993 | \param[in] event Received event |
---|
| 994 | */ |
---|
| 995 | void CGrid::recvAddAxis(CEventServer& event) |
---|
| 996 | { |
---|
| 997 | |
---|
[650] | 998 | CBufferIn* buffer = event.subEvents.begin()->buffer; |
---|
[540] | 999 | string id; |
---|
[650] | 1000 | *buffer >> id; |
---|
| 1001 | get(id)->recvAddAxis(*buffer); |
---|
[540] | 1002 | } |
---|
| 1003 | |
---|
| 1004 | /*! |
---|
| 1005 | \brief Receive a message annoucing the creation of an axis on server side |
---|
| 1006 | \param[in] buffer Buffer containing message |
---|
| 1007 | */ |
---|
| 1008 | void CGrid::recvAddAxis(CBufferIn& buffer) |
---|
| 1009 | { |
---|
[650] | 1010 | string id; |
---|
| 1011 | buffer >> id; |
---|
| 1012 | addAxis(id); |
---|
[540] | 1013 | } |
---|
| 1014 | |
---|
[551] | 1015 | /*! |
---|
| 1016 | \brief Solve domain and axis references |
---|
| 1017 | As field, domain and axis can refer to other domains or axis. In order to inherit correctly |
---|
| 1018 | all attributes from their parents, they should be processed with this function |
---|
| 1019 | \param[in] apply inherit all attributes of parents (true) |
---|
| 1020 | */ |
---|
[540] | 1021 | void CGrid::solveDomainAxisRefInheritance(bool apply) |
---|
| 1022 | { |
---|
| 1023 | CContext* context = CContext::getCurrent(); |
---|
| 1024 | unsigned int vecSize, i; |
---|
| 1025 | std::vector<StdString>::iterator it, itE; |
---|
| 1026 | setDomainList(); |
---|
| 1027 | it = domList_.begin(); itE = domList_.end(); |
---|
| 1028 | for (; it != itE; ++it) |
---|
| 1029 | { |
---|
| 1030 | CDomain* pDom = CDomain::get(*it); |
---|
| 1031 | if (context->hasClient) |
---|
| 1032 | { |
---|
| 1033 | pDom->solveRefInheritance(apply); |
---|
| 1034 | pDom->solveBaseReference(); |
---|
[631] | 1035 | pDom->solveInheritanceTransformation(); |
---|
[540] | 1036 | if ((!pDom->domain_ref.isEmpty()) && (pDom->name.isEmpty())) |
---|
| 1037 | pDom->name.setValue(pDom->getBaseDomainReference()->getId()); |
---|
| 1038 | } |
---|
| 1039 | } |
---|
| 1040 | |
---|
| 1041 | setAxisList(); |
---|
| 1042 | it = axisList_.begin(); itE = axisList_.end(); |
---|
| 1043 | for (; it != itE; ++it) |
---|
| 1044 | { |
---|
| 1045 | CAxis* pAxis = CAxis::get(*it); |
---|
| 1046 | if (context->hasClient) |
---|
| 1047 | { |
---|
| 1048 | pAxis->solveRefInheritance(apply); |
---|
| 1049 | pAxis->solveBaseReference(); |
---|
[619] | 1050 | pAxis->solveInheritanceTransformation(); |
---|
[540] | 1051 | if ((!pAxis->axis_ref.isEmpty()) && (pAxis->name.isEmpty())) |
---|
| 1052 | pAxis->name.setValue(pAxis->getBaseAxisReference()->getId()); |
---|
| 1053 | } |
---|
| 1054 | } |
---|
| 1055 | } |
---|
| 1056 | |
---|
[619] | 1057 | bool CGrid::isTransformed() |
---|
| 1058 | { |
---|
| 1059 | return isTransformed_; |
---|
| 1060 | } |
---|
| 1061 | |
---|
| 1062 | void CGrid::setTransformed() |
---|
| 1063 | { |
---|
| 1064 | isTransformed_ = true; |
---|
| 1065 | } |
---|
| 1066 | |
---|
[620] | 1067 | CGridTransformation* CGrid::getTransformations() |
---|
[619] | 1068 | { |
---|
[620] | 1069 | return transformations_; |
---|
[619] | 1070 | } |
---|
| 1071 | |
---|
[632] | 1072 | void CGrid::transformGrid(CGrid* transformGridSrc) |
---|
[619] | 1073 | { |
---|
[632] | 1074 | if (isTransformed()) return; |
---|
| 1075 | setTransformed(); |
---|
| 1076 | if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) |
---|
[619] | 1077 | { |
---|
[632] | 1078 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[619] | 1079 | << "Two grids have different dimension size" |
---|
[650] | 1080 | << "Dimension of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl |
---|
| 1081 | << "Dimension of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); |
---|
[619] | 1082 | } |
---|
| 1083 | else |
---|
| 1084 | { |
---|
| 1085 | int ssize = axis_domain_order.numElements(); |
---|
| 1086 | for (int i = 0; i < ssize; ++i) |
---|
[632] | 1087 | if (axis_domain_order(i) != (transformGridSrc->axis_domain_order)(i)) |
---|
| 1088 | ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", |
---|
[650] | 1089 | << "Grids " << this->getId() << " and " << transformGridSrc->getId() |
---|
[619] | 1090 | << " don't have elements in the same order"); |
---|
| 1091 | } |
---|
| 1092 | |
---|
[632] | 1093 | transformations_ = new CGridTransformation(this, transformGridSrc); |
---|
[622] | 1094 | transformations_->computeAll(); |
---|
[623] | 1095 | |
---|
| 1096 | // Ok, now need to compute index of grid source |
---|
[632] | 1097 | transformGridSrc->checkMaskIndex(false); |
---|
[619] | 1098 | } |
---|
| 1099 | |
---|
[551] | 1100 | /*! |
---|
| 1101 | \brief Get the list of domain pointers |
---|
| 1102 | \return list of domain pointers |
---|
| 1103 | */ |
---|
[540] | 1104 | std::vector<CDomain*> CGrid::getDomains() |
---|
| 1105 | { |
---|
| 1106 | std::vector<CDomain*> domList; |
---|
| 1107 | if (!domList_.empty()) |
---|
| 1108 | { |
---|
| 1109 | for (int i = 0; i < domList_.size(); ++i) domList.push_back(CDomain::get(domList_[i])); |
---|
| 1110 | } |
---|
| 1111 | return domList; |
---|
| 1112 | } |
---|
| 1113 | |
---|
[551] | 1114 | /*! |
---|
| 1115 | \brief Get the list of axis pointers |
---|
| 1116 | \return list of axis pointers |
---|
| 1117 | */ |
---|
[540] | 1118 | std::vector<CAxis*> CGrid::getAxis() |
---|
| 1119 | { |
---|
| 1120 | std::vector<CAxis*> aList; |
---|
| 1121 | if (!axisList_.empty()) |
---|
| 1122 | for (int i =0; i < axisList_.size(); ++i) aList.push_back(CAxis::get(axisList_[i])); |
---|
| 1123 | |
---|
| 1124 | return aList; |
---|
| 1125 | } |
---|
| 1126 | |
---|
[551] | 1127 | /*! |
---|
| 1128 | \brief Set domain(s) of a grid from a list |
---|
| 1129 | \param[in] domains list of domains |
---|
| 1130 | */ |
---|
[540] | 1131 | void CGrid::setDomainList(const std::vector<CDomain*> domains) |
---|
| 1132 | { |
---|
| 1133 | if (isDomListSet) return; |
---|
| 1134 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 1135 | if (!domains.empty() && domList.empty()) domList = domains; |
---|
| 1136 | if (!domList.empty()) |
---|
| 1137 | { |
---|
| 1138 | int sizeDom = domList.size(); |
---|
| 1139 | domList_.resize(sizeDom); |
---|
[650] | 1140 | for (int i = 0; i < sizeDom; ++i) |
---|
[540] | 1141 | { |
---|
| 1142 | domList_[i] = domList[i]->getId(); |
---|
| 1143 | } |
---|
| 1144 | isDomListSet = true; |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | } |
---|
| 1148 | |
---|
[551] | 1149 | /*! |
---|
| 1150 | \brief Set axis(s) of a grid from a list |
---|
| 1151 | \param[in] axis list of axis |
---|
| 1152 | */ |
---|
[540] | 1153 | void CGrid::setAxisList(const std::vector<CAxis*> axis) |
---|
| 1154 | { |
---|
| 1155 | if (isAxisListSet) return; |
---|
| 1156 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 1157 | if (!axis.empty() && aList.empty()) aList = axis; |
---|
| 1158 | if (!aList.empty()) |
---|
| 1159 | { |
---|
| 1160 | int sizeAxis = aList.size(); |
---|
| 1161 | axisList_.resize(sizeAxis); |
---|
| 1162 | for (int i = 0; i < sizeAxis; ++i) |
---|
| 1163 | { |
---|
| 1164 | axisList_[i] = aList[i]->getId(); |
---|
| 1165 | } |
---|
| 1166 | isAxisListSet = true; |
---|
| 1167 | } |
---|
| 1168 | } |
---|
| 1169 | |
---|
[551] | 1170 | /*! |
---|
| 1171 | \brief Get list of id of domains |
---|
| 1172 | \return id list of domains |
---|
| 1173 | */ |
---|
[540] | 1174 | std::vector<StdString> CGrid::getDomainList() |
---|
| 1175 | { |
---|
| 1176 | setDomainList(); |
---|
| 1177 | return domList_; |
---|
| 1178 | } |
---|
| 1179 | |
---|
[551] | 1180 | /*! |
---|
| 1181 | \brief Get list of id of axis |
---|
| 1182 | \return id list of axis |
---|
| 1183 | */ |
---|
[540] | 1184 | std::vector<StdString> CGrid::getAxisList() |
---|
| 1185 | { |
---|
| 1186 | setAxisList(); |
---|
| 1187 | return axisList_; |
---|
| 1188 | } |
---|
| 1189 | |
---|
| 1190 | void CGrid::sendAllDomains() |
---|
| 1191 | { |
---|
| 1192 | std::vector<CDomain*> domList = this->getVirtualDomainGroup()->getAllChildren(); |
---|
| 1193 | int dSize = domList.size(); |
---|
| 1194 | for (int i = 0; i < dSize; ++i) |
---|
| 1195 | { |
---|
| 1196 | sendAddDomain(domList[i]->getId()); |
---|
| 1197 | domList[i]->sendAllAttributesToServer(); |
---|
| 1198 | } |
---|
| 1199 | } |
---|
| 1200 | |
---|
| 1201 | void CGrid::sendAllAxis() |
---|
| 1202 | { |
---|
| 1203 | std::vector<CAxis*> aList = this->getVirtualAxisGroup()->getAllChildren(); |
---|
| 1204 | int aSize = aList.size(); |
---|
| 1205 | |
---|
| 1206 | for (int i = 0; i < aSize; ++i) |
---|
| 1207 | { |
---|
| 1208 | sendAddAxis(aList[i]->getId()); |
---|
| 1209 | aList[i]->sendAllAttributesToServer(); |
---|
| 1210 | } |
---|
| 1211 | } |
---|
| 1212 | |
---|
[650] | 1213 | void CGrid::parse(xml::CXMLNode& node) |
---|
[540] | 1214 | { |
---|
| 1215 | SuperClass::parse(node); |
---|
[567] | 1216 | |
---|
[551] | 1217 | // List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) |
---|
| 1218 | std::vector<bool> order; |
---|
[540] | 1219 | |
---|
| 1220 | if (node.goToChildElement()) |
---|
| 1221 | { |
---|
| 1222 | StdString domainName("domain"); |
---|
| 1223 | StdString axisName("axis"); |
---|
| 1224 | do |
---|
| 1225 | { |
---|
| 1226 | if (node.getElementName() == domainName) { |
---|
[551] | 1227 | order.push_back(true); |
---|
[540] | 1228 | this->getVirtualDomainGroup()->parseChild(node); |
---|
| 1229 | } |
---|
| 1230 | if (node.getElementName() == axisName) { |
---|
[551] | 1231 | order.push_back(false); |
---|
[540] | 1232 | this->getVirtualAxisGroup()->parseChild(node); |
---|
| 1233 | } |
---|
[650] | 1234 | } while (node.goToNextElement()); |
---|
[540] | 1235 | node.goToParentElement(); |
---|
| 1236 | } |
---|
| 1237 | |
---|
[551] | 1238 | if (!order.empty()) |
---|
[540] | 1239 | { |
---|
[551] | 1240 | int sizeOrd = order.size(); |
---|
[575] | 1241 | axis_domain_order.resize(sizeOrd); |
---|
[540] | 1242 | for (int i = 0; i < sizeOrd; ++i) |
---|
| 1243 | { |
---|
[575] | 1244 | axis_domain_order(i) = order[i]; |
---|
[540] | 1245 | } |
---|
| 1246 | } |
---|
| 1247 | |
---|
| 1248 | setDomainList(); |
---|
| 1249 | setAxisList(); |
---|
| 1250 | } |
---|
[335] | 1251 | } // namespace xios |
---|