Changeset 829


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

Refactoring transformation code

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

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

Location:
XIOS/trunk/src
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/client_client_dht_decl.cpp

    r721 r829  
    1313 
    1414template class CClientClientDHTTemplate<int>; 
     15template class CClientClientDHTTemplate<PairIntInt>; 
    1516 
    1617} 
  • XIOS/trunk/src/client_client_dht_template.hpp

    r727 r829  
    1616#include "policy.hpp" 
    1717#include <boost/unordered_map.hpp> 
     18//#include "utils.hpp" 
     19#include "dht_data_types.hpp" 
    1820 
    1921namespace xios 
     
    3335    typedef T InfoType; 
    3436    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; 
    3539 
    3640  public: 
    3741    /** Default constructor */ 
    38     CClientClientDHTTemplate(const boost::unordered_map<size_t,T>& indexInfoInitMap, 
     42    CClientClientDHTTemplate(const Index2InfoTypeMap& indexInfoInitMap, 
    3943                             const MPI_Comm& clientIntraComm, 
    4044                             int hierarLvl = 2); 
     
    4246    void computeIndexInfoMapping(const CArray<size_t,1>& indices); 
    4347 
    44     const std::map<T, std::vector<size_t> >& getInfoIndexMap() const {return indexGlobalOnServer_; } 
     48    const Index2InfoTypeMap& getInfoIndexMap() const {return infoIndexMapping_; } 
    4549 
    4650    /** Default destructor */ 
     
    4953  protected: 
    5054    // Redistribute index and info among clients 
    51     void computeDistributedIndex(const boost::unordered_map<size_t,T>& indexInfoInitMap, 
     55    void computeDistributedIndex(const Index2InfoTypeMap& indexInfoInitMap, 
    5256                                 const MPI_Comm& intraCommLevel, 
    5357                                 int level); 
     
    6771                                      const MPI_Comm& intraComm); 
    6872 
    69     void probeInfoMessageFromClients(InfoType* recvIndexServerBuff, 
     73    void probeInfoMessageFromClients(unsigned char* recvIndexServerBuff, 
    7074                                     const int recvNbIndexCount, 
    7175                                     int& countIndexServer, 
    72                                      std::map<int, InfoType*>& indexServerBuffBegin, 
     76                                     std::map<int, unsigned char*>& indexServerBuffBegin, 
    7377                                     std::map<int, MPI_Request>& requestRecvIndexServer, 
    7478                                     const MPI_Comm& intraComm); 
     
    9397  protected: 
    9498    //! Mapping of global index to the corresponding client 
    95     boost::unordered_map<size_t,InfoType> index2InfoMapping_; 
     99    Index2InfoTypeMap index2InfoMapping_; 
    96100 
    97101    //! 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_; 
    99103 
    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_; 
    102106 
    103107    //! intracommuntion of clients 
     
    109113 
    110114typedef CClientClientDHTTemplate<int> CClientClientDHTInt; 
     115typedef CClientClientDHTTemplate<PairIntInt> CClientClientDHTPairIntInt; 
    111116 
    112117} // namespace xios 
  • XIOS/trunk/src/client_client_dht_template_impl.hpp

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

    r569 r829  
    1212 
    1313CClientServerMapping::CClientServerMapping() 
    14   : indexGlobalOnServer_(), localIndexSend2Server_(), connectedClients_() 
     14  : indexGlobalOnServer_(), connectedClients_() //, localIndexSend2Server_() 
    1515{ 
    1616} 
     
    2020} 
    2121 
    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 } 
     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//} 
    3232 
    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 } 
     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//} 
    6969 
    7070/*! 
     
    134134} 
    135135 
    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 std::map<int, std::vector<int> >& CClientServerMapping::getLocalIndexSendToServer() const 
    141 { 
    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//} 
    144144 
    145145/*! 
     
    149149  \return mapping of server rank and its global index. 
    150150*/ 
    151 const std::map<int, std::vector<size_t> >& CClientServerMapping::getGlobalIndexOnServer() const 
     151const CClientServerMapping::GlobalIndexMap& CClientServerMapping::getGlobalIndexOnServer() const 
    152152{ 
    153153  return indexGlobalOnServer_; 
  • XIOS/trunk/src/client_server_mapping.hpp

    r598 r829  
    1313#include "array_new.hpp" 
    1414#include "mpi.hpp" 
     15#include <boost/unordered_map.hpp> 
    1516 
    1617namespace xios { 
     
    2324class CClientServerMapping 
    2425{ 
     26public: 
     27  typedef boost::unordered_map<int, std::vector<size_t> > GlobalIndexMap; 
     28  typedef std::map<int, std::vector<int> > LocalIndexMap; 
    2529  public: 
    2630    /** Default constructor */ 
     
    3337    virtual void computeServerIndexMapping(const CArray<size_t,1>& globalIndexOnClient) = 0; 
    3438 
    35 //    // In case of computing local index on client sent to server 
     39//    // Simple case, global index on client and index on servers 
    3640//    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); 
    4242 
    4343    static std::map<int,int> computeConnectedClients(int nbServer, int nbClient, 
     
    4545                                                     const std::vector<int>& connectedServerRank); 
    4646 
    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; 
    4949 
    5050  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); 
    5454 
    5555  protected: 
    5656    //! Global index of data on SERVER, which are calculated by client(s) 
    57     std::map<int, std::vector<size_t> > indexGlobalOnServer_; 
     57    GlobalIndexMap indexGlobalOnServer_; 
    5858 
    5959    //! 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_; 
    6161 
    6262    //!< Number of clients connected to a server 
  • XIOS/trunk/src/client_server_mapping_distributed.cpp

    r721 r829  
    33   \author Ha NGUYEN 
    44   \since 27 Feb 2015 
    5    \date 06 Oct 2015 
     5   \date 16 Mars 2016 
    66 
    77   \brief Mapping between index client and server. 
     
    1919CClientServerMappingDistributed::CClientServerMappingDistributed(const boost::unordered_map<size_t,int>& globalIndexOfServer, 
    2020                                                                 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) 
    2422{ 
    25   clientIntraComm_ = clientIntraComm; 
    26   MPI_Comm_size(clientIntraComm,&(nbClient_)); 
    27   MPI_Comm_rank(clientIntraComm,&clientRank_); 
    28   computeHashIndex(); 
    29  
    3023  ccDHT_ = new CClientClientDHTInt(globalIndexOfServer, 
    3124                                   clientIntraComm, 
    3225                                   isDataDistributed); 
    33  
    34 //  computeDistributedServerIndex(globalIndexOfServer, clientIntraComm); 
    3526} 
    3627 
     
    4738{ 
    4839  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(); 
    24043  for (; it != ite; ++it) 
    24144  { 
    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); 
    37246  } 
    37347} 
    37448 
    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 buffer 
    379   \param [in] recvIndexServerBuff buffer dedicated for receiving server index 
    380   \param [in] recvNbIndexCount size of the buffer 
    381 */ 
    382 void CClientServerMappingDistributed::probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount) 
    383 { 
    384   MPI_Status statusIndexServer; 
    385   int flagIndexServer, count; 
    386  
    387   // Probing for server index 
    388   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   } 
    39949} 
    400  
    401 /*! 
    402   Send message containing global index to clients 
    403   \param [in] clientDestRank rank of destination client 
    404   \param [in] indexGlobal global index to send 
    405   \param [in] clientIntraComm communication group of client 
    406   \param [in] requestSendIndexGlobal list of sending request 
    407 */ 
    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 clients 
    420   \param [in] clientDestRank rank of destination client 
    421   \param [in] indexServer server index to send 
    422   \param [in] clientIntraComm communication group of client 
    423   \param [in] requestSendIndexServer list of sending request 
    424 */ 
    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 request 
    437   \param [in] sendRequest sending request to verify 
    438 */ 
    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 map 
    465   \param[in] buffIndexGlobal pointer to the begining of buffer containing global index 
    466   \param[in] buffIndexServer pointer to the begining of buffer containing server index 
    467   \param[in] count size of received message 
    468 */ 
    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 index 
    477   \param[in] requestRecv request of message 
    478 */ 
    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 index 
    495   \param[in] requestRecv request of message 
    496 */ 
    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 counter 
    513 */ 
    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  
    4242    virtual ~CClientServerMappingDistributed(); 
    4343 
    44  
    45  
    4644  protected: 
    47     // Redistribute global index and server index among clients 
    48     void computeDistributedServerIndex(const boost::unordered_map<size_t,int>& globalIndexOfServer, 
    49                                        const MPI_Comm& clientIntraComm); 
    50  
    51     // Send server index to clients 
    52     void sendIndexServerToClients(int clientDestRank, std::vector<int>& indexServer, 
    53                                   const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexServer); 
    54  
    55     // Send global index to clients 
    56     void sendIndexGlobalToClients(int clientDestRank, std::vector<size_t>& indexGlobal, 
    57                                   const MPI_Comm& clientIntraComm, std::list<MPI_Request>& requestSendIndexGlobal); 
    58  
    59     // Verify sending request 
    60     void testSendRequest(std::list<MPI_Request>& sendRequest); 
    61  
    62     // Process request 
    63     void processReceivedRequest(unsigned long* buffIndexGlobal, int* buffIndexServer, int count); 
    64  
    65     // Probe and receive message of global index 
    66     void probeIndexGlobalMessageFromClients(unsigned long* recvIndexGlobalBuff, int recvNbIndexCount); 
    67  
    68     // Probe and receive message of server index 
    69     void probeIndexServerMessageFromClients(int* recvIndexServerBuff, int recvNbIndexCount); 
    70  
    71     // Compute range of hashing 
    72     void computeHashIndex(); 
    73  
    74     // Compute size of receiving buffer for global index 
    75     int computeBuffCountIndexGlobal(MPI_Request& requestRecv); 
    76  
    77     // Compute size of receiving buffer for server index 
    78     int computeBuffCountIndexServer(MPI_Request& requestRecv); 
    79  
    80     // Reset request map 
    81     void resetReceivingRequestAndCount(); 
    82  
    83   protected: 
    84     //! Mapping of global index to the corresponding server 
    85     boost::unordered_map<size_t,int> globalIndexToServerMapping_; 
    86  
    87     //! Bounds of hash index 
    88     std::vector<size_t> indexClientHash_; 
    89  
    90     //! Number of client 
    91     int nbClient_; 
    92  
    93     //! Rank of client 
    94     int clientRank_; 
    95  
    96     //! Counting of buffer for receiving global index 
    97     int countIndexGlobal_; 
    98  
    99     //! Counting of buffer for receiving server index 
    100     int countIndexServer_; 
    101  
    102     //! intracommuntion of clients 
    103     MPI_Comm clientIntraComm_; 
    104  
    105     //! Request returned by MPI_IRecv function about global index 
    106     std::map<int, MPI_Request> requestRecvIndexGlobal_; 
    107  
    108     //! Request returned by MPI_IRecv function about index of server 
    109     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 client 
    112     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 client 
    115     std::map<int, int*> indexServerBuffBegin_; 
    116  
    117     //! Flag to specify whether data is distributed or not 
    118     bool isDataDistributed_; 
    119  
    120 //    CClientClientDHTTemplate<int>* ccDHT_; 
    12145    CClientClientDHTInt* ccDHT_; 
    12246}; 
  • XIOS/trunk/src/mpi_tag.hpp

    r821 r829  
    1818 
    1919/* Tag for mpi communication to send and receive info of current grid source in grid transformation*/ 
    20 #define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX 32 
     20#define MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX 32 
    2121 
    2222/* 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 
    2430 
    2531/* Tag for mpi communication to send and receive info of DOMAIN in domain interpolation*/ 
     
    3238#define MPI_DOMAIN_INTERPOLATION_WEIGHT 9 
    3339 
     40 
     41 
    3442#endif 
  • XIOS/trunk/src/node/axis.cpp

    r823 r829  
    433433    CServerDistributionDescription serverDescriptionGlobal(globalDim, nbServer); 
    434434    int distributedDimensionOnServer = serverDescriptionGlobal.getDimensionDistributed(); 
    435     std::map<int, std::vector<size_t> > globalIndexAxisOnServer; 
     435    CClientServerMapping::GlobalIndexMap globalIndexAxisOnServer; 
    436436    if (distributedDimensionOnServer == orderPositionInGrid) // So we have distributed axis on client side and also on server side* 
    437437    { 
     
    472472    } 
    473473 
    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(); 
    476476    std::vector<size_t>::const_iterator itbVec = (globalAxisZoom).begin(), 
    477477                                        iteVec = (globalAxisZoom).end(); 
     
    505505    if (!indSrv_.empty()) 
    506506    { 
     507      std::map<int, vector<size_t> >::const_iterator itIndSrv  = indSrv_.begin(), 
     508                                                     iteIndSrv = indSrv_.end(); 
    507509      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); 
    510512    } 
    511513    nbConnectedClients_ = CClientServerMapping::computeConnectedClients(client->serverSize, client->clientSize, client->intraComm, connectedServerRank_); 
  • XIOS/trunk/src/node/domain.cpp

    r823 r829  
    13861386                                                                                client->intraComm); 
    13871387    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(); 
    13921392    typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 
    13931393    std::vector<int>::iterator itVec; 
  • XIOS/trunk/src/node/grid.cpp

    r824 r829  
    457457 
    458458     clientServerMap_->computeServerIndexMapping(clientDistribution_->getGlobalIndex()); 
    459      const std::map<int, std::vector<size_t> >& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 
     459     const CClientServerMapping::GlobalIndexMap& globalIndexOnServer = clientServerMap_->getGlobalIndexOnServer(); 
    460460 
    461461     const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 
    462      std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
    463      itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 
     462     CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
     463     itGlobalMap  = itbGlobalMap = globalIndexOnServer.begin(); 
    464464     iteGlobalMap = globalIndexOnServer.end(); 
    465465 
     
    488488 
    489489     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); 
    492492     } 
    493493 
     
    787787    list<CMessage> listMsg; 
    788788    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(); 
    790790    const std::vector<int>& localIndexSendToServer = clientDistribution_->getLocalDataIndexSendToServer(); 
    791791    const std::vector<size_t>& globalIndexSendToServer = clientDistribution_->getGlobalDataIndexSendToServer(); 
     
    821821    else 
    822822    { 
    823       std::map<int, std::vector<size_t> >::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
     823      CClientServerMapping::GlobalIndexMap::const_iterator iteGlobalMap, itbGlobalMap, itGlobalMap; 
    824824      itbGlobalMap = itGlobalMap = globalIndexOnServer.begin(); 
    825825      iteGlobalMap = globalIndexOnServer.end(); 
  • XIOS/trunk/src/transformation/axis_algorithm_inverse.cpp

    r827 r829  
    7272  std::map<int, std::vector<double> >& transWeight = this->transformationWeight_[0]; 
    7373 
    74   std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexMapFromDestToSource; 
     74  CTransformationMapping::DestinationIndexMap globaIndexMapFromDestToSource; 
    7575  std::map<int, std::vector<int> >::const_iterator it = transMap.begin(), ite = transMap.end(); 
     76  int localIndex = 0; 
    7677  for (; it != ite; ++it) 
    7778  { 
    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; 
    7981  } 
    8082 
    8183  transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 
    8284 
    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(); 
    8587 
    8688 // 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(); 
    8991 int sendBuffSize = 0; 
    9092 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); 
     
    99101 { 
    100102   int destRank = itSend->first; 
    101    const std::vector<size_t>& globalIndexOfCurrentGridSourceToSend = itSend->second; 
     103   const std::vector<std::pair<int,size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 
    102104   int countSize = globalIndexOfCurrentGridSourceToSend.size(); 
    103105   for (int idx = 0; idx < (countSize); ++idx) 
    104106   { 
    105      int index = globalIndexOfCurrentGridSourceToSend[idx] - ibeginSrc; 
     107     int index = globalIndexOfCurrentGridSourceToSend[idx].first; 
    106108     sendBuff[idx+currentBuffPosition] = (axisSrc_->value)(index); 
    107109   } 
     
    112114 
    113115 // 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                                                                                      iteRecv = globalIndexToReceive.end(); 
     116 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 
     117                                                          iteRecv = globalIndexToReceive.end(); 
    116118 int recvBuffSize = 0; 
    117119 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); 
  • XIOS/trunk/src/transformation/axis_algorithm_transformation.cpp

    r827 r829  
    4949                                                                          const std::vector<int>& gridDestGlobalDim, 
    5050                                                                          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, 
    5353                                                                          std::vector<std::vector<size_t> >& globalIndexSrcGrid) 
    5454{ 
     
    7272  } 
    7373 
    74   std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, 
    75                                       iteArr = globalIndexGridDestSendToServer.end(); 
     74  GlobalLocalMap::const_iterator iteArr = globalLocalIndexDestSendToServerMap.end(), it; 
    7675 
    7776  while (idx < ssize) 
     
    111110    } 
    112111 
    113     if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize; 
     112    if (iteArr != globalLocalIndexDestSendToServerMap.find(globIndex)) ++realGlobalIndexSize; 
    114113    ++idxLoop[0]; 
    115114    ++idx; 
    116115  } 
    117116 
    118   if (globalIndexDestGrid.numElements() != realGlobalIndexSize) 
    119     globalIndexDestGrid.resize(realGlobalIndexSize); 
     117  if (globalLocalIndexDestMap.size() != realGlobalIndexSize) 
     118    globalLocalIndexDestMap.resize(realGlobalIndexSize); 
    120119 
    121120  if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); 
     
    162161    } 
    163162 
    164     if (std::binary_search(itbArr, iteArr, globIndex)) 
     163    it = globalLocalIndexDestSendToServerMap.find(globIndex); 
     164    if (iteArr != it) 
    165165    { 
    166       globalIndexDestGrid(realGlobalIndex) = globIndex; 
     166      globalLocalIndexDestMap[realGlobalIndex] = (std::make_pair(it->first,it->second)); 
    167167      for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) 
    168168      { 
     
    183183    ++idx; 
    184184  } 
    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 //  } 
    286185} 
    287186} 
  • XIOS/trunk/src/transformation/axis_algorithm_transformation.hpp

    r827 r829  
    3333                                                        const std::vector<int>& gridDestGlobalDim, 
    3434                                                        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, 
    3737                                                        std::vector<std::vector<size_t> >& globalIndexSrcGrid); 
    3838 
  • XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp

    r827 r829  
    417417 
    418418  domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp); 
    419   const std::map<int, std::vector<size_t> >& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer(); 
     419  const CClientServerMapping::GlobalIndexMap& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer(); 
    420420 
    421421  //Inform each client number of index they will receive 
     
    429429  } 
    430430  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(); 
    433433  for (itMap = itbMap; itMap != iteMap; ++itMap) 
    434434  { 
  • XIOS/trunk/src/transformation/domain_algorithm_transformation.cpp

    r827 r829  
    4242                                                                          const std::vector<int>& gridDestGlobalDim, 
    4343                                                                          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, 
    4646                                                                          std::vector<std::vector<size_t> >& globalIndexSrcGrid) 
    4747{ 
     
    7979  for (int i = 0; i< numElement; ++i) ssize *= gridDomainGlobalDim[i]; 
    8080 
    81   std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, 
    82                                       iteArr = globalIndexGridDestSendToServer.end(); 
     81  GlobalLocalMap::const_iterator iteArr = globalLocalIndexDestSendToServerMap.end(), it; 
     82 
    8383  idx = 0; 
    8484  while (idx < ssize) 
     
    112112    } 
    113113 
    114     if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize; 
     114    if (iteArr != globalLocalIndexDestSendToServerMap.find(globIndex)) ++realGlobalIndexSize; 
    115115    ++idxLoop[0]; 
    116116    ++idx; 
    117117  } 
    118118 
    119   if (globalIndexDestGrid.numElements() != realGlobalIndexSize) 
    120     globalIndexDestGrid.resize(realGlobalIndexSize); 
     119  if (globalLocalIndexDestMap.size() != realGlobalIndexSize) 
     120    globalLocalIndexDestMap.resize(realGlobalIndexSize); 
    121121 
    122122  if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); 
     
    158158    } 
    159159 
    160     if (std::binary_search(itbArr, iteArr, globIndex)) 
     160    it = globalLocalIndexDestSendToServerMap.find(globIndex); 
     161    if (iteArr != it) 
    161162    { 
    162       globalIndexDestGrid(realGlobalIndex) = globIndex; 
     163      globalLocalIndexDestMap[realGlobalIndex] = (std::make_pair(it->first,it->second)); 
    163164      for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) 
    164165      { 
  • XIOS/trunk/src/transformation/domain_algorithm_transformation.hpp

    r827 r829  
    3333                                                        const std::vector<int>& gridDestGlobalDim, 
    3434                                                        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, 
    3737                                                        std::vector<std::vector<size_t> >& globalIndexSrcGrid); 
    3838 
  • XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp

    r827 r829  
    33   \author Ha NGUYEN 
    44   \since 14 May 2015 
    5    \date 29 June 2015 
     5   \date 21 Mars 2016 
    66 
    77   \brief Interface for all transformation algorithms. 
     
    2323  \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) 
    2424  \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 
    2526  \param[in/out] globaIndexWeightFromDestToSource mapping between transformed global index of grid destination 
    26              and the weighted value as long as global index from grid index source 
     27             and the weighted value as well as global index from grid index source 
    2728*/ 
    2829void CGenericAlgorithmTransformation::computeGlobalSourceIndex(int elementPositionInGrid, 
     
    3031                                                             const std::vector<int>& gridSrcGlobalDim, 
    3132                                                             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) 
    3335{ 
    3436  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 
    3744  for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 
    3845  { 
     
    5158 
    5259    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; 
    5661    for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 
    5762    { 
     63      boost::unordered_map<size_t,int> globalLocalIndexDestMap; 
    5864      if (!isTransPosEmpty) 
    5965      { 
    6066        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); 
    6975        ++itTransPos; 
    7076      } 
     
    7278      { 
    7379        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); 
    8288      } 
    83       size_t globalIndexSize = globalIndexDestGrid.numElements(); 
     89      std::vector<std::pair<size_t,int> >::const_iterator it = globalLocalIndexDest.begin(), ite = globalLocalIndexDest.end(); 
    8490      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) 
    8693      { 
    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) 
    8997        { 
    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]))); 
    9199        } 
    92100      } 
  • XIOS/trunk/src/transformation/generic_algorithm_transformation.hpp

    r827 r829  
    2222{ 
    2323public: 
     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; 
     27protected: 
     28  typedef boost::unordered_map<size_t,int> GlobalLocalMap; 
     29 
     30public: 
    2431  CGenericAlgorithmTransformation(); 
    2532 
     
    3037                                const std::vector<int>& gridSrcGlobalDim, 
    3138                                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); 
    3341 
    3442  std::vector<StdString> getIdAuxInputs(); 
     
    4654    \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) 
    4755    \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] globalIndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted 
    49     \param[in/out] globalIndexDestGrid array of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated 
     56    \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 
    5058    \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 
    5159  */ 
     
    5664                                                        const std::vector<int>& gridDestGlobalDim, 
    5765                                                        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, 
    6068                                                        std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0; 
    6169 
  • XIOS/trunk/src/transformation/grid_transformation.cpp

    r827 r829  
    1919#include "distribution_client.hpp" 
    2020#include "mpi_tag.hpp" 
     21#include <boost/unordered_map.hpp> 
    2122 
    2223namespace xios { 
     
    359360  if (nbAlgos_ < 1) return; 
    360361  if (!auxInputs_.empty() && !dynamicalTransformation_) { dynamicalTransformation_ = true; return; } 
    361   if (dynamicalTransformation_) GlobalIndexMap().swap(currentGridIndexToOriginalGridIndex_);  // Reset map 
     362  if (dynamicalTransformation_) DestinationIndexMap().swap(currentGridIndexToOriginalGridIndex_);  // Reset map 
    362363 
    363364  CContext* context = CContext::getCurrent(); 
     
    374375    ETranformationType transType = (it->second).first; 
    375376    int transformationOrder = (it->second).second; 
    376     std::map<size_t, std::vector<std::pair<size_t,double> > > globaIndexWeightFromDestToSource; 
     377    DestinationIndexMap globaIndexWeightFromDestToSource; 
    377378 
    378379    // First of all, select an algorithm 
     
    392393      CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 
    393394      const std::vector<size_t>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 
     395      const std::vector<int>& localIndexGridDestSendToServer = distributionClientDest.getLocalDataIndexSendToServer(); 
    394396 
    395397      // ComputeTransformation of global index of each element 
     
    401403                                     gridSrcDimensionSize, 
    402404                                     globalIndexGridDestSendToServer, 
     405                                     localIndexGridDestSendToServer, 
    403406                                     globaIndexWeightFromDestToSource); 
    404407 
     
    446449  iteArr = globalIndexOnClientDest.end(); 
    447450 
    448   GlobalIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end(); 
     451  DestinationIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end(); 
    449452  const size_t sfmax = NumTraits<unsigned long>::sfmax(); 
    450453  int maskIndexNum = 0; 
     
    453456    if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 
    454457    { 
    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]; 
    456459      for (int idx = 0; idx < vecIndex.size(); ++idx) 
    457460      { 
    458         if (sfmax == vecIndex[idx].first) 
     461        if (sfmax == (vecIndex[idx].second).first) 
    459462        { 
    460463          ++maskIndexNum; 
     
    471474    if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 
    472475    { 
    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]; 
    474477      for (int idx = 0; idx < vecIndex.size(); ++idx) 
    475478      { 
    476         if (sfmax == vecIndex[idx].first) 
     479        if (sfmax == (vecIndex[idx].second).first) 
    477480        { 
    478481          int localIdx = std::distance(itbArr, itArr); 
     
    493496the final grid destination 
    494497*/ 
    495 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource) 
     498void CGridTransformation::computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource) 
    496499{ 
    497500  CContext* context = CContext::getCurrent(); 
     
    509512  transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 
    510513 
    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(); 
    513516 
    514517 // 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(); 
    517520 int sendBuffSize = 0; 
    518521 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); 
     
    526529 for (StdSize idx = 0; idx < sendBuffSize; ++idx) sendBuff[idx] = NumTraits<Scalar>::sfmax(); 
    527530 
    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(); 
    530533 
    531534  // Only send global index of original source corresponding to non-masked index 
     
    536539 { 
    537540   int destRank = itSend->first; 
    538    const std::vector<size_t>& globalIndexOfCurrentGridSourceToSend = itSend->second; 
     541   const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 
    539542   int countSize  = globalIndexOfCurrentGridSourceToSend.size(); 
    540543   size_t countBlock = 0; 
    541544   for (int idx = 0; idx < countSize; ++idx) 
    542545   { 
    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)) 
    545548     { 
    546549       globalIndexOriginalSrcSendBuffSize += currentGridIndexToOriginalGridIndex_[index].size() + 1; // 1 for number of elements in this block 
     
    555558 } 
    556559 
    557  Scalar* sendOriginalIndexBuff, *currentOriginalIndexSendBuff; 
    558  if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalIndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize]; 
     560 Scalar* sendOriginalGlobalIndexBuff, *currentOriginalGlobalIndexSendBuff; 
     561 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize]; 
    559562 double* sendOriginalWeightBuff, *currentOriginalWeightSendBuff; 
    560563 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalWeightBuff = new double [globalIndexOriginalSrcSendBuffSize]; 
     
    564567 { 
    565568   int destRank = itSend->first; 
    566    const std::vector<size_t>& globalIndexOfCurrentGridSourceToSend = itSend->second; 
     569   const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 
    567570   int countSize = globalIndexOfCurrentGridSourceToSend.size(); 
    568571   int increaseStep = 0; 
    569572   for (int idx = 0; idx < countSize; ++idx) 
    570573   { 
    571      size_t index = globalIndexOfCurrentGridSourceToSend[idx]; 
     574     size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 
    572575     if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 
    573576     { 
    574577       size_t vectorSize = currentGridIndexToOriginalGridIndex_[index].size(); 
    575        sendOriginalIndexBuff[currentBuffPosition+increaseStep]  = vectorSize; 
     578       sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep]  = vectorSize; 
    576579       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]; 
    578581       for (size_t i = 0; i < vectorSize; ++i) 
    579582       { 
    580583         ++increaseStep; 
    581          sendOriginalIndexBuff[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; 
    583586       } 
    584587       ++increaseStep; 
     
    586589   } 
    587590 
    588    currentOriginalIndexSendBuff = sendOriginalIndexBuff + currentBuffPosition; 
     591   currentOriginalGlobalIndexSendBuff = sendOriginalGlobalIndexBuff + currentBuffPosition; 
    589592   currentOriginalWeightSendBuff = sendOriginalWeightBuff + currentBuffPosition; 
    590593   if (0 != increaseStep) 
    591594   { 
    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]); 
    594599   } 
    595600   currentBuffPosition += increaseStep; 
     
    598603 
    599604 // 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                                                                                      iteRecv = globalIndexToReceive.end(); 
     605 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 
     606                                                          iteRecv = globalIndexToReceive.end(); 
    602607 int recvBuffSize = 0; 
    603608 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); 
     
    623628 } 
    624629 
    625  Scalar* recvOriginalIndexBuff, *currentOriginalIndexRecvBuff; 
    626  if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalIndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize]; 
     630 Scalar* recvOriginalGlobalIndexBuff, *currentOriginalGlobalIndexRecvBuff; 
     631 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize]; 
    627632 double* recvOriginalWeightBuff, *currentOriginalWeightRecvBuff; 
    628633 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalWeightBuff = new double [globalIndexOriginalSrcRecvBuffSize]; 
     
    633638 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
    634639 { 
    635    MPI_Status statusIndex, statusWeight; 
     640   MPI_Status statusGlobalIndex, statusLocalIndex, statusWeight; 
    636641   int srcRank = itRecv->first; 
    637642   countBlock = countBlockMap[srcRank]; 
    638    currentOriginalIndexRecvBuff = recvOriginalIndexBuff + currentBuffPosition; 
     643   currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff + currentBuffPosition; 
    639644   currentOriginalWeightRecvBuff = recvOriginalWeightBuff + currentBuffPosition; 
    640645   if (0 != countBlock) 
    641646   { 
    642      MPI_Recv(currentOriginalIndexRecvBuff, 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); 
    643648     MPI_Recv(currentOriginalWeightRecvBuff, countBlock, MPI_DOUBLE, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &statusWeight); 
    644649   } 
     
    649654 // The way to process masked index needs discussing 
    650655 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 
    651  GlobalIndexMap currentToOriginalTmp; 
     656 DestinationIndexMap currentToOriginalTmp; 
    652657 
    653658 currentRecvBuffPosition = 0; 
    654659 currentRecvBuff = recvBuff; 
    655  currentOriginalIndexRecvBuff  = recvOriginalIndexBuff; 
     660 currentOriginalGlobalIndexRecvBuff  = recvOriginalGlobalIndexBuff; 
    656661 currentOriginalWeightRecvBuff = recvOriginalWeightBuff; 
    657662 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 
     
    669674       if (0 != countBlockRank) 
    670675       { 
    671          countBlock = *(currentOriginalIndexRecvBuff+currentRecvBuffPosition); 
     676         countBlock = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition); 
    672677         for (int i = 0; i < ssize; ++i) 
    673678         { 
    674679           for (int j = 0; j < countBlock; ++j) 
    675680           { 
    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))); 
    679685           } 
    680686         } 
     
    697703 for (itRequest = requestsCurrentGrid.begin(); itRequest != requestsCurrentGrid.end(); ++itRequest) 
    698704   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) 
    700706   MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 
    701707 for (itRequest = requestsWeightGrid.begin(); itRequest != requestsWeightGrid.end(); ++itRequest) 
     
    704710 if (0 != sendBuffSize) delete [] sendBuff; 
    705711 if (0 != recvBuffSize) delete [] recvBuff; 
    706  if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalIndexBuff; 
     712 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalGlobalIndexBuff; 
    707713 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalWeightBuff; 
    708  if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalIndexBuff; 
     714 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalGlobalIndexBuff; 
    709715 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalWeightBuff; 
    710716} 
     
    724730  transformationMap.computeTransformationMapping(currentGridIndexToOriginalGridIndex_); 
    725731 
    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); 
    748754  itbMapRecv = globalIndexToReceive.begin(); 
    749755  iteMapRecv = globalIndexToReceive.end(); 
     
    756762    { 
    757763      int vecSize = ((itMapRecv->second)[i]).size(); 
    758       std::vector<std::pair<int,double> > tmpVec; 
     764//      std::vector<std::pair<int,double> > tmpVec; 
    759765      for (int idx = 0; idx < vecSize; ++idx) 
    760766      { 
    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//        } 
    767775      } 
    768       localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec; 
     776//      localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec; 
    769777    } 
    770778  } 
    771779 
    772780  // 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); 
    779787  itbMap = globalIndexToSend.begin(); 
    780788  iteMap = globalIndexToSend.end(); 
     
    786794    for (int idx = 0; idx < vecSize; ++idx) 
    787795    { 
    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//      } 
    792800    } 
    793801  } 
  • XIOS/trunk/src/transformation/grid_transformation.hpp

    r827 r829  
    3535public: 
    3636  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; 
    3738 
    3839public: 
     
    6364  void setUpGrid(int elementPositionInGrid, ETranformationType transType, int nbTransformation); 
    6465  void computeFinalTransformationMapping(); 
    65   void computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource); 
     66  void computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource); 
    6667  void updateFinalGridDestination(); 
    6768  bool isSpecialTransformation(ETranformationType transType); 
     
    8485  int nbAlgos_; 
    8586 
    86   typedef std::map<size_t, std::vector<std::pair<size_t,double> > > GlobalIndexMap; 
    87  
    8887  // true if domain algorithm and false if axis algorithm (can be replaced by tuple with listAlgos_ 
    8988  std::vector<bool> algoTypes_; 
     
    105104 
    106105  //! (Grid) Global index of grid source 
    107   GlobalIndexMap currentGridIndexToOriginalGridIndex_; 
     106  DestinationIndexMap currentGridIndexToOriginalGridIndex_; 
    108107 
    109108  std::vector<CGrid*> tempGrids_; 
  • XIOS/trunk/src/transformation/transformation_mapping.cpp

    r668 r829  
    1313#include "context_client.hpp" 
    1414#include "distribution_client.hpp" 
     15#include "client_client_dht_template.hpp" 
     16#include "dht_data_types.hpp" 
     17#include "mpi_tag.hpp" 
    1518 
    1619namespace xios { 
     
    2629 
    2730  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; 
    2935  int globalIndexSize = globalIndexGridSrc.size(); 
     36  PairIntInt pii; 
    3037  for (int idx = 0; idx < globalIndexSize; ++idx) 
    3138  { 
    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); 
    3847} 
    3948 
     
    4857  int ibeginSrc = source->begin.getValue(); 
    4958 
    50   boost::unordered_map<size_t,int> globalIndexOfAxisSource; 
     59  CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfAxisSource; 
     60  PairIntInt pii; 
    5161  for (int idx = 0; idx < niSrc; ++idx) 
    5262  { 
    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); 
    5971} 
    6072 
     
    7183  \param [in] globaIndexWeightFromDestToSource mapping representing the transformations 
    7284*/ 
    73 void CTransformationMapping::computeTransformationMapping(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource) 
     85void CTransformationMapping::computeTransformationMapping(const DestinationIndexMap& globaIndexWeightFromDestToSource) 
    7486{ 
    7587  CContext* context = CContext::getCurrent(); 
    7688  CContextClient* client=context->client; 
    7789 
    78   std::map<size_t, std::vector<std::pair<size_t,double> > >::const_iterator itbMap = globaIndexWeightFromDestToSource.begin(), itMap, 
    79                                                                             iteMap = globaIndexWeightFromDestToSource.end(); 
     90  DestinationIndexMap::const_iterator itbMap = globaIndexWeightFromDestToSource.begin(), itMap, 
     91                                      iteMap = globaIndexWeightFromDestToSource.end(); 
    8092 
    8193  // Not only one index on grid destination can demande two indexes from grid source 
    8294  // 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; 
    8598  for (itMap = itbMap; itMap != iteMap; ++itMap) 
    8699  { 
     
    89102    for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 
    90103    { 
    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))); 
    92121    } 
    93122  } 
     
    95124  // All global indexes of a client on grid destination 
    96125  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(); 
    99128  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; 
    103132    ++idx; 
    104133  } 
    105134 
    106135  // Find out on which clients the necessary indexes of grid source are. 
    107   gridIndexClientClientMapping_->computeServerIndexMapping(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(); 
    111140  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; 
    112148  for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) 
    113149  { 
    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]; 
    133160 
    134161  // 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 
    139164  unsigned long* recvBuffGlobalIndex; 
    140165  if (0 != buffSize) recvBuffGlobalIndex = new unsigned long [buffSize]; 
     
    143168 
    144169  // 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]); 
    148175    MPI_Isend(sendPtr, 
    149               (itMapSrc->second).size(), 
     176              (itSendIndex->second).size(), 
    150177              MPI_UNSIGNED_LONG, 
    151               itMapSrc->first, 
    152               11, 
     178              (itSendIndex->first), 
     179              MPI_TRANSFORMATION_MAPPING_INDEX, 
    153180              client->intraComm, 
    154               &requests[itMapSrc->first]); 
     181              &requests[(itSendIndex->first)]); 
    155182  } 
    156183 
     
    165192             MPI_UNSIGNED_LONG, 
    166193             MPI_ANY_SOURCE, 
    167              11, 
     194             MPI_TRANSFORMATION_MAPPING_INDEX, 
    168195             client->intraComm, 
    169196             &status); 
     
    171198    MPI_Get_count(&status, MPI_UNSIGNED_LONG, &countBuff); 
    172199    int clientDestRank = status.MPI_SOURCE; 
    173     for (int idx = 0; idx < countBuff; ++idx) 
     200    for (int idx = 0; idx < countBuff; idx += 2) 
    174201    { 
    175       globalIndexSendToGridDestMapping_[clientDestRank].push_back(recvBuffGlobalIndex[idx]); 
     202      globalIndexSendToGridDestMapping_[clientDestRank].push_back(std::make_pair<int,size_t>(recvBuffGlobalIndex[idx], recvBuffGlobalIndex[idx+1])); 
    176203    } 
    177204    ++numClientReceived; 
     
    182209    MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 
    183210 
    184   delete [] sendBuff; 
    185   delete [] recvBuff; 
    186211  if (0 != buffSize) delete [] recvBuffGlobalIndex; 
    187212} 
     
    192217  \return global index mapping to receive on grid destination 
    193218*/ 
    194 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& CTransformationMapping::getGlobalIndexReceivedOnGridDestMapping() const 
     219const CTransformationMapping::ReceivedIndexMap& CTransformationMapping::getGlobalIndexReceivedOnGridDestMapping() const 
    195220{ 
    196221  return globalIndexReceivedOnGridDestMapping_; 
     
    202227  \return global index mapping to send on grid source 
    203228*/ 
    204 const std::map<int,std::vector<size_t> >& CTransformationMapping::getGlobalIndexSendToGridDestMapping() const 
     229const CTransformationMapping::SentIndexMap& CTransformationMapping::getGlobalIndexSendToGridDestMapping() const 
    205230{ 
    206231  return globalIndexSendToGridDestMapping_; 
  • XIOS/trunk/src/transformation/transformation_mapping.hpp

    r630 r829  
    2828{ 
    2929public: 
     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 
     34public: 
    3035  /** Default constructor */ 
    3136  CTransformationMapping(CGrid* destination, CGrid* source); 
     
    3439  ~CTransformationMapping(); 
    3540 
    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; 
    3944 
    4045protected: 
     
    4348 
    4449  //! Global index mapping of grid source and grid destination between two clients 
    45   CClientServerMappingDistributed* gridIndexClientClientMapping_; 
     50  CClientClientDHTPairIntInt* gridIndexClientClientMapping_; 
    4651 
    4752  //! 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_; 
    4954 
    5055  //! 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_; 
    5257}; 
    5358 
Note: See TracChangeset for help on using the changeset viewer.