Changeset 552 for XIOS


Ignore:
Timestamp:
02/11/15 16:23:07 (10 years ago)
Author:
mhnguyen
Message:

Doing some cleans and improving a little bit performance of creating local index on server

+) Add some comments, add some initialization
+) Change the way to calculate local index on server

Test
+) On Curie

Location:
XIOS/trunk/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/distribution.cpp

    r551 r552  
    1515CDistribution::~CDistribution() 
    1616{ 
     17  if (0 != globalIndex_) delete globalIndex_; 
    1718} 
    1819 
    19 const CArray<size_t,1>* CDistribution::getGlobalIndex() const 
    20 { 
    21   return globalIndex_; 
    22 } 
     20//const CArray<size_t,1>* CDistribution::getGlobalIndex() const 
     21//{ 
     22//  return globalIndex_; 
     23//} 
    2324 
    2425int CDistribution::getDims() const 
  • XIOS/trunk/src/distribution.hpp

    r551 r552  
    1414    /** Default destructor */ 
    1515    virtual ~CDistribution(); 
    16     const CArray<size_t,1>* getGlobalIndex() const; 
    1716 
    1817    int getDims() const; 
    1918    int getRank() const; 
    2019  protected: 
    21     virtual void createGlobalIndex() = 0; // Maybe change to pure ? = 0; 
     20    virtual void createGlobalIndex() = 0; 
    2221  protected: 
    2322    CArray<size_t,1>* globalIndex_; 
  • XIOS/trunk/src/node/distribution_client.cpp

    r551 r552  
    55CDistributionClient::CDistributionClient(int rank, int dims, CArray<size_t,1>* globalIndex) 
    66   : CDistribution(rank, dims, globalIndex), 
    7    axisDomainOrder_(), indexGlobalOnServer_(), isConnectedServerComputed_(false) 
     7   localDataIndex_(0), indexGlobalOnServer_(), localIndexSend2Server_(), axisDomainOrder_(), 
     8   nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 
     9   dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 
     10   gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), connectedClients_(), 
     11   isConnectedServerComputed_(false), indexDomainData_() 
    812{ 
    913} 
    1014 
    1115CDistributionClient::CDistributionClient(int rank, CGrid* grid) 
    12    : CDistribution(rank, 0, 0), isConnectedServerComputed_(false) 
     16   : CDistribution(rank, 0, 0), 
     17   localDataIndex_(0), indexGlobalOnServer_(), localIndexSend2Server_(), axisDomainOrder_(), 
     18   nLocal_(), nGlob_(), nBeginLocal_(), nBeginGlobal_(),nZoomBegin_(), nZoomEnd_(), 
     19   dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_(), 
     20   gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), connectedClients_(), 
     21   isConnectedServerComputed_(false), indexDomainData_() 
    1322{ 
    1423  readDistributionInfo(grid); 
     
    1827CDistributionClient::~CDistributionClient() 
    1928{ 
    20   if (0 != this->globalIndex_) delete globalIndex_; 
    2129  if (0 != localDataIndex_) delete localDataIndex_; 
    2230} 
     
    625633 
    626634  std::vector<CArray<size_t,1>::const_iterator> itBegin(nServer), itEnd(nServer), it(nServer); 
    627  
    628635  for (int i = 0; i < nServer; ++i) 
    629636  { 
    630     itBegin[i] = globalIndexServer[i]->begin(); 
     637    itBegin[i] = it[i] = globalIndexServer[i]->begin(); 
    631638    itEnd[i]   = globalIndexServer[i]->end(); 
    632639  } 
     
    637644    for (int j = 0; j < nServer; ++j) 
    638645    { 
    639       // Just temporarily, it's so so bad. 
    640 //      if (std::binary_search(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 
    641 //      if (itEnd[j] != std::find(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 
    642       it[j] = std::find(itBegin[j], itEnd[j], (*this->globalIndex_)(i)); 
    643       if (itEnd[j] != it[j]) 
    644       { 
    645 //        (indexGlobalOnServer_[j]).push_back((*this->globalIndex_)(i)); 
     646      // Just temporarily, it's bad. 
     647 
     648      if (std::binary_search(itBegin[j], itEnd[j], (*this->globalIndex_)(i))) 
     649      { 
    646650        // Just try to calculate local index server on client side 
    647         (indexGlobalOnServer_[j]).push_back(std::distance(itBegin[j], it[j])); 
     651        (indexGlobalOnServer_[j]).push_back((*this->globalIndex_)(i)); 
    648652        (localIndexSend2Server_[j]).push_back(i); 
    649653        continue; 
    650654      } 
    651655    } 
    652   } 
    653  
    654  
    655   for (int i = 0; i < nServer; ++i) 
    656   { 
    657     if (indexGlobalOnServer_[i].empty()) indexGlobalOnServer_.erase(i); 
    658     if (localIndexSend2Server_[i].empty()) localIndexSend2Server_.erase(i); 
    659656  } 
    660657 
  • XIOS/trunk/src/node/distribution_client.hpp

    r551 r552  
    6565    std::vector<CArray<size_t,1>* > computeServerBandDistribution(int nServer); 
    6666  private: 
    67     CArray<int,1>* localDataIndex_; //!< LocalData index on client 
    68     CArray<size_t,1>* globalIndex_; //!< Global index on client 
     67    //!< LocalData index on client 
     68    CArray<int,1>* localDataIndex_; 
    6969 
     70    //! Index of the local data which will be sent to the corresponding server(s) 
     71    std::map<int, std::vector<int> >  localIndexSend2Server_; 
     72 
     73    //! Global index of data on SERVER, which are calculated by client(s) 
    7074    std::map<int, std::vector<size_t> > indexGlobalOnServer_; 
    71     std::map<int, std::vector<int> >  localIndexSend2Server_; 
    7275  private: 
    7376    /*! Domains and axis are considered elements. 
     
    7578    int numElement_; 
    7679    CArray<bool,1> axisDomainOrder_; //!< 
    77  
    7880 
    7981    std::vector<int> nLocal_; //!< Local size of each dimension (ni, nj, etc, ...) 
  • XIOS/trunk/src/node/distribution_server.cpp

    r551 r552  
    22 
    33namespace xios { 
    4 CDistributionServer::CDistributionServer(int rank, int dims, int nServer, CArray<size_t,1>* globalIndex) 
    5   : CDistribution(rank, dims, globalIndex), nServer_(nServer), nGlobal_() 
     4CDistributionServer::CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex) 
     5  : CDistribution(rank, dims, globalIndex), nGlobal_(), nZoomSize_(), nZoomBegin_() 
    66{ 
    7  
    87} 
    98 
    10 CDistributionServer::CDistributionServer(int rank, int nServer, const std::vector<int>& nGlobal) 
    11   : CDistribution(rank, nGlobal.size()), nServer_(nServer) 
     9CDistributionServer::CDistributionServer(int rank, const std::vector<int>& nZoomBegin, 
     10                                         const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal) 
     11  : CDistribution(rank, nGlobal.size()), nGlobal_(nGlobal), nZoomSize_(nZoomSize), nZoomBegin_(nZoomBegin) 
    1212{ 
    13   readDistributionInfo(nGlobal); 
    1413  createGlobalIndex(); 
    1514} 
     
    1716CDistributionServer::~CDistributionServer() 
    1817{ 
    19   if (0 != this->globalIndex_) delete globalIndex_; 
    2018} 
    2119 
    22 void CDistributionServer::readDistributionInfo(const std::vector<int>& nGlobal) 
     20/*! 
     21  Create global index on server side 
     22  Like the similar function on client side, this function serves on creating global index 
     23for data written by the server. The global index is used to calculating local index of data 
     24written on each server 
     25*/ 
     26void CDistributionServer::createGlobalIndex() 
    2327{ 
    24   if (nGlobal.empty()) 
     28  size_t idx = 0, ssize = 1; 
     29  for (int i = 0; i < nZoomSize_.size(); ++i) ssize *= nZoomSize_[i]; 
     30 
     31  this->globalIndex_ = new CArray<size_t,1>(ssize); 
     32  std::vector<int> idxLoop(this->getDims(),0); 
     33  std::vector<int> currentIndex(this->getDims()); 
     34  int innerLoopSize = nZoomSize_[0]; 
     35 
     36  while (idx<ssize) 
    2537  { 
    26     //! TODO: This error must be replaced a call to function processing scalar value 
    27     ERROR("CDistributionServer::readDistributionInfo(const std::vector<int>& nGlobal)", 
    28        << "At least one dimension must be defined for this field."); 
     38    for (int i = 0; i < this->dims_-1; ++i) 
     39    { 
     40      if (idxLoop[i] == nZoomSize_[i]) 
     41      { 
     42        idxLoop[i] = 0; 
     43        ++idxLoop[i+1]; 
     44      } 
     45    } 
     46 
     47    for (int i = 1; i < this->dims_; ++i)  currentIndex[i] = idxLoop[i] + nZoomBegin_[i]; 
     48 
     49    size_t mulDim, globalIndex; 
     50    for (int i = 0; i < innerLoopSize; ++i) 
     51    { 
     52      mulDim = 1; 
     53      globalIndex = i + nZoomBegin_[0]; 
     54 
     55      for (int k = 1; k < this->dims_; ++k) 
     56      { 
     57        mulDim *= nGlobal_[k-1]; 
     58        globalIndex += (currentIndex[k])*mulDim; 
     59      } 
     60      (*this->globalIndex_)(idx) = globalIndex; 
     61      ++idx; 
     62    } 
     63    idxLoop[0] += innerLoopSize; 
    2964  } 
    30   nGlobal_ = nGlobal; 
    31   this->dims_ = nGlobal.size(); 
    3265} 
    3366 
    34 void CDistributionServer::createGlobalIndex() 
     67/*! 
     68  Compute local index for writing data on server 
     69  \param [in] globalIndex global index received from client 
     70  \return local index of written data 
     71*/ 
     72CArray<size_t,1> CDistributionServer::computeLocalIndex(const CArray<size_t,1>& globalIndex) 
    3573{ 
    36   size_t globalIndexSize = 1; 
    37   for (int i = 0; i < nGlobal_.size(); ++i) 
    38     globalIndexSize *= nGlobal_[i]; 
    39   size_t rangeSize    = globalIndexSize / nServer_; 
    40   size_t modulusSize = globalIndexSize % nServer_; 
     74  CArray<size_t,1>::const_iterator itBegin = (this->globalIndex_)->begin(), 
     75                                   itEnd   = (this->globalIndex_)->end(), it; 
    4176 
    42   if ((this->rank_ == (nServer_-1)) && (0 != modulusSize)) 
     77  int ssize = globalIndex.numElements(), idx = 0; 
     78  CArray<size_t,1> localIndex(ssize); 
     79  it = itBegin; 
     80  for (int i = 0; i < ssize; ++i) 
    4381  { 
    44     this->globalIndex_ = new CArray<size_t,1>(modulusSize); 
    45     globalIndexSize = modulusSize; 
    46   } 
    47   else 
    48   { 
    49     this->globalIndex_ = new CArray<size_t,1>(rangeSize); 
    50     globalIndexSize = rangeSize; 
     82    it = std::lower_bound(it, itEnd, globalIndex(i)); 
     83    if (itEnd != it) 
     84    { 
     85      localIndex(idx) = std::distance(itBegin, it); 
     86      ++idx; 
     87    } 
    5188  } 
    5289 
    53   size_t idxBegin = this->rank_ * rangeSize; 
    54   for (size_t i = 0; i < globalIndexSize;++i) 
    55     (*this->globalIndex_)(i) = i+idxBegin; 
     90  return localIndex; 
    5691} 
    5792 
     93/*! 
     94  Compute local index for writing data on server 
     95  \param [in] globalIndex Global index received from client 
     96*/ 
     97void CDistributionServer::computeLocalIndex(CArray<size_t,1>& globalIndex) 
     98{ 
     99  CArray<size_t,1>::const_iterator itBegin = (this->globalIndex_)->begin(), 
     100                                   itEnd   = (this->globalIndex_)->end(), it; 
     101 
     102  int ssize = globalIndex.numElements(), idx = 0; 
     103  CArray<size_t,1> localIndex(ssize); 
     104  it = itBegin; 
     105  for (int i = 0; i < ssize; ++i) 
     106  { 
     107    it = std::lower_bound(it, itEnd, globalIndex(i)); 
     108    if (itEnd != it) 
     109    { 
     110      localIndex(idx) = std::distance(itBegin, it); 
     111      ++idx; 
     112    } 
     113  } 
     114 
     115  globalIndex = localIndex; 
    58116} 
     117 
     118} // namespace xios 
  • XIOS/trunk/src/node/distribution_server.hpp

    r551 r552  
    55 
    66namespace xios { 
     7/*! 
     8\class CDistributionServer 
     9 The class, for now, plays a role of computing local index for writing data on server 
     10*/ 
    711class CDistributionServer : public CDistribution 
    812{ 
    913  public: 
    1014    /** Default constructor */ 
    11     CDistributionServer(int rank, int dims, int nServer, CArray<size_t,1>* globalIndex = 0); 
    12     CDistributionServer(int rank, int nServer, const std::vector<int>& nGlobal); 
     15    CDistributionServer(int rank, int dims, CArray<size_t,1>* globalIndex = 0); 
     16    CDistributionServer(int rank, const std::vector<int>& nZoomBegin, 
     17                        const std::vector<int>& nZoomSize, const std::vector<int>& nGlobal); 
    1318 
    1419    /** Default destructor */ 
    1520    virtual ~CDistributionServer(); 
    1621 
     22    CArray<size_t,1> computeLocalIndex(const CArray<size_t,1>& globalIndex); 
     23    void computeLocalIndex(CArray<size_t,1>& globalIndex); 
     24 
    1725  protected: 
    1826    virtual void createGlobalIndex(); 
    19  
    20     //! Read info 
    21     void readDistributionInfo(const std::vector<int>& nGlobal); 
    2227  private: 
    23     int nServer_; 
    2428    std::vector<int> nGlobal_; 
     29    std::vector<int> nZoomSize_; 
     30    std::vector<int> nZoomBegin_; 
    2531}; 
    2632 
    27 } 
     33} // namespace xios 
    2834#endif // __XIOS_DISTRIBUTION_SERVER_HPP__ 
  • XIOS/trunk/src/node/grid.cpp

    r551 r552  
    1111#include "context.hpp" 
    1212#include "context_client.hpp" 
     13#include "context_server.hpp" 
    1314#include "array_new.hpp" 
    1415 
     
    2223      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    2324      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
     25      , serverDistribution_(0) 
    2426   { 
    2527     setVirtualDomainGroup(); 
     
    3234      , storeIndex(1), out_i_index(1), out_j_index(1), out_l_index(1), isDomConServerComputed_(false) 
    3335      , vDomainGroup_(), vAxisGroup_(), axisList_(), isAxisListSet(false), isDomListSet(false), clientDistribution_(0), isIndexSent(false) 
     36      , serverDistribution_(0) 
    3437   { 
    3538     setVirtualDomainGroup(); 
     
    5558 
    5659    if (0 != clientDistribution_) delete clientDistribution_; 
     60    if (0 != serverDistribution_) delete serverDistribution_; 
    5761 
    5862   } 
     
    807811  void CGrid::recvIndex(int rank, CBufferIn& buffer) 
    808812  { 
     813     if (0 == serverDistribution_) 
     814     { 
     815       CContext* context = CContext::getCurrent() ; 
     816       CContextServer* server=context->server ; 
     817       int idx = 0, numElement = axisDomainOrder.numElements(); 
     818       int ssize = numElement; 
     819       std::vector<int> indexMap(numElement); 
     820       for (int i = 0; i < numElement; ++i) 
     821       { 
     822         indexMap[i] = idx; 
     823         if (true == axisDomainOrder(i)) 
     824        { 
     825          ++ssize; 
     826          idx += 2; 
     827        } 
     828       } 
     829 
     830       int axisId = 0, domainId = 0; 
     831       std::vector<CDomain*> domainList = getDomains(); 
     832       std::vector<CAxis*> axisList = getAxis(); 
     833       std::vector<int> nZoomBegin(ssize), nZoomSize(ssize), nGlob(ssize); 
     834       for (int i = 0; i < numElement; ++i) 
     835       { 
     836         if (axisDomainOrder(i)) 
     837         { 
     838            nZoomBegin[indexMap[i]]   = domainList[domainId]->zoom_ibegin_srv; 
     839            nZoomSize[indexMap[i]]    = domainList[domainId]->zoom_ni_srv; 
     840            nGlob[indexMap[i]]    = domainList[domainId]->ni_glo; 
     841 
     842            nZoomBegin[indexMap[i]+1] = domainList[domainId]->zoom_jbegin_srv; 
     843            nZoomSize[indexMap[i]+1]  = domainList[domainId]->zoom_nj_srv; 
     844            nGlob[indexMap[i]+1]    = domainList[domainId]->nj_glo; 
     845            ++domainId; 
     846         } 
     847         else 
     848         { 
     849            nZoomBegin[indexMap[i]] = axisList[axisId]->zoom_begin; 
     850            nZoomSize[indexMap[i]]  = axisList[axisId]->zoom_size; 
     851            nGlob[indexMap[i]]      = axisList[axisId]->size; 
     852            ++axisId; 
     853         } 
     854       } 
     855       serverDistribution_ = new CDistributionServer(server->intraCommRank, nZoomBegin, nZoomSize, nGlob); 
     856     } 
     857 
    809858     CArray<size_t,1> outIndex; 
    810859     buffer>>outIndex; 
     860     serverDistribution_->computeLocalIndex(outIndex); 
    811861     outIndexFromClient.insert(std::pair<int, CArray<size_t,1>* >(rank, new CArray<size_t,1>(outIndex))); 
    812862 
  • XIOS/trunk/src/node/grid.hpp

    r551 r552  
    1212#include "attribute_array.hpp" 
    1313#include "distribution_client.hpp" 
     14#include "distribution_server.hpp" 
    1415 
    1516namespace xios { 
     
    2324   class CGrid; 
    2425   class CDistributionClient; 
     26   class CDistributionServer; 
    2527 
    2628   ///-------------------------------------------------------------- 
     
    217219        bool isAxisListSet, isDomListSet; 
    218220        CDistributionClient* clientDistribution_; 
     221        CDistributionServer* serverDistribution_; 
    219222   }; // class CGrid 
    220223 
Note: See TracChangeset for help on using the changeset viewer.