Ignore:
Timestamp:
04/01/15 17:53:02 (9 years ago)
Author:
mhnguyen
Message:

Fixing some bugs on writting non-distributed data

+) Implement scalar grid: Allow to send scalar real data
+) Modify the way to compute the mapping of buffer size from one client to a server
+) Fix a bug of writting axis on one_file mode
+) Make some changes in test_new_features.f90 and test_complete.f90

Test
+) On Curie,
+) test_client and test_complete pass and results are correct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/node/grid.cpp

    • Property svn:executable set to *
    r585 r586  
    2424      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    2525      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() 
    26       , connectedDataSize_(), connectedServerRank_() 
     26      , connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true) 
    2727   { 
    2828     setVirtualDomainGroup(); 
     
    3535      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    3636      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(0), writtenDataSize_(0), globalDim_() 
    37       , connectedDataSize_(), connectedServerRank_() 
     37      , connectedDataSize_(), connectedServerRank_(), isDataDistributed_(true) 
    3838   { 
    3939     setVirtualDomainGroup(); 
     
    166166   StdSize CGrid::getDataSize(void) const 
    167167   { 
     168     StdSize retvalue = 1; 
     169     if (true == scalar_grid.getValue()) return retvalue; 
    168170      std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); 
    169       StdSize retvalue = 1; 
     171 
    170172      for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; 
    171173      return (retvalue); 
     
    175177   { 
    176178     double secureFactor = 2.5 * sizeof(double) * CXios::bufferServerFactorSize; 
    177      StdSize retVal; 
     179     StdSize retVal = 1; 
    178180     std::map<int, StdSize> ret; 
    179      std::map<int, size_t >::const_iterator it = connectedDataSize_.begin(), itE = connectedDataSize_.end(); 
    180      for (; it != itE; ++it) 
     181     std::map<int, size_t >::const_iterator itb = connectedDataSize_.begin(), it, itE = connectedDataSize_.end(); 
     182 
     183     if (true == scalar_grid.getValue()) 
     184     { 
     185       for (it = itb; it != itE; ++it) 
     186       { 
     187         retVal *= secureFactor; 
     188         ret.insert(std::make_pair(it->first, retVal)); 
     189       } 
     190       return ret; 
     191     } 
     192 
     193     for (it = itb; it != itE; ++it) 
    181194     { 
    182195        retVal = it->second; 
     
    185198     } 
    186199 
     200     if (connectedDataSize_.empty()) 
     201     { 
     202       for (int i = 0; i < connectedServerRank_.size(); ++i) 
     203       { 
     204         retVal = 1; 
     205         retVal *= secureFactor; 
     206         ret.insert(std::make_pair<int,StdSize>(connectedServerRank_[i], retVal)); 
     207       } 
     208     } 
     209 
    187210     return ret; 
    188211   } 
     
    203226     CContext* context = CContext::getCurrent() ; 
    204227     CContextClient* client=context->client ; 
     228 
     229     if (true == scalar_grid) 
     230     { 
     231       if (context->hasClient) 
     232          if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndexScalarGrid(); this->isIndexSent = true; } 
     233 
     234       if (this->isChecked) return; 
     235       if (context->hasClient) 
     236       { 
     237          this->computeIndexScalarGrid(); 
     238       } 
     239 
     240       this->isChecked = true; 
     241       return; 
     242     } 
    205243 
    206244     if (context->hasClient) 
     
    315353     // First of all, compute distribution on client side 
    316354     clientDistribution_ = new CDistributionClient(client->clientRank, this); 
     355     // Get local data index on client 
     356     storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); 
     357     storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 
     358     isDataDistributed_= clientDistribution_->isDataDistributed(); 
     359 
     360     if (!doGridHaveDataDistributed()) 
     361     { 
     362        if (0 == client->clientRank) 
     363        { 
     364          size_t ssize = clientDistribution_->getLocalDataIndexOnClient().numElements(); 
     365          for (int rank = 0; rank < client->serverSize; ++rank) 
     366            connectedDataSize_[rank] = ssize; 
     367        } 
     368        return; 
     369     } 
     370 
     371     // Compute mapping between client and server 
    317372     size_t globalSizeIndex = 1, indexBegin, indexEnd; 
    318373     int range, clientSize = client->clientSize; 
     
    377432 
    378433    nbSenders = clientServerMap_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
    379  
    380      // Get local data index on client 
    381      storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); 
    382      storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 
    383434   } 
    384435 
     
    409460      if (!domains.empty()) for (int i = 0; i < domains.size(); ++i) new_id += domains[i]->getId() + StdString("_"); 
    410461      if (!axis.empty()) for (int i = 0; i < axis.size(); ++i) new_id += axis[i]->getId() + StdString("_") ; 
     462      if (domains.empty() && axis.empty()) new_id += StdString("scalar_grid"); 
    411463      new_id += StdString("_"); 
    412464 
     
    427479      } 
    428480 
    429       grid->computeGridGlobalDimension(domains, axis, grid->axis_domain_order); 
     481      if (domains.empty() && axis.empty()) grid->scalar_grid = true; 
     482      else grid->scalar_grid = false; 
     483 
     484      grid->computeGridGlobalDimension(domains, axis, grid->axisDomainOrder); 
    430485 
    431486      return (grid); 
     
    463518      for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; 
    464519   } 
     520 
     521  void CGrid::computeIndexScalarGrid() 
     522  { 
     523    CContext* context = CContext::getCurrent(); 
     524    CContextClient* client=context->client; 
     525 
     526    storeIndex_client.resize(1); 
     527    storeIndex_client[0] = 0; 
     528    if (0 == client->clientRank) 
     529    { 
     530      for (int rank = 0; rank < client->serverSize; ++rank) 
     531        connectedDataSize_[rank] = 1; 
     532    } 
     533    isDataDistributed_ = false; 
     534  } 
     535 
     536  void CGrid::sendIndexScalarGrid() 
     537  { 
     538    CContext* context = CContext::getCurrent() ; 
     539    CContextClient* client=context->client ; 
     540 
     541    CEventClient event(getType(),EVENT_ID_INDEX); 
     542    list<shared_ptr<CMessage> > list_msg ; 
     543    list< CArray<size_t,1>* > listOutIndex; 
     544    if (0 == client->clientRank) 
     545    { 
     546      for (int rank = 0; rank < client->serverSize; ++rank) 
     547      { 
     548        int nb = 1; 
     549        CArray<size_t, 1> outGlobalIndexOnServer(nb); 
     550        CArray<int, 1> outLocalIndexToServer(nb); 
     551        for (int k = 0; k < nb; ++k) 
     552        { 
     553          outGlobalIndexOnServer(k) = 0; 
     554          outLocalIndexToServer(k)  = 0; 
     555        } 
     556 
     557        storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 
     558        listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 
     559 
     560        list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
     561        *list_msg.back()<<getId()<<isDataDistributed_<<*listOutIndex.back(); 
     562 
     563        event.push(rank, 1, *list_msg.back()); 
     564      } 
     565      client->sendEvent(event); 
     566    } 
     567    else 
     568      client->sendEvent(event); 
     569 
     570    for(list<CArray<size_t,1>* >::iterator it=listOutIndex.begin();it!=listOutIndex.end();++it) delete *it ; 
     571  } 
    465572 
    466573  void CGrid::sendIndex(void) 
     
    477584    const CArray<size_t,1>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 
    478585 
    479     std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
    480     itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 
    481     iteGlobalMap = globalIndexOnServer.end(); 
    482  
    483     int nbGlobalIndex = globalIndexSendToServer.numElements(); 
    484     std::map<int,std::vector<int> >localIndexTmp; 
    485     std::map<int,std::vector<size_t> > globalIndexTmp; 
    486     for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
    487     { 
    488       int serverRank = itGlobalMap->first; 
    489       std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), 
    490                                           iteVecGlobal = (itGlobalMap->second).end(); 
    491       for (int i = 0; i < nbGlobalIndex; ++i) 
    492       { 
    493         if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i))) 
    494         { 
    495           globalIndexTmp[serverRank].push_back(globalIndexSendToServer(i)); 
    496           localIndexTmp[serverRank].push_back(localIndexSendToServer(i)); 
    497         } 
    498       } 
    499     } 
    500  
    501  
    502586    if (!doGridHaveDataDistributed()) 
    503587    { 
    504588      if (0 == client->clientRank) 
    505589      { 
     590        CArray<size_t, 1> outGlobalIndexOnServer = globalIndexSendToServer; 
     591        CArray<int,1> outLocalIndexToServer = localIndexSendToServer; 
    506592        for (rank = 0; rank < client->serverSize; ++rank) 
    507593        { 
    508           int nb = 0; 
    509           if (globalIndexTmp.end() != globalIndexTmp.find(rank)) 
    510             nb = globalIndexTmp[rank].size(); 
    511  
    512           CArray<size_t, 1> outGlobalIndexOnServer(nb); 
    513           CArray<int, 1> outLocalIndexToServer(nb); 
    514           for (int k = 0; k < nb; ++k) 
    515           { 
    516             outGlobalIndexOnServer(k) = globalIndexTmp[rank].at(k); 
    517             outLocalIndexToServer(k)  = localIndexTmp[rank].at(k); 
    518           } 
    519  
    520           storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 
     594          storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer))); 
    521595          listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 
    522596 
    523597          list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
    524           *list_msg.back()<<getId()<<*listOutIndex.back(); 
     598          *list_msg.back()<<getId()<<isDataDistributed_<<*listOutIndex.back(); 
    525599 
    526600          event.push(rank, 1, *list_msg.back()); 
     
    533607    else 
    534608    { 
     609      std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
     610      itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 
     611      iteGlobalMap = globalIndexOnServer.end(); 
     612 
     613      int nbGlobalIndex = globalIndexSendToServer.numElements(); 
     614      std::map<int,std::vector<int> >localIndexTmp; 
     615      std::map<int,std::vector<size_t> > globalIndexTmp; 
     616      for (; itGlobalMap != iteGlobalMap; ++itGlobalMap) 
     617      { 
     618        int serverRank = itGlobalMap->first; 
     619        std::vector<size_t>::const_iterator itbVecGlobal = (itGlobalMap->second).begin(), 
     620                                            iteVecGlobal = (itGlobalMap->second).end(); 
     621        for (int i = 0; i < nbGlobalIndex; ++i) 
     622        { 
     623          if (iteVecGlobal != std::find(itbVecGlobal, iteVecGlobal, globalIndexSendToServer(i))) 
     624          { 
     625            globalIndexTmp[serverRank].push_back(globalIndexSendToServer(i)); 
     626            localIndexTmp[serverRank].push_back(localIndexSendToServer(i)); 
     627          } 
     628        } 
     629      } 
     630 
    535631      for (int ns = 0; ns < connectedServerRank_.size(); ++ns) 
    536632      { 
     
    552648 
    553649        list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
    554         *list_msg.back()<<getId()<<*listOutIndex.back(); 
     650        *list_msg.back()<<getId()<<isDataDistributed_<<*listOutIndex.back(); 
    555651 
    556652        event.push(rank, nbSenders[rank], *list_msg.back()); 
     
    612708  bool CGrid::doGridHaveDataToWrite() 
    613709  { 
    614 //    return (0 != serverDistribution_); 
    615     return (0 != writtenDataSize_); 
     710    size_t ssize = 0; 
     711    for (map<int, CArray<size_t, 1>* >::const_iterator it = outIndexFromClient.begin(); 
     712                                                       it != outIndexFromClient.end(); ++it) 
     713    { 
     714      ssize += (it->second)->numElements(); 
     715    } 
     716    return (0 != ssize); 
    616717  } 
    617718 
     
    627728  } 
    628729 
    629  
    630730  const CDistributionServer* CGrid::getDistributionServer() const 
    631731  { 
     
    635735  bool CGrid::doGridHaveDataDistributed() 
    636736  { 
    637     return clientDistribution_->isDataDistributed(); 
     737    if (true == scalar_grid.getValue()) return false; 
     738    else 
     739      return isDataDistributed_; 
    638740  } 
    639741 
    640742  void CGrid::recvIndex(int rank, CBufferIn& buffer) 
    641743  { 
     744    CContext* context = CContext::getCurrent() ; 
     745    CContextServer* server=context->server ; 
     746    buffer>>isDataDistributed_; 
     747    size_t dataSize = 0; 
     748 
     749    if (true == scalar_grid) 
     750    { 
     751       writtenDataSize_ = 1; 
     752       CArray<size_t,1> outIndex; 
     753       buffer>>outIndex; 
     754       outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 
     755       std::vector<int> nZoomBegin(1,0), nZoomSize(1,1), nGlob(1,1), nZoomBeginGlobal(1,0); 
     756       serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, 
     757                                                     nZoomBeginGlobal, nGlob); 
     758       return; 
     759    } 
     760 
     761 
    642762     if (0 == serverDistribution_) 
    643763     { 
    644        CContext* context = CContext::getCurrent() ; 
    645        CContextServer* server=context->server ; 
    646        int idx = 0, numElement = axis_domain_order.numElements(); 
    647764       int ssize = numElement; 
    648765       std::vector<int> indexMap(numElement); 
     
    687804         } 
    688805       } 
    689        writtenDataSize_ = 1; 
     806       dataSize = 1; 
    690807       for (int i = 0; i < nZoomSize.size(); ++i) 
    691         writtenDataSize_ *= nZoomSize[i]; 
     808        dataSize *= nZoomSize[i]; 
    692809 
    693810       serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, 
     
    697814     CArray<size_t,1> outIndex; 
    698815     buffer>>outIndex; 
    699      serverDistribution_->computeLocalIndex(outIndex); 
     816     if (isDataDistributed_) 
     817      serverDistribution_->computeLocalIndex(outIndex); 
     818     else 
     819     { 
     820       dataSize = outIndex.numElements(); 
     821       for (int i = 0; i < outIndex.numElements(); ++i) outIndex(i) = i; 
     822     } 
     823     writtenDataSize_ += dataSize; 
     824 
    700825     outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 
    701826  } 
     
    10811206        axis_domain_order(i) = order[i]; 
    10821207      } 
    1083     } 
     1208      scalar_grid = false; 
     1209    } 
     1210    else scalar_grid = true; 
    10841211 
    10851212    setDomainList(); 
Note: See TracChangeset for help on using the changeset viewer.