Changeset 567 for XIOS/trunk/src/node


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

Location:
XIOS/trunk/src/node
Files:
12 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 
  • XIOS/trunk/src/node/axis.hpp

    r551 r567  
    1111#include "attribute_enum.hpp" 
    1212#include "attribute_enum_impl.hpp" 
     13#include "server_distribution_description.hpp" 
    1314 
    1415namespace xios { 
     
    3334      , public CAxisAttributes 
    3435   { 
     36         enum EEventId 
     37         { 
     38           EVENT_ID_SERVER_ATTRIBUT 
     39         } ; 
     40 
    3541         /// typedef /// 
    3642         typedef CObjectTemplate<CAxis>   SuperClass; 
     
    6672         static StdString GetName(void); 
    6773         static StdString GetDefName(void); 
    68  
    6974         static ENodeType GetType(void); 
    7075 
     76         void sendServerAttribut(void); 
     77         static bool dispatchEvent(CEventServer& event); 
     78         static void recvServerAttribut(CEventServer& event); 
     79         void recvServerAttribut(CBufferIn& buffer) ; 
     80         void checkAttributesOnClient(const std::vector<int>& globalDim, int orderPositionInGrid, 
     81                                      CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION); 
     82         void sendCheckedAttributes(const std::vector<int>& globalDim, int orderPositionInGrid, 
     83                                    CServerDistributionDescription::ServerDistributionType disType = CServerDistributionDescription::BAND_DISTRIBUTION); 
     84      public: 
     85        int zoom_begin_srv, zoom_end_srv, zoom_size_srv; 
     86        int ni_srv, begin_srv, end_srv; 
    7187      private : 
    7288         void checkData(); 
    7389         void checkMask(); 
     90         void checkZoom(); 
     91         void computeServerIndex(const std::vector<int>& globalDim, int orderPositionInGrid, 
     92                                 CServerDistributionDescription::ServerDistributionType disType); 
     93      private: 
     94 
    7495         bool isChecked; 
     96         bool areClientAttributesChecked_; 
    7597         std::set<StdString> relFiles; 
    7698 
  • XIOS/trunk/src/node/context.cpp

    r550 r567  
    308308     if (hasClient) 
    309309     { 
    310 //       std::cout << "Current context " << *this << std::endl; 
    311310       // After xml is parsed, there are some more works with post processing 
    312311       postProcessing(); 
     
    317316     if (hasClient && !hasServer) 
    318317     { 
    319        // After xml is parsed, there are some more works with post processing 
    320 //       postProcessing(); 
    321  
    322 //       setClientServerBuffer(); 
    323  
    324318      // Send all attributes of current context to server 
    325319      this->sendAllAttributesToServer(); 
     
    336330 
    337331      // At last, we have all info of domain and axis, then send them 
    338        sendRefDomainsAxis(); 
     332//       sendRefDomainsAxis(); 
    339333 
    340334      // After that, send all grid (if any) 
    341335       sendRefGrid(); 
    342  
    343  
    344336    } 
    345337 
     
    416408   } 
    417409 
    418 //    void CContext::processEnabledFiles(void) 
    419 //   { 
    420 //     for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 
    421 //     this->enabledFiles[i]->processEnabledFile(); 
    422 //   } 
    423  
    424  
    425410   void CContext::solveAllRefOfEnabledFields(bool sendToServer) 
    426411   { 
     
    440425     } 
    441426   } 
    442  
    443 //   void CContext::solveAllGridRef(void) 
    444 //   { 
    445 //     for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 
    446 //     this->enabledFiles[i]->solveEFGridRef(); 
    447 //   } 
    448 // 
    449 //   void CContext::solveAllOperation(void) 
    450 //   { 
    451 //      for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 
    452 //      this->enabledFiles[i]->solveEFOperation(); 
    453 //   } 
    454 // 
    455 //   void CContext::solveAllExpression(void) 
    456 //   { 
    457 //      for (unsigned int i = 0; i < this->enabledFiles.size(); i++) 
    458 //      this->enabledFiles[i]->solveEFExpression(); 
    459 //   } 
    460427 
    461428   void CContext::solveAllInheritance(bool apply) 
     
    671638      CCalendarWrapper::get(CCalendarWrapper::GetDefName())->createCalendar(); 
    672639      postProcessing(); 
    673 //      std::cout << "server context " << *this << std::endl; 
    674640   } 
    675641 
     
    719685   std::map<int, StdSize>& CContext::getDataSize() 
    720686   { 
    721      std::set<StdString> domainIds; 
     687     // Set of grid used by enabled fields 
     688     std::set<StdString> usedGrid; 
    722689 
    723690     // Find all reference domain and axis of all active fields 
     
    729696       for (int j = 0; j < numEnabledFields; ++j) 
    730697       { 
    731          const std::pair<StdString, StdString>& prDomAxisId = enabledFields[j]->getDomainAxisIds(); 
     698//         const std::pair<StdString, StdString>& prDomAxisId = enabledFields[j]->getDomainAxisIds(); 
     699         StdString currentGrid = enabledFields[j]->grid->getId(); 
    732700         const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataSize(); 
    733701         if (dataSize_.empty()) 
    734702         { 
    735703           dataSize_ = mapSize; 
    736            domainIds.insert(prDomAxisId.first); 
     704           usedGrid.insert(currentGrid); 
     705//           domainIds.insert(prDomAxisId.first); 
    737706         } 
    738707         else 
    739708         { 
    740709           std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 
    741            if (domainIds.find(prDomAxisId.first) == domainIds.end()) 
     710           if (usedGrid.find(currentGrid) == usedGrid.end()) 
    742711           { 
    743712             for (; it != itE; ++it) 
     
    830799 
    831800   //! Client side: Send information of reference domain and axis of active fields 
    832    void CContext::sendRefDomainsAxis() 
    833    { 
    834      std::set<StdString> domainIds; 
    835      std::set<StdString> axisIds; 
    836  
    837      // Find all reference domain and axis of all active fields 
    838      int numEnabledFiles = this->enabledFiles.size(); 
    839      for (int i = 0; i < numEnabledFiles; ++i) 
    840      { 
    841        std::vector<CField*> enabledFields = this->enabledFiles[i]->getEnabledFields(); 
    842        int numEnabledFields = enabledFields.size(); 
    843        for (int j = 0; j < numEnabledFields; ++j) 
    844        { 
    845          const std::pair<StdString, StdString>& prDomAxisId = enabledFields[j]->getDomainAxisIds(); 
    846          domainIds.insert(prDomAxisId.first); 
    847          axisIds.insert(prDomAxisId.second); 
    848        } 
    849      } 
    850  
    851      // Create all reference axis on server side 
    852      std::set<StdString>::iterator itDom, itAxis; 
    853      std::set<StdString>::const_iterator itE; 
    854  
    855      StdString axiDefRoot("axis_definition"); 
    856      CAxisGroup* axisPtr = CAxisGroup::get(axiDefRoot); 
    857      itE = axisIds.end(); 
    858      for (itAxis = axisIds.begin(); itAxis != itE; ++itAxis) 
    859      { 
    860        if (!itAxis->empty()) 
    861        { 
    862          axisPtr->sendCreateChild(*itAxis); 
    863          CAxis::get(*itAxis)->sendAllAttributesToServer(); 
    864        } 
    865      } 
    866  
    867      // Create all reference domains on server side 
    868      StdString domDefRoot("domain_definition"); 
    869      CDomainGroup* domPtr = CDomainGroup::get(domDefRoot); 
    870      itE = domainIds.end(); 
    871      for (itDom = domainIds.begin(); itDom != itE; ++itDom) 
    872      { 
    873        if (!itDom->empty()) { 
    874           domPtr->sendCreateChild(*itDom); 
    875           CDomain::get(*itDom)->sendAllAttributesToServer(); 
    876        } 
    877      } 
    878    } 
     801//   void CContext::sendRefDomainsAxis() 
     802//   { 
     803//     std::set<StdString> domainIds; 
     804//     std::set<StdString> axisIds; 
     805// 
     806//     // Find all reference domain and axis of all active fields 
     807//     int numEnabledFiles = this->enabledFiles.size(); 
     808//     for (int i = 0; i < numEnabledFiles; ++i) 
     809//     { 
     810//       std::vector<CField*> enabledFields = this->enabledFiles[i]->getEnabledFields(); 
     811//       int numEnabledFields = enabledFields.size(); 
     812//       for (int j = 0; j < numEnabledFields; ++j) 
     813//       { 
     814//         const std::pair<StdString, StdString>& prDomAxisId = enabledFields[j]->getDomainAxisIds(); 
     815//         domainIds.insert(prDomAxisId.first); 
     816//         axisIds.insert(prDomAxisId.second); 
     817//       } 
     818//     } 
     819// 
     820//     // Create all reference axis on server side 
     821//     std::set<StdString>::iterator itDom, itAxis; 
     822//     std::set<StdString>::const_iterator itE; 
     823// 
     824//     StdString axiDefRoot("axis_definition"); 
     825//     CAxisGroup* axisPtr = CAxisGroup::get(axiDefRoot); 
     826//     itE = axisIds.end(); 
     827//     for (itAxis = axisIds.begin(); itAxis != itE; ++itAxis) 
     828//     { 
     829//       if (!itAxis->empty()) 
     830//       { 
     831//         axisPtr->sendCreateChild(*itAxis); 
     832//         CAxis::get(*itAxis)->sendAllAttributesToServer(); 
     833//       } 
     834//     } 
     835// 
     836//     // Create all reference domains on server side 
     837//     StdString domDefRoot("domain_definition"); 
     838//     CDomainGroup* domPtr = CDomainGroup::get(domDefRoot); 
     839//     itE = domainIds.end(); 
     840//     for (itDom = domainIds.begin(); itDom != itE; ++itDom) 
     841//     { 
     842//       if (!itDom->empty()) { 
     843//          domPtr->sendCreateChild(*itDom); 
     844//          CDomain::get(*itDom)->sendAllAttributesToServer(); 
     845//       } 
     846//     } 
     847//   } 
    879848 
    880849   //! Update calendar in each time step 
  • XIOS/trunk/src/node/distribution_client.cpp

    r553 r567  
    1616   nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 
    1717   dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 
    18    gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 
     18   gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_(), 
     19   isDataDistributed_(true), axisNum_(0), domainNum_(0), localDataIndexSendToServer_(0) 
    1920{ 
    2021} 
     
    2526   nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 
    2627   dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 
    27    gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 
     28   gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_(), 
     29   isDataDistributed_(true), axisNum_(0), domainNum_(0), localDataIndexSendToServer_(0) 
    2830{ 
    2931  readDistributionInfo(grid); 
     
    3436{ 
    3537  if (0 != localDataIndex_) delete localDataIndex_; 
     38  if (0 != localDataIndexSendToServer_) delete localDataIndexSendToServer_; 
    3639} 
    3740 
     
    4649  std::vector<CDomain*> domList = grid->getDomains(); 
    4750  std::vector<CAxis*> axisList = grid->getAxis(); 
    48   CArray<bool,1>& axisDomainOrder = grid->axisDomainOrder; 
     51  CArray<bool,1> axisDomainOrder = grid->axisDomainOrder; 
    4952 
    5053  std::vector<CDomain*>::iterator itbDom, iteDom, itDom; 
     
    5558 
    5659  // First of all, every attribute of domain and axis should be checked 
    57   for (;itDom != iteDom; ++itDom) (*itDom)->checkAttributesOnClient(); 
    58   for (;itAxis != iteAxis; ++itAxis) (*itAxis)->checkAttributes(); 
     60//  for (;itDom != iteDom; ++itDom) (*itDom)->checkAttributesOnClient(); 
     61//  for (;itAxis != iteAxis; ++itAxis) (*itAxis)->checkAttributesOnClient(); 
     62 
     63  readDistributionInfo(domList, axisList, axisDomainOrder); 
    5964 
    6065  // Then check mask of grid 
     66  int gridDim = domList.size()*2 + axisList.size(); 
    6167  grid->checkMask(); 
    62   CArray<bool,3>& gridMask = grid->mask; 
    63  
    64   //////////////////////////////////////////////////////// 
    65  
    66   int gridDim = domList.size()*2 + axisList.size(); 
    67  
    68   // For now, just suppose that gridMask is all true, but we need to cope with this problem 
    69   //  std::vector<std::vector<bool> > gridMask(gridDim); 
    70 //  int idxDomain = 0, idxAxis = 0; 
    71 //  for (int i = 0; i < axisDomainOrder.size(); ++i) 
    72 //  { 
    73 //    if (axisDomainOrder(i)) 
    74 //    { 
    75 //      gridMask[idxDomain*2+i].resize(domList[idxDomain]->ni); 
    76 //      gridMask[idxDomain*2+i+1].resize(domList[idxDomain]->nj); 
    77 //      ++idxDomain; 
    78 //    } 
    79 //    else 
    80 //    { 
    81 //      gridMask[i].resize(axisList[idxAxis]->ni); 
    82 //      ++idxAxis; 
    83 //    } 
    84 //  } 
    85  
    86   readDistributionInfo(domList, axisList, axisDomainOrder, gridMask); 
     68  switch (gridDim) { 
     69    case 1: 
     70      readGridMaskInfo(grid->mask1); 
     71      break; 
     72    case 2: 
     73      readGridMaskInfo(grid->mask2); 
     74      break; 
     75    case 3: 
     76      readGridMaskInfo(grid->mask3); 
     77      break; 
     78    default: 
     79      break; 
     80  } 
    8781} 
    8882 
     
    9690  \param [in] axisList List of axis of grid 
    9791  \param [in] axisDomainOrder order of axis and domain inside a grid. True if domain, false if axis 
    98   \param [in] gridMask Mask of grid, for now, keep it 3 dimension, but it needs changing 
     92//  \param [in] gridMask Mask of grid, for now, keep it 3 dimension, but it needs changing 
    9993*/ 
    10094void CDistributionClient::readDistributionInfo(const std::vector<CDomain*>& domList, 
    10195                                               const std::vector<CAxis*>& axisList, 
    102                                                const CArray<bool,1>& axisDomainOrder, 
    103                                                const CArray<bool,3>& gridMask) 
    104 { 
     96                                               const CArray<bool,1>& axisDomainOrder) 
     97{ 
     98  domainNum_ = domList.size(); 
     99  axisNum_   = axisList.size(); 
    105100  numElement_ = axisDomainOrder.numElements(); // Number of element, e.x: Axis, Domain 
    106101 
     
    109104 
    110105  // Each domain or axis has its mask, of course 
    111   domainMasks_.resize(domList.size()); 
    112   for (int i = 0; i < domainMasks_.size();++i) 
     106  domainMasks_.resize(domainNum_); 
     107  for (int i = 0; i < domainNum_;++i) 
    113108  { 
    114109    domainMasks_[i].resize(domList[i]->mask.extent(0), domList[i]->mask.extent(1)); 
     
    116111  } 
    117112 
    118   axisMasks_.resize(axisList.size()); 
    119   for (int i = 0; i < axisMasks_.size(); ++i) 
     113  axisMasks_.resize(axisNum_); 
     114  for (int i = 0; i < axisNum_; ++i) 
    120115  { 
    121116    axisMasks_[i].resize(axisList[i]->mask.numElements()); 
    122117    axisMasks_[i] = axisList[i]->mask; 
    123118  } 
    124  
    125   gridMask_.resize(gridMask.extent(0), gridMask.extent(1), gridMask.extent(2)); 
    126   gridMask_ = gridMask; 
    127119 
    128120  // Because domain and axis can be in any order (axis1, domain1, axis2, axis3, ) 
     
    139131      idx += 2; 
    140132    } 
     133    else ++idx; 
    141134  } 
    142135 
     
    215208    ++idx; 
    216209  } 
     210 
     211  // Grid has only one axis and it is not distributed 
     212  bool isDataNotDistributed = true; 
     213  for (int i = 0; i < this->dims_; ++i) 
     214    isDataNotDistributed &= (nLocal_[i] == nGlob_[i]); 
     215  isDataDistributed_ = !isDataNotDistributed; 
    217216} 
    218217 
     
    343342 
    344343    // Find out outer index 
     344    // Depending the inner-most element is axis or domain, 
     345    // The outer loop index begins correspondingly at one (1) or zero (0) 
    345346    idxDomain = idxAxis = 0; 
     347    if (axisDomainOrder_(0)) ++idxDomain; 
     348    else ++idxAxis; 
    346349    for (int i = 1; i < numElement_; ++i) 
    347350    { 
     
    359362    } 
    360363 
     364    int maskIndex = currentIndex[0]; 
     365    for (int j = 0; j < this->dims_; ++j) 
     366 
    361367    // Inner most index 
    362368    idxDomain = idxAxis = 0; 
     
    370376      else currentIndex[0]   = localAxisIndex_[idxAxis][i]; 
    371377 
    372       if (gridMask_(currentIndex[0], currentIndex[1], currentIndex[2])) 
     378      int gridMaskIndex = currentIndex[0]; 
     379      int mulDimMask = 1; 
     380      for (int k = 1; k < this->dims_; ++k) 
     381      { 
     382        mulDimMask *= nLocal_[k-1]; 
     383        gridMaskIndex += (currentIndex[k])*mulDimMask; 
     384      } 
     385 
     386      if (gridMask_(gridMaskIndex)) //(gridMask_(currentIndex[0], currentIndex[1], currentIndex[2])) 
    373387      { 
    374388        ++indexLocalDataOnClientCount; 
     
    389403  this->globalIndex_ = new CArray<size_t,1>(indexSend2ServerCount); 
    390404  localDataIndex_ = new CArray<int,1>(indexLocalDataOnClientCount); 
     405  localDataIndexSendToServer_ = new CArray<int,1>(indexSend2ServerCount); 
    391406 
    392407  // We need to loop with data index 
    393   innerLoopSize = dataNIndex_[0]; 
    394   ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 
    395408  idxLoop.assign(numElement_,0); 
    396409  idx = indexLocalDataOnClientCount = indexSend2ServerCount = 0; 
    397   int count = 0, correctOuterIndexDomain = 0, correctOuterIndexAxis = 0; 
     410  ssize = 1; for (int i = 0; i < numElement_; ++i) ssize *= dataNIndex_[i]; 
     411  innerLoopSize = dataNIndex_[0]; 
     412  int countLocalData = 0; 
     413  std::vector<int> correctOuterIndex(numElement_,0); 
    398414  while (idx < ssize) 
    399415  { 
     
    403419      { 
    404420        idxLoop[i] = 0; 
     421        correctOuterIndex[i] = 0; 
    405422        ++idxLoop[i+1]; 
    406       } 
    407     } 
    408  
    409     // Outer index 
     423        ++correctOuterIndex[i+1]; 
     424      } 
     425    } 
     426 
     427    // Depending the inner-most element axis or domain, 
     428    // The outer loop index begins correspondingly at one (1) or zero (0) 
    410429    idxDomain = idxAxis = 0; 
    411     bool isIndexDomainDataCorrect = false; 
    412     bool isIndexAxisDataCorrect = false; 
     430    if (axisDomainOrder_(0)) ++idxDomain; 
     431    else ++idxAxis; 
     432    bool isIndexDomainDataCorrect = true; 
     433    bool isIndexAxisDataCorrect = true; 
    413434 
    414435    for (int i = 1; i < numElement_; ++i) 
     
    418439        if (indexDomainData_[idxDomain][idxLoop[i]]) 
    419440        { 
    420           currentIndex[indexMap_[i]]   = localDomainIndex_[idxDomain][correctOuterIndexDomain]; 
    421           currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain*2+1][correctOuterIndexDomain]; 
    422           isIndexDomainDataCorrect = true; 
    423           ++correctOuterIndexDomain; 
    424         } 
     441          currentIndex[indexMap_[i]]   = localDomainIndex_[idxDomain][correctOuterIndex[i]]; 
     442          currentIndex[indexMap_[i]+1] = localDomainIndex_[idxDomain*2+1][correctOuterIndex[i]]; 
     443        } 
     444        else isIndexDomainDataCorrect = false; 
    425445        ++idxDomain; 
    426446      } 
     
    429449        if (indexAxisData_[idxAxis][idxLoop[i]]) 
    430450        { 
    431           currentIndex[indexMap_[i]]   = localAxisIndex_[idxAxis][correctOuterIndexAxis]; 
    432           isIndexAxisDataCorrect = true; 
    433           ++correctOuterIndexAxis; 
    434         } 
     451          currentIndex[indexMap_[i]]   = localAxisIndex_[idxAxis][correctOuterIndex[i]]; 
     452        } 
     453        else isIndexAxisDataCorrect = false; 
    435454        ++idxAxis; 
    436455      } 
     
    464483      } 
    465484 
     485      int gridMaskIndex = currentIndex[0]; 
     486      int mulDimMask = 1; 
     487      for (int k = 1; k < this->dims_; ++k) 
     488      { 
     489        mulDimMask *= nLocal_[k-1]; 
     490        gridMaskIndex += (currentIndex[k])*mulDimMask; 
     491      } 
     492 
    466493      if (isIndexDomainDataCorrect && 
    467494          isIndexAxisDataCorrect && 
    468           gridMask_(currentIndex[0], currentIndex[1], currentIndex[2])) 
    469       { 
    470         (*localDataIndex_)(indexLocalDataOnClientCount) = count; 
    471         ++indexLocalDataOnClientCount; 
     495          gridMask_(gridMaskIndex)) 
     496      { 
     497        (*localDataIndex_)(indexLocalDataOnClientCount) = countLocalData; 
    472498 
    473499        bool isIndexOnServer = true; 
     
    486512          } 
    487513          (*this->globalIndex_)(indexSend2ServerCount) = globalIndex; 
     514          (*localDataIndexSendToServer_)(indexSend2ServerCount) = indexLocalDataOnClientCount; 
    488515          ++indexSend2ServerCount; 
    489516        } 
    490       } 
    491       ++count; 
     517        ++indexLocalDataOnClientCount; 
     518      } 
     519      ++countLocalData; 
    492520    } 
    493521    idxLoop[0] += innerLoopSize; 
     
    546574} 
    547575 
     576const CArray<int,1>& CDistributionClient::getLocalDataIndexSendToServerOnClient() const 
     577{ 
     578  return (*localDataIndexSendToServer_); 
     579} 
     580 
    548581} // namespace xios 
  • XIOS/trunk/src/node/distribution_client.hpp

    r554 r567  
    3737 
    3838    virtual const CArray<int,1>& getLocalDataIndexOnClient() const; 
     39    virtual const CArray<int,1>& getLocalDataIndexSendToServerOnClient() const; 
     40 
    3941    std::vector<int> getNGlob() { return nGlob_; } 
     42    std::vector<int> getDataNIndex() { return dataNIndex_; } 
     43    bool isDataDistributed() { return isDataDistributed_; } 
    4044 
    4145  protected: 
     
    4448    void readDistributionInfo(const std::vector<CDomain*>& domList, 
    4549                              const std::vector<CAxis*>& axisList, 
    46                               const CArray<bool,1>& axisDomainOrder, 
    47                               const CArray<bool,3>& gridMask); 
    48  
     50                              const CArray<bool,1>& axisDomainOrder); 
    4951  private: 
    5052    //! Create local index of a domain 
     
    5961    inline int getAxisIndex(const int& dataIndex, const int& dataBegin, const int& ni); 
    6062 
     63    template<int N> 
     64    void readGridMaskInfo(const CArray<bool,N>& gridMask); 
     65 
    6166  private: 
    6267    //!< LocalData index on client 
    6368    CArray<int,1>* localDataIndex_; 
     69    CArray<int,1>* localDataIndexSendToServer_; 
    6470 
    6571  private: 
     
    8591    std::vector<CArray<bool,1> > axisMasks_; //!< Axis mask 
    8692 
    87     // Just suppose that grid mask has 3 dimension. Need change 
    88     CArray<bool,3> gridMask_; // TODO: more general grid mask 
    89  
    9093    std::vector<std::vector<int> > localDomainIndex_; 
    9194    std::vector<std::vector<int> > localAxisIndex_; 
     
    9699    std::vector<std::vector<bool> > indexAxisData_; 
    97100 
     101    //!< (Only for grid with one axis or scalar)Flag to determine whether data is distributed or not 
     102    bool isDataDistributed_; 
     103    int axisNum_; 
     104    int domainNum_; 
     105 
     106  private: 
     107    // Just suppose that grid mask has 3 dimension. Need change 
     108    CArray<bool,1> gridMask_; //!< Mask of grid 
     109 
    98110  private: 
    99111    CDistributionClient(const CDistributionClient& distClient); //! Not implement 
    100112}; 
    101113 
     114template<int N> 
     115void CDistributionClient::readGridMaskInfo(const CArray<bool,N>& gridMask) 
     116{ 
     117  int dim = gridMask.dimensions(); 
     118  std::vector<int> dimensionSizes(dim); 
     119  for (int i = 0; i < dim; ++i) dimensionSizes[i] = gridMask.extent(i); 
     120 
     121  std::vector<int> idxLoop(dim,0); 
     122  int ssize = gridMask.numElements(), idx = 0; 
     123  gridMask_.resize(ssize); 
     124  while (idx < ssize) 
     125  { 
     126    for (int i = 0; i < dim-1; ++i) 
     127    { 
     128      if (idxLoop[i] == dimensionSizes[i]) 
     129      { 
     130        idxLoop[i] = 0; 
     131        ++idxLoop[i+1]; 
     132      } 
     133    } 
     134 
     135    int maskIndex = idxLoop[0]; 
     136    int mulDim = 1; 
     137    for (int k = 1; k < dim; ++k) 
     138    { 
     139      mulDim *= dimensionSizes[k-1]; 
     140      maskIndex += idxLoop[k]*mulDim; 
     141    } 
     142    gridMask_(maskIndex) = *(gridMask.dataFirst()+maskIndex); 
     143 
     144    ++idxLoop[0]; 
     145    ++idx; 
     146  } 
     147} 
     148 
     149 
    102150} // namespace xios 
    103151#endif // __XIOS_DISTRIBUTIONCLIENT_HPP__ 
  • XIOS/trunk/src/node/distribution_server.cpp

    r553 r567  
    1919                                         const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal) 
    2020  : CDistribution(rank, nGlobal.size()), nGlobal_(nGlobal), nZoomSize_(nZoomSize), nZoomBegin_(nZoomBegin) 
     21{ 
     22  createGlobalIndex(); 
     23} 
     24 
     25CDistributionServer::CDistributionServer(int rank, const std::vector<int>& nZoomBegin, 
     26                                         const std::vector<int>& nZoomSize, 
     27                                         const std::vector<int>& nZoomBeginGlobal, 
     28                                         const std::vector<int>& nGlobal) 
     29  : CDistribution(rank, nGlobal.size()), nGlobal_(nGlobal), nZoomBeginGlobal_(nZoomBeginGlobal), 
     30    nZoomSize_(nZoomSize), nZoomBegin_(nZoomBegin) 
    2131{ 
    2232  createGlobalIndex(); 
     
    8999  for (int i = 0; i < ssize; ++i) 
    90100  { 
    91     it = std::lower_bound(it, itEnd, globalIndex(i)); 
     101    it = std::find(itBegin, itEnd, globalIndex(i)); 
     102//    it = std::lower_bound(it, itEnd, globalIndex(i)); 
    92103    if (itEnd != it) 
    93104    { 
     
    114125  for (int i = 0; i < ssize; ++i) 
    115126  { 
    116     it = std::lower_bound(it, itEnd, globalIndex(i)); 
     127    it = std::find(itBegin, itEnd, globalIndex(i)); 
     128//    it = std::lower_bound(it, itEnd, globalIndex(i)); 
    117129    if (itEnd != it) 
    118130    { 
     
    125137} 
    126138 
     139 
     140std::vector<int> CDistributionServer::getZoomBeginGlobal() const 
     141{ 
     142  return nZoomBeginGlobal_; 
     143} 
     144 
     145std::vector<int> CDistributionServer::getZoomBeginServer() const 
     146{ 
     147  return nZoomBegin_; 
     148} 
     149 
     150std::vector<int> CDistributionServer::getZoomSizeServer() const 
     151{ 
     152  return nZoomSize_; 
     153} 
    127154} // namespace xios 
  • XIOS/trunk/src/node/distribution_server.hpp

    r554 r567  
    2424    /** Default constructor */ 
    2525    CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex = 0); 
    26     CDistributionServer(int rank, const std::vector<int>& nZoomBegin, 
    27                         const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal); 
     26    CDistributionServer(int rank, const std::vector<int>& nZoomBeginServer, 
     27                        const std::vector<int>& nZoomSizeServer, const std::vector<int>& nGlobal); 
     28    CDistributionServer(int rank, const std::vector<int>& nZoomBeginServer, 
     29                        const std::vector<int>& nZoomSizeServer, 
     30                        const std::vector<int>& nZoomBeginGlobal, 
     31                        const std::vector<int>& nGlobal); 
    2832 
    2933    /** Default destructor */ 
    3034    virtual ~CDistributionServer(); 
     35 
     36    std::vector<int> getZoomBeginGlobal() const; 
     37    std::vector<int> getZoomBeginServer() const; 
     38    std::vector<int> getZoomSizeServer() const; 
    3139 
    3240    virtual CArray<size_t,1> computeLocalIndex(const CArray<size_t,1>& globalIndex); 
     
    3745  private: 
    3846    std::vector<int> nGlobal_; 
     47    std::vector<int> nZoomBeginGlobal_; 
    3948    std::vector<int> nZoomSize_; 
    4049    std::vector<int> nZoomBegin_; 
     50 
    4151}; 
    4252 
  • XIOS/trunk/src/node/field.cpp

    • Property svn:executable set to *
    r562 r567  
    152152    list< CArray<double,1>* > list_data; 
    153153 
    154      for (it = grid->storeIndex_toSrv.begin(); it != grid->storeIndex_toSrv.end(); it++) 
    155     { 
    156       int rank = (*it).first; 
    157       CArray<int,1>& index = *(it->second); 
    158       CArray<double,1> data_tmp(index.numElements()); 
    159       for (int n = 0; n < data_tmp.numElements(); n++) data_tmp(n) = data(index(n)); 
    160       list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
    161       list_data.push_back(new CArray<double,1>(data_tmp)); 
    162       *list_msg.back() << getId() << *list_data.back(); 
    163       event.push(rank,grid->nbSenders[rank],*list_msg.back()); 
    164     } 
    165     client->sendEvent(event); 
     154    if (!grid->doGridHaveDataDistributed()) 
     155    { 
     156       if (0 == client->getClientRank()) 
     157       { 
     158          for(it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++) 
     159          { 
     160            int rank=(*it).first ; 
     161            CArray<int,1>& index = *(it->second) ; 
     162            CArray<double,1> data_tmp(index.numElements()) ; 
     163            for(int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n)) ; 
     164 
     165            list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
     166            list_data.push_back(new CArray<double,1>(data_tmp)) ; 
     167            *list_msg.back()<<getId()<<*list_data.back() ; 
     168            event.push(rank,1,*list_msg.back()) ; 
     169          } 
     170          client->sendEvent(event) ; 
     171       } else client->sendEvent(event); 
     172    } 
     173    else 
     174    { 
     175      for(it=grid->storeIndex_toSrv.begin();it!=grid->storeIndex_toSrv.end();it++) 
     176      { 
     177        int rank=(*it).first ; 
     178        CArray<int,1>& index = *(it->second) ; 
     179        CArray<double,1> data_tmp(index.numElements()) ; 
     180        for(int n=0;n<data_tmp.numElements();n++) data_tmp(n)=data(index(n)) ; 
     181        list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
     182        list_data.push_back(new CArray<double,1>(data_tmp)) ; 
     183        *list_msg.back()<<getId()<<*list_data.back() ; 
     184        event.push(rank,grid->nbSenders[rank],*list_msg.back()) ; 
     185      } 
     186      client->sendEvent(event) ; 
     187    } 
    166188 
    167189    for (list< CArray<double,1>* >::iterator it = list_data.begin(); it != list_data.end(); it++) delete *it; 
     
    189211  void  CField::recvUpdateData(vector<int>& ranks, vector<CBufferIn*>& buffers) 
    190212  { 
    191  
    192213    if (data_srv.empty()) 
    193214    { 
    194 //      for (map<int, CArray<int, 1>* >::iterator it = grid->out_i_fromClient.begin(); it != grid->out_i_fromClient.end(); it++) 
    195215      for (map<int, CArray<size_t, 1>* >::iterator it = grid->outIndexFromClient.begin(); it != grid->outIndexFromClient.end(); ++it) 
    196216      { 
     
    234254  { 
    235255    if (!getRelFile()->allDomainEmpty) 
    236       if (!grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 
     256      if (grid->doGridHaveDataToWrite() || getRelFile()->type == CFile::type_attr::one_file) //      if (! grid->domain->isEmpty() || getRelFile()->type == CFile::type_attr::one_file) 
    237257      { 
    238258        getRelFile()->checkFile(); 
     
    553573      } 
    554574 
    555 //     if (!grid_ref.isEmpty()) 
    556 //     { 
    557 //       domain = grid->domain; 
    558 //       axis = grid->axis; 
    559 //     } 
    560  
    561 //     CType<string> goodDomain; 
    562 //     CType<string> goodAxis; 
    563 //     if (!grid_ref.isEmpty()) 
    564 //     { 
    565 //       if (!grid->domain_ref.isEmpty()) goodDomain = grid->domain_ref; 
    566 //       if (!grid->axis_ref.isEmpty()) goodAxis = grid->axis_ref; 
    567 //     } 
    568 //     if (!domain_ref.isEmpty()) goodDomain = domain_ref; 
    569 //     if (!axis_ref.isEmpty()) goodAxis = axis_ref; 
    570  
    571 //     CArray<std::string,1> domListTmp = grid->domainList.getValue(); 
    572 //     CArray<std::string,1> axisListTmp = grid->axisList.getValue(); 
    573575 
    574576     if (domList.empty() && axisList.empty()) 
     
    576578       this->grid = CGrid::createGrid(vecDom, vecAxis); 
    577579     } 
    578  
    579 //     std::string goodDomain = domListTmp[0]; 
    580 //     std::string goodAxis = axisListTmp[0]; 
    581  
    582 //     if (goodDomain.isEmpty()) 
    583 //     if (goodDomain.empty()) 
    584 //     { 
    585 //       ERROR("CField::solveGridReference(void)", << "The horizontal domain for this field is not defined"); 
    586 //     } 
    587 //     else 
    588 //     { 
    589 //       if (CDomain::has(goodDomain)) domain = CDomain::get(goodDomain); 
    590 //       else ERROR("CField::solveGridReference(void)",<< "Reference to the domain \'" 
    591 //                  << goodDomain << "\' is wrong"); 
    592 ////                << goodDomain.get() << "\' is wrong"); 
    593 //     } 
    594 // 
    595 ////     if (!goodAxis.isEmpty()) 
    596 //     if (!goodAxis.empty()) 
    597 //     { 
    598 //       if (CAxis::has(goodAxis))  axis = CAxis::get(goodAxis); 
    599 //       else  ERROR("CField::solveGridReference(void)", << "Reference to the axis \'" 
    600 //                   << goodAxis <<"\' is wrong"); 
    601 //                   << goodAxis.get() <<"\' is wrong"); 
    602 //     } 
    603  
    604 //     bool nothingToDo = false; 
    605 // 
    606 //     if (!grid_ref.isEmpty()) 
    607 //     { 
    608 //       if (!grid->domain_ref.isEmpty() && goodDomain.get() == grid->domain_ref.get()) 
    609 //         if (goodAxis.isEmpty()) nothingToDo = true; 
    610 //         else if (!grid->axis_ref.isEmpty()) 
    611 //                 if (grid->axis_ref.get() == goodAxis.get()) nothingToDo = true; 
    612 //     } 
    613 // 
    614 //     nothingToDo = true; 
    615 //     if (!nothingToDo) 
    616 //     { 
    617 //       if (!goodAxis.isEmpty()) 
    618 //       { 
    619 //         this->grid = CGrid::createGrid(domain, axis); 
    620 //         this->grid_ref.setValue(this->grid->getId()); 
    621 //       } 
    622 //       else 
    623 //       { 
    624 //         this->grid = CGrid::createGrid(domain); 
    625 //         this->grid_ref.setValue(this->grid->getId()); 
    626 //       } 
    627 //     } 
    628  
    629 //     grid->solveReference(); 
    630 //     grid->solveDomainAxisRef(); 
    631 //     grid->checkMaskIndex(); 
    632580   } 
    633581 
     
    682630        grid->outputField(it->first,*it->second, fieldOut.dataFirst()); 
    683631      } 
    684  
    685 //         grid->outputField(it->first,*it->second, fieldOut.); 
    686632   } 
    687633 
     
    689635   { 
    690636      map<int, CArray<double,1>* >::iterator it; 
     637      for(it=data_srv.begin();it!=data_srv.end();it++) 
     638      { 
     639         grid->outputField(it->first,*it->second, fieldOut.dataFirst()) ; 
     640      } 
     641   } 
     642 
     643   void CField::outputField(CArray<double,1>& fieldOut) 
     644   { 
     645      map<int, CArray<double,1>* >::iterator it; 
    691646 
    692647      for (it = data_srv.begin(); it != data_srv.end(); it++) 
    693648      { 
    694          grid->outputField(it->first, *it->second, fieldOut); 
     649         grid->outputField(it->first,*it->second, fieldOut.dataFirst()) ; 
    695650      } 
    696651   } 
     
    844799   \return pair of Domain and Axis id 
    845800   */ 
    846    const std::pair<StdString,StdString>& CField::getDomainAxisIds() 
    847    { 
    848      CGrid* cgPtr = getRelGrid(); 
    849      if (NULL != cgPtr) 
    850      { 
    851        if (NULL != cgPtr->getRelDomain()) domAxisIds_.first = cgPtr->getRelDomain()->getId(); 
    852        if (NULL != cgPtr->getRelAxis()) domAxisIds_.second = cgPtr->getRelAxis()->getId(); 
    853      } 
    854  
    855      return domAxisIds_; 
    856    } 
     801//   const std::pair<StdString,StdString>& CField::getDomainAxisIds() 
     802//   { 
     803//     CGrid* cgPtr = getRelGrid(); 
     804//     if (NULL != cgPtr) 
     805//     { 
     806//       if (NULL != cgPtr->getRelDomain()) domAxisIds_.first = cgPtr->getRelDomain()->getId(); 
     807//       if (NULL != cgPtr->getRelAxis()) domAxisIds_.second = cgPtr->getRelAxis()->getId(); 
     808//     } 
     809// 
     810//     return (domAxisIds_); 
     811//   } 
    857812 
    858813   CVariable* CField::addVariable(const string& id) 
  • XIOS/trunk/src/node/field.hpp

    r540 r567  
    135135        void outputField(CArray<double,3>& fieldOut) ; 
    136136        void outputField(CArray<double,2>& fieldOut) ; 
     137        void outputField(CArray<double,1>& fieldOut) ; 
    137138        void scaleFactorAddOffset(double scaleFactor, double addOffset) ; 
    138139        void parse(xml::CXMLNode & node) ; 
     
    156157 
    157158 
    158         const std::pair<StdString, StdString>& getDomainAxisIds(); 
     159//        const std::pair<StdString, StdString>& getDomainAxisIds(); 
    159160      public : 
    160161         /// Propriétés privées /// 
  • XIOS/trunk/src/node/file.cpp

    r561 r567  
    212212 
    213213      allDomainEmpty=true ; 
     214 
    214215      set<CDomain*> setDomain ; 
    215216 
     
    218219      { 
    219220         CField* field = *it; 
    220          allDomainEmpty&=field->grid->domain->isEmpty() ; 
    221          setDomain.insert(field->grid->domain) ; 
     221//         allDomainEmpty&=field->grid->domain->isEmpty() ; 
     222         allDomainEmpty&=(!field->grid->doGridHaveDataToWrite()); 
     223         std::vector<CDomain*> vecDomain = field->grid->getDomains(); 
     224         for (int i = 0; i < vecDomain.size(); ++i) 
     225            setDomain.insert(vecDomain[i]); 
     226//            setDomain.insert(field->grid->domain) ; 
    222227      } 
    223228      nbDomain=setDomain.size() ; 
     
    320325 
    321326        bool append = !this->append.isEmpty() && this->append.getValue(); 
    322          
     327 
    323328         bool useClassicFormat = !format.isEmpty() && format == format_attr::netcdf4_classic; 
    324329 
  • XIOS/trunk/src/node/grid.cpp

    r553 r567  
    2020   CGrid::CGrid(void) 
    2121      : CObjectTemplate<CGrid>(), CGridAttributes() 
    22       , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 
    23       , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
     22      , isChecked(false), isDomainAxisChecked(false), storeIndex(1) 
    2423      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    25       , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_() 
     24      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(), writtenDataSize_(0), globalDim_() 
    2625   { 
    2726     setVirtualDomainGroup(); 
     
    3130   CGrid::CGrid(const StdString & id) 
    3231      : CObjectTemplate<CGrid>(id), CGridAttributes() 
    33       , withAxis(false), isChecked(false), isDomainAxisChecked(false), axis(), domain() 
    34       , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
     32      , isChecked(false), isDomainAxisChecked(false), storeIndex(1) 
    3533      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
    36       , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_() 
     34      , serverDistribution_(0), serverDistributionDescription_(0), clientServerMap_(), writtenDataSize_(0), globalDim_() 
    3735   { 
    3836     setVirtualDomainGroup(); 
     
    4240   CGrid::~CGrid(void) 
    4341   { 
    44  //     this->axis.reset() ; 
    45 //      this->domain.reset() ; 
    4642    deque< CArray<int, 1>* >::iterator it ; 
    4743 
    4844    for(deque< CArray<int,1>* >::iterator it=storeIndex.begin(); it!=storeIndex.end();it++)  delete *it ; 
    49     for(deque< CArray<int,1>* >::iterator it=out_i_index.begin();it!=out_i_index.end();it++) delete *it ; 
    50     for(deque< CArray<int,1>* >::iterator it=out_j_index.begin();it!=out_j_index.end();it++) delete *it ; 
    51     for(deque< CArray<int,1>* >::iterator it=out_l_index.begin();it!=out_l_index.end();it++) delete *it ; 
    52  
    53     for(map<int,CArray<int,1>* >::iterator it=out_i_fromClient.begin();it!=out_i_fromClient.end();it++) delete it->second ; 
    54     for(map<int,CArray<int,1>* >::iterator it=out_j_fromClient.begin();it!=out_j_fromClient.end();it++) delete it->second ; 
    55     for(map<int,CArray<int,1>* >::iterator it=out_l_fromClient.begin();it!=out_l_fromClient.end();it++) delete it->second ; 
    56  
    5745    for(map<int,CArray<size_t,1>* >::iterator it=outIndexFromClient.begin();it!=outIndexFromClient.end();++it) delete (it->second); 
    5846 
     
    6048    if (0 != serverDistribution_) delete serverDistribution_; 
    6149    if (0 != serverDistributionDescription_) delete serverDistributionDescription_; 
    62  
    6350   } 
    6451 
     
    7764 
    7865   //--------------------------------------------------------------- 
    79  
    80    const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void)  const 
    81    { 
    82       return (this->out_i_index ); 
    83    } 
     66// 
     67//   const std::deque< CArray<int,1>* > & CGrid::getOutIIndex(void)  const 
     68//   { 
     69//      return (this->out_i_index ); 
     70//   } 
     71// 
     72//   //--------------------------------------------------------------- 
     73// 
     74//   const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void)  const 
     75//   { 
     76//      return (this->out_j_index ); 
     77//   } 
     78// 
     79//   //--------------------------------------------------------------- 
     80// 
     81//   const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void)  const 
     82//   { 
     83//      return (this->out_l_index ); 
     84//   } 
     85// 
     86//   //--------------------------------------------------------------- 
     87// 
     88//   const CAxis*   CGrid::getRelAxis  (void) const 
     89//   { 
     90//      return (this->axis ); 
     91//   } 
     92 
     93//   //--------------------------------------------------------------- 
     94// 
     95//   const CDomain* CGrid::getRelDomain(void) const 
     96//   { 
     97//      return (this->domain ); 
     98//   } 
    8499 
    85100   //--------------------------------------------------------------- 
    86101 
    87    const std::deque< CArray<int,1>* > & CGrid::getOutJIndex(void) const 
    88    { 
    89       return (this->out_j_index ); 
    90    } 
     102//   bool CGrid::hasAxis(void) const 
     103//   { 
     104//      return (this->withAxis); 
     105//   } 
    91106 
    92107   //--------------------------------------------------------------- 
    93108 
    94    const std::deque< CArray<int,1>* > & CGrid::getOutLIndex(void)  const 
    95    { 
    96       return (this->out_l_index ); 
    97    } 
    98  
    99    //--------------------------------------------------------------- 
    100  
    101    const CAxis*   CGrid::getRelAxis  (void) const 
    102    { 
    103       return (this->axis ); 
    104    } 
    105  
    106    //--------------------------------------------------------------- 
    107  
    108    const CDomain* CGrid::getRelDomain(void) const 
    109    { 
    110       return (this->domain ); 
    111    } 
    112  
    113    //--------------------------------------------------------------- 
    114  
    115    bool CGrid::hasAxis(void) const 
    116    { 
    117       return (this->withAxis); 
    118    } 
    119  
    120    //--------------------------------------------------------------- 
    121  
    122109   StdSize CGrid::getDimension(void) const 
    123110   { 
    124       return ((this->withAxis)?3:2); 
     111      return (globalDim_.size()); 
    125112   } 
    126113 
     
    176163   StdSize CGrid::getDataSize(void) const 
    177164   { 
    178       StdSize retvalue=domain->data_ni.getValue() ; 
    179       if (domain->data_dim.getValue()==2) retvalue*=domain->data_nj.getValue() ; 
    180       if (this->withAxis) retvalue*=this->axis->size.getValue() ; 
    181  
     165      std::vector<int> dataNindex = clientDistribution_->getDataNIndex(); 
     166      StdSize retvalue = 1; 
     167      for (int i = 0; i < dataNindex.size(); ++i) retvalue *= dataNindex[i]; 
    182168      return (retvalue); 
    183169   } 
     
    201187 
    202188 
    203    //--------------------------------------------------------------- 
    204  
    205 //   void CGrid::solveReference(void) 
    206 //   { 
    207 //      if (this->isChecked) return; 
    208 //      CContext* context = CContext::getCurrent() ; 
    209 //      CContextClient* client=context->client ; 
    210 // 
    211 //      this->solveDomainRef() ; 
    212 //      this->solveAxisRef() ; 
    213 // 
    214 //      if (context->hasClient) 
    215 //      { 
    216 //         checkMask() ; 
    217 //         this->computeIndex() ; 
    218 // 
    219 //         this->storeIndex.push_front(new CArray<int,1>() ); 
    220 //         this->out_i_index.push_front(new CArray<int,1>()); 
    221 //         this->out_j_index.push_front(new CArray<int,1>()); 
    222 //         this->out_l_index.push_front(new CArray<int,1>()); 
    223 //      } 
    224 ////      this->computeIndexServer(); 
    225 //      this->isChecked = true; 
    226 //   } 
    227  
    228189   void CGrid::solveDomainAxisRef(bool areAttributesChecked) 
    229190   { 
     
    250211        checkMask() ; 
    251212        this->computeIndex() ; 
    252  
    253213        this->storeIndex.push_front(new CArray<int,1>() ); 
    254         this->out_i_index.push_front(new CArray<int,1>()); 
    255         this->out_j_index.push_front(new CArray<int,1>()); 
    256         this->out_l_index.push_front(new CArray<int,1>()); 
    257214     } 
    258 //      this->computeIndexServer(); 
    259215     this->isChecked = true; 
    260216   } 
    261217 
    262  
    263218   void CGrid::checkMask(void) 
    264219   { 
    265220      using namespace std; 
    266  
    267       unsigned int niu = domain->ni, nju = domain->nj; 
    268       unsigned int nlu = 1 ; 
    269       if (hasAxis()) nlu=axis->size ; 
    270  
    271       if (!mask.isEmpty()) 
    272       { 
    273          if ((mask.extent(0) != niu) || 
    274              (mask.extent(1) != nju) || 
    275              (mask.extent(2) != nlu)) 
    276              ERROR("CGrid::checkAttributes(void)", 
    277                   <<"The mask has not the same size than the local grid"<<endl 
    278                   <<"Local size is "<<niu<<"x"<<nju<<"x"<<nlu<<endl 
    279                   <<"Mask size is "<<mask.extent(0)<<"x"<<mask.extent(1)<<"x"<<mask.extent(2)); 
    280       } 
    281       else 
    282       { 
    283         mask.resize(niu,nju,nlu) ; 
    284         mask=true  ; 
    285       } 
    286  
    287       CArray<bool,2>& domainMask = domain->mask ; 
    288       for (int l=0; l < nlu ; l++) 
    289         for (int j=0; j < nju ; j++) 
    290           for(int i=0; i<niu ; i++) mask(i,j,l) = mask(i,j,l) && domainMask(i,j) ; 
    291  
    292  
    293    } 
    294  
     221      std::vector<CDomain*> domainP = this->getDomains(); 
     222      std::vector<CAxis*> axisP = this->getAxis(); 
     223      int dim = domainP.size() * 2 + axisP.size(); 
     224 
     225      std::vector<CArray<bool,2>* > domainMasks(domainP.size()); 
     226      for (int i = 0; i < domainMasks.size(); ++i) domainMasks[i] = &(domainP[i]->mask); 
     227      std::vector<CArray<bool,1>* > axisMasks(axisP.size()); 
     228      for (int i = 0; i < axisMasks.size(); ++i) axisMasks[i] = &(axisP[i]->mask); 
     229 
     230      switch (dim) { 
     231        case 1: 
     232          checkGridMask(mask1, domainMasks, axisMasks, axisDomainOrder); 
     233          break; 
     234        case 2: 
     235          checkGridMask(mask2, domainMasks, axisMasks, axisDomainOrder); 
     236          break; 
     237        case 3: 
     238          checkGridMask(mask3, domainMasks, axisMasks, axisDomainOrder); 
     239          break; 
     240//        case 4: 
     241//          checkGridMask(mask4, domainMasks, axisMasks, axisDomainOrder); 
     242//          break; 
     243//        case 5: 
     244//          checkGridMask(mask5, domainMasks, axisMasks, axisDomainOrder); 
     245//          break; 
     246//        case 6: 
     247//          checkGridMask(mask6, domainMasks, axisMasks, axisDomainOrder); 
     248//          break; 
     249//        case 7: 
     250//          checkGridMask(mask7, domainMasks, axisMasks, axisDomainOrder); 
     251//          break; 
     252        default: 
     253          break; 
     254      } 
     255   } 
    295256   //--------------------------------------------------------------- 
    296257 
    297 //   void CGrid::solveDomainRef(void) 
    298 //   { 
    299 //      if (!domain_ref.isEmpty()) 
    300 //      { 
    301 //         if (CDomain::has(domain_ref.getValue())) 
    302 //         { 
    303 //            this->domain = CDomain::get(domain_ref.getValue()) ; 
    304 //            domain->checkAttributes() ; 
    305 //         } 
    306 //         else ERROR("CGrid::solveDomainRef(void)", 
    307 //                     << "Wrong domain reference") ; 
    308 //      } 
    309 //      else ERROR("CGrid::solveDomainRef(void)", 
    310 //                  << "Domain reference is not defined") ; 
    311 //   } 
    312 // 
    313 //   //--------------------------------------------------------------- 
    314 // 
    315 //   void CGrid::solveAxisRef(void) 
    316 //   { 
    317 //      if (!axis_ref.isEmpty()) 
    318 //      { 
    319 //         this->withAxis = true ; 
    320 //         if (CAxis::get(axis_ref.getValue())) 
    321 //         { 
    322 //            this->axis = CAxis::get(axis_ref.getValue()) ; 
    323 //            axis->checkAttributes() ; 
    324 //         } 
    325 //         else ERROR("CGrid::solveAxisRef(void)", 
    326 //                    << "Wrong axis reference") ; 
    327 //      } 
    328 //      else withAxis = false ; 
    329 //   } 
    330  
    331  
    332258   void CGrid::solveDomainRef(bool sendAtt) 
    333259   { 
    334 //      if (!domain_ref.isEmpty()) 
    335 //      { 
    336 //         if (CDomain::has(domain_ref.getValue())) 
    337 //         { 
    338 //            this->domain = CDomain::get(domain_ref.getValue()) ; 
    339 //            if (sendAtt) domain->sendCheckedAttributes(); 
    340 //            else domain->checkAttributesOnClient() ; 
    341 //         } 
    342 //         else ERROR("CGrid::solveDomainRef(void)", 
    343 //                     << "Wrong domain reference") ; 
    344 //      } 
    345 //      else ERROR("CGrid::solveDomainRef(void)", 
    346 //                  << "Domain reference is not defined") ; 
    347260      setDomainList(); 
    348       this->domain = CDomain::get(domList_.at(0)); 
    349       if (0 != this->domain) 
    350       { 
    351 //        this->domain = this->getDomain(); 
    352         if (sendAtt) domain->sendCheckedAttributes(); 
    353         else domain->checkAttributesOnClient() ; 
    354       } 
    355       else ERROR("CGrid::solveDomainRef(void)", 
    356                   << "Domain reference is not defined") ; 
     261      std::vector<CDomain*> domListP = this->getDomains(); 
     262      if (!domListP.empty()) 
     263      { 
     264        computeGridGlobalDimension(getDomains(), getAxis(), axisDomainOrder); 
     265        for (int i = 0; i < domListP.size(); ++i) 
     266        { 
     267          if (sendAtt) domListP[i]->sendCheckedAttributes(); 
     268          else domListP[i]->checkAttributesOnClient(); 
     269        } 
     270      } 
    357271   } 
    358272 
    359273   //--------------------------------------------------------------- 
    360274 
    361    void CGrid::solveAxisRef(bool checkAtt) 
    362    { 
    363 //      if (!axis_ref.isEmpty()) 
    364 //      { 
    365 //         this->withAxis = true ; 
    366 //         if (CAxis::get(axis_ref.getValue())) 
    367 //         { 
    368 //            this->axis = CAxis::get(axis_ref.getValue()) ; 
    369 //            axis->checkAttributes() ; 
    370 //         } 
    371 //         else ERROR("CGrid::solveAxisRef(void)", 
    372 //                    << "Wrong axis reference") ; 
    373 //      } 
    374 //      else withAxis = false ; 
    375 //      getAllAxis(); 
     275   void CGrid::solveAxisRef(bool sendAtt) 
     276   { 
    376277      setAxisList(); 
    377       if (!axisList_.empty()) 
    378       { 
    379         int sizeList = axisList_.size(); 
    380         for (int i = 0; i < sizeList; ++i) 
     278      std::vector<CAxis*> axisListP = this->getAxis(); 
     279      if (!axisListP.empty()) 
     280      { 
     281        int idx = 0; 
     282        computeGridGlobalDimension(getDomains(), getAxis(), axisDomainOrder); 
     283        for (int i = 0; i < axisListP.size(); ++i) 
    381284        { 
    382           CAxis::get(axisList_.at(i))->checkAttributes(); 
    383           this->axis = CAxis::get(axisList_.at(i)); 
     285          while (this->axisDomainOrder(idx)) idx += 2; 
     286          if (sendAtt) 
     287            axisListP[i]->sendCheckedAttributes(globalDim_,idx); 
     288          else 
     289            axisListP[i]->checkAttributesOnClient(globalDim_,idx); 
     290          ++idx; 
    384291        } 
    385         withAxis = true; 
    386  
    387       } 
    388 //      if (!axis_ref.isEmpty()) 
    389 //      { 
    390 //         this->withAxis = true ; 
    391 //         if (CAxis::get(axis_ref.getValue())) 
    392 //         { 
    393 //            this->axis = CAxis::get(axis_ref.getValue()) ; 
    394 //            axis->checkAttributes() ; 
    395 //         } 
    396 //         else ERROR("CGrid::solveAxisRef(void)", 
    397 //                    << "Wrong axis reference") ; 
    398 //      } 
    399       else withAxis = false ; 
     292 
     293      } 
    400294   } 
    401295 
     
    415309 
    416310     // Finally, compute index mapping between client(s) and server(s) 
    417      clientServerMap_.computeServerIndexMapping(clientDistribution_->getGlobalIndex(),serverDistributionDescription_->getGlobalIndex()); 
     311     clientServerMap_.computeServerIndexMapping(clientDistribution_->getGlobalIndex(), 
     312                                                clientDistribution_->getLocalDataIndexSendToServerOnClient(), 
     313                                                serverDistributionDescription_->getGlobalIndex()); 
    418314     const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_.getGlobalIndexOnServer(); 
    419315     std::vector<int> connectedServerRank; 
     
    427323     storeIndex_client = (clientDistribution_->getLocalDataIndexOnClient()); 
    428324 
    429 /* 
    430       const int ni   = domain->ni.getValue() , 
    431                 nj   = domain->nj.getValue() , 
    432                 size = (this->hasAxis()) ? axis->size.getValue() : 1 , 
    433                 lbegin = (this->hasAxis()) ? axis->zoom_begin.getValue()-1 : 0 , 
    434                 lend = (this->hasAxis()) ? axis->zoom_end.getValue()-1 : 0 ; 
    435  
    436  
    437       const int data_dim     = domain->data_dim.getValue() , 
    438                 data_n_index = domain->data_n_index.getValue() , 
    439                 data_ibegin  = domain->data_ibegin.getValue() , 
    440                 data_jbegin  = (data_dim == 2) 
    441                              ? domain->data_jbegin.getValue() : -1; 
    442  
    443       CArray<int,1> data_i_index = domain->data_i_index ; 
    444       CArray<int,1> data_j_index = domain->data_j_index ; 
    445  
    446  
    447       int indexCount = 0; 
    448  
    449       for(int l = 0; l < size ; l++) 
    450       { 
    451          for(int n = 0, i = 0, j = 0; n < data_n_index; n++) 
    452          { 
    453             int temp_i = data_i_index(n) + data_ibegin, 
    454                 temp_j = (data_dim == 1) ? -1 
    455                        : data_j_index(n) + data_jbegin; 
    456             i = (data_dim == 1) ? (temp_i - 1) % ni 
    457                                 : (temp_i - 1) ; 
    458             j = (data_dim == 1) ? (temp_i - 1) / ni 
    459                                 : (temp_j - 1) ; 
    460  
    461             if ((l >=lbegin && l<= lend) && 
    462                 (i >= 0 && i < ni) && 
    463                 (j >= 0 && j < nj) && mask(i,j,l)) 
    464                indexCount++ ; 
    465          } 
    466       } 
    467  
    468       storeIndex[0]  = new CArray<int,1>(indexCount) ; 
    469       out_i_index[0] = new CArray<int,1>(indexCount) ; 
    470       out_j_index[0] = new CArray<int,1>(indexCount) ; 
    471       out_l_index[0] = new CArray<int,1>(indexCount) ; 
    472  
    473       storeIndex_client.resize(indexCount) ; 
    474       out_i_client.resize(indexCount) ; 
    475       out_j_client.resize(indexCount) ; 
    476       out_l_client.resize(indexCount) ; 
    477  
    478  
    479       for(int count = 0, indexCount = 0,  l = 0; l < size; l++) 
    480       { 
    481          for(int n = 0, i = 0, j = 0; n < data_n_index; n++, count++) 
    482          { 
    483             int temp_i = data_i_index(n) + data_ibegin, 
    484                 temp_j = (data_dim == 1) ? -1 
    485                        : data_j_index(n) + data_jbegin; 
    486             i = (data_dim == 1) ? (temp_i - 1) % ni 
    487                                 : (temp_i - 1) ; 
    488             j = (data_dim == 1) ? (temp_i - 1) / ni 
    489                                 : (temp_j - 1) ; 
    490  
    491             if ((l >= lbegin && l <= lend) && 
    492                 (i >= 0 && i < ni) && 
    493                 (j >= 0 && j < nj) && mask(i,j,l)) 
    494             { 
    495                (*storeIndex[0])(indexCount) = count ; 
    496                (*out_l_index[0])(indexCount) = l ; 
    497                (*out_i_index[0])(indexCount) = i ; 
    498                (*out_j_index[0])(indexCount) = j ; 
    499  
    500                storeIndex_client(indexCount) = count ; 
    501                out_i_client(indexCount)=i+domain->ibegin_client-1 ; 
    502                out_j_client(indexCount)=j+domain->jbegin_client-1 ; 
    503                out_l_client(indexCount)=l-lbegin ; 
    504                indexCount++ ; 
    505             } 
    506          } 
    507       } 
    508 */ 
    509 //      computeDomConServer(); 
    510 //      sendIndex() ; 
    511  
    512  
    513325   } 
    514326 
     
    517329   CGrid* CGrid::createGrid(CDomain* domain) 
    518330   { 
    519       StdString new_id = StdString("__") + domain->getId() + StdString("__") ; 
    520       CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; 
    521  
    522331      std::vector<CDomain*> vecDom(1,domain); 
    523       grid->setDomainList(vecDom); 
    524 //      grid->domain_ref.setValue(domain->getId()); 
     332      std::vector<CAxis*> vecAxis; 
     333 
     334      CGrid* grid = createGrid(vecDom, vecAxis); 
     335 
    525336      return (grid); 
    526337   } 
     
    528339   CGrid* CGrid::createGrid(CDomain* domain, CAxis* axis) 
    529340   { 
    530       StdString new_id = StdString("__") + domain->getId() + 
    531                          StdString("_") + axis->getId() + StdString("__") ; 
    532       CGrid* grid = CGridGroup::get("grid_definition")->createChild(new_id) ; 
    533  
    534341      std::vector<CDomain*> vecDom(1,domain); 
    535342      std::vector<CAxis*> vecAxis(1,axis); 
    536       grid->setDomainList(vecDom); 
    537       grid->setAxisList(vecAxis); 
    538 //      grid->domain_ref.setValue(domain->getId()); 
    539 //      grid->axis_ref.setValue(axis->getId()); 
     343      CGrid* grid = createGrid(vecDom, vecAxis); 
     344 
    540345      return (grid); 
    541346   } 
     
    564369      } 
    565370 
     371      grid->computeGridGlobalDimension(domains, axis, grid->axisDomainOrder); 
     372 
    566373      return (grid); 
    567374   } 
     
    575382   { 
    576383     return (this->vAxisGroup_); 
    577    } 
    578  
    579    //---------------------------------------------------------------- 
    580  
    581    void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 3>& field) 
    582    { 
    583       CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    584       CArray<int,1>& out_j=*out_j_fromClient[rank] ; 
    585       CArray<int,1>& out_l=*out_l_fromClient[rank] ; 
    586  
    587       for(StdSize n = 0; n < stored.numElements(); n++) 
    588          field(out_i(n), out_j(n), out_l(n)) = stored(n) ; 
    589    } 
    590  
    591    void CGrid::outputField(int rank, const CArray<double, 1>& stored,  CArray<double, 2>& field) 
    592    { 
    593       CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    594       CArray<int,1>& out_j=*out_j_fromClient[rank] ; 
    595  
    596       for(StdSize n = 0; n < stored.numElements(); n++) 
    597          field(out_i(n), out_j(n)) = stored(n) ;   } 
    598  
    599    //--------------------------------------------------------------- 
    600  
    601    void CGrid::outputField(int rank,const CArray<double, 1>& stored,  CArray<double, 1>& field) 
    602    { 
    603       CArray<int,1>& out_i=*out_i_fromClient[rank] ; 
    604  
    605       for(StdSize n = 0; n < stored.numElements(); n++) 
    606          field(out_i(n)) = stored(n) ; 
    607384   } 
    608385 
     
    629406   } 
    630407 
    631    //--------------------------------------------------------------- 
    632  
    633 //  void CGrid::sendIndex(void) 
    634 //  { 
    635 //    CContext* context = CContext::getCurrent() ; 
    636 //    CContextClient* client=context->client ; 
    637 // 
    638 //    CEventClient event(getType(),EVENT_ID_INDEX) ; 
    639 //    int rank ; 
    640 //    list<shared_ptr<CMessage> > list_msg ; 
    641 //    list< CArray<int,1>* > list_out_i,list_out_j,list_out_l ; 
    642 // 
    643 //    for(int ns=0;ns<domain->connectedServer.size();ns++) 
    644 //    { 
    645 //       rank=domain->connectedServer[ns] ; 
    646 // 
    647 //       int i,j ; 
    648 //       int nb=0 ; 
    649 //       for(int k=0;k<storeIndex_client.numElements();k++) 
    650 //       { 
    651 //         i=out_i_client(k)- domain->ibegin +1; 
    652 //         j=out_j_client(k)- domain->jbegin +1; 
    653 //         if (domain->mapConnectedServer(i,j)==ns)  nb++ ; 
    654 //       } 
    655 //       CArray<int,1> storeIndex(nb) ; 
    656 //       CArray<int,1> out_i(nb) ; 
    657 //       CArray<int,1> out_j(nb) ; 
    658 //       CArray<int,1> out_l(nb) ; 
    659 // 
    660 // 
    661 //       nb=0 ; 
    662 //       for(int k=0;k<storeIndex_client.numElements();k++) 
    663 //       { 
    664 //         i=out_i_client(k)- domain->ibegin +1 ; 
    665 //         j=out_j_client(k)- domain->jbegin +1 ; 
    666 //         if (domain->mapConnectedServer(i,j)==ns) 
    667 //         { 
    668 //            storeIndex(nb)=k ; 
    669 //            out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 
    670 //            out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 
    671 //            out_l(nb)=out_l_client(k) ; 
    672 //            nb++ ; 
    673 //         } 
    674 //       } 
    675 // 
    676 //       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 
    677 //       nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 
    678 //       list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
    679 //       list_out_i.push_back(new CArray<int,1>(out_i)) ; 
    680 //       list_out_j.push_back(new CArray<int,1>(out_j)) ; 
    681 //       list_out_l.push_back(new CArray<int,1>(out_l)) ; 
    682 // 
    683 //       *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; 
    684 //       event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; 
    685 //    } 
    686 //    client->sendEvent(event) ; 
    687 // 
    688 //    for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; 
    689 //    for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 
    690 //    for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 
    691 // 
    692 //  } 
    693  
    694   void CGrid::computeDomConServer() 
    695   { 
    696     if (!isDomConServerComputed_) 
    697     { 
    698       for(int ns=0;ns<domain->connectedServer.size(); ++ns) 
    699       { 
    700          int rank=domain->connectedServer[ns] ; 
    701  
    702          int i,j ; 
    703          int nb=0 ; 
    704          for(int k=0;k<storeIndex_client.numElements();++k) 
    705          { 
    706            i=out_i_client(k)- domain->ibegin +1; 
    707            j=out_j_client(k)- domain->jbegin +1; 
    708            if (domain->mapConnectedServer(i,j)==ns)  ++nb ; 
    709          } 
    710  
    711          domConnectedServerSide_.insert(std::make_pair(rank, nb)); 
    712       } 
    713       isDomConServerComputed_ = true; 
    714     } 
    715   } 
    716  
    717  
    718   std::map<int, int> CGrid::getDomConServerSide() 
    719   { 
    720     return domConnectedServerSide_; 
    721   } 
    722  
    723408  void CGrid::sendIndex(void) 
    724409  { 
     
    739424    itLocal = localIndexSendToServer.begin(); 
    740425 
    741     for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) 
    742     { 
    743       rank = itGlobal->first; 
    744       int nb = (itGlobal->second).size(); 
    745  
    746       CArray<size_t, 1> outGlobalIndexOnServer(nb); 
    747       CArray<int, 1> outLocalIndexToServer(nb); 
    748       for (int k = 0; k < nb; ++k) 
    749       { 
    750         outGlobalIndexOnServer(k) = itGlobal->second.at(k); 
    751         outLocalIndexToServer(k)  = itLocal->second.at(k); 
    752       } 
    753  
    754       storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 
    755       listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 
    756  
    757       list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
    758       *list_msg.back()<<getId()<<*listOutIndex.back(); 
    759       event.push(rank, nbSenders[rank], *list_msg.back()); 
    760     } 
    761     client->sendEvent(event); 
     426    if (!doGridHaveDataDistributed()) 
     427    { 
     428      if (0 == client->getClientRank()) 
     429      { 
     430       for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) 
     431        { 
     432          rank = itGlobal->first; 
     433          int nb = (itGlobal->second).size(); 
     434 
     435          CArray<size_t, 1> outGlobalIndexOnServer(nb); 
     436          CArray<int, 1> outLocalIndexToServer(nb); 
     437          for (int k = 0; k < nb; ++k) 
     438          { 
     439            outGlobalIndexOnServer(k) = itGlobal->second.at(k); 
     440            outLocalIndexToServer(k)  = itLocal->second.at(k); 
     441          } 
     442 
     443          storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 
     444          listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 
     445 
     446          list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
     447          *list_msg.back()<<getId()<<*listOutIndex.back(); 
     448          event.push(rank, 1, *list_msg.back()); 
     449        } 
     450        client->sendEvent(event); 
     451      } else client->sendEvent(event); 
     452    } 
     453    else 
     454    { 
     455      for (int ns = 0; itGlobal != iteMap; ++itGlobal, ++itLocal, ++ns) 
     456      { 
     457        rank = itGlobal->first; 
     458        int nb = (itGlobal->second).size(); 
     459 
     460        CArray<size_t, 1> outGlobalIndexOnServer(nb); 
     461        CArray<int, 1> outLocalIndexToServer(nb); 
     462        for (int k = 0; k < nb; ++k) 
     463        { 
     464          outGlobalIndexOnServer(k) = itGlobal->second.at(k); 
     465          outLocalIndexToServer(k)  = itLocal->second.at(k); 
     466        } 
     467 
     468        storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(outLocalIndexToServer) )); 
     469        listOutIndex.push_back(new CArray<size_t,1>(outGlobalIndexOnServer)); 
     470 
     471        list_msg.push_back(shared_ptr<CMessage>(new CMessage)); 
     472        *list_msg.back()<<getId()<<*listOutIndex.back(); 
     473        event.push(rank, nbSenders[rank], *list_msg.back()); 
     474      } 
     475      client->sendEvent(event); 
     476    } 
     477 
    762478    for(list<CArray<size_t,1>* >::iterator it=listOutIndex.begin();it!=listOutIndex.end();++it) delete *it ; 
    763  
    764 /* 
    765     if (!isDomConServerComputed_) computeDomConServer(); 
    766  
    767     for(int ns=0;ns<domain->connectedServer.size();ns++) 
    768     { 
    769        rank=domain->connectedServer[ns] ; 
    770  
    771        int nb = domConnectedServerSide_.find(rank)->second; 
    772        CArray<int,1> storeIndex(nb) ; 
    773        CArray<int,1> out_i(nb) ; 
    774        CArray<int,1> out_j(nb) ; 
    775        CArray<int,1> out_l(nb) ; 
    776  
    777        int i, j; 
    778        nb=0 ; 
    779        for(int k=0;k<storeIndex_client.numElements();k++) 
    780        { 
    781          i=out_i_client(k)- domain->ibegin +1 ; 
    782          j=out_j_client(k)- domain->jbegin +1 ; 
    783          if (domain->mapConnectedServer(i,j)==ns) 
    784          { 
    785             storeIndex(nb)=k ; 
    786             out_i(nb)=domain->i_index(i,j) + domain->ibegin-1; 
    787             out_j(nb)=domain->j_index(i,j) + domain->jbegin-1; 
    788             out_l(nb)=out_l_client(k) ; 
    789             nb++ ; 
    790          } 
    791        } 
    792  
    793        storeIndex_toSrv.insert( pair<int,CArray<int,1>* >(rank,new CArray<int,1>(storeIndex) )) ; 
    794        nbSenders.insert(pair<int,int>(rank,domain->nbSenders[ns])) ; 
    795        list_msg.push_back(shared_ptr<CMessage>(new CMessage)) ; 
    796        list_out_i.push_back(new CArray<int,1>(out_i)) ; 
    797        list_out_j.push_back(new CArray<int,1>(out_j)) ; 
    798        list_out_l.push_back(new CArray<int,1>(out_l)) ; 
    799  
    800        *list_msg.back()<<getId()<<*list_out_i.back()<<*list_out_j.back()<<*list_out_l.back() ; 
    801        event.push(rank,domain->nbSenders[ns],*list_msg.back()) ; 
    802     } 
    803     client->sendEvent(event) ; 
    804  
    805     for(list<CArray<int,1>* >::iterator it=list_out_i.begin();it!=list_out_i.end();it++) delete *it ; 
    806     for(list<CArray<int,1>* >::iterator it=list_out_j.begin();it!=list_out_j.end();it++) delete *it ; 
    807     for(list<CArray<int,1>* >::iterator it=list_out_l.begin();it!=list_out_l.end();it++) delete *it ; 
    808 */ 
    809479  } 
    810480 
     
    820490      get(gridId)->recvIndex(rank,*buffer) ; 
    821491    } 
     492  } 
     493 
     494  void CGrid::computeGridGlobalDimension(const std::vector<CDomain*>& domains, 
     495                                         const std::vector<CAxis*>& axis, 
     496                                         const CArray<bool,1>& axisDomainOrder) 
     497  { 
     498    globalDim_.resize(domains.size()*2+axis.size()); 
     499    int idx = 0, idxDomain = 0, idxAxis = 0; 
     500    for (int i = 0; i < axisDomainOrder.numElements(); ++i) 
     501    { 
     502      if (axisDomainOrder(i)) 
     503      { 
     504        globalDim_[idx]   = domains[idxDomain]->ni_glo.getValue(); 
     505        globalDim_[idx+1] = domains[idxDomain]->nj_glo.getValue(); 
     506        ++idxDomain; 
     507        idx += 2; 
     508      } 
     509      else 
     510      { 
     511        globalDim_[idx] = axis[idxAxis]->size.getValue(); 
     512        ++idxAxis; 
     513        ++idx; 
     514      } 
     515    } 
     516  } 
     517 
     518  std::vector<int> CGrid::getGlobalDimension() 
     519  { 
     520    return globalDim_; 
     521  } 
     522 
     523  /*! 
     524    Verify whether one server need to write data 
     525    There are some cases on which one server has nodata to write. For example, when we 
     526  just only want to zoom on a domain. 
     527  */ 
     528  bool CGrid::doGridHaveDataToWrite() 
     529  { 
     530    return (0 != serverDistribution_); 
     531  } 
     532 
     533  /*! 
     534    Return size of data which is written on each server 
     535    Whatever dimension of a grid, data which are written on server must be presented as 
     536  an one dimension array. 
     537  \return size of data written on server 
     538  */ 
     539  size_t CGrid::getWrittenDataSize() const 
     540  { 
     541    return writtenDataSize_; 
     542  } 
     543 
     544 
     545  const CDistributionServer* CGrid::getDistributionServer() const 
     546  { 
     547    return serverDistribution_; 
     548  } 
     549 
     550  bool CGrid::doGridHaveDataDistributed() 
     551  { 
     552    return clientDistribution_->isDataDistributed(); 
    822553  } 
    823554 
     
    835566         indexMap[i] = idx; 
    836567         if (true == axisDomainOrder(i)) 
    837         { 
    838           ++ssize; 
    839           idx += 2; 
    840         } 
     568         { 
     569            ++ssize; 
     570            idx += 2; 
     571         } 
     572         else 
     573          ++idx; 
    841574       } 
    842575 
     
    844577       std::vector<CDomain*> domainList = getDomains(); 
    845578       std::vector<CAxis*> axisList = getAxis(); 
    846        std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize); 
     579       std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize), nZoomBeginGlobal(ssize); 
    847580       for (int i = 0; i < numElement; ++i) 
    848581       { 
     
    851584            nZoomBegin[indexMap[i]]   = domainList[domainId]->zoom_ibegin_srv; 
    852585            nZoomSize[indexMap[i]]    = domainList[domainId]->zoom_ni_srv; 
     586            nZoomBeginGlobal[indexMap[i]] = domainList[domainId]->zoom_ibegin; 
    853587            nGlob[indexMap[i]]    = domainList[domainId]->ni_glo; 
    854588 
    855589            nZoomBegin[indexMap[i]+1] = domainList[domainId]->zoom_jbegin_srv; 
    856590            nZoomSize[indexMap[i]+1]  = domainList[domainId]->zoom_nj_srv; 
     591            nZoomBeginGlobal[indexMap[i]+1] = domainList[domainId]->zoom_jbegin; 
    857592            nGlob[indexMap[i]+1]    = domainList[domainId]->nj_glo; 
    858593            ++domainId; 
     
    860595         else 
    861596         { 
    862             nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin; 
    863             nZoomSize[indexMap[i]]  = axisList[axisId]->zoom_size; 
     597            nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin_srv; 
     598            nZoomSize[indexMap[i]]  = axisList[axisId]->zoom_size_srv; 
     599            nZoomBeginGlobal[indexMap[i]] = axisList[axisId]->zoom_begin; 
    864600            nGlob[indexMap[i]]      = axisList[axisId]->size; 
    865601            ++axisId; 
    866602         } 
    867603       } 
    868        serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, nGlob); 
     604       writtenDataSize_ = 1; 
     605       for (int i = 0; i < nZoomSize.size(); ++i) 
     606        writtenDataSize_ *= nZoomSize[i]; 
     607 
     608       serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, 
     609                                                     nZoomBeginGlobal, nGlob); 
    869610     } 
    870611 
     
    873614     serverDistribution_->computeLocalIndex(outIndex); 
    874615     outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 
    875  
    876     /* 
    877     CArray<int,1> out_i ; 
    878     CArray<int,1> out_j ; 
    879     CArray<int,1> out_l ; 
    880  
    881     buffer>>out_i>>out_j>>out_l ; 
    882  
    883     out_i -= domain->zoom_ibegin_srv-1 ; 
    884     out_j -= domain->zoom_jbegin_srv-1 ; 
    885  
    886     out_i_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_i) )) ; 
    887     out_j_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_j) )) ; 
    888     out_l_fromClient.insert(pair< int,CArray<int,1>* >(rank,new CArray<int,1>(out_l) )) ; 
    889     */ 
    890616  } 
    891617 
     
    1240966  { 
    1241967    SuperClass::parse(node); 
     968 
    1242969    // List order of axis and domain in a grid, if there is a domain, it will take value 1 (true), axis 0 (false) 
    1243 //    std::vector<int> axisOrder; 
    1244970    std::vector<bool> order; 
    1245971 
  • XIOS/trunk/src/node/grid.hpp

    r553 r567  
    1515#include "server_distribution_description.hpp" 
    1616#include "client_server_mapping.hpp" 
     17#include "utils.hpp" 
    1718 
    1819namespace xios { 
     
    133134         void computeIndexServer(void); 
    134135         void computeIndex(void); 
    135 //         void solveDomainRef(void);  //TODO temporarily comment 
    136 //         void solveAxisRef(void);   // TODO: temporarily comment 
    137136 
    138137         void solveDomainRef(bool checkAtt); 
     
    164163         std::vector<CAxis*> getAxis(); 
    165164         std::vector<int> getAxisOrder(); 
     165         std::vector<int> getGlobalDimension(); 
     166 
     167         bool doGridHaveDataToWrite(); 
     168         bool doGridHaveDataDistributed(); 
     169         size_t getWrittenDataSize() const; 
     170 
     171         const CDistributionServer* getDistributionServer() const; 
    166172 
    167173      public: 
    168174 
    169175         /// Propriétés privées /// 
    170          bool withAxis ; 
    171176         bool isChecked; 
    172177         bool isDomainAxisChecked; 
    173178         bool isIndexSent; 
    174179 
    175          CAxis*   axis ; 
    176          CDomain* domain ; 
    177  
    178180         std::deque< CArray<int, 1>* > storeIndex ; 
    179          std::deque< CArray<int, 1>* > out_i_index ; 
    180          std::deque< CArray<int, 1>* > out_j_index ; 
    181          std::deque< CArray<int, 1>* > out_l_index ; 
    182  
    183181        CArray<int, 1>  storeIndex_client ; 
    184         CArray<int, 1>  out_i_client ; 
    185         CArray<int, 1>  out_j_client ; 
    186         CArray<int, 1>  out_l_client ; 
     182 
    187183 
    188184         map<int, CArray<int, 1>* >  storeIndex_toSrv ; 
    189185         map<int,int> nbSenders ; 
    190 //         std::deque<ARRAY(int, 1)> out_i_toSrv ; 
    191 //         std::deque<ARRAY(int, 1)> out_j_toSrv ; 
    192 //         std::deque<ARRAY(int, 1)> out_l_toSrv ; 
    193  
    194          map<int, CArray<int, 1>* > out_i_fromClient ; 
    195          map<int, CArray<int, 1>* > out_j_fromClient ; 
    196          map<int, CArray<int, 1>* > out_l_fromClient ; 
    197186 
    198187         map<int, CArray<size_t, 1>* > outIndexFromClient; 
    199188         void checkMask(void) ; 
    200189 
    201          std::map<int, int> domConnectedServerSide_; 
    202          bool isDomConServerComputed_; 
    203  
    204190      private: 
     191       template<int N> 
     192       void checkGridMask(CArray<bool,N>& gridMask, 
     193                          const std::vector<CArray<bool,2>* >& domainMasks, 
     194                          const std::vector<CArray<bool,1>* >& axisMasks, 
     195                          const CArray<bool,1>& axisDomainOrder); 
    205196        void setVirtualDomainGroup(CDomainGroup* newVDomainGroup); 
    206197        void setVirtualDomainGroup(); 
    207198        void setVirtualAxisGroup(CAxisGroup* newVAxisGroup); 
    208199        void setVirtualAxisGroup(); 
    209 //        void setAxisList(); 
     200 
    210201        void setAxisList(const std::vector<CAxis*> axis = std::vector<CAxis*>()); 
    211 //        void setDomainList(); 
    212202        void setDomainList(const std::vector<CDomain*> domains = std::vector<CDomain*>()); 
     203 
     204        void computeGridGlobalDimension(const std::vector<CDomain*>& domains, 
     205                                        const std::vector<CAxis*>& axis, 
     206                                        const CArray<bool,1>& axisDomainOrder); 
    213207 
    214208        CDomain* addDomain(const std::string& id); 
     
    217211        CAxisGroup* getVirtualAxisGroup() const; 
    218212        CDomainGroup* getVirtualDomainGroup() const; 
     213        std::vector<int> globalDim_; 
    219214      private: 
    220215        CDomainGroup* vDomainGroup_; 
     
    222217        std::vector<std::string> axisList_, domList_; 
    223218        bool isAxisListSet, isDomListSet; 
     219 
    224220        CDistributionClient* clientDistribution_; 
    225221        CDistributionServer* serverDistribution_; 
    226222        CServerDistributionDescription* serverDistributionDescription_; 
    227223        CClientServerMapping clientServerMap_; 
     224        size_t writtenDataSize_; 
    228225   }; // class CGrid 
    229226 
     
    231228 
    232229   template <int n> 
    233       void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const 
     230   void CGrid::inputField(const CArray<double,n>& field, CArray<double,1>& stored) const 
    234231   { 
    235232      if (this->getDataSize() != field.numElements()) 
     
    241238   } 
    242239 
     240   template<int N> 
     241   void CGrid::checkGridMask(CArray<bool,N>& gridMask, 
     242                             const std::vector<CArray<bool,2>* >& domainMasks, 
     243                             const std::vector<CArray<bool,1>* >& axisMasks, 
     244                             const CArray<bool,1>& axisDomainOrder) 
     245   { 
     246     int idx = 0; 
     247     int numElement = axisDomainOrder.numElements(); 
     248     int dim = domainMasks.size()*2 + axisMasks.size(); 
     249 
     250     std::vector<int> idxLoop(dim,0), indexMap(numElement), eachDimSize(dim); 
     251     std::vector<int> currentIndex(dim); 
     252     int idxDomain = 0, idxAxis = 0; 
     253    for (int i = 0; i < numElement; ++i) 
     254    { 
     255      indexMap[i] = idx; 
     256      if (true == axisDomainOrder(i)) { 
     257          eachDimSize[indexMap[i]]   = domainMasks[idxDomain]->extent(0); 
     258          eachDimSize[indexMap[i]+1] = domainMasks[idxDomain]->extent(1); 
     259          idx += 2; ++idxDomain; 
     260      } 
     261      else { 
     262        eachDimSize[indexMap[i]] = axisMasks[idxAxis]->numElements(); 
     263        ++idx; ++idxAxis; 
     264      } 
     265    } 
     266 
     267    if (!gridMask.isEmpty()) 
     268    { 
     269      for (int i = 0; i < dim; ++i) 
     270      { 
     271        if (gridMask.extent(i) != eachDimSize[i]) 
     272           ERROR("CGrid::checkMask(void)", 
     273                <<"The mask has one dimension whose size is different from the one of the local grid"<<endl 
     274                <<"Local size is "<< i << " " << eachDimSize[i]<<endl 
     275                <<"Mask dimension size is "<<gridMask.extent(i)); 
     276      } 
     277    } 
     278    else { 
     279        CArrayBoolTraits<CArray<bool,N> >::resizeArray(gridMask,eachDimSize); 
     280        gridMask = true; 
     281    } 
     282 
     283    int ssize = gridMask.numElements(); 
     284    idx = 0; 
     285    while (idx < ssize) 
     286    { 
     287      for (int i = 0; i < dim-1; ++i) 
     288      { 
     289        if (idxLoop[i] == eachDimSize[i]) 
     290        { 
     291          idxLoop[i] = 0; 
     292          ++idxLoop[i+1]; 
     293        } 
     294      } 
     295 
     296      // Find out outer index 
     297      idxDomain = idxAxis = 0; 
     298      bool maskValue = true; 
     299      for (int i = 0; i < numElement; ++i) 
     300      { 
     301        if (axisDomainOrder(i)) 
     302        { 
     303          maskValue = maskValue && (*domainMasks[idxDomain])(idxLoop[indexMap[i]], 
     304                                                          idxLoop[indexMap[i]+1]); 
     305          ++idxDomain; 
     306        } 
     307        else 
     308        { 
     309          maskValue = maskValue && (*axisMasks[idxAxis])(idxLoop[indexMap[i]]); 
     310          ++idxAxis; 
     311        } 
     312      } 
     313 
     314      int maskIndex = idxLoop[0]; 
     315      int mulDim = 1; 
     316      for (int k = 1; k < dim; ++k) 
     317      { 
     318        mulDim *= eachDimSize[k-1]; 
     319        maskIndex += idxLoop[k]*mulDim; 
     320      } 
     321      *(gridMask.dataFirst()+maskIndex) = maskValue; 
     322 
     323      ++idxLoop[0]; 
     324      ++idx; 
     325    } 
     326 
     327   } 
     328 
    243329   ///-------------------------------------------------------------- 
    244330 
Note: See TracChangeset for help on using the changeset viewer.