Changeset 829
- Timestamp:
- 03/23/16 16:11:01 (9 years ago)
- Location:
- XIOS/trunk/src
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/client_client_dht_decl.cpp
r721 r829 13 13 14 14 template class CClientClientDHTTemplate<int>; 15 template class CClientClientDHTTemplate<PairIntInt>; 15 16 16 17 } -
XIOS/trunk/src/client_client_dht_template.hpp
r727 r829 16 16 #include "policy.hpp" 17 17 #include <boost/unordered_map.hpp> 18 //#include "utils.hpp" 19 #include "dht_data_types.hpp" 18 20 19 21 namespace xios … … 33 35 typedef T InfoType; 34 36 static const int infoTypeSize = sizeof(InfoType); 37 typedef typename boost::unordered_map<InfoType, std::vector<size_t> > InfoType2IndexMap; 38 typedef typename boost::unordered_map<size_t,InfoType> Index2InfoTypeMap; 35 39 36 40 public: 37 41 /** Default constructor */ 38 CClientClientDHTTemplate(const boost::unordered_map<size_t,T>& indexInfoInitMap,42 CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap, 39 43 const MPI_Comm& clientIntraComm, 40 44 int hierarLvl = 2); … … 42 46 void computeIndexInfoMapping(const CArray<size_t,1>& indices); 43 47 44 const std::map<T, std::vector<size_t> >& getInfoIndexMap() const {return indexGlobalOnServer_; }48 const Index2InfoTypeMap& getInfoIndexMap() const {return infoIndexMapping_; } 45 49 46 50 /** Default destructor */ … … 49 53 protected: 50 54 // Redistribute index and info among clients 51 void computeDistributedIndex(const boost::unordered_map<size_t,T>& indexInfoInitMap,55 void computeDistributedIndex(const Index2InfoTypeMap& indexInfoInitMap, 52 56 const MPI_Comm& intraCommLevel, 53 57 int level); … … 67 71 const MPI_Comm& intraComm); 68 72 69 void probeInfoMessageFromClients( InfoType* recvIndexServerBuff,73 void probeInfoMessageFromClients(unsigned char* recvIndexServerBuff, 70 74 const int recvNbIndexCount, 71 75 int& countIndexServer, 72 std::map<int, InfoType*>& indexServerBuffBegin,76 std::map<int, unsigned char*>& indexServerBuffBegin, 73 77 std::map<int, MPI_Request>& requestRecvIndexServer, 74 78 const MPI_Comm& intraComm); … … 93 97 protected: 94 98 //! Mapping of global index to the corresponding client 95 boost::unordered_map<size_t,InfoType>index2InfoMapping_;99 Index2InfoTypeMap index2InfoMapping_; 96 100 97 101 //! A temporary mapping of index to the corresponding information in each level of hierarchy 98 boost::unordered_map<size_t,InfoType>indexToInfoMappingLevel_;102 Index2InfoTypeMap indexToInfoMappingLevel_; 99 103 100 //! Global index of data on SERVER, which are calculated by client(s)101 std::map<int, std::vector<size_t> > indexGlobalOnServer_;104 //! Data (information) corresponding to global index 105 Index2InfoTypeMap infoIndexMapping_; 102 106 103 107 //! intracommuntion of clients … … 109 113 110 114 typedef CClientClientDHTTemplate<int> CClientClientDHTInt; 115 typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt; 111 116 112 117 } // namespace xios -
XIOS/trunk/src/client_client_dht_template_impl.hpp
r721 r829 49 49 for (size_t idx = 0; idx < size; ++idx) 50 50 { 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; 53 54 } 54 55 } … … 125 126 126 127 // 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; 128 130 int nbIndexReceivedFromOthers = nbIndexToSend; 129 131 if (0 != nbIndexReceivedFromOthers) 130 recvBuffInfo = new InfoType[nbIndexReceivedFromOthers];132 recvBuffInfo = new unsigned char[nbIndexReceivedFromOthers*infoTypeSize]; 131 133 132 134 std::map<int, MPI_Request>::iterator itRequest; … … 212 214 213 215 // 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; 215 217 216 218 while ((!sendInfoRequest.empty()) || (nbSendBuffInfoReceived < nbIndexReceivedFromOthers)) … … 233 235 if (true == flagInfo) 234 236 { 235 MPI_Get_count(&statusInfo, MPI_INT, &count); 237 MPI_Get_count(&statusInfo, MPI_CHAR, &count); 238 int actualCountInfo = count/infoTypeSize; 236 239 int clientSourceRank = statusInfo.MPI_SOURCE; 237 InfoType* beginBuff = infoBuffBegin[clientSourceRank];240 unsigned char* beginBuff = infoBuffBegin[clientSourceRank]; 238 241 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) 240 244 { 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; 242 248 } 243 nbSendBuffInfoReceived += count;249 nbSendBuffInfoReceived += actualCountInfo; 244 250 repondAlreadyReceived.push_back(clientSourceRank); 245 251 } … … 251 257 } 252 258 253 indexToInfoMappingLevel_ = indexToInfoMapping;259 indexToInfoMappingLevel_.swap(indexToInfoMapping); 254 260 if (0 != maxNbIndexDemandedFromOthers) delete [] recvBuffIndex; 255 261 if (0 != nbIndexReceivedFromOthers) delete [] recvBuffInfo; … … 289 295 template<typename T, typename H> 290 296 void 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) 293 299 { 294 300 int nbClient, clientRank; … … 340 346 int recvNbIndexCount = recvNbIndexBuff[clientRank]; 341 347 unsigned long* recvIndexBuff = new unsigned long[recvNbIndexCount]; 342 InfoType* recvInfoBuff = new InfoType[recvNbIndexCount];348 unsigned char* recvInfoBuff = new unsigned char[recvNbIndexCount*infoTypeSize]; 343 349 344 350 // If a client holds information about index and the corresponding which don't belong to it, … … 374 380 375 381 // 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; 377 383 378 384 boost::unordered_map<size_t,InfoType> indexToInfoMapping; … … 418 424 { 419 425 int count = it->second; 426 TypeToBytes<InfoType> u; 420 427 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 422 434 processedList.push_back(rank); 423 435 --recvNbClient; … … 466 478 template<typename T, typename H> 467 479 void 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) 473 485 { 474 486 MPI_Status statusIndexGlobal; … … 500 512 */ 501 513 template<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)514 void 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) 508 520 { 509 521 MPI_Status statusInfo; … … 515 527 { 516 528 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, 519 532 statusInfo.MPI_SOURCE, MPI_DHT_INFO, intraComm, 520 533 &requestRecvInfo[statusInfo.MPI_SOURCE]); … … 533 546 template<typename T, typename H> 534 547 void 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) 537 550 { 538 551 MPI_Request request; … … 551 564 template<typename T, typename H> 552 565 void 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) 555 568 { 556 569 MPI_Request request; -
XIOS/trunk/src/client_server_mapping.cpp
r569 r829 12 12 13 13 CClientServerMapping::CClientServerMapping() 14 : indexGlobalOnServer_(), localIndexSend2Server_(), connectedClients_()14 : indexGlobalOnServer_(), connectedClients_() //, localIndexSend2Server_() 15 15 { 16 16 } … … 20 20 } 21 21 22 / *!23 Compute mapping global index of server which client sends to.24 \param [in] globalIndexOnClient global index on client25 \param [in] globalIndexServer global index of servers26 */27 void CClientServerMapping::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient,28 const std::vector<CArray<size_t,1>* >& globalIndexServer)29 {30 defaultComputeServerIndexMapping(globalIndexOnClient, globalIndexServer);31 }22 ///*! 23 // Compute mapping global index of server which client sends to. 24 // \param [in] globalIndexOnClient global index on client 25 // \param [in] globalIndexServer global index of servers 26 //*/ 27 //void CClientServerMapping::computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 28 // const std::vector<CArray<size_t,1>* >& globalIndexServer) 29 //{ 30 // defaultComputeServerIndexMapping(globalIndexOnClient, globalIndexServer); 31 //} 32 32 33 / *!34 Compute index of data which are sent to server and index global on server side35 \param [in] globalIndexOnClient global index of data on client36 \param [in] globalIndexServer global index of server(s)37 \param [in] localIndexOnClient local index of data on client which are sent to server38 */39 void CClientServerMapping::defaultComputeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient,40 const std::vector<CArray<size_t,1>* >& globalIndexServer,41 const CArray<int,1>* localIndexOnClient)42 {43 int nServer = globalIndexServer.size();44 std::vector<CArray<size_t,1>::const_iterator> itBegin(nServer), itEnd(nServer), it(nServer);45 for (int i = 0; i < nServer; ++i)46 {47 itBegin[i] = it[i] = globalIndexServer[i]->begin();48 itEnd[i] = globalIndexServer[i]->end();49 }50 51 size_t ssize = globalIndexOnClient.numElements();52 for (int i = 0; i < ssize; ++i)53 {54 for (int j = 0; j < nServer; ++j)55 {56 // Just temporarily, it's bad.57 if (std::binary_search(itBegin[j], itEnd[j], globalIndexOnClient(i)))58 {59 // Just try to calculate local index server on client side60 (indexGlobalOnServer_[j]).push_back((globalIndexOnClient)(i));61 if (0 != localIndexOnClient) (localIndexSend2Server_[j]).push_back((*localIndexOnClient)(i));62 else63 (localIndexSend2Server_[j]).push_back(i);64 continue;65 }66 }67 }68 }33 ///*! 34 // Compute index of data which are sent to server and index global on server side 35 // \param [in] globalIndexOnClient global index of data on client 36 // \param [in] globalIndexServer global index of server(s) 37 // \param [in] localIndexOnClient local index of data on client which are sent to server 38 //*/ 39 //void CClientServerMapping::defaultComputeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 40 // const std::vector<CArray<size_t,1>* >& globalIndexServer, 41 // const CArray<int,1>* localIndexOnClient) 42 //{ 43 // int nServer = globalIndexServer.size(); 44 // std::vector<CArray<size_t,1>::const_iterator> itBegin(nServer), itEnd(nServer), it(nServer); 45 // for (int i = 0; i < nServer; ++i) 46 // { 47 // itBegin[i] = it[i] = globalIndexServer[i]->begin(); 48 // itEnd[i] = globalIndexServer[i]->end(); 49 // } 50 // 51 // size_t ssize = globalIndexOnClient.numElements(); 52 // for (int i = 0; i < ssize; ++i) 53 // { 54 // for (int j = 0; j < nServer; ++j) 55 // { 56 // // Just temporarily, it's bad. 57 // if (std::binary_search(itBegin[j], itEnd[j], globalIndexOnClient(i))) 58 // { 59 // // Just try to calculate local index server on client side 60 // (indexGlobalOnServer_[j]).push_back((globalIndexOnClient)(i)); 61 // if (0 != localIndexOnClient) (localIndexSend2Server_[j]).push_back((*localIndexOnClient)(i)); 62 // else 63 // (localIndexSend2Server_[j]).push_back(i); 64 // continue; 65 // } 66 // } 67 // } 68 //} 69 69 70 70 /*! … … 134 134 } 135 135 136 / *!137 Return local index of data that is send to server138 \return mapping of server rank and local index of sending data on the client139 */140 const std::map<int, std::vector<int> >& CClientServerMapping::getLocalIndexSendToServer() const141 {142 return localIndexSend2Server_;143 }136 ///*! 137 // Return local index of data that is send to server 138 // \return mapping of server rank and local index of sending data on the client 139 //*/ 140 //const CClientServerMapping::LocalIndexMap& CClientServerMapping::getLocalIndexSendToServer() const 141 //{ 142 // return localIndexSend2Server_; 143 //} 144 144 145 145 /*! … … 149 149 \return mapping of server rank and its global index. 150 150 */ 151 const std::map<int, std::vector<size_t> >& CClientServerMapping::getGlobalIndexOnServer() const151 const CClientServerMapping::GlobalIndexMap& CClientServerMapping::getGlobalIndexOnServer() const 152 152 { 153 153 return indexGlobalOnServer_; -
XIOS/trunk/src/client_server_mapping.hpp
r598 r829 13 13 #include "array_new.hpp" 14 14 #include "mpi.hpp" 15 #include <boost/unordered_map.hpp> 15 16 16 17 namespace xios { … … 23 24 class CClientServerMapping 24 25 { 26 public: 27 typedef boost::unordered_map<int, std::vector<size_t> > GlobalIndexMap; 28 typedef std::map<int, std::vector<int> > LocalIndexMap; 25 29 public: 26 30 /** Default constructor */ … … 33 37 virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient) = 0; 34 38 35 // // In case of computing local index on client sent to server39 // // Simple case, global index on client and index on servers 36 40 // virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 37 // const CArray<int,1>& localIndexOnClient) = 0; 38 39 // Simple case, global index on client and index on servers 40 virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 41 const std::vector<CArray<size_t,1>* >& globalIndexOnServer); 41 // const std::vector<CArray<size_t,1>* >& globalIndexOnServer); 42 42 43 43 static std::map<int,int> computeConnectedClients(int nbServer, int nbClient, … … 45 45 const std::vector<int>& connectedServerRank); 46 46 47 const std::map<int, std::vector<size_t> >& getGlobalIndexOnServer() const;48 const std::map<int, std::vector<int> >& getLocalIndexSendToServer() const;47 const GlobalIndexMap& getGlobalIndexOnServer() const; 48 // const LocalIndexMap& getLocalIndexSendToServer() const; 49 49 50 50 protected: 51 void defaultComputeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient,52 const std::vector<CArray<size_t,1>* >& globalIndexOnServer,53 const CArray<int,1>* localIndexOnClient = 0);51 // void defaultComputeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient, 52 // const std::vector<CArray<size_t,1>* >& globalIndexOnServer, 53 // const CArray<int,1>* localIndexOnClient = 0); 54 54 55 55 protected: 56 56 //! Global index of data on SERVER, which are calculated by client(s) 57 std::map<int, std::vector<size_t> >indexGlobalOnServer_;57 GlobalIndexMap indexGlobalOnServer_; 58 58 59 59 //! Index of the local data which will be sent to the corresponding server(s) 60 std::map<int, std::vector<int> >localIndexSend2Server_;60 // LocalIndexMap localIndexSend2Server_; 61 61 62 62 //!< Number of clients connected to a server -
XIOS/trunk/src/client_server_mapping_distributed.cpp
r721 r829 3 3 \author Ha NGUYEN 4 4 \since 27 Feb 2015 5 \date 06 Oct 20155 \date 16 Mars 2016 6 6 7 7 \brief Mapping between index client and server. … … 19 19 CClientServerMappingDistributed::CClientServerMappingDistributed(const boost::unordered_map<size_t,int>& globalIndexOfServer, 20 20 const MPI_Comm& clientIntraComm, bool isDataDistributed) 21 : CClientServerMapping(), indexClientHash_(), countIndexGlobal_(0), countIndexServer_(0), 22 indexGlobalBuffBegin_(), indexServerBuffBegin_(), requestRecvIndexServer_(), isDataDistributed_(isDataDistributed), 23 ccDHT_(0) 21 : CClientServerMapping(), ccDHT_(0) 24 22 { 25 clientIntraComm_ = clientIntraComm;26 MPI_Comm_size(clientIntraComm,&(nbClient_));27 MPI_Comm_rank(clientIntraComm,&clientRank_);28 computeHashIndex();29 30 23 ccDHT_ = new CClientClientDHTInt(globalIndexOfServer, 31 24 clientIntraComm, 32 25 isDataDistributed); 33 34 // computeDistributedServerIndex(globalIndexOfServer, clientIntraComm);35 26 } 36 27 … … 47 38 { 48 39 ccDHT_->computeIndexInfoMapping(globalIndexOnClient); 49 indexGlobalOnServer_ = (ccDHT_->getInfoIndexMap()); 50 51 /* 52 size_t ssize = globalIndexOnClient.numElements(), hashedIndex; 53 54 std::vector<size_t>::const_iterator itbClientHash = indexClientHash_.begin(), itClientHash, 55 iteClientHash = indexClientHash_.end(); 56 std::map<int, std::vector<size_t> > client2ClientIndexGlobal; 57 std::map<int, std::vector<int> > client2ClientIndexServer; 58 59 // Number of global index whose mapping server can be found out thanks to index-server mapping 60 int nbIndexAlreadyOnClient = 0; 61 62 // Number of global index whose mapping server are on other clients 63 int nbIndexSendToOthers = 0; 64 HashXIOS<size_t> hashGlobalIndex; 65 for (int i = 0; i < ssize; ++i) 66 { 67 size_t globalIndexClient = globalIndexOnClient(i); 68 hashedIndex = hashGlobalIndex(globalIndexClient); 69 itClientHash = std::upper_bound(itbClientHash, iteClientHash, hashedIndex); 70 if (iteClientHash != itClientHash) 71 { 72 int indexClient = std::distance(itbClientHash, itClientHash)-1; 73 { 74 client2ClientIndexGlobal[indexClient].push_back(globalIndexClient); 75 ++nbIndexSendToOthers; 76 } 77 } 78 } 79 80 int* sendBuff = new int[nbClient_]; 81 for (int i = 0; i < nbClient_; ++i) sendBuff[i] = 0; 82 std::map<int, std::vector<size_t> >::iterator itb = client2ClientIndexGlobal.begin(), it, 83 ite = client2ClientIndexGlobal.end(); 84 for (it = itb; it != ite; ++it) sendBuff[it->first] = 1; 85 int* recvBuff = new int[nbClient_]; 86 MPI_Allreduce(sendBuff, recvBuff, nbClient_, MPI_INT, MPI_SUM, clientIntraComm_); 87 88 std::list<MPI_Request> sendRequest; 89 if (0 != nbIndexSendToOthers) 90 for (it = itb; it != ite; ++it) 91 sendIndexGlobalToClients(it->first, it->second, clientIntraComm_, sendRequest); 92 93 int nbDemandingClient = recvBuff[clientRank_], nbIndexServerReceived = 0; 94 95 // Receiving demand as well as the responds from other clients 96 // The demand message contains global index; meanwhile the responds have server index information 97 // Buffer to receive demand from other clients, it can be allocated or not depending whether it has demand(s) 98 // There are some cases we demand duplicate index so need to determine maxium size of demanding buffer 99 for (it = itb; it != ite; ++it) sendBuff[it->first] = (it->second).size(); 100 MPI_Allreduce(sendBuff, recvBuff, nbClient_, MPI_INT, MPI_SUM, clientIntraComm_); 101 102 unsigned long* recvBuffIndexGlobal = 0; 103 int maxNbIndexDemandedFromOthers = recvBuff[clientRank_]; 104 if (!isDataDistributed_) maxNbIndexDemandedFromOthers = nbDemandingClient * nbIndexSendToOthers; //globalIndexToServerMapping_.size(); // Not very optimal but it's general 105 106 if (0 != maxNbIndexDemandedFromOthers) 107 recvBuffIndexGlobal = new unsigned long[maxNbIndexDemandedFromOthers]; 108 109 // Buffer to receive respond from other clients, it can be allocated or not depending whether it demands other clients 110 int* recvBuffIndexServer = 0; 111 int nbIndexReceivedFromOthers = nbIndexSendToOthers; 112 if (0 != nbIndexReceivedFromOthers) 113 recvBuffIndexServer = new int[nbIndexReceivedFromOthers]; 114 115 std::map<int, MPI_Request>::iterator itRequest; 116 std::vector<int> demandAlreadyReceived, repondAlreadyReceived; 117 118 119 resetReceivingRequestAndCount(); 120 while ((0 < nbDemandingClient) || (!sendRequest.empty()) || 121 (nbIndexServerReceived < nbIndexReceivedFromOthers)) 122 { 123 // Just check whether a client has any demand from other clients. 124 // If it has, then it should send responds to these client(s) 125 probeIndexGlobalMessageFromClients(recvBuffIndexGlobal, maxNbIndexDemandedFromOthers); 126 if (0 < nbDemandingClient) 127 { 128 for (itRequest = requestRecvIndexGlobal_.begin(); 129 itRequest != requestRecvIndexGlobal_.end(); ++itRequest) 130 { 131 int flagIndexGlobal, count; 132 MPI_Status statusIndexGlobal; 133 134 MPI_Test(&(itRequest->second), &flagIndexGlobal, &statusIndexGlobal); 135 if (true == flagIndexGlobal) 136 { 137 MPI_Get_count(&statusIndexGlobal, MPI_UNSIGNED_LONG, &count); 138 int clientSourceRank = statusIndexGlobal.MPI_SOURCE; 139 unsigned long* beginBuff = indexGlobalBuffBegin_[clientSourceRank]; 140 for (int i = 0; i < count; ++i) 141 { 142 client2ClientIndexServer[clientSourceRank].push_back(globalIndexToServerMapping_[*(beginBuff+i)]); 143 } 144 sendIndexServerToClients(clientSourceRank, client2ClientIndexServer[clientSourceRank], clientIntraComm_, sendRequest); 145 --nbDemandingClient; 146 147 demandAlreadyReceived.push_back(clientSourceRank); 148 } 149 } 150 for (int i = 0; i< demandAlreadyReceived.size(); ++i) 151 requestRecvIndexGlobal_.erase(demandAlreadyReceived[i]); 152 } 153 154 testSendRequest(sendRequest); 155 156 // In some cases, a client need to listen respond from other clients about server information 157 // Ok, with the information, a client can fill in its server-global index map. 158 probeIndexServerMessageFromClients(recvBuffIndexServer, nbIndexReceivedFromOthers); 159 for (itRequest = requestRecvIndexServer_.begin(); 160 itRequest != requestRecvIndexServer_.end(); 161 ++itRequest) 162 { 163 int flagIndexServer, count; 164 MPI_Status statusIndexServer; 165 166 MPI_Test(&(itRequest->second), &flagIndexServer, &statusIndexServer); 167 if (true == flagIndexServer) 168 { 169 MPI_Get_count(&statusIndexServer, MPI_INT, &count); 170 int clientSourceRank = statusIndexServer.MPI_SOURCE; 171 int* beginBuff = indexServerBuffBegin_[clientSourceRank]; 172 std::vector<size_t>& globalIndexTmp = client2ClientIndexGlobal[clientSourceRank]; 173 for (int i = 0; i < count; ++i) 174 { 175 (indexGlobalOnServer_[*(beginBuff+i)]).push_back(globalIndexTmp[i]); 176 } 177 nbIndexServerReceived += count; 178 repondAlreadyReceived.push_back(clientSourceRank); 179 } 180 } 181 182 for (int i = 0; i< repondAlreadyReceived.size(); ++i) 183 requestRecvIndexServer_.erase(repondAlreadyReceived[i]); 184 repondAlreadyReceived.resize(0); 185 } 186 187 if (0 != maxNbIndexDemandedFromOthers) delete [] recvBuffIndexGlobal; 188 if (0 != nbIndexReceivedFromOthers) delete [] recvBuffIndexServer; 189 delete [] sendBuff; 190 delete [] recvBuff; 191 */ 192 } 193 194 /*! 195 Compute the hash index distribution of whole size_t space then each client will have a range of this distribution 196 */ 197 void CClientServerMappingDistributed::computeHashIndex() 198 { 199 // Compute range of hash index for each client 200 indexClientHash_.resize(nbClient_+1); 201 size_t nbHashIndexMax = std::numeric_limits<size_t>::max(); 202 size_t nbHashIndex; 203 indexClientHash_[0] = 0; 204 for (int i = 1; i < nbClient_; ++i) 205 { 206 nbHashIndex = nbHashIndexMax / nbClient_; 207 if (i < (nbHashIndexMax%nbClient_)) ++nbHashIndex; 208 indexClientHash_[i] = indexClientHash_[i-1] + nbHashIndex; 209 } 210 indexClientHash_[nbClient_] = nbHashIndexMax; 211 } 212 213 /*! 214 Compute distribution of global index for servers 215 Each client already holds a piece of information about global index and the corresponding server. 216 This information is redistributed into size_t space in which each client possesses a specific range of index. 217 After the redistribution, each client as well as its range of index contains all necessary information about server. 218 \param [in] globalIndexOfServer global index and the corresponding server 219 \param [in] clientIntraComm client joining distribution process. 220 */ 221 void CClientServerMappingDistributed::computeDistributedServerIndex(const boost::unordered_map<size_t,int>& globalIndexOfServer, 222 const MPI_Comm& clientIntraComm) 223 { 224 int* sendBuff = new int[nbClient_]; 225 int* sendNbIndexBuff = new int[nbClient_]; 226 for (int i = 0; i < nbClient_; ++i) 227 { 228 sendBuff[i] = 0; sendNbIndexBuff[i] = 0; 229 } 230 231 // Compute size of sending and receving buffer 232 std::map<int, std::vector<size_t> > client2ClientIndexGlobal; 233 std::map<int, std::vector<int> > client2ClientIndexServer; 234 235 std::vector<size_t>::const_iterator itbClientHash = indexClientHash_.begin(), itClientHash, 236 iteClientHash = indexClientHash_.end(); 237 boost::unordered_map<size_t,int>::const_iterator it = globalIndexOfServer.begin(), 238 ite = globalIndexOfServer.end(); 239 HashXIOS<size_t> hashGlobalIndex; 40 const boost::unordered_map<size_t,int>& infoIndexMap = (ccDHT_->getInfoIndexMap()); 41 // indexGlobalOnServer_ = (ccDHT_->getInfoIndexMap()); 42 boost::unordered_map<size_t,int>::const_iterator it = infoIndexMap.begin(), ite = infoIndexMap.end(); 240 43 for (; it != ite; ++it) 241 44 { 242 size_t hashIndex = hashGlobalIndex(it->first); 243 itClientHash = std::upper_bound(itbClientHash, iteClientHash, hashIndex); 244 if (itClientHash != iteClientHash) 245 { 246 int indexClient = std::distance(itbClientHash, itClientHash)-1; 247 { 248 sendBuff[indexClient] = 1; 249 ++sendNbIndexBuff[indexClient]; 250 client2ClientIndexGlobal[indexClient].push_back(it->first); 251 client2ClientIndexServer[indexClient].push_back(it->second); 252 } 253 } 254 } 255 256 // Calculate from how many clients each client receive message. 257 int* recvBuff = new int[nbClient_]; 258 MPI_Allreduce(sendBuff, recvBuff, nbClient_, MPI_INT, MPI_SUM, clientIntraComm); 259 int recvNbClient = recvBuff[clientRank_]; 260 261 // Calculate size of buffer for receiving message 262 int* recvNbIndexBuff = new int[nbClient_]; 263 MPI_Allreduce(sendNbIndexBuff, recvNbIndexBuff, nbClient_, MPI_INT, MPI_SUM, clientIntraComm); 264 int recvNbIndexCount = recvNbIndexBuff[clientRank_]; 265 unsigned long* recvIndexGlobalBuff = new unsigned long[recvNbIndexCount]; 266 int* recvIndexServerBuff = new int[recvNbIndexCount]; 267 268 // If a client holds information about global index and servers which don't belong to it, 269 // it will send a message to the correct clients. 270 // Contents of the message are global index and its corresponding server index 271 std::list<MPI_Request> sendRequest; 272 std::map<int, std::vector<size_t> >::iterator itGlobal = client2ClientIndexGlobal.begin(), 273 iteGlobal = client2ClientIndexGlobal.end(); 274 for ( ;itGlobal != iteGlobal; ++itGlobal) 275 sendIndexGlobalToClients(itGlobal->first, itGlobal->second, clientIntraComm, sendRequest); 276 std::map<int, std::vector<int> >::iterator itServer = client2ClientIndexServer.begin(), 277 iteServer = client2ClientIndexServer.end(); 278 for (; itServer != iteServer; ++itServer) 279 sendIndexServerToClients(itServer->first, itServer->second, clientIntraComm, sendRequest); 280 281 std::map<int, MPI_Request>::iterator itRequestIndexGlobal, itRequestIndexServer; 282 std::map<int, int> countBuffIndexServer, countBuffIndexGlobal; 283 std::vector<int> processedList; 284 285 bool isFinished = (0 == recvNbClient) ? true : false; 286 287 // Just to make sure before listening message, all counting index and receiving request have already beeen reset 288 resetReceivingRequestAndCount(); 289 290 // Now each client trys to listen to demand from others. 291 // If they have message, it processes: pushing global index and corresponding server to its map 292 while (!isFinished || (!sendRequest.empty())) 293 { 294 testSendRequest(sendRequest); 295 probeIndexGlobalMessageFromClients(recvIndexGlobalBuff, recvNbIndexCount); 296 297 // Processing complete request 298 for (itRequestIndexGlobal = requestRecvIndexGlobal_.begin(); 299 itRequestIndexGlobal != requestRecvIndexGlobal_.end(); 300 ++itRequestIndexGlobal) 301 { 302 int rank = itRequestIndexGlobal->first; 303 int countIndexGlobal = computeBuffCountIndexGlobal(itRequestIndexGlobal->second); 304 if (0 != countIndexGlobal) 305 countBuffIndexGlobal[rank] = countIndexGlobal; 306 } 307 308 probeIndexServerMessageFromClients(recvIndexServerBuff, recvNbIndexCount); 309 for (itRequestIndexServer = requestRecvIndexServer_.begin(); 310 itRequestIndexServer != requestRecvIndexServer_.end(); 311 ++itRequestIndexServer) 312 { 313 int rank = itRequestIndexServer->first; 314 int countIndexServer = computeBuffCountIndexServer(itRequestIndexServer->second); 315 if (0 != countIndexServer) 316 countBuffIndexServer[rank] = countIndexServer; 317 } 318 319 for (std::map<int, int>::iterator it = countBuffIndexGlobal.begin(); 320 it != countBuffIndexGlobal.end(); ++it) 321 { 322 int rank = it->first; 323 if (countBuffIndexServer.end() != countBuffIndexServer.find(rank)) 324 { 325 processReceivedRequest(indexGlobalBuffBegin_[rank], indexServerBuffBegin_[rank], it->second); 326 processedList.push_back(rank); 327 --recvNbClient; 328 } 329 } 330 331 for (int i = 0; i < processedList.size(); ++i) 332 { 333 requestRecvIndexServer_.erase(processedList[i]); 334 requestRecvIndexGlobal_.erase(processedList[i]); 335 countBuffIndexGlobal.erase(processedList[i]); 336 countBuffIndexServer.erase(processedList[i]); 337 } 338 339 if (0 == recvNbClient) isFinished = true; 340 } 341 342 delete [] sendBuff; 343 delete [] sendNbIndexBuff; 344 delete [] recvBuff; 345 delete [] recvNbIndexBuff; 346 delete [] recvIndexGlobalBuff; 347 delete [] recvIndexServerBuff; 348 } 349 350 /*! 351 Probe and receive message containg global index from other clients. 352 Each client can send a message of global index to other clients to fulfill their maps. 353 Each client probes message from its queue then if the message is ready, it will be put into the receiving buffer 354 \param [in] recvIndexGlobalBuff buffer dedicated for receiving global index 355 \param [in] recvNbIndexCount size of the buffer 356 */ 357 void CClientServerMappingDistributed::probeIndexGlobalMessageFromClients(unsigned long* recvIndexGlobalBuff, int recvNbIndexCount) 358 { 359 MPI_Status statusIndexGlobal; 360 int flagIndexGlobal, count; 361 362 // Probing for global index 363 MPI_Iprobe(MPI_ANY_SOURCE, MPI_DHT_INDEX_0, clientIntraComm_, &flagIndexGlobal, &statusIndexGlobal); 364 if ((true == flagIndexGlobal) && (countIndexGlobal_ < recvNbIndexCount)) 365 { 366 MPI_Get_count(&statusIndexGlobal, MPI_UNSIGNED_LONG, &count); 367 indexGlobalBuffBegin_.insert(std::make_pair<int, unsigned long*>(statusIndexGlobal.MPI_SOURCE, recvIndexGlobalBuff+countIndexGlobal_)); 368 MPI_Irecv(recvIndexGlobalBuff+countIndexGlobal_, count, MPI_UNSIGNED_LONG, 369 statusIndexGlobal.MPI_SOURCE, MPI_DHT_INDEX_0, clientIntraComm_, 370 &requestRecvIndexGlobal_[statusIndexGlobal.MPI_SOURCE]); 371 countIndexGlobal_ += count; 45 indexGlobalOnServer_[it->second].push_back(it->first); 372 46 } 373 47 } 374 48 375 /*!376 Probe and receive message containg server index from other clients.377 Each client can send a message of server index to other clients to fulfill their maps.378 Each client probes message from its queue then if the message is ready, it will be put into the receiving buffer379 \param [in] recvIndexServerBuff buffer dedicated for receiving server index380 \param [in] recvNbIndexCount size of the buffer381 */382 void CClientServerMappingDistributed::probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount)383 {384 MPI_Status statusIndexServer;385 int flagIndexServer, count;386 387 // Probing for server index388 MPI_Iprobe(MPI_ANY_SOURCE, MPI_DHT_INFO_0, clientIntraComm_, &flagIndexServer, &statusIndexServer);389 if ((true == flagIndexServer) && (countIndexServer_ < recvNbIndexCount))390 {391 MPI_Get_count(&statusIndexServer, MPI_INT, &count);392 indexServerBuffBegin_.insert(std::make_pair<int, int*>(statusIndexServer.MPI_SOURCE, recvIndexServerBuff+countIndexServer_));393 MPI_Irecv(recvIndexServerBuff+countIndexServer_, count, MPI_INT,394 statusIndexServer.MPI_SOURCE, MPI_DHT_INFO_0, clientIntraComm_,395 &requestRecvIndexServer_[statusIndexServer.MPI_SOURCE]);396 397 countIndexServer_ += count;398 }399 49 } 400 401 /*!402 Send message containing global index to clients403 \param [in] clientDestRank rank of destination client404 \param [in] indexGlobal global index to send405 \param [in] clientIntraComm communication group of client406 \param [in] requestSendIndexGlobal list of sending request407 */408 void CClientServerMappingDistributed::sendIndexGlobalToClients(int clientDestRank, std::vector<size_t>& indexGlobal,409 const MPI_Comm& clientIntraComm,410 std::list<MPI_Request>& requestSendIndexGlobal)411 {412 MPI_Request request;413 requestSendIndexGlobal.push_back(request);414 MPI_Isend(&(indexGlobal)[0], (indexGlobal).size(), MPI_UNSIGNED_LONG,415 clientDestRank, MPI_DHT_INDEX_0, clientIntraComm, &(requestSendIndexGlobal.back()));416 }417 418 /*!419 Send message containing server index to clients420 \param [in] clientDestRank rank of destination client421 \param [in] indexServer server index to send422 \param [in] clientIntraComm communication group of client423 \param [in] requestSendIndexServer list of sending request424 */425 void CClientServerMappingDistributed::sendIndexServerToClients(int clientDestRank, std::vector<int>& indexServer,426 const MPI_Comm& clientIntraComm,427 std::list<MPI_Request>& requestSendIndexServer)428 {429 MPI_Request request;430 requestSendIndexServer.push_back(request);431 MPI_Isend(&(indexServer)[0], (indexServer).size(), MPI_INT,432 clientDestRank, MPI_DHT_INFO_0, clientIntraComm, &(requestSendIndexServer.back()));433 }434 435 /*!436 Verify status of sending request437 \param [in] sendRequest sending request to verify438 */439 void CClientServerMappingDistributed::testSendRequest(std::list<MPI_Request>& sendRequest)440 {441 int flag = 0;442 MPI_Status status;443 std::list<MPI_Request>::iterator itRequest;444 int sizeListRequest = sendRequest.size();445 int idx = 0;446 while (idx < sizeListRequest)447 {448 bool isErased = false;449 for (itRequest = sendRequest.begin(); itRequest != sendRequest.end(); ++itRequest)450 {451 MPI_Test(&(*itRequest), &flag, &status);452 if (true == flag)453 {454 isErased = true;455 break;456 }457 }458 if (true == isErased) sendRequest.erase(itRequest);459 ++idx;460 }461 }462 463 /*!464 Process the received request. Pushing global index and server index into map465 \param[in] buffIndexGlobal pointer to the begining of buffer containing global index466 \param[in] buffIndexServer pointer to the begining of buffer containing server index467 \param[in] count size of received message468 */469 void CClientServerMappingDistributed::processReceivedRequest(unsigned long* buffIndexGlobal, int* buffIndexServer, int count)470 {471 for (int i = 0; i < count; ++i)472 globalIndexToServerMapping_.insert(std::make_pair<size_t,int>(*(buffIndexGlobal+i),*(buffIndexServer+i)));473 }474 475 /*!476 Compute size of message containing global index477 \param[in] requestRecv request of message478 */479 int CClientServerMappingDistributed::computeBuffCountIndexGlobal(MPI_Request& requestRecv)480 {481 int flag, count = 0;482 MPI_Status status;483 484 MPI_Test(&requestRecv, &flag, &status);485 if (true == flag)486 {487 MPI_Get_count(&status, MPI_UNSIGNED_LONG, &count);488 }489 490 return count;491 }492 493 /*!494 Compute size of message containing server index495 \param[in] requestRecv request of message496 */497 int CClientServerMappingDistributed::computeBuffCountIndexServer(MPI_Request& requestRecv)498 {499 int flag, count = 0;500 MPI_Status status;501 502 MPI_Test(&requestRecv, &flag, &status);503 if (true == flag)504 {505 MPI_Get_count(&status, MPI_INT, &count);506 }507 508 return count;509 }510 511 /*!512 Reset all receiving request map and counter513 */514 void CClientServerMappingDistributed::resetReceivingRequestAndCount()515 {516 countIndexGlobal_ = countIndexServer_ = 0;517 requestRecvIndexGlobal_.clear();518 requestRecvIndexServer_.clear();519 indexGlobalBuffBegin_.clear();520 indexServerBuffBegin_.clear();521 }522 523 } -
XIOS/trunk/src/client_server_mapping_distributed.hpp
r759 r829 42 42 virtual ~CClientServerMappingDistributed(); 43 43 44 45 46 44 protected: 47 // Redistribute global index and server index among clients48 void computeDistributedServerIndex(const boost::unordered_map<size_t,int>& globalIndexOfServer,49 const MPI_Comm& clientIntraComm);50 51 // Send server index to clients52 void sendIndexServerToClients(int clientDestRank, std::vector<int>& indexServer,53 const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer);54 55 // Send global index to clients56 void sendIndexGlobalToClients(int clientDestRank, std::vector<size_t>& indexGlobal,57 const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal);58 59 // Verify sending request60 void testSendRequest(std::list<MPI_Request>& sendRequest);61 62 // Process request63 void processReceivedRequest(unsigned long* buffIndexGlobal, int* buffIndexServer, int count);64 65 // Probe and receive message of global index66 void probeIndexGlobalMessageFromClients(unsigned long* recvIndexGlobalBuff, int recvNbIndexCount);67 68 // Probe and receive message of server index69 void probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount);70 71 // Compute range of hashing72 void computeHashIndex();73 74 // Compute size of receiving buffer for global index75 int computeBuffCountIndexGlobal(MPI_Request& requestRecv);76 77 // Compute size of receiving buffer for server index78 int computeBuffCountIndexServer(MPI_Request& requestRecv);79 80 // Reset request map81 void resetReceivingRequestAndCount();82 83 protected:84 //! Mapping of global index to the corresponding server85 boost::unordered_map<size_t,int> globalIndexToServerMapping_;86 87 //! Bounds of hash index88 std::vector<size_t> indexClientHash_;89 90 //! Number of client91 int nbClient_;92 93 //! Rank of client94 int clientRank_;95 96 //! Counting of buffer for receiving global index97 int countIndexGlobal_;98 99 //! Counting of buffer for receiving server index100 int countIndexServer_;101 102 //! intracommuntion of clients103 MPI_Comm clientIntraComm_;104 105 //! Request returned by MPI_IRecv function about global index106 std::map<int, MPI_Request> requestRecvIndexGlobal_;107 108 //! Request returned by MPI_IRecv function about index of server109 std::map<int, MPI_Request> requestRecvIndexServer_;110 111 //! Mapping client rank and the beginning position of receiving buffer for message of global index from this client112 std::map<int, unsigned long*> indexGlobalBuffBegin_;113 114 //! Mapping client rank and the begining position of receiving buffer for message of server index from this client115 std::map<int, int*> indexServerBuffBegin_;116 117 //! Flag to specify whether data is distributed or not118 bool isDataDistributed_;119 120 // CClientClientDHTTemplate<int>* ccDHT_;121 45 CClientClientDHTInt* ccDHT_; 122 46 }; -
XIOS/trunk/src/mpi_tag.hpp
r821 r829 18 18 19 19 /* Tag for mpi communication to send and receive info of current grid source in grid transformation*/ 20 #define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_ INDEX 3220 #define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX 32 21 21 22 22 /* Tag for mpi communication to send and receive info of current grid source in grid transformation*/ 23 #define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT 33 23 #define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_LOCAL_INDEX 33 24 25 /* Tag for mpi communication to send and receive info of current grid source in grid transformation*/ 26 #define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT 34 27 28 /* Tag for mpi communication to send and receive info grid source and grid destination in transformation mapping*/ 29 #define MPI_TRANSFORMATION_MAPPING_INDEX 35 24 30 25 31 /* Tag for mpi communication to send and receive info of DOMAIN in domain interpolation*/ … … 32 38 #define MPI_DOMAIN_INTERPOLATION_WEIGHT 9 33 39 40 41 34 42 #endif -
XIOS/trunk/src/node/axis.cpp
r823 r829 433 433 CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer); 434 434 int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); 435 std::map<int, std::vector<size_t> >globalIndexAxisOnServer;435 CClientServerMapping::GlobalIndexMap globalIndexAxisOnServer; 436 436 if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* 437 437 { … … 472 472 } 473 473 474 std::map<int, std::vector<size_t> >::const_iterator it = globalIndexAxisOnServer.begin(),475 ite = globalIndexAxisOnServer.end();474 CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexAxisOnServer.begin(), 475 ite = globalIndexAxisOnServer.end(); 476 476 std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), 477 477 iteVec = (globalAxisZoom).end(); … … 505 505 if (!indSrv_.empty()) 506 506 { 507 std::map<int, vector<size_t> >::const_iterator itIndSrv = indSrv_.begin(), 508 iteIndSrv = indSrv_.end(); 507 509 connectedServerRank_.clear(); 508 for ( it = indSrv_.begin(); it != indSrv_.end(); ++it)509 connectedServerRank_.push_back(it ->first);510 for (; itIndSrv != iteIndSrv; ++itIndSrv) 511 connectedServerRank_.push_back(itIndSrv->first); 510 512 } 511 513 nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); -
XIOS/trunk/src/node/domain.cpp
r823 r829 1386 1386 client->intraComm); 1387 1387 clientServerMap->computeServerIndexMapping(globalIndexDomain); 1388 const std::map<int, std::vector<size_t> >& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer();1389 1390 std::map<int, std::vector<size_t> >::const_iterator it= globalIndexDomainOnServer.begin(),1391 ite = globalIndexDomainOnServer.end();1388 const CClientServerMapping::GlobalIndexMap& globalIndexDomainOnServer = clientServerMap->getGlobalIndexOnServer(); 1389 1390 CClientServerMapping::GlobalIndexMap::const_iterator it = globalIndexDomainOnServer.begin(), 1391 ite = globalIndexDomainOnServer.end(); 1392 1392 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 1393 1393 std::vector<int>::iterator itVec; -
XIOS/trunk/src/node/grid.cpp
r824 r829 457 457 458 458 clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex()); 459 const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer();459 const CClientServerMapping::GlobalIndexMap& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 460 460 461 461 const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 462 std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap;463 it bGlobalMap = itGlobalMap = globalIndexOnServer.begin();462 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 463 itGlobalMap = itbGlobalMap = globalIndexOnServer.begin(); 464 464 iteGlobalMap = globalIndexOnServer.end(); 465 465 … … 488 488 489 489 connectedServerRank_.clear(); 490 for ( std::map<int, std::vector<size_t> >::const_iterator it = globalIndexOnServer.begin(); it != globalIndexOnServer.end(); ++it) {491 connectedServerRank_.push_back(it ->first);490 for (itGlobalMap = itbGlobalMap; itGlobalMap != iteGlobalMap; ++itGlobalMap) { 491 connectedServerRank_.push_back(itGlobalMap->first); 492 492 } 493 493 … … 787 787 list<CMessage> listMsg; 788 788 list<CArray<size_t,1> > listOutIndex; 789 const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer();789 const CClientServerMapping::GlobalIndexMap& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 790 790 const std::vector<int>& localIndexSendToServer = clientDistribution_->getLocalDataIndexSendToServer(); 791 791 const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); … … 821 821 else 822 822 { 823 std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap;823 CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 824 824 itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 825 825 iteGlobalMap = globalIndexOnServer.end(); -
XIOS/trunk/src/transformation/axis_algorithm_inverse.cpp
r827 r829 72 72 std::map<int, std::vector<double> >& transWeight = this->transformationWeight_[0]; 73 73 74 std::map<size_t, std::vector<std::pair<size_t,double> > >globaIndexMapFromDestToSource;74 CTransformationMapping::DestinationIndexMap globaIndexMapFromDestToSource; 75 75 std::map<int, std::vector<int> >::const_iterator it = transMap.begin(), ite = transMap.end(); 76 int localIndex = 0; 76 77 for (; it != ite; ++it) 77 78 { 78 globaIndexMapFromDestToSource[it->first].push_back(make_pair((it->second)[0], (transWeight[it->first])[0])); 79 globaIndexMapFromDestToSource[it->first].push_back(make_pair(localIndex,make_pair((it->second)[0], (transWeight[it->first])[0]))); 80 ++localIndex; 79 81 } 80 82 81 83 transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 82 84 83 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();84 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();85 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 86 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 85 87 86 88 // Sending global index of original grid source 87 std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend,88 iteSend = globalIndexToSend.end();89 CTransformationMapping::SentIndexMap::const_iterator itbSend = globalIndexToSend.begin(), itSend, 90 iteSend = globalIndexToSend.end(); 89 91 int sendBuffSize = 0; 90 92 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); … … 99 101 { 100 102 int destRank = itSend->first; 101 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;103 const std::vector<std::pair<int,size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 102 104 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 103 105 for (int idx = 0; idx < (countSize); ++idx) 104 106 { 105 int index = globalIndexOfCurrentGridSourceToSend[idx] - ibeginSrc;107 int index = globalIndexOfCurrentGridSourceToSend[idx].first; 106 108 sendBuff[idx+currentBuffPosition] = (axisSrc_->value)(index); 107 109 } … … 112 114 113 115 // Receiving global index of grid source sending from current grid source 114 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv,115 116 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 117 iteRecv = globalIndexToReceive.end(); 116 118 int recvBuffSize = 0; 117 119 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); -
XIOS/trunk/src/transformation/axis_algorithm_transformation.cpp
r827 r829 49 49 const std::vector<int>& gridDestGlobalDim, 50 50 const std::vector<int>& gridSrcGlobalDim, 51 const std::vector<size_t>& globalIndexGridDestSendToServer,52 CArray<size_t,1>& globalIndexDestGrid,51 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 52 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 53 53 std::vector<std::vector<size_t> >& globalIndexSrcGrid) 54 54 { … … 72 72 } 73 73 74 std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, 75 iteArr = globalIndexGridDestSendToServer.end(); 74 GlobalLocalMap::const_iterator iteArr = globalLocalIndexDestSendToServerMap.end(), it; 76 75 77 76 while (idx < ssize) … … 111 110 } 112 111 113 if ( std::binary_search(itbArr, iteArr,globIndex)) ++realGlobalIndexSize;112 if (iteArr != globalLocalIndexDestSendToServerMap.find(globIndex)) ++realGlobalIndexSize; 114 113 ++idxLoop[0]; 115 114 ++idx; 116 115 } 117 116 118 if (global IndexDestGrid.numElements() != realGlobalIndexSize)119 global IndexDestGrid.resize(realGlobalIndexSize);117 if (globalLocalIndexDestMap.size() != realGlobalIndexSize) 118 globalLocalIndexDestMap.resize(realGlobalIndexSize); 120 119 121 120 if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); … … 162 161 } 163 162 164 if (std::binary_search(itbArr, iteArr, globIndex)) 163 it = globalLocalIndexDestSendToServerMap.find(globIndex); 164 if (iteArr != it) 165 165 { 166 global IndexDestGrid(realGlobalIndex) = globIndex;166 globalLocalIndexDestMap[realGlobalIndex] = (std::make_pair(it->first,it->second)); 167 167 for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) 168 168 { … … 183 183 ++idx; 184 184 } 185 186 187 188 // int globalDim = gridDestGlobalDim.size();189 //190 // std::vector<size_t> currentIndex(globalDim);191 // std::vector<int> gridAxisGlobalDim(globalDim);192 // std::vector<int> idxLoop(globalDim, 0);193 //194 // size_t ssize = 1, idx = 0, realGlobalIndexSize = 0;195 // for (int i = 0; i< globalDim; ++i)196 // {197 // if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1;198 // else gridAxisGlobalDim[i] = gridDestGlobalDim[i];199 // ssize *= gridAxisGlobalDim[i];200 // }201 //202 // std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,203 // iteArr = globalIndexGridDestSendToServer.end();204 //205 // while (idx < ssize)206 // {207 // for (int i = 0; i < globalDim-1; ++i)208 // {209 // if (idxLoop[i] == gridAxisGlobalDim[i])210 // {211 // idxLoop[i] = 0;212 // ++idxLoop[i+1];213 // }214 // }215 //216 // for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];217 // currentIndex[axisPositionInGrid] = axisDestGlobalIndex;218 //219 // size_t globIndex = currentIndex[0];220 // size_t mulDim = 1;221 // for (int k = 1; k < globalDim; ++k)222 // {223 // mulDim *= gridDestGlobalDim[k-1];224 // globIndex += (currentIndex[k])*mulDim;225 // }226 //227 // if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize;228 // ++idxLoop[0];229 // ++idx;230 // }231 //232 // if (globalIndexDestGrid.numElements() != realGlobalIndexSize)233 // globalIndexDestGrid.resize(realGlobalIndexSize);234 //235 // if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize);236 // for (int i = 0; i < globalIndexSrcGrid.size(); ++i)237 // if (globalIndexSrcGrid[i].size() != axisSrcGlobalIndex.size())238 // globalIndexSrcGrid[i].resize(axisSrcGlobalIndex.size());239 //240 // size_t realGlobalIndex = 0;241 // idx = 0;242 // idxLoop.assign(globalDim, 0);243 // while (idx < ssize)244 // {245 // for (int i = 0; i < globalDim-1; ++i)246 // {247 // if (idxLoop[i] == gridAxisGlobalDim[i])248 // {249 // idxLoop[i] = 0;250 // ++idxLoop[i+1];251 // }252 // }253 //254 // for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];255 // currentIndex[axisPositionInGrid] = axisDestGlobalIndex;256 //257 // size_t globIndex = currentIndex[0];258 // size_t mulDim = 1;259 // for (int k = 1; k < globalDim; ++k)260 // {261 // mulDim *= gridDestGlobalDim[k-1];262 // globIndex += (currentIndex[k])*mulDim;263 // }264 //265 // if (std::binary_search(itbArr, iteArr, globIndex))266 // {267 // globalIndexDestGrid(realGlobalIndex) = globIndex;268 // for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i)269 // {270 // currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i];271 // globIndex = currentIndex[0];272 // mulDim = 1;273 // for (int k = 1; k < globalDim; ++k)274 // {275 // mulDim *= gridDestGlobalDim[k-1];276 // globIndex += (currentIndex[k])*mulDim;277 // }278 // (globalIndexSrcGrid[realGlobalIndex])[i] = globIndex;279 // }280 // ++realGlobalIndex;281 // }282 //283 // ++idxLoop[0];284 // ++idx;285 // }286 185 } 287 186 } -
XIOS/trunk/src/transformation/axis_algorithm_transformation.hpp
r827 r829 33 33 const std::vector<int>& gridDestGlobalDim, 34 34 const std::vector<int>& gridSrcGlobalDim, 35 const std::vector<size_t>& globalIndexGridDestSendToServer,36 CArray<size_t,1>& globalIndexDestGrid,35 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 36 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 37 37 std::vector<std::vector<size_t> >& globalIndexSrcGrid); 38 38 -
XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp
r827 r829 417 417 418 418 domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp); 419 const std::map<int, std::vector<size_t> >& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer();419 const CClientServerMapping::GlobalIndexMap& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer(); 420 420 421 421 //Inform each client number of index they will receive … … 429 429 } 430 430 int sendBuffSize = 0; 431 std::map<int, std::vector<size_t> >::const_iterator itbMap = globalIndexInterpSendToClient.begin(), itMap,432 iteMap = globalIndexInterpSendToClient.end();431 CClientServerMapping::GlobalIndexMap::const_iterator itbMap = globalIndexInterpSendToClient.begin(), itMap, 432 iteMap = globalIndexInterpSendToClient.end(); 433 433 for (itMap = itbMap; itMap != iteMap; ++itMap) 434 434 { -
XIOS/trunk/src/transformation/domain_algorithm_transformation.cpp
r827 r829 42 42 const std::vector<int>& gridDestGlobalDim, 43 43 const std::vector<int>& gridSrcGlobalDim, 44 const std::vector<size_t>& globalIndexGridDestSendToServer,45 CArray<size_t,1>& globalIndexDestGrid,44 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 45 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 46 46 std::vector<std::vector<size_t> >& globalIndexSrcGrid) 47 47 { … … 79 79 for (int i = 0; i< numElement; ++i) ssize *= gridDomainGlobalDim[i]; 80 80 81 std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,82 iteArr = globalIndexGridDestSendToServer.end(); 81 GlobalLocalMap::const_iterator iteArr = globalLocalIndexDestSendToServerMap.end(), it; 82 83 83 idx = 0; 84 84 while (idx < ssize) … … 112 112 } 113 113 114 if ( std::binary_search(itbArr, iteArr,globIndex)) ++realGlobalIndexSize;114 if (iteArr != globalLocalIndexDestSendToServerMap.find(globIndex)) ++realGlobalIndexSize; 115 115 ++idxLoop[0]; 116 116 ++idx; 117 117 } 118 118 119 if (global IndexDestGrid.numElements() != realGlobalIndexSize)120 global IndexDestGrid.resize(realGlobalIndexSize);119 if (globalLocalIndexDestMap.size() != realGlobalIndexSize) 120 globalLocalIndexDestMap.resize(realGlobalIndexSize); 121 121 122 122 if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); … … 158 158 } 159 159 160 if (std::binary_search(itbArr, iteArr, globIndex)) 160 it = globalLocalIndexDestSendToServerMap.find(globIndex); 161 if (iteArr != it) 161 162 { 162 global IndexDestGrid(realGlobalIndex) = globIndex;163 globalLocalIndexDestMap[realGlobalIndex] = (std::make_pair(it->first,it->second)); 163 164 for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) 164 165 { -
XIOS/trunk/src/transformation/domain_algorithm_transformation.hpp
r827 r829 33 33 const std::vector<int>& gridDestGlobalDim, 34 34 const std::vector<int>& gridSrcGlobalDim, 35 const std::vector<size_t>& globalIndexGridDestSendToServer,36 CArray<size_t,1>& globalIndexDestGrid,35 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 36 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 37 37 std::vector<std::vector<size_t> >& globalIndexSrcGrid); 38 38 -
XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp
r827 r829 3 3 \author Ha NGUYEN 4 4 \since 14 May 2015 5 \date 2 9 June 20155 \date 21 Mars 2016 6 6 7 7 \brief Interface for all transformation algorithms. … … 23 23 \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed) 24 24 \param[in] globalIndexGridDestSendToServer global index of grid destination on the current client to send to server 25 \param[in] localIndexGridSendToServer local index of grid destination on the current client to send to server 25 26 \param[in/out] globaIndexWeightFromDestToSource mapping between transformed global index of grid destination 26 and the weighted value as longas global index from grid index source27 and the weighted value as well as global index from grid index source 27 28 */ 28 29 void CGenericAlgorithmTransformation::computeGlobalSourceIndex(int elementPositionInGrid, … … 30 31 const std::vector<int>& gridSrcGlobalDim, 31 32 const std::vector<size_t>& globalIndexGridDestSendToServer, 32 std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource) 33 const std::vector<int>& localIndexGridSendToServer, 34 DestinationIndexMap& globaIndexWeightFromDestToSource) 33 35 { 34 36 bool isTransPosEmpty = transformationPosition_.empty(); 35 std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); 36 std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); 37 boost::unordered_map<size_t,int> globalLocalIndexDestSendToServerMap; 38 size_t nbGlobalIndexDest = globalIndexGridDestSendToServer.size(); 39 for (size_t idx = 0; idx < nbGlobalIndexDest; ++idx) 40 { 41 globalLocalIndexDestSendToServerMap[globalIndexGridDestSendToServer[idx]] = localIndexGridSendToServer[idx]; 42 } 43 37 44 for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 38 45 { … … 51 58 52 59 std::vector<std::vector<size_t> > globalIndexSrcGrid; 53 CArray<size_t,1> globalIndexDestGrid; 54 // std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); 55 // std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); 60 std::vector<std::pair<size_t,int> > globalLocalIndexDest; 56 61 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 57 62 { 63 boost::unordered_map<size_t,int> globalLocalIndexDestMap; 58 64 if (!isTransPosEmpty) 59 65 { 60 66 this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first, 61 itTransMap->second,62 itTransPos->second,63 elementPositionInGrid,64 gridDestGlobalDim,65 gridSrcGlobalDim,66 vecGlobalIndexGridSendToServer,67 globalIndexDestGrid,68 globalIndexSrcGrid);67 itTransMap->second, 68 itTransPos->second, 69 elementPositionInGrid, 70 gridDestGlobalDim, 71 gridSrcGlobalDim, 72 globalLocalIndexDestSendToServerMap, 73 globalLocalIndexDest, 74 globalIndexSrcGrid); 69 75 ++itTransPos; 70 76 } … … 72 78 { 73 79 this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first, 74 itTransMap->second,75 emptyTransPos,76 elementPositionInGrid,77 gridDestGlobalDim,78 gridSrcGlobalDim,79 vecGlobalIndexGridSendToServer,80 globalIndexDestGrid,81 globalIndexSrcGrid);80 itTransMap->second, 81 emptyTransPos, 82 elementPositionInGrid, 83 gridDestGlobalDim, 84 gridSrcGlobalDim, 85 globalLocalIndexDestSendToServerMap, 86 globalLocalIndexDest, 87 globalIndexSrcGrid); 82 88 } 83 s ize_t globalIndexSize = globalIndexDestGrid.numElements();89 std::vector<std::pair<size_t,int> >::const_iterator it = globalLocalIndexDest.begin(), ite = globalLocalIndexDest.end(); 84 90 const std::vector<double>& currentVecWeight = itTransWeight->second; 85 for (size_t idx = 0; idx < globalIndexSize; ++idx) 91 92 for (size_t idx = 0; it != ite; ++it, ++idx) 86 93 { 87 size_t globalIndex = globalIndexDestGrid(idx); 88 for (int i = 0; i < globalIndexSrcGrid[idx].size(); ++i) 94 size_t srcGridSize = globalIndexSrcGrid[idx].size(); 95 globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize); 96 for (int i = 0; i < srcGridSize; ++i) 89 97 { 90 globaIndexWeightFromDestToSource[ globalIndex].push_back(make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]));98 globaIndexWeightFromDestToSource[(it->first)].push_back(make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]))); 91 99 } 92 100 } -
XIOS/trunk/src/transformation/generic_algorithm_transformation.hpp
r827 r829 22 22 { 23 23 public: 24 // Stupid global index map, it must be replaced by tuple 25 // 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; 27 protected: 28 typedef boost::unordered_map<size_t,int> GlobalLocalMap; 29 30 public: 24 31 CGenericAlgorithmTransformation(); 25 32 … … 30 37 const std::vector<int>& gridSrcGlobalDim, 31 38 const std::vector<size_t>& globalIndexGridDestSendToServer, 32 std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource); 39 const std::vector<int>& localIndexGridSendToServer, 40 DestinationIndexMap& globaIndexWeightFromDestToSource); 33 41 34 42 std::vector<StdString> getIdAuxInputs(); … … 46 54 \param[in] elementPositionInGrid position of the element in the grid (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) 47 55 \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the element on which transformation is performed) 48 \param[in] global IndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted49 \param[in/out] global IndexDestGridarray of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated56 \param[in] globalLocalIndexDestSendToServerMap pair of global index and local index of destination grid which are to be sent to server(s), this array is already acsending sorted 57 \param[in/out] globalLocalIndexDestMap array of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated 50 58 \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated 51 59 */ … … 56 64 const std::vector<int>& gridDestGlobalDim, 57 65 const std::vector<int>& gridSrcGlobalDim, 58 const std::vector<size_t>& globalIndexGridDestSendToServer,59 CArray<size_t,1>& globalIndexDestGrid,66 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 67 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 60 68 std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0; 61 69 -
XIOS/trunk/src/transformation/grid_transformation.cpp
r827 r829 19 19 #include "distribution_client.hpp" 20 20 #include "mpi_tag.hpp" 21 #include <boost/unordered_map.hpp> 21 22 22 23 namespace xios { … … 359 360 if (nbAlgos_ < 1) return; 360 361 if (!auxInputs_.empty() && !dynamicalTransformation_) { dynamicalTransformation_ = true; return; } 361 if (dynamicalTransformation_) GlobalIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map362 if (dynamicalTransformation_) DestinationIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map 362 363 363 364 CContext* context = CContext::getCurrent(); … … 374 375 ETranformationType transType = (it->second).first; 375 376 int transformationOrder = (it->second).second; 376 std::map<size_t, std::vector<std::pair<size_t,double> > >globaIndexWeightFromDestToSource;377 DestinationIndexMap globaIndexWeightFromDestToSource; 377 378 378 379 // First of all, select an algorithm … … 392 393 CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 393 394 const std::vector<size_t>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 395 const std::vector<int>& localIndexGridDestSendToServer = distributionClientDest.getLocalDataIndexSendToServer(); 394 396 395 397 // ComputeTransformation of global index of each element … … 401 403 gridSrcDimensionSize, 402 404 globalIndexGridDestSendToServer, 405 localIndexGridDestSendToServer, 403 406 globaIndexWeightFromDestToSource); 404 407 … … 446 449 iteArr = globalIndexOnClientDest.end(); 447 450 448 GlobalIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end();451 DestinationIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end(); 449 452 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 450 453 int maskIndexNum = 0; … … 453 456 if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 454 457 { 455 const std::vector<std::pair< size_t,double> >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr];458 const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr]; 456 459 for (int idx = 0; idx < vecIndex.size(); ++idx) 457 460 { 458 if (sfmax == vecIndex[idx].first)461 if (sfmax == (vecIndex[idx].second).first) 459 462 { 460 463 ++maskIndexNum; … … 471 474 if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 472 475 { 473 const std::vector<std::pair< size_t,double> >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr];476 const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr]; 474 477 for (int idx = 0; idx < vecIndex.size(); ++idx) 475 478 { 476 if (sfmax == vecIndex[idx].first)479 if (sfmax == (vecIndex[idx].second).first) 477 480 { 478 481 int localIdx = std::distance(itbArr, itArr); … … 493 496 the final grid destination 494 497 */ 495 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource)498 void CGridTransformation::computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource) 496 499 { 497 500 CContext* context = CContext::getCurrent(); … … 509 512 transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 510 513 511 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();512 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();514 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 515 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 513 516 514 517 // Sending global index of original grid source 515 std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend,516 iteSend = globalIndexToSend.end();518 CTransformationMapping::SentIndexMap::const_iterator itbSend = globalIndexToSend.begin(), itSend, 519 iteSend = globalIndexToSend.end(); 517 520 int sendBuffSize = 0; 518 521 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); … … 526 529 for (StdSize idx = 0; idx < sendBuffSize; ++idx) sendBuff[idx] = NumTraits<Scalar>::sfmax(); 527 530 528 std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGrid , requestsWeightGrid;529 GlobalIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end();531 std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGridGlobalIndex, requestsOriginalGridLocalIndex, requestsWeightGrid; 532 DestinationIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end(); 530 533 531 534 // Only send global index of original source corresponding to non-masked index … … 536 539 { 537 540 int destRank = itSend->first; 538 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;541 const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 539 542 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 540 543 size_t countBlock = 0; 541 544 for (int idx = 0; idx < countSize; ++idx) 542 545 { 543 size_t index = globalIndexOfCurrentGridSourceToSend[idx] ;544 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) // searchCurrentSrc.search(itbIndex, iteIndex, globalIndexOfCurrentGridSourceToSend[idx], itIndex))546 size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 547 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 545 548 { 546 549 globalIndexOriginalSrcSendBuffSize += currentGridIndexToOriginalGridIndex_[index].size() + 1; // 1 for number of elements in this block … … 555 558 } 556 559 557 Scalar* sendOriginal IndexBuff, *currentOriginalIndexSendBuff;558 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginal IndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize];560 Scalar* sendOriginalGlobalIndexBuff, *currentOriginalGlobalIndexSendBuff; 561 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize]; 559 562 double* sendOriginalWeightBuff, *currentOriginalWeightSendBuff; 560 563 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalWeightBuff = new double [globalIndexOriginalSrcSendBuffSize]; … … 564 567 { 565 568 int destRank = itSend->first; 566 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;569 const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 567 570 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 568 571 int increaseStep = 0; 569 572 for (int idx = 0; idx < countSize; ++idx) 570 573 { 571 size_t index = globalIndexOfCurrentGridSourceToSend[idx] ;574 size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 572 575 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 573 576 { 574 577 size_t vectorSize = currentGridIndexToOriginalGridIndex_[index].size(); 575 sendOriginal IndexBuff[currentBuffPosition+increaseStep] = vectorSize;578 sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep] = vectorSize; 576 579 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (double)vectorSize; 577 const std::vector<std::pair< size_t,double> >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index];580 const std::vector<std::pair<int, std::pair<size_t,double> > >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index]; 578 581 for (size_t i = 0; i < vectorSize; ++i) 579 582 { 580 583 ++increaseStep; 581 sendOriginal IndexBuff[currentBuffPosition+increaseStep] = indexWeightPair[i].first;582 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = indexWeightPair[i].second;584 sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).first; 585 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).second; 583 586 } 584 587 ++increaseStep; … … 586 589 } 587 590 588 currentOriginal IndexSendBuff = sendOriginalIndexBuff + currentBuffPosition;591 currentOriginalGlobalIndexSendBuff = sendOriginalGlobalIndexBuff + currentBuffPosition; 589 592 currentOriginalWeightSendBuff = sendOriginalWeightBuff + currentBuffPosition; 590 593 if (0 != increaseStep) 591 594 { 592 MPI_Isend(currentOriginalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX, client->intraComm, &requestsOriginalGrid[destRank]); 593 MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]); 595 MPI_Isend(currentOriginalGlobalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank, 596 MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &requestsOriginalGridGlobalIndex[destRank]); 597 MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank, 598 MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]); 594 599 } 595 600 currentBuffPosition += increaseStep; … … 598 603 599 604 // Receiving global index of grid source sending from current grid source 600 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv,601 605 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 606 iteRecv = globalIndexToReceive.end(); 602 607 int recvBuffSize = 0; 603 608 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); … … 623 628 } 624 629 625 Scalar* recvOriginal IndexBuff, *currentOriginalIndexRecvBuff;626 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginal IndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize];630 Scalar* recvOriginalGlobalIndexBuff, *currentOriginalGlobalIndexRecvBuff; 631 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize]; 627 632 double* recvOriginalWeightBuff, *currentOriginalWeightRecvBuff; 628 633 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalWeightBuff = new double [globalIndexOriginalSrcRecvBuffSize]; … … 633 638 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 634 639 { 635 MPI_Status status Index, statusWeight;640 MPI_Status statusGlobalIndex, statusLocalIndex, statusWeight; 636 641 int srcRank = itRecv->first; 637 642 countBlock = countBlockMap[srcRank]; 638 currentOriginal IndexRecvBuff = recvOriginalIndexBuff + currentBuffPosition;643 currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff + currentBuffPosition; 639 644 currentOriginalWeightRecvBuff = recvOriginalWeightBuff + currentBuffPosition; 640 645 if (0 != countBlock) 641 646 { 642 MPI_Recv(currentOriginal IndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX, client->intraComm, &statusIndex);647 MPI_Recv(currentOriginalGlobalIndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &statusGlobalIndex); 643 648 MPI_Recv(currentOriginalWeightRecvBuff, countBlock, MPI_DOUBLE, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &statusWeight); 644 649 } … … 649 654 // The way to process masked index needs discussing 650 655 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 651 GlobalIndexMap currentToOriginalTmp;656 DestinationIndexMap currentToOriginalTmp; 652 657 653 658 currentRecvBuffPosition = 0; 654 659 currentRecvBuff = recvBuff; 655 currentOriginal IndexRecvBuff = recvOriginalIndexBuff;660 currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff; 656 661 currentOriginalWeightRecvBuff = recvOriginalWeightBuff; 657 662 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) … … 669 674 if (0 != countBlockRank) 670 675 { 671 countBlock = *(currentOriginal IndexRecvBuff+currentRecvBuffPosition);676 countBlock = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition); 672 677 for (int i = 0; i < ssize; ++i) 673 678 { 674 679 for (int j = 0; j < countBlock; ++j) 675 680 { 676 size_t globalOriginalIndex = *(currentOriginalIndexRecvBuff+currentRecvBuffPosition+j+1); 677 double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second; 678 currentToOriginalTmp[(itRecv->second)[idx][i].first].push_back(make_pair(globalOriginalIndex,weightGlobal)); 681 size_t globalOriginalIndex = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition+j+1); 682 int currentGridLocalIndex = (itRecv->second)[idx][i].first; 683 double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second.second; 684 currentToOriginalTmp[(itRecv->second)[idx][i].second.first].push_back(make_pair(currentGridLocalIndex,make_pair(globalOriginalIndex,weightGlobal))); 679 685 } 680 686 } … … 697 703 for (itRequest = requestsCurrentGrid.begin(); itRequest != requestsCurrentGrid.end(); ++itRequest) 698 704 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 699 for (itRequest = requestsOriginalGrid .begin(); itRequest != requestsOriginalGrid.end(); ++itRequest)705 for (itRequest = requestsOriginalGridGlobalIndex.begin(); itRequest != requestsOriginalGridGlobalIndex.end(); ++itRequest) 700 706 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 701 707 for (itRequest = requestsWeightGrid.begin(); itRequest != requestsWeightGrid.end(); ++itRequest) … … 704 710 if (0 != sendBuffSize) delete [] sendBuff; 705 711 if (0 != recvBuffSize) delete [] recvBuff; 706 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginal IndexBuff;712 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalGlobalIndexBuff; 707 713 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalWeightBuff; 708 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginal IndexBuff;714 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalGlobalIndexBuff; 709 715 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalWeightBuff; 710 716 } … … 724 730 transformationMap.computeTransformationMapping(currentGridIndexToOriginalGridIndex_); 725 731 726 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();727 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();728 729 CDistributionClient distributionClientDest(client->clientRank, gridDestination_);730 CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_);731 732 const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer();733 const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer();734 735 std::vector<size_t>::const_iterator itbArr, itArr, iteArr;736 std::vector<int>::const_iterator itIndex, itbIndex, iteIndex;737 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv;738 739 std::vector<int> permutIndex;740 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch;741 742 // Find out local index on grid destination (received)743 XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex);744 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientDest, permutIndex);745 itbIndex = permutIndex.begin();746 iteIndex = permutIndex.end();747 BinarySearch searchClientDest(globalIndexOnClientDest);732 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 733 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 734 735 // CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 736 // CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 737 // 738 // const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 739 // const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); 740 741 // std::vector<size_t>::const_iterator itbArr, itArr, iteArr; 742 // std::vector<int>::const_iterator itIndex, itbIndex, iteIndex; 743 CTransformationMapping::ReceivedIndexMap::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 744 745 // std::vector<int> permutIndex; 746 // typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 747 // 748 // // Find out local index on grid destination (received) 749 // XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex); 750 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientDest, permutIndex); 751 // itbIndex = permutIndex.begin(); 752 // iteIndex = permutIndex.end(); 753 // BinarySearch searchClientDest(globalIndexOnClientDest); 748 754 itbMapRecv = globalIndexToReceive.begin(); 749 755 iteMapRecv = globalIndexToReceive.end(); … … 756 762 { 757 763 int vecSize = ((itMapRecv->second)[i]).size(); 758 std::vector<std::pair<int,double> > tmpVec;764 // std::vector<std::pair<int,double> > tmpVec; 759 765 for (int idx = 0; idx < vecSize; ++idx) 760 766 { 761 size_t globalIndex = (itMapRecv->second)[i][idx].first; 762 double weight = (itMapRecv->second)[i][idx].second; 763 if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 764 { 765 tmpVec.push_back(make_pair(*itIndex, weight)); 766 } 767 const std::pair<int, std::pair<size_t,double> >& tmpPair = (itMapRecv->second)[i][idx]; 768 localIndexToReceiveOnGridDest_[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second)); 769 // size_t globalIndex = (itMapRecv->second)[i][idx].first; 770 // double weight = (itMapRecv->second)[i][idx].second; 771 // if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 772 // { 773 // tmpVec.push_back(make_pair(*itIndex, weight)); 774 // } 767 775 } 768 localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec;776 // localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec; 769 777 } 770 778 } 771 779 772 780 // Find out local index on grid source (to send) 773 std::map<int,std::vector<size_t> >::const_iterator itbMap, itMap, iteMap;774 XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex);775 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientSrc, permutIndex);776 itbIndex = permutIndex.begin();777 iteIndex = permutIndex.end();778 BinarySearch searchClientSrc(globalIndexOnClientSrc);781 CTransformationMapping::SentIndexMap::const_iterator itbMap, itMap, iteMap; 782 // XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex); 783 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientSrc, permutIndex); 784 // itbIndex = permutIndex.begin(); 785 // iteIndex = permutIndex.end(); 786 // BinarySearch searchClientSrc(globalIndexOnClientSrc); 779 787 itbMap = globalIndexToSend.begin(); 780 788 iteMap = globalIndexToSend.end(); … … 786 794 for (int idx = 0; idx < vecSize; ++idx) 787 795 { 788 if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex))789 {790 localIndexToSendFromGridSource_[destRank](idx) = *itIndex;791 }796 // if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex)) 797 // { 798 localIndexToSendFromGridSource_[destRank](idx) = itMap->second[idx].first; //*itIndex; 799 // } 792 800 } 793 801 } -
XIOS/trunk/src/transformation/grid_transformation.hpp
r827 r829 35 35 public: 36 36 typedef std::list<std::pair<int,std::pair<ETranformationType,int> > > ListAlgoType; 37 typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 37 38 38 39 public: … … 63 64 void setUpGrid(int elementPositionInGrid, ETranformationType transType, int nbTransformation); 64 65 void computeFinalTransformationMapping(); 65 void computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource);66 void computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource); 66 67 void updateFinalGridDestination(); 67 68 bool isSpecialTransformation(ETranformationType transType); … … 84 85 int nbAlgos_; 85 86 86 typedef std::map<size_t, std::vector<std::pair<size_t,double> > > GlobalIndexMap;87 88 87 // true if domain algorithm and false if axis algorithm (can be replaced by tuple with listAlgos_ 89 88 std::vector<bool> algoTypes_; … … 105 104 106 105 //! (Grid) Global index of grid source 107 GlobalIndexMap currentGridIndexToOriginalGridIndex_;106 DestinationIndexMap currentGridIndexToOriginalGridIndex_; 108 107 109 108 std::vector<CGrid*> tempGrids_; -
XIOS/trunk/src/transformation/transformation_mapping.cpp
r668 r829 13 13 #include "context_client.hpp" 14 14 #include "distribution_client.hpp" 15 #include "client_client_dht_template.hpp" 16 #include "dht_data_types.hpp" 17 #include "mpi_tag.hpp" 15 18 16 19 namespace xios { … … 26 29 27 30 const std::vector<size_t>& globalIndexGridSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 28 boost::unordered_map<size_t,int> globalIndexOfServer; 31 const std::vector<int>& localIndexGridSrc = distributionClientSrc.getLocalDataIndexSendToServer(); 32 33 // Mapping of global index and pair containing rank and local index 34 CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfServer; 29 35 int globalIndexSize = globalIndexGridSrc.size(); 36 PairIntInt pii; 30 37 for (int idx = 0; idx < globalIndexSize; ++idx) 31 38 { 32 globalIndexOfServer[globalIndexGridSrc[idx]] = clientRank; 33 } 34 35 gridIndexClientClientMapping_ = new CClientServerMappingDistributed(globalIndexOfServer, 36 client->intraComm, 37 true); 39 pii.first = clientRank; 40 pii.second = localIndexGridSrc[idx]; 41 globalIndexOfServer[globalIndexGridSrc[idx]] = pii; //std::make_pair(clientRank, localIndexGridSrc[idx]); 42 } 43 44 gridIndexClientClientMapping_ = new CClientClientDHTPairIntInt(globalIndexOfServer, 45 client->intraComm, 46 true); 38 47 } 39 48 … … 48 57 int ibeginSrc = source->begin.getValue(); 49 58 50 boost::unordered_map<size_t,int> globalIndexOfAxisSource; 59 CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfAxisSource; 60 PairIntInt pii; 51 61 for (int idx = 0; idx < niSrc; ++idx) 52 62 { 53 globalIndexOfAxisSource[idx+ibeginSrc] = clientRank; 54 } 55 56 gridIndexClientClientMapping_ = new CClientServerMappingDistributed(globalIndexOfAxisSource, 57 client->intraComm, 58 true); 63 pii.first = clientRank; 64 pii.second = idx; 65 globalIndexOfAxisSource[idx+ibeginSrc] = pii; //std::make_pair(clientRank,idx); 66 } 67 68 gridIndexClientClientMapping_ = new CClientClientDHTPairIntInt(globalIndexOfAxisSource, 69 client->intraComm, 70 true); 59 71 } 60 72 … … 71 83 \param [in] globaIndexWeightFromDestToSource mapping representing the transformations 72 84 */ 73 void CTransformationMapping::computeTransformationMapping(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource)85 void CTransformationMapping::computeTransformationMapping(const DestinationIndexMap& globaIndexWeightFromDestToSource) 74 86 { 75 87 CContext* context = CContext::getCurrent(); 76 88 CContextClient* client=context->client; 77 89 78 std::map<size_t, std::vector<std::pair<size_t,double> > >::const_iterator itbMap = globaIndexWeightFromDestToSource.begin(), itMap,79 90 DestinationIndexMap::const_iterator itbMap = globaIndexWeightFromDestToSource.begin(), itMap, 91 iteMap = globaIndexWeightFromDestToSource.end(); 80 92 81 93 // Not only one index on grid destination can demande two indexes from grid source 82 94 // but an index on grid source has to be sent to two indexes of grid destination 83 std::map<size_t, std::vector<std::pair<size_t,double> > > globalIndexMapFromSrcToDest; 84 std::vector<std::pair<size_t,double> >::const_iterator itbVecPair, itVecPair, iteVecPair; 95 DestinationIndexMap globalIndexMapFromSrcToDest; 96 boost::unordered_map<size_t, int> nbGlobalIndexMapFromSrcToDest; 97 std::vector<std::pair<int, std::pair<size_t,double> > >::const_iterator itbVecPair, itVecPair, iteVecPair; 85 98 for (itMap = itbMap; itMap != iteMap; ++itMap) 86 99 { … … 89 102 for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 90 103 { 91 globalIndexMapFromSrcToDest[itVecPair->first].push_back(std::make_pair(itMap->first, itVecPair->second)); 104 ++nbGlobalIndexMapFromSrcToDest[(itVecPair->second).first]; 105 } 106 } 107 108 for (boost::unordered_map<size_t, int>::const_iterator it = nbGlobalIndexMapFromSrcToDest.begin(); 109 it != nbGlobalIndexMapFromSrcToDest.end(); ++it) 110 { 111 globalIndexMapFromSrcToDest[it->first].reserve(it->second); 112 } 113 114 for (itMap = itbMap; itMap != iteMap; ++itMap) 115 { 116 itbVecPair = (itMap->second).begin(); 117 iteVecPair = (itMap->second).end(); 118 for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 119 { 120 globalIndexMapFromSrcToDest[(itVecPair->second).first].push_back(std::make_pair(itVecPair->first, std::make_pair(itMap->first, (itVecPair->second).second))); 92 121 } 93 122 } … … 95 124 // All global indexes of a client on grid destination 96 125 CArray<size_t,1> globalIndexMap(globalIndexMapFromSrcToDest.size()); 97 itbMap = globalIndexMapFromSrcToDest.begin();98 iteMap= globalIndexMapFromSrcToDest.end();126 DestinationIndexMap::const_iterator itbMapBoost = globalIndexMapFromSrcToDest.begin(), itMapBoost; 127 DestinationIndexMap::const_iterator iteMapBoost = globalIndexMapFromSrcToDest.end(); 99 128 int idx = 0; 100 for (itMap = itbMap; itMap != iteMap; ++itMap)101 { 102 globalIndexMap(idx) = itMap ->first;129 for (itMapBoost = itbMapBoost; itMapBoost != iteMapBoost; ++itMapBoost) 130 { 131 globalIndexMap(idx) = itMapBoost->first; 103 132 ++idx; 104 133 } 105 134 106 135 // Find out on which clients the necessary indexes of grid source are. 107 gridIndexClientClientMapping_->compute ServerIndexMapping(globalIndexMap);108 const std::map<int, std::vector<size_t> >& globalIndexSentFromGridSource = gridIndexClientClientMapping_->getGlobalIndexOnServer();109 std::map<int, std::vector<size_t> >::const_iterator itbMapSrc = globalIndexSentFromGridSource.begin(), itMapSrc,110 iteMapSrc = globalIndexSentFromGridSource.end();136 gridIndexClientClientMapping_->computeIndexInfoMapping(globalIndexMap); 137 const CClientClientDHTPairIntInt::Index2InfoTypeMap& globalIndexSentFromGridSource = gridIndexClientClientMapping_->getInfoIndexMap(); 138 CClientClientDHTPairIntInt::Index2InfoTypeMap::const_iterator itbMapSrc = globalIndexSentFromGridSource.begin(), itMapSrc, 139 iteMapSrc = globalIndexSentFromGridSource.end(); 111 140 std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 141 // Inform client about the destination to which it needs to send global indexes 142 int nbClient = client->clientSize; 143 std::vector<int> sendNbClientBuff(nbClient,0); 144 std::vector<int> recvNbClientBuff(nbClient,0); 145 std::vector<int> sendIndexBuff(nbClient,0); 146 std::vector<int> recvIndexBuff(nbClient,0); 147 boost::unordered_map<int,std::vector<size_t> > sendIndexMap; 112 148 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) 113 149 { 114 int sourceRank = itMapSrc->first; 115 itbVec = (itMapSrc->second).begin(); 116 iteVec = (itMapSrc->second).end(); 117 for (itVec = itbVec; itVec != iteVec; ++itVec) 118 { 119 (globalIndexReceivedOnGridDestMapping_[sourceRank]).push_back(globalIndexMapFromSrcToDest[*itVec]); 120 } 121 } 122 123 // Inform client about the destination to which it needs to send global indexes 124 int nbClient = client->clientSize; 125 int* sendBuff = new int[nbClient]; 126 int* recvBuff = new int[nbClient]; 127 for (int i = 0; i < nbClient; ++i) sendBuff[i] = 0; 128 129 // First of all, inform the number of destination a client needs to send global index 130 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) sendBuff[itMapSrc->first] = 1; 131 MPI_Allreduce(sendBuff, recvBuff, nbClient, MPI_INT, MPI_SUM, client->intraComm); 132 int numClientToReceive = recvBuff[client->clientRank]; 150 int sourceRank = (itMapSrc->second).first; 151 (globalIndexReceivedOnGridDestMapping_[sourceRank]).push_back(globalIndexMapFromSrcToDest[itMapSrc->first]); 152 sendIndexMap[sourceRank].push_back((itMapSrc->second).second); 153 sendIndexMap[sourceRank].push_back(itMapSrc->first); 154 sendNbClientBuff[sourceRank] = 1; 155 ++sendIndexBuff[sourceRank]; 156 } 157 158 MPI_Allreduce(&sendNbClientBuff[0], &recvNbClientBuff[0], nbClient, MPI_INT, MPI_SUM, client->intraComm); 159 int numClientToReceive = recvNbClientBuff[client->clientRank]; 133 160 134 161 // Then specify the size of receiving buffer, because we use synch send/receive so only necessary to know maximum size 135 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) sendBuff[itMapSrc->first] = (itMapSrc->second).size(); 136 MPI_Allreduce(sendBuff, recvBuff, nbClient, MPI_INT, MPI_MAX, client->intraComm); 137 138 int buffSize = recvBuff[client->clientRank]; 162 MPI_Allreduce(&sendIndexBuff[0], &recvIndexBuff[0], nbClient, MPI_INT, MPI_MAX, client->intraComm); 163 int buffSize = 2*recvIndexBuff[client->clientRank]; // we send global as well as local index 139 164 unsigned long* recvBuffGlobalIndex; 140 165 if (0 != buffSize) recvBuffGlobalIndex = new unsigned long [buffSize]; … … 143 168 144 169 // Inform all "source clients" about index that they need to send 145 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) 146 { 147 unsigned long* sendPtr = const_cast<unsigned long*>(&(itMapSrc->second)[0]); 170 boost::unordered_map<int,std::vector<size_t> >::const_iterator itSendIndex = sendIndexMap.begin(), 171 iteSendIndex= sendIndexMap.end(); 172 for (; itSendIndex != iteSendIndex; ++itSendIndex) 173 { 174 unsigned long* sendPtr = const_cast<unsigned long*>(&(itSendIndex->second)[0]); 148 175 MPI_Isend(sendPtr, 149 (it MapSrc->second).size(),176 (itSendIndex->second).size(), 150 177 MPI_UNSIGNED_LONG, 151 itMapSrc->first,152 11,178 (itSendIndex->first), 179 MPI_TRANSFORMATION_MAPPING_INDEX, 153 180 client->intraComm, 154 &requests[ itMapSrc->first]);181 &requests[(itSendIndex->first)]); 155 182 } 156 183 … … 165 192 MPI_UNSIGNED_LONG, 166 193 MPI_ANY_SOURCE, 167 11,194 MPI_TRANSFORMATION_MAPPING_INDEX, 168 195 client->intraComm, 169 196 &status); … … 171 198 MPI_Get_count(&status, MPI_UNSIGNED_LONG, &countBuff); 172 199 int clientDestRank = status.MPI_SOURCE; 173 for (int idx = 0; idx < countBuff; ++idx)200 for (int idx = 0; idx < countBuff; idx += 2) 174 201 { 175 globalIndexSendToGridDestMapping_[clientDestRank].push_back( recvBuffGlobalIndex[idx]);202 globalIndexSendToGridDestMapping_[clientDestRank].push_back(std::make_pair<int,size_t>(recvBuffGlobalIndex[idx], recvBuffGlobalIndex[idx+1])); 176 203 } 177 204 ++numClientReceived; … … 182 209 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 183 210 184 delete [] sendBuff;185 delete [] recvBuff;186 211 if (0 != buffSize) delete [] recvBuffGlobalIndex; 187 212 } … … 192 217 \return global index mapping to receive on grid destination 193 218 */ 194 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& CTransformationMapping::getGlobalIndexReceivedOnGridDestMapping() const219 const CTransformationMapping::ReceivedIndexMap& CTransformationMapping::getGlobalIndexReceivedOnGridDestMapping() const 195 220 { 196 221 return globalIndexReceivedOnGridDestMapping_; … … 202 227 \return global index mapping to send on grid source 203 228 */ 204 const std::map<int,std::vector<size_t> >& CTransformationMapping::getGlobalIndexSendToGridDestMapping() const229 const CTransformationMapping::SentIndexMap& CTransformationMapping::getGlobalIndexSendToGridDestMapping() const 205 230 { 206 231 return globalIndexSendToGridDestMapping_; -
XIOS/trunk/src/transformation/transformation_mapping.hpp
r630 r829 28 28 { 29 29 public: 30 typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 31 typedef boost::unordered_map<int,std::vector<std::vector<std::pair<int, std::pair<size_t,double> > > > > ReceivedIndexMap; 32 typedef boost::unordered_map<int,std::vector<std::pair<int, size_t> > > SentIndexMap; 33 34 public: 30 35 /** Default constructor */ 31 36 CTransformationMapping(CGrid* destination, CGrid* source); … … 34 39 ~CTransformationMapping(); 35 40 36 void computeTransformationMapping(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource);37 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& getGlobalIndexReceivedOnGridDestMapping() const;38 const std::map<int,std::vector<size_t> >& getGlobalIndexSendToGridDestMapping() const;41 void computeTransformationMapping(const DestinationIndexMap& globaIndexMapFromDestToSource); 42 const ReceivedIndexMap& getGlobalIndexReceivedOnGridDestMapping() const; 43 const SentIndexMap& getGlobalIndexSendToGridDestMapping() const; 39 44 40 45 protected: … … 43 48 44 49 //! Global index mapping of grid source and grid destination between two clients 45 CClient ServerMappingDistributed* gridIndexClientClientMapping_;50 CClientClientDHTPairIntInt* gridIndexClientClientMapping_; 46 51 47 52 //! Mapping of client rank of grid source and global index received in grid destination 48 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >globalIndexReceivedOnGridDestMapping_;53 ReceivedIndexMap globalIndexReceivedOnGridDestMapping_; 49 54 50 55 //! Mapping of client rank of grid destination and global index to send from grid source 51 std::map<int,std::vector<size_t> >globalIndexSendToGridDestMapping_;56 SentIndexMap globalIndexSendToGridDestMapping_; 52 57 }; 53 58
Note: See TracChangeset
for help on using the changeset viewer.