Ignore:
Timestamp:
03/23/16 16:11:01 (8 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/transformation
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • 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.