Ignore:
Timestamp:
03/23/16 16:11:01 (8 years ago)
Author:
mhnguyen
Message:

Refactoring transformation code

+) On exchanging information during transformation, not only global index are sent but also local index
+) Correct a bug in distributed hash table (dht)
+) Add new type for dht
+) Clean up some redundant codes

Test
+) On Curie
+) Every test passes
+) Code runs faster in some cases (up to 30%)

File:
1 edited

Legend:

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

    r721 r829  
    4949  for (size_t idx = 0; idx < size; ++idx) 
    5050  { 
    51     int serverIdx = indexToInfoMappingLevel_[indices(idx)]; 
    52     indexGlobalOnServer_[serverIdx].push_back(indices(idx)); 
     51    T& info = indexToInfoMappingLevel_[indices(idx)]; 
     52//    infoIndexMapping_[info].push_back(indices(idx)); 
     53    infoIndexMapping_[indices(idx)] = info; 
    5354  } 
    5455} 
     
    125126 
    126127  // Buffer to receive respond from other clients, it can be allocated or not depending whether it demands other clients 
    127   InfoType* recvBuffInfo = 0; 
     128//  InfoType* recvBuffInfo = 0; 
     129  unsigned char* recvBuffInfo = 0; 
    128130  int nbIndexReceivedFromOthers = nbIndexToSend; 
    129131  if (0 != nbIndexReceivedFromOthers) 
    130     recvBuffInfo = new InfoType[nbIndexReceivedFromOthers]; 
     132    recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*infoTypeSize]; 
    131133 
    132134  std::map<int, MPI_Request>::iterator itRequest; 
     
    212214 
    213215  // Mapping client rank and the begining position of receiving buffer for message of server index from this client 
    214   std::map<int, InfoType*> infoBuffBegin; 
     216  std::map<int, unsigned char*> infoBuffBegin; 
    215217 
    216218  while ((!sendInfoRequest.empty()) || (nbSendBuffInfoReceived < nbIndexReceivedFromOthers)) 
     
    233235      if (true == flagInfo) 
    234236      { 
    235         MPI_Get_count(&statusInfo, MPI_INT, &count); 
     237        MPI_Get_count(&statusInfo, MPI_CHAR, &count); 
     238        int actualCountInfo = count/infoTypeSize; 
    236239        int clientSourceRank = statusInfo.MPI_SOURCE; 
    237         InfoType* beginBuff = infoBuffBegin[clientSourceRank]; 
     240        unsigned char* beginBuff = infoBuffBegin[clientSourceRank]; 
    238241        std::vector<size_t>& indexTmp = client2ClientIndex[clientSourceRank]; 
    239         for (int i = 0; i < count; ++i) 
     242        TypeToBytes<InfoType> u; 
     243        for (int i = 0; i < actualCountInfo; ++i) 
    240244        { 
    241           indexToInfoMapping[indexTmp[i]] = *(beginBuff+i); 
     245          unsigned char* tmpBeginBuff = beginBuff+i*infoTypeSize; 
     246          for (size_t idx = 0; idx < infoTypeSize; ++idx) u.bytes[idx] = *(tmpBeginBuff+idx); 
     247          indexToInfoMapping[indexTmp[i]] = u.value; 
    242248        } 
    243         nbSendBuffInfoReceived += count; 
     249        nbSendBuffInfoReceived += actualCountInfo; 
    244250        repondAlreadyReceived.push_back(clientSourceRank); 
    245251      } 
     
    251257  } 
    252258 
    253   indexToInfoMappingLevel_ = indexToInfoMapping; 
     259  indexToInfoMappingLevel_.swap(indexToInfoMapping); 
    254260  if (0 != maxNbIndexDemandedFromOthers) delete [] recvBuffIndex; 
    255261  if (0 != nbIndexReceivedFromOthers) delete [] recvBuffInfo; 
     
    289295template<typename T, typename H> 
    290296void CClientClientDHTTemplate<T,H>::computeDistributedIndex(const boost::unordered_map<size_t,T>& indexInfoMap, 
    291                                                           const MPI_Comm& commLevel, 
    292                                                           int level) 
     297                                                            const MPI_Comm& commLevel, 
     298                                                            int level) 
    293299{ 
    294300  int nbClient, clientRank; 
     
    340346  int recvNbIndexCount = recvNbIndexBuff[clientRank]; 
    341347  unsigned long* recvIndexBuff = new unsigned long[recvNbIndexCount]; 
    342   InfoType* recvInfoBuff = new InfoType[recvNbIndexCount]; 
     348  unsigned char* recvInfoBuff = new unsigned char[recvNbIndexCount*infoTypeSize]; 
    343349 
    344350  // If a client holds information about index and the corresponding which don't belong to it, 
     
    374380 
    375381  // Mapping client rank and the begining position of receiving buffer for message of server index from this client 
    376   std::map<int, int*> infoBuffBegin; 
     382  std::map<int, unsigned char*> infoBuffBegin; 
    377383 
    378384  boost::unordered_map<size_t,InfoType> indexToInfoMapping; 
     
    418424      { 
    419425        int count = it->second; 
     426        TypeToBytes<InfoType> u; 
    420427        for (int i = 0; i < count; ++i) 
    421            indexToInfoMapping.insert(std::make_pair<size_t,InfoType>(*(indexBuffBegin[rank]+i),*(infoBuffBegin[rank]+i))); 
     428        { 
     429          unsigned char* tmpBeginBuff = infoBuffBegin[rank]+i*infoTypeSize; 
     430          for (size_t idx = 0; idx < infoTypeSize; ++idx) u.bytes[idx] = *(tmpBeginBuff+idx); 
     431          indexToInfoMapping.insert(std::make_pair<size_t,InfoType>(*(indexBuffBegin[rank]+i),u.value)); 
     432        } 
     433 
    422434        processedList.push_back(rank); 
    423435        --recvNbClient; 
     
    466478template<typename T, typename H> 
    467479void CClientClientDHTTemplate<T,H>::probeIndexMessageFromClients(unsigned long* recvIndexBuff, 
    468                                                     const int recvNbIndexCount, 
    469                                                     int& countIndex, 
    470                                                     std::map<int, unsigned long*>& indexBuffBegin, 
    471                                                     std::map<int, MPI_Request>& requestRecvIndex, 
    472                                                     const MPI_Comm& intraComm) 
     480                                                                 const int recvNbIndexCount, 
     481                                                                 int& countIndex, 
     482                                                                 std::map<int, unsigned long*>& indexBuffBegin, 
     483                                                                 std::map<int, MPI_Request>& requestRecvIndex, 
     484                                                                 const MPI_Comm& intraComm) 
    473485{ 
    474486  MPI_Status statusIndexGlobal; 
     
    500512*/ 
    501513template<typename T, typename H> 
    502 void CClientClientDHTTemplate<T,H>::probeInfoMessageFromClients(T* recvInfoBuff, 
    503                                                    const int recvNbIndexCount, 
    504                                                    int& countInfo, 
    505                                                    std::map<int, T*>& infoBuffBegin, 
    506                                                    std::map<int, MPI_Request>& requestRecvInfo, 
    507                                                    const MPI_Comm& intraComm) 
     514void CClientClientDHTTemplate<T,H>::probeInfoMessageFromClients(unsigned char* recvInfoBuff, 
     515                                                                const int recvNbIndexCount, 
     516                                                                int& countInfo, 
     517                                                                std::map<int, unsigned char*>& infoBuffBegin, 
     518                                                                std::map<int, MPI_Request>& requestRecvInfo, 
     519                                                                const MPI_Comm& intraComm) 
    508520{ 
    509521  MPI_Status statusInfo; 
     
    515527  { 
    516528    MPI_Get_count(&statusInfo, MPI_CHAR, &count); 
    517     infoBuffBegin.insert(std::make_pair<int, T*>(statusInfo.MPI_SOURCE, recvInfoBuff+countInfo)); 
    518     MPI_Irecv(recvInfoBuff+countInfo, count, MPI_CHAR, 
     529    unsigned char* beginInfoBuff = recvInfoBuff+countInfo*infoTypeSize; 
     530    infoBuffBegin.insert(std::make_pair<int, unsigned char*>(statusInfo.MPI_SOURCE, beginInfoBuff)); 
     531    MPI_Irecv(beginInfoBuff, count, MPI_CHAR, 
    519532              statusInfo.MPI_SOURCE, MPI_DHT_INFO, intraComm, 
    520533              &requestRecvInfo[statusInfo.MPI_SOURCE]); 
     
    533546template<typename T, typename H> 
    534547void CClientClientDHTTemplate<T,H>::sendIndexToClients(int clientDestRank, std::vector<size_t>& indices, 
    535                                           const MPI_Comm& clientIntraComm, 
    536                                           std::list<MPI_Request>& requestSendIndex) 
     548                                                       const MPI_Comm& clientIntraComm, 
     549                                                       std::list<MPI_Request>& requestSendIndex) 
    537550{ 
    538551  MPI_Request request; 
     
    551564template<typename T, typename H> 
    552565void CClientClientDHTTemplate<T,H>::sendInfoToClients(int clientDestRank, std::vector<T>& info, 
    553                                          const MPI_Comm& clientIntraComm, 
    554                                          std::list<MPI_Request>& requestSendInfo) 
     566                                                      const MPI_Comm& clientIntraComm, 
     567                                                      std::list<MPI_Request>& requestSendInfo) 
    555568{ 
    556569  MPI_Request request; 
Note: See TracChangeset for help on using the changeset viewer.