Ignore:
Timestamp:
02/11/15 16:23:02 (9 years ago)
Author:
mhnguyen
Message:

Redesigning grid structure

+) Add an intermediate class to calculate distribution on client and servers
+) Change all index of attributes to zero (0), instead of one(1)

Test
+) On Curie
+) Test new features passes but some data are still shifted

File:
1 edited

Legend:

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

    r540 r551  
    2121      , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 
    2222      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    23       , vDomainGroup_(), vAxisGroup_(), axisOrder_(), axisList_(), isAxisListSet(false), isDomListSet(false) 
     23      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    2424   { 
    2525     setVirtualDomainGroup(); 
     
    3131      , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 
    3232      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    33       , vDomainGroup_(), vAxisGroup_(), axisOrder_(), axisList_(), isAxisListSet(false), isDomListSet(false) 
     33      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    3434   { 
    3535     setVirtualDomainGroup(); 
     
    5151    for(map<int,CArray<int,1>* >::iterator it=out_j_fromClient.begin();it!=out_j_fromClient.end();it++) delete it->second ; 
    5252    for(map<int,CArray<int,1>* >::iterator it=out_l_fromClient.begin();it!=out_l_fromClient.end();it++) delete it->second ; 
     53 
     54    for(map<int,CArray<size_t,1>* >::iterator it=outIndexFromClient.begin();it!=outIndexFromClient.end();++it) delete (it->second); 
     55 
     56    if (0 != clientDistribution_) delete clientDistribution_; 
    5357 
    5458   } 
     
    176180   std::map<int, StdSize> CGrid::getConnectedServerDataSize() 
    177181   { 
     182     double secureFactor = 2.5 * sizeof(double) * CXios::bufferServerFactorSize; 
     183     StdSize retVal; 
    178184     std::map<int, StdSize> ret; 
    179      std::map<int, int>::const_iterator it = domConnectedServerSide_.begin(), 
    180                                        itE = domConnectedServerSide_.end(); 
    181      std::vector<int> nData = domain->nbDataSrv; 
    182      std::vector<int>::const_iterator itData = nData.begin(); 
    183      StdSize retVal = StdSize(0.0); 
    184      for (; it != itE; ++it, ++itData) 
     185     const std::map<int, std::vector<int> >& distribution = clientDistribution_->getLocalIndexSendToServer(); 
     186     std::map<int, std::vector<int> >::const_iterator it = distribution.begin(), itE = distribution.end(); 
     187     for (; it != itE; ++it) 
    185188     { 
    186        retVal = (it->second < *itData) ? *itData : it->second; 
    187        if (this->withAxis) retVal *= this->axis->size.getValue(); 
    188        retVal *= sizeof(double); 
    189        retVal *= 2.5 * CXios::bufferServerFactorSize; // Secure factor, myterious number 
    190        ret.insert(make_pair(it->first, retVal)); 
     189        retVal = it->second.size(); 
     190        retVal *= secureFactor; 
     191        ret.insert(std::make_pair<int,StdSize>(it->first, retVal)); 
    191192     } 
     193 
    192194     return ret; 
    193195   } 
     
    235237 
    236238     if (context->hasClient) 
    237       if (this->isChecked && doSendingIndex) sendIndex(); 
     239      if (this->isChecked && doSendingIndex && !isIndexSent) { sendIndex(); this->isIndexSent = true; } 
    238240 
    239241     if (this->isChecked) return; 
     
    397399   void CGrid::computeIndex(void) 
    398400   { 
    399  
     401     CContext* context = CContext::getCurrent() ; 
     402     CContextClient* client=context->client ; 
     403     clientDistribution_ = new CDistributionClient(client->clientRank, this); 
     404     clientDistribution_->computeServerIndexMapping(client->serverSize); 
     405     nbSenders = clientDistribution_->computeConnectedClients(client->serverSize, client->clientSize, client->intraComm); 
     406 
     407     storeIndex_client.resize(clientDistribution_->getLocalDataIndexOnClient().numElements()); 
     408     storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 
     409 
     410/* 
    400411      const int ni   = domain->ni.getValue() , 
    401412                nj   = domain->nj.getValue() , 
     
    476487         } 
    477488      } 
    478       computeDomConServer(); 
     489*/ 
     490//      computeDomConServer(); 
    479491//      sendIndex() ; 
    480492 
     
    520532      grid->setDomainList(domains); 
    521533      grid->setAxisList(axis); 
     534 
     535      //By default, domains are always the first ones of a grid 
     536      if (grid->axisDomainOrder.isEmpty()) 
     537      { 
     538        int size = domains.size()+axis.size(); 
     539        grid->axisDomainOrder.resize(size); 
     540        for (int i = 0; i < size; ++i) 
     541        { 
     542          if (i < domains.size()) grid->axisDomainOrder(i) = true; 
     543          else grid->axisDomainOrder(i) = false; 
     544        } 
     545      } 
     546 
    522547      return (grid); 
    523548   } 
     
    561586      for(StdSize n = 0; n < stored.numElements(); n++) 
    562587         field(out_i(n)) = stored(n) ; 
     588   } 
     589 
     590   void CGrid::outputField(int rank, const CArray<double, 1>& stored, double* field) 
     591   { 
     592     CArray<size_t,1>& out_i=*outIndexFromClient[rank]; 
     593     StdSize numElements = stored.numElements(); 
     594     for (StdSize n = 0; n < numElements; ++n) 
     595     { 
     596       *(field+out_i(n)) = stored(n); 
     597     } 
    563598   } 
    564599 
     
    599634//         if (domain->mapConnectedServer(i,j)==ns)  nb++ ; 
    600635//       } 
    601 // 
    602636//       CArray<int,1> storeIndex(nb) ; 
    603637//       CArray<int,1> out_i(nb) ; 
     
    676710    int rank ; 
    677711    list<shared_ptr<CMessage> > list_msg ; 
    678     list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 
    679  
     712    list< CArray<size_t,1>* > listOutIndex; 
     713 
     714    const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientDistribution_->getGlobalIndexOnServer(); 
     715    const std::map<int, std::vector<int> >& localIndexSendToServer  = clientDistribution_->getLocalIndexSendToServer(); 
     716 
     717    std::map<int, std::vector<size_t> >::const_iterator iteMap, itbMap, itGlobal; 
     718    std::map<int, std::vector<int> >::const_iterator itLocal; 
     719    itbMap = itGlobal = globalIndexOnServer.begin(); 
     720    iteMap = globalIndexOnServer.end(); 
     721    itLocal = localIndexSendToServer.begin(); 
     722 
     723 
     724    for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) 
     725    { 
     726      rank = itGlobal->first; 
     727      int nb = (itGlobal->second).size(); 
     728 
     729      CArray<size_t, 1> outGlobalIndexOnServer(nb); 
     730      CArray<int, 1> outLocalIndexToServer(nb); 
     731      for (int k = 0; k < nb; ++k) 
     732      { 
     733        outGlobalIndexOnServer(k) = itGlobal->second.at(k); 
     734        outLocalIndexToServer(k)  = itLocal->second.at(k); 
     735      } 
     736 
     737      storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 
     738      listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 
     739 
     740      list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
     741      *list_msg.back()<<getId()<<*listOutIndex.back(); 
     742      event.push(rank, nbSenders[rank], *list_msg.back()); 
     743    } 
     744    client->sendEvent(event); 
     745    for(list<CArray<size_t,1>* >::iterator it=listOutIndex.begin();it!=listOutIndex.end();++it) delete *it ; 
     746 
     747/* 
    680748    if (!isDomConServerComputed_) computeDomConServer(); 
    681749 
     
    721789    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 
    722790    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 
    723  
     791*/ 
    724792  } 
    725793 
     
    731799      int rank=it->rank; 
    732800      CBufferIn* buffer=it->buffer; 
    733       string domainId ; 
    734       *buffer>>domainId ; 
    735       get(domainId)->recvIndex(rank,*buffer) ; 
     801      string gridId ; 
     802      *buffer>>gridId ; 
     803      get(gridId)->recvIndex(rank,*buffer) ; 
    736804    } 
    737805  } 
     
    739807  void CGrid::recvIndex(int rank, CBufferIn& buffer) 
    740808  { 
     809     CArray<size_t,1> outIndex; 
     810     buffer>>outIndex; 
     811     outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 
     812 
     813    /* 
    741814    CArray<int,1> out_i ; 
    742815    CArray<int,1> out_j ; 
     
    751824    out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; 
    752825    out_l_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_l) )) ; 
     826    */ 
    753827  } 
    754828 
     
    9471021   } 
    9481022 
     1023  /*! 
     1024  \brief Solve domain and axis references 
     1025  As field, domain and axis can refer to other domains or axis. In order to inherit correctly 
     1026  all attributes from their parents, they should be processed with this function 
     1027  \param[in] apply inherit all attributes of parents (true) 
     1028  */ 
    9491029  void CGrid::solveDomainAxisRefInheritance(bool apply) 
    9501030  { 
     
    9631043        if ((!pDom->domain_ref.isEmpty()) && (pDom->name.isEmpty())) 
    9641044          pDom->name.setValue(pDom->getBaseDomainReference()->getId()); 
    965  
    9661045      } 
    9671046    } 
     
    9821061  } 
    9831062 
     1063  /*! 
     1064  \brief Get the list of domain pointers 
     1065  \return list of domain pointers 
     1066  */ 
    9841067  std::vector<CDomain*> CGrid::getDomains() 
    9851068  { 
     
    9921075  } 
    9931076 
     1077  /*! 
     1078  \brief Get the list of  axis pointers 
     1079  \return list of axis pointers 
     1080  */ 
    9941081  std::vector<CAxis*> CGrid::getAxis() 
    9951082  { 
     
    10011088  } 
    10021089 
     1090  /*! 
     1091  \brief Set domain(s) of a grid from a list 
     1092  \param[in] domains list of domains 
     1093  */ 
    10031094  void CGrid::setDomainList(const std::vector<CDomain*> domains) 
    10041095  { 
     
    10191110  } 
    10201111 
     1112  /*! 
     1113  \brief Set axis(s) of a grid from a list 
     1114  \param[in] axis list of axis 
     1115  */ 
    10211116  void CGrid::setAxisList(const std::vector<CAxis*> axis) 
    10221117  { 
     
    10361131  } 
    10371132 
     1133  /*! 
     1134  \brief Get list of id of domains 
     1135  \return id list of domains 
     1136  */ 
    10381137  std::vector<StdString> CGrid::getDomainList() 
    10391138  { 
     
    10421141  } 
    10431142 
     1143  /*! 
     1144  \brief Get list of id of axis 
     1145  \return id list of axis 
     1146  */ 
    10441147  std::vector<StdString> CGrid::getAxisList() 
    10451148  { 
     
    10741177  { 
    10751178    SuperClass::parse(node); 
     1179    // List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) 
     1180//    std::vector<int> axisOrder; 
     1181    std::vector<bool> order; 
    10761182 
    10771183    if (node.goToChildElement()) 
    10781184    { 
    1079       int domainIdx = -1; 
    1080       int posAxis = 0; 
    10811185      StdString domainName("domain"); 
    10821186      StdString axisName("axis"); 
     
    10841188      { 
    10851189        if (node.getElementName() == domainName) { 
    1086           axisOrder_.push_back(domainIdx); 
     1190          order.push_back(true); 
    10871191          this->getVirtualDomainGroup()->parseChild(node); 
    10881192        } 
    10891193        if (node.getElementName() == axisName) { 
    1090           axisOrder_.push_back(posAxis); 
    1091           ++posAxis; 
     1194          order.push_back(false); 
    10921195          this->getVirtualAxisGroup()->parseChild(node); 
    10931196        } 
     
    10961199    } 
    10971200 
    1098     if (!axisOrder_.empty()) 
    1099     { 
    1100       int sizeOrd = axisOrder_.size(); 
    1101       axisDomOrder.resize(sizeOrd); 
     1201    if (!order.empty()) 
     1202    { 
     1203      int sizeOrd = order.size(); 
     1204      axisDomainOrder.resize(sizeOrd); 
    11021205      for (int i = 0; i < sizeOrd; ++i) 
    11031206      { 
    1104         axisDomOrder(i) = axisOrder_[i]; 
     1207        axisDomainOrder(i) = order[i]; 
    11051208      } 
    11061209    } 
Note: See TracChangeset for help on using the changeset viewer.