Changeset 830
- Timestamp:
- 03/23/16 16:11:06 (9 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/client_client_dht_template.hpp
r829 r830 16 16 #include "policy.hpp" 17 17 #include <boost/unordered_map.hpp> 18 //#include "utils.hpp"19 18 #include "dht_data_types.hpp" 20 19 … … 39 38 40 39 public: 41 /** Default constructor */42 40 CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap, 43 41 const MPI_Comm& clientIntraComm, … … 46 44 void computeIndexInfoMapping(const CArray<size_t,1>& indices); 47 45 48 const Index2InfoTypeMap& getInfoIndexMap() const {return in foIndexMapping_; }46 const Index2InfoTypeMap& getInfoIndexMap() const {return indexToInfoMappingLevel_; } 49 47 50 48 /** Default destructor */ … … 74 72 const int recvNbIndexCount, 75 73 int& countIndexServer, 76 std::map<int, unsigned char*>& in dexServerBuffBegin,74 std::map<int, unsigned char*>& infoBuffBegin, 77 75 std::map<int, MPI_Request>& requestRecvIndexServer, 78 76 const MPI_Comm& intraComm); 79 77 80 // Send server indexto clients81 void sendInfoToClients(int clientDestRank, std::vector<InfoType>& indexServer,78 // Send information to clients 79 void sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize, 82 80 const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer); 83 81 … … 99 97 Index2InfoTypeMap index2InfoMapping_; 100 98 101 //! A temporarymapping of index to the corresponding information in each level of hierarchy99 //! A mapping of index to the corresponding information in each level of hierarchy 102 100 Index2InfoTypeMap indexToInfoMappingLevel_; 103 104 //! Data (information) corresponding to global index105 Index2InfoTypeMap infoIndexMapping_;106 101 107 102 //! intracommuntion of clients -
XIOS/trunk/src/client_client_dht_template_impl.hpp
r829 r830 23 23 template<typename T, typename H> 24 24 CClientClientDHTTemplate<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) 27 27 : index2InfoMapping_(), indexToInfoMappingLevel_() 28 28 { … … 46 46 int lvl = this->commLevel_.size() - 1; 47 47 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 }55 48 } 56 49 … … 130 123 int nbIndexReceivedFromOthers = nbIndexToSend; 131 124 if (0 != nbIndexReceivedFromOthers) 132 recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers* infoTypeSize];125 recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*ProcessDHTElement<InfoType>::typeSize()]; 133 126 134 127 std::map<int, MPI_Request>::iterator itRequest; 135 128 std::vector<int> demandAlreadyReceived, repondAlreadyReceived; 136 137 129 138 130 int countIndex = 0; // Counting of buffer for receiving index … … 195 187 196 188 std::map<int, std::vector<InfoType> > client2ClientInfo; 189 std::vector<unsigned char*> infoToSend(src2Index.size()); 197 190 std::list<MPI_Request> sendInfoRequest; 198 std::map<int, std::vector<size_t> >::iterator it bSrc2Idx = src2Index.begin(), itSrc2Idx,191 std::map<int, std::vector<size_t> >::iterator itSrc2Idx = src2Index.begin(), 199 192 iteSrc2Idx = src2Index.end(); 200 for (i tSrc2Idx = itbSrc2Idx; itSrc2Idx != iteSrc2Idx; ++itSrc2Idx)193 for (int i=0; itSrc2Idx != iteSrc2Idx; ++itSrc2Idx, ++i) 201 194 { 202 195 int clientSourceRank = itSrc2Idx->first; 203 196 std::vector<size_t>& srcIdx = itSrc2Idx->second; 197 infoToSend[i] = new unsigned char [srcIdx.size()*ProcessDHTElement<InfoType>::typeSize()]; 198 int infoIndex = 0; 204 199 for (int idx = 0; idx < srcIdx.size(); ++idx) 205 200 { 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); 209 204 } 210 205 … … 240 235 unsigned char* beginBuff = infoBuffBegin[clientSourceRank]; 241 236 std::vector<size_t>& indexTmp = client2ClientIndex[clientSourceRank]; 242 TypeToBytes<InfoType> u;237 int infoIndex = 0; 243 238 for (int i = 0; i < actualCountInfo; ++i) 244 239 { 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); 248 241 } 249 242 nbSendBuffInfoReceived += actualCountInfo; … … 260 253 if (0 != maxNbIndexDemandedFromOthers) delete [] recvBuffIndex; 261 254 if (0 != nbIndexReceivedFromOthers) delete [] recvBuffInfo; 255 for (int idx = 0; idx < infoToSend.size(); ++idx) delete [] infoToSend[idx]; 262 256 delete [] sendBuff; 263 257 delete [] recvBuff; … … 346 340 int recvNbIndexCount = recvNbIndexBuff[clientRank]; 347 341 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()]; 349 343 350 344 // If a client holds information about index and the corresponding which don't belong to it, … … 356 350 for (; itIndex != iteIndex; ++itIndex) 357 351 sendIndexToClients(itIndex->first, itIndex->second, commLevel, sendRequest); 358 typename std::map<int, std::vector<InfoType> >::iterator it Info = client2ClientInfo.begin(),352 typename std::map<int, std::vector<InfoType> >::iterator itbInfo = client2ClientInfo.begin(), itInfo, 359 353 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 362 379 363 380 std::map<int, MPI_Request>::iterator itRequestIndex, itRequestInfo; … … 424 441 { 425 442 int count = it->second; 426 TypeToBytes<InfoType> u; 443 InfoType infoValue; 444 int infoIndex = 0; 427 445 for (int i = 0; i < count; ++i) 428 446 { 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)); 432 449 } 433 450 … … 448 465 } 449 466 467 for (int idx = 0; idx < infoToSend.size(); ++idx) delete [] infoToSend[idx]; 450 468 delete [] sendBuff; 451 469 delete [] sendNbIndexBuff; … … 563 581 */ 564 582 template<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) 583 void CClientClientDHTTemplate<T,H>::sendInfoToClients(int clientDestRank, unsigned char* info, int infoSize, 584 const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendInfo) 568 585 { 569 586 MPI_Request request; 570 587 requestSendInfo.push_back(request); 571 588 572 MPI_Isend( &(info)[0], info.size() * infoTypeSize, MPI_CHAR,589 MPI_Isend(info, infoSize, MPI_CHAR, 573 590 clientDestRank, MPI_DHT_INFO, clientIntraComm, &(requestSendInfo.back())); 574 591 }
Note: See TracChangeset
for help on using the changeset viewer.