Ignore:
Timestamp:
03/10/15 10:49:02 (9 years ago)
Author:
mhnguyen
Message:

Implementing a grid formed by only one axis or group of axis

+) Add several new attributes to axis. From now on, each axis can be distributed on client side
+) Modify mask of grid to make it more flexible to different dimension
+) Fix some bugs relating to calculation of local data index on client
+) Clean some redundant codes

Test
+) On Curie, only test_new_features.f90
+) Test cases:

  • Grid composed of: 1 domain and 1 axis, 3 axis, 1 axis
  • Mode: Attached and connected
  • No of client-server: 6-2(Connected), 2 (Attached)

+) All tests passed and results are correct

File:
1 edited

Legend:

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

    • Property svn:executable set to *
    r566 r567  
    66#include "message.hpp" 
    77#include "type.hpp" 
     8#include "context.hpp" 
     9#include "context_client.hpp" 
    810#include "xmlioserver_spl.hpp" 
    911 
     
    1416   CAxis::CAxis(void) 
    1517      : CObjectTemplate<CAxis>() 
    16       , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject() 
     18      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject(), areClientAttributesChecked_(false) 
    1719   { /* Ne rien faire de plus */ } 
    1820 
    1921   CAxis::CAxis(const StdString & id) 
    2022      : CObjectTemplate<CAxis>(id) 
    21       , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject() 
     23      , CAxisAttributes(), isChecked(false), relFiles(), baseRefObject(), areClientAttributesChecked_(false) 
    2224   { /* Ne rien faire de plus */ } 
    2325 
     
    5254   void CAxis::checkAttributes(void) 
    5355   { 
    54       if (this->isChecked) return; 
    5556      if (this->size.isEmpty()) 
    5657         ERROR("CAxis::checkAttributes(void)", 
     
    7677      else this->ni.setValue(size); 
    7778 
    78       StdSize zoom_begin,zoom_end, zoom_size; 
    79  
    80       // Maybe index begins at 0 (zero) 
    81       zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue(); 
    82       zoom_end = (this->zoom_end.isEmpty()) ?  size-1 : this->zoom_end.getValue(); 
    83       zoom_size = (this->zoom_size.isEmpty()) ?  size : this->zoom_size.getValue(); 
    84  
    85       if (this->zoom_begin.isEmpty()) zoom_begin=zoom_end-zoom_size+1; 
    86       if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1; 
    87       if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1; 
    88  
    89       if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) 
    90         ERROR("CAxis::checkAttributes(void)", 
    9179              << "One or more attributes among <zoom_begin>, <zoom_end>, <zoom_size> of axis [ id = '" << getId() << "' , context = '" << CObjectFactory::GetCurrentContextId() << "' ] are not well specified"); 
    92  
    93       this->zoom_begin.setValue(zoom_begin); 
    94       this->zoom_end.setValue(zoom_end); 
    95       this->zoom_size.setValue(zoom_size); 
    96  
    9780      StdSize true_size = value.numElements(); 
    9881      if (size != true_size) 
     
    10285      this->checkData(); 
    10386      this->checkMask(); 
    104       this->isChecked = true; 
     87      this->checkZoom(); 
    10588   } 
    10689 
     
    122105        for (int i = 0; i < dn; ++i) data_index(i) = (i+1); 
    123106      } 
     107   } 
     108 
     109   void CAxis::checkZoom(void) 
     110   { 
     111      StdSize zoom_begin,zoom_end, zoom_size; 
     112 
     113      zoom_begin = (this->zoom_begin.isEmpty()) ?  0 : this->zoom_begin.getValue() ; 
     114      zoom_size  = (this->zoom_size.isEmpty()) ?  size.getValue() : this->zoom_size.getValue() ; 
     115      zoom_end   = (this->zoom_end.isEmpty()) ?  (size.getValue() - 1) : this->zoom_end.getValue() ; 
     116 
     117      if (this->zoom_begin.isEmpty()) zoom_begin=zoom_end-zoom_size+1 ; 
     118      if (this->zoom_end.isEmpty()) zoom_end=zoom_begin+zoom_size-1 ; 
     119      if (this->zoom_size.isEmpty()) zoom_size=zoom_end-zoom_begin+1 ; 
     120 
     121      if ( (zoom_begin < 0) || (zoom_begin > size-1) || (zoom_end<0) || (zoom_end>size-1) || (zoom_size<1) || (zoom_size>size) || (zoom_begin>zoom_end)) 
     122        ERROR("CAxis::checkAttributes(void)",<< "One or more attribut of <zoom_begin>, <zoom_end>, <zoom_size>, are not well specified") ; 
     123 
     124      this->zoom_begin.setValue(zoom_begin) ; 
     125      this->zoom_end.setValue(zoom_end) ; 
     126      this->zoom_size.setValue(zoom_size) ; 
     127 
     128      // compute client zoom indices 
     129//      zoom_begin_client = ibegin_client > zoom_begin ? begin_client : zoom_begin ; 
     130//      zoom_end_client   = iend_client < zoom_end ? iend_client : zoom_end ; 
     131//      zoom_size_client  = zoom_end_client-zoom_begin_client+1 ; 
     132//      if (zoom_ni_client<0) zoom_ni_client=0 ; 
    124133   } 
    125134 
     
    166175   } 
    167176 
     177  bool CAxis::dispatchEvent(CEventServer& event) 
     178   { 
     179      if (SuperClass::dispatchEvent(event)) return true ; 
     180      else 
     181      { 
     182        switch(event.type) 
     183        { 
     184           case EVENT_ID_SERVER_ATTRIBUT : 
     185             recvServerAttribut(event) ; 
     186             return true ; 
     187             break ; 
     188           default : 
     189             ERROR("bool CContext::dispatchEvent(CEventServer& event)", 
     190                    <<"Unknown Event") ; 
     191           return false ; 
     192         } 
     193      } 
     194   } 
     195 
     196   void CAxis::checkAttributesOnClient(const std::vector<int>& globalDim, int orderPositionInGrid, 
     197                                       CServerDistributionDescription::ServerDistributionType distType) 
     198   { 
     199     if (this->areClientAttributesChecked_) return; 
     200     this->checkAttributes(); 
     201 
     202     CContext* context=CContext::getCurrent() ; 
     203     if (context->hasClient) 
     204     { 
     205       computeServerIndex(globalDim, orderPositionInGrid, distType); 
     206     } 
     207 
     208     this->areClientAttributesChecked_ = true; 
     209   } 
     210 
     211   void CAxis::computeServerIndex(const std::vector<int>& globalDim, int orderPositionInGrid, 
     212                                  CServerDistributionDescription::ServerDistributionType distType) 
     213   { 
     214     CServerDistributionDescription serverDescription(globalDim); 
     215 
     216     CContext* context=CContext::getCurrent() ; 
     217     CContextClient* client=context->client ; 
     218     int nbServer=client->serverSize ; 
     219     int serverRank=client->getServerLeader() ; 
     220 
     221     serverDescription.computeServerDistribution(nbServer, false, distType); 
     222     std::vector<std::vector<int> > serverIndexBegin = serverDescription.getServerIndexBegin(); 
     223     std::vector<std::vector<int> > serverDimensionSizes = serverDescription.getServerDimensionSizes(); 
     224     begin_srv = (serverIndexBegin[serverRank])[orderPositionInGrid]; 
     225     ni_srv = serverDimensionSizes[serverRank][orderPositionInGrid]; 
     226     end_srv = begin_srv+ni_srv-1; 
     227   } 
     228 
     229   // Send all checked attributes to server 
     230   void CAxis::sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid, 
     231                                     CServerDistributionDescription::ServerDistributionType distType) 
     232   { 
     233     if (!this->areClientAttributesChecked_) checkAttributesOnClient(globalDim, 
     234                                                                     orderPositionInGrid, 
     235                                                                     distType); 
     236     CContext* context=CContext::getCurrent() ; 
     237 
     238     if (this->isChecked) return; 
     239     if (context->hasClient) 
     240     { 
     241       sendServerAttribut() ; 
     242     } 
     243 
     244     this->isChecked = true; 
     245   } 
     246 
     247  void CAxis::sendServerAttribut(void) 
     248  { 
     249    CContext* context=CContext::getCurrent(); 
     250    CContextClient* client=context->client; 
     251 
     252    CEventClient event(getType(),EVENT_ID_SERVER_ATTRIBUT) ; 
     253    if (client->isServerLeader()) 
     254    { 
     255      CMessage msg ; 
     256      msg<<this->getId() ; 
     257      msg<<ni_srv<<begin_srv<<end_srv; 
     258      event.push(client->getServerLeader(),1,msg) ; 
     259      client->sendEvent(event) ; 
     260    } 
     261    else client->sendEvent(event) ; 
     262  } 
     263 
     264  void CAxis::recvServerAttribut(CEventServer& event) 
     265  { 
     266    CBufferIn* buffer=event.subEvents.begin()->buffer; 
     267    string axisId ; 
     268    *buffer>>axisId ; 
     269    get(axisId)->recvServerAttribut(*buffer) ; 
     270  } 
     271 
     272  void CAxis::recvServerAttribut(CBufferIn& buffer) 
     273  { 
     274    int zoom_end = zoom_begin.getValue()+zoom_size.getValue()-1; 
     275    int ni_srv, begin_srv, end_srv; 
     276 
     277    buffer>>ni_srv>>begin_srv>>end_srv; 
     278 
     279    zoom_begin_srv = zoom_begin.getValue() > begin_srv ? zoom_begin.getValue() : begin_srv ; 
     280    zoom_end_srv   = zoom_end < end_srv ? zoom_end : end_srv ; 
     281    zoom_size_srv  = zoom_end_srv-zoom_begin_srv+1 ; 
     282 
     283    if (zoom_size_srv<=0) 
     284    { 
     285      zoom_begin_srv=0 ; zoom_end_srv=0 ; zoom_size_srv=0 ; 
     286    } 
     287  } 
     288 
    168289   DEFINE_REF_FUNC(Axis,axis) 
    169290 
Note: See TracChangeset for help on using the changeset viewer.