Changeset 829 for XIOS/trunk/src/transformation
- Timestamp:
- 03/23/16 16:11:01 (8 years ago)
- Location:
- XIOS/trunk/src/transformation
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
XIOS/trunk/src/transformation/axis_algorithm_inverse.cpp
r827 r829 72 72 std::map<int, std::vector<double> >& transWeight = this->transformationWeight_[0]; 73 73 74 std::map<size_t, std::vector<std::pair<size_t,double> > >globaIndexMapFromDestToSource;74 CTransformationMapping::DestinationIndexMap globaIndexMapFromDestToSource; 75 75 std::map<int, std::vector<int> >::const_iterator it = transMap.begin(), ite = transMap.end(); 76 int localIndex = 0; 76 77 for (; it != ite; ++it) 77 78 { 78 globaIndexMapFromDestToSource[it->first].push_back(make_pair((it->second)[0], (transWeight[it->first])[0])); 79 globaIndexMapFromDestToSource[it->first].push_back(make_pair(localIndex,make_pair((it->second)[0], (transWeight[it->first])[0]))); 80 ++localIndex; 79 81 } 80 82 81 83 transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 82 84 83 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();84 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();85 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 86 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 85 87 86 88 // Sending global index of original grid source 87 std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend,88 iteSend = globalIndexToSend.end();89 CTransformationMapping::SentIndexMap::const_iterator itbSend = globalIndexToSend.begin(), itSend, 90 iteSend = globalIndexToSend.end(); 89 91 int sendBuffSize = 0; 90 92 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); … … 99 101 { 100 102 int destRank = itSend->first; 101 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;103 const std::vector<std::pair<int,size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 102 104 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 103 105 for (int idx = 0; idx < (countSize); ++idx) 104 106 { 105 int index = globalIndexOfCurrentGridSourceToSend[idx] - ibeginSrc;107 int index = globalIndexOfCurrentGridSourceToSend[idx].first; 106 108 sendBuff[idx+currentBuffPosition] = (axisSrc_->value)(index); 107 109 } … … 112 114 113 115 // Receiving global index of grid source sending from current grid source 114 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv,115 116 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 117 iteRecv = globalIndexToReceive.end(); 116 118 int recvBuffSize = 0; 117 119 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); -
XIOS/trunk/src/transformation/axis_algorithm_transformation.cpp
r827 r829 49 49 const std::vector<int>& gridDestGlobalDim, 50 50 const std::vector<int>& gridSrcGlobalDim, 51 const std::vector<size_t>& globalIndexGridDestSendToServer,52 CArray<size_t,1>& globalIndexDestGrid,51 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 52 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 53 53 std::vector<std::vector<size_t> >& globalIndexSrcGrid) 54 54 { … … 72 72 } 73 73 74 std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr, 75 iteArr = globalIndexGridDestSendToServer.end(); 74 GlobalLocalMap::const_iterator iteArr = globalLocalIndexDestSendToServerMap.end(), it; 76 75 77 76 while (idx < ssize) … … 111 110 } 112 111 113 if ( std::binary_search(itbArr, iteArr,globIndex)) ++realGlobalIndexSize;112 if (iteArr != globalLocalIndexDestSendToServerMap.find(globIndex)) ++realGlobalIndexSize; 114 113 ++idxLoop[0]; 115 114 ++idx; 116 115 } 117 116 118 if (global IndexDestGrid.numElements() != realGlobalIndexSize)119 global IndexDestGrid.resize(realGlobalIndexSize);117 if (globalLocalIndexDestMap.size() != realGlobalIndexSize) 118 globalLocalIndexDestMap.resize(realGlobalIndexSize); 120 119 121 120 if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); … … 162 161 } 163 162 164 if (std::binary_search(itbArr, iteArr, globIndex)) 163 it = globalLocalIndexDestSendToServerMap.find(globIndex); 164 if (iteArr != it) 165 165 { 166 global IndexDestGrid(realGlobalIndex) = globIndex;166 globalLocalIndexDestMap[realGlobalIndex] = (std::make_pair(it->first,it->second)); 167 167 for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) 168 168 { … … 183 183 ++idx; 184 184 } 185 186 187 188 // int globalDim = gridDestGlobalDim.size();189 //190 // std::vector<size_t> currentIndex(globalDim);191 // std::vector<int> gridAxisGlobalDim(globalDim);192 // std::vector<int> idxLoop(globalDim, 0);193 //194 // size_t ssize = 1, idx = 0, realGlobalIndexSize = 0;195 // for (int i = 0; i< globalDim; ++i)196 // {197 // if (axisPositionInGrid == i) gridAxisGlobalDim[i] = 1;198 // else gridAxisGlobalDim[i] = gridDestGlobalDim[i];199 // ssize *= gridAxisGlobalDim[i];200 // }201 //202 // std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,203 // iteArr = globalIndexGridDestSendToServer.end();204 //205 // while (idx < ssize)206 // {207 // for (int i = 0; i < globalDim-1; ++i)208 // {209 // if (idxLoop[i] == gridAxisGlobalDim[i])210 // {211 // idxLoop[i] = 0;212 // ++idxLoop[i+1];213 // }214 // }215 //216 // for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];217 // currentIndex[axisPositionInGrid] = axisDestGlobalIndex;218 //219 // size_t globIndex = currentIndex[0];220 // size_t mulDim = 1;221 // for (int k = 1; k < globalDim; ++k)222 // {223 // mulDim *= gridDestGlobalDim[k-1];224 // globIndex += (currentIndex[k])*mulDim;225 // }226 //227 // if (std::binary_search(itbArr, iteArr, globIndex)) ++realGlobalIndexSize;228 // ++idxLoop[0];229 // ++idx;230 // }231 //232 // if (globalIndexDestGrid.numElements() != realGlobalIndexSize)233 // globalIndexDestGrid.resize(realGlobalIndexSize);234 //235 // if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize);236 // for (int i = 0; i < globalIndexSrcGrid.size(); ++i)237 // if (globalIndexSrcGrid[i].size() != axisSrcGlobalIndex.size())238 // globalIndexSrcGrid[i].resize(axisSrcGlobalIndex.size());239 //240 // size_t realGlobalIndex = 0;241 // idx = 0;242 // idxLoop.assign(globalDim, 0);243 // while (idx < ssize)244 // {245 // for (int i = 0; i < globalDim-1; ++i)246 // {247 // if (idxLoop[i] == gridAxisGlobalDim[i])248 // {249 // idxLoop[i] = 0;250 // ++idxLoop[i+1];251 // }252 // }253 //254 // for (int i = 0; i < globalDim; ++i) currentIndex[i] = idxLoop[i];255 // currentIndex[axisPositionInGrid] = axisDestGlobalIndex;256 //257 // size_t globIndex = currentIndex[0];258 // size_t mulDim = 1;259 // for (int k = 1; k < globalDim; ++k)260 // {261 // mulDim *= gridDestGlobalDim[k-1];262 // globIndex += (currentIndex[k])*mulDim;263 // }264 //265 // if (std::binary_search(itbArr, iteArr, globIndex))266 // {267 // globalIndexDestGrid(realGlobalIndex) = globIndex;268 // for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i)269 // {270 // currentIndex[axisPositionInGrid] = axisSrcGlobalIndex[i];271 // globIndex = currentIndex[0];272 // mulDim = 1;273 // for (int k = 1; k < globalDim; ++k)274 // {275 // mulDim *= gridDestGlobalDim[k-1];276 // globIndex += (currentIndex[k])*mulDim;277 // }278 // (globalIndexSrcGrid[realGlobalIndex])[i] = globIndex;279 // }280 // ++realGlobalIndex;281 // }282 //283 // ++idxLoop[0];284 // ++idx;285 // }286 185 } 287 186 } -
XIOS/trunk/src/transformation/axis_algorithm_transformation.hpp
r827 r829 33 33 const std::vector<int>& gridDestGlobalDim, 34 34 const std::vector<int>& gridSrcGlobalDim, 35 const std::vector<size_t>& globalIndexGridDestSendToServer,36 CArray<size_t,1>& globalIndexDestGrid,35 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 36 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 37 37 std::vector<std::vector<size_t> >& globalIndexSrcGrid); 38 38 -
XIOS/trunk/src/transformation/domain_algorithm_interpolate.cpp
r827 r829 417 417 418 418 domainIndexClientClientMapping.computeServerIndexMapping(globalIndexInterp); 419 const std::map<int, std::vector<size_t> >& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer();419 const CClientServerMapping::GlobalIndexMap& globalIndexInterpSendToClient = domainIndexClientClientMapping.getGlobalIndexOnServer(); 420 420 421 421 //Inform each client number of index they will receive … … 429 429 } 430 430 int sendBuffSize = 0; 431 std::map<int, std::vector<size_t> >::const_iterator itbMap = globalIndexInterpSendToClient.begin(), itMap,432 iteMap = globalIndexInterpSendToClient.end();431 CClientServerMapping::GlobalIndexMap::const_iterator itbMap = globalIndexInterpSendToClient.begin(), itMap, 432 iteMap = globalIndexInterpSendToClient.end(); 433 433 for (itMap = itbMap; itMap != iteMap; ++itMap) 434 434 { -
XIOS/trunk/src/transformation/domain_algorithm_transformation.cpp
r827 r829 42 42 const std::vector<int>& gridDestGlobalDim, 43 43 const std::vector<int>& gridSrcGlobalDim, 44 const std::vector<size_t>& globalIndexGridDestSendToServer,45 CArray<size_t,1>& globalIndexDestGrid,44 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 45 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 46 46 std::vector<std::vector<size_t> >& globalIndexSrcGrid) 47 47 { … … 79 79 for (int i = 0; i< numElement; ++i) ssize *= gridDomainGlobalDim[i]; 80 80 81 std::vector<size_t>::const_iterator itbArr = globalIndexGridDestSendToServer.begin(), itArr,82 iteArr = globalIndexGridDestSendToServer.end(); 81 GlobalLocalMap::const_iterator iteArr = globalLocalIndexDestSendToServerMap.end(), it; 82 83 83 idx = 0; 84 84 while (idx < ssize) … … 112 112 } 113 113 114 if ( std::binary_search(itbArr, iteArr,globIndex)) ++realGlobalIndexSize;114 if (iteArr != globalLocalIndexDestSendToServerMap.find(globIndex)) ++realGlobalIndexSize; 115 115 ++idxLoop[0]; 116 116 ++idx; 117 117 } 118 118 119 if (global IndexDestGrid.numElements() != realGlobalIndexSize)120 global IndexDestGrid.resize(realGlobalIndexSize);119 if (globalLocalIndexDestMap.size() != realGlobalIndexSize) 120 globalLocalIndexDestMap.resize(realGlobalIndexSize); 121 121 122 122 if (realGlobalIndexSize != globalIndexSrcGrid.size()) globalIndexSrcGrid.resize(realGlobalIndexSize); … … 158 158 } 159 159 160 if (std::binary_search(itbArr, iteArr, globIndex)) 160 it = globalLocalIndexDestSendToServerMap.find(globIndex); 161 if (iteArr != it) 161 162 { 162 global IndexDestGrid(realGlobalIndex) = globIndex;163 globalLocalIndexDestMap[realGlobalIndex] = (std::make_pair(it->first,it->second)); 163 164 for (int i = 0; i < globalIndexSrcGrid[realGlobalIndex].size(); ++i) 164 165 { -
XIOS/trunk/src/transformation/domain_algorithm_transformation.hpp
r827 r829 33 33 const std::vector<int>& gridDestGlobalDim, 34 34 const std::vector<int>& gridSrcGlobalDim, 35 const std::vector<size_t>& globalIndexGridDestSendToServer,36 CArray<size_t,1>& globalIndexDestGrid,35 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 36 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 37 37 std::vector<std::vector<size_t> >& globalIndexSrcGrid); 38 38 -
XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp
r827 r829 3 3 \author Ha NGUYEN 4 4 \since 14 May 2015 5 \date 2 9 June 20155 \date 21 Mars 2016 6 6 7 7 \brief Interface for all transformation algorithms. … … 23 23 \param[in] gridSrcGlobalDim dimension size of source grid (it should share the same size for all dimension, maybe except the domain on which transformation is performed) 24 24 \param[in] globalIndexGridDestSendToServer global index of grid destination on the current client to send to server 25 \param[in] localIndexGridSendToServer local index of grid destination on the current client to send to server 25 26 \param[in/out] globaIndexWeightFromDestToSource mapping between transformed global index of grid destination 26 and the weighted value as longas global index from grid index source27 and the weighted value as well as global index from grid index source 27 28 */ 28 29 void CGenericAlgorithmTransformation::computeGlobalSourceIndex(int elementPositionInGrid, … … 30 31 const std::vector<int>& gridSrcGlobalDim, 31 32 const std::vector<size_t>& globalIndexGridDestSendToServer, 32 std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource) 33 const std::vector<int>& localIndexGridSendToServer, 34 DestinationIndexMap& globaIndexWeightFromDestToSource) 33 35 { 34 36 bool isTransPosEmpty = transformationPosition_.empty(); 35 std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); 36 std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); 37 boost::unordered_map<size_t,int> globalLocalIndexDestSendToServerMap; 38 size_t nbGlobalIndexDest = globalIndexGridDestSendToServer.size(); 39 for (size_t idx = 0; idx < nbGlobalIndexDest; ++idx) 40 { 41 globalLocalIndexDestSendToServerMap[globalIndexGridDestSendToServer[idx]] = localIndexGridSendToServer[idx]; 42 } 43 37 44 for (size_t idxTrans = 0; idxTrans < transformationMapping_.size(); ++idxTrans) 38 45 { … … 51 58 52 59 std::vector<std::vector<size_t> > globalIndexSrcGrid; 53 CArray<size_t,1> globalIndexDestGrid; 54 // std::vector<size_t> vecGlobalIndexGridSendToServer(globalIndexGridDestSendToServer.begin(), globalIndexGridDestSendToServer.end()); 55 // std::sort(vecGlobalIndexGridSendToServer.begin(), vecGlobalIndexGridSendToServer.end()); 60 std::vector<std::pair<size_t,int> > globalLocalIndexDest; 56 61 for (itTransMap = itbTransMap; itTransMap != iteTransMap; ++itTransMap, ++itTransWeight) 57 62 { 63 boost::unordered_map<size_t,int> globalLocalIndexDestMap; 58 64 if (!isTransPosEmpty) 59 65 { 60 66 this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first, 61 itTransMap->second,62 itTransPos->second,63 elementPositionInGrid,64 gridDestGlobalDim,65 gridSrcGlobalDim,66 vecGlobalIndexGridSendToServer,67 globalIndexDestGrid,68 globalIndexSrcGrid);67 itTransMap->second, 68 itTransPos->second, 69 elementPositionInGrid, 70 gridDestGlobalDim, 71 gridSrcGlobalDim, 72 globalLocalIndexDestSendToServerMap, 73 globalLocalIndexDest, 74 globalIndexSrcGrid); 69 75 ++itTransPos; 70 76 } … … 72 78 { 73 79 this->computeGlobalGridIndexFromGlobalIndexElement(itTransMap->first, 74 itTransMap->second,75 emptyTransPos,76 elementPositionInGrid,77 gridDestGlobalDim,78 gridSrcGlobalDim,79 vecGlobalIndexGridSendToServer,80 globalIndexDestGrid,81 globalIndexSrcGrid);80 itTransMap->second, 81 emptyTransPos, 82 elementPositionInGrid, 83 gridDestGlobalDim, 84 gridSrcGlobalDim, 85 globalLocalIndexDestSendToServerMap, 86 globalLocalIndexDest, 87 globalIndexSrcGrid); 82 88 } 83 s ize_t globalIndexSize = globalIndexDestGrid.numElements();89 std::vector<std::pair<size_t,int> >::const_iterator it = globalLocalIndexDest.begin(), ite = globalLocalIndexDest.end(); 84 90 const std::vector<double>& currentVecWeight = itTransWeight->second; 85 for (size_t idx = 0; idx < globalIndexSize; ++idx) 91 92 for (size_t idx = 0; it != ite; ++it, ++idx) 86 93 { 87 size_t globalIndex = globalIndexDestGrid(idx); 88 for (int i = 0; i < globalIndexSrcGrid[idx].size(); ++i) 94 size_t srcGridSize = globalIndexSrcGrid[idx].size(); 95 globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize); 96 for (int i = 0; i < srcGridSize; ++i) 89 97 { 90 globaIndexWeightFromDestToSource[ globalIndex].push_back(make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]));98 globaIndexWeightFromDestToSource[(it->first)].push_back(make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i]))); 91 99 } 92 100 } -
XIOS/trunk/src/transformation/generic_algorithm_transformation.hpp
r827 r829 22 22 { 23 23 public: 24 // Stupid global index map, it must be replaced by tuple 25 // Mapping between global index map of DESTINATION and its local index with pair of global index of SOURCE and weights 26 typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 27 protected: 28 typedef boost::unordered_map<size_t,int> GlobalLocalMap; 29 30 public: 24 31 CGenericAlgorithmTransformation(); 25 32 … … 30 37 const std::vector<int>& gridSrcGlobalDim, 31 38 const std::vector<size_t>& globalIndexGridDestSendToServer, 32 std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource); 39 const std::vector<int>& localIndexGridSendToServer, 40 DestinationIndexMap& globaIndexWeightFromDestToSource); 33 41 34 42 std::vector<StdString> getIdAuxInputs(); … … 46 54 \param[in] elementPositionInGrid position of the element in the grid (for example: a grid with one domain and one axis, position of domain is 1, position of axis is 2) 47 55 \param[in] gridDestGlobalDim dimension size of destination grid (it should share the same size for all dimension, maybe except the element on which transformation is performed) 48 \param[in] global IndexGridDestSendToServer global index of destination grid which are to be sent to server(s), this array is already acsending sorted49 \param[in/out] global IndexDestGridarray of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated56 \param[in] globalLocalIndexDestSendToServerMap pair of global index and local index of destination grid which are to be sent to server(s), this array is already acsending sorted 57 \param[in/out] globalLocalIndexDestMap array of global index (for 2d grid, this array maybe a line, for 3d, this array may represent a plan). It should be preallocated 50 58 \param[in/out] globalIndexSrcGrid array of global index of source grid (for 2d grid, this array is a line, for 3d, this array represents a plan). It should be preallocated 51 59 */ … … 56 64 const std::vector<int>& gridDestGlobalDim, 57 65 const std::vector<int>& gridSrcGlobalDim, 58 const std::vector<size_t>& globalIndexGridDestSendToServer,59 CArray<size_t,1>& globalIndexDestGrid,66 const GlobalLocalMap& globalLocalIndexDestSendToServerMap, 67 std::vector<std::pair<size_t,int> >& globalLocalIndexDestMap, 60 68 std::vector<std::vector<size_t> >& globalIndexSrcGrid) = 0; 61 69 -
XIOS/trunk/src/transformation/grid_transformation.cpp
r827 r829 19 19 #include "distribution_client.hpp" 20 20 #include "mpi_tag.hpp" 21 #include <boost/unordered_map.hpp> 21 22 22 23 namespace xios { … … 359 360 if (nbAlgos_ < 1) return; 360 361 if (!auxInputs_.empty() && !dynamicalTransformation_) { dynamicalTransformation_ = true; return; } 361 if (dynamicalTransformation_) GlobalIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map362 if (dynamicalTransformation_) DestinationIndexMap().swap(currentGridIndexToOriginalGridIndex_); // Reset map 362 363 363 364 CContext* context = CContext::getCurrent(); … … 374 375 ETranformationType transType = (it->second).first; 375 376 int transformationOrder = (it->second).second; 376 std::map<size_t, std::vector<std::pair<size_t,double> > >globaIndexWeightFromDestToSource;377 DestinationIndexMap globaIndexWeightFromDestToSource; 377 378 378 379 // First of all, select an algorithm … … 392 393 CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 393 394 const std::vector<size_t>& globalIndexGridDestSendToServer = distributionClientDest.getGlobalDataIndexSendToServer(); 395 const std::vector<int>& localIndexGridDestSendToServer = distributionClientDest.getLocalDataIndexSendToServer(); 394 396 395 397 // ComputeTransformation of global index of each element … … 401 403 gridSrcDimensionSize, 402 404 globalIndexGridDestSendToServer, 405 localIndexGridDestSendToServer, 403 406 globaIndexWeightFromDestToSource); 404 407 … … 446 449 iteArr = globalIndexOnClientDest.end(); 447 450 448 GlobalIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end();451 DestinationIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end(); 449 452 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 450 453 int maskIndexNum = 0; … … 453 456 if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 454 457 { 455 const std::vector<std::pair< size_t,double> >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr];458 const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr]; 456 459 for (int idx = 0; idx < vecIndex.size(); ++idx) 457 460 { 458 if (sfmax == vecIndex[idx].first)461 if (sfmax == (vecIndex[idx].second).first) 459 462 { 460 463 ++maskIndexNum; … … 471 474 if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(*itArr)) 472 475 { 473 const std::vector<std::pair< size_t,double> >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr];476 const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[*itArr]; 474 477 for (int idx = 0; idx < vecIndex.size(); ++idx) 475 478 { 476 if (sfmax == vecIndex[idx].first)479 if (sfmax == (vecIndex[idx].second).first) 477 480 { 478 481 int localIdx = std::distance(itbArr, itArr); … … 493 496 the final grid destination 494 497 */ 495 void CGridTransformation::computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource)498 void CGridTransformation::computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource) 496 499 { 497 500 CContext* context = CContext::getCurrent(); … … 509 512 transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource); 510 513 511 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();512 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();514 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 515 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 513 516 514 517 // Sending global index of original grid source 515 std::map<int,std::vector<size_t> >::const_iterator itbSend = globalIndexToSend.begin(), itSend,516 iteSend = globalIndexToSend.end();518 CTransformationMapping::SentIndexMap::const_iterator itbSend = globalIndexToSend.begin(), itSend, 519 iteSend = globalIndexToSend.end(); 517 520 int sendBuffSize = 0; 518 521 for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size(); … … 526 529 for (StdSize idx = 0; idx < sendBuffSize; ++idx) sendBuff[idx] = NumTraits<Scalar>::sfmax(); 527 530 528 std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGrid , requestsWeightGrid;529 GlobalIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end();531 std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGridGlobalIndex, requestsOriginalGridLocalIndex, requestsWeightGrid; 532 DestinationIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end(); 530 533 531 534 // Only send global index of original source corresponding to non-masked index … … 536 539 { 537 540 int destRank = itSend->first; 538 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;541 const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 539 542 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 540 543 size_t countBlock = 0; 541 544 for (int idx = 0; idx < countSize; ++idx) 542 545 { 543 size_t index = globalIndexOfCurrentGridSourceToSend[idx] ;544 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) // searchCurrentSrc.search(itbIndex, iteIndex, globalIndexOfCurrentGridSourceToSend[idx], itIndex))546 size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 547 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 545 548 { 546 549 globalIndexOriginalSrcSendBuffSize += currentGridIndexToOriginalGridIndex_[index].size() + 1; // 1 for number of elements in this block … … 555 558 } 556 559 557 Scalar* sendOriginal IndexBuff, *currentOriginalIndexSendBuff;558 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginal IndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize];560 Scalar* sendOriginalGlobalIndexBuff, *currentOriginalGlobalIndexSendBuff; 561 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize]; 559 562 double* sendOriginalWeightBuff, *currentOriginalWeightSendBuff; 560 563 if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalWeightBuff = new double [globalIndexOriginalSrcSendBuffSize]; … … 564 567 { 565 568 int destRank = itSend->first; 566 const std::vector<s ize_t>& globalIndexOfCurrentGridSourceToSend = itSend->second;569 const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second; 567 570 int countSize = globalIndexOfCurrentGridSourceToSend.size(); 568 571 int increaseStep = 0; 569 572 for (int idx = 0; idx < countSize; ++idx) 570 573 { 571 size_t index = globalIndexOfCurrentGridSourceToSend[idx] ;574 size_t index = globalIndexOfCurrentGridSourceToSend[idx].second; 572 575 if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index)) 573 576 { 574 577 size_t vectorSize = currentGridIndexToOriginalGridIndex_[index].size(); 575 sendOriginal IndexBuff[currentBuffPosition+increaseStep] = vectorSize;578 sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep] = vectorSize; 576 579 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (double)vectorSize; 577 const std::vector<std::pair< size_t,double> >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index];580 const std::vector<std::pair<int, std::pair<size_t,double> > >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index]; 578 581 for (size_t i = 0; i < vectorSize; ++i) 579 582 { 580 583 ++increaseStep; 581 sendOriginal IndexBuff[currentBuffPosition+increaseStep] = indexWeightPair[i].first;582 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = indexWeightPair[i].second;584 sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).first; 585 sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).second; 583 586 } 584 587 ++increaseStep; … … 586 589 } 587 590 588 currentOriginal IndexSendBuff = sendOriginalIndexBuff + currentBuffPosition;591 currentOriginalGlobalIndexSendBuff = sendOriginalGlobalIndexBuff + currentBuffPosition; 589 592 currentOriginalWeightSendBuff = sendOriginalWeightBuff + currentBuffPosition; 590 593 if (0 != increaseStep) 591 594 { 592 MPI_Isend(currentOriginalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX, client->intraComm, &requestsOriginalGrid[destRank]); 593 MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]); 595 MPI_Isend(currentOriginalGlobalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank, 596 MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &requestsOriginalGridGlobalIndex[destRank]); 597 MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank, 598 MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]); 594 599 } 595 600 currentBuffPosition += increaseStep; … … 598 603 599 604 // Receiving global index of grid source sending from current grid source 600 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv,601 605 CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv, 606 iteRecv = globalIndexToReceive.end(); 602 607 int recvBuffSize = 0; 603 608 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size(); … … 623 628 } 624 629 625 Scalar* recvOriginal IndexBuff, *currentOriginalIndexRecvBuff;626 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginal IndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize];630 Scalar* recvOriginalGlobalIndexBuff, *currentOriginalGlobalIndexRecvBuff; 631 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize]; 627 632 double* recvOriginalWeightBuff, *currentOriginalWeightRecvBuff; 628 633 if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalWeightBuff = new double [globalIndexOriginalSrcRecvBuffSize]; … … 633 638 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) 634 639 { 635 MPI_Status status Index, statusWeight;640 MPI_Status statusGlobalIndex, statusLocalIndex, statusWeight; 636 641 int srcRank = itRecv->first; 637 642 countBlock = countBlockMap[srcRank]; 638 currentOriginal IndexRecvBuff = recvOriginalIndexBuff + currentBuffPosition;643 currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff + currentBuffPosition; 639 644 currentOriginalWeightRecvBuff = recvOriginalWeightBuff + currentBuffPosition; 640 645 if (0 != countBlock) 641 646 { 642 MPI_Recv(currentOriginal IndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_INDEX, client->intraComm, &statusIndex);647 MPI_Recv(currentOriginalGlobalIndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &statusGlobalIndex); 643 648 MPI_Recv(currentOriginalWeightRecvBuff, countBlock, MPI_DOUBLE, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &statusWeight); 644 649 } … … 649 654 // The way to process masked index needs discussing 650 655 const size_t sfmax = NumTraits<unsigned long>::sfmax(); 651 GlobalIndexMap currentToOriginalTmp;656 DestinationIndexMap currentToOriginalTmp; 652 657 653 658 currentRecvBuffPosition = 0; 654 659 currentRecvBuff = recvBuff; 655 currentOriginal IndexRecvBuff = recvOriginalIndexBuff;660 currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff; 656 661 currentOriginalWeightRecvBuff = recvOriginalWeightBuff; 657 662 for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) … … 669 674 if (0 != countBlockRank) 670 675 { 671 countBlock = *(currentOriginal IndexRecvBuff+currentRecvBuffPosition);676 countBlock = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition); 672 677 for (int i = 0; i < ssize; ++i) 673 678 { 674 679 for (int j = 0; j < countBlock; ++j) 675 680 { 676 size_t globalOriginalIndex = *(currentOriginalIndexRecvBuff+currentRecvBuffPosition+j+1); 677 double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second; 678 currentToOriginalTmp[(itRecv->second)[idx][i].first].push_back(make_pair(globalOriginalIndex,weightGlobal)); 681 size_t globalOriginalIndex = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition+j+1); 682 int currentGridLocalIndex = (itRecv->second)[idx][i].first; 683 double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second.second; 684 currentToOriginalTmp[(itRecv->second)[idx][i].second.first].push_back(make_pair(currentGridLocalIndex,make_pair(globalOriginalIndex,weightGlobal))); 679 685 } 680 686 } … … 697 703 for (itRequest = requestsCurrentGrid.begin(); itRequest != requestsCurrentGrid.end(); ++itRequest) 698 704 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 699 for (itRequest = requestsOriginalGrid .begin(); itRequest != requestsOriginalGrid.end(); ++itRequest)705 for (itRequest = requestsOriginalGridGlobalIndex.begin(); itRequest != requestsOriginalGridGlobalIndex.end(); ++itRequest) 700 706 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 701 707 for (itRequest = requestsWeightGrid.begin(); itRequest != requestsWeightGrid.end(); ++itRequest) … … 704 710 if (0 != sendBuffSize) delete [] sendBuff; 705 711 if (0 != recvBuffSize) delete [] recvBuff; 706 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginal IndexBuff;712 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalGlobalIndexBuff; 707 713 if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalWeightBuff; 708 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginal IndexBuff;714 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalGlobalIndexBuff; 709 715 if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalWeightBuff; 710 716 } … … 724 730 transformationMap.computeTransformationMapping(currentGridIndexToOriginalGridIndex_); 725 731 726 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();727 const std::map<int,std::vector<size_t> >& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();728 729 CDistributionClient distributionClientDest(client->clientRank, gridDestination_);730 CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_);731 732 const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer();733 const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer();734 735 std::vector<size_t>::const_iterator itbArr, itArr, iteArr;736 std::vector<int>::const_iterator itIndex, itbIndex, iteIndex;737 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >::const_iterator itbMapRecv, itMapRecv, iteMapRecv;738 739 std::vector<int> permutIndex;740 typedef XIOSBinarySearchWithIndex<size_t> BinarySearch;741 742 // Find out local index on grid destination (received)743 XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex);744 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientDest, permutIndex);745 itbIndex = permutIndex.begin();746 iteIndex = permutIndex.end();747 BinarySearch searchClientDest(globalIndexOnClientDest);732 const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping(); 733 const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping(); 734 735 // CDistributionClient distributionClientDest(client->clientRank, gridDestination_); 736 // CDistributionClient distributionClientSrc(client->clientRank, originalGridSource_); 737 // 738 // const std::vector<size_t>& globalIndexOnClientDest = distributionClientDest.getGlobalDataIndexSendToServer(); 739 // const std::vector<size_t>& globalIndexOnClientSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); 740 741 // std::vector<size_t>::const_iterator itbArr, itArr, iteArr; 742 // std::vector<int>::const_iterator itIndex, itbIndex, iteIndex; 743 CTransformationMapping::ReceivedIndexMap::const_iterator itbMapRecv, itMapRecv, iteMapRecv; 744 745 // std::vector<int> permutIndex; 746 // typedef XIOSBinarySearchWithIndex<size_t> BinarySearch; 747 // 748 // // Find out local index on grid destination (received) 749 // XIOSAlgorithms::fillInIndex(globalIndexOnClientDest.size(), permutIndex); 750 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientDest, permutIndex); 751 // itbIndex = permutIndex.begin(); 752 // iteIndex = permutIndex.end(); 753 // BinarySearch searchClientDest(globalIndexOnClientDest); 748 754 itbMapRecv = globalIndexToReceive.begin(); 749 755 iteMapRecv = globalIndexToReceive.end(); … … 756 762 { 757 763 int vecSize = ((itMapRecv->second)[i]).size(); 758 std::vector<std::pair<int,double> > tmpVec;764 // std::vector<std::pair<int,double> > tmpVec; 759 765 for (int idx = 0; idx < vecSize; ++idx) 760 766 { 761 size_t globalIndex = (itMapRecv->second)[i][idx].first; 762 double weight = (itMapRecv->second)[i][idx].second; 763 if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 764 { 765 tmpVec.push_back(make_pair(*itIndex, weight)); 766 } 767 const std::pair<int, std::pair<size_t,double> >& tmpPair = (itMapRecv->second)[i][idx]; 768 localIndexToReceiveOnGridDest_[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second)); 769 // size_t globalIndex = (itMapRecv->second)[i][idx].first; 770 // double weight = (itMapRecv->second)[i][idx].second; 771 // if (searchClientDest.search(itbIndex, iteIndex, globalIndex, itIndex)) 772 // { 773 // tmpVec.push_back(make_pair(*itIndex, weight)); 774 // } 767 775 } 768 localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec;776 // localIndexToReceiveOnGridDest_[sourceRank][i] = tmpVec; 769 777 } 770 778 } 771 779 772 780 // Find out local index on grid source (to send) 773 std::map<int,std::vector<size_t> >::const_iterator itbMap, itMap, iteMap;774 XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex);775 XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientSrc, permutIndex);776 itbIndex = permutIndex.begin();777 iteIndex = permutIndex.end();778 BinarySearch searchClientSrc(globalIndexOnClientSrc);781 CTransformationMapping::SentIndexMap::const_iterator itbMap, itMap, iteMap; 782 // XIOSAlgorithms::fillInIndex(globalIndexOnClientSrc.size(), permutIndex); 783 // XIOSAlgorithms::sortWithIndex<size_t, CVectorStorage>(globalIndexOnClientSrc, permutIndex); 784 // itbIndex = permutIndex.begin(); 785 // iteIndex = permutIndex.end(); 786 // BinarySearch searchClientSrc(globalIndexOnClientSrc); 779 787 itbMap = globalIndexToSend.begin(); 780 788 iteMap = globalIndexToSend.end(); … … 786 794 for (int idx = 0; idx < vecSize; ++idx) 787 795 { 788 if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex))789 {790 localIndexToSendFromGridSource_[destRank](idx) = *itIndex;791 }796 // if (searchClientSrc.search(itbIndex, iteIndex, itMap->second[idx], itIndex)) 797 // { 798 localIndexToSendFromGridSource_[destRank](idx) = itMap->second[idx].first; //*itIndex; 799 // } 792 800 } 793 801 } -
XIOS/trunk/src/transformation/grid_transformation.hpp
r827 r829 35 35 public: 36 36 typedef std::list<std::pair<int,std::pair<ETranformationType,int> > > ListAlgoType; 37 typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 37 38 38 39 public: … … 63 64 void setUpGrid(int elementPositionInGrid, ETranformationType transType, int nbTransformation); 64 65 void computeFinalTransformationMapping(); 65 void computeTransformationFromOriginalGridSource(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource);66 void computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource); 66 67 void updateFinalGridDestination(); 67 68 bool isSpecialTransformation(ETranformationType transType); … … 84 85 int nbAlgos_; 85 86 86 typedef std::map<size_t, std::vector<std::pair<size_t,double> > > GlobalIndexMap;87 88 87 // true if domain algorithm and false if axis algorithm (can be replaced by tuple with listAlgos_ 89 88 std::vector<bool> algoTypes_; … … 105 104 106 105 //! (Grid) Global index of grid source 107 GlobalIndexMap currentGridIndexToOriginalGridIndex_;106 DestinationIndexMap currentGridIndexToOriginalGridIndex_; 108 107 109 108 std::vector<CGrid*> tempGrids_; -
XIOS/trunk/src/transformation/transformation_mapping.cpp
r668 r829 13 13 #include "context_client.hpp" 14 14 #include "distribution_client.hpp" 15 #include "client_client_dht_template.hpp" 16 #include "dht_data_types.hpp" 17 #include "mpi_tag.hpp" 15 18 16 19 namespace xios { … … 26 29 27 30 const std::vector<size_t>& globalIndexGridSrc = distributionClientSrc.getGlobalDataIndexSendToServer(); //gridSource_->getDistributionClient()->getGlobalDataIndexSendToServer(); 28 boost::unordered_map<size_t,int> globalIndexOfServer; 31 const std::vector<int>& localIndexGridSrc = distributionClientSrc.getLocalDataIndexSendToServer(); 32 33 // Mapping of global index and pair containing rank and local index 34 CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfServer; 29 35 int globalIndexSize = globalIndexGridSrc.size(); 36 PairIntInt pii; 30 37 for (int idx = 0; idx < globalIndexSize; ++idx) 31 38 { 32 globalIndexOfServer[globalIndexGridSrc[idx]] = clientRank; 33 } 34 35 gridIndexClientClientMapping_ = new CClientServerMappingDistributed(globalIndexOfServer, 36 client->intraComm, 37 true); 39 pii.first = clientRank; 40 pii.second = localIndexGridSrc[idx]; 41 globalIndexOfServer[globalIndexGridSrc[idx]] = pii; //std::make_pair(clientRank, localIndexGridSrc[idx]); 42 } 43 44 gridIndexClientClientMapping_ = new CClientClientDHTPairIntInt(globalIndexOfServer, 45 client->intraComm, 46 true); 38 47 } 39 48 … … 48 57 int ibeginSrc = source->begin.getValue(); 49 58 50 boost::unordered_map<size_t,int> globalIndexOfAxisSource; 59 CClientClientDHTPairIntInt::Index2InfoTypeMap globalIndexOfAxisSource; 60 PairIntInt pii; 51 61 for (int idx = 0; idx < niSrc; ++idx) 52 62 { 53 globalIndexOfAxisSource[idx+ibeginSrc] = clientRank; 54 } 55 56 gridIndexClientClientMapping_ = new CClientServerMappingDistributed(globalIndexOfAxisSource, 57 client->intraComm, 58 true); 63 pii.first = clientRank; 64 pii.second = idx; 65 globalIndexOfAxisSource[idx+ibeginSrc] = pii; //std::make_pair(clientRank,idx); 66 } 67 68 gridIndexClientClientMapping_ = new CClientClientDHTPairIntInt(globalIndexOfAxisSource, 69 client->intraComm, 70 true); 59 71 } 60 72 … … 71 83 \param [in] globaIndexWeightFromDestToSource mapping representing the transformations 72 84 */ 73 void CTransformationMapping::computeTransformationMapping(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexWeightFromDestToSource)85 void CTransformationMapping::computeTransformationMapping(const DestinationIndexMap& globaIndexWeightFromDestToSource) 74 86 { 75 87 CContext* context = CContext::getCurrent(); 76 88 CContextClient* client=context->client; 77 89 78 std::map<size_t, std::vector<std::pair<size_t,double> > >::const_iterator itbMap = globaIndexWeightFromDestToSource.begin(), itMap,79 90 DestinationIndexMap::const_iterator itbMap = globaIndexWeightFromDestToSource.begin(), itMap, 91 iteMap = globaIndexWeightFromDestToSource.end(); 80 92 81 93 // Not only one index on grid destination can demande two indexes from grid source 82 94 // but an index on grid source has to be sent to two indexes of grid destination 83 std::map<size_t, std::vector<std::pair<size_t,double> > > globalIndexMapFromSrcToDest; 84 std::vector<std::pair<size_t,double> >::const_iterator itbVecPair, itVecPair, iteVecPair; 95 DestinationIndexMap globalIndexMapFromSrcToDest; 96 boost::unordered_map<size_t, int> nbGlobalIndexMapFromSrcToDest; 97 std::vector<std::pair<int, std::pair<size_t,double> > >::const_iterator itbVecPair, itVecPair, iteVecPair; 85 98 for (itMap = itbMap; itMap != iteMap; ++itMap) 86 99 { … … 89 102 for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 90 103 { 91 globalIndexMapFromSrcToDest[itVecPair->first].push_back(std::make_pair(itMap->first, itVecPair->second)); 104 ++nbGlobalIndexMapFromSrcToDest[(itVecPair->second).first]; 105 } 106 } 107 108 for (boost::unordered_map<size_t, int>::const_iterator it = nbGlobalIndexMapFromSrcToDest.begin(); 109 it != nbGlobalIndexMapFromSrcToDest.end(); ++it) 110 { 111 globalIndexMapFromSrcToDest[it->first].reserve(it->second); 112 } 113 114 for (itMap = itbMap; itMap != iteMap; ++itMap) 115 { 116 itbVecPair = (itMap->second).begin(); 117 iteVecPair = (itMap->second).end(); 118 for (itVecPair = itbVecPair; itVecPair != iteVecPair; ++itVecPair) 119 { 120 globalIndexMapFromSrcToDest[(itVecPair->second).first].push_back(std::make_pair(itVecPair->first, std::make_pair(itMap->first, (itVecPair->second).second))); 92 121 } 93 122 } … … 95 124 // All global indexes of a client on grid destination 96 125 CArray<size_t,1> globalIndexMap(globalIndexMapFromSrcToDest.size()); 97 itbMap = globalIndexMapFromSrcToDest.begin();98 iteMap= globalIndexMapFromSrcToDest.end();126 DestinationIndexMap::const_iterator itbMapBoost = globalIndexMapFromSrcToDest.begin(), itMapBoost; 127 DestinationIndexMap::const_iterator iteMapBoost = globalIndexMapFromSrcToDest.end(); 99 128 int idx = 0; 100 for (itMap = itbMap; itMap != iteMap; ++itMap)101 { 102 globalIndexMap(idx) = itMap ->first;129 for (itMapBoost = itbMapBoost; itMapBoost != iteMapBoost; ++itMapBoost) 130 { 131 globalIndexMap(idx) = itMapBoost->first; 103 132 ++idx; 104 133 } 105 134 106 135 // Find out on which clients the necessary indexes of grid source are. 107 gridIndexClientClientMapping_->compute ServerIndexMapping(globalIndexMap);108 const std::map<int, std::vector<size_t> >& globalIndexSentFromGridSource = gridIndexClientClientMapping_->getGlobalIndexOnServer();109 std::map<int, std::vector<size_t> >::const_iterator itbMapSrc = globalIndexSentFromGridSource.begin(), itMapSrc,110 iteMapSrc = globalIndexSentFromGridSource.end();136 gridIndexClientClientMapping_->computeIndexInfoMapping(globalIndexMap); 137 const CClientClientDHTPairIntInt::Index2InfoTypeMap& globalIndexSentFromGridSource = gridIndexClientClientMapping_->getInfoIndexMap(); 138 CClientClientDHTPairIntInt::Index2InfoTypeMap::const_iterator itbMapSrc = globalIndexSentFromGridSource.begin(), itMapSrc, 139 iteMapSrc = globalIndexSentFromGridSource.end(); 111 140 std::vector<size_t>::const_iterator itbVec, itVec, iteVec; 141 // Inform client about the destination to which it needs to send global indexes 142 int nbClient = client->clientSize; 143 std::vector<int> sendNbClientBuff(nbClient,0); 144 std::vector<int> recvNbClientBuff(nbClient,0); 145 std::vector<int> sendIndexBuff(nbClient,0); 146 std::vector<int> recvIndexBuff(nbClient,0); 147 boost::unordered_map<int,std::vector<size_t> > sendIndexMap; 112 148 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) 113 149 { 114 int sourceRank = itMapSrc->first; 115 itbVec = (itMapSrc->second).begin(); 116 iteVec = (itMapSrc->second).end(); 117 for (itVec = itbVec; itVec != iteVec; ++itVec) 118 { 119 (globalIndexReceivedOnGridDestMapping_[sourceRank]).push_back(globalIndexMapFromSrcToDest[*itVec]); 120 } 121 } 122 123 // Inform client about the destination to which it needs to send global indexes 124 int nbClient = client->clientSize; 125 int* sendBuff = new int[nbClient]; 126 int* recvBuff = new int[nbClient]; 127 for (int i = 0; i < nbClient; ++i) sendBuff[i] = 0; 128 129 // First of all, inform the number of destination a client needs to send global index 130 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) sendBuff[itMapSrc->first] = 1; 131 MPI_Allreduce(sendBuff, recvBuff, nbClient, MPI_INT, MPI_SUM, client->intraComm); 132 int numClientToReceive = recvBuff[client->clientRank]; 150 int sourceRank = (itMapSrc->second).first; 151 (globalIndexReceivedOnGridDestMapping_[sourceRank]).push_back(globalIndexMapFromSrcToDest[itMapSrc->first]); 152 sendIndexMap[sourceRank].push_back((itMapSrc->second).second); 153 sendIndexMap[sourceRank].push_back(itMapSrc->first); 154 sendNbClientBuff[sourceRank] = 1; 155 ++sendIndexBuff[sourceRank]; 156 } 157 158 MPI_Allreduce(&sendNbClientBuff[0], &recvNbClientBuff[0], nbClient, MPI_INT, MPI_SUM, client->intraComm); 159 int numClientToReceive = recvNbClientBuff[client->clientRank]; 133 160 134 161 // Then specify the size of receiving buffer, because we use synch send/receive so only necessary to know maximum size 135 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) sendBuff[itMapSrc->first] = (itMapSrc->second).size(); 136 MPI_Allreduce(sendBuff, recvBuff, nbClient, MPI_INT, MPI_MAX, client->intraComm); 137 138 int buffSize = recvBuff[client->clientRank]; 162 MPI_Allreduce(&sendIndexBuff[0], &recvIndexBuff[0], nbClient, MPI_INT, MPI_MAX, client->intraComm); 163 int buffSize = 2*recvIndexBuff[client->clientRank]; // we send global as well as local index 139 164 unsigned long* recvBuffGlobalIndex; 140 165 if (0 != buffSize) recvBuffGlobalIndex = new unsigned long [buffSize]; … … 143 168 144 169 // Inform all "source clients" about index that they need to send 145 for (itMapSrc = itbMapSrc; itMapSrc != iteMapSrc; ++itMapSrc) 146 { 147 unsigned long* sendPtr = const_cast<unsigned long*>(&(itMapSrc->second)[0]); 170 boost::unordered_map<int,std::vector<size_t> >::const_iterator itSendIndex = sendIndexMap.begin(), 171 iteSendIndex= sendIndexMap.end(); 172 for (; itSendIndex != iteSendIndex; ++itSendIndex) 173 { 174 unsigned long* sendPtr = const_cast<unsigned long*>(&(itSendIndex->second)[0]); 148 175 MPI_Isend(sendPtr, 149 (it MapSrc->second).size(),176 (itSendIndex->second).size(), 150 177 MPI_UNSIGNED_LONG, 151 itMapSrc->first,152 11,178 (itSendIndex->first), 179 MPI_TRANSFORMATION_MAPPING_INDEX, 153 180 client->intraComm, 154 &requests[ itMapSrc->first]);181 &requests[(itSendIndex->first)]); 155 182 } 156 183 … … 165 192 MPI_UNSIGNED_LONG, 166 193 MPI_ANY_SOURCE, 167 11,194 MPI_TRANSFORMATION_MAPPING_INDEX, 168 195 client->intraComm, 169 196 &status); … … 171 198 MPI_Get_count(&status, MPI_UNSIGNED_LONG, &countBuff); 172 199 int clientDestRank = status.MPI_SOURCE; 173 for (int idx = 0; idx < countBuff; ++idx)200 for (int idx = 0; idx < countBuff; idx += 2) 174 201 { 175 globalIndexSendToGridDestMapping_[clientDestRank].push_back( recvBuffGlobalIndex[idx]);202 globalIndexSendToGridDestMapping_[clientDestRank].push_back(std::make_pair<int,size_t>(recvBuffGlobalIndex[idx], recvBuffGlobalIndex[idx+1])); 176 203 } 177 204 ++numClientReceived; … … 182 209 MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE); 183 210 184 delete [] sendBuff;185 delete [] recvBuff;186 211 if (0 != buffSize) delete [] recvBuffGlobalIndex; 187 212 } … … 192 217 \return global index mapping to receive on grid destination 193 218 */ 194 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& CTransformationMapping::getGlobalIndexReceivedOnGridDestMapping() const219 const CTransformationMapping::ReceivedIndexMap& CTransformationMapping::getGlobalIndexReceivedOnGridDestMapping() const 195 220 { 196 221 return globalIndexReceivedOnGridDestMapping_; … … 202 227 \return global index mapping to send on grid source 203 228 */ 204 const std::map<int,std::vector<size_t> >& CTransformationMapping::getGlobalIndexSendToGridDestMapping() const229 const CTransformationMapping::SentIndexMap& CTransformationMapping::getGlobalIndexSendToGridDestMapping() const 205 230 { 206 231 return globalIndexSendToGridDestMapping_; -
XIOS/trunk/src/transformation/transformation_mapping.hpp
r630 r829 28 28 { 29 29 public: 30 typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap; 31 typedef boost::unordered_map<int,std::vector<std::vector<std::pair<int, std::pair<size_t,double> > > > > ReceivedIndexMap; 32 typedef boost::unordered_map<int,std::vector<std::pair<int, size_t> > > SentIndexMap; 33 34 public: 30 35 /** Default constructor */ 31 36 CTransformationMapping(CGrid* destination, CGrid* source); … … 34 39 ~CTransformationMapping(); 35 40 36 void computeTransformationMapping(const std::map<size_t, std::vector<std::pair<size_t,double> > >& globaIndexMapFromDestToSource);37 const std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >& getGlobalIndexReceivedOnGridDestMapping() const;38 const std::map<int,std::vector<size_t> >& getGlobalIndexSendToGridDestMapping() const;41 void computeTransformationMapping(const DestinationIndexMap& globaIndexMapFromDestToSource); 42 const ReceivedIndexMap& getGlobalIndexReceivedOnGridDestMapping() const; 43 const SentIndexMap& getGlobalIndexSendToGridDestMapping() const; 39 44 40 45 protected: … … 43 48 44 49 //! Global index mapping of grid source and grid destination between two clients 45 CClient ServerMappingDistributed* gridIndexClientClientMapping_;50 CClientClientDHTPairIntInt* gridIndexClientClientMapping_; 46 51 47 52 //! Mapping of client rank of grid source and global index received in grid destination 48 std::map<int,std::vector<std::vector<std::pair<size_t,double> > > >globalIndexReceivedOnGridDestMapping_;53 ReceivedIndexMap globalIndexReceivedOnGridDestMapping_; 49 54 50 55 //! Mapping of client rank of grid destination and global index to send from grid source 51 std::map<int,std::vector<size_t> >globalIndexSendToGridDestMapping_;56 SentIndexMap globalIndexSendToGridDestMapping_; 52 57 }; 53 58
Note: See TracChangeset
for help on using the changeset viewer.