Index: /XIOS/trunk/src/filter/spatial_transform_filter.cpp
===================================================================
--- /XIOS/trunk/src/filter/spatial_transform_filter.cpp	(revision 1639)
+++ /XIOS/trunk/src/filter/spatial_transform_filter.cpp	(revision 1640)
@@ -188,4 +188,6 @@
     
     CContextClient* client = CContext::getCurrent()->client;
+    int rank;
+    MPI_Comm_rank (client->intraComm, &rank);
 
     // Get default value for output data
@@ -217,8 +219,15 @@
       int idxSendBuff = 0;
       std::vector<double*> sendBuff(localIndexToSend.size());
+      double* sendBuffRank;
       for (itSend = itbSend; itSend != iteSend; ++itSend, ++idxSendBuff)
       {
+        int destRank = itSend->first;
         if (0 != itSend->second.numElements())
-          sendBuff[idxSendBuff] = new double[itSend->second.numElements()];
+        {
+          if (rank != itSend->first)
+            sendBuff[idxSendBuff] = new double[itSend->second.numElements()];
+          else
+            sendBuffRank = new double[itSend->second.numElements()];
+        }
       }
 
@@ -230,10 +239,20 @@
         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());
+        if (destRank != rank)
+        {
+          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());
+          }
+        }
+        else
+        {
+          for (int idx = 0; idx < countSize; ++idx)
+          {
+            sendBuffRank[idx] = dataCurrentSrc(localIndex_p(idx));
+          }
+        }
       }
 
@@ -243,7 +262,12 @@
                                                                        iteRecv = localIndexToReceive.end();
       int recvBuffSize = 0;
-      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv) recvBuffSize += itRecv->second.size(); //(recvBuffSize < itRecv->second.size())
-                                                                       //? itRecv->second.size() : recvBuffSize;
+      for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
+      {
+        if (itRecv->first != rank )
+          recvBuffSize += itRecv->second.size();
+      }
+      //(recvBuffSize < itRecv->second.size()) ? itRecv->second.size() : recvBuffSize;
       double* recvBuff;
+
       if (0 != recvBuffSize) recvBuff = new double[recvBuffSize];
       int currentBuff = 0;
@@ -251,8 +275,11 @@
       {
         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;
+        if (srcRank != rank)
+        {
+          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());
@@ -267,13 +294,25 @@
       for (itRecv = itbRecv; itRecv != iteRecv; ++itRecv)
       {
-        int countSize = itRecv->second.size();
         const std::vector<std::pair<int,double> >& localIndex_p = itRecv->second;
-        (*itAlgo)->apply(localIndex_p,
-                         recvBuff+currentBuff,
-                         dataCurrentDest,
-                         localInitFlag,
-                         ignoreMissingValue,firstPass);
-
-        currentBuff += countSize;
+        int srcRank = itRecv->first;
+        if (srcRank != rank)
+        {
+          int countSize = itRecv->second.size();
+          (*itAlgo)->apply(localIndex_p,
+                           recvBuff+currentBuff,
+                           dataCurrentDest,
+                           localInitFlag,
+                           ignoreMissingValue,firstPass);
+          currentBuff += countSize;
+        }
+        else
+        {
+          (*itAlgo)->apply(localIndex_p,
+                           sendBuffRank,
+                           dataCurrentDest,
+                           localInitFlag,
+                           ignoreMissingValue,firstPass);
+        }
+
         firstPass=false ;
       }
@@ -285,5 +324,10 @@
       {
         if (0 != itSend->second.numElements())
-          delete [] sendBuff[idxSendBuff];
+        {
+          if (rank != itSend->first)
+            delete [] sendBuff[idxSendBuff];
+          else
+            delete [] sendBuffRank;
+        }
       }
       if (0 != recvBuffSize) delete [] recvBuff;
