Changeset 843


Ignore:
Timestamp:
04/26/16 16:04:04 (8 years ago)
Author:
mhnguyen
Message:

Several improvements

+) Replace some time-consuming operations by simpler ones

Test
+) On Curie
+) All tests pass

Location:
XIOS/trunk/src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/client_client_dht_template.hpp

    r839 r843  
    4444 
    4545    const Index2InfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; } 
     46 
     47    int getNbClient() { return nbClient_; } 
    4648 
    4749    /** Default destructor */ 
     
    101103    //! Flag to specify whether data is distributed or not 
    102104    bool isDataDistributed_; 
     105 
     106    //! Number of client 
     107    int nbClient_; 
    103108}; 
    104109 
  • XIOS/trunk/src/client_client_dht_template_impl.hpp

    r839 r843  
    2424CClientClientDHTTemplate<T,H>::CClientClientDHTTemplate(const boost::unordered_map<size_t,T>& indexInfoMap, 
    2525                                                        const MPI_Comm& clientIntraComm) 
    26   : H(clientIntraComm), index2InfoMapping_(), indexToInfoMappingLevel_() 
    27 { 
     26  : H(clientIntraComm), index2InfoMapping_(), indexToInfoMappingLevel_(), nbClient_(0) 
     27{ 
     28  MPI_Comm_size(clientIntraComm, &nbClient_); 
    2829  this->computeMPICommLevel(); 
    2930  int nbLvl = this->getNbLevel(); 
     
    8889  } 
    8990 
    90   std::map<int, size_t* > client2ClientIndex; 
     91  boost::unordered_map<int, size_t* > client2ClientIndex; 
    9192  for (int idx = 0; idx < nbClient; ++idx) 
    9293  { 
     
    140141  } 
    141142 
    142   std::map<int, size_t* >::iterator itbIndex = client2ClientIndex.begin(), itIndex, 
    143                                     iteIndex = client2ClientIndex.end(); 
     143  boost::unordered_map<int, size_t* >::iterator itbIndex = client2ClientIndex.begin(), itIndex, 
     144                                                iteIndex = client2ClientIndex.end(); 
    144145  for (itIndex = itbIndex; itIndex != iteIndex; ++itIndex) 
    145146    sendIndexToClients(itIndex->first, (itIndex->second), sendNbIndexBuff[itIndex->first-groupRankBegin], commLevel, request); 
     
    213214  } 
    214215 
    215   std::map<int,unsigned char*> client2ClientInfoOnReturn; 
    216   std::map<int,size_t*> client2ClientIndexOnReturn; 
     216  boost::unordered_map<int,unsigned char*> client2ClientInfoOnReturn; 
     217  boost::unordered_map<int,size_t*> client2ClientIndexOnReturn; 
    217218  currentIndex = 0; 
    218219  for (int idx = 0; idx < nbRecvClient; ++idx) 
     
    249250 
    250251  boost::unordered_map<size_t,InfoType> indexToInfoMapping; 
     252  indexToInfoMapping.rehash(std::ceil(recvNbIndexCountOnReturn/indexToInfoMapping.max_load_factor())); 
    251253  int infoIndex = 0; 
    252254  for (int idx = 0; idx < recvNbIndexCountOnReturn; ++idx) 
     
    255257  } 
    256258 
    257   indexToInfoMappingLevel_ = (indexToInfoMapping); 
     259  indexToInfoMappingLevel_.swap(indexToInfoMapping); //indexToInfoMappingLevel_ = (indexToInfoMapping); 
    258260  if (0 != recvNbIndexCount) delete [] recvIndexBuff; 
    259   for (std::map<int,size_t*>::const_iterator it = client2ClientIndex.begin(); 
    260                                             it != client2ClientIndex.end(); ++it) 
     261  for (boost::unordered_map<int,size_t*>::const_iterator it = client2ClientIndex.begin(); 
     262                                                        it != client2ClientIndex.end(); ++it) 
    261263      delete [] it->second; 
    262264  delete tmpGlobalIndex; 
     
    268270  } 
    269271 
    270   for (std::map<int,unsigned char*>::const_iterator it = client2ClientInfoOnReturn.begin(); 
    271                                                     it != client2ClientInfoOnReturn.end(); ++it) 
     272  for (boost::unordered_map<int,unsigned char*>::const_iterator it = client2ClientInfoOnReturn.begin(); 
     273                                                               it != client2ClientInfoOnReturn.end(); ++it) 
    272274      delete [] it->second; 
    273275 
    274   for (std::map<int,size_t*>::const_iterator it = client2ClientIndexOnReturn.begin(); 
     276  for (boost::unordered_map<int,size_t*>::const_iterator it = client2ClientIndexOnReturn.begin(); 
    275277                                            it != client2ClientIndexOnReturn.end(); ++it) 
    276278      delete [] it->second; 
     
    342344  } 
    343345 
    344   std::map<int, size_t*> client2ClientIndex; 
    345   std::map<int, unsigned char*> client2ClientInfo; 
     346  boost::unordered_map<int, size_t*> client2ClientIndex; 
     347  boost::unordered_map<int, unsigned char*> client2ClientInfo; 
    346348  for (int idx = 0; idx < nbClient; ++idx) 
    347349  { 
     
    407409  } 
    408410 
    409   std::map<int, size_t* >::iterator itbIndex = client2ClientIndex.begin(), itIndex, 
    410                                     iteIndex = client2ClientIndex.end(); 
     411  boost::unordered_map<int, size_t* >::iterator itbIndex = client2ClientIndex.begin(), itIndex, 
     412                                                iteIndex = client2ClientIndex.end(); 
    411413  for (itIndex = itbIndex; itIndex != iteIndex; ++itIndex) 
    412414    sendIndexToClients(itIndex->first, itIndex->second, sendNbIndexBuff[itIndex->first-groupRankBegin], commLevel, request); 
    413   std::map<int, unsigned char*>::iterator itbInfo = client2ClientInfo.begin(), itInfo, 
    414                                           iteInfo = client2ClientInfo.end(); 
     415  boost::unordered_map<int, unsigned char*>::iterator itbInfo = client2ClientInfo.begin(), itInfo, 
     416                                                      iteInfo = client2ClientInfo.end(); 
    415417  for (itInfo = itbInfo; itInfo != iteInfo; ++itInfo) 
    416418    sendInfoToClients(itInfo->first, itInfo->second, sendNbInfo[itInfo->first-groupRankBegin], commLevel, request); 
     
    420422 
    421423  boost::unordered_map<size_t,InfoType> indexToInfoMapping; 
     424  indexToInfoMapping.rehash(std::ceil(currentIndex/indexToInfoMapping.max_load_factor())); 
    422425  currentIndex = 0; 
    423426  InfoType infoValue; 
     
    440443    delete [] recvInfoBuff; 
    441444  } 
    442   for (std::map<int,unsigned char*>::const_iterator it = client2ClientInfo.begin(); 
    443                                                     it != client2ClientInfo.end(); ++it) 
     445  for (boost::unordered_map<int,unsigned char*>::const_iterator it = client2ClientInfo.begin(); 
     446                                                               it != client2ClientInfo.end(); ++it) 
    444447      delete [] it->second; 
    445448 
    446   for (std::map<int,size_t*>::const_iterator it = client2ClientIndex.begin(); 
    447                                             it != client2ClientIndex.end(); ++it) 
     449  for (boost::unordered_map<int,size_t*>::const_iterator it = client2ClientIndex.begin(); 
     450                                                        it != client2ClientIndex.end(); ++it) 
    448451      delete [] it->second; 
    449452 
     
    455458  } 
    456459  else 
    457     index2InfoMapping_ = (indexToInfoMapping); 
     460    index2InfoMapping_.swap(indexToInfoMapping); //index2InfoMapping_ = (indexToInfoMapping); 
    458461} 
    459462 
  • XIOS/trunk/src/client_server_mapping.cpp

    r832 r843  
    1212 
    1313CClientServerMapping::CClientServerMapping() 
    14   : indexGlobalOnServer_(), connectedClients_() //, localIndexSend2Server_() 
     14  : indexGlobalOnServer_() 
    1515{ 
    1616} 
  • XIOS/trunk/src/client_server_mapping.hpp

    r831 r843  
    4545    //! Global index of data on SERVER, which are calculated by client(s) 
    4646    GlobalIndexMap indexGlobalOnServer_; 
    47  
    48     //!< Number of clients connected to a server 
    49     std::map<int, int> connectedClients_; 
    5047}; 
    5148 
  • XIOS/trunk/src/client_server_mapping_distributed.cpp

    r835 r843  
    3838  ccDHT_->computeIndexInfoMapping(globalIndexOnClient); 
    3939  const boost::unordered_map<size_t,int>& infoIndexMap = (ccDHT_->getInfoIndexMap()); 
    40   boost::unordered_map<size_t,int>::const_iterator it = infoIndexMap.begin(), ite = infoIndexMap.end(); 
    41   for (; it != ite; ++it) 
     40  boost::unordered_map<size_t,int>::const_iterator itb = infoIndexMap.begin(), ite = infoIndexMap.end(), it; 
     41  std::vector<size_t> nbInfoIndex(ccDHT_->getNbClient(),0); 
     42 
     43  for (it = itb; it != ite; ++it) 
    4244  { 
    43     indexGlobalOnServer_[it->second].push_back(it->first); 
     45    ++nbInfoIndex[it->second]; 
     46  } 
     47 
     48  for (int idx = 0; idx < nbInfoIndex.size(); ++idx) 
     49  { 
     50    if (0 != nbInfoIndex[idx]) 
     51    { 
     52      indexGlobalOnServer_[idx].resize(nbInfoIndex[idx]); 
     53      nbInfoIndex[idx] = 0; 
     54    } 
     55  } 
     56 
     57  for (it = itb; it != ite; ++it) 
     58  { 
     59    indexGlobalOnServer_[it->second][nbInfoIndex[it->second]] = (it->first); 
     60    ++nbInfoIndex[it->second]; 
    4461  } 
    4562} 
  • XIOS/trunk/src/distribution_client.cpp

    r834 r843  
    1717   , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_() 
    1818   , gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 
    19    , isDataDistributed_(true), axisNum_(0), domainNum_(0), nIndexDomain_(), nIndexAxis_() 
     19   , isDataDistributed_(true), axisNum_(0), domainNum_(0) 
    2020   , localDataIndex_(), localMaskIndex_() 
    2121   , globalLocalDataSendToServerMap_() 
     
    3030   , dataNIndex_(), dataDims_(), dataBegin_(), dataIndex_(), domainMasks_(), axisMasks_() 
    3131   , gridMask_(), localDomainIndex_(), localAxisIndex_(), indexMap_(), indexDomainData_(), indexAxisData_() 
    32    , isDataDistributed_(true), axisNum_(0), domainNum_(0), nIndexDomain_(), nIndexAxis_() 
     32   , isDataDistributed_(true), axisNum_(0), domainNum_(0) 
    3333   , localDataIndex_(), localMaskIndex_() 
    3434   , globalLocalDataSendToServerMap_() 
     
    3737  readDistributionInfo(grid); 
    3838  createGlobalIndex(); 
    39 //  createGlobalIndexSendToServer(); 
    4039} 
    4140 
     
    8180} 
    8281 
    83 void CDistributionClient::readDomainIndex(const std::vector<CDomain*>& domList) 
    84 { 
    85   int domainSize = domList.size(); 
    86   nIndexDomain_.resize(domainSize); 
    87  
    88   for (int k = 0; k < domainSize; ++k) 
    89   { 
    90     nIndexDomain_[k].resize(2); 
    91     int ni = domList[k]->ni; 
    92     int nj = domList[k]->nj; 
    93     nIndexDomain_[k][0].resize(ni*nj); 
    94     nIndexDomain_[k][1].resize(ni*nj); 
    95     nIndexDomain_[k][0] = domList[k]->i_index; 
    96     nIndexDomain_[k][1] = domList[k]->j_index; 
    97   } 
    98 } 
    99  
    100 void CDistributionClient::readAxisIndex(const std::vector<CAxis*>& axisList) 
    101 { 
    102   int axisSize = axisList.size(); 
    103   nIndexAxis_.resize(axisSize); 
    104  
    105   for (int k = 0; k < axisSize; ++k) 
    106   { 
    107     int n = axisList[k]->n; 
    108     nIndexAxis_[k].resize(n); 
    109     for (int i = 0; i < n; ++i) 
    110       nIndexAxis_[k](i) = i; 
    111   } 
    112 } 
    113  
    11482/*! 
    11583  Read information from domain(s) and axis to generate distribution. 
     
    204172 
    205173      dataBegin_.at(indexMap_[idx]+1) = domList[domIndex]->data_jbegin.getValue(); //(2 == domList[domIndex]->data_dim) ? domList[domIndex]->data_jbegin.getValue() : -1; 
    206 //      dataIndex_.at(indexMap_[idx]+1).resize(domList[domIndex]->data_j_index.numElements()); 
    207174      dataIndex_.at(indexMap_[idx]+1) = &(domList[domIndex]->data_j_index); 
    208 //      infoIndex_.at(indexMap_[idx]+1).resize(domList[domIndex]->j_index.numElements()); 
    209175      infoIndex_.at(indexMap_[idx]+1) = &(domList[domIndex]->j_index); 
    210176 
     
    218184 
    219185      dataBegin_.at(indexMap_[idx]) = domList[domIndex]->data_ibegin.getValue(); 
    220 //      dataIndex_.at(indexMap_[idx]).resize(domList[domIndex]->data_i_index.numElements()); 
    221186      dataIndex_.at(indexMap_[idx]) = &(domList[domIndex]->data_i_index); 
    222 //      infoIndex_.at(indexMap_[idx]).resize(domList[domIndex]->i_index.numElements()); 
    223187      infoIndex_.at(indexMap_[idx]) = &(domList[domIndex]->i_index); 
    224188 
     
    240204 
    241205      dataBegin_.at(indexMap_[idx]) = axisList[axisIndex]->data_begin.getValue(); 
    242 //      dataIndex_.at(indexMap_[idx]).resize(axisList[axisIndex]->data_index.numElements()); 
    243206      dataIndex_.at(indexMap_[idx]) = &(axisList[axisIndex]->data_index); 
    244 //      infoIndex_.at(indexMap_[idx]).resize(axisList[axisIndex]->index.numElements()); 
    245207      infoIndex_.at(indexMap_[idx]) = &(axisList[axisIndex]->index); 
    246208      dataNIndex_.at(idx) = axisList[axisIndex]->data_index.numElements(); 
     
    253215    ++idx; 
    254216  } 
    255   readDomainIndex(domList); 
    256   readAxisIndex(axisList); 
    257217} 
    258218 
     
    511471  localDataIndex_.resize(indexLocalDataOnClientCount); 
    512472  localMaskIndex_.resize(indexSend2ServerCount); 
     473  globalLocalDataSendToServerMap_.rehash(std::ceil(indexSend2ServerCount/globalLocalDataSendToServerMap_.max_load_factor())); //globalLocalDataSendToServerMap_.reserve(indexSend2ServerCount); 
    513474 
    514475  // We need to loop with data index 
  • XIOS/trunk/src/distribution_client.hpp

    r834 r843  
    6262                              const std::vector<CAxis*>& axisList, 
    6363                              const CArray<bool,1>& axisDomainOrder); 
    64     void readDomainIndex(const std::vector<CDomain*>& domList); 
    65     void readAxisIndex(const std::vector<CAxis*>& axisList); 
    6664  private: 
    6765    //! Create local index of a domain 
     
    9290    std::vector<int> nZoomBegin_; //!< Begin index of zoom of each dimension 
    9391    std::vector<int> nZoomEnd_; //!< End index of zoom of each dimension 
    94     std::vector<std::vector<CArray<int,1> > > nIndexDomain_; //!< Local index of each domain dimension (e.x: i_index, j_index) 
    95     std::vector<CArray<int,1> > nIndexAxis_; 
    9692 
    9793    // Data_n_index of domain or axis (For now, axis uses its size as data_n_index 
  • XIOS/trunk/src/server_distribution_description.cpp

    r815 r843  
    117117           << "Index begin is larger than index end"); 
    118118 
     119  globalIndex_.rehash(std::ceil((indexEnd-indexBegin+1)/globalIndex_.max_load_factor())); 
     120 
    119121  int dim = nGlobal_.size(); 
    120122  std::vector<int> currentIndex(dim); 
     
    153155        } 
    154156        if ((indexBegin <= globalIndex) && (globalIndex <= indexEnd)) 
    155           globalIndex_.insert(std::make_pair<size_t,int>(globalIndex, idxServer)); 
     157          globalIndex_[globalIndex] = idxServer; 
    156158        ++idx; 
    157159      } 
  • XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp

    r841 r843  
    8383      { 
    8484        size_t srcGridSize = globalIndexSrcGrid[idx].size(); 
    85 //        globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize); 
    86         globaIndexWeightFromDestToSource[(it->first)].resize(srcGridSize); 
     85//        globaIndexWeightFromDestToSource[(it->first)].resize(srcGridSize); 
     86        DestinationGlobalIndex& tmp = globaIndexWeightFromDestToSource[(it->first)]; 
     87        tmp.resize(srcGridSize); 
    8788        for (int i = 0; i < srcGridSize; ++i) 
    8889        { 
    89           globaIndexWeightFromDestToSource[(it->first)][i] = (make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]))); 
     90          tmp[i].first = it->second; 
     91          tmp[i].second = make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]); 
     92//          globaIndexWeightFromDestToSource[(it->first)][i] = (make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]))); 
    9093        } 
    9194      } 
  • XIOS/trunk/src/transformation/generic_algorithm_transformation.hpp

    r833 r843  
    2121class CGenericAlgorithmTransformation 
    2222{ 
     23protected: 
     24  typedef std::vector<std::pair<int, std::pair<size_t,double> > > DestinationGlobalIndex; 
    2325public: 
    2426  // Stupid global index map, it must be replaced by tuple 
    2527  // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights 
    26   typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 
     28  typedef boost::unordered_map<size_t, DestinationGlobalIndex> DestinationIndexMap; 
     29 
    2730protected: 
    2831  typedef boost::unordered_map<size_t,int> GlobalLocalMap; 
  • XIOS/trunk/src/transformation/transformation_mapping.cpp

    r842 r843  
    3131 
    3232  // Mapping of global index and pair containing rank and local index 
    33   CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfServer; 
     33  CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfClientSrc; 
     34  globalIndexOfClientSrc.rehash(std::ceil(globalLocalIndexGridSrc.size()/globalIndexOfClientSrc.max_load_factor())); 
     35 
    3436  PairIntInt pairIntInt; 
    3537  for (; itIndex != iteIndex; ++itIndex) 
     
    3739    pairIntInt.first  = clientRank; 
    3840    pairIntInt.second = itIndex->second; 
    39     globalIndexOfServer[itIndex->first] = pairIntInt; 
    40   } 
    41  
    42   gridIndexClientClientMapping_ = new CClientClientDHTPairIntInt(globalIndexOfServer, 
     41    globalIndexOfClientSrc[itIndex->first] = pairIntInt; 
     42  } 
     43 
     44  gridIndexClientClientMapping_ = new CClientClientDHTPairIntInt(globalIndexOfClientSrc, 
    4345                                                                 client->intraComm); 
    4446} 
Note: See TracChangeset for help on using the changeset viewer.