Changeset 1263
- Timestamp:
- 09/12/17 16:35:36 (7 years ago)
- Location:
- XIOS/dev/XIOS_DEV_CMIP6/src/node
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/dev/XIOS_DEV_CMIP6/src/node/field.cpp
r1250 r1263 132 132 CContext* context = CContext::getCurrent(); 133 133 CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient(); 134 int receiverSize = client->serverSize; 134 135 135 136 CEventClient event(getType(), EVENT_ID_UPDATE_DATA); … … 175 176 176 177 list_msg.back() << getId() << data_tmp; 177 event.push(rank, grid->nbSenders[ client][rank], list_msg.back());178 event.push(rank, grid->nbSenders[receiverSize][rank], list_msg.back()); 178 179 } 179 180 client->sendEvent(event); -
XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.cpp
r1250 r1263 146 146 147 147 /*! 148 * Compute the minimum buffer size required to send the data to the server(s).149 * 148 * Compute the minimum buffer size required to send the data. 149 * \param client contextClient used to determine the size of connected receivers 150 150 * \param id the id used to tag the data 151 * \return A map associating the se rver rank with its minimum buffer size.151 * \return A map associating the sender rank with its minimum buffer size. 152 152 */ 153 153 std::map<int, StdSize> CGrid::getDataBufferSize(CContextClient* client, const std::string& id /*= ""*/) … … 176 176 177 177 std::map<int, StdSize> dataSizes; 178 std::map<int, size_t>::const_iterator itEnd = connectedDataSize_[client].end(); 179 for (size_t k = 0; k < connectedServerRank_[client].size(); ++k) 178 int receiverSize = client->serverSize; 179 std::map<int, size_t>::const_iterator itEnd = connectedDataSize_[receiverSize].end(); 180 for (size_t k = 0; k < connectedServerRank_[receiverSize].size(); ++k) 180 181 { 181 int rank = connectedServerRank_[ client][k];182 std::map<int, size_t>::const_iterator it = connectedDataSize_[ client].find(rank);182 int rank = connectedServerRank_[receiverSize][k]; 183 std::map<int, size_t>::const_iterator it = connectedDataSize_[receiverSize].find(rank); 183 184 size_t count = (it != itEnd) ? it->second : 0; 184 185 … … 315 316 { 316 317 CContext* context = CContext::getCurrent(); 317 // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1;318 318 int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 0) : 1; 319 319 nbSrvPools = 1; … … 658 658 CContext* context = CContext::getCurrent(); 659 659 660 // This needs to change one day 661 int nbSrvPools = 1; 662 for (int p = 0; p < nbSrvPools; ++p) 660 CContextClient* client = context->client; // Here it's not important which contextClient to recuperate 661 int rank = client->clientRank; 662 663 clientDistribution_ = new CDistributionClient(rank, this); 664 // Get local data index on client 665 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); 666 int nbStoreIndex = storeIndex_client.numElements(); 667 for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 668 669 if (0 == serverDistribution_) isDataDistributed_= clientDistribution_->isDataDistributed(); 670 else 663 671 { 664 CContextClient* client = (context->hasServer) ? (context->hasClient ? context->clientPrimServer[p] : context->client) : context->client; 665 int rank = client->clientRank; 666 667 clientDistribution_ = new CDistributionClient(rank, this); 668 // Get local data index on client 669 storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); 670 int nbStoreIndex = storeIndex_client.numElements(); 671 for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 672 673 if (0 == serverDistribution_) isDataDistributed_= clientDistribution_->isDataDistributed(); 674 else 675 { 676 // Mapping global index received from clients to the storeIndex_client 677 CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution_->getGlobalDataIndexOnClient(); 678 CDistributionClient::GlobalLocalDataMap::const_iterator itGloe = globalDataIndex.end(); 679 map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClient.begin(), 680 ite = outGlobalIndexFromClient.end(), it; 681 682 for (it = itb; it != ite; ++it) 672 // Mapping global index received from clients to the storeIndex_client 673 CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution_->getGlobalDataIndexOnClient(); 674 CDistributionClient::GlobalLocalDataMap::const_iterator itGloe = globalDataIndex.end(); 675 map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClient.begin(), 676 ite = outGlobalIndexFromClient.end(), it; 677 678 for (it = itb; it != ite; ++it) 679 { 680 int rank = it->first; 681 CArray<size_t,1>& globalIndex = outGlobalIndexFromClient[rank]; 682 outLocalIndexStoreOnClient.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); 683 CArray<size_t,1>& localIndex = outLocalIndexStoreOnClient[rank]; 684 size_t nbIndex = 0; 685 686 // Keep this code for this moment but it should be removed (or moved to DEBUG) to improve performance 687 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 683 688 { 684 int rank = it->first; 685 CArray<size_t,1>& globalIndex = outGlobalIndexFromClient[rank]; 686 outLocalIndexStoreOnClient.insert(make_pair(rank, CArray<size_t,1>(globalIndex.numElements()))); 687 CArray<size_t,1>& localIndex = outLocalIndexStoreOnClient[rank]; 688 size_t nbIndex = 0; 689 690 // Keep this code for this moment but it should be removed (or moved to DEBUG) to improve performance 691 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 689 if (itGloe != globalDataIndex.find(globalIndex(idx))) 692 690 { 693 if (itGloe != globalDataIndex.find(globalIndex(idx))) 694 { 695 ++nbIndex; 696 } 691 ++nbIndex; 697 692 } 698 699 700 if (doGridHaveDataDistributed(client) && (nbIndex != localIndex.numElements())) 701 ERROR("void CGrid::computeClientIndex()", 702 << "Number of local index on client is different from number of received global index" 703 << "Rank of sent client " << rank <<"." 704 << "Number of local index " << nbIndex << ". " 705 << "Number of received global index " << localIndex.numElements() << "."); 706 707 nbIndex = 0; 708 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 693 } 694 695 if (doGridHaveDataDistributed(client) && (nbIndex != localIndex.numElements())) 696 ERROR("void CGrid::computeClientIndex()", 697 << "Number of local index on client is different from number of received global index" 698 << "Rank of sent client " << rank <<"." 699 << "Number of local index " << nbIndex << ". " 700 << "Number of received global index " << localIndex.numElements() << "."); 701 702 nbIndex = 0; 703 for (size_t idx = 0; idx < globalIndex.numElements(); ++idx) 704 { 705 if (itGloe != globalDataIndex.find(globalIndex(idx))) 709 706 { 710 if (itGloe != globalDataIndex.find(globalIndex(idx))) 711 { 712 localIndex(idx) = globalDataIndex[globalIndex(idx)]; 713 } 707 localIndex(idx) = globalDataIndex[globalIndex(idx)]; 714 708 } 715 } 709 } 716 710 } 717 711 } … … 719 713 720 714 /*! 721 Compute the connected clients and index to send to these clients. 722 Each client can connect to a pool of other clients, each of which can have a piece of information of a grid 715 Compute connected receivers and indexes to be sent to these receivers. 723 716 */ 724 717 void CGrid::computeConnectedClients() 725 718 { 726 719 CContext* context = CContext::getCurrent(); 727 int nbSrvPools = (context-> hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1;720 int nbSrvPools = (context->clientPrimServer.size() == 0) ? 1 : context->clientPrimServer.size(); 728 721 connectedServerRank_.clear(); 729 722 connectedDataSize_.clear(); … … 733 726 for (int p = 0; p < nbSrvPools; ++p) 734 727 { 735 CContextClient* client = (context-> hasServer) ? context->clientPrimServer[p] : context->client;736 737 connectedServerRank_[client].clear();738 739 if ( !doGridHaveDataDistributed(client))728 CContextClient* client = (context->clientPrimServer.size() == 0) ? context->client : context->clientPrimServer[p]; 729 int receiverSize = client->serverSize; 730 // connectedServerRank_[client].clear(); 731 732 if (connectedServerRank_.find(receiverSize) == connectedServerRank_.end()) 740 733 { 741 if (client->isServerLeader()) 742 { 743 size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); 744 const std::list<int>& ranks = client->getRanksServerLeader(); 745 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 734 if (!doGridHaveDataDistributed(client)) 735 { 736 if (client->isServerLeader()) 746 737 { 747 connectedServerRank_[client].push_back(*itRank); 748 connectedDataSize_[client][*itRank] = ssize; 738 size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); 739 const std::list<int>& ranks = client->getRanksServerLeader(); 740 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 741 { 742 connectedServerRank_[receiverSize].push_back(*itRank); 743 connectedDataSize_[receiverSize][*itRank] = ssize; 744 } 749 745 } 750 } 751 return; 746 return; 747 } 748 749 // Compute mapping between client and server 750 std::vector<boost::unordered_map<size_t,std::vector<int> > > indexServerOnElement; 751 CServerDistributionDescription serverDistributionDescription(getGlobalDimension(), client->serverSize); 752 std::vector<int> serverZeroIndex = serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, 753 client->clientRank, 754 client->clientSize, 755 axis_domain_order, 756 getDistributedDimension()); 757 758 // Even if servers have no index, they must received something from client 759 // We only use several client to send "empty" message to these servers 760 std::list<int> serverZeroIndexLeader; 761 std::list<int> serverZeroIndexNotLeader; 762 CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); 763 for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 764 *it = serverZeroIndex[*it]; 765 766 if (globalIndexOnServer_.find(receiverSize) == globalIndexOnServer_.end()) 767 computeIndexByElement(indexServerOnElement, client, globalIndexOnServer_[receiverSize]); 768 769 const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 770 CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; 771 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 772 itbGlobalMap = globalIndexOnServer_[receiverSize].begin(); 773 iteGlobalMap = globalIndexOnServer_[receiverSize].end(); 774 775 for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) 776 { 777 int serverRank = itGlobalMap->first; 778 int indexSize = itGlobalMap->second.size(); 779 const std::vector<size_t>& indexVec = itGlobalMap->second; 780 for (int idx = 0; idx < indexSize; ++idx) 781 { 782 itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); 783 if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) 784 { 785 if (connectedDataSize_[receiverSize].end() == connectedDataSize_[receiverSize].find(serverRank)) 786 connectedDataSize_[receiverSize][serverRank] = 1; 787 else 788 ++connectedDataSize_[receiverSize][serverRank]; 789 } 790 } 791 } 792 793 // Connected servers which really have index 794 for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { 795 connectedServerRank_[receiverSize].push_back(itGlobalMap->first); 796 } 797 798 // Connected servers which have no index at all 799 for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 800 connectedServerRank_[receiverSize].push_back(*it); 801 802 // Even if a client has no index, it must connect to at least one server and 803 // send an "empty" data to this server 804 if (connectedServerRank_[receiverSize].empty()) 805 connectedServerRank_[receiverSize].push_back(client->clientRank % client->serverSize); 806 807 nbSenders[receiverSize] = clientServerMap_->computeConnectedClients(receiverSize, client->clientSize, client->intraComm, connectedServerRank_[receiverSize]); 752 808 } 753 754 // Compute mapping between client and server755 std::vector<boost::unordered_map<size_t,std::vector<int> > > indexServerOnElement;756 CServerDistributionDescription serverDistributionDescription(getGlobalDimension(), client->serverSize);757 std::vector<int> serverZeroIndex = serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement,758 client->clientRank,759 client->clientSize,760 axis_domain_order,761 getDistributedDimension());762 763 // Even if servers have no index, they must received something from client764 // We only use several client to send "empty" message to these servers765 std::list<int> serverZeroIndexLeader;766 std::list<int> serverZeroIndexNotLeader;767 CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader);768 for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it)769 *it = serverZeroIndex[*it];770 771 computeIndexByElement(indexServerOnElement, globalIndexOnServer_[client]);772 773 const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer();774 CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap;775 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap;776 itbGlobalMap = globalIndexOnServer_[client].begin();777 iteGlobalMap = globalIndexOnServer_[client].end();778 779 for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap)780 {781 int serverRank = itGlobalMap->first;782 int indexSize = itGlobalMap->second.size();783 const std::vector<size_t>& indexVec = itGlobalMap->second;784 for (int idx = 0; idx < indexSize; ++idx)785 {786 itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]);787 if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap)788 {789 if (connectedDataSize_[client].end() == connectedDataSize_[client].find(serverRank))790 connectedDataSize_[client][serverRank] = 1;791 else792 ++connectedDataSize_[client][serverRank];793 }794 }795 }796 797 // Connected servers which really have index798 for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) {799 connectedServerRank_[client].push_back(itGlobalMap->first);800 }801 802 // Connected servers which have no index at all803 for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it)804 connectedServerRank_[client].push_back(*it);805 806 // Even if a client has no index, it must connect to at least one server and807 // send an "empty" data to this server808 if (connectedServerRank_[client].empty())809 connectedServerRank_[client].push_back(client->clientRank % client->serverSize);810 811 nbSenders[client] = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_[client]);812 809 } 813 810 } … … 847 844 on each element whose size is much smaller than one of whole grid. 848 845 \param [in] indexServerOnElement global index of each element and the rank of server associated with these index 846 \param [in] client contextClient 849 847 \param [out] globalIndexOnServer global index of grid and its corresponding rank of server. 850 848 */ 851 849 void CGrid::computeIndexByElement(const std::vector<boost::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, 850 const CContextClient* client, 852 851 CClientServerMapping::GlobalIndexMap& globalIndexOnServer) 853 852 { 854 CContext* context = CContext::getCurrent(); 855 // int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 856 int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1; 857 nbSrvPools = 1; 858 for (int p = 0; p < nbSrvPools; ++p) 853 int serverSize = client->serverSize; 854 855 std::vector<CDomain*> domList = getDomains(); 856 std::vector<CAxis*> axisList = getAxis(); 857 858 // Some pre-calculations of global index on each element of current grid. 859 int nbElement = axis_domain_order.numElements(); 860 std::vector<CArray<size_t,1> > globalIndexElement(nbElement); 861 int domainIdx = 0, axisIdx = 0, scalarIdx = 0; 862 std::vector<size_t> elementNGlobal(nbElement); 863 elementNGlobal[0] = 1; 864 size_t globalSize = 1; 865 for (int idx = 0; idx < nbElement; ++idx) 859 866 { 860 CContextClient* client = context->hasServer ? context->clientPrimServer[p] : context->client; 861 int serverSize = client->serverSize; 862 std::vector<CDomain*> domList = getDomains(); 863 std::vector<CAxis*> axisList = getAxis(); 864 865 // Some pre-calculations of global index on each element of current grid. 866 int nbElement = axis_domain_order.numElements(); 867 std::vector<CArray<size_t,1> > globalIndexElement(nbElement); 868 int domainIdx = 0, axisIdx = 0, scalarIdx = 0; 869 std::vector<size_t> elementNGlobal(nbElement); 870 elementNGlobal[0] = 1; 871 size_t globalSize = 1; 872 for (int idx = 0; idx < nbElement; ++idx) 867 elementNGlobal[idx] = globalSize; 868 size_t elementSize; 869 size_t elementGlobalSize = 1; 870 if (2 == axis_domain_order(idx)) // This is domain 873 871 { 874 elementNGlobal[idx] = globalSize; 875 size_t elementSize; 876 size_t elementGlobalSize = 1; 877 if (2 == axis_domain_order(idx)) // This is domain 872 elementSize = domList[domainIdx]->i_index.numElements(); 873 globalIndexElement[idx].resize(elementSize); 874 for (int jdx = 0; jdx < elementSize; ++jdx) 878 875 { 879 elementSize = domList[domainIdx]->i_index.numElements(); 880 globalIndexElement[idx].resize(elementSize); 881 for (int jdx = 0; jdx < elementSize; ++jdx) 876 globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); 877 } 878 elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); 879 ++domainIdx; 880 } 881 else if (1 == axis_domain_order(idx)) // This is axis 882 { 883 elementSize = axisList[axisIdx]->index.numElements(); 884 globalIndexElement[idx].resize(elementSize); 885 for (int jdx = 0; jdx < elementSize; ++jdx) 886 { 887 globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); 888 } 889 elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); 890 ++axisIdx; 891 } 892 else // Of course, this is scalar 893 { 894 globalIndexElement[idx].resize(1); 895 globalIndexElement[idx](0) = 0; 896 elementGlobalSize = 1; 897 } 898 globalSize *= elementGlobalSize; 899 } 900 901 std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); 902 std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); 903 CArray<int,1> nbIndexOnServer(serverSize); // Number of distributed global index held by each client for each server 904 // Number of temporary distributed global index held by each client for each server 905 // We have this variable for the case of non-distributed element (often axis) to check the duplicate server rank 906 CArray<int,1> nbIndexOnServerTmp(serverSize); 907 for (int idx = 0; idx < nbElement; ++idx) 908 { 909 nbIndexOnServer = 0; 910 const boost::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; 911 const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; 912 CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); 913 clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); 914 const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); 915 CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), 916 ite = globalIndexElementOnServerMap.end(), it; 917 for (it = itb; it != ite; ++it) 918 { 919 const std::vector<int>& tmp = it->second; 920 nbIndexOnServerTmp = 0; 921 for (int i = 0; i < tmp.size(); ++i) 922 { 923 if (0 == nbIndexOnServerTmp(tmp[i])) ++nbIndexOnServerTmp(tmp[i]); 924 } 925 nbIndexOnServer += nbIndexOnServerTmp; 926 } 927 928 for (int i = 0; i < serverSize; ++i) 929 { 930 if (0 != nbIndexOnServer(i)) 931 { 932 globalElementIndexOnServer[idx][i].resize(nbIndexOnServer(i)); 933 elementOnServer[idx][i] = true; 934 } 935 } 936 937 nbIndexOnServer = 0; 938 for (size_t j = 0; j < globalIndexElementOnServerMap.size(); ++j) 939 { 940 it = globalIndexElementOnServerMap.find(globalIndexElementOnClient(j)); 941 if (it != ite) 942 { 943 const std::vector<int>& tmp = it->second; 944 nbIndexOnServerTmp = 0; 945 for (int i = 0; i < tmp.size(); ++i) 946 { 947 if (0 == nbIndexOnServerTmp(tmp[i])) 882 948 { 883 globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); 884 } 885 elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); 886 ++domainIdx; 887 } 888 else if (1 == axis_domain_order(idx)) // This is axis 889 { 890 elementSize = axisList[axisIdx]->index.numElements(); 891 globalIndexElement[idx].resize(elementSize); 892 for (int jdx = 0; jdx < elementSize; ++jdx) 893 { 894 globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); 895 } 896 elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); 897 ++axisIdx; 898 } 899 else // Of course, this is scalar 900 { 901 globalIndexElement[idx].resize(1); 902 globalIndexElement[idx](0) = 0; 903 elementGlobalSize = 1; 904 } 905 globalSize *= elementGlobalSize; 906 } 907 908 std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); 909 std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); 910 CArray<int,1> nbIndexOnServer(serverSize); // Number of distributed global index held by each client for each server 911 // Number of temporary distributed global index held by each client for each server 912 // We have this variable for the case of non-distributed element (often axis) to check the duplicate server rank 913 CArray<int,1> nbIndexOnServerTmp(serverSize); 914 for (int idx = 0; idx < nbElement; ++idx) 915 { 916 nbIndexOnServer = 0; 917 const boost::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; 918 const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; 919 CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); 920 clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); 921 const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); 922 CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), 923 ite = globalIndexElementOnServerMap.end(), it; 924 for (it = itb; it != ite; ++it) 925 { 926 const std::vector<int>& tmp = it->second; 927 nbIndexOnServerTmp = 0; 928 for (int i = 0; i < tmp.size(); ++i) 929 { 930 if (0 == nbIndexOnServerTmp(tmp[i])) ++nbIndexOnServerTmp(tmp[i]); 931 } 932 nbIndexOnServer += nbIndexOnServerTmp; 933 } 934 935 for (int i = 0; i < serverSize; ++i) 936 { 937 if (0 != nbIndexOnServer(i)) 938 { 939 globalElementIndexOnServer[idx][i].resize(nbIndexOnServer(i)); 940 elementOnServer[idx][i] = true; 949 globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer(tmp[i])] = it->first; 950 ++nbIndexOnServerTmp(tmp[i]); 941 951 } 942 952 } 943 944 nbIndexOnServer = 0; 945 for (size_t j = 0; j < globalIndexElementOnServerMap.size(); ++j) 946 { 947 it = globalIndexElementOnServerMap.find(globalIndexElementOnClient(j)); 948 if (it != ite) 949 { 950 const std::vector<int>& tmp = it->second; 951 nbIndexOnServerTmp = 0; 952 for (int i = 0; i < tmp.size(); ++i) 953 { 954 if (0 == nbIndexOnServerTmp(tmp[i])) 955 { 956 globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer(tmp[i])] = it->first; 957 ++nbIndexOnServerTmp(tmp[i]); 958 } 959 } 960 nbIndexOnServer += nbIndexOnServerTmp; 961 } 953 nbIndexOnServer += nbIndexOnServerTmp; 962 954 } 963 955 } 964 965 // Determine server which contain global source index 966 std::vector<bool> intersectedProc(serverSize, true); 956 } 957 958 // Determine server which contain global source index 959 std::vector<bool> intersectedProc(serverSize, true); 960 for (int idx = 0; idx < nbElement; ++idx) 961 { 962 std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), 963 intersectedProc.begin(), intersectedProc.begin(), 964 std::logical_and<bool>()); 965 } 966 967 std::vector<int> srcRank; 968 for (int idx = 0; idx < serverSize; ++idx) 969 { 970 if (intersectedProc[idx]) srcRank.push_back(idx); 971 } 972 973 // Compute the global index of grid from global index of each element. 974 for (int i = 0; i < srcRank.size(); ++i) 975 { 976 size_t ssize = 1; 977 int rankSrc = srcRank[i]; 978 std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); 979 std::vector<size_t> currentIndex(nbElement,0); 967 980 for (int idx = 0; idx < nbElement; ++idx) 968 981 { 969 std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), 970 intersectedProc.begin(), intersectedProc.begin(), 971 std::logical_and<bool>()); 972 } 973 974 std::vector<int> srcRank; 975 for (int idx = 0; idx < serverSize; ++idx) 976 { 977 if (intersectedProc[idx]) srcRank.push_back(idx); 978 } 979 980 // Compute the global index of grid from global index of each element. 981 for (int i = 0; i < srcRank.size(); ++i) 982 { 983 size_t ssize = 1; 984 int rankSrc = srcRank[i]; 985 std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); 986 std::vector<size_t> currentIndex(nbElement,0); 987 for (int idx = 0; idx < nbElement; ++idx) 988 { 989 ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); 990 globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); 991 } 992 globalIndexOnServer[rankSrc].resize(ssize); 993 994 std::vector<int> idxLoop(nbElement,0); 995 int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); 996 size_t idx = 0; 997 while (idx < ssize) 998 { 999 for (int ind = 0; ind < nbElement; ++ind) 982 ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); 983 globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); 984 } 985 globalIndexOnServer[rankSrc].resize(ssize); 986 987 std::vector<int> idxLoop(nbElement,0); 988 int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); 989 size_t idx = 0; 990 while (idx < ssize) 991 { 992 for (int ind = 0; ind < nbElement; ++ind) 993 { 994 if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) 1000 995 { 1001 if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) 1002 { 1003 idxLoop[ind] = 0; 1004 ++idxLoop[ind+1]; 1005 } 1006 1007 currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; 996 idxLoop[ind] = 0; 997 ++idxLoop[ind+1]; 1008 998 } 1009 999 1010 for (int ind = 0; ind < innnerLoopSize; ++ind) 1000 currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; 1001 } 1002 1003 for (int ind = 0; ind < innnerLoopSize; ++ind) 1004 { 1005 currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; 1006 size_t globalSrcIndex = 0; 1007 for (int idxElement = 0; idxElement < nbElement; ++idxElement) 1011 1008 { 1012 currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; 1013 size_t globalSrcIndex = 0; 1014 for (int idxElement = 0; idxElement < nbElement; ++idxElement) 1015 { 1016 globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; 1017 } 1018 globalIndexOnServer[rankSrc][idx] = globalSrcIndex; 1019 ++idx; 1020 ++idxLoop[0]; 1009 globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; 1021 1010 } 1011 globalIndexOnServer[rankSrc][idx] = globalSrcIndex; 1012 ++idx; 1013 ++idxLoop[0]; 1022 1014 } 1023 1015 } … … 1270 1262 { 1271 1263 CContext* context = CContext::getCurrent(); 1272 int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1; // This should be changed soon 1273 for (int p = 0; p < nbSrvPools; ++p) 1274 { 1275 CContextClient* client = (context->hasServer) ? (context->hasClient ? context->clientPrimServer[p] : context->client) 1276 : context->client; 1264 // int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1; // This should be changed soon 1265 // for (int p = 0; p < nbSrvPools; ++p) 1266 { 1267 // CContextClient* client = (context->hasServer) ? (context->hasClient ? context->clientPrimServer[p] : context->client) 1268 // : context->client; 1269 CContextClient* client = context->client; 1277 1270 1278 1271 int rank = client->clientRank; … … 1308 1301 { 1309 1302 CContext* context = CContext::getCurrent(); 1310 int nbSrvPools = (context-> hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1;1303 int nbSrvPools = (context->clientPrimServer.size()==0) ? 1 : context->clientPrimServer.size(); 1311 1304 connectedServerRank_.clear(); 1312 1305 connectedDataSize_.clear(); … … 1315 1308 for (int p = 0; p < nbSrvPools; ++p) 1316 1309 { 1317 CContextClient* client = (context->hasServer) ? (context->hasClient ? context->clientPrimServer[p] : context->client) 1318 : context->client; 1319 1320 connectedServerRank_[client].clear(); 1321 1322 if (client->isServerLeader()) 1323 { 1324 const std::list<int>& ranks = client->getRanksServerLeader(); 1325 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1326 { 1327 int rank = *itRank; 1328 int nb = 1; 1329 connectedServerRank_[client].push_back(rank); 1330 connectedDataSize_[client][rank] = nb; 1331 nbSenders[client][rank] = nb; 1332 } 1333 } 1334 else 1335 { 1336 const std::list<int>& ranks = client->getRanksServerNotLeader(); 1337 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1338 { 1339 int rank = *itRank; 1340 int nb = 1; 1341 connectedServerRank_[client].push_back(rank); 1342 connectedDataSize_[client][rank] = nb; 1343 nbSenders[client][rank] = nb; 1344 } 1345 } 1346 1310 CContextClient* client = (context->clientPrimServer.size()==0) ? context->client : context->clientPrimServer[p]; 1311 int receiverSize = client->serverSize; 1312 1313 // connectedServerRank_[client].clear(); 1314 1315 if (connectedServerRank_.find(receiverSize)==connectedServerRank_.end()) 1316 { 1317 if (client->isServerLeader()) 1318 { 1319 const std::list<int>& ranks = client->getRanksServerLeader(); 1320 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1321 { 1322 int rank = *itRank; 1323 int nb = 1; 1324 connectedServerRank_[receiverSize].push_back(rank); 1325 connectedDataSize_[receiverSize][rank] = nb; 1326 nbSenders[receiverSize][rank] = nb; 1327 } 1328 } 1329 else 1330 { 1331 const std::list<int>& ranks = client->getRanksServerNotLeader(); 1332 for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 1333 { 1334 int rank = *itRank; 1335 int nb = 1; 1336 connectedServerRank_[receiverSize].push_back(rank); 1337 connectedDataSize_[receiverSize][rank] = nb; 1338 nbSenders[receiverSize][rank] = nb; 1339 } 1340 } 1341 } 1347 1342 isDataDistributed_ = false; 1348 1343 } … … 1358 1353 { 1359 1354 CContextClient* client = context->hasServer ? context->clientPrimServer[p] : context->client; 1355 int receiverSize = client->serverSize; 1360 1356 1361 1357 CEventClient event(getType(), EVENT_ID_INDEX); … … 1416 1412 { 1417 1413 CContext* context = CContext::getCurrent(); 1418 int nbSrvPools = (context-> hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1;1414 int nbSrvPools = (context->clientPrimServer.size() == 0) ? 1 : context->clientPrimServer.size(); 1419 1415 storeIndex_toSrv.clear(); 1420 1416 for (int p = 0; p < nbSrvPools; ++p) 1421 1417 { 1422 CContextClient* client = context->hasServer ? context->clientPrimServer[p] : context->client ; 1418 CContextClient* client = (context->clientPrimServer.size() == 0) ? context->client : context->clientPrimServer[p]; 1419 int receiverSize = client->serverSize; 1423 1420 1424 1421 CEventClient event(getType(), EVENT_ID_INDEX); … … 1480 1477 { 1481 1478 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; 1482 itGlobalMap = globalIndexOnServer_[ client].begin();1483 iteGlobalMap = globalIndexOnServer_[ client].end();1479 itGlobalMap = globalIndexOnServer_[receiverSize].begin(); 1480 iteGlobalMap = globalIndexOnServer_[receiverSize].end(); 1484 1481 1485 1482 std::map<int,std::vector<int> >localIndexTmp; … … 1501 1498 } 1502 1499 1503 for (int ns = 0; ns < connectedServerRank_[ client].size(); ++ns)1504 { 1505 rank = connectedServerRank_[ client][ns];1500 for (int ns = 0; ns < connectedServerRank_[receiverSize].size(); ++ns) 1501 { 1502 rank = connectedServerRank_[receiverSize][ns]; 1506 1503 int nb = 0; 1507 1504 if (globalIndexTmp.end() != globalIndexTmp.find(rank)) … … 1524 1521 listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); 1525 1522 1526 event.push(rank, nbSenders[ client][rank], listMsg.back());1523 event.push(rank, nbSenders[receiverSize][rank], listMsg.back()); 1527 1524 } 1528 1525 -
XIOS/dev/XIOS_DEV_CMIP6/src/node/grid.hpp
r1250 r1263 205 205 CArray<int, 1> storeIndex_client; 206 206 207 /** Map containing indexes that will be sent in sendIndex(). In future: change the key to pair<distrType, serverSize> (?)*/207 /** Map containing indexes that will be sent in sendIndex(). */ 208 208 std::map<CContextClient*, map<int, CArray<int, 1> > > storeIndex_toSrv; 209 209 210 /** Map storing the number of senders. Key = size of receiver's intracomm */ 211 std::map<int, std::map<int,int> > nbSenders; 212 213 std::map<CContextClient*, std::map<int,int> > nbReadSenders; 214 210 215 map<int, CArray<int, 1> > storeIndex_fromSrv; // Support, for now, reading with level-1 server 211 216 212 213 std::map<CContextClient*, std::map<int,int> > nbSenders, nbReadSenders;214 217 215 218 map<int, CArray<size_t, 1> > outIndexFromClient, compressedOutIndexFromClient, outGlobalIndexFromClient; … … 271 274 void setTransformationAlgorithms(); 272 275 void computeIndexByElement(const std::vector<boost::unordered_map<size_t,std::vector<int> > >& indexServerOnElement, 276 const CContextClient* client, 273 277 CClientServerMapping::GlobalIndexMap& globalIndexOnServer); 274 278 int computeGridGlobalDimension(std::vector<int>& globalDim, … … 305 309 int numberWrittenIndexes_, totalNumberWrittenIndexes_, offsetWrittenIndexes_; 306 310 307 /** Map storing ranks of connected servers. In future: change the key to the server size (?)*/308 std::map< CContextClient*, std::vector<int> > connectedServerRank_;309 310 /** Map storing data size that will be sent to connected servers. In future: change the key to the server size (?)*/311 std::map< CContextClient*, std::map<int,size_t> > connectedDataSize_;311 /** Map storing local ranks of connected receivers. Key = size of receiver's intracomm */ 312 std::map<int, std::vector<int> > connectedServerRank_; 313 314 /** Map storing the size of data to be send. Key = size of receiver's intracomm */ 315 std::map<int, std::map<int,size_t> > connectedDataSize_; 312 316 313 317 bool isDataDistributed_; … … 324 328 bool hasTransform_; 325 329 326 /** Map storing data size that will be sent to connected servers. In future: change the key to the server size (?) */ 327 std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; 330 /** Map storing global indexes of server-like (band-wise) distribution for sending to receivers. 331 * Key = size of receiver's intracomm. 332 */ 333 // std::map<CContextClient*, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; 334 std::map<int, CClientServerMapping::GlobalIndexMap> globalIndexOnServer_; 335 328 336 329 337 /** List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) */
Note: See TracChangeset
for help on using the changeset viewer.