Changeset 842


Ignore:
Timestamp:
04/26/16 16:03:58 (6 years ago)
Author:
mhnguyen
Message:

Small improvements on transformation mapping

+) Remove complex structure of transformation mapping by a simpler one

Test
+) On Curie
+) All tests pass

Location:
XIOS/trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • XIOS/trunk/src/filter/spatial_transform_filter.cpp

    r841 r842  
    169169      { 
    170170        int countSize = itRecv->second.size(); 
     171        const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second; 
    171172        for (int idx = 0; idx < countSize; ++idx) 
    172173        { 
    173           const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second[idx]; 
    174           int numIndex = localIndex_p.size(); 
    175           for (int i = 0; i < numIndex; ++i) 
    176           { 
    177             dataCurrentDest(localIndex_p[i].first) += *(recvBuff+currentBuff+idx) * localIndex_p[i].second; 
    178           } 
     174          dataCurrentDest(localIndex_p[idx].first) += *(recvBuff+currentBuff+idx) * localIndex_p[idx].second; 
    179175        } 
    180176        currentBuff += countSize; 
  • XIOS/trunk/src/transformation/axis_algorithm_inverse.cpp

    r833 r842  
    139139   for (int idx = 0; idx < countSize; ++idx, ++currentRecvBuff) 
    140140   { 
    141      int ssize = (itRecv->second)[idx].size(); 
    142      for (int i = 0; i < ssize; ++i) 
    143      { 
    144        int index = ((itRecv->second)[idx][i]).first - ibeginDest; 
    145        (axisDest_->value)(index) = *currentRecvBuff; 
    146      } 
     141     int index = ((itRecv->second)[idx]).localIndex - ibeginDest; 
     142     (axisDest_->value)(index) = *currentRecvBuff; 
     143//     int ssize = (itRecv->second)[idx].size(); 
     144//     for (int i = 0; i < ssize; ++i) 
     145//     { 
     146//       int index = ((itRecv->second)[idx][i]).first - ibeginDest; 
     147//       (axisDest_->value)(index) = *currentRecvBuff; 
     148//     } 
    147149   } 
    148150 } 
  • XIOS/trunk/src/transformation/grid_transformation.cpp

    r841 r842  
    450450    for (int i = 0; i < numGlobalIndex; ++i) 
    451451    { 
    452       int vecSize = ((itMapRecv->second)[i]).size(); 
    453       for (int idx = 0; idx < vecSize; ++idx) 
    454       { 
    455         const std::pair<int, std::pair<size_t,double> >& tmpPair = (itMapRecv->second)[i][idx]; 
    456         recvTmp[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second)); 
    457       } 
     452      recvTmp[sourceRank][i] = make_pair((itMapRecv->second)[i].localIndex,(itMapRecv->second)[i].weight); 
    458453    } 
    459454  } 
  • XIOS/trunk/src/transformation/grid_transformation.hpp

    r841 r842  
    3838  typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 
    3939  typedef std::map<int, CArray<int,1> > SendingIndexGridSourceMap; 
    40   typedef std::map<int,std::vector<std::vector<std::pair<int,double> > > > RecvIndexGridDestinationMap; 
     40  typedef std::map<int,std::vector<std::pair<int,double> > > RecvIndexGridDestinationMap; 
     41//  typedef std::map<int,std::vector<std::vector<std::pair<int,double> > > > RecvIndexGridDestinationMap; 
    4142 
    4243public: 
  • XIOS/trunk/src/transformation/transformation_mapping.cpp

    r836 r842  
    8989  // Not only one index on grid destination can demande two indexes from grid source 
    9090  // but an index on grid source has to be sent to two indexes of grid destination 
    91   DestinationIndexMap globalIndexMapFromSrcToDest; 
    92   boost::unordered_map<size_t, int> nbGlobalIndexMapFromSrcToDest; 
     91  size_t nbGlobalIndexSrc = 0; 
     92  for (itMap = itbMap; itMap != iteMap; ++itMap) 
     93  { 
     94    nbGlobalIndexSrc += (itMap->second).size(); 
     95  } 
     96 
     97  CArray<size_t,1> globalIndexMap(nbGlobalIndexSrc); 
    9398  std::vector<std::pair<int, std::pair<size_t,double> > >::const_iterator itbVecPair, itVecPair, iteVecPair; 
     99  size_t idxSrc = 0; 
    94100  for (itMap = itbMap; itMap != iteMap; ++itMap) 
    95101  { 
     
    98104    for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 
    99105    { 
    100       ++nbGlobalIndexMapFromSrcToDest[(itVecPair->second).first]; 
    101     } 
    102   } 
    103  
    104   for (boost::unordered_map<size_t, int>::const_iterator it = nbGlobalIndexMapFromSrcToDest.begin(); 
    105                                                          it != nbGlobalIndexMapFromSrcToDest.end(); ++it) 
    106   { 
    107     globalIndexMapFromSrcToDest[it->first].reserve(it->second); 
    108   } 
    109  
    110   for (itMap = itbMap; itMap != iteMap; ++itMap) 
    111   { 
    112     itbVecPair = (itMap->second).begin(); 
    113     iteVecPair = (itMap->second).end(); 
    114     for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 
    115     { 
    116       globalIndexMapFromSrcToDest[(itVecPair->second).first].push_back(std::make_pair(itVecPair->first, std::make_pair(itMap->first, (itVecPair->second).second))); 
    117     } 
    118   } 
    119  
    120   // All global indexes of a client on grid destination 
    121   CArray<size_t,1> globalIndexMap(globalIndexMapFromSrcToDest.size()); 
    122   DestinationIndexMap::const_iterator itbMapBoost = globalIndexMapFromSrcToDest.begin(), itMapBoost; 
    123   DestinationIndexMap::const_iterator iteMapBoost = globalIndexMapFromSrcToDest.end(); 
    124   int idx = 0; 
    125   for (itMapBoost = itbMapBoost; itMapBoost != iteMapBoost; ++itMapBoost) 
    126   { 
    127     globalIndexMap(idx) = itMapBoost->first; 
    128     ++idx; 
     106      globalIndexMap(idxSrc) = itVecPair->second.first; 
     107      ++idxSrc; 
     108    } 
    129109  } 
    130110 
     
    134114  CClientClientDHTPairIntInt::Index2InfoTypeMap::const_iterator itbMapSrc = globalIndexSentFromGridSource.begin(), itMapSrc, 
    135115                                                                iteMapSrc = globalIndexSentFromGridSource.end(); 
    136   std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 
    137     // Inform client about the destination to which it needs to send global indexes 
     116  size_t currentIndexSrc; 
    138117  int nbClient = client->clientSize; 
     118  std::vector<int> nbIndexEachClient(nbClient,0); 
    139119  std::vector<int> sendNbClientBuff(nbClient,0); 
     120  for (idxSrc = 0; idxSrc < nbGlobalIndexSrc; ++idxSrc) 
     121  { 
     122    currentIndexSrc = globalIndexMap(idxSrc); 
     123    itMapSrc = globalIndexSentFromGridSource.find(currentIndexSrc); 
     124    if (iteMapSrc != itMapSrc) 
     125    { 
     126      ++nbIndexEachClient[itMapSrc->second.first]; 
     127    } 
     128  } 
     129 
     130  boost::unordered_map<int,size_t* > sendIndexMap; 
     131  for (int idx = 0; idx < nbClient; ++idx) 
     132  { 
     133    if (0 != nbIndexEachClient[idx]) 
     134    { 
     135      globalIndexReceivedOnGridDestMapping_[idx].resize(nbIndexEachClient[idx]); 
     136      sendIndexMap[idx] = new unsigned long [2*nbIndexEachClient[idx]]; 
     137      nbIndexEachClient[idx] = 0; 
     138      sendNbClientBuff[idx] = 1; 
     139    } 
     140  } 
     141 
     142  int srcRank; 
     143  for (itMap = itbMap; itMap != iteMap; ++itMap) 
     144  { 
     145    itbVecPair = (itMap->second).begin(); 
     146    iteVecPair = (itMap->second).end(); 
     147    for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 
     148    { 
     149      currentIndexSrc = itVecPair->second.first; 
     150      itMapSrc = globalIndexSentFromGridSource.find(currentIndexSrc); 
     151      if (iteMapSrc != itMapSrc) 
     152      { 
     153        srcRank = (itMapSrc->second).first; 
     154        int& ind = nbIndexEachClient[srcRank]; 
     155        globalIndexReceivedOnGridDestMapping_[srcRank][ind] = ReceivedIndex(itVecPair->first, itMap->first, itVecPair->second.second); 
     156        sendIndexMap[srcRank][2*ind] = (itMapSrc->second).second; 
     157        sendIndexMap[srcRank][2*ind+1] = itMapSrc->first; 
     158        ++ind; 
     159      } 
     160    } 
     161  } 
     162 
    140163  std::vector<int> recvNbClientBuff(nbClient,0); 
    141   std::vector<int> sendIndexBuff(nbClient,0); 
    142   std::vector<int> recvIndexBuff(nbClient,0); 
    143   boost::unordered_map<int,std::vector<size_t> > sendIndexMap; 
    144   for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) 
    145   { 
    146     int sourceRank = (itMapSrc->second).first; 
    147     (globalIndexReceivedOnGridDestMapping_[sourceRank]).push_back(globalIndexMapFromSrcToDest[itMapSrc->first]); 
    148     sendIndexMap[sourceRank].push_back((itMapSrc->second).second); 
    149     sendIndexMap[sourceRank].push_back(itMapSrc->first); 
    150     sendNbClientBuff[sourceRank] = 1; 
    151     ++sendIndexBuff[sourceRank]; 
    152   } 
    153  
    154164  MPI_Allreduce(&sendNbClientBuff[0], &recvNbClientBuff[0], nbClient, MPI_INT, MPI_SUM, client->intraComm); 
    155165  int numClientToReceive = recvNbClientBuff[client->clientRank]; 
    156166 
    157167  // Then specify the size of receiving buffer, because we use synch send/receive so only necessary to know maximum size 
    158   MPI_Allreduce(&sendIndexBuff[0], &recvIndexBuff[0], nbClient, MPI_INT, MPI_MAX, client->intraComm); 
     168  std::vector<int> recvIndexBuff(nbClient,0); 
     169  MPI_Allreduce(&nbIndexEachClient[0], &recvIndexBuff[0], nbClient, MPI_INT, MPI_MAX, client->intraComm); 
     170  std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 
     171 
    159172  int buffSize = 2*recvIndexBuff[client->clientRank]; // we send global as well as local index 
    160173  unsigned long* recvBuffGlobalIndex; 
     
    164177 
    165178  // Inform all "source clients" about index that they need to send 
    166   boost::unordered_map<int,std::vector<size_t> >::const_iterator itSendIndex = sendIndexMap.begin(), 
    167                                                                  iteSendIndex= sendIndexMap.end(); 
     179  boost::unordered_map<int,size_t* >::const_iterator itSendIndex = sendIndexMap.begin(), 
     180                                                     iteSendIndex= sendIndexMap.end(); 
    168181  for (; itSendIndex != iteSendIndex; ++itSendIndex) 
    169182  { 
    170     unsigned long* sendPtr = const_cast<unsigned long*>(&(itSendIndex->second)[0]); 
    171     MPI_Isend(sendPtr, 
    172               (itSendIndex->second).size(), 
     183    MPI_Isend((itSendIndex->second), 
     184              2*nbIndexEachClient[itSendIndex->first], 
    173185              MPI_UNSIGNED_LONG, 
    174186              (itSendIndex->first), 
     
    194206    MPI_Get_count(&status, MPI_UNSIGNED_LONG, &countBuff); 
    195207    int clientDestRank = status.MPI_SOURCE; 
    196     for (int idx = 0; idx < countBuff; idx += 2) 
    197     { 
    198       globalIndexSendToGridDestMapping_[clientDestRank].push_back(std::make_pair<int,size_t>(recvBuffGlobalIndex[idx], recvBuffGlobalIndex[idx+1])); 
     208    int sizeMap = countBuff/2; 
     209    globalIndexSendToGridDestMapping_[clientDestRank].resize(sizeMap); 
     210    for (int idx = 0, i = 0; idx < countBuff; idx += 2, ++i) 
     211    { 
     212      globalIndexSendToGridDestMapping_[clientDestRank][i].first = recvBuffGlobalIndex[idx]; 
     213      globalIndexSendToGridDestMapping_[clientDestRank][i].second = recvBuffGlobalIndex[idx+1]; 
    199214    } 
    200215    ++numClientReceived; 
     
    206221 
    207222  if (0 != buffSize) delete [] recvBuffGlobalIndex; 
     223  for (itSendIndex = sendIndexMap.begin(); itSendIndex != iteSendIndex; ++itSendIndex) 
     224    delete [] itSendIndex->second; 
    208225} 
    209226 
  • XIOS/trunk/src/transformation/transformation_mapping.hpp

    r829 r842  
    2929public: 
    3030  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; 
     31  struct ReceivedIndex { 
     32    ReceivedIndex(int l, size_t g, double w) : localIndex(l),globalIndex(g), weight(w) {} 
     33    ReceivedIndex() : localIndex(0), globalIndex(0), weight(0.0) {} 
     34    int localIndex; 
     35    size_t globalIndex; 
     36    double weight; 
     37  }; 
     38 
     39  typedef boost::unordered_map<int,std::vector<ReceivedIndex> > ReceivedIndexMap; 
    3240  typedef boost::unordered_map<int,std::vector<std::pair<int, size_t> > > SentIndexMap; 
    3341 
Note: See TracChangeset for help on using the changeset viewer.