Index: /XIOS/trunk/src/filter/spatial_transform_filter.cpp
===================================================================
--- /XIOS/trunk/src/filter/spatial_transform_filter.cpp	(revision 840)
+++ /XIOS/trunk/src/filter/spatial_transform_filter.cpp	(revision 841)
@@ -100,74 +100,100 @@
     CContextClient* client = CContext::getCurrent()->client;
 
-    const std::map<int, CArray<int,1> >& localIndexToSend = gridTransformation->getLocalIndexToSendFromGridSource();
-    const std::map<int, std::vector<std::vector<std::pair<int,double> > > >& localIndexToReceive = gridTransformation->getLocalIndexToReceiveOnGridDest();
+    const std::list<CGridTransformation::SendingIndexGridSourceMap>& listLocalIndexSend = gridTransformation->getLocalIndexToSendFromGridSource();
+    const std::list<CGridTransformation::RecvIndexGridDestinationMap>& listLocalIndexToReceive = gridTransformation->getLocalIndexToReceiveOnGridDest();
+    const std::list<size_t>& listNbLocalIndexToReceive = gridTransformation->getNbLocalIndexToReceiveOnGridDest();
 
-    dataDest = 0.0;
+    CArray<double,1> dataCurrentDest(dataSrc.copy());
 
-    // Sending data from field sources to do transformations
-    std::map<int, CArray<int,1> >::const_iterator itbSend = localIndexToSend.begin(), itSend,
-                                                  iteSend = localIndexToSend.end();
-    int idxSendBuff = 0;
-    std::vector<double*> sendBuff(localIndexToSend.size());
-    for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
+    std::list<CGridTransformation::SendingIndexGridSourceMap>::const_iterator itListSend  = listLocalIndexSend.begin(),
+                                                                              iteListSend = listLocalIndexSend.end();
+    std::list<CGridTransformation::RecvIndexGridDestinationMap>::const_iterator itListRecv = listLocalIndexToReceive.begin();
+    std::list<size_t>::const_iterator itNbListRecv = listNbLocalIndexToReceive.begin();
+
+    for (; itListSend != iteListSend; ++itListSend, ++itListRecv, ++itNbListRecv)
     {
-      if (0 != itSend->second.numElements())
-        sendBuff[idxSendBuff] = new double[itSend->second.numElements()];
+      CArray<double,1> dataCurrentSrc(dataCurrentDest);
+      const CGridTransformation::SendingIndexGridSourceMap& localIndexToSend = *itListSend;
+
+      // Sending data from field sources to do transformations
+      std::map<int, CArray<int,1> >::const_iterator itbSend = localIndexToSend.begin(), itSend,
+                                                    iteSend = localIndexToSend.end();
+      int idxSendBuff = 0;
+      std::vector<double*> sendBuff(localIndexToSend.size());
+      for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
+      {
+        if (0 != itSend->second.numElements())
+          sendBuff[idxSendBuff] = new double[itSend->second.numElements()];
+      }
+
+      idxSendBuff = 0;
+      std::vector<MPI_Request> sendRecvRequest;
+      for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
+      {
+        int destRank = itSend->first;
+        const CArray<int,1>& localIndex_p = itSend->second;
+        int countSize = localIndex_p.numElements();
+        for (int idx = 0; idx < countSize; ++idx)
+        {
+          sendBuff[idxSendBuff][idx] = dataCurrentSrc(localIndex_p(idx));
+        }
+        sendRecvRequest.push_back(MPI_Request());
+        MPI_Isend(sendBuff[idxSendBuff], countSize, MPI_DOUBLE, destRank, 12, client->intraComm, &sendRecvRequest.back());
+      }
+
+      // Receiving data on destination fields
+      const CGridTransformation::RecvIndexGridDestinationMap& localIndexToReceive = *itListRecv;
+      CGridTransformation::RecvIndexGridDestinationMap::const_iterator itbRecv = localIndexToReceive.begin(), itRecv,
+                                                                       iteRecv = localIndexToReceive.end();
+      int recvBuffSize = 0;
+      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += itRecv->second.size(); //(recvBuffSize < itRecv->second.size())
+                                                                       //? itRecv->second.size() : recvBuffSize;
+      double* recvBuff;
+      if (0 != recvBuffSize) recvBuff = new double[recvBuffSize];
+      int currentBuff = 0;
+      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
+      {
+        int srcRank = itRecv->first;
+        int countSize = itRecv->second.size();
+        sendRecvRequest.push_back(MPI_Request());
+        MPI_Irecv(recvBuff + currentBuff, countSize, MPI_DOUBLE, srcRank, 12, client->intraComm, &sendRecvRequest.back());
+        currentBuff += countSize;
+      }
+      std::vector<MPI_Status> status(sendRecvRequest.size());
+      MPI_Waitall(sendRecvRequest.size(), &sendRecvRequest[0], &status[0]);
+
+      dataCurrentDest.resize(*itNbListRecv);
+      dataCurrentDest = 0.0;
+      currentBuff = 0;
+      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
+      {
+        int countSize = itRecv->second.size();
+        for (int idx = 0; idx < countSize; ++idx)
+        {
+          const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second[idx];
+          int numIndex = localIndex_p.size();
+          for (int i = 0; i < numIndex; ++i)
+          {
+            dataCurrentDest(localIndex_p[i].first) += *(recvBuff+currentBuff+idx) * localIndex_p[i].second;
+          }
+        }
+        currentBuff += countSize;
+      }
+
+      idxSendBuff = 0;
+      for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
+      {
+        if (0 != itSend->second.numElements())
+          delete [] sendBuff[idxSendBuff];
+      }
+      if (0 != recvBuffSize) delete [] recvBuff;
     }
