Ignore:
Timestamp:
11/13/14 15:09:14 (9 years ago)
Author:
mhnguyen
Message:

Implementing buffer size auto-detection for mode client -server

+) Process xml tree in client side then send all the information to server
+) Only information enabled fields in enabled files are sent to server
+) Some important change in structure of code which must be refactored

Test
+) On Curie
+) Only mode client-server
+) Passed for all tests

File:
1 edited

Legend:

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

    r501 r509  
    1919   CGrid::CGrid(void) 
    2020      : CObjectTemplate<CGrid>(), CGridAttributes() 
    21       , withAxis(false), isChecked(false), axis(), domain() 
    22       , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) 
     21      , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 
     22      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    2323   { /* Ne rien faire de plus */ } 
    2424 
    2525   CGrid::CGrid(const StdString & id) 
    2626      : CObjectTemplate<CGrid>(id), CGridAttributes() 
    27       , withAxis(false), isChecked(false), axis(), domain() 
    28       , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1) 
     27      , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 
     28      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    2929   { /* Ne rien faire de plus */ } 
    3030 
    3131   CGrid::~CGrid(void) 
    32    {  
     32   { 
    3333 //     this->axis.reset() ; 
    3434//      this->domain.reset() ; 
    3535    deque< CArray<int, 1>* >::iterator it ; 
    36      
     36 
    3737    for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++)  delete *it ; 
    3838    for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; 
     
    5555 
    5656   const std::deque< CArray<int,1>* > & CGrid::getStoreIndex(void) const 
    57    {  
     57   { 
    5858      return (this->storeIndex ); 
    5959   } 
     
    6262 
    6363   const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void)  const 
    64    {  
    65       return (this->out_i_index );  
     64   { 
     65      return (this->out_i_index ); 
    6666   } 
    6767 
     
    6969 
    7070   const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void)  const 
    71    {  
    72       return (this->out_j_index );  
     71   { 
     72      return (this->out_j_index ); 
    7373   } 
    7474 
     
    7676 
    7777   const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void)  const 
    78    {  
    79       return (this->out_l_index );  
     78   { 
     79      return (this->out_l_index ); 
    8080   } 
    8181 
     
    8383 
    8484   const CAxis*   CGrid::getRelAxis  (void) const 
    85    {  
    86       return (this->axis );  
     85   { 
     86      return (this->axis ); 
    8787   } 
    8888 
     
    9090 
    9191   const CDomain* CGrid::getRelDomain(void) const 
    92    {  
    93       return (this->domain );  
    94    } 
    95  
    96    //--------------------------------------------------------------- 
    97  
    98    bool CGrid::hasAxis(void) const  
    99    {  
    100       return (this->withAxis);  
     92   { 
     93      return (this->domain ); 
     94   } 
     95 
     96   //--------------------------------------------------------------- 
     97 
     98   bool CGrid::hasAxis(void) const 
     99   { 
     100      return (this->withAxis); 
    101101   } 
    102102 
     
    122122*/ 
    123123   //--------------------------------------------------------------- 
    124     
     124 
    125125/* 
    126126   StdSize CGrid::getLocalSize(void) const 
     
    147147   //--------------------------------------------------------------- 
    148148 
    149 /*    
     149/* 
    150150   StdSize CGrid::getGlobalSize(void) const 
    151151   { 
     
    166166   } 
    167167 
    168    //--------------------------------------------------------------- 
    169  
    170    void CGrid::solveReference(void) 
    171    { 
    172       if (this->isChecked) return; 
    173       CContext* context = CContext::getCurrent() ; 
    174       CContextClient* client=context->client ; 
    175        
    176       this->solveDomainRef() ; 
    177       this->solveAxisRef() ; 
    178          
    179       if (context->hasClient) 
    180       { 
    181          checkMask() ; 
    182          this->computeIndex() ; 
    183  
    184          this->storeIndex.push_front(new CArray<int,1>() ); 
    185          this->out_i_index.push_front(new CArray<int,1>()); 
    186          this->out_j_index.push_front(new CArray<int,1>()); 
    187          this->out_l_index.push_front(new CArray<int,1>()); 
    188       } 
     168   std::map<int, StdSize> CGrid::getConnectedServerDataSize() 
     169   { 
     170     std::map<int, StdSize> ret; 
     171     std::map<int, int>::const_iterator it = domConnectedServerSide_.begin(), 
     172                                       itE = domConnectedServerSide_.end(); 
     173     StdSize retVal = StdSize(0.0); 
     174     for (; it != itE; ++it) 
     175     { 
     176       retVal = it->second; 
     177       if (this->withAxis) retVal *= this->axis->size.getValue(); 
     178       retVal *= sizeof(double); 
     179       ret.insert(make_pair(it->first, retVal)); 
     180     } 
     181     return ret; 
     182   } 
     183 
     184 
     185   //--------------------------------------------------------------- 
     186 
     187//   void CGrid::solveReference(void) 
     188//   { 
     189//      if (this->isChecked) return; 
     190//      CContext* context = CContext::getCurrent() ; 
     191//      CContextClient* client=context->client ; 
     192// 
     193//      this->solveDomainRef() ; 
     194//      this->solveAxisRef() ; 
     195// 
     196//      if (context->hasClient) 
     197//      { 
     198//         checkMask() ; 
     199//         this->computeIndex() ; 
     200// 
     201//         this->storeIndex.push_front(new CArray<int,1>() ); 
     202//         this->out_i_index.push_front(new CArray<int,1>()); 
     203//         this->out_j_index.push_front(new CArray<int,1>()); 
     204//         this->out_l_index.push_front(new CArray<int,1>()); 
     205//      } 
     206////      this->computeIndexServer(); 
     207//      this->isChecked = true; 
     208//   } 
     209 
     210   void CGrid::solveDomainAxisRef(bool areAttributesChecked) 
     211   { 
     212     if (this->isDomainAxisChecked) return; 
     213 
     214     this->solveDomainRef(areAttributesChecked); 
     215     this->solveAxisRef(areAttributesChecked); 
     216 
     217     this->isDomainAxisChecked = areAttributesChecked; 
     218   } 
     219 
     220   void CGrid::checkMaskIndex(bool doSendingIndex) 
     221   { 
     222     CContext* context = CContext::getCurrent() ; 
     223     CContextClient* client=context->client ; 
     224 
     225     if (context->hasClient) 
     226      if (this->isChecked && doSendingIndex) sendIndex(); 
     227 
     228     if (this->isChecked) return; 
     229 
     230     if (context->hasClient) 
     231     { 
     232        checkMask() ; 
     233        this->computeIndex() ; 
     234 
     235        this->storeIndex.push_front(new CArray<int,1>() ); 
     236        this->out_i_index.push_front(new CArray<int,1>()); 
     237        this->out_j_index.push_front(new CArray<int,1>()); 
     238        this->out_l_index.push_front(new CArray<int,1>()); 
     239     } 
    189240//      this->computeIndexServer(); 
    190       this->isChecked = true; 
     241     this->isChecked = true; 
    191242   } 
    192243 
     
    206257             (mask.extent(2) != nlu)) 
    207258             ERROR("CGrid::checkAttributes(void)", 
    208                   <<"The mask has not the same size than the local grid"<<endl  
     259                  <<"The mask has not the same size than the local grid"<<endl 
    209260                  <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl 
    210261                  <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); 
    211262      } 
    212       else  
     263      else 
    213264      { 
    214265        mask.resize(niu,nju,nlu) ; 
    215266        mask=true  ; 
    216267      } 
    217       
     268 
    218269      CArray<bool,2>& domainMask = domain->mask ; 
    219270      for (int l=0; l < nlu ; l++) 
    220271        for (int j=0; j < nju ; j++) 
    221272          for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ; 
    222          
    223        
    224    } 
    225     
    226    //--------------------------------------------------------------- 
    227  
    228    void CGrid::solveDomainRef(void) 
     273 
     274 
     275   } 
     276 
     277   //--------------------------------------------------------------- 
     278 
     279//   void CGrid::solveDomainRef(void) 
     280//   { 
     281//      if (!domain_ref.isEmpty()) 
     282//      { 
     283//         if (CDomain::has(domain_ref.getValue())) 
     284//         { 
     285//            this->domain = CDomain::get(domain_ref.getValue()) ; 
     286//            domain->checkAttributes() ; 
     287//         } 
     288//         else ERROR("CGrid::solveDomainRef(void)", 
     289//                     << "Wrong domain reference") ; 
     290//      } 
     291//      else ERROR("CGrid::solveDomainRef(void)", 
     292//                  << "Domain reference is not defined") ; 
     293//   } 
     294// 
     295//   //--------------------------------------------------------------- 
     296// 
     297//   void CGrid::solveAxisRef(void) 
     298//   { 
     299//      if (!axis_ref.isEmpty()) 
     300//      { 
     301//         this->withAxis = true ; 
     302//         if (CAxis::get(axis_ref.getValue())) 
     303//         { 
     304//            this->axis = CAxis::get(axis_ref.getValue()) ; 
     305//            axis->checkAttributes() ; 
     306//         } 
     307//         else ERROR("CGrid::solveAxisRef(void)", 
     308//                    << "Wrong axis reference") ; 
     309//      } 
     310//      else withAxis = false ; 
     311//   } 
     312 
     313 
     314   void CGrid::solveDomainRef(bool sendAtt) 
    229315   { 
    230316      if (!domain_ref.isEmpty()) 
     
    233319         { 
    234320            this->domain = CDomain::get(domain_ref.getValue()) ; 
    235             domain->checkAttributes() ; 
     321            if (sendAtt) domain->sendCheckedAttributes(); 
     322            else domain->checkAttributesOnClient() ; 
    236323         } 
    237324         else ERROR("CGrid::solveDomainRef(void)", 
     
    244331   //--------------------------------------------------------------- 
    245332 
    246    void CGrid::solveAxisRef(void) 
     333   void CGrid::solveAxisRef(bool checkAtt) 
    247334   { 
    248335      if (!axis_ref.isEmpty()) 
     
    263350 
    264351   void CGrid::computeIndex(void) 
    265    {     
    266     
     352   { 
     353 
    267354      const int ni   = domain->ni.getValue() , 
    268355                nj   = domain->nj.getValue() , 
     
    280367      CArray<int,1> data_i_index = domain->data_i_index ; 
    281368      CArray<int,1> data_j_index = domain->data_j_index ; 
    282        
     369 
    283370 
    284371      int indexCount = 0; 
     
    302389         } 
    303390      } 
    304        
     391 
    305392      storeIndex[0]  = new CArray<int,1>(indexCount) ; 
    306393      out_i_index[0] = new CArray<int,1>(indexCount) ; 
    307394      out_j_index[0] = new CArray<int,1>(indexCount) ; 
    308395      out_l_index[0] = new CArray<int,1>(indexCount) ; 
    309        
     396 
    310397      storeIndex_client.resize(indexCount) ; 
    311398      out_i_client.resize(indexCount) ; 
    312399      out_j_client.resize(indexCount) ; 
    313400      out_l_client.resize(indexCount) ; 
    314        
    315        
     401 
     402 
    316403      for(int count = 0, indexCount = 0,  l = 0; l < size; l++) 
    317404      { 
     
    334421               (*out_i_index[0])(indexCount) = i ; 
    335422               (*out_j_index[0])(indexCount) = j ; 
    336                 
     423 
    337424               storeIndex_client(indexCount) = count ; 
    338425               out_i_client(indexCount)=i+domain->ibegin_client-1 ; 
     
    343430         } 
    344431      } 
    345       sendIndex() ; 
     432      computeDomConServer(); 
     433//      sendIndex() ; 
    346434 
    347435 
     
    370458   //---------------------------------------------------------------- 
    371459 
    372    void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 3>& field)  
     460   void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 3>& field) 
    373461   { 
    374462      CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    375463      CArray<int,1>& out_j=*out_j_fromClient[rank] ; 
    376464      CArray<int,1>& out_l=*out_l_fromClient[rank] ; 
    377        
     465 
    378466      for(StdSize n = 0; n < stored.numElements(); n++) 
    379467         field(out_i(n), out_j(n), out_l(n)) = stored(n) ; 
    380468   } 
    381469 
    382    void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 2>& field)  
     470   void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 2>& field) 
    383471   { 
    384472      CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    385473      CArray<int,1>& out_j=*out_j_fromClient[rank] ; 
    386        
     474 
    387475      for(StdSize n = 0; n < stored.numElements(); n++) 
    388476         field(out_i(n), out_j(n)) = stored(n) ;   } 
     
    393481   { 
    394482      CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    395   
     483 
    396484      for(StdSize n = 0; n < stored.numElements(); n++) 
    397485         field(out_i(n)) = stored(n) ; 
     
    399487 
    400488   //---------------------------------------------------------------- 
    401    
     489 
    402490 
    403491   void CGrid::storeField_arr 
     
    409497      for(StdSize i = 0; i < size; i++) stored(i) = data[storeIndex_client(i)] ; 
    410498   } 
    411     
    412    //--------------------------------------------------------------- 
     499 
     500   //--------------------------------------------------------------- 
     501 
     502//  void CGrid::sendIndex(void) 
     503//  { 
     504//    CContext* context = CContext::getCurrent() ; 
     505//    CContextClient* client=context->client ; 
     506// 
     507//    CEventClient event(getType(),EVENT_ID_INDEX) ; 
     508//    int rank ; 
     509//    list<shared_ptr<CMessage> > list_msg ; 
     510//    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 
     511// 
     512//    for(int ns=0;ns<domain->connectedServer.size();ns++) 
     513//    { 
     514//       rank=domain->connectedServer[ns] ; 
     515// 
     516//       int i,j ; 
     517//       int nb=0 ; 
     518//       for(int k=0;k<storeIndex_client.numElements();k++) 
     519//       { 
     520//         i=out_i_client(k)- domain->ibegin +1; 
     521//         j=out_j_client(k)- domain->jbegin +1; 
     522//         if (domain->mapConnectedServer(i,j)==ns)  nb++ ; 
     523//       } 
     524// 
     525//       CArray<int,1> storeIndex(nb) ; 
     526//       CArray<int,1> out_i(nb) ; 
     527//       CArray<int,1> out_j(nb) ; 
     528//       CArray<int,1> out_l(nb) ; 
     529// 
     530// 
     531//       nb=0 ; 
     532//       for(int k=0;k<storeIndex_client.numElements();k++) 
     533//       { 
     534//         i=out_i_client(k)- domain->ibegin +1 ; 
     535//         j=out_j_client(k)- domain->jbegin +1 ; 
     536//         if (domain->mapConnectedServer(i,j)==ns) 
     537//         { 
     538//            storeIndex(nb)=k ; 
     539//            out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 
     540//            out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 
     541//            out_l(nb)=out_l_client(k) ; 
     542//            nb++ ; 
     543//         } 
     544//       } 
     545// 
     546//       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 
     547//       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 
     548//       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
     549//       list_out_i.push_back(new CArray<int,1>(out_i)) ; 
     550//       list_out_j.push_back(new CArray<int,1>(out_j)) ; 
     551//       list_out_l.push_back(new CArray<int,1>(out_l)) ; 
     552// 
     553//       *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; 
     554//       event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; 
     555//    } 
     556//    client->sendEvent(event) ; 
     557// 
     558//    for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; 
     559//    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 
     560//    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 
     561// 
     562//  } 
     563 
     564  void CGrid::computeDomConServer() 
     565  { 
     566    if (!isDomConServerComputed_) 
     567    { 
     568      for(int ns=0;ns<domain->connectedServer.size(); ++ns) 
     569      { 
     570         int rank=domain->connectedServer[ns] ; 
     571 
     572         int i,j ; 
     573         int nb=0 ; 
     574         for(int k=0;k<storeIndex_client.numElements();++k) 
     575         { 
     576           i=out_i_client(k)- domain->ibegin +1; 
     577           j=out_j_client(k)- domain->jbegin +1; 
     578           if (domain->mapConnectedServer(i,j)==ns)  ++nb ; 
     579         } 
     580 
     581         domConnectedServerSide_.insert(std::make_pair(rank, nb)); 
     582      } 
     583      isDomConServerComputed_ = true; 
     584    } 
     585  } 
     586 
     587 
     588  std::map<int, int> CGrid::getDomConServerSide() 
     589  { 
     590    return domConnectedServerSide_; 
     591  } 
    413592 
    414593  void CGrid::sendIndex(void) 
     
    416595    CContext* context = CContext::getCurrent() ; 
    417596    CContextClient* client=context->client ; 
    418      
     597 
    419598    CEventClient event(getType(),EVENT_ID_INDEX) ; 
    420599    int rank ; 
    421600    list<shared_ptr<CMessage> > list_msg ; 
    422601    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 
    423       
     602 
     603    if (!isDomConServerComputed_) computeDomConServer(); 
     604 
    424605    for(int ns=0;ns<domain->connectedServer.size();ns++) 
    425606    { 
    426607       rank=domain->connectedServer[ns] ; 
    427         
    428        int i,j ; 
    429        int nb=0 ; 
    430        for(int k=0;k<storeIndex_client.numElements();k++) 
    431        { 
    432          i=out_i_client(k)- domain->ibegin +1; 
    433          j=out_j_client(k)- domain->jbegin +1; 
    434          if (domain->mapConnectedServer(i,j)==ns)  nb++ ; 
    435        } 
    436         
     608 
     609       int nb = domConnectedServerSide_.find(rank)->second; 
    437610       CArray<int,1> storeIndex(nb) ; 
    438611       CArray<int,1> out_i(nb) ; 
    439612       CArray<int,1> out_j(nb) ; 
    440613       CArray<int,1> out_l(nb) ; 
    441   
    442         
     614 
     615       int i, j; 
    443616       nb=0 ; 
    444617       for(int k=0;k<storeIndex_client.numElements();k++) 
     
    450623            storeIndex(nb)=k ; 
    451624            out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 
    452             out_j(nb)=domain->j_index(i,j) + domain->jbegin-1;  
     625            out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 
    453626            out_l(nb)=out_l_client(k) ; 
    454627            nb++ ; 
    455628         } 
    456629       } 
    457         
     630 
    458631       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 
    459632       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 
     
    471644    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 
    472645    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 
    473      
     646 
    474647  } 
    475    
     648 
    476649  void CGrid::recvIndex(CEventServer& event) 
    477650  { 
     
    486659    } 
    487660  } 
    488    
     661 
    489662  void CGrid::recvIndex(int rank, CBufferIn& buffer) 
    490663  { 
     
    492665    CArray<int,1> out_j ; 
    493666    CArray<int,1> out_l ; 
    494      
     667 
    495668    buffer>>out_i>>out_j>>out_l ; 
    496      
     669 
    497670    out_i -= domain->zoom_ibegin_srv-1 ; 
    498671    out_j -= domain->zoom_jbegin_srv-1 ; 
    499      
     672 
    500673    out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; 
    501674    out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; 
     
    505678  bool CGrid::dispatchEvent(CEventServer& event) 
    506679  { 
    507       
     680 
    508681    if (SuperClass::dispatchEvent(event)) return true ; 
    509682    else 
     
    515688          return true ; 
    516689          break ; 
    517   
     690 
    518691        default : 
    519692          ERROR("bool CDomain::dispatchEvent(CEventServer& event)", 
     
    532705                << "Data from clients are missing!") ; 
    533706      storedServer.resize(storeIndex[0]->numElements()); 
    534           
     707 
    535708      for (StdSize i = 0, n = 0; i < storedClient.size(); i++) 
    536709         for (StdSize j = 0; j < storedClient[i]->numElements(); j++) 
     
    543716     int nb=index.numElements() ; 
    544717     fieldOut.resize(nb) ; 
    545       
     718 
    546719     for(int k=0;k<nb;k++) fieldOut(k)=fieldIn(index(k)) ; 
    547720    } 
Note: See TracChangeset for help on using the changeset viewer.