Ignore:
Timestamp:
03/23/16 16:11:06 (5 years ago)
Author:
mhnguyen
Message:

Implementing pack and unpack function for generic type of dht

+) Replace union with the more generic function for packing data into buffer and unpacking data from buffer
+) Change PairIntInt? from struct to std::pair<int,int>

Test
+) On Curie
+) All tests pass

File:
1 edited

Legend:

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

    r829 r830  
    2323template<typename T, typename H> 
    2424CClientClientDHTTemplate<T,H>::CClientClientDHTTemplate(const boost::unordered_map<size_t,T>& indexInfoMap, 
    25                                                       const MPI_Comm& clientIntraComm, 
    26                                                       int hierarLvl) 
     25                                                        const MPI_Comm& clientIntraComm, 
     26                                                        int hierarLvl) 
    2727  : index2InfoMapping_(), indexToInfoMappingLevel_() 
    2828{ 
     
    4646  int lvl = this->commLevel_.size() - 1; 
    4747  computeIndexInfoMappingLevel(indices, this->commLevel_[lvl], lvl); 
    48   size_t size = indices.numElements(); 
    49   for (size_t idx = 0; idx < size; ++idx) 
    50   { 
    51     T& info = indexToInfoMappingLevel_[indices(idx)]; 
    52 //    infoIndexMapping_[info].push_back(indices(idx)); 
    53     infoIndexMapping_[indices(idx)] = info; 
    54   } 
    5548} 
    5649 
     
    130123  int nbIndexReceivedFromOthers = nbIndexToSend; 
    131124  if (0 != nbIndexReceivedFromOthers) 
    132     recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*infoTypeSize]; 
     125    recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*ProcessDHTElement<InfoType>::typeSize()]; 
    133126 
    134127  std::map<int, MPI_Request>::iterator itRequest; 
    135128  std::vector<int> demandAlreadyReceived, repondAlreadyReceived; 
    136  
    137129 
    138130  int countIndex = 0;  // Counting of buffer for receiving index 
     
    195187 
    196188  std::map<int, std::vector<InfoType> > client2ClientInfo; 
     189  std::vector<unsigned char*> infoToSend(src2Index.size()); 
    197190  std::list<MPI_Request> sendInfoRequest; 
    198   std::map<int, std::vector<size_t> >::iterator itbSrc2Idx = src2Index.begin(), itSrc2Idx, 
     191  std::map<int, std::vector<size_t> >::iterator itSrc2Idx = src2Index.begin(), 
    199192                                                iteSrc2Idx = src2Index.end(); 
    200   for (itSrc2Idx = itbSrc2Idx; itSrc2Idx != iteSrc2Idx; ++itSrc2Idx) 
     193  for (int i=0; itSrc2Idx != iteSrc2Idx; ++itSrc2Idx, ++i) 
    201194  { 
    202195    int clientSourceRank = itSrc2Idx->first; 
    203196    std::vector<size_t>& srcIdx = itSrc2Idx->second; 
     197    infoToSend[i] = new unsigned char [srcIdx.size()*ProcessDHTElement<InfoType>::typeSize()]; 
     198    int infoIndex = 0; 
    204199    for (int idx = 0; idx < srcIdx.size(); ++idx) 
    205200    { 
    206       client2ClientInfo[clientSourceRank].push_back(indexToInfoMappingLevel_[srcIdx[idx]]); 
    207     } 
    208     sendInfoToClients(clientSourceRank, client2ClientInfo[clientSourceRank], commLevel, sendInfoRequest); 
     201      ProcessDHTElement<InfoType>::packElement(indexToInfoMappingLevel_[srcIdx[idx]], infoToSend[i], infoIndex); 
     202    } 
     203    sendInfoToClients(clientSourceRank, infoToSend[i], infoIndex, commLevel, sendInfoRequest); 
    209204  } 
    210205 
     
    240235        unsigned char* beginBuff = infoBuffBegin[clientSourceRank]; 
    241236        std::vector<size_t>& indexTmp = client2ClientIndex[clientSourceRank]; 
    242         TypeToBytes<InfoType> u; 
     237        int infoIndex = 0; 
    243238        for (int i = 0; i < actualCountInfo; ++i) 
    244239        { 
    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; 
     240          ProcessDHTElement<InfoType>::unpackElement(indexToInfoMapping[indexTmp[i]], beginBuff, infoIndex); 
    248241        } 
    249242        nbSendBuffInfoReceived += actualCountInfo; 
     
    260253  if (0 != maxNbIndexDemandedFromOthers) delete [] recvBuffIndex; 
    261254  if (0 != nbIndexReceivedFromOthers) delete [] recvBuffInfo; 
     255  for (int idx = 0; idx < infoToSend.size(); ++idx) delete [] infoToSend[idx]; 
    262256  delete [] sendBuff; 
    263257  delete [] recvBuff; 
     
    346340  int recvNbIndexCount = recvNbIndexBuff[clientRank]; 
    347341  unsigned long* recvIndexBuff = new unsigned long[recvNbIndexCount]; 
    348   unsigned char* recvInfoBuff = new unsigned char[recvNbIndexCount*infoTypeSize]; 
     342  unsigned char* recvInfoBuff = new unsigned char[recvNbIndexCount*ProcessDHTElement<InfoType>::typeSize()]; 
    349343 
    350344  // If a client holds information about index and the corresponding which don't belong to it, 
     
    356350  for (; itIndex != iteIndex; ++itIndex) 
    357351    sendIndexToClients(itIndex->first, itIndex->second, commLevel, sendRequest); 
    358   typename std::map<int, std::vector<InfoType> >::iterator itInfo  = client2ClientInfo.begin(), 
     352  typename std::map<int, std::vector<InfoType> >::iterator itbInfo = client2ClientInfo.begin(), itInfo, 
    359353                                                           iteInfo = client2ClientInfo.end(); 
    360   for (; itInfo != iteInfo; ++itInfo) 
    361     sendInfoToClients(itInfo->first, itInfo->second, commLevel, sendRequest); 
     354 
     355  std::vector<int> infoSizeToSend(client2ClientInfo.size(),0); 
     356  std::vector<unsigned char*> infoToSend(client2ClientInfo.size()); 
     357  itInfo = itbInfo; 
     358  for (int idx = 0; itInfo != iteInfo; ++itInfo, ++idx) 
     359  { 
     360    const std::vector<InfoType>& infoVec = itInfo->second; 
     361    int infoVecSize = infoVec.size(); 
     362    std::vector<int> infoIndex(infoVecSize); 
     363    for (int i = 0; i < infoVecSize; ++i) 
     364    { 
     365      infoIndex[i] = infoSizeToSend[idx]; 
     366      ProcessDHTElement<InfoType>::packElement(infoVec[i], NULL, infoSizeToSend[idx]); 
     367    } 
     368 
     369    infoToSend[idx] = new unsigned char[infoSizeToSend[idx]]; 
     370    infoSizeToSend[idx] = 0; 
     371    for (int i = 0; i < infoVecSize; ++i) 
     372    { 
     373      ProcessDHTElement<InfoType>::packElement(infoVec[i], infoToSend[idx], infoSizeToSend[idx]); 
     374    } 
     375 
     376    sendInfoToClients(itInfo->first, infoToSend[idx], infoSizeToSend[idx], commLevel, sendRequest); 
     377  } 
     378 
    362379 
    363380  std::map<int, MPI_Request>::iterator itRequestIndex, itRequestInfo; 
     
    424441      { 
    425442        int count = it->second; 
    426         TypeToBytes<InfoType> u; 
     443        InfoType infoValue; 
     444        int infoIndex = 0; 
    427445        for (int i = 0; i < count; ++i) 
    428446        { 
    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)); 
     447          ProcessDHTElement<InfoType>::unpackElement(infoValue, infoBuffBegin[rank], infoIndex); 
     448          indexToInfoMapping.insert(std::make_pair<size_t,InfoType>(*(indexBuffBegin[rank]+i),infoValue)); 
    432449        } 
    433450 
     
    448465  } 
    449466 
     467  for (int idx = 0; idx < infoToSend.size(); ++idx) delete [] infoToSend[idx]; 
    450468  delete [] sendBuff; 
    451469  delete [] sendNbIndexBuff; 
     
    563581*/ 
    564582template<typename T, typename H> 
    565 void CClientClientDHTTemplate<T,H>::sendInfoToClients(int clientDestRank, std::vector<T>& info, 
    566                                                       const MPI_Comm& clientIntraComm, 
    567                                                       std::list<MPI_Request>& requestSendInfo) 
     583void CClientClientDHTTemplate<T,H>::sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize, 
     584                       const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendInfo) 
    568585{ 
    569586  MPI_Request request; 
    570587  requestSendInfo.push_back(request); 
    571588 
    572   MPI_Isend(&(info)[0], info.size() * infoTypeSize, MPI_CHAR, 
     589  MPI_Isend(info, infoSize, MPI_CHAR, 
    573590            clientDestRank, MPI_DHT_INFO, clientIntraComm, &(requestSendInfo.back())); 
    574591} 
Note: See TracChangeset for help on using the changeset viewer.