+    if (dataCurrentDest.numElements() != dataDest.numElements())
+    ERROR("CSpatialTransformFilterEngine::apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest)",
+          "Incoherent between the received size and expected size" <<
+          "Expected size: " << dataDest.numElements() <<
+          "Received size: " << dataCurrentDest.numElements());
 
-    idxSendBuff = 0;
-    std::vector<MPI_Request> sendRequest;
-    for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
-    {
-      int destRank = itSend->first;
-      const CArray<int,1>& localIndex_p = itSend->second;
-      int countSize = localIndex_p.numElements();
-      for (int idx = 0; idx < countSize; ++idx)
-      {
-        sendBuff[idxSendBuff][idx] = dataSrc(localIndex_p(idx));
-      }
-      sendRequest.push_back(MPI_Request());
-      MPI_Isend(sendBuff[idxSendBuff], countSize, MPI_DOUBLE, destRank, 12, client->intraComm, &sendRequest.back());
-    }
-
-    // Receiving data on destination fields
-    std::map<int,std::vector<std::vector<std::pair<int,double> > > >::const_iterator itbRecv = localIndexToReceive.begin(), itRecv,
-                                                                                     iteRecv = localIndexToReceive.end();
-    int recvBuffSize = 0;
-    for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize = (recvBuffSize < itRecv->second.size())
-                                                                     ? itRecv->second.size() : recvBuffSize;
-    double* recvBuff;
-    if (0 != recvBuffSize) recvBuff = new double[recvBuffSize];
-    for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
-    {
-      MPI_Status status;
-      int srcRank = itRecv->first;
-      int countSize = itRecv->second.size();
-      MPI_Recv(recvBuff, recvBuffSize, MPI_DOUBLE, srcRank, 12, client->intraComm, &status);
-      int countBuff = 0;
-      MPI_Get_count(&status, MPI_DOUBLE, &countBuff);
-      if (countBuff != countSize)
-        ERROR("CSpatialTransformFilterEngine::apply(const CArray<double, 1>& dataSrc, CArray<double,1>& dataDest)",
-              "Incoherent between the received size and expected size");
-      for (int idx = 0; idx < countSize; ++idx)
-      {
-        const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second[idx];
-        int numIndex = localIndex_p.size();
-        for (int i = 0; i < numIndex; ++i)
-        {
-          dataDest(localIndex_p[i].first) += recvBuff[idx] * localIndex_p[i].second;
-        }
-      }
-    }
-
-
-    if (!sendRequest.empty()) MPI_Waitall(sendRequest.size(), &sendRequest[0], MPI_STATUSES_IGNORE);
-    idxSendBuff = 0;
-    for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
-    {
-      if (0 != itSend->second.numElements())
-        delete [] sendBuff[idxSendBuff];
-    }
-    if (0 != recvBuffSize) delete [] recvBuff;
+    dataDest = dataCurrentDest;
   }
 } // namespace xios
