Ignore:
Timestamp:
12/05/16 17:47:54 (7 years ago)
Author:
oabramkina
Message:

First working version with compression by secondary servers.

File:
1 edited

Legend:

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

    r987 r1009  
    273273   { 
    274274     CContext* context = CContext::getCurrent(); 
    275      CContextClient* client= context->hasServer ? context->clientPrimServer : context->client; 
    276  
    277      if (isScalarGrid()) 
     275     CContextClient* client; 
     276 
     277     int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     278     for (int i = 0; i < nbSrvPools; ++i) 
    278279     { 
     280       if (context->hasClient) 
     281       { 
     282         if (context->hasServer) 
     283           client = context->clientPrimServer[i]; 
     284         else 
     285           client = context->client; 
     286       } 
     287 
     288       if (isScalarGrid()) 
     289       { 
     290         if (context->hasClient && !context->hasServer) 
     291  //         if (context->hasClient) 
     292            if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } 
     293 
     294         if (this->isChecked) return; 
     295         if (context->hasClient && !context->hasServer) 
     296  //       if (context->hasClient) 
     297         { 
     298            this->computeIndexScalarGrid(); 
     299         } 
     300 
     301         this->isChecked = true; 
     302         return; 
     303       } 
     304 
    279305       if (context->hasClient && !context->hasServer) 
    280 //         if (context->hasClient) 
    281           if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } 
     306  //     if (context->hasClient) 
     307        if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } 
    282308 
    283309       if (this->isChecked) return; 
     310 
    284311       if (context->hasClient && !context->hasServer) 
    285 //       if (context->hasClient) 
     312  //     if (context->hasClient) 
    286313       { 
    287           this->computeIndexScalarGrid(); 
     314          this->checkAttributesAfterTransformation(); 
     315          this->checkMask(); 
     316          this->computeIndex(); 
    288317       } 
    289  
    290318       this->isChecked = true; 
    291        return; 
    292319     } 
    293  
    294      if (context->hasClient && !context->hasServer) 
    295 //     if (context->hasClient) 
    296       if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } 
    297  
    298      if (this->isChecked) return; 
    299  
    300      if (context->hasClient && !context->hasServer) 
    301 //     if (context->hasClient) 
    302      { 
    303         this->checkAttributesAfterTransformation(); 
    304         this->checkMask(); 
    305         this->computeIndex(); 
    306      } 
    307      this->isChecked = true; 
    308320   } 
    309321 
     
    502514     CContext* context = CContext::getCurrent(); 
    503515//     CContextClient* client = context->client; 
    504      CContextClient* client = (context->hasServer) ? context->clientPrimServer : context->client; 
    505  
    506  
    507      // First of all, compute distribution on client side 
    508      if (0 != serverDistribution_) 
    509        clientDistribution_ = new CDistributionClient(client->clientRank, serverDistribution_->getGlobalLocalIndex()); 
    510      else 
    511        clientDistribution_ = new CDistributionClient(client->clientRank, this); 
    512  
    513      // Get local data index on client 
    514      int tmp = clientDistribution_->getLocalDataIndexOnClient().size(); 
    515      storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); 
    516      int nbStoreIndex = storeIndex_client.numElements(); 
    517      for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 
    518      isDataDistributed_= clientDistribution_->isDataDistributed(); 
    519  
    520      connectedServerRank_.clear(); 
    521  
    522      if (!doGridHaveDataDistributed()) 
     516     int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     517     for (int i = 0; i < nbSrvPools; ++i) 
    523518     { 
    524         if (client->isServerLeader()) 
    525         { 
    526           size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); 
    527           const std::list<int>& ranks = client->getRanksServerLeader(); 
    528           for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
     519       CContextClient* client = (context->hasServer) ? context->clientPrimServer[i] : context->client; 
     520 
     521 
     522       // First of all, compute distribution on client side 
     523       if (0 != serverDistribution_) 
     524         clientDistribution_ = new CDistributionClient(client->clientRank, serverDistribution_->getGlobalLocalIndex()); 
     525       else 
     526         clientDistribution_ = new CDistributionClient(client->clientRank, this); 
     527 
     528       // Get local data index on client 
     529       int tmp = clientDistribution_->getLocalDataIndexOnClient().size(); 
     530       storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().size()); 
     531       int nbStoreIndex = storeIndex_client.numElements(); 
     532       for (int idx = 0; idx < nbStoreIndex; ++idx) storeIndex_client(idx) = (clientDistribution_->getLocalDataIndexOnClient())[idx]; 
     533       isDataDistributed_= clientDistribution_->isDataDistributed(); 
     534 
     535       connectedServerRank_.clear(); 
     536 
     537       if (!doGridHaveDataDistributed()) 
     538       { 
     539          if (client->isServerLeader()) 
    529540          { 
    530             connectedServerRank_.push_back(*itRank); 
    531             connectedDataSize_[*itRank] = ssize; 
     541            size_t ssize = clientDistribution_->getLocalDataIndexOnClient().size(); 
     542            const std::list<int>& ranks = client->getRanksServerLeader(); 
     543            for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
     544            { 
     545              connectedServerRank_.push_back(*itRank); 
     546              connectedDataSize_[*itRank] = ssize; 
     547            } 
    532548          } 
    533         } 
    534         return; 
     549          return; 
     550       } 
     551 
     552       // Compute mapping between client and server 
     553       std::vector<boost::unordered_map<size_t,std::vector<int> > > indexServerOnElement; 
     554       CServerDistributionDescription serverDistributionDescription(globalDim_, client->serverSize); 
     555       serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, 
     556                                                                  client->clientRank, 
     557                                                                  client->clientSize, 
     558                                                                  axis_domain_order, 
     559                                                                  positionDimensionDistributed_); 
     560       computeIndexByElement(indexServerOnElement, globalIndexOnServer_); 
     561 
     562       const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 
     563       CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; 
     564       CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
     565       itGlobalMap  = itbGlobalMap = globalIndexOnServer_.begin(); 
     566       iteGlobalMap = globalIndexOnServer_.end(); 
     567 
     568       for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
     569       { 
     570         int serverRank = itGlobalMap->first; 
     571         int indexSize = itGlobalMap->second.size(); 
     572         const std::vector<size_t>& indexVec = itGlobalMap->second; 
     573         for (int idx = 0; idx < indexSize; ++idx) 
     574         { 
     575            itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); 
     576            if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) 
     577            { 
     578               if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) 
     579                 connectedDataSize_[serverRank] = 1; 
     580               else 
     581                 ++connectedDataSize_[serverRank]; 
     582            } 
     583         } 
     584       } 
     585 
     586       for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { 
     587         connectedServerRank_.push_back(itGlobalMap->first); 
     588       } 
     589 
     590       nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
    535591     } 
    536  
    537      // Compute mapping between client and server 
    538      std::vector<boost::unordered_map<size_t,std::vector<int> > > indexServerOnElement; 
    539      CServerDistributionDescription serverDistributionDescription(globalDim_, client->serverSize); 
    540      serverDistributionDescription.computeServerGlobalByElement(indexServerOnElement, 
    541                                                                 client->clientRank, 
    542                                                                 client->clientSize, 
    543                                                                 axis_domain_order, 
    544                                                                 positionDimensionDistributed_); 
    545      computeIndexByElement(indexServerOnElement, globalIndexOnServer_); 
    546  
    547      const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 
    548      CDistributionClient::GlobalLocalDataMap::const_iterator iteGlobalLocalIndexMap = globalLocalIndexSendToServer.end(), itGlobalLocalIndexMap; 
    549      CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
    550      itGlobalMap  = itbGlobalMap = globalIndexOnServer_.begin(); 
    551      iteGlobalMap = globalIndexOnServer_.end(); 
    552  
    553      for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
    554      { 
    555        int serverRank = itGlobalMap->first; 
    556        int indexSize = itGlobalMap->second.size(); 
    557        const std::vector<size_t>& indexVec = itGlobalMap->second; 
    558        for (int idx = 0; idx < indexSize; ++idx) 
    559        { 
    560           itGlobalLocalIndexMap = globalLocalIndexSendToServer.find(indexVec[idx]); 
    561           if (iteGlobalLocalIndexMap != itGlobalLocalIndexMap) 
    562           { 
    563              if (connectedDataSize_.end() == connectedDataSize_.find(serverRank)) 
    564                connectedDataSize_[serverRank] = 1; 
    565              else 
    566                ++connectedDataSize_[serverRank]; 
    567           } 
    568        } 
    569      } 
    570  
    571      for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { 
    572        connectedServerRank_.push_back(itGlobalMap->first); 
    573      } 
    574  
    575      nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
    576592   } 
    577593 
     
    588604   { 
    589605     CContext* context = CContext::getCurrent(); 
    590      CContextClient* client = context->hasServer ? context->clientPrimServer : context->client; 
    591      int serverSize = client->serverSize; 
    592      std::vector<CDomain*> domList = getDomains(); 
    593      std::vector<CAxis*> axisList = getAxis(); 
    594  
    595      // Some pre-calculations of global index on each element of current grid. 
    596      int nbElement = axis_domain_order.numElements(); 
    597      std::vector<CArray<size_t,1> > globalIndexElement(nbElement); 
    598      int domainIdx = 0, axisIdx = 0, scalarIdx = 0; 
    599      std::vector<size_t> elementNGlobal(nbElement); 
    600      elementNGlobal[0] = 1; 
    601      size_t globalSize = 1; 
    602      for (int idx = 0; idx < nbElement; ++idx) 
     606     int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     607     for (int i = 0; i < nbSrvPools; ++i) 
    603608     { 
    604        elementNGlobal[idx] = globalSize; 
    605        size_t elementSize; 
    606        size_t elementGlobalSize = 1; 
    607        if (2 == axis_domain_order(idx)) // This is domain 
     609       CContextClient* client = context->hasServer ? context->clientPrimServer[i] : context->client; 
     610       int serverSize = client->serverSize; 
     611       std::vector<CDomain*> domList = getDomains(); 
     612       std::vector<CAxis*> axisList = getAxis(); 
     613 
     614       // Some pre-calculations of global index on each element of current grid. 
     615       int nbElement = axis_domain_order.numElements(); 
     616       std::vector<CArray<size_t,1> > globalIndexElement(nbElement); 
     617       int domainIdx = 0, axisIdx = 0, scalarIdx = 0; 
     618       std::vector<size_t> elementNGlobal(nbElement); 
     619       elementNGlobal[0] = 1; 
     620       size_t globalSize = 1; 
     621       for (int idx = 0; idx < nbElement; ++idx) 
    608622       { 
    609          elementSize = domList[domainIdx]->i_index.numElements(); 
    610          globalIndexElement[idx].resize(elementSize); 
    611          for (int jdx = 0; jdx < elementSize; ++jdx) 
     623         elementNGlobal[idx] = globalSize; 
     624         size_t elementSize; 
     625         size_t elementGlobalSize = 1; 
     626         if (2 == axis_domain_order(idx)) // This is domain 
    612627         { 
    613            globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); 
     628           elementSize = domList[domainIdx]->i_index.numElements(); 
     629           globalIndexElement[idx].resize(elementSize); 
     630           for (int jdx = 0; jdx < elementSize; ++jdx) 
     631           { 
     632             globalIndexElement[idx](jdx) = (domList[domainIdx]->i_index)(jdx) + domList[domainIdx]->ni_glo * (domList[domainIdx]->j_index)(jdx); 
     633           } 
     634           elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); 
     635           ++domainIdx; 
    614636         } 
    615          elementGlobalSize = domList[domainIdx]->ni_glo.getValue() * domList[domainIdx]->nj_glo.getValue(); 
    616          ++domainIdx; 
     637         else if (1 == axis_domain_order(idx))  // This is axis 
     638         { 
     639           elementSize = axisList[axisIdx]->index.numElements(); 
     640           globalIndexElement[idx].resize(elementSize); 
     641           for (int jdx = 0; jdx < elementSize; ++jdx) 
     642           { 
     643             globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); 
     644           } 
     645           elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); 
     646           ++axisIdx; 
     647         } 
     648         else  // Of course, this is scalar 
     649         { 
     650           globalIndexElement[idx].resize(1); 
     651           globalIndexElement[idx](0) = 0; 
     652           elementGlobalSize = 1; 
     653         } 
     654         globalSize *= elementGlobalSize; 
    617655       } 
    618        else if (1 == axis_domain_order(idx))  // This is axis 
     656 
     657       std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); 
     658       std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); 
     659       CArray<int,1> nbIndexOnServer(serverSize); // Number of distributed global index held by each client for each server 
     660       // Number of temporary distributed global index held by each client for each server 
     661       // We have this variable for the case of non-distributed element (often axis) to check the duplicate server rank 
     662       CArray<int,1> nbIndexOnServerTmp(serverSize); 
     663       for (int idx = 0; idx < nbElement; ++idx) 
    619664       { 
    620          elementSize = axisList[axisIdx]->index.numElements(); 
    621          globalIndexElement[idx].resize(elementSize); 
    622          for (int jdx = 0; jdx < elementSize; ++jdx) 
     665         nbIndexOnServer = 0; 
     666         const boost::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; 
     667         const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; 
     668         CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); 
     669         clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); 
     670         const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); 
     671         CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), 
     672                                                                      ite = globalIndexElementOnServerMap.end(), it; 
     673         for (it = itb; it != ite; ++it) 
    623674         { 
    624            globalIndexElement[idx](jdx) = (axisList[axisIdx]->index)(jdx); 
     675           const std::vector<int>& tmp = it->second; 
     676           nbIndexOnServerTmp = 0; 
     677           for (int i = 0; i < tmp.size(); ++i) 
     678           { 
     679             if (0 == nbIndexOnServerTmp(tmp[i])) ++nbIndexOnServerTmp(tmp[i]); 
     680           } 
     681           nbIndexOnServer += nbIndexOnServerTmp; 
    625682         } 
    626          elementGlobalSize = axisList[axisIdx]->n_glo.getValue(); 
    627          ++axisIdx; 
    628        } 
    629        else  // Of course, this is scalar 
    630        { 
    631          globalIndexElement[idx].resize(1); 
    632          globalIndexElement[idx](0) = 0; 
    633          elementGlobalSize = 1; 
    634        } 
    635        globalSize *= elementGlobalSize; 
    636      } 
    637  
    638      std::vector<std::vector<bool> > elementOnServer(nbElement, std::vector<bool>(serverSize, false)); 
    639      std::vector<boost::unordered_map<int,std::vector<size_t> > > globalElementIndexOnServer(nbElement); 
    640      CArray<int,1> nbIndexOnServer(serverSize); // Number of distributed global index held by each client for each server 
    641      // Number of temporary distributed global index held by each client for each server 
    642      // We have this variable for the case of non-distributed element (often axis) to check the duplicate server rank 
    643      CArray<int,1> nbIndexOnServerTmp(serverSize); 
    644      for (int idx = 0; idx < nbElement; ++idx) 
    645      { 
    646        nbIndexOnServer = 0; 
    647        const boost::unordered_map<size_t,std::vector<int> >& indexServerElement = indexServerOnElement[idx]; 
    648        const CArray<size_t,1>& globalIndexElementOnClient = globalIndexElement[idx]; 
    649        CClientClientDHTInt clientClientDHT(indexServerElement, client->intraComm); 
    650        clientClientDHT.computeIndexInfoMapping(globalIndexElementOnClient); 
    651        const CClientClientDHTInt::Index2VectorInfoTypeMap& globalIndexElementOnServerMap = clientClientDHT.getInfoIndexMap(); 
    652        CClientClientDHTInt::Index2VectorInfoTypeMap::const_iterator itb = globalIndexElementOnServerMap.begin(), 
    653                                                                     ite = globalIndexElementOnServerMap.end(), it; 
    654        for (it = itb; it != ite; ++it) 
    655        { 
    656          const std::vector<int>& tmp = it->second; 
    657          nbIndexOnServerTmp = 0; 
    658          for (int i = 0; i < tmp.size(); ++i) 
     683 
     684         for (int i = 0; i < serverSize; ++i) 
    659685         { 
    660            if (0 == nbIndexOnServerTmp(tmp[i])) ++nbIndexOnServerTmp(tmp[i]); 
     686           if (0 != nbIndexOnServer(i)) 
     687           { 
     688             globalElementIndexOnServer[idx][i].resize(nbIndexOnServer(i)); 
     689             elementOnServer[idx][i] = true; 
     690           } 
    661691         } 
    662          nbIndexOnServer += nbIndexOnServerTmp; 
    663        } 
    664  
    665        for (int i = 0; i < serverSize; ++i) 
    666        { 
    667          if (0 != nbIndexOnServer(i)) 
     692 
     693         nbIndexOnServer = 0; 
     694         for (it = itb; it != ite; ++it) 
    668695         { 
    669            globalElementIndexOnServer[idx][i].resize(nbIndexOnServer(i)); 
    670            elementOnServer[idx][i] = true; 
     696           const std::vector<int>& tmp = it->second; 
     697           nbIndexOnServerTmp = 0; 
     698           for (int i = 0; i < tmp.size(); ++i) 
     699           { 
     700             if (0 == nbIndexOnServerTmp(tmp[i])) 
     701             { 
     702               globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer(tmp[i])] = it->first; 
     703               ++nbIndexOnServerTmp(tmp[i]); 
     704             } 
     705           } 
     706           nbIndexOnServer += nbIndexOnServerTmp; 
    671707         } 
    672708       } 
    673709 
    674        nbIndexOnServer = 0; 
    675        for (it = itb; it != ite; ++it) 
    676        { 
    677          const std::vector<int>& tmp = it->second; 
    678          nbIndexOnServerTmp = 0; 
    679          for (int i = 0; i < tmp.size(); ++i) 
    680          { 
    681            if (0 == nbIndexOnServerTmp(tmp[i])) 
    682            { 
    683              globalElementIndexOnServer[idx][tmp[i]][nbIndexOnServer(tmp[i])] = it->first; 
    684              ++nbIndexOnServerTmp(tmp[i]); 
    685            } 
    686          } 
    687          nbIndexOnServer += nbIndexOnServerTmp; 
    688        } 
     710      // Determine server which contain global source index 
     711      std::vector<bool> intersectedProc(serverSize, true); 
     712      for (int idx = 0; idx < nbElement; ++idx) 
     713      { 
     714        std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), 
     715                       intersectedProc.begin(), intersectedProc.begin(), 
     716                       std::logical_and<bool>()); 
     717      } 
     718 
     719      std::vector<int> srcRank; 
     720      for (int idx = 0; idx < serverSize; ++idx) 
     721      { 
     722        if (intersectedProc[idx]) srcRank.push_back(idx); 
     723      } 
     724 
     725      // Compute the global index of grid from global index of each element. 
     726      for (int i = 0; i < srcRank.size(); ++i) 
     727      { 
     728        size_t ssize = 1; 
     729        int rankSrc = srcRank[i]; 
     730        std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); 
     731        std::vector<size_t> currentIndex(nbElement,0); 
     732        for (int idx = 0; idx < nbElement; ++idx) 
     733        { 
     734          ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); 
     735          globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); 
     736        } 
     737        globalIndexOnServer[rankSrc].resize(ssize); 
     738 
     739        std::vector<int> idxLoop(nbElement,0); 
     740        int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); 
     741        size_t idx = 0; 
     742        while (idx < ssize) 
     743        { 
     744          for (int ind = 0; ind < nbElement; ++ind) 
     745          { 
     746            if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) 
     747            { 
     748              idxLoop[ind] = 0; 
     749              ++idxLoop[ind+1]; 
     750            } 
     751 
     752            currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; 
     753          } 
     754 
     755          for (int ind = 0; ind < innnerLoopSize; ++ind) 
     756          { 
     757            currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; 
     758            size_t globalSrcIndex = 0; 
     759            for (int idxElement = 0; idxElement < nbElement; ++idxElement) 
     760            { 
     761              globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; 
     762            } 
     763            globalIndexOnServer[rankSrc][idx] = globalSrcIndex; 
     764            ++idx; 
     765            ++idxLoop[0]; 
     766          } 
     767        } 
     768      } 
    689769     } 
    690  
    691     // Determine server which contain global source index 
    692     std::vector<bool> intersectedProc(serverSize, true); 
    693     for (int idx = 0; idx < nbElement; ++idx) 
    694     { 
    695       std::transform(elementOnServer[idx].begin(), elementOnServer[idx].end(), 
    696                      intersectedProc.begin(), intersectedProc.begin(), 
    697                      std::logical_and<bool>()); 
    698     } 
    699  
    700     std::vector<int> srcRank; 
    701     for (int idx = 0; idx < serverSize; ++idx) 
    702     { 
    703       if (intersectedProc[idx]) srcRank.push_back(idx); 
    704     } 
    705  
    706     // Compute the global index of grid from global index of each element. 
    707     for (int i = 0; i < srcRank.size(); ++i) 
    708     { 
    709       size_t ssize = 1; 
    710       int rankSrc = srcRank[i]; 
    711       std::vector<std::vector<size_t>* > globalIndexOfElementTmp(nbElement); 
    712       std::vector<size_t> currentIndex(nbElement,0); 
    713       for (int idx = 0; idx < nbElement; ++idx) 
    714       { 
    715         ssize *= (globalElementIndexOnServer[idx][rankSrc]).size(); 
    716         globalIndexOfElementTmp[idx] = &(globalElementIndexOnServer[idx][rankSrc]); 
    717       } 
    718       globalIndexOnServer[rankSrc].resize(ssize); 
    719  
    720       std::vector<int> idxLoop(nbElement,0); 
    721       int innnerLoopSize = (globalIndexOfElementTmp[0])->size(); 
    722       size_t idx = 0; 
    723       while (idx < ssize) 
    724       { 
    725         for (int ind = 0; ind < nbElement; ++ind) 
    726         { 
    727           if (idxLoop[ind] == (globalIndexOfElementTmp[ind])->size()) 
    728           { 
    729             idxLoop[ind] = 0; 
    730             ++idxLoop[ind+1]; 
    731           } 
    732  
    733           currentIndex[ind] = (*(globalIndexOfElementTmp[ind]))[idxLoop[ind]]; 
    734         } 
    735  
    736         for (int ind = 0; ind < innnerLoopSize; ++ind) 
    737         { 
    738           currentIndex[0] = (*globalIndexOfElementTmp[0])[ind]; 
    739           size_t globalSrcIndex = 0; 
    740           for (int idxElement = 0; idxElement < nbElement; ++idxElement) 
    741           { 
    742             globalSrcIndex += currentIndex[idxElement] * elementNGlobal[idxElement]; 
    743           } 
    744           globalIndexOnServer[rankSrc][idx] = globalSrcIndex; 
    745           ++idx; 
    746           ++idxLoop[0]; 
    747         } 
    748       } 
    749     } 
    750770   } 
    751771   //---------------------------------------------------------------- 
     
    9861006  { 
    9871007    CContext* context = CContext::getCurrent(); 
    988     CContextClient* client = context->hasServer ? context->clientPrimServer : context->client; 
    989  
    990     storeIndex_client.resize(1); 
    991     storeIndex_client(0) = 0; 
    992  
    993     connectedServerRank_.clear(); 
    994  
    995     if (0 == client->clientRank) 
    996     { 
    997       for (int rank = 0; rank < client->serverSize; ++rank) 
    998       { 
    999         connectedServerRank_.push_back(rank); 
    1000         connectedDataSize_[rank] = 1; 
    1001         nbSenders[rank] = 1; 
    1002       } 
    1003     } 
    1004     isDataDistributed_ = false; 
     1008    int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     1009    for (int i = 0; i < nbSrvPools; ++i) 
     1010    { 
     1011      CContextClient* client = context->hasServer ? context->clientPrimServer[i] : context->client; 
     1012 
     1013      storeIndex_client.resize(1); 
     1014      storeIndex_client(0) = 0; 
     1015 
     1016      connectedServerRank_.clear(); 
     1017 
     1018      if (0 == client->clientRank) 
     1019      { 
     1020        for (int rank = 0; rank < client->serverSize; ++rank) 
     1021        { 
     1022          connectedServerRank_.push_back(rank); 
     1023          connectedDataSize_[rank] = 1; 
     1024          nbSenders[rank] = 1; 
     1025        } 
     1026      } 
     1027      isDataDistributed_ = false; 
     1028    } 
    10051029  } 
    10061030 
     
    10421066  { 
    10431067    CContext* context = CContext::getCurrent(); 
    1044     CContextClient* client = context->hasServer ? context->clientPrimServer : context->client; 
    1045  
    1046     CEventClient event(getType(), EVENT_ID_INDEX); 
    1047     list<CMessage> listMsg; 
    1048     list<CArray<size_t,1> > listOutIndex; 
    1049  
    1050     if (client->isServerLeader()) 
    1051     { 
    1052       const std::list<int>& ranks = client->getRanksServerLeader(); 
    1053       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    1054       { 
    1055         int rank = *itRank; 
    1056         int nb = 1; 
    1057         storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(nb))); 
    1058         listOutIndex.push_back(CArray<size_t,1>(nb)); 
    1059  
    1060         CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; 
    1061         CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 
    1062  
    1063         for (int k = 0; k < nb; ++k) 
    1064         { 
    1065           outGlobalIndexOnServer(k) = 0; 
    1066           outLocalIndexToServer(k)  = 0; 
    1067         } 
    1068  
    1069         listMsg.push_back(CMessage()); 
    1070         listMsg.back() << getId( )<< isDataDistributed_ << isCompressible_ << listOutIndex.back(); 
    1071  
    1072         event.push(rank, 1, listMsg.back()); 
    1073       } 
    1074       client->sendEvent(event); 
    1075     } 
    1076     else 
    1077       client->sendEvent(event); 
    1078   } 
    1079  
    1080   void CGrid::sendIndex(void) 
    1081   { 
    1082     CContext* context = CContext::getCurrent(); 
    1083 //    CContextClient* client = context->client; 
    1084     CContextClient* client = context->hasServer ? context->clientPrimServer : context->client ; 
    1085  
    1086     CEventClient event(getType(), EVENT_ID_INDEX); 
    1087     int rank; 
    1088     list<CMessage> listMsg; 
    1089     list<CArray<size_t,1> > listOutIndex; 
    1090     const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 
    1091     CDistributionClient::GlobalLocalDataMap::const_iterator itIndex = globalLocalIndexSendToServer.begin(), 
    1092                                                            iteIndex = globalLocalIndexSendToServer.end(); 
    1093  
    1094     if (!doGridHaveDataDistributed()) 
    1095     { 
     1068    int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     1069    for (int i = 0; i < nbSrvPools; ++i) 
     1070    { 
     1071      CContextClient* client = context->hasServer ? context->clientPrimServer[i] : context->client; 
     1072 
     1073      CEventClient event(getType(), EVENT_ID_INDEX); 
     1074      list<CMessage> listMsg; 
     1075      list<CArray<size_t,1> > listOutIndex; 
     1076 
    10961077      if (client->isServerLeader()) 
    10971078      { 
    1098         int indexSize = globalLocalIndexSendToServer.size(); 
    1099         CArray<size_t,1> outGlobalIndexOnServer(indexSize); 
    1100         CArray<int,1> outLocalIndexToServer(indexSize); 
    1101         for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) 
    1102         { 
    1103           outGlobalIndexOnServer(idx) = itIndex->first; 
    1104           outLocalIndexToServer(idx) = itIndex->second; 
    1105         } 
    1106  
    1107         //int nbClient = client->clientSize; // This stupid variable signals the servers the number of client connect to them 
    11081079        const std::list<int>& ranks = client->getRanksServerLeader(); 
    11091080        for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    11101081        { 
    1111           storeIndex_toSrv.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 
    1112           listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); 
     1082          int rank = *itRank; 
     1083          int nb = 1; 
     1084          storeIndex_toSrv.insert(std::make_pair(rank, CArray<int,1>(nb))); 
     1085          listOutIndex.push_back(CArray<size_t,1>(nb)); 
     1086 
     1087          CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; 
     1088          CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 
     1089 
     1090          for (int k = 0; k < nb; ++k) 
     1091          { 
     1092            outGlobalIndexOnServer(k) = 0; 
     1093            outLocalIndexToServer(k)  = 0; 
     1094          } 
     1095 
     1096          listMsg.push_back(CMessage()); 
     1097          listMsg.back() << getId( )<< isDataDistributed_ << isCompressible_ << listOutIndex.back(); 
     1098 
     1099          event.push(rank, 1, listMsg.back()); 
     1100        } 
     1101        client->sendEvent(event); 
     1102      } 
     1103      else 
     1104        client->sendEvent(event); 
     1105    } 
     1106  } 
     1107 
     1108  void CGrid::sendIndex(void) 
     1109  { 
     1110    CContext* context = CContext::getCurrent(); 
     1111//    CContextClient* client = context->client; 
     1112    int nbSrvPools = (context->hasServer) ? context->clientPrimServer.size() : 1; 
     1113    for (int i = 0; i < nbSrvPools; ++i) 
     1114    { 
     1115      CContextClient* client = context->hasServer ? context->clientPrimServer[i] : context->client ; 
     1116 
     1117      CEventClient event(getType(), EVENT_ID_INDEX); 
     1118      int rank; 
     1119      list<CMessage> listMsg; 
     1120      list<CArray<size_t,1> > listOutIndex; 
     1121      const CDistributionClient::GlobalLocalDataMap& globalLocalIndexSendToServer = clientDistribution_->getGlobalLocalDataSendToServer(); 
     1122      CDistributionClient::GlobalLocalDataMap::const_iterator itIndex = globalLocalIndexSendToServer.begin(), 
     1123                                                             iteIndex = globalLocalIndexSendToServer.end(); 
     1124 
     1125      if (!doGridHaveDataDistributed()) 
     1126      { 
     1127        if (client->isServerLeader()) 
     1128        { 
     1129          int indexSize = globalLocalIndexSendToServer.size(); 
     1130          CArray<size_t,1> outGlobalIndexOnServer(indexSize); 
     1131          CArray<int,1> outLocalIndexToServer(indexSize); 
     1132          for (int idx = 0; itIndex != iteIndex; ++itIndex, ++idx) 
     1133          { 
     1134            outGlobalIndexOnServer(idx) = itIndex->first; 
     1135            outLocalIndexToServer(idx) = itIndex->second; 
     1136          } 
     1137 
     1138          //int nbClient = client->clientSize; // This stupid variable signals the servers the number of client connect to them 
     1139          const std::list<int>& ranks = client->getRanksServerLeader(); 
     1140          for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
     1141          { 
     1142            storeIndex_toSrv.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer))); 
     1143            listOutIndex.push_back(CArray<size_t,1>(outGlobalIndexOnServer)); 
     1144 
     1145            listMsg.push_back(CMessage()); 
     1146            listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); 
     1147 
     1148            event.push(*itRank, 1, listMsg.back()); 
     1149          } 
     1150          client->sendEvent(event); 
     1151        } 
     1152        else 
     1153          client->sendEvent(event); 
     1154      } 
     1155      else 
     1156      { 
     1157        CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; 
     1158        itGlobalMap = globalIndexOnServer_.begin(); 
     1159        iteGlobalMap = globalIndexOnServer_.end(); 
     1160 
     1161        std::map<int,std::vector<int> >localIndexTmp; 
     1162        std::map<int,std::vector<size_t> > globalIndexTmp; 
     1163        for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
     1164        { 
     1165          int serverRank = itGlobalMap->first; 
     1166          int indexSize = itGlobalMap->second.size(); 
     1167          const std::vector<size_t>& indexVec = itGlobalMap->second; 
     1168          for (int idx = 0; idx < indexSize; ++idx) 
     1169          { 
     1170            itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); 
     1171            if (iteIndex != itIndex) 
     1172            { 
     1173              globalIndexTmp[serverRank].push_back(itIndex->first); 
     1174              localIndexTmp[serverRank].push_back(itIndex->second); 
     1175            } 
     1176          } 
     1177        } 
     1178 
     1179//        for (int ns = 0; ns < connectedServerRank_.size(); ++ns) 
     1180        for (int ns = 0; ns < client->serverSize; ++ns) 
     1181        { 
     1182          rank = connectedServerRank_[ns]; 
     1183          int nb = 0; 
     1184          if (globalIndexTmp.end() != globalIndexTmp.find(rank)) 
     1185            nb = globalIndexTmp[rank].size(); 
     1186 
     1187          storeIndex_toSrv.insert(make_pair(rank, CArray<int,1>(nb))); 
     1188          listOutIndex.push_back(CArray<size_t,1>(nb)); 
     1189 
     1190          CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; 
     1191          CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 
     1192 
     1193          for (int k = 0; k < nb; ++k) 
     1194          { 
     1195            outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); 
     1196            outLocalIndexToServer(k)  = localIndexTmp[rank].at(k); 
     1197          } 
    11131198 
    11141199          listMsg.push_back(CMessage()); 
    11151200          listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); 
    11161201 
    1117           event.push(*itRank, 1, listMsg.back()); 
    1118         } 
     1202          event.push(rank, nbSenders[rank], listMsg.back()); 
     1203        } 
     1204 
    11191205        client->sendEvent(event); 
    11201206      } 
    1121       else 
    1122         client->sendEvent(event); 
    1123     } 
    1124     else 
    1125     { 
    1126       CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itGlobalMap; 
    1127       itGlobalMap = globalIndexOnServer_.begin(); 
    1128       iteGlobalMap = globalIndexOnServer_.end(); 
    1129  
    1130       std::map<int,std::vector<int> >localIndexTmp; 
    1131       std::map<int,std::vector<size_t> > globalIndexTmp; 
    1132       for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
    1133       { 
    1134         int serverRank = itGlobalMap->first; 
    1135         int indexSize = itGlobalMap->second.size(); 
    1136         const std::vector<size_t>& indexVec = itGlobalMap->second; 
    1137         for (int idx = 0; idx < indexSize; ++idx) 
    1138         { 
    1139           itIndex = globalLocalIndexSendToServer.find(indexVec[idx]); 
    1140           if (iteIndex != itIndex) 
    1141           { 
    1142             globalIndexTmp[serverRank].push_back(itIndex->first); 
    1143             localIndexTmp[serverRank].push_back(itIndex->second); 
    1144           } 
    1145         } 
    1146       } 
    1147  
    1148       for (int ns = 0; ns < connectedServerRank_.size(); ++ns) 
    1149       { 
    1150         rank = connectedServerRank_[ns]; 
    1151         int nb = 0; 
    1152         if (globalIndexTmp.end() != globalIndexTmp.find(rank)) 
    1153           nb = globalIndexTmp[rank].size(); 
    1154  
    1155         storeIndex_toSrv.insert(make_pair(rank, CArray<int,1>(nb))); 
    1156         listOutIndex.push_back(CArray<size_t,1>(nb)); 
    1157  
    1158         CArray<int, 1>& outLocalIndexToServer = storeIndex_toSrv[rank]; 
    1159         CArray<size_t, 1>& outGlobalIndexOnServer = listOutIndex.back(); 
    1160  
    1161         for (int k = 0; k < nb; ++k) 
    1162         { 
    1163           outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); 
    1164           outLocalIndexToServer(k)  = localIndexTmp[rank].at(k); 
    1165         } 
    1166  
    1167         listMsg.push_back(CMessage()); 
    1168         listMsg.back() << getId() << isDataDistributed_ << isCompressible_ << listOutIndex.back(); 
    1169  
    1170         event.push(rank, nbSenders[rank], listMsg.back()); 
    1171       } 
    1172  
    1173       client->sendEvent(event); 
    11741207    } 
    11751208  } 
     
    12021235  { 
    12031236    CContext* context = CContext::getCurrent(); 
    1204     CContextServer* server = (context->hasServer) ? context->server : context->serverPrimServer; 
    1205     CContextClient* client = (context->hasServer) ? context->client : context->clientPrimServer; 
     1237//    CContextServer* server = (context->hasServer) ? context->server : context->serverPrimServer; 
     1238//    CContextClient* client = (context->hasServer) ? context->client : context->clientPrimServer; 
     1239    CContextServer* server = context->server; 
     1240    CContextClient* client = context->client; 
    12061241    numberWrittenIndexes_ = totalNumberWrittenIndexes_ = offsetWrittenIndexes_ = 0; 
    12071242    connectedServerRank_ = ranks; 
Note: See TracChangeset for help on using the changeset viewer.