Changeset 731 for XIOS/trunk/src/node


Ignore:
Timestamp:
10/13/15 15:14:23 (9 years ago)
Author:
rlacroix
Message:

Correctly estimate the needed buffer sizes.

The attributes were not considered which could lead to incorrect estimations.

Location:
XIOS/trunk/src/node
Files:
10 edited

Legend:

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

    r713 r731  
    116116   { 
    117117     return offsetWrittenIndexes_; 
     118   } 
     119 
     120   //---------------------------------------------------------------- 
     121 
     122   /*! 
     123    * Compute the minimum buffer size required to send the attributes to the server(s). 
     124    * 
     125    * \return A map associating the server rank with its minimum buffer size. 
     126    */ 
     127   std::map<int, StdSize> CAxis::getAttributesBufferSize() 
     128   { 
     129     CContextClient* client = CContext::getCurrent()->client; 
     130 
     131     std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(); 
     132 
     133     bool isNonDistributed = (n == n_glo); 
     134 
     135     if (client->isServerLeader()) 
     136     { 
     137       // size estimation for sendServerAttribut 
     138       size_t size = 6 * sizeof(size_t); 
     139       // size estimation for sendNonDistributedValue 
     140       if (isNonDistributed) 
     141         size = std::max(size, CArray<double,1>::size(n_glo) + (isCompressible_ ? CArray<int,1>::size(n_glo) : 0)); 
     142       size += CEventClient::headerSize + getId().size() + sizeof(size_t); 
     143 
     144       const std::list<int>& ranks = client->getRanksServerLeader(); 
     145       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
     146       { 
     147         if (size > attributesSizes[*itRank]) 
     148           attributesSizes[*itRank] = size; 
     149       } 
     150     } 
     151 
     152     if (!isNonDistributed) 
     153     { 
     154       // size estimation for sendDistributedValue 
     155       std::map<int, std::vector<size_t> >::const_iterator it, ite = indSrv_.end(); 
     156       for (it = indSrv_.begin(); it != ite; ++it) 
     157       { 
     158         size_t sizeIndexEvent = CArray<int,1>::size(it->second.size()); 
     159         if (isCompressible_) 
     160           sizeIndexEvent += CArray<int,1>::size(indWrittenSrv_[it->first].size()); 
     161 
     162         size_t sizeValEvent = CArray<double,1>::size(it->second.size()); 
     163         if (hasBounds_) 
     164           sizeValEvent += CArray<double,2>::size(it->second.size()); 
     165 
     166         size_t size = CEventClient::headerSize + getId().size() + sizeof(size_t) + std::max(sizeIndexEvent, sizeValEvent); 
     167         if (size > attributesSizes[it->first]) 
     168           attributesSizes[it->first] = size; 
     169       } 
     170     } 
     171 
     172     return attributesSizes; 
    118173   } 
    119174 
  • XIOS/trunk/src/node/axis.hpp

    r676 r731  
    7171         int getTotalNumberWrittenIndexes() const; 
    7272         int getOffsetWrittenIndexes() const; 
     73 
     74         std::map<int, StdSize> getAttributesBufferSize(); 
    7375 
    7476         /// Test /// 
  • XIOS/trunk/src/node/context.cpp

    r730 r731  
    266266   void CContext::setClientServerBuffer() 
    267267   { 
    268      size_t bufferSizeMin = CXios::minBufferSize; 
     268     size_t minBufferSize = CXios::minBufferSize; 
    269269#define DECLARE_NODE(Name_, name_)    \ 
    270      if (bufferSizeMin < sizeof(C##Name_##Definition)) bufferSizeMin = sizeof(C##Name_##Definition); 
     270     if (minBufferSize < sizeof(C##Name_##Definition)) minBufferSize = sizeof(C##Name_##Definition); 
    271271#define DECLARE_NODE_PAR(Name_, name_) 
    272272#include "node_type.conf" 
     
    274274#undef DECLARE_NODE_PAR 
    275275 
    276      std::map<int, StdSize> bufferSize = getDataSize(); 
    277      std::map<int, StdSize>::iterator it  = bufferSize.begin(), 
    278                                       ite = bufferSize.end(); 
    279      for (; it != ite; ++it) 
    280        if (it->second < bufferSizeMin) it->second = bufferSizeMin; 
     276     std::map<int, StdSize> bufferSize = getAttributesBufferSize(); 
     277     std::map<int, StdSize>::iterator it, ite = bufferSize.end(); 
     278     for (it = bufferSize.begin(); it != ite; ++it) 
     279       if (it->second < minBufferSize) it->second = minBufferSize; 
     280 
     281     std::map<int, StdSize> dataBufferSize = getDataBufferSize(); 
     282     ite = dataBufferSize.end(); 
     283     for (it = dataBufferSize.begin(); it != ite; ++it) 
     284       if (it->second > bufferSize[it->first]) bufferSize[it->first] = it->second; 
    281285 
    282286     if (client->isServerLeader()) 
     
    284288       const std::list<int>& ranks = client->getRanksServerLeader(); 
    285289       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
    286          if (!bufferSize.count(*itRank)) bufferSize[*itRank] = bufferSizeMin; 
     290         if (!bufferSize.count(*itRank)) bufferSize[*itRank] = minBufferSize; 
    287291     } 
    288292 
     
    791795   } 
    792796 
    793    std::map<int, StdSize>& CContext::getDataSize() 
     797   std::map<int, StdSize>& CContext::getAttributesBufferSize() 
     798   { 
     799     std::map<int, StdSize> attributesSize; 
     800 
     801     size_t numEnabledFiles = this->enabledFiles.size(); 
     802     for (size_t i = 0; i < numEnabledFiles; ++i) 
     803     { 
     804       CFile* file = this->enabledFiles[i]; 
     805 
     806       std::vector<CField*> enabledFields = file->getEnabledFields(); 
     807       size_t numEnabledFields = enabledFields.size(); 
     808       for (size_t j = 0; j < numEnabledFields; ++j) 
     809       { 
     810         const std::map<int, StdSize> mapSize = enabledFields[j]->getGridAttributesBufferSize(); 
     811         std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 
     812         for (; it != itE; ++it) 
     813         { 
     814           // If attributesSize[it->first] does not exist, it will be zero-initialized 
     815           // so we can use it safely without checking for its existance 
     816           if (attributesSize[it->first] < it->second) 
     817             attributesSize[it->first] = it->second; 
     818         } 
     819       } 
     820     } 
     821 
     822     return attributesSize; 
     823   } 
     824 
     825   std::map<int, StdSize>& CContext::getDataBufferSize() 
    794826   { 
    795827     CFile::mode_attr::t_enum mode = hasClient ? CFile::mode_attr::write : CFile::mode_attr::read; 
     
    810842         for (size_t j = 0; j < numEnabledFields; ++j) 
    811843         { 
    812            const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataSize(); 
     844           const std::map<int, StdSize> mapSize = enabledFields[j]->getGridDataBufferSize(); 
    813845           std::map<int, StdSize>::const_iterator it = mapSize.begin(), itE = mapSize.end(); 
    814846           for (; it != itE; ++it) 
  • XIOS/trunk/src/node/context.hpp

    r730 r731  
    120120         void postProcessing(); 
    121121 
    122          std::map<int, StdSize>& getDataSize(); 
     122         std::map<int, StdSize>& getAttributesBufferSize(); 
     123         std::map<int, StdSize>& getDataBufferSize(); 
    123124         void setClientServerBuffer(); 
    124125 
  • XIOS/trunk/src/node/domain.cpp

    r727 r731  
    102102   { 
    103103     return offsetWrittenIndexes_; 
     104   } 
     105 
     106   //---------------------------------------------------------------- 
     107 
     108   /*! 
     109    * Compute the minimum buffer size required to send the attributes to the server(s). 
     110    * 
     111    * \return A map associating the server rank with its minimum buffer size. 
     112    */ 
     113   std::map<int, StdSize> CDomain::getAttributesBufferSize() 
     114   { 
     115     CContextClient* client = CContext::getCurrent()->client; 
     116 
     117     std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(); 
     118 
     119     if (client->isServerLeader()) 
     120     { 
     121       // size estimation for sendServerAttribut 
     122       size_t size = 11 * sizeof(size_t); 
     123 
     124       const std::list<int>& ranks = client->getRanksServerLeader(); 
     125       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank) 
     126       { 
     127         if (size > attributesSizes[*itRank]) 
     128           attributesSizes[*itRank] = size; 
     129       } 
     130     } 
     131 
     132     std::map<int, std::vector<size_t> >::const_iterator it, ite = indSrv_.end(); 
     133     for (it = indSrv_.begin(); it != ite; ++it) 
     134     { 
     135       // size estimation for sendIndex (and sendArea which is always smaller or equal) 
     136       size_t sizeIndexEvent = 2 * sizeof(size_t) + 2 * CArray<int,1>::size(it->second.size()); 
     137       if (isCompressible_) 
     138         sizeIndexEvent += CArray<int,1>::size(indWrittenSrv_[it->first].size()); 
     139 
     140       // size estimation for sendLonLat 
     141       size_t sizeLonLatEvent = CArray<double,1>::size(it->second.size()); 
     142       if (hasBounds) 
     143         sizeLonLatEvent += CArray<double,2>::size(it->second.size()); 
     144 
     145       size_t size = CEventClient::headerSize + getId().size() + sizeof(size_t) + std::max(sizeIndexEvent, sizeLonLatEvent); 
     146       if (size > attributesSizes[it->first]) 
     147         attributesSizes[it->first] = size; 
     148     } 
     149 
     150     return attributesSizes; 
    104151   } 
    105152 
  • XIOS/trunk/src/node/domain.hpp

    r727 r731  
    9090         int getTotalNumberWrittenIndexes() const; 
    9191         int getOffsetWrittenIndexes() const; 
     92 
     93         std::map<int, StdSize> getAttributesBufferSize(); 
    9294 
    9395         bool isEmpty(void) const; 
  • XIOS/trunk/src/node/field.cpp

    r708 r731  
    527527   } 
    528528 
    529    std::map<int, StdSize> CField::getGridDataSize() 
    530    { 
    531      return grid->getConnectedServerDataSize(); 
     529   std::map<int, StdSize> CField::getGridAttributesBufferSize() 
     530   { 
     531     return grid->getAttributesBufferSize(); 
     532   } 
     533 
     534   std::map<int, StdSize> CField::getGridDataBufferSize() 
     535   { 
     536     return grid->getDataBufferSize(getId()); 
    532537   } 
    533538 
  • XIOS/trunk/src/node/field.hpp

    r707 r731  
    9393         void resetNStepMax(); 
    9494 
    95          std::map<int, StdSize> getGridDataSize(); 
     95         std::map<int, StdSize> getGridAttributesBufferSize(); 
     96         std::map<int, StdSize> getGridDataBufferSize(); 
    9697 
    9798       public: 
  • XIOS/trunk/src/node/grid.cpp

    r721 r731  
    8484   } 
    8585 
    86    std::map<int, StdSize> CGrid::getConnectedServerDataSize() 
    87    { 
    88      double secureFactor = 2.5 * sizeof(double) * CXios::bufferSizeFactor; 
    89      StdSize retVal = 1; 
    90      std::map<int, StdSize> ret; 
    91      std::map<int, size_t >::const_iterator itb = connectedDataSize_.begin(), it, itE = connectedDataSize_.end(); 
    92  
    93      if (isScalarGrid()) 
     86   /*! 
     87    * Compute the minimum buffer size required to send the attributes to the server(s). 
     88    * 
     89    * \return A map associating the server rank with its minimum buffer size. 
     90    */ 
     91   std::map<int, StdSize> CGrid::getAttributesBufferSize() 
     92   { 
     93     std::map<int, StdSize> attributesSizes = getMinimumBufferSizeForAttributes(); 
     94 
     95     // The grid indexes require a similar size as the actual data 
     96     std::map<int, StdSize> dataSizes = getDataBufferSize(); 
     97     std::map<int, StdSize>::iterator it, itE = dataSizes.end(); 
     98     for (it = dataSizes.begin(); it != itE; ++it) 
    9499     { 
    95        for (it = itb; it != itE; ++it) 
     100       it->second += 2 * sizeof(bool); 
     101       if (it->second > attributesSizes[it->first]) 
     102         attributesSizes[it->first] = it->second; 
     103     } 
     104 
     105     // Account for the axis attributes 
     106     std::vector<CAxis*> axisList = getAxis(); 
     107     for (size_t i = 0; i < axisList.size(); ++i) 
     108     { 
     109       std::map<int, StdSize> axisAttBuffSize = axisList[i]->getAttributesBufferSize(); 
     110       for (it = axisAttBuffSize.begin(), itE = axisAttBuffSize.end(); it != itE; ++it) 
    96111       { 
    97          retVal *= secureFactor; 
    98          ret.insert(std::make_pair(it->first, retVal)); 
    99        } 
    100        return ret; 
    101      } 
    102  
    103      for (it = itb; it != itE; ++it) 
    104      { 
    105         retVal = it->second; 
    106         retVal *= secureFactor; 
    107         ret.insert(std::make_pair<int,StdSize>(it->first, retVal)); 
    108      } 
    109  
    110      if (connectedDataSize_.empty()) 
    111      { 
    112        for (int i = 0; i < connectedServerRank_.size(); ++i) 
    113        { 
    114          retVal = 1; 
    115          retVal *= secureFactor; 
    116          ret.insert(std::make_pair<int,StdSize>(connectedServerRank_[i], retVal)); 
     112         if (it->second > attributesSizes[it->first]) 
     113           attributesSizes[it->first] = it->second; 
    117114       } 
    118115     } 
    119116 
    120      // In some cases in which domain is masked, we need to count for connected server for longitude and latitude 
    121      std::vector<CDomain*> domListP = this->getDomains(); 
    122      if (!domListP.empty()) 
     117     // Account for the domain attributes 
     118     std::vector<CDomain*> domList = getDomains(); 
     119     for (size_t i = 0; i < domList.size(); ++i) 
    123120     { 
    124        for (int i = 0; i < domListP.size(); ++i) 
     121       std::map<int, StdSize> domAttBuffSize = domList[i]->getAttributesBufferSize(); 
     122       for (it = domAttBuffSize.begin(), itE = domAttBuffSize.end(); it != itE; ++it) 
    125123       { 
    126          const std::map<int, vector<size_t> >& indexDomainServer = domListP[i]->getIndexServer(); 
    127          std::map<int, vector<size_t> >::const_iterator itDom = indexDomainServer.begin(), iteDom = indexDomainServer.end(); 
    128          for (; itDom != iteDom; ++itDom) 
    129          { 
    130            if (ret.end() == ret.find(itDom->first)) 
    131            { 
    132               retVal = (itDom->second).size(); 
    133               retVal *= secureFactor; 
    134               ret.insert(std::make_pair<int,StdSize>(itDom->first, retVal)); 
    135            } 
    136          } 
     124         if (it->second > attributesSizes[it->first]) 
     125           attributesSizes[it->first] = it->second; 
    137126       } 
    138127     } 
    139  
    140      return ret; 
     128      
     129     return attributesSizes; 
     130   } 
     131 
     132   /*! 
     133    * Compute the minimum buffer size required to send the data to the server(s). 
     134    * 
     135    * \param id the id used to tag the data 
     136    * \return A map associating the server rank with its minimum buffer size. 
     137    */ 
     138   std::map<int, StdSize> CGrid::getDataBufferSize(const std::string& id /*= ""*/) 
     139   { 
     140     std::map<int, StdSize> dataSizes; 
     141     const size_t extraSize = CEventClient::headerSize + (id.empty() ? getId() : id).size() + sizeof(size_t); 
     142 
     143     std::map<int, size_t>::const_iterator itb = connectedDataSize_.begin(), it, itE = connectedDataSize_.end(); 
     144     for (it = itb; it != itE; ++it) 
     145       dataSizes.insert(std::make_pair(it->first, extraSize + CArray<double,1>::size(it->second))); 
     146 
     147     return dataSizes; 
    141148   } 
    142149 
  • XIOS/trunk/src/node/grid.hpp

    r687 r731  
    158158         void computeDomConServer(); 
    159159         std::map<int, int> getDomConServerSide(); 
    160          std::map<int, StdSize> getConnectedServerDataSize(); 
     160         std::map<int, StdSize> getAttributesBufferSize(); 
     161         std::map<int, StdSize> getDataBufferSize(const std::string& id = ""); 
    161162         std::vector<StdString> getDomainList(); 
    162163         std::vector<StdString> getAxisList(); 
Note: See TracChangeset for help on using the changeset viewer.