Index: /XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp
===================================================================
--- /XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp	(revision 840)
+++ /XIOS/trunk/src/transformation/generic_algorithm_transformation.cpp	(revision 841)
@@ -83,8 +83,9 @@
       {
         size_t srcGridSize = globalIndexSrcGrid[idx].size();
-        globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize);
+//        globaIndexWeightFromDestToSource[(it->first)].reserve(srcGridSize);
+        globaIndexWeightFromDestToSource[(it->first)].resize(srcGridSize);
         for (int i = 0; i < srcGridSize; ++i)
         {
-          globaIndexWeightFromDestToSource[(it->first)].push_back(make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i])));
+          globaIndexWeightFromDestToSource[(it->first)][i] = (make_pair(it->second, make_pair(globalIndexSrcGrid[idx][i], currentVecWeight[i])));
         }
       }
Index: /XIOS/trunk/src/transformation/grid_transformation.cpp
===================================================================
--- /XIOS/trunk/src/transformation/grid_transformation.cpp	(revision 840)
+++ /XIOS/trunk/src/transformation/grid_transformation.cpp	(revision 841)
@@ -410,327 +410,29 @@
                                      globaIndexWeightFromDestToSource);
 
+      // Compute transformation of global indexes among grids
+      computeTransformationMapping(globaIndexWeightFromDestToSource);
+
       if (1 < nbAlgos_)
       {
-        // Compute transformation of global indexes among grids
-        computeTransformationFromOriginalGridSource(globaIndexWeightFromDestToSource);
-
         // Now grid destination becomes grid source in a new transformation
         if (nbAgloTransformation != (nbAlgos_-1)) setUpGrid(elementPositionInGrid, transType, nbAgloTransformation);
       }
-      else
-      {
-        currentGridIndexToOriginalGridIndex_.swap(globaIndexWeightFromDestToSource);
-      }
-
       ++nbAgloTransformation;
     }
   }
