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/domain.cpp

    r501 r509  
    1616 
    1717namespace xios { 
    18     
     18 
    1919   /// ////////////////////// Définitions ////////////////////// /// 
    2020 
    2121   CDomain::CDomain(void) 
    2222      : CObjectTemplate<CDomain>(), CDomainAttributes() 
    23       , isChecked(false),  relFiles() 
     23      , isChecked(false), relFiles(), isClientChecked(false) 
    2424   { /* Ne rien faire de plus */ } 
    2525 
    2626   CDomain::CDomain(const StdString & id) 
    2727      : CObjectTemplate<CDomain>(id), CDomainAttributes() 
    28       , isChecked(false), relFiles() 
     28      , isChecked(false), relFiles(), isClientChecked(false) 
    2929         { /* Ne rien faire de plus */ } 
    3030 
    3131   CDomain::~CDomain(void) 
    32    {  
     32   { 
    3333   } 
    3434 
     
    3737   const std::set<StdString> & CDomain::getRelFiles(void) const 
    3838   { 
    39       return (this->relFiles);  
    40    } 
    41  
    42    //---------------------------------------------------------------- 
    43     
     39      return (this->relFiles); 
     40   } 
     41 
     42   //---------------------------------------------------------------- 
     43 
    4444   bool CDomain::hasZoom(void) const 
    4545   { 
    46       return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) &&  
     46      return ((this->zoom_ni.getValue() != this->ni_glo.getValue()) && 
    4747              (this->zoom_nj.getValue() != this->nj_glo.getValue())); 
    4848   } 
    49     
    50    //---------------------------------------------------------------- 
    51     
     49 
     50   //---------------------------------------------------------------- 
     51 
    5252   bool CDomain::isEmpty(void) const 
    5353   { 
    54       return ((this->zoom_ni_srv == 0) ||  
     54      return ((this->zoom_ni_srv == 0) || 
    5555              (this->zoom_nj_srv == 0)); 
    5656   } 
     
    8686               << "[ Id = " << this->getId() << " ] " 
    8787               << "The global domain is badly defined," 
    88                << " check the \'ni_glo\'  value !")  
     88               << " check the \'ni_glo\'  value !") 
    8989         } 
    9090         nj_glo=ni_glo ; 
     
    111111         ibegin=1 ; 
    112112         iend=1 ; 
    113           
     113 
    114114      } 
    115115      else if ((ni_glo.isEmpty() || ni_glo.getValue() <= 0 ) || 
     
    119119               << "[ Id = " << this->getId() << " ] " 
    120120               << "The global domain is badly defined," 
    121                << " check the \'ni_glo\' et \'nj_glo\' values !")  
     121               << " check the \'ni_glo\' et \'nj_glo\' values !") 
    122122      } 
    123123      checkLocalIDomain() ; 
    124124      checkLocalJDomain() ; 
    125        
     125 
    126126     if (i_index.isEmpty()) 
    127127     { 
    128128       i_index.resize(ni,nj) ; 
    129129       for(int j=0;j<nj;j++) 
    130          for(int i=0;i<ni;i++) i_index(i,j)=i ;    
     130         for(int i=0;i<ni;i++) i_index(i,j)=i ; 
    131131     } 
    132       
     132 
    133133     if (j_index.isEmpty()) 
    134134     { 
    135135        j_index.resize(ni,nj) ; 
    136136        for(int j=0;j<nj;j++) 
    137          for(int i=0;i<ni;i++) j_index(i,j)=j ;    
     137         for(int i=0;i<ni;i++) j_index(i,j)=j ; 
    138138     } 
    139   
     139 
    140140   } 
    141141 
     
    211211               << "Domain is wrong defined," 
    212212               << " Check the values : nj, nj_glo, jbegin, jend") ; 
    213                 
     213 
    214214     ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 
    215215     jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 
     
    221221   { 
    222222      using namespace std; 
    223        
     223 
    224224      int ibegin_mask = 0, 
    225225          jbegin_mask = 0, 
    226226          iend_mask = iend.getValue() - ibegin.getValue(), 
    227227          jend_mask = jend.getValue() - jbegin.getValue(); 
    228        
     228 
    229229      if (!zoom_ibegin.isEmpty()) 
    230230      { 
    231231         int zoom_iend = zoom_ibegin.getValue() + zoom_ni.getValue() - 1; 
    232232         int zoom_jend = zoom_jbegin.getValue() + zoom_nj.getValue() - 1; 
    233           
     233 
    234234         ibegin_mask = max (ibegin.getValue(), zoom_ibegin.getValue()); 
    235235         jbegin_mask = max (jbegin.getValue(), zoom_jbegin.getValue()); 
    236236         iend_mask   = min (iend.getValue(), zoom_iend); 
    237237         jend_mask   = min (jend.getValue(), zoom_jend); 
    238                   
     238 
    239239         ibegin_mask -= ibegin.getValue(); 
    240240         jbegin_mask -= jbegin.getValue(); 
     
    242242         jend_mask   -= jbegin.getValue(); 
    243243      } 
    244        
     244 
    245245 
    246246      if (!mask.isEmpty()) 
     
    251251                  <<"the mask has not the same size than the local domain"<<endl 
    252252                   <<"Local size is "<<ni<<"x"<<nj<<endl 
    253                   <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1));                  
     253                  <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)); 
    254254         for (int i = 0; i < ni; i++) 
    255255         { 
     
    283283 
    284284   void CDomain::checkDomainData(void) 
    285    {      
     285   { 
    286286      if (!data_dim.isEmpty() && 
    287287         !(data_dim.getValue() == 1 || data_dim.getValue() == 2)) 
     
    378378            data_i_index.resize(dni) ; 
    379379            data_j_index.resize(dni) ; 
    380              
     380 
    381381            data_n_index.setValue(dni); 
    382              
     382 
    383383            for(int count = 0, j = 0; j  < data_nj.getValue(); j++) 
    384384            { 
     
    394394 
    395395   //---------------------------------------------------------------- 
    396     
     396 
    397397   void CDomain::completeLonLatClient(void) 
    398398   { 
     
    402402      CArray<double,2> bounds_lon_temp(nvertex,ni*nj) ; 
    403403      CArray<double,2> bounds_lat_temp(nvertex,ni*nj) ; 
    404        
     404 
    405405      if (type.isEmpty()) 
    406406      { 
    407         if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj )  
     407        if ( lonvalue.numElements() == ni*nj && latvalue.numElements() == ni*nj ) 
    408408        { 
    409409          type.setValue(type_attr::curvilinear) ; 
    410410          isCurvilinear=true ; 
    411411        } 
    412         else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj )  
     412        else if ( lonvalue.numElements() == ni && latvalue.numElements() == nj ) 
    413413        { 
    414414          type.setValue(type_attr::regular) ; 
     
    429429      { 
    430430        for(j=0;j<nj;j++) 
    431           for(i=0;i<ni;i++)  
     431          for(i=0;i<ni;i++) 
    432432          { 
    433433            k=j*ni+i ; 
     
    436436            if (hasBounds) 
    437437            { 
    438               for(int n=0;n<nvertex;n++)  
     438              for(int n=0;n<nvertex;n++) 
    439439              { 
    440440                bounds_lon_temp(n,k)=bounds_lon(n,i) ; 
     
    444444          } 
    445445      } 
    446           
     446 
    447447      StdSize dm = zoom_ni_client * zoom_nj_client; 
    448448 
    449449      lonvalue.resize(dm); 
    450450      latvalue.resize(dm); 
    451           
     451 
    452452      for (int i = 0; i < zoom_ni_client; i++) 
    453453      { 
    454454        for (int j = 0; j < zoom_nj_client; j++) 
    455455        { 
    456           lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni );  
     456          lonvalue(i + j * zoom_ni_client) = lonvalue_temp( (i + zoom_ibegin_client-ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 
    457457          latvalue(i + j * zoom_ni_client) = latvalue_temp( (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client - jbegin)*ni ); 
    458458          if (hasBounds) 
    459459          { 
    460             for(int n=0;n<nvertex;n++)  
     460            for(int n=0;n<nvertex;n++) 
    461461            { 
    462               bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni );  
     462              bounds_lon(n,i + j * zoom_ni_client) = bounds_lon_temp( n, (i + zoom_ibegin_client - ibegin) + (j + zoom_jbegin_client -jbegin)*ni ); 
    463463              bounds_lat(n,i + j * zoom_ni_client) = bounds_lat_temp( n, (i + zoom_ibegin_client - ibegin)+(j + zoom_jbegin_client -jbegin)*ni ); 
    464464            } 
     
    467467      } 
    468468    } 
    469   
     469 
    470470 
    471471   //---------------------------------------------------------------- 
     
    487487            int zoom_iend = zoom_ibegin + zoom_ni - 1; 
    488488            int zoom_jend = zoom_jbegin + zoom_nj - 1; 
    489                  
     489 
    490490            if (zoom_ibegin < 1  || zoom_jbegin < 1 || zoom_iend > ni_glo || zoom_jend > nj_glo) 
    491491               ERROR("CDomain::checkZoom(void)", 
     
    496496      else 
    497497      { 
    498          zoom_ni = ni_glo;  
     498         zoom_ni = ni_glo; 
    499499         zoom_nj = nj_glo; 
    500500         zoom_ibegin = 1; 
    501501         zoom_jbegin = 1; 
    502502      } 
    503        
     503 
    504504      // compute client zoom indices 
    505505 
     
    510510      if (zoom_ni_client<0) zoom_ni_client=0 ; 
    511511 
    512      
     512 
    513513      int zoom_jend=zoom_jbegin+zoom_nj-1 ; 
    514514      zoom_jbegin_client = jbegin_client > zoom_jbegin ? jbegin_client : zoom_jbegin ; 
     
    518518 
    519519   } 
    520     
     520 
    521521   void CDomain::checkBounds(void) 
    522522   { 
     
    524524     { 
    525525       hasBounds=true ; 
    526         
     526 
    527527     } 
    528      else  
     528     else 
    529529     { 
    530530       hasBounds=false; 
     
    532532     } 
    533533   } 
    534              
    535    //---------------------------------------------------------------- 
    536  
    537    void CDomain::checkAttributes(void) 
    538    { 
    539       if (this->isChecked) return; 
    540       CContext* context=CContext::getCurrent() ; 
     534 
     535   //---------------------------------------------------------------- 
     536   // Divide function checkAttributes into 2 seperate ones 
     537   // This function only checks all attributes of current domain 
     538   void CDomain::checkAttributesOnClient() 
     539   { 
     540     if (this->isClientChecked) return; 
     541     CContext* context=CContext::getCurrent(); 
    541542 
    542543      this->checkDomain(); 
    543544      this->checkZoom(); 
    544545      this->checkBounds(); 
    545        
     546 
    546547      if (context->hasClient) 
    547548      { // CÃŽté client uniquement 
     
    550551         this->checkCompression(); 
    551552         this->completeLonLatClient(); 
     553         this->computeConnectedServer() ; 
    552554      } 
    553555      else 
     
    556558// ne sert plus //   this->completeLonLatServer(); 
    557559      } 
    558      
     560 
     561      this->isClientChecked = true; 
     562   } 
     563 
     564   // Send all checked attributes to server 
     565   void CDomain::sendCheckedAttributes() 
     566   { 
     567     if (!this->isClientChecked) checkAttributesOnClient(); 
     568     CContext* context=CContext::getCurrent() ; 
     569 
     570     if (this->isChecked) return; 
     571     if (context->hasClient) 
     572     { 
     573       sendServerAttribut() ; 
     574       sendLonLat() ; 
     575     } 
     576 
     577     this->isChecked = true; 
     578   } 
     579 
     580   void CDomain::checkAttributes(void) 
     581   { 
     582      if (this->isChecked) return; 
     583      CContext* context=CContext::getCurrent() ; 
     584 
     585      this->checkDomain(); 
     586      this->checkZoom(); 
     587      this->checkBounds(); 
     588 
     589      if (context->hasClient) 
     590      { // CÃŽté client uniquement 
     591         this->checkMask(); 
     592         this->checkDomainData(); 
     593         this->checkCompression(); 
     594         this->completeLonLatClient(); 
     595      } 
     596      else 
     597      { // CÃŽté serveur uniquement 
     598//         if (!this->isEmpty()) 
     599// ne sert plus //   this->completeLonLatServer(); 
     600      } 
     601 
    559602      if (context->hasClient) 
    560603      { 
     
    563606        sendLonLat() ; 
    564607      } 
    565        
     608 
    566609      this->isChecked = true; 
    567610   } 
    568     
     611 
    569612  void CDomain::sendServerAttribut(void) 
    570613  { 
     
    572615    int ibegin_srv=1 ; 
    573616    int iend_srv=ni_glo.getValue() ; 
    574       
     617 
    575618    int nj_srv ; 
    576619    int jbegin_srv ; 
    577620    int jend_srv ; 
    578      
     621 
    579622    CContext* context=CContext::getCurrent() ; 
    580623    CContextClient* client=context->client ; 
    581624    int nbServer=client->serverSize ; 
    582625    int serverRank=client->getServerLeader() ; 
    583      
     626 
    584627    jend_srv=0 ; 
    585628    for(int i=0;i<=serverRank;i++) 
     
    590633      jend_srv=jbegin_srv+nj_srv-1 ; 
    591634    } 
    592      
    593      CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ;    
     635 
     636     CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 
    594637     if (client->isServerLeader()) 
    595638     { 
     
    606649  { 
    607650    int i,j,i_ind,j_ind ; 
    608      
     651 
    609652    ibegin_client=ibegin ; iend_client=iend ; ni_client=ni ; 
    610653    jbegin_client=jbegin ; jend_client=jend ; nj_client=nj ; 
    611       
     654 
    612655    CContext* context = CContext::getCurrent() ; 
    613656    CContextClient* client=context->client ; 
     
    617660    int zoom_iend=zoom_ibegin+zoom_ni-1 ; 
    618661    int zoom_jend=zoom_jbegin+zoom_nj-1 ; 
    619      
     662 
    620663    int blockSize=nj_glo/nbServer ; 
    621664    int ns=nj_glo%nbServer ; 
    622665    int pos=ns*(blockSize+1) ; 
    623666    int serverNum ; 
    624      
     667 
    625668    mapConnectedServer.resize(ni,nj) ; 
    626669    vector<int> nbData(nbServer,0) ; 
    627670    vector<int> indServer(nbServer,-1) ; 
    628671    vector<bool> IsConnected(nbServer,false) ; 
    629      
     672 
    630673    for(j=0;j<nj;j++) 
    631674      for(i=0;i<ni;i++) 
     
    633676        i_ind=ibegin+i_index(i,j)-1 ; 
    634677        j_ind=jbegin+j_index(i,j)-1 ; 
    635          
     678 
    636679        if (j_ind<pos) serverNum=j_ind/(blockSize+1) ; 
    637680        else serverNum=ns+(j_ind-pos)/blockSize ; 
    638681        IsConnected[serverNum]=true ; 
    639                  
     682 
    640683        if (i_ind >= zoom_ibegin-1 && i_ind <= zoom_iend-1 && j_ind >= zoom_jbegin-1 && j_ind <= zoom_jend-1) 
    641684        { 
     
    647690 
    648691 
    649     for(serverNum=0 ; serverNum<nbServer ; serverNum++)  
     692    for(serverNum=0 ; serverNum<nbServer ; serverNum++) 
    650693      if (IsConnected[serverNum]) 
    651694      { 
     
    655698        nbDataSrv.push_back(nbData[serverNum]) ; 
    656699      } 
    657       
     700 
    658701     i_indSrv.resize(connectedServer.size()) ; 
    659702     j_indSrv.resize(connectedServer.size()) ; 
    660703 
    661704     for(j=0;j<nj;j++) 
    662       for(i=0;i<ni;i++)  
     705      for(i=0;i<ni;i++) 
    663706      { 
    664707        if (mapConnectedServer(i,j)>=0) 
     
    670713        } 
    671714      } 
    672            
     715 
    673716    int nbConnectedServer=connectedServer.size() ; 
    674717 
     
    677720    int* sendBuff=new int[nbConnectedServer] ; 
    678721    valarray<int> nbClient(0,client->serverSize) ; 
    679      
     722 
    680723    for(int n=0;n<nbConnectedServer;n++) sendBuff[n]=connectedServer[n] ; 
    681      
     724 
    682725    // get connected server for everybody 
    683726    MPI_Allgather(&nbConnectedServer,1,MPI_INT,recvCount,1,MPI_INT,client->intraComm) ; 
    684      
     727 
    685728    displ[0]=0 ; 
    686729    for(int n=1;n<client->clientSize;n++) displ[n]=displ[n-1]+recvCount[n-1] ; 
    687730    int recvSize=displ[client->clientSize-1]+recvCount[client->clientSize-1] ; 
    688731    int* recvBuff=new int[recvSize] ; 
    689   
    690      
     732 
     733 
    691734    MPI_Allgatherv(sendBuff,nbConnectedServer,MPI_INT,recvBuff,recvCount,displ,MPI_INT,client->intraComm) ; 
    692735    for(int n=0;n<recvSize;n++) nbClient[recvBuff[n]]++ ; 
    693      
     736 
    694737    for(int n=0;n<nbConnectedServer;n++) nbSenders.push_back(nbClient[connectedServer[n]]) ; 
    695     
     738 
    696739    delete [] recvCount ; 
    697740    delete [] displ ; 
     
    708751    // send lon lat for each connected server 
    709752    CEventClient event(getType(),EVENT_ID_LON_LAT) ; 
    710      
    711     list<shared_ptr<CMessage> > list_msg ;     
     753 
     754    list<shared_ptr<CMessage> > list_msg ; 
    712755    list< CArray<int,1>* > list_indi,list_indj ; 
    713756    list< CArray<double,1>* >list_lon,list_lat ; 
     
    723766      CArray<double,2> boundslon(nvertex,nbData) ; 
    724767      CArray<double,2> boundslat(nvertex,nbData) ; 
    725        
    726       for(n=0;n<nbData;n++)  
     768 
     769      for(n=0;n<nbData;n++) 
    727770      { 
    728771        i=i_indSrv[ns][n] ; 
    729772        j=j_indSrv[ns][n] ; 
    730773        ind=(i-(zoom_ibegin_client-1))+(j-(zoom_jbegin_client-1))*zoom_ni_client ; 
    731          
     774 
    732775        lon(n)=lonvalue(ind) ; 
    733776        lat(n)=latvalue(ind) ; 
     
    743786        indj(n)=jbegin+j_index(i-ibegin+1,j-jbegin+1)-1  ; 
    744787      } 
    745      
     788 
    746789      list_indi.push_back(new CArray<int,1>(indi.copy())) ; 
    747790      list_indj.push_back(new CArray<int,1>(indj.copy())) ; 
     
    761804 
    762805    client->sendEvent(event) ; 
    763      
    764      
     806 
     807 
    765808    for(list<CArray<int,1>* >::iterator it=list_indi.begin();it!=list_indi.end();it++) delete *it; 
    766809    for(list<CArray<int,1>* >::iterator it=list_indj.begin();it!=list_indj.end();it++) delete *it; 
     
    768811    for(list<CArray<double,1>* >::iterator it=list_lat.begin();it!=list_lat.end();it++)   delete *it; 
    769812    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslon.begin();it!=list_boundslon.end();it++)   delete *it; 
    770     if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++)   delete *it;     
    771      
     813    if (hasBounds) for(list<CArray<double,2>* >::iterator it=list_boundslat.begin();it!=list_boundslat.end();it++)   delete *it; 
     814 
    772815  } 
    773    
    774    
     816 
     817 
    775818  bool CDomain::dispatchEvent(CEventServer& event) 
    776819   { 
    777        
     820 
    778821      if (SuperClass::dispatchEvent(event)) return true ; 
    779822      else 
     
    796839      } 
    797840   } 
    798     
     841 
    799842  void CDomain::recvServerAttribut(CEventServer& event) 
    800843  { 
     
    804847    get(domainId)->recvServerAttribut(*buffer) ; 
    805848  } 
    806    
     849 
    807850  void CDomain::recvServerAttribut(CBufferIn& buffer) 
    808851  { 
     
    811854 
    812855     buffer>>ni_srv>>ibegin_srv>>iend_srv>>nj_srv>>jbegin_srv>>jend_srv; 
    813       
    814      
     856 
     857 
    815858    zoom_ibegin_srv = zoom_ibegin.getValue() > ibegin_srv ? zoom_ibegin.getValue() : ibegin_srv ; 
    816859    zoom_iend_srv = zoom_iend < iend_srv ? zoom_iend : iend_srv ; 
    817860    zoom_ni_srv=zoom_iend_srv-zoom_ibegin_srv+1 ; 
    818        
     861 
    819862    zoom_jbegin_srv = zoom_jbegin.getValue() > jbegin_srv ? zoom_jbegin.getValue() : jbegin_srv ; 
    820863    zoom_jend_srv = zoom_jend < jend_srv ? zoom_jend : jend_srv ; 
    821864    zoom_nj_srv=zoom_jend_srv-zoom_jbegin_srv+1 ; 
    822865 
    823     if (zoom_ni_srv<=0 || zoom_nj_srv<=0)  
     866    if (zoom_ni_srv<=0 || zoom_nj_srv<=0) 
    824867    { 
    825868      zoom_ibegin_srv=1 ; zoom_iend_srv=0 ; zoom_ni_srv=0 ; 
     
    830873    latvalue_srv.resize(zoom_ni_srv*zoom_nj_srv) ; 
    831874    latvalue_srv = 0. ; 
    832     if (hasBounds)  
     875    if (hasBounds) 
    833876    { 
    834877      bounds_lon_srv.resize(nvertex,zoom_ni_srv*zoom_nj_srv) ; 
     
    838881    } 
    839882  } 
    840      
     883 
    841884  void CDomain::recvLonLat(CEventServer& event) 
    842885  { 
     
    850893    } 
    851894  } 
    852    
     895 
    853896  void CDomain::recvLonLat(CBufferIn& buffer) 
    854897  { 
     
    859902    CArray<double,2> boundslon ; 
    860903    CArray<double,2> boundslat ; 
    861      
     904 
    862905    int type_int ; 
    863906    buffer>>type_int>>isCurvilinear>>indi>>indj>>lon>>lat ; 
     
    872915      lonvalue_srv(ind_srv)=lon(ind) ; 
    873916      latvalue_srv(ind_srv)=lat(ind) ; 
    874       if (hasBounds)  
    875       { 
    876         for(int nv=0;nv<nvertex;nv++)  
     917      if (hasBounds) 
     918      { 
     919        for(int nv=0;nv<nvertex;nv++) 
    877920        { 
    878921          bounds_lon_srv(nv,ind_srv)=boundslon(nv,ind) ; 
     
    883926  } 
    884927   //---------------------------------------------------------------- 
    885     
    886     
    887     
     928 
     929 
     930 
    888931   ///--------------------------------------------------------------- 
    889932 
Note: See TracChangeset for help on using the changeset viewer.