Ignore:
Timestamp:
04/15/20 13:23:39 (4 years ago)
Author:
ymipsl
Message:

Some update...

YM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp

    r1853 r1869  
    9090   //--------------------------------------------------------------- 
    9191 
    92    StdSize CGrid::getDataSize(void) const 
     92   StdSize CGrid::getDataSize(void)  
    9393   TRY 
    9494   { 
     
    9696     if (!isScalarGrid()) 
    9797     { 
    98        std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); 
     98       std::vector<int> dataNindex = getDistributionClient()->getDataNIndex(); 
    9999       for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i];        
    100100     } 
     
    634634 
    635635      size_t nbWritten = 0, indGlo; 
    636       CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution_->getGlobalDataIndexOnClient(); 
     636      CDistributionClient::GlobalLocalDataMap& globalDataIndex = getDistributionClient()->getGlobalDataIndexOnClient(); 
    637637      CDistributionClient::GlobalLocalDataMap::const_iterator itb = globalDataIndex.begin(), 
    638638                                                              ite = globalDataIndex.end(), it;     
     
    677677   CATCH_DUMP_ATTR 
    678678 
     679    
     680 
     681   /*! 
     682     Compute the global index of grid to send to server as well as the connected server of the current client. 
     683     First of all, from the local data on each element of grid, we can calculate their local index which also allows us to know 
     684     their global index. We can have a map of global index of grid and local index that each client holds 
     685     Then, each client holds a piece of information about the distribution of servers, which permits to compute the connected server(s) 
     686     of the current client. 
     687   */ 
     688   void CGrid::computeGridIndexToFileServer(CContextClient* client) 
     689   { 
     690     if (isScalarGrid()) 
     691     { 
     692       computeClientIndexScalarGrid(); 
     693       computeConnectedClientsScalarGrid(client); 
     694     } 
     695     else 
     696     { 
     697       computeClientIndex(); 
     698       computeConnectedClients(client); 
     699     } 
     700 
     701     // compute indices for client/server transfer for domain 
     702     for (const auto& domainId : domList_) CDomain::get(domainId)->computeConnectedClients(client); 
     703    
     704    
     705     // compute indices for client/server transfer for axis 
     706     std::vector<CAxis*> axisList = this->getAxis(); 
     707     std::vector<int> axisPosInGrid ; 
     708     // compute axis position in grid      
     709     int idx=0 ; 
     710     for (int i = 0 ; i < axis_domain_order.numElements(); ++i) 
     711     { 
     712       if (axis_domain_order(i) == 0)  idx += 0 ; 
     713       else if (axis_domain_order(i) == 1) { axisPosInGrid.push_back(idx) ; ++idx; } 
     714       else if (axis_domain_order(i) == 2) idx += 2; 
     715     } 
     716     for(int i=0 ; i<axisList.size(); i++) axisList[i] -> computeConnectedClients(client, getGlobalDimension(),axisPositionInGrid_[i]) ; 
     717   } 
    679718   //--------------------------------------------------------------- 
     719 
     720    
     721   void CGrid::computeClientDistribution(void) 
     722   { 
     723     if (computeClientDistribution_done_) return ; 
     724     else computeClientDistribution_done_ = true ; 
     725 
     726     CContext* context = CContext::getCurrent(); 
     727     int rank = context-> getIntraCommRank(); 
     728     clientDistribution_ = new CDistributionClient(rank, this); 
     729   } 
     730 
     731   void CGrid::computeStoreIndex_client(void) 
     732   { 
     733     if (computeStoreIndex_client_done_) return ; 
     734     else computeStoreIndex_client_done_ = true ; 
     735     if (isScalarGrid()) 
     736     { 
     737       storeIndex_client_.resize(1); 
     738       storeIndex_client_(0) = 0; 
     739     } 
     740     else 
     741     { 
     742       CDistributionClient* clientDistribution = getDistributionClient() ; 
     743       const std::vector<int>& localDataIndex = clientDistribution->getLocalDataIndexOnClient() ; 
     744       int nbStoreIndex = localDataIndex.size() ; 
     745       storeIndex_client_.resize(nbStoreIndex); 
     746       for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client_(idx) = localDataIndex[idx]; 
     747     } 
     748   } 
     749 
     750   void CGrid::computeStoreMask_client(void) 
     751   { 
     752     if (computeStoreMask_client_done_) return ; 
     753     else computeStoreMask_client_done_ = true ; 
     754     if (isScalarGrid()) 
     755     { 
     756       storeMask_client_.resize(1); 
     757       storeMask_client_(0) = true; 
     758     } 
     759     else 
     760     { 
     761       CDistributionClient* clientDistribution = getDistributionClient() ; 
     762       const std::vector<bool>& localMaskIndex = clientDistribution->getLocalMaskIndexOnClient() ; 
     763       int nbMaskIndex = localMaskIndex.size() ; 
     764       storeMask_client_.resize(nbMaskIndex); 
     765       for (int idx = 0; idx < nbMaskIndex; ++idx) storeMask_client_(idx) = localMaskIndex[idx]; 
     766     } 
     767   } 
    680768 
    681769   /* 
     
    688776   TRY 
    689777   { 
     778     if (computeClientIndex_done_) return ; 
     779 
    690780     CContext* context = CContext::getCurrent(); 
    691  
    692      CContextClient* client = context->client; 
    693      int rank = client->clientRank; 
    694  
    695      clientDistribution_ = new CDistributionClient(rank, this); 
     781     int rank = context-> getIntraCommRank(); 
     782 
     783     auto clientDistribution = getDistributionClient(); 
    696784     // Get local data index on client 
    697      int nbStoreIndex = clientDistribution_->getLocalDataIndexOnClient().size(); 
    698      int nbStoreGridMask = clientDistribution_->getLocalMaskIndexOnClient().size(); 
     785     int nbStoreIndex = clientDistribution->getLocalDataIndexOnClient().size(); 
     786     int nbStoreGridMask = clientDistribution->getLocalMaskIndexOnClient().size(); 
    699787     // nbStoreGridMask = nbStoreIndex if grid mask is defined, and 0 otherwise 
    700788     storeIndex_client_.resize(nbStoreIndex); 
    701789     storeMask_client_.resize(nbStoreGridMask); 
    702      for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client_(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 
    703      for (int idx = 0; idx < nbStoreGridMask; ++idx) storeMask_client_(idx) = (clientDistribution_->getLocalMaskIndexOnClient())[idx]; 
    704  
    705      if (0 == serverDistribution_) isDataDistributed_= clientDistribution_->isDataDistributed(); 
     790     for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client_(idx) = (clientDistribution->getLocalDataIndexOnClient())[idx]; 
     791     for (int idx = 0; idx < nbStoreGridMask; ++idx) storeMask_client_(idx) = (clientDistribution->getLocalMaskIndexOnClient())[idx]; 
     792 
     793     if (0 == serverDistribution_) isDataDistributed_= clientDistribution->isDataDistributed(); 
    706794     else 
    707795     { 
    708796        // Mapping global index received from clients to the storeIndex_client_ 
    709         CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution_->getGlobalDataIndexOnClient(); 
     797        CDistributionClient::GlobalLocalDataMap& globalDataIndex = clientDistribution->getGlobalDataIndexOnClient(); 
    710798        CDistributionClient::GlobalLocalDataMap::const_iterator itGloe = globalDataIndex.end(); 
    711799        map<int, CArray<size_t, 1> >::iterator itb = outGlobalIndexFromClient_.begin(), 
     
    746834        } 
    747835      } 
     836      computeClientIndex_done_ = true ; 
    748837   } 
    749838   CATCH_DUMP_ATTR 
     
    752841     Compute connected receivers and indexes to be sent to these receivers. 
    753842   */ 
    754    void CGrid::computeConnectedClients() 
    755    TRY 
    756    { 
     843   void CGrid::computeConnectedClients(CContextClient* client) 
     844   TRY 
     845   { 
     846     if (computeConnectedClients_done_.count(client)!=0) return ; 
     847 
    757848     CContext* context = CContext::getCurrent(); 
    758849      
    759850     set<int> listReceiverSize ; 
    760      for (auto it=clients.begin(); it!=clients.end(); ++it) 
     851     int receiverSize = client->serverSize; 
     852       
     853     if (listReceiverSize.find(receiverSize)==listReceiverSize.end()) 
    761854     { 
    762         
    763        CContextClient* client = *it ; 
    764  
    765        int receiverSize = client->serverSize; 
    766        
    767        if (listReceiverSize.find(receiverSize)==listReceiverSize.end()) 
     855       listReceiverSize.insert(receiverSize) ; 
     856       if (connectedServerRank_.find(receiverSize) != connectedServerRank_.end()) 
    768857       { 
    769          listReceiverSize.insert(receiverSize) ; 
    770          if (connectedServerRank_.find(receiverSize) != connectedServerRank_.end()) 
    771          { 
    772             // delete corresponding map in case of recompute, probably because a grid could has been modifiedd  
    773             // by a transformation 
    774             connectedServerRank_.erase(receiverSize); 
    775             connectedDataSize_.erase(receiverSize); 
    776             globalIndexOnServer_.erase(receiverSize); 
    777             nbSenders_.erase(receiverSize); 
    778          } 
    779  
    780          if (!doGridHaveDataDistributed(client)) 
    781          { 
    782             if (client->isServerLeader()) 
     858          // delete corresponding map in case of recompute, probably because a grid could has been modifiedd  
     859          // by a transformation 
     860          connectedServerRank_.erase(receiverSize); 
     861          connectedDataSize_.erase(receiverSize); 
     862          globalIndexOnServer_.erase(receiverSize); 
     863          nbSenders_.erase(receiverSize); 
     864       } 
     865 
     866       if (!doGridHaveDataDistributed(client)) 
     867       { 
     868          if (client->isServerLeader()) 
     869          { 
     870            size_t ssize = getDistributionClient()->getLocalDataIndexOnClient().size(); 
     871            const std::list<int>& ranks = client->getRanksServerLeader(); 
     872            for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    783873            { 
    784               size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); 
    785               const std::list<int>& ranks = client->getRanksServerLeader(); 
    786               for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    787               { 
    788                 connectedServerRank_[receiverSize].push_back(*itRank); 
    789                 connectedDataSize_[receiverSize][*itRank] = ssize; 
    790               } 
     874              connectedServerRank_[receiverSize].push_back(*itRank); 
     875              connectedDataSize_[receiverSize][*itRank] = ssize; 
    791876            } 
    792             return; 
    793          } 
    794  
    795          // Compute mapping between client and server 
    796          std::vector<std::unordered_map<size_t,std::vector<int> > > indexServerOnElement; 
    797          CServerDistributionDescription serverDistributionDescription(getGlobalDimension(), client->serverSize); 
    798          std::vector<int> serverZeroIndex = serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, 
     877          } 
     878          return; 
     879       } 
     880 
     881       // Compute mapping between client and server 
     882       std::vector<std::unordered_map<size_t,std::vector<int> > > indexServerOnElement; 
     883       CServerDistributionDescription serverDistributionDescription(getGlobalDimension(), client->serverSize); 
     884       std::vector<int> serverZeroIndex = serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, 
    799885                                                                                                    client->clientRank, 
    800886                                                                                                    client->clientSize, 
     
    802888                                                                                                    getDistributedDimension()); 
    803889 
    804          // Even if servers have no index, they must received something from client 
    805          // We only use several client to send "empty" message to these servers 
    806          std::list<int> serverZeroIndexLeader; 
    807          std::list<int> serverZeroIndexNotLeader; 
    808          CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); 
    809          for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 
    810            *it = serverZeroIndex[*it]; 
    811  
    812          if (globalIndexOnServer_.find(receiverSize) == globalIndexOnServer_.end()) 
    813            computeIndexByElement(indexServerOnElement, client, globalIndexOnServer_[receiverSize]); 
    814  
    815          const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 
    816          CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; 
    817          CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
    818          itbGlobalMap = globalIndexOnServer_[receiverSize].begin(); 
    819          iteGlobalMap = globalIndexOnServer_[receiverSize].end(); 
    820  
    821          for (itGlobalMap  = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
     890       // Even if servers have no index, they must received something from client 
     891       // We only use several client to send "empty" message to these servers 
     892       std::list<int> serverZeroIndexLeader; 
     893       std::list<int> serverZeroIndexNotLeader; 
     894       CContextClient::computeLeader(client->clientRank, client->clientSize, serverZeroIndex.size(), serverZeroIndexLeader, serverZeroIndexNotLeader); 
     895       for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 
     896         *it = serverZeroIndex[*it]; 
     897 
     898       if (globalIndexOnServer_.find(receiverSize) == globalIndexOnServer_.end()) 
     899         computeIndexByElement(indexServerOnElement, client, globalIndexOnServer_[receiverSize]); 
     900 
     901       const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = getDistributionClient()->getGlobalLocalDataSendToServer(); 
     902       CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; 
     903       CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
     904       itbGlobalMap = globalIndexOnServer_[receiverSize].begin(); 
     905       iteGlobalMap = globalIndexOnServer_[receiverSize].end(); 
     906 
     907       for (itGlobalMap  = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
     908       { 
     909         int serverRank = itGlobalMap->first; 
     910         int indexSize = itGlobalMap->second.size(); 
     911         const std::vector<size_t>& indexVec = itGlobalMap->second; 
     912         for (int idx = 0; idx < indexSize; ++idx) 
    822913         { 
    823            int serverRank = itGlobalMap->first; 
    824            int indexSize = itGlobalMap->second.size(); 
    825            const std::vector<size_t>& indexVec = itGlobalMap->second; 
    826            for (int idx = 0; idx < indexSize; ++idx) 
    827            { 
    828               itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); 
    829               if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) 
    830               { 
    831                 if (connectedDataSize_[receiverSize].end() == connectedDataSize_[receiverSize].find(serverRank)) 
    832                   connectedDataSize_[receiverSize][serverRank] = 1; 
    833                 else 
    834                   ++connectedDataSize_[receiverSize][serverRank]; 
    835               } 
    836            } 
     914            itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); 
     915            if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) 
     916            { 
     917              if (connectedDataSize_[receiverSize].end() == connectedDataSize_[receiverSize].find(serverRank)) 
     918                connectedDataSize_[receiverSize][serverRank] = 1; 
     919              else 
     920                ++connectedDataSize_[receiverSize][serverRank]; 
     921            } 
    837922         } 
    838  
    839          // Connected servers which really have index 
    840          for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { 
    841            connectedServerRank_[receiverSize].push_back(itGlobalMap->first); 
    842          } 
    843  
    844          // Connected servers which have no index at all 
    845          for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 
    846            connectedServerRank_[receiverSize].push_back(*it); 
    847  
    848          // Even if a client has no index, it must connect to at least one server and 
    849          // send an "empty" data to this server 
    850          if (connectedServerRank_[receiverSize].empty()) 
    851           connectedServerRank_[receiverSize].push_back(client->clientRank % client->serverSize); 
    852  
    853          // Now check if all servers have data to receive. If not, master client will send empty data. 
    854          // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. 
    855          std::vector<int> counts (client->clientSize); 
    856          std::vector<int> displs (client->clientSize); 
    857          displs[0] = 0; 
    858          int localCount = connectedServerRank_[receiverSize].size() ; 
    859          MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ; 
    860          for (int i = 0; i < client->clientSize-1; ++i) 
    861          { 
    862            displs[i+1] = displs[i] + counts[i]; 
    863          } 
    864          std::vector<int> allConnectedServers(displs[client->clientSize-1]+counts[client->clientSize-1]); 
    865          MPI_Gatherv(&(connectedServerRank_[receiverSize])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm); 
    866  
    867          if ((allConnectedServers.size() != receiverSize) && (client->clientRank == 0)) 
    868          { 
    869            std::vector<bool> isSrvConnected (receiverSize, false); 
    870            for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; 
    871            for (int i = 0; i < receiverSize; ++i) 
    872            { 
    873              if (!isSrvConnected[i]) connectedServerRank_[receiverSize].push_back(i); 
    874            } 
    875          } 
    876  
    877          nbSenders_[receiverSize] = clientServerMap_->computeConnectedClients(receiverSize, client->clientSize, client->intraComm, connectedServerRank_[receiverSize]); 
    878923       } 
     924 
     925       // Connected servers which really have index 
     926       for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap)  
     927         connectedServerRank_[receiverSize].push_back(itGlobalMap->first); 
     928      
     929       // Connected servers which have no index at all 
     930       for (std::list<int>::iterator it = serverZeroIndexLeader.begin(); it != serverZeroIndexLeader.end(); ++it) 
     931         connectedServerRank_[receiverSize].push_back(*it); 
     932 
     933       // Even if a client has no index, it must connect to at least one server and 
     934       // send an "empty" data to this server 
     935       if (connectedServerRank_[receiverSize].empty()) 
     936         connectedServerRank_[receiverSize].push_back(client->clientRank % client->serverSize); 
     937  
     938       // Now check if all servers have data to receive. If not, master client will send empty data. 
     939       // This ensures that all servers will participate in collective calls upon receiving even if they have no date to receive. 
     940       std::vector<int> counts (client->clientSize); 
     941       std::vector<int> displs (client->clientSize); 
     942       displs[0] = 0; 
     943       int localCount = connectedServerRank_[receiverSize].size() ; 
     944       MPI_Gather(&localCount, 1, MPI_INT, &counts[0], 1, MPI_INT, 0, client->intraComm) ; 
     945       for (int i = 0; i < client->clientSize-1; ++i) displs[i+1] = displs[i] + counts[i]; 
     946       std::vector<int> allConnectedServers(displs[client->clientSize-1]+counts[client->clientSize-1]); 
     947       MPI_Gatherv(&(connectedServerRank_[receiverSize])[0], localCount, MPI_INT, &allConnectedServers[0], &counts[0], &displs[0], MPI_INT, 0, client->intraComm); 
     948 
     949       if ((allConnectedServers.size() != receiverSize) && (client->clientRank == 0)) 
     950       { 
     951         std::vector<bool> isSrvConnected (receiverSize, false); 
     952         for (int i = 0; i < allConnectedServers.size(); ++i) isSrvConnected[allConnectedServers[i]] = true; 
     953         for (int i = 0; i < receiverSize; ++i) if (!isSrvConnected[i]) connectedServerRank_[receiverSize].push_back(i); 
     954       } 
     955 
     956       nbSenders_[receiverSize] = CClientServerMapping::computeConnectedClients(receiverSize, client->clientSize, client->intraComm, connectedServerRank_[receiverSize]); 
    879957     } 
     958     computeConnectedClients_done_.insert(client) ; 
    880959   } 
    881960   CATCH_DUMP_ATTR 
     
    888967     of the current client. 
    889968   */ 
     969   // ym obsolete : to be removed.... 
    890970   void CGrid::computeIndex(void) 
    891971   TRY 
    892972   { 
     973    // old interface 
    893974     CContext* context = CContext::getCurrent(); 
    894975     if (isScalarGrid()) 
     
    897978       if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) 
    898979       { 
    899          computeConnectedClientsScalarGrid(); 
     980         // ym computeConnectedClientsScalarGrid(); 
    900981       } 
    901982     } 
     
    905986       if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) 
    906987       { 
    907          computeConnectedClients(); 
     988         //computeConnectedClients(); 
    908989       } 
    909990     } 
     
    11781259      } 
    11791260 
    1180       grid->solveDomainAxisRefInheritance(true); 
     1261 //     grid->solveElementsRefInheritance(true); 
    11811262 
    11821263      return grid; 
     
    13101391   //---------------------------------------------------------------- 
    13111392 
    1312    void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored) const 
    1313    TRY 
    1314    { 
    1315       const StdSize size = storeIndex_client_.numElements(); 
     1393   void CGrid::storeField_arr(const double* const data, CArray<double, 1>& stored)  
     1394   TRY 
     1395   { 
     1396      auto& storeIndex_client = getStoreIndex_client() ; 
     1397      const StdSize size = storeIndex_client.numElements(); 
    13161398 
    13171399      stored.resize(size); 
    1318       for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client_(i)]; 
     1400      for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; 
    13191401   } 
    13201402   CATCH 
    13211403 
    1322    void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data) const 
    1323    TRY 
    1324    { 
    1325       const StdSize size = storeIndex_client_.numElements(); 
    1326  
    1327       for(StdSize i = 0; i < size; i++) data[storeIndex_client_(i)] = stored(i); 
     1404   void CGrid::restoreField_arr(const CArray<double, 1>& stored, double* const data)  
     1405   TRY 
     1406   { 
     1407      auto& storeIndex_client=getStoreIndex_client() ; 
     1408      const StdSize size = storeIndex_client.numElements(); 
     1409 
     1410      for(StdSize i = 0; i < size; i++) data[storeIndex_client(i)] = stored(i); 
    13281411   } 
    13291412   CATCH 
    13301413 
    1331    void CGrid::maskField_arr(const double* const data, CArray<double, 1>& stored) const 
    1332    { 
    1333       const StdSize size = storeIndex_client_.numElements(); 
     1414   void CGrid::maskField_arr(const double* const data, CArray<double, 1>& stored)  
     1415   { 
     1416      auto& storeIndex_client=getStoreIndex_client() ; 
     1417      auto& storeMask_client=getStoreMask_client() ; 
     1418         
     1419      const StdSize size = storeIndex_client.numElements(); 
    13341420      stored.resize(size); 
    13351421      const double nanValue = std::numeric_limits<double>::quiet_NaN(); 
    13361422 
    1337       if (storeMask_client_.numElements() != 0) 
    1338         for(StdSize i = 0; i < size; i++) stored(i) = (storeMask_client_(i)) ? data[storeIndex_client_(i)] : nanValue; 
     1423      if (storeMask_client.numElements() != 0) 
     1424        for(StdSize i = 0; i < size; i++) stored(i) = (storeMask_client(i)) ? data[storeIndex_client(i)] : nanValue; 
    13391425      else 
    1340         for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client_(i)]; 
    1341    } 
    1342  
    1343    void CGrid::uncompressField_arr(const double* const data, CArray<double, 1>& out) const 
    1344    TRY 
    1345    { 
    1346       const std::vector<int>& localMaskedDataIndex = clientDistribution_->getLocalMaskedDataIndexOnClient(); 
     1426        for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)]; 
     1427   } 
     1428 
     1429   void CGrid::uncompressField_arr(const double* const data, CArray<double, 1>& out)  
     1430   TRY 
     1431   { 
     1432      const std::vector<int>& localMaskedDataIndex = getDistributionClient()->getLocalMaskedDataIndexOnClient(); 
    13471433      const int size = localMaskedDataIndex.size(); 
    13481434      for(int i = 0; i < size; ++i) out(localMaskedDataIndex[i]) = data[i]; 
     
    13531439  TRY 
    13541440  { 
     1441    if (computeClientIndexScalarGrid_done_) return ; 
     1442 
    13551443    CContext* context = CContext::getCurrent();     
    13561444    { 
    13571445      int rank = context->intraCommRank_; 
    13581446 
    1359       clientDistribution_ = new CDistributionClient(rank, this); 
     1447      auto clientDistribution = getDistributionClient(); 
    13601448 
    13611449      storeIndex_client_.resize(1); 
     
    13821470      } 
    13831471    } 
    1384   } 
    1385   CATCH_DUMP_ATTR 
    1386  
    1387   void CGrid::computeConnectedClientsScalarGrid() 
    1388   TRY 
    1389   { 
     1472    computeClientIndexScalarGrid_done_ = true ; 
     1473  } 
     1474  CATCH_DUMP_ATTR 
     1475 
     1476  void CGrid::computeConnectedClientsScalarGrid(CContextClient* client) 
     1477  TRY 
     1478  { 
     1479    if (computeConnectedClientsScalarGrid_done_.count(client)!=0) return ; 
    13901480 
    13911481    CContext* context = CContext::getCurrent(); 
    13921482      
    13931483    set<int> listReceiverSize ; 
    1394     for (auto it=clients.begin(); it!=clients.end(); ++it) 
    1395     { 
    1396         
    1397       CContextClient* client = *it ; 
    1398  
    1399       int receiverSize = client->serverSize; 
     1484 
     1485    int receiverSize = client->serverSize; 
    14001486       
    1401       if (listReceiverSize.find(receiverSize)==listReceiverSize.end()) 
    1402       { 
    1403         listReceiverSize.insert(receiverSize) ; 
    1404         if (connectedServerRank_.find(receiverSize) != connectedServerRank_.end()) 
     1487    if (listReceiverSize.find(receiverSize)==listReceiverSize.end()) 
     1488    { 
     1489      listReceiverSize.insert(receiverSize) ; 
     1490      if (connectedServerRank_.find(receiverSize) != connectedServerRank_.end()) 
     1491      { 
     1492         // delete corresponding map in case of recompute, probably because a grid could has been modifiedd  
     1493         // by a transformation 
     1494        connectedServerRank_.erase(receiverSize); 
     1495        connectedDataSize_.erase(receiverSize); 
     1496        globalIndexOnServer_.erase(receiverSize); 
     1497        nbSenders_.erase(receiverSize); 
     1498      } 
     1499 
     1500      if (client->isServerLeader()) 
     1501      { 
     1502        const std::list<int>& ranks = client->getRanksServerLeader(); 
     1503        for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    14051504        { 
    1406            // delete corresponding map in case of recompute, probably because a grid could has been modifiedd  
    1407            // by a transformation 
    1408           connectedServerRank_.erase(receiverSize); 
    1409           connectedDataSize_.erase(receiverSize); 
    1410           globalIndexOnServer_.erase(receiverSize); 
    1411           nbSenders_.erase(receiverSize); 
    1412         } 
    1413  
    1414         if (client->isServerLeader()) 
     1505          int rank = *itRank; 
     1506          int nb = 1; 
     1507          connectedServerRank_[receiverSize].push_back(rank); 
     1508          connectedDataSize_[receiverSize][rank] = nb; 
     1509          nbSenders_[receiverSize][rank] = nb; 
     1510        } 
     1511      } 
     1512      else 
     1513      { 
     1514        const std::list<int>& ranks = client->getRanksServerNotLeader(); 
     1515        for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    14151516        { 
    1416           const std::list<int>& ranks = client->getRanksServerLeader(); 
    1417           for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    1418           { 
    1419             int rank = *itRank; 
    1420             int nb = 1; 
    1421             connectedServerRank_[receiverSize].push_back(rank); 
    1422             connectedDataSize_[receiverSize][rank] = nb; 
    1423             nbSenders_[receiverSize][rank] = nb; 
    1424           } 
    1425         } 
    1426         else 
    1427         { 
    1428           const std::list<int>& ranks = client->getRanksServerNotLeader(); 
    1429           for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    1430           { 
    1431             int rank = *itRank; 
    1432             int nb = 1; 
    1433             connectedServerRank_[receiverSize].push_back(rank); 
    1434             connectedDataSize_[receiverSize][rank] = nb; 
    1435             nbSenders_[receiverSize][rank] = nb; 
    1436           } 
    1437         } 
    1438       } 
    1439       isDataDistributed_ = false; 
    1440     } 
     1517          int rank = *itRank; 
     1518          int nb = 1; 
     1519          connectedServerRank_[receiverSize].push_back(rank); 
     1520          connectedDataSize_[receiverSize][rank] = nb; 
     1521          nbSenders_[receiverSize][rank] = nb; 
     1522        } 
     1523      } 
     1524    } 
     1525    isDataDistributed_ = false; 
     1526    computeConnectedClientsScalarGrid_done_.insert(client) ; 
    14411527  } 
    14421528  CATCH_DUMP_ATTR 
     
    15251611      list<CMessage> listMsg; 
    15261612      list<CArray<size_t,1> > listOutIndex; 
    1527       const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 
     1613      const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = getDistributionClient()->getGlobalLocalDataSendToServer(); 
    15281614      CDistributionClient::GlobalLocalDataMap::const_iterator itbIndex = globalLocalIndexSendToServer.begin(), itIndex, 
    15291615                                                              iteIndex = globalLocalIndexSendToServer.end(); 
     
    19712057  TRY 
    19722058  { 
     2059    if (!computeClientDistribution_done_) computeClientDistribution() ; 
    19732060    return clientDistribution_; 
    19742061  } 
     
    22092296 
    22102297  /*! 
     2298  \brief Check if all elements of the grid are complete 
     2299  Before make any grid processing, we must be sure that all grid information elements have 
     2300  been sent, for exemple when reading a grid in a file or when grid elements are sent by an 
     2301  other context (coupling) 
     2302  */ 
     2303  bool CGrid::checkIfCompleted(void) 
     2304  { 
     2305    setDomainList(); 
     2306    for (auto domainId : domList_) if (!CDomain::get(domainId)->checkIfCompleted()) return false ; 
     2307    setAxisList() ; 
     2308    for (auto axisId : axisList_) if (!CAxis::get(axisId)->checkIfCompleted()) return false ; 
     2309    setScalarList() ; 
     2310    for (auto scalarId : scalarList_) if (!CScalar::get(scalarId)->checkIfCompleted()) return false ; 
     2311    return true ; 
     2312  } 
     2313 
     2314  /*! 
    22112315  \brief Solve domain and axis references 
    22122316  As field, domain and axis can refer to other domains or axis. In order to inherit correctly 
     
    22142318  \param[in] apply inherit all attributes of parents (true) 
    22152319  */ 
    2216   void CGrid::solveDomainAxisRefInheritance(bool apply) 
    2217   TRY 
    2218   { 
    2219     CContext* context = CContext::getCurrent(); 
    2220     unsigned int vecSize, i; 
    2221     std::vector<StdString>::iterator it, itE; 
     2320  void CGrid::solveElementsRefInheritance(bool apply) 
     2321  TRY 
     2322  { 
    22222323    setDomainList(); 
    2223     it = domList_.begin(); itE = domList_.end(); 
    2224     for (; it != itE; ++it) 
    2225     { 
    2226       CDomain* pDom = CDomain::get(*it); 
    2227       if (context->getServiceType()==CServicesManager::CLIENT) 
    2228       { 
    2229         pDom->solveRefInheritance(apply); 
    2230         pDom->solveInheritanceTransformation(); 
    2231       } 
     2324    for (auto domainId : domList_) 
     2325    { 
     2326      CDomain* pDom = CDomain::get(domainId); 
     2327      pDom->solveRefInheritance(apply); 
     2328      pDom->solveInheritanceTransformation(); 
    22322329    } 
    22332330 
    22342331    setAxisList(); 
    2235     it = axisList_.begin(); itE = axisList_.end(); 
    2236     for (; it != itE; ++it) 
    2237     { 
    2238       CAxis* pAxis = CAxis::get(*it); 
    2239       if (context->getServiceType()==CServicesManager::CLIENT) 
    2240       { 
    2241         pAxis->solveRefInheritance(apply); 
    2242         pAxis->solveInheritanceTransformation(); 
    2243       } 
     2332    for (auto axisId : axisList_) 
     2333    { 
     2334      CAxis* pAxis = CAxis::get(axisId); 
     2335      pAxis->solveRefInheritance(apply); 
     2336      pAxis->solveInheritanceTransformation(); 
    22442337    } 
    22452338 
    22462339    setScalarList(); 
    2247     it = scalarList_.begin(); itE = scalarList_.end(); 
    2248     for (; it != itE; ++it) 
    2249     { 
    2250       CScalar* pScalar = CScalar::get(*it); 
    2251       if (context->getServiceType()==CServicesManager::CLIENT) 
    2252       { 
    2253         pScalar->solveRefInheritance(apply); 
    2254         pScalar->solveInheritanceTransformation(); 
    2255       } 
    2256     } 
     2340    for (auto scalarId : scalarList_) 
     2341    { 
     2342      CScalar* pScalar = CScalar::get(scalarId); 
     2343      pScalar->solveRefInheritance(apply); 
     2344      pScalar->solveInheritanceTransformation(); 
     2345    } 
     2346  } 
     2347  CATCH_DUMP_ATTR 
     2348 
     2349 /*! 
     2350  \brief check attributes of all elements of the grid 
     2351  */ 
     2352  void CGrid::checkElementsAttributes(void) 
     2353  TRY 
     2354  { 
     2355    setDomainList(); 
     2356    for (auto domainId : domList_) CDomain::get(domainId)->checkAttributes(); 
     2357 
     2358    setAxisList(); 
     2359    for (auto axisId : axisList_) CAxis::get(axisId)->checkAttributes(); 
     2360     
     2361    setScalarList(); 
     2362    for (auto scalarId : scalarList_) CScalar::get(scalarId)->checkAttributes(); 
    22572363  } 
    22582364  CATCH_DUMP_ATTR 
     
    23012407  TRY 
    23022408  { 
    2303     if (0 != transformGridSrc) 
     2409    if (nullptr != transformGridSrc) 
    23042410    { 
    23052411      if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) 
     
    23622468  } 
    23632469  CATCH_DUMP_ATTR 
     2470 
     2471 
     2472 
     2473 
     2474  void CGrid::prepareTransformGrid(CGrid* transformGridSrc) 
     2475  TRY 
     2476  { 
     2477    if (prepareTransformGrid_done_) return ; 
     2478 
     2479    if (!transformGridSrc) 
     2480      ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", 
     2481            << "Impossible to transform grid '" << getId() << "', the source grid is null."); 
     2482 
     2483    if (isTransformed()) return; 
     2484    setTransformed(); 
     2485    if (axis_domain_order.numElements() != transformGridSrc->axis_domain_order.numElements()) 
     2486    { 
     2487      ERROR("CGrid::transformGrid(CGrid* transformGridSrc)", 
     2488           << "Two grids have different number of elements. " << std::endl 
     2489           << "Number of element of grid destination " << this->getId() << " is " << axis_domain_order.numElements() << std::endl 
     2490           << "Number of element of grid source " << transformGridSrc->getId() << " is " << transformGridSrc->axis_domain_order.numElements()); 
     2491    } 
     2492    else 
     2493    { 
     2494    } 
     2495 
     2496    transformations_ = new CGridTransformation(this, transformGridSrc); 
     2497    if (0 < transformations_->getNbAlgo()) hasTransform_ = true; 
     2498 
     2499    prepareTransformGrid_done_ = true;  
     2500  } 
     2501  CATCH_DUMP_ATTR 
     2502 
     2503 
     2504  void CGrid::makeTransformGrid(void) 
     2505  TRY 
     2506  { 
     2507    if (makeTransformGrid_done_) return ; 
     2508    transformations_->computeAll(); 
     2509 
     2510    makeTransformGrid_done_ = true ;  
     2511  } 
     2512  CATCH_DUMP_ATTR 
     2513 
     2514 
     2515  vector<std::string> CGrid::getAuxInputTransformGrid(void) 
     2516  TRY 
     2517  { 
     2518    if (transformations_ != nullptr) return transformations_->getAuxInputs() ; 
     2519  } 
     2520  CATCH_DUMP_ATTR 
     2521 
     2522 
     2523 
     2524 
     2525 
     2526 
    23642527 
    23652528  bool CGrid::hasTransform() 
Note: See TracChangeset for help on using the changeset viewer.