-
-  if (0 != nbAgloTransformation)
-  {
-    updateFinalGridDestination();
-    computeFinalTransformationMapping();
-  }
-}
-
-
-/*!
-  After applying the algorithms, there are some informations on grid destination needing change, for now, there are:
-   +) mask
-*/
-void CGridTransformation::updateFinalGridDestination()
+}
+
+/*!
+  Compute exchange index between grid source and grid destination
+  \param [in] globalIndexWeightFromDestToSource global index mapping between grid destination and grid source
+*/
+void CGridTransformation::computeTransformationMapping(const DestinationIndexMap& globalIndexWeightFromDestToSource)
 {
   CContext* context = CContext::getCurrent();
   CContextClient* client = context->client;
 
-  //First of all, retrieve info of local mask of grid destination
-  CDistributionClient distributionClientDest(client->clientRank, gridDestination_);
-  const std::vector<int>& localMaskIndexOnClientDest = distributionClientDest.getLocalMaskIndexOnClient();
-  const CDistributionClient::GlobalLocalDataMap& globalIndexOnClientDest = distributionClientDest.getGlobalLocalDataSendToServer();
-
-  CDistributionClient::GlobalLocalDataMap::const_iterator itbArr, itArr, iteArr;
-  itbArr = globalIndexOnClientDest.begin();
-  iteArr = globalIndexOnClientDest.end();
-
-  DestinationIndexMap::const_iterator iteGlobalMap = currentGridIndexToOriginalGridIndex_.end();
-  const size_t sfmax = NumTraits<unsigned long>::sfmax();
-  int maskIndexNum = 0;
-  for (itArr = itbArr; itArr != iteArr; ++itArr)
-  {
-    if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(itArr->first))
-    {
-      const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[itArr->first];
-      for (int idx = 0; idx < vecIndex.size(); ++idx)
-      {
-        if (sfmax == (vecIndex[idx].second).first)
-        {
-          ++maskIndexNum;
-          break;
-        }
-      }
-    }
-  }
-
-  CArray<int,1> maskIndexToModify(maskIndexNum);
-  maskIndexNum = 0;
-  for (itArr = itbArr; itArr != iteArr; ++itArr)
-  {
-    if (iteGlobalMap != currentGridIndexToOriginalGridIndex_.find(itArr->first))
-    {
-      const std::vector<std::pair<int, std::pair<size_t,double> > >& vecIndex = currentGridIndexToOriginalGridIndex_[itArr->first];
-      for (int idx = 0; idx < vecIndex.size(); ++idx)
-      {
-        if (sfmax == (vecIndex[idx].second).first)
-        {
-          int localIdx = std::distance(itbArr, itArr);
-          maskIndexToModify(maskIndexNum) = localMaskIndexOnClientDest[localIdx];
-          ++maskIndexNum;
-          break;
-        }
-      }
-    }
-  }
-
-  gridDestination_->modifyMask(maskIndexToModify);
-}
-
-/*!
-  A transformation from a grid source to grid destination often passes several intermediate grids, which play a role of
-temporary grid source and/or grid destination. This function makes sure that global index of original grid source are mapped correctly to
-the final grid destination
-*/
-void CGridTransformation::computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource)
-{
-  CContext* context = CContext::getCurrent();
-  CContextClient* client = context->client;
-
-  if (currentGridIndexToOriginalGridIndex_.empty())
-  {
-    currentGridIndexToOriginalGridIndex_ = globaIndexMapFromDestToSource;
-    return;
-  }
-
   CTransformationMapping transformationMap(gridDestination_, gridSource_);
 
-    // Then compute transformation mapping among clients
-  transformationMap.computeTransformationMapping(globaIndexMapFromDestToSource);
-
-  const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();
-  const CTransformationMapping::SentIndexMap& globalIndexToSend = transformationMap.getGlobalIndexSendToGridDestMapping();
-
- // Sending global index of original grid source
-  CTransformationMapping::SentIndexMap::const_iterator itbSend = globalIndexToSend.begin(), itSend,
-                                                       iteSend = globalIndexToSend.end();
- int sendBuffSize = 0;
- for (itSend = itbSend; itSend != iteSend; ++itSend) sendBuffSize += (itSend->second).size();
- // We use the first element of each block to send number of element in this block
- sendBuffSize += globalIndexToSend.size();
-
-
- typedef unsigned long Scalar;
- Scalar* sendBuff, *currentSendBuff;
- if (0 != sendBuffSize) sendBuff = new Scalar [sendBuffSize];
- for (StdSize idx = 0; idx < sendBuffSize; ++idx) sendBuff[idx] = NumTraits<Scalar>::sfmax();
-
- std::map<int, MPI_Request> requestsCurrentGrid, requestsOriginalGridGlobalIndex, requestsOriginalGridLocalIndex, requestsWeightGrid;
- DestinationIndexMap::const_iterator iteGlobalIndex = currentGridIndexToOriginalGridIndex_.end();
-
-  // Only send global index of original source corresponding to non-masked index
-  // Use first position of each block to specify the number of elemnt in this block
- int globalIndexOriginalSrcSendBuffSize = 0;
- int currentBuffPosition = 0;
- for (itSend = itbSend; itSend != iteSend; ++itSend)
- {
-   int destRank = itSend->first;
-   const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second;
-   int countSize  = globalIndexOfCurrentGridSourceToSend.size();
-   size_t countBlock = 0;
-   for (int idx = 0; idx < countSize; ++idx)
-   {
-     size_t index = globalIndexOfCurrentGridSourceToSend[idx].second;
-     if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index))
-     {
-       globalIndexOriginalSrcSendBuffSize += currentGridIndexToOriginalGridIndex_[index].size() + 1; // 1 for number of elements in this block
-       sendBuff[idx+currentBuffPosition+1] = index;
-       countBlock += currentGridIndexToOriginalGridIndex_[index].size() + 1;
-     }
-   }
-   sendBuff[currentBuffPosition] = countBlock;
-   currentSendBuff = sendBuff + currentBuffPosition;
-   MPI_Isend(currentSendBuff, countSize +1, MPI_UNSIGNED_LONG, destRank, MPI_GRID_TRANSFORMATION_CURRENT_GRID_INDEX, client->intraComm, &requestsCurrentGrid[destRank]);
-   currentBuffPosition += countSize + 1;
- }
-
- Scalar* sendOriginalGlobalIndexBuff, *currentOriginalGlobalIndexSendBuff;
- if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcSendBuffSize];
- double* sendOriginalWeightBuff, *currentOriginalWeightSendBuff;
- if (0 != globalIndexOriginalSrcSendBuffSize) sendOriginalWeightBuff = new double [globalIndexOriginalSrcSendBuffSize];
-
- currentBuffPosition = 0;
- for (itSend = itbSend; itSend != iteSend; ++itSend)
- {
-   int destRank = itSend->first;
-   const std::vector<std::pair<int, size_t> >& globalIndexOfCurrentGridSourceToSend = itSend->second;
-   int countSize = globalIndexOfCurrentGridSourceToSend.size();
-   int increaseStep = 0;
-   for (int idx = 0; idx < countSize; ++idx)
-   {
-     size_t index = globalIndexOfCurrentGridSourceToSend[idx].second;
-     if (iteGlobalIndex != currentGridIndexToOriginalGridIndex_.find(index))
-     {
-       size_t vectorSize = currentGridIndexToOriginalGridIndex_[index].size();
-       sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep]  = vectorSize;
-       sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (double)vectorSize;
-       const std::vector<std::pair<int, std::pair<size_t,double> > >& indexWeightPair = currentGridIndexToOriginalGridIndex_[index];
-       for (size_t i = 0; i < vectorSize; ++i)
-       {
-         ++increaseStep;
-         sendOriginalGlobalIndexBuff[currentBuffPosition+increaseStep]  = (indexWeightPair[i].second).first;
-         sendOriginalWeightBuff[currentBuffPosition+increaseStep] = (indexWeightPair[i].second).second;
-       }
-       ++increaseStep;
-     }
-   }
-
-   currentOriginalGlobalIndexSendBuff = sendOriginalGlobalIndexBuff + currentBuffPosition;
-   currentOriginalWeightSendBuff = sendOriginalWeightBuff + currentBuffPosition;
-   if (0 != increaseStep)
-   {
-     MPI_Isend(currentOriginalGlobalIndexSendBuff, increaseStep, MPI_UNSIGNED_LONG, destRank,
-               MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &requestsOriginalGridGlobalIndex[destRank]);
-     MPI_Isend(currentOriginalWeightSendBuff, increaseStep, MPI_DOUBLE, destRank,
-               MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &requestsWeightGrid[destRank]);
-   }
-   currentBuffPosition += increaseStep;
- }
-
-
- // Receiving global index of grid source sending from current grid source
- CTransformationMapping::ReceivedIndexMap::const_iterator itbRecv = globalIndexToReceive.begin(), itRecv,
-                                                          iteRecv = globalIndexToReceive.end();
- int recvBuffSize = 0;
- for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += (itRecv->second).size();
- recvBuffSize += globalIndexToReceive.size();
-
- Scalar* recvBuff, *currentRecvBuff;
- if (0 != recvBuffSize) recvBuff = new Scalar [recvBuffSize];
- for (StdSize idx = 0; idx < recvBuffSize; ++idx) recvBuff[idx] = NumTraits<Scalar>::sfmax();
-
- std::map<int,int> countBlockMap;
- int globalIndexOriginalSrcRecvBuffSize = 0;
- int currentRecvBuffPosition = 0;
- for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
- {
-   MPI_Status status;
-   int srcRank = itRecv->first;
-   int countSize = (itRecv->second).size();
-   currentRecvBuff = recvBuff + currentRecvBuffPosition;
-   MPI_Recv(currentRecvBuff, countSize +1, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_CURRENT_GRID_INDEX, client->intraComm, &status);
-   globalIndexOriginalSrcRecvBuffSize += *currentRecvBuff;
-   countBlockMap[srcRank] = *currentRecvBuff;
-   currentRecvBuffPosition += countSize +1;
- }
-
- Scalar* recvOriginalGlobalIndexBuff, *currentOriginalGlobalIndexRecvBuff;
- if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalGlobalIndexBuff = new Scalar [globalIndexOriginalSrcRecvBuffSize];
- double* recvOriginalWeightBuff, *currentOriginalWeightRecvBuff;
- if (0 != globalIndexOriginalSrcRecvBuffSize) recvOriginalWeightBuff = new double [globalIndexOriginalSrcRecvBuffSize];
-
- int countBlock = 0;
- currentRecvBuffPosition = 0;
- currentBuffPosition = 0;
- for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
- {
-   MPI_Status statusGlobalIndex, statusLocalIndex, statusWeight;
-   int srcRank = itRecv->first;
-   countBlock = countBlockMap[srcRank];
-   currentOriginalGlobalIndexRecvBuff = recvOriginalGlobalIndexBuff + currentBuffPosition;
-   currentOriginalWeightRecvBuff = recvOriginalWeightBuff + currentBuffPosition;
-   if (0 != countBlock)
-   {
-     MPI_Recv(currentOriginalGlobalIndexRecvBuff, countBlock, MPI_UNSIGNED_LONG, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_GLOBAL_INDEX, client->intraComm, &statusGlobalIndex);
-     MPI_Recv(currentOriginalWeightRecvBuff, countBlock, MPI_DOUBLE, srcRank, MPI_GRID_TRANSFORMATION_ORIGINAL_GRID_WEIGHT, client->intraComm, &statusWeight);
-   }
-   currentBuffPosition += countBlock;
- }
-
- // We process everything in here, even case of masked index
- // The way to process masked index needs discussing
- const size_t sfmax = NumTraits<unsigned long>::sfmax();
- DestinationIndexMap currentToOriginalTmp;
-
- currentRecvBuffPosition = 0;
- currentRecvBuff = recvBuff;
- currentOriginalGlobalIndexRecvBuff  = recvOriginalGlobalIndexBuff;
- currentOriginalWeightRecvBuff = recvOriginalWeightBuff;
- for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
- {
-   int countBlockRank = countBlockMap[itRecv->first];
-
-   ++currentRecvBuff;  // it's very subtle here, pay attention
-   int countSize = (itRecv->second).size();
-   for (int idx = 0; idx < countSize; ++idx)
-   {
-      ++currentRecvBuff;
-     int ssize = (itRecv->second)[idx].size();
-     if (sfmax != *currentRecvBuff)
-     {
-       if (0 != countBlockRank)
-       {
-         countBlock = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition);
-         for (int i = 0; i < ssize; ++i)
-         {
-           for (int j = 0; j < countBlock; ++j)
-           {
-             size_t globalOriginalIndex = *(currentOriginalGlobalIndexRecvBuff+currentRecvBuffPosition+j+1);
-             int currentGridLocalIndex = (itRecv->second)[idx][i].first;
-             double weightGlobal = *(currentOriginalWeightRecvBuff+currentRecvBuffPosition+j+1) * (itRecv->second)[idx][i].second.second;
-             currentToOriginalTmp[(itRecv->second)[idx][i].second.first].push_back(make_pair(currentGridLocalIndex,make_pair(globalOriginalIndex,weightGlobal)));
-           }
-         }
-         currentRecvBuffPosition += countBlock+1;
-       }
-     }
-//     else
-//     {
-//       for (int i = 0; i < ssize; ++i)
-//       {
-//         currentToOriginalTmp[(itRecv->second)[idx][i].first].push_back(make_pair(sfmax,1.0));
-//       }
-//     }
-   }
- }
-
- currentGridIndexToOriginalGridIndex_.swap(currentToOriginalTmp);
-
- std::map<int, MPI_Request>::iterator itRequest;
- for (itRequest = requestsCurrentGrid.begin(); itRequest != requestsCurrentGrid.end(); ++itRequest)
-   MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE);
- for (itRequest = requestsOriginalGridGlobalIndex.begin(); itRequest != requestsOriginalGridGlobalIndex.end(); ++itRequest)
-   MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE);
- for (itRequest = requestsWeightGrid.begin(); itRequest != requestsWeightGrid.end(); ++itRequest)
-   MPI_Wait(&itRequest->second, MPI_STATUS_IGNORE);
-
- if (0 != sendBuffSize) delete [] sendBuff;
- if (0 != recvBuffSize) delete [] recvBuff;
- if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalGlobalIndexBuff;
- if (0 != globalIndexOriginalSrcSendBuffSize) delete [] sendOriginalWeightBuff;
- if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalGlobalIndexBuff;
- if (0 != globalIndexOriginalSrcRecvBuffSize) delete [] recvOriginalWeightBuff;
-}
-
-/*!
-  Compute transformation mapping between grid source and grid destination
-  The transformation between grid source and grid destination is represented in form of mapping between global index
-of two grids. Then local index mapping between data on each grid will be found out thanks to these global indexes
-*/
-void CGridTransformation::computeFinalTransformationMapping()
-{
-  CContext* context = CContext::getCurrent();
-  CContextClient* client = context->client;
-
-  CTransformationMapping transformationMap(gridDestination_, originalGridSource_);
-
-  transformationMap.computeTransformationMapping(currentGridIndexToOriginalGridIndex_);
+  transformationMap.computeTransformationMapping(globalIndexWeightFromDestToSource);
 
   const CTransformationMapping::ReceivedIndexMap& globalIndexToReceive = transformationMap.getGlobalIndexReceivedOnGridDestMapping();
@@ -738,9 +440,12 @@
   itbMapRecv = globalIndexToReceive.begin();
   iteMapRecv = globalIndexToReceive.end();
+  nbLocalIndexOnGridDest_.push_back(globalIndexWeightFromDestToSource.size());
+  localIndexToReceiveOnGridDest_.push_back(RecvIndexGridDestinationMap());
+  RecvIndexGridDestinationMap& recvTmp = localIndexToReceiveOnGridDest_.back();
   for (itMapRecv = itbMapRecv; itMapRecv != iteMapRecv; ++itMapRecv)
   {
     int sourceRank = itMapRecv->first;
     int numGlobalIndex = (itMapRecv->second).size();
-    localIndexToReceiveOnGridDest_[sourceRank].resize(numGlobalIndex);
+    recvTmp[sourceRank].resize(numGlobalIndex);
     for (int i = 0; i < numGlobalIndex; ++i)
     {
@@ -749,5 +454,5 @@
       {
         const std::pair<int, std::pair<size_t,double> >& tmpPair = (itMapRecv->second)[i][idx];
-        localIndexToReceiveOnGridDest_[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second));
+        recvTmp[sourceRank][i].push_back(make_pair(tmpPair.first, tmpPair.second.second));
       }
     }
@@ -759,12 +464,14 @@
   itbMap = globalIndexToSend.begin();
   iteMap = globalIndexToSend.end();
+  localIndexToSendFromGridSource_.push_back(SendingIndexGridSourceMap());
+  SendingIndexGridSourceMap& tmpSend = localIndexToSendFromGridSource_.back();
   for (itMap = itbMap; itMap != iteMap; ++itMap)
   {
     int destRank = itMap->first;
     int vecSize = itMap->second.size();
-    localIndexToSendFromGridSource_[destRank].resize(vecSize);
+    tmpSend[destRank].resize(vecSize);
     for (int idx = 0; idx < vecSize; ++idx)
     {
-      localIndexToSendFromGridSource_[destRank](idx) = itMap->second[idx].first;
+      tmpSend[destRank](idx) = itMap->second[idx].first;
     }
   }
@@ -791,5 +498,5 @@
   \return local index of data
 */
-const std::map<int, CArray<int,1> >& CGridTransformation::getLocalIndexToSendFromGridSource() const
+const std::list<CGridTransformation::SendingIndexGridSourceMap>& CGridTransformation::getLocalIndexToSendFromGridSource() const
 {
   return localIndexToSendFromGridSource_;
@@ -800,8 +507,13 @@
   \return local index of data
 */
-const std::map<int,std::vector<std::vector<std::pair<int,double> > > >& CGridTransformation::getLocalIndexToReceiveOnGridDest() const
+const std::list<CGridTransformation::RecvIndexGridDestinationMap>& CGridTransformation::getLocalIndexToReceiveOnGridDest() const
 {
   return localIndexToReceiveOnGridDest_;
 }
 
-}
+const std::list<size_t>& CGridTransformation::getNbLocalIndexToReceiveOnGridDest() const
+{
+  return nbLocalIndexOnGridDest_;
+}
+
+}
Index: /XIOS/trunk/src/transformation/grid_transformation.hpp
===================================================================
--- /XIOS/trunk/src/transformation/grid_transformation.hpp	(revision 840)
+++ /XIOS/trunk/src/transformation/grid_transformation.hpp	(revision 841)
@@ -37,4 +37,6 @@
   typedef std::list<std::pair<int,std::pair<ETranformationType,int> > > ListAlgoType;
   typedef boost::unordered_map<size_t, std::vector<std::pair<int, std::pair<size_t,double> > > > DestinationIndexMap;
