Changeset 1869 for XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp
- Timestamp:
- 04/15/20 13:23:39 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp
r1853 r1869 274 274 TRY 275 275 { 276 if (checkAttributes_done_) return ; 277 276 278 CContext* context=CContext::getCurrent(); 277 279 … … 318 320 if (!this->value.isEmpty()) 319 321 { 320 // Avoid this check at writing because it fails in case of a hole 321 if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) 322 { 323 StdSize true_size = value.numElements(); 324 if (this->n.getValue() != true_size) 325 ERROR("CAxis::checkAttributes(void)", 326 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 327 << "The axis is wrongly defined, attribute 'value' has a different size (" << true_size 328 << ") than the one defined by the \'size\' attribute (" << n.getValue() << ")."); 329 } 322 StdSize true_size = value.numElements(); 323 if (this->n.getValue() != true_size) 324 ERROR("CAxis::checkAttributes(void)", 325 << "[ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] " 326 << "The axis is wrongly defined, attribute 'value' has a different size (" << true_size 327 << ") than the one defined by the \'size\' attribute (" << n.getValue() << ")."); 330 328 this->hasValue = true; 331 329 } 332 330 333 331 this->checkBounds(); 334 335 if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) 336 { 337 this->checkMask(); 338 this->checkData(); 339 this->checkLabel(); 340 } 332 this->checkMask(); 333 this->checkData(); 334 this->checkLabel(); 335 336 checkAttributes_done_ = true ; 341 337 } 342 338 CATCH_DUMP_ATTR … … 522 518 Therefore, we should recheck them. 523 519 */ 520 // ym : obsolete to be removed 524 521 void CAxis::checkAttributesOnClientAfterTransformation(const std::vector<int>& globalDim, int orderPositionInGrid, 525 522 CServerDistributionDescription::ServerDistributionType distType) … … 531 528 if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) 532 529 { 530 /* suppressed because of interface changed 533 531 if (orderPositionInGrid == CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), distType)) 534 532 computeConnectedClients(globalDim, orderPositionInGrid, distType); 535 533 else if (index.numElements() != n_glo) computeConnectedClients(globalDim, orderPositionInGrid, CServerDistributionDescription::ROOT_DISTRIBUTION); 534 */ 536 535 } 537 536 … … 594 593 \param [in] distType distribution type of the server. For now, we only have band distribution. 595 594 */ 596 void CAxis::computeConnectedClients(const std::vector<int>& globalDim, int orderPositionInGrid, 597 CServerDistributionDescription::ServerDistributionType distType) 598 TRY 599 { 595 void CAxis::computeConnectedClients(CContextClient* client, const std::vector<int>& globalDim, int orderPositionInGrid) 596 TRY 597 { 598 if (computeConnectedClients_done_.count(client)!=0) return ; 599 else computeConnectedClients_done_.insert(client) ; 600 600 601 CContext* context = CContext::getCurrent(); 601 602 set<int> listNbServer ; 603 604 for (auto client : clients) 605 { 606 int nbServer = client->serverSize; 607 int range, clientSize = client->clientSize; 608 int rank = client->clientRank; 609 610 if (listNbServer.find(nbServer)==listNbServer.end()) 611 { 612 listNbServer.insert(nbServer) ; 613 614 if (connectedServerRank_.find(nbServer) != connectedServerRank_.end()) 615 { 616 nbSenders.erase(nbServer); 617 connectedServerRank_.erase(nbServer); 618 } 619 620 size_t ni = this->n.getValue(); 621 size_t ibegin = this->begin.getValue(); 622 size_t nbIndex = index.numElements(); 623 624 // First of all, we should compute the mapping of the global index and local index of the current client 625 if (globalLocalIndexMap_.empty()) 626 { 627 for (size_t idx = 0; idx < nbIndex; ++idx) 628 { 629 globalLocalIndexMap_[index(idx)] = idx; 630 } 631 } 632 633 // Calculate the compressed index if any 634 // std::set<int> writtenInd; 635 // if (isCompressible_) 636 // { 637 // for (int idx = 0; idx < data_index.numElements(); ++idx) 638 // { 639 // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); 640 // 641 // if (ind >= 0 && ind < ni && mask(ind)) 642 // { 643 // ind += ibegin; 644 // writtenInd.insert(ind); 645 // } 646 // } 647 // } 648 649 // Compute the global index of the current client (process) hold 650 std::vector<int> nGlobAxis(1); 651 nGlobAxis[0] = n_glo.getValue(); 652 653 size_t globalSizeIndex = 1, indexBegin, indexEnd; 654 for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; 655 indexBegin = 0; 656 if (globalSizeIndex <= clientSize) 657 { 658 indexBegin = rank%globalSizeIndex; 659 indexEnd = indexBegin; 660 } 661 else 662 { 663 for (int i = 0; i < clientSize; ++i) 664 { 665 range = globalSizeIndex / clientSize; 666 if (i < (globalSizeIndex%clientSize)) ++range; 667 if (i == client->clientRank) break; 668 indexBegin += range; 669 } 670 indexEnd = indexBegin + range - 1; 671 } 672 673 CArray<size_t,1> globalIndex(index.numElements()); 674 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 675 globalIndex(idx) = index(idx); 676 677 // Describe the distribution of server side 678 679 CServerDistributionDescription serverDescription(nGlobAxis, nbServer, distType); 680 681 std::vector<int> serverZeroIndex; 682 serverZeroIndex = serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t&,size_t&>(indexBegin, indexEnd), 0); 683 684 std::list<int> serverZeroIndexLeader; 685 std::list<int> serverZeroIndexNotLeader; 686 CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); 687 for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 688 *it = serverZeroIndex[*it]; 689 690 // Find out the connection between client and server side 691 CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); 692 clientServerMap->computeServerIndexMapping(globalIndex, nbServer); 693 CClientServerMapping::GlobalIndexMap& globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); 694 695 indSrv_[nbServer].swap(globalIndexAxisOnServer); 696 697 if (distType==CServerDistributionDescription::ROOT_DISTRIBUTION) 698 { 699 for(int i=1; i<nbServer; ++i) indSrv_[nbServer].insert(pair<int, vector<size_t> >(i,indSrv_[nbServer][0]) ) ; 700 serverZeroIndexLeader.clear() ; 701 } 702 703 CClientServerMapping::GlobalIndexMap::const_iterator it = indSrv_[nbServer].begin(), 704 ite = indSrv_[nbServer].end(); 705 706 for (it = indSrv_[nbServer].begin(); it != ite; ++it) connectedServerRank_[nbServer].push_back(it->first); 707 708 for (std::list<int>::const_iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 709 connectedServerRank_[nbServer].push_back(*it); 710 711 // Even if a client has no index, it must connect to at least one server and 712 // send an "empty" data to this server 713 if (connectedServerRank_[nbServer].empty()) 714 connectedServerRank_[nbServer].push_back(client->clientRank % client->serverSize); 715 716 nbSenders[nbServer] = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[nbServer]); 717 718 delete clientServerMap; 719 } 602 CServerDistributionDescription::ServerDistributionType distType ; 603 int defaultDistributedPos = CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), CServerDistributionDescription::BAND_DISTRIBUTION) ; 604 605 if (orderPositionInGrid == defaultDistributedPos) distType = CServerDistributionDescription::BAND_DISTRIBUTION ; 606 else if (index.numElements() != n_glo) distType = CServerDistributionDescription::ROOT_DISTRIBUTION ; 607 else return ; 608 609 int nbServer = client->serverSize; 610 int range, clientSize = client->clientSize; 611 int rank = client->clientRank; 612 613 if (listNbServer_.count(nbServer) == 0) 614 { 615 listNbServer_.insert(nbServer) ; 616 617 if (connectedServerRank_.find(nbServer) != connectedServerRank_.end()) 618 { 619 nbSenders.erase(nbServer); 620 connectedServerRank_.erase(nbServer); 621 } 622 623 size_t ni = this->n.getValue(); 624 size_t ibegin = this->begin.getValue(); 625 size_t nbIndex = index.numElements(); 626 627 // First of all, we should compute the mapping of the global index and local index of the current client 628 if (globalLocalIndexMap_.empty()) 629 { 630 for (size_t idx = 0; idx < nbIndex; ++idx) 631 { 632 globalLocalIndexMap_[index(idx)] = idx; 633 } 634 } 635 636 // Calculate the compressed index if any 637 // std::set<int> writtenInd; 638 // if (isCompressible_) 639 // { 640 // for (int idx = 0; idx < data_index.numElements(); ++idx) 641 // { 642 // int ind = CDistributionClient::getAxisIndex(data_index(idx), data_begin, ni); 643 // 644 // if (ind >= 0 && ind < ni && mask(ind)) 645 // { 646 // ind += ibegin; 647 // writtenInd.insert(ind); 648 // } 649 // } 650 // } 651 652 // Compute the global index of the current client (process) hold 653 std::vector<int> nGlobAxis(1); 654 nGlobAxis[0] = n_glo.getValue(); 655 656 size_t globalSizeIndex = 1, indexBegin, indexEnd; 657 for (int i = 0; i < nGlobAxis.size(); ++i) globalSizeIndex *= nGlobAxis[i]; 658 indexBegin = 0; 659 if (globalSizeIndex <= clientSize) 660 { 661 indexBegin = rank%globalSizeIndex; 662 indexEnd = indexBegin; 663 } 664 else 665 { 666 for (int i = 0; i < clientSize; ++i) 667 { 668 range = globalSizeIndex / clientSize; 669 if (i < (globalSizeIndex%clientSize)) ++range; 670 if (i == client->clientRank) break; 671 indexBegin += range; 672 } 673 indexEnd = indexBegin + range - 1; 674 } 675 676 CArray<size_t,1> globalIndex(index.numElements()); 677 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 678 globalIndex(idx) = index(idx); 679 680 // Describe the distribution of server side 681 682 CServerDistributionDescription serverDescription(nGlobAxis, nbServer, distType); 683 684 std::vector<int> serverZeroIndex; 685 serverZeroIndex = serverDescription.computeServerGlobalIndexInRange(std::make_pair<size_t&,size_t&>(indexBegin, indexEnd), 0); 686 687 std::list<int> serverZeroIndexLeader; 688 std::list<int> serverZeroIndexNotLeader; 689 CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); 690 for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 691 *it = serverZeroIndex[*it]; 692 693 // Find out the connection between client and server side 694 CClientServerMapping* clientServerMap = new CClientServerMappingDistributed(serverDescription.getGlobalIndexRange(), client->intraComm); 695 clientServerMap->computeServerIndexMapping(globalIndex, nbServer); 696 CClientServerMapping::GlobalIndexMap& globalIndexAxisOnServer = clientServerMap->getGlobalIndexOnServer(); 697 698 indSrv_[nbServer].swap(globalIndexAxisOnServer); 699 700 if (distType==CServerDistributionDescription::ROOT_DISTRIBUTION) 701 { 702 for(int i=1; i<nbServer; ++i) indSrv_[nbServer].insert(pair<int, vector<size_t> >(i,indSrv_[nbServer][0]) ) ; 703 serverZeroIndexLeader.clear() ; 704 } 705 706 CClientServerMapping::GlobalIndexMap::const_iterator it = indSrv_[nbServer].begin(), 707 ite = indSrv_[nbServer].end(); 708 709 for (it = indSrv_[nbServer].begin(); it != ite; ++it) connectedServerRank_[nbServer].push_back(it->first); 710 711 for (std::list<int>::const_iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 712 connectedServerRank_[nbServer].push_back(*it); 713 714 // Even if a client has no index, it must connect to at least one server and 715 // send an "empty" data to this server 716 if (connectedServerRank_[nbServer].empty()) 717 connectedServerRank_[nbServer].push_back(client->clientRank % client->serverSize); 718 719 nbSenders[nbServer] = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[nbServer]); 720 721 delete clientServerMap; 720 722 } 721 723 } … … 1431 1433 CATCH_DUMP_ATTR 1432 1434 1435 /*! 1436 \brief Check if a axis is completed 1437 Before make any axis processing, we must be sure that all axis informations have 1438 been sent, for exemple when reading a grid in a file or when grid elements are sent by an 1439 other context (coupling). So all direct reference of the axis (axis_ref) must be also completed 1440 \return true if axis and axis reference are completed 1441 */ 1442 bool CAxis::checkIfCompleted(void) 1443 { 1444 if (hasDirectAxisReference()) if (!getDirectAxisReference()->checkIfCompleted()) return false; 1445 return isCompleted_ ; 1446 } 1447 1448 /*! 1449 \brief Set a axis as completed 1450 When all information about a axis have been received, the axis is tagged as completed and is 1451 suitable for processing 1452 */ 1453 void CAxis::setCompleted(void) 1454 { 1455 if (hasDirectAxisReference()) getDirectAxisReference()->setCompleted() ; 1456 isCompleted_=true ; 1457 } 1458 1459 /*! 1460 \brief Set a axis as uncompleted 1461 When informations about a axis are expected from a grid reading from file or coupling, the axis is 1462 tagged as uncompleted and is not suitable for processing 1463 */ 1464 void CAxis::setUncompleted(void) 1465 { 1466 if (hasDirectAxisReference()) getDirectAxisReference()->setUncompleted() ; 1467 isCompleted_=false ; 1468 } 1469 1470 1471 1433 1472 /*! 1434 1473 * Go through the hierarchy to find the axis from which the transformations must be inherited
Note: See TracChangeset
for help on using the changeset viewer.