+  typedef std::map<int, CArray<int,1> > SendingIndexGridSourceMap;
+  typedef std::map<int,std::vector<std::vector<std::pair<int,double> > > > RecvIndexGridDestinationMap;
 
 public:
@@ -45,6 +47,8 @@
   void computeAll(const std::vector<CArray<double,1>* >& dataAuxInput=std::vector<CArray<double,1>* >(), Time timeStamp = 0);
 
-  const std::map<int, CArray<int,1> >& getLocalIndexToSendFromGridSource() const;
-  const std::map<int, std::vector<std::vector<std::pair<int,double> > > >& getLocalIndexToReceiveOnGridDest() const;
+  const std::list<SendingIndexGridSourceMap>& getLocalIndexToSendFromGridSource() const;
+  const std::list<RecvIndexGridDestinationMap>& getLocalIndexToReceiveOnGridDest() const;
+  const std::list<size_t>& getNbLocalIndexToReceiveOnGridDest() const;
+
   CGrid* getGridSource() { return originalGridSource_; }
   CGrid* getGridDestination() { return gridDestination_; }
@@ -64,7 +68,8 @@
   void selectAlgo(int elementPositionInGrid, ETranformationType transType, int transformationOrder, bool isDomainAlgo);
   void setUpGrid(int elementPositionInGrid, ETranformationType transType, int nbTransformation);
-  void computeFinalTransformationMapping();
-  void computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource);
-  void updateFinalGridDestination();
+//  void computeFinalTransformationMapping();
+//  void computeTransformationFromOriginalGridSource(const DestinationIndexMap& globaIndexMapFromDestToSource);
+  void computeTransformationMapping(const DestinationIndexMap& globalIndexWeightFromDestToSource);
+//  void updateFinalGridDestination();
   bool isSpecialTransformation(ETranformationType transType);
 
@@ -96,8 +101,11 @@
 
   //! Local index of data to send from grid source
-  std::map<int, CArray<int,1> > localIndexToSendFromGridSource_;
+  std::list<SendingIndexGridSourceMap> localIndexToSendFromGridSource_;
 
   //! Local index of data to receive on grid destination
-  std::map<int,std::vector<std::vector<std::pair<int,double> > > > localIndexToReceiveOnGridDest_;
+  std::list<RecvIndexGridDestinationMap> localIndexToReceiveOnGridDest_;
+
+  //! Number of local index of data to receive on grid destination
+  std::list<size_t> nbLocalIndexOnGridDest_;
 
   //! Position of axis and domain in grid
