Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_client.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_client.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_client.cpp	(revision 2130)
@@ -7,4 +7,5 @@
 #include "mpi.hpp"
 #include "tracer.hpp"
+#include "timeline_events.hpp"
 
 namespace xios
@@ -200,7 +201,16 @@
   
     lockBuffer();
+    count=*bufferCount[current] ;
+    
+    if (resizingBufferStep_ > 0 ) return false ;
+
     if (size > bufferSize)
-      ERROR("bool CClientBuffer::isBufferFree(StdSize size)",
-            << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
+    {
+      // ERROR("bool CClientBuffer::isBufferFree(StdSize size)",
+      //      << "The requested size (" << size << " bytes) is too big to fit the buffer (" << bufferSize << " bytes), please increase the client buffer size." << endl);
+      resizingBufferStep_=1 ;
+      newBufferSize_=size ;
+      return false ;
+    }
 
     if (size > maxEventSize)
@@ -214,7 +224,15 @@
       if (size > maxRequestSize) maxRequestSize = size;
     }
-
-      count=*bufferCount[current] ;
-      return (size <= remain());
+    
+    if (size > remain())
+    {
+      if (isGrowableBuffer_)
+      {
+        resizingBufferStep_ = 1 ;
+        newBufferSize_ = (count+size)*growFactor_ ;
+      }  
+      return false ;
+    }
+    else return true ;
   }
 
@@ -276,5 +294,6 @@
     if (!pending)
     {
-      if (!send) return false ;
+      if (!send && resizingBufferStep_==0 ) return false ;
+
       if (count > 0)
       {
@@ -284,4 +303,5 @@
         {
           MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
+          if (resizingBufferStep_==3) resizingBufferStep_=0 ;
           pending = true;
 //          *control[current]=0 ;
@@ -295,9 +315,92 @@
           count = 0;
         }
-        else unlockBuffer() ;
+        else 
+        {
+          unlockBuffer() ;
+        }
       }
+      else
+      {
+        if (resizingBufferStep_==2) resizeBuffer(newBufferSize_) ;
+        if (resizingBufferStep_==1) resizeBufferNotify() ;
+      }
     }
 
     return pending;
+  }
+
+  void CClientBuffer::resizeBufferNotify(void)
+  {
+    // notify server of changing buffers size
+    lockBuffer() ;
+    int size=sizeof(int)+sizeof(size_t) ;
+    CBufferOut* bufOut = this->getBuffer(timelineEventNotifyChangeBufferSize, size);
+    bufOut->put(size);
+    bufOut->put(timelineEventNotifyChangeBufferSize);
+    resizingBufferStep_ = 2 ;
+    unlockBuffer() ;
+  }
+
+  void CClientBuffer::resizeBuffer(size_t newSize)
+  {
+    if (hasWindows)
+    { 
+      MPI_Win_detach(windows_[0], bufferHeader[0]) ;
+      MPI_Win_detach(windows_[1], bufferHeader[1]) ;
+    }
+    MPI_Free_mem(bufferHeader[0]) ;
+    MPI_Free_mem(bufferHeader[1]) ;
+
+    bufferSize=newSize ;
+    MPI_Alloc_mem(bufferSize+headerSize, MPI_INFO_NULL, &bufferHeader[0]) ;
+    MPI_Alloc_mem(bufferSize+headerSize, MPI_INFO_NULL, &bufferHeader[1]) ;
+    buffer[0] = bufferHeader[0]+headerSize ;
+    buffer[1] = bufferHeader[1]+headerSize ;
+    firstTimeLine[0]=(size_t*)bufferHeader[0] ;
+    firstTimeLine[1]=(size_t*)bufferHeader[1] ;
+    bufferCount[0]=(size_t*)bufferHeader[0] +1 ;
+    bufferCount[1]=(size_t*)bufferHeader[1] +1 ;
+    control[0]=(size_t*)bufferHeader[0] +2 ;
+    control[1]=(size_t*)bufferHeader[1] +2 ;
+    finalize[0]=(size_t*)bufferHeader[0] +3 ;
+    finalize[1]=(size_t*)bufferHeader[1] +3 ;
+
+    *firstTimeLine[0]=0 ;
+    *firstTimeLine[1]=0 ;
+    *bufferCount[0]=0 ;
+    *bufferCount[1]=0 ;
+    *control[0]=0 ;
+    *control[1]=0 ;
+    *finalize[0]=0 ;
+    *finalize[1]=0 ;
+    winState[0]=false ;
+    winState[1]=false ;
+    current=0 ;
+    
+    if (hasWindows)
+    {  
+    
+      MPI_Win_attach(windows_[0], bufferHeader[0], bufferSize+headerSize) ;
+      MPI_Win_attach(windows_[1], bufferHeader[1], bufferSize+headerSize) ;
+          
+      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, clientRank_, 0, windows_[0]) ;
+      MPI_Win_lock(MPI_LOCK_EXCLUSIVE, clientRank_, 0, windows_[1]) ;
+
+      MPI_Win_unlock(clientRank_, windows_[1]) ;
+      MPI_Win_unlock(clientRank_, windows_[0]) ;
+    } 
+
+    lockBuffer() ;
+ 
+    int size=sizeof(int)+2*sizeof(size_t)+2*sizeof(MPI_AINT) ;
+    CBufferOut* bufOut = this->getBuffer(timelineEventChangeBufferSize, size);
+    bufOut->put(size);
+    bufOut->put(timelineEventChangeBufferSize);
+    bufOut->put(newBufferSize_);
+    bufOut->put(this->getWinAddress(0));
+    bufOut->put(this->getWinAddress(1));
+
+    resizingBufferStep_=3;
+    unlockBuffer() ;
   }
 
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_client.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_client.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_client.hpp	(revision 2130)
@@ -29,5 +29,12 @@
       void infoBuffer(void) ;
       bool isNotifiedFinalized(void) ;
+      void setGrowableBuffer(double growFactor) { growFactor_=growFactor ; isGrowableBuffer_=true ;}
+      void fixBufferSize(size_t bufferSize) { newBufferSize_=bufferSize ; isGrowableBuffer_=false ; resizingBufferStep_=1 ;}
+      void fixBuffer(void) { isGrowableBuffer_=false ;}
     private:
+       void resizeBuffer(size_t newSize) ;
+       void resizeBufferNotify(void) ;
+
+
       char* buffer[2];
       char* bufferHeader[2];
@@ -38,8 +45,13 @@
       bool winState[2] ;
       int current;
+      
+      double growFactor_=1.2 ;
+      bool isGrowableBuffer_=true ;
 
+      int resizingBufferStep_ = 0 ;
+      size_t newBufferSize_ ;
       StdSize count;
       StdSize maxEventSize;
-      const StdSize bufferSize;
+      StdSize bufferSize;
       const StdSize estimatedMaxEventSize;
 
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_server.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_server.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_server.cpp	(revision 2130)
@@ -15,5 +15,5 @@
     end = size;
     used=0 ;
-    buffer = new char[size]; // use MPI_ALLOC_MEM later?
+    MPI_Alloc_mem(size, MPI_INFO_NULL, &buffer) ;
     currentWindows=1 ;
     if (windows[0]==MPI_WIN_NULL && windows[1]==MPI_WIN_NULL) hasWindows=false ;
@@ -22,5 +22,5 @@
   CServerBuffer::~CServerBuffer()
   {
-    delete [] buffer ;
+    MPI_Free_mem(buffer) ;
   }
 
@@ -222,5 +222,5 @@
   bool CServerBuffer::getBufferFromClient(size_t timeLine, char*& buffer, size_t& count)
   {
-    if (!hasWindows) return false ;
+    if (!hasWindows || resizingBuffer_) return false ;
 
     
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_server.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_server.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/buffer_server.hpp	(revision 2130)
@@ -26,4 +26,5 @@
       void unlockBuffer(void) ;
       void notifyClientFinalize(void) ;
+      void notifyBufferResizing(void) { resizingBuffer_=true ;}
     private:
       char* buffer;
@@ -35,5 +36,5 @@
       std::vector<MPI_Win> windows_ ;
       std::vector<MPI_Aint> winAddress_ ;
-
+      bool resizingBuffer_ = false ;
       int currentWindows ;
       bool hasWindows ;
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.cpp	(revision 2130)
@@ -12,4 +12,8 @@
 #include "cxios.hpp"
 #include "server.hpp"
+#include "services.hpp"
+#include <boost/functional/hash.hpp>
+#include <random>
+#include <chrono>
 
 namespace xios
@@ -25,5 +29,5 @@
     {
       
-      context = parent;
+      context_ = parent;
       intraComm = intraComm_;
       interComm = interComm_;
@@ -66,4 +70,10 @@
       MPI_Comm_split(intraComm_,clientRank,clientRank, &commSelf) ;
 
+      auto time=chrono::system_clock::now().time_since_epoch().count() ;
+      std::default_random_engine rd(time); // not reproducible from a run to another
+      std::uniform_int_distribution<size_t> dist;
+      hashId_=dist(rd) ;
+      MPI_Bcast(&hashId_,1,MPI_SIZE_T,0,intraComm) ; // Bcast to all server of the context
+
       timeLine = 1;
     }
@@ -124,5 +134,5 @@
     {
       list<int> ranks = event.getRanks();
-      info(100)<<"Event "<<timeLine<<" of context "<<context->getId()<<endl ;
+      info(100)<<"Event "<<timeLine<<" of context "<<context_->getId()<<endl ;
       if (CXios::checkEventSync)
       {
@@ -154,5 +164,5 @@
 
         unlockBuffers(ranks) ;
-        info(100)<<"Event "<<timeLine<<" of context "<<context->getId()<<"  sent"<<endl ;
+        info(100)<<"Event "<<timeLine<<" of context "<<context_->getId()<<"  sent"<<endl ;
           
         checkBuffers(ranks);
@@ -161,6 +171,8 @@
       if (isAttachedModeEnabled()) // couldBuffer is always true in attached mode
       {
-        waitEvent(ranks);
-        CContext::setCurrent(context->getId());
+        while (checkBuffers(ranks)) context_->globalEventLoop() ;
+      
+        CXios::getDaemonsManager()->scheduleContext(hashId_) ;
+        while (CXios::getDaemonsManager()->isScheduledContext(hashId_)) context_->globalEventLoop() ;
       }
       
@@ -177,5 +189,5 @@
       while (checkBuffers(ranks))
       {
-        CXios::getDaemonsManager()->eventLoop() ;
+        context_->eventLoop() ;
       }
 
@@ -256,5 +268,5 @@
           for (itBuffer = bufferList.begin(); itBuffer != bufferList.end(); itBuffer++) (*itBuffer)->unlockBuffer();
           checkBuffers();
-          
+/*          
           context->server->listen();
 
@@ -265,6 +277,8 @@
             context->globalEventLoop() ;
           }
-
-        }
+*/
+           context_->globalEventLoop() ;
+        }
+
       } while (!areBuffersFree && !nonBlocking);
       CTimer::get("Blocking time").suspend();
@@ -295,12 +309,15 @@
   
       CClientBuffer* buffer = buffers[rank] = new CClientBuffer(interComm, Wins, clientRank, rank, mapBufferSize_[rank], maxEventSizes[rank]);
+      if (isGrowableBuffer_) buffer->setGrowableBuffer(1.2) ;
+      else buffer->fixBuffer() ;
       // Notify the server
-      CBufferOut* bufOut = buffer->getBuffer(0, 3*sizeof(MPI_Aint));
-      MPI_Aint sendBuff[3] ;
-      sendBuff[0]=mapBufferSize_[rank]; // Stupid C++
-      sendBuff[1]=buffers[rank]->getWinAddress(0); 
-      sendBuff[2]=buffers[rank]->getWinAddress(1); 
+      CBufferOut* bufOut = buffer->getBuffer(0, 4*sizeof(MPI_Aint));
+      MPI_Aint sendBuff[4] ;
+      sendBuff[0]=hashId_;
+      sendBuff[1]=mapBufferSize_[rank];
+      sendBuff[2]=buffers[rank]->getWinAddress(0); 
+      sendBuff[3]=buffers[rank]->getWinAddress(1); 
       info(100)<<"CContextClient::newBuffer : rank "<<rank<<" winAdress[0] "<<buffers[rank]->getWinAddress(0)<<" winAdress[1] "<<buffers[rank]->getWinAddress(1)<<endl;
-      bufOut->put(sendBuff, 3); // Stupid C++
+      bufOut->put(sendBuff, 4); 
       buffer->checkBuffer(true);
 
@@ -383,8 +400,7 @@
     * \param [in] maxEventSize maps the rank of the connected servers to the size of the biggest event
    */
-   void CContextClient::setBufferSize(const std::map<int,StdSize>& mapSize, const std::map<int,StdSize>& maxEventSize)
-   {
-     mapBufferSize_ = mapSize;
-     maxEventSizes = maxEventSize;
+   void CContextClient::setBufferSize(const std::map<int,StdSize>& mapSize)
+   {
+     for(auto& it : mapSize) {buffers[it.first]->fixBufferSize(std::min(it.second*CXios::bufferSizeFactor*1.01,CXios::maxBufferSize*1.0));}
    }
 
@@ -463,9 +479,9 @@
     for (itMap = itbMap; itMap != iteMap; ++itMap)
     {
-      report(10) << " Memory report : Context <" << context->getId() << "> : client side : memory used for buffer of each connection to server" << endl
+      report(10) << " Memory report : Context <" << context_->getId() << "> : client side : memory used for buffer of each connection to server" << endl
                  << "  +) To server with rank " << itMap->first << " : " << itMap->second << " bytes " << endl;
       totalBuf += itMap->second;
     }
-    report(0) << " Memory report : Context <" << context->getId() << "> : client side : total memory used for buffer " << totalBuf << " bytes" << endl;
+    report(0) << " Memory report : Context <" << context_->getId() << "> : client side : total memory used for buffer " << totalBuf << " bytes" << endl;
 
   }
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.hpp	(revision 2130)
@@ -63,5 +63,5 @@
       void finalize(void);
 
-      void setBufferSize(const std::map<int,StdSize>& mapSize, const std::map<int,StdSize>& maxEventSize);
+      void setBufferSize(const std::map<int,StdSize>& mapSize);
 
       int getRemoteSize(void) {return serverSize;}
@@ -75,7 +75,8 @@
       /*! get the associated server (dual chanel client/server) */      
       CContextServer* getAssociatedServer(void) { return associatedServer_;}
-
+      void setGrowableBuffer(void) { isGrowableBuffer_=true;}
+      void setFixedBuffer(void) { isGrowableBuffer_=false;}
     public:
-      CContext* context; //!< Context for client
+      CContext* context_; //!< Context for client
 
       size_t timeLine; //!< Timeline of each event
@@ -98,4 +99,6 @@
 
       bool pureOneSided ; //!< if true, client will communicated with servers only trough one sided communication. Otherwise the hybrid mode P2P /One sided is used.
+
+      size_t hashId_ ; //!< hash id on the context client that will be used for context server to identify the remote calling context client.
 
     private:
@@ -122,5 +125,5 @@
       bool isAttached_ ;
       CContextServer* associatedServer_ ; //!< The server associated to the pair client/server
-
+      bool isGrowableBuffer_ = true ;
   };
 }
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_server.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_server.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_server.cpp	(revision 2130)
@@ -20,4 +20,5 @@
 #include "services.hpp"
 #include "contexts_manager.hpp"
+#include "timeline_events.hpp"
 
 #include <boost/functional/hash.hpp>
@@ -188,9 +189,10 @@
     if (it==buffers.end()) // Receive the buffer size and allocate the buffer
     {
-       MPI_Aint recvBuff[3] ;
-       MPI_Recv(recvBuff, 3, MPI_AINT, rank, 20, interComm, &status);
-       StdSize buffSize = recvBuff[0];
+       MPI_Aint recvBuff[4] ;
+       MPI_Recv(recvBuff, 4, MPI_AINT, rank, 20, interComm, &status);
+       remoteHashId_ = recvBuff[0] ;
+       StdSize buffSize = recvBuff[1];
        vector<MPI_Aint> winAdress(2) ;
-       winAdress[0]=recvBuff[1] ; winAdress[1]=recvBuff[2] ;
+       winAdress[0]=recvBuff[2] ; winAdress[1]=recvBuff[3] ;
        mapBufferSize_.insert(std::make_pair(rank, buffSize));
        it=(buffers.insert(pair<int,CServerBuffer*>(rank,new CServerBuffer(windows, winAdress, rank, buffSize)))).first;
@@ -290,13 +292,28 @@
       CBufferIn newBuffer(startBuffer,buffer.remain());
       newBuffer>>size>>timeLine;
-      it=events.find(timeLine);
-      if (it==events.end()) it=events.insert(pair<int,CEventServer*>(timeLine,new CEventServer(this))).first;
-      it->second->push(rank,buffers[rank],startBuffer,size);
-
+
+      if (timeLine==timelineEventNotifyChangeBufferSize)
+      {
+        buffers[rank]->notifyBufferResizing() ;
+        buffers[rank]->updateCurrentWindows() ;
+      } 
+      else if (timeLine==timelineEventChangeBufferSize)
+      {
+        size_t newSize ;
+        vector<MPI_Aint> winAdress(2) ;
+        newBuffer>>newSize>>winAdress[0]>>winAdress[1] ;
+        buffers.erase(rank) ;
+        buffers.insert(pair<int,CServerBuffer*>(rank,new CServerBuffer(windows, winAdress, rank, newSize)));
+      }
+      else
+      {
+        it=events.find(timeLine);
+        if (it==events.end()) it=events.insert(pair<int,CEventServer*>(timeLine,new CEventServer(this))).first;
+        it->second->push(rank,buffers[rank],startBuffer,size);
+        if (timeLine>0) lastTimeLine[rank]=timeLine ;
+      }
       buffer.advance(size);
       count=buffer.remain();
     }
-
-    if (timeLine>0) lastTimeLine[rank]=timeLine ;
     
     CTimer::get("Process request").suspend();
@@ -310,4 +327,6 @@
 //    if (context->isProcessingEvent()) return ;
     if (isProcessingEvent_) return ;
+    if (isAttachedModeEnabled())
+      if (!CXios::getDaemonsManager()->isScheduledContext(remoteHashId_)) return ;
 
     it=events.find(currentTimeLine);
@@ -356,4 +375,5 @@
          currentTimeLine++;
          scheduled = false;
+         if (isAttachedModeEnabled()) CXios::getDaemonsManager()->unscheduleContext() ;
         }
       }
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_server.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_server.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/context_server.hpp	(revision 2130)
@@ -72,4 +72,5 @@
       bool isProcessingEvent_ ;
       CContextClient* associatedClient_ ;
+      size_t remoteHashId_; //!< the hash is of the calling context client
   } ;
 
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_scatterer_connector.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_scatterer_connector.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/distribution/grid_scatterer_connector.hpp	(revision 2130)
@@ -42,5 +42,6 @@
       }     
 
-
+      const map<int,int>& getTransferedDataSize(void) {return dstSize_;}
+     
       template<typename T, int N> 
       void transfer(const CArray<T,N>& input, map<int, CArray<T,1>>& output)
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/client_to_server_store_filter.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/client_to_server_store_filter.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/client_to_server_store_filter.cpp	(revision 2130)
@@ -28,4 +28,10 @@
     CTimer::get("Field : send data").suspend();
   }
+  
+  CContextClient* CClientToServerStoreFilter::getTransferedDataSize(map<int,int>& size)
+  {
+    size = field_->getSentGrid()->getClientToServerConnector(client_)->getTransferedDataSize() ;
+    return client_ ;
+  }
 
   bool CClientToServerStoreFilter::mustAutoTrigger() const
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/client_to_server_store_filter.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/client_to_server_store_filter.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/client_to_server_store_filter.hpp	(revision 2130)
@@ -23,4 +23,11 @@
        */
       CClientToServerStoreFilter(CGarbageCollector& gc, CField* field, CContextClient* client);
+      /*!
+       * Get the size of data transfered by call. Needed for context client buffer size evaluation
+       *
+       * \param size : map returning the size for each server rank  
+       * \return the associated context client
+       */
+      CContextClient* getTransferedDataSize(map<int,int>& size) ;
 
       /*!
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/server_to_client_store_filter.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/server_to_client_store_filter.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/server_to_client_store_filter.cpp	(revision 2130)
@@ -44,4 +44,9 @@
   }
 
+  CContextClient* CServerToClientStoreFilter::getTransferedDataSize(map<int,int>& size)
+  {
+    size = grid_->getServerToClientConnector()->getTransferedDataSize() ;
+    return client_ ;
+  }
 
   bool CServerToClientStoreFilter::mustAutoTrigger() const
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/server_to_client_store_filter.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/server_to_client_store_filter.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/filter/server_to_client_store_filter.hpp	(revision 2130)
@@ -24,4 +24,12 @@
        */
       CServerToClientStoreFilter(CGarbageCollector& gc, CField* field, CContextClient* client);
+
+      /*!
+       * Get the size of data transfered by call. Needed for context client buffer size evaluation
+       *
+       * \param size : map returning the size for each server rank  
+       * \return the associated context client
+       */
+      CContextClient* getTransferedDataSize(map<int,int>& size) ;
 
       /*!
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/daemons_manager.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/daemons_manager.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/daemons_manager.hpp	(revision 2130)
@@ -1,4 +1,5 @@
 #ifndef __DAEMONS_MANAGER_HPP__
 #define __DAEMONS_MANAGER_HPP__
+#include <cstddef>
 
 namespace xios
@@ -16,6 +17,11 @@
     bool servicesEventLoop(void) ;
     
+    void scheduleContext(size_t hashId) { scheduledContext_=hashId ;} //!< for attached mode, give the hand to the associated context server
+    bool isScheduledContext(size_t hashId) { return scheduledContext_==hashId ;} //!< for attached mode, return true if context server is sceduled
+    void unscheduleContext(void) { scheduledContext_=0 ;} //!< for attached mode : unschedule context
+
     private:
     bool isServer_ ;
+    size_t scheduledContext_ = 0 ; //!< Hash id of the next scehduled context for attached mode
   } ;
 }
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/server_context.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/server_context.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/server_context.hpp	(revision 2130)
@@ -33,4 +33,6 @@
     void freeComm(void) ;
     bool isAttachedMode(void) { return isAttachedMode_ ;}
+    CService* getParentService(void) {return parentService_ ; }
+
     private:
     void createIntercomm(void) ;
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/services.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/services.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/manager/services.hpp	(revision 2130)
@@ -37,5 +37,5 @@
     int getType(void) {return type_;}
     int getNbPartitions(void) {return nbPartitions_;}
-
+    
     private:
     void sendNotification(int rank) ;
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp	(revision 2130)
@@ -292,121 +292,4 @@
 
 
-   void CContext::setClientServerBuffer(vector<CField*>& fields, bool bufferForWriting)
-   TRY
-   {
-      // Estimated minimum event size for small events (20 is an arbitrary constant just for safety)
-     const size_t minEventSize = CEventClient::headerSize + 20 * sizeof(int);
-      // Ensure there is at least some room for 20 of such events in the buffers
-     size_t minBufferSize = std::max(CXios::minBufferSize, 20 * minEventSize);
-
-#define DECLARE_NODE(Name_, name_)    \
-     if (minBufferSize < sizeof(C##Name_##Definition)) minBufferSize = sizeof(C##Name_##Definition);
-#define DECLARE_NODE_PAR(Name_, name_)
-#include "node_type.conf"
-#undef DECLARE_NODE
-#undef DECLARE_NODE_PAR
-
-
-     map<CContextClient*,map<int,size_t>> dataSize ;
-     map<CContextClient*,map<int,size_t>> maxEventSize ;
-     map<CContextClient*,map<int,size_t>> attributesSize ;  
-
-     for(auto field : fields)
-     {
-       field->setContextClientDataBufferSize(dataSize, maxEventSize, bufferForWriting) ;
-       field->setContextClientAttributesBufferSize(attributesSize, maxEventSize, bufferForWriting) ;
-     }
-     
-
-     for(auto& it : attributesSize)
-     {
-       auto contextClient = it.first ;
-       auto& contextDataSize =  dataSize[contextClient] ;
-       auto& contextAttributesSize =  attributesSize[contextClient] ;
-       auto& contextMaxEventSize =  maxEventSize[contextClient] ;
-   
-       for (auto& it : contextAttributesSize)
-       {
-         auto serverRank=it.first ;
-         auto& buffer = contextAttributesSize[serverRank] ;
-         if (contextDataSize[serverRank] > buffer) buffer=contextDataSize[serverRank] ;
-         buffer *= CXios::bufferSizeFactor;
-         if (buffer < minBufferSize) buffer = minBufferSize;
-         if (buffer > CXios::maxBufferSize ) buffer = CXios::maxBufferSize;
-       }
-
-       // Leaders will have to send some control events so ensure there is some room for those in the buffers
-       if (contextClient->isServerLeader())
-         for(auto& rank : contextClient->getRanksServerLeader())
-           if (!contextAttributesSize.count(rank))
-           {
-             contextAttributesSize[rank] = minBufferSize;
-             contextMaxEventSize[rank] = minEventSize;
-           }
-      
-       contextClient->setBufferSize(contextAttributesSize, contextMaxEventSize);    
-     }
-   }
-   CATCH_DUMP_ATTR
-
-
-    /*!
-    Sets client buffers.
-    \param [in] contextClient
-    \param [in] bufferForWriting True if buffers are used for sending data for writing
-    This flag is only true for client and server-1 for communication with server-2
-  */
-  // ym obsolete to be removed
-   void CContext::setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting)
-   TRY
-   {
-      // Estimated minimum event size for small events (20 is an arbitrary constant just for safety)
-     const size_t minEventSize = CEventClient::headerSize + 20 * sizeof(int);
-
-      // Ensure there is at least some room for 20 of such events in the buffers
-      size_t minBufferSize = std::max(CXios::minBufferSize, 20 * minEventSize);
-
-#define DECLARE_NODE(Name_, name_)    \
-     if (minBufferSize < sizeof(C##Name_##Definition)) minBufferSize = sizeof(C##Name_##Definition);
-#define DECLARE_NODE_PAR(Name_, name_)
-#include "node_type.conf"
-#undef DECLARE_NODE
-#undef DECLARE_NODE_PAR
-
-     // Compute the buffer sizes needed to send the attributes and data corresponding to fields
-     std::map<int, StdSize> maxEventSize;
-     std::map<int, StdSize> bufferSize = getAttributesBufferSize(maxEventSize, contextClient, bufferForWriting);
-     std::map<int, StdSize> dataBufferSize = getDataBufferSize(maxEventSize, contextClient, bufferForWriting);
-
-     std::map<int, StdSize>::iterator it, ite = dataBufferSize.end();
-     for (it = dataBufferSize.begin(); it != ite; ++it)
-       if (it->second > bufferSize[it->first]) bufferSize[it->first] = it->second;
-
-     // Apply the buffer size factor, check that we are above the minimum buffer size and below the maximum size
-     ite = bufferSize.end();
-     for (it = bufferSize.begin(); it != ite; ++it)
-     {
-       it->second *= CXios::bufferSizeFactor;
-       if (it->second < minBufferSize) it->second = minBufferSize;
-       if (it->second > CXios::maxBufferSize) it->second = CXios::maxBufferSize;
-     }
-
-     // Leaders will have to send some control events so ensure there is some room for those in the buffers
-     if (contextClient->isServerLeader())
-     {
-       const std::list<int>& ranks = contextClient->getRanksServerLeader();
-       for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-       {
-         if (!bufferSize.count(*itRank))
-         {
-           bufferSize[*itRank] = minBufferSize;
-           maxEventSize[*itRank] = minEventSize;
-         }
-       }
-     }
-     contextClient->setBufferSize(bufferSize, maxEventSize);
-   }
-   CATCH_DUMP_ATTR
-
  /*!
     * Compute the required buffer size to send the fields data.
@@ -716,4 +599,12 @@
   CATCH_DUMP_ATTR
 
+  void CContext::globalEventLoop(void)
+  {
+    lockContext() ;
+    CXios::getDaemonsManager()->eventLoop() ;
+    unlockContext() ;
+    setCurrent(getId()) ;
+  }
+
   bool CContext::scheduledEventLoop(bool enableEventsProcessing) 
   {
@@ -739,4 +630,6 @@
   {
     bool  finished; 
+    if (isLockedContext()) return ;
+    
     setCurrent(getId()) ;
 
@@ -792,18 +685,4 @@
         couplerOutClient_[fullContextId] = client ;
         couplerOutServer_[fullContextId] = server ;
-
-/*
-      // for now, we don't now which beffer size must be used for client coupler
-      // It will be evaluated later. Fix a constant size for now...
-      // set to 10Mb for development
-       map<int,size_t> bufferSize, maxEventSize ;
-       for(int i=0;i<client->getRemoteSize();i++)
-       {
-         bufferSize[i]=10000000 ;
-         maxEventSize[i]=10000000 ;
-       }
-
-       client->setBufferSize(bufferSize, maxEventSize);    
-*/
       }
     }
@@ -827,12 +706,4 @@
        MPI_Comm_free(&interComm) ;
 
-       map<int,size_t> bufferSize, maxEventSize ;
-       for(int i=0;i<client->getRemoteSize();i++)
-       {
-         bufferSize[i]=10000000 ;
-         maxEventSize[i]=10000000 ;
-       }
-
-       client->setBufferSize(bufferSize, maxEventSize);    
        couplerInClient_[fullContextId] = client ;
        couplerInServer_[fullContextId] = server ;        
@@ -840,11 +711,4 @@
   }
   
-  void CContext::globalEventLoop(void)
-  {
-    CXios::getDaemonsManager()->eventLoop() ;
-    setCurrent(getId()) ;
-  }
-
-
    void CContext::finalize(void)
    TRY
@@ -1054,5 +918,4 @@
         // connect to couplerOut -> to do
       }
-      if (first) setClientServerBuffer(couplerOutField, true) ; // set buffer context --> to check
 
       bool couplersReady ;
@@ -1099,5 +962,4 @@
         field->connectToFileServer(garbageCollector) ; // connect the field to server filter
       }
-      setClientServerBuffer(fileOutField, true) ; // set buffer context --> to review
       for(auto field : fileOutField) field->sendFieldToFileServer() ;
     }
@@ -1207,4 +1069,14 @@
       this->scheduledEventLoop() ;
     } while (!ok) ;
+
+    // Now evaluate the size of the context client buffers
+    map<CContextClient*,map<int,size_t>> fieldBufferEvaluation ;
+    for(auto field : fileOutField) field->evaluateBufferSize(fieldBufferEvaluation, CXios::isOptPerformance) ; // output to server
+    for(auto field : couplerOutField) field->evaluateBufferSize(fieldBufferEvaluation, CXios::isOptPerformance) ; // output to coupler
+    for(auto field : fieldModelIn) field->evaluateBufferSize(fieldBufferEvaluation, CXios::isOptPerformance) ; // server to client (for io servers)
+    
+    // fix size for each context client
+    for(auto& it : fieldBufferEvaluation) it.first->setBufferSize(it.second) ;
+
 
      CTimer::get("Context : close definition").suspend() ;
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.hpp	(revision 2130)
@@ -150,6 +150,4 @@
          std::map<int, StdSize> getAttributesBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
          std::map<int, StdSize> getDataBufferSize(std::map<int, StdSize>& maxEventSize, CContextClient* contextClient, bool bufferForWriting = false);
-         void setClientServerBuffer(CContextClient* contextClient, bool bufferForWriting = false); // old interface to be removed
-         void setClientServerBuffer(vector<CField*>& fields, bool bufferForWriting) ; 
 
          // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
@@ -357,6 +355,14 @@
          string contextId_ ; //!< context client id for the servers. For clients this is same as getId() 
          bool isProcessingEvent_ ;
+    private:     
          CServerContext* parentServerContext_ ;
-
+    public:
+         CServerContext* getParentServerContext(void) { return parentServerContext_; }
+    private: 
+      bool lockedContext_=false;
+    public: 
+        void lockContext(void) {lockedContext_=true; }
+        void unlockContext(void) {lockedContext_=true; }
+        bool isLockedContext(void) { return lockedContext_;}
       public: // Some function maybe removed in the near future
         // virtual void toBinary  (StdOStream & os) const;
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp	(revision 2130)
@@ -497,4 +497,42 @@
   CATCH_DUMP_ATTR
 
+  bool CField::evaluateBufferSize(map<CContextClient*,map<int,size_t>>& evaluateBuffer, bool isOptPerformance)
+  {
+    CContextClient* client=nullptr ;
+
+    for(int i=0;i<2;i++)
+    {
+      map<int,int> dataSize ;
+      if (i==0  && clientToServerStoreFilter_) client = clientToServerStoreFilter_-> getTransferedDataSize(dataSize) ;
+      if (i==1  && serverToClientStoreFilter_) client = serverToClientStoreFilter_-> getTransferedDataSize(dataSize) ;
+
+      if (client!=nullptr)
+      {
+        map<int,size_t> bufferSize ;
+   
+        if (evaluateBuffer.count(client)!=0) bufferSize = evaluateBuffer[client] ;
+        if (isOptPerformance)
+        {
+          for(auto& it : dataSize) 
+          {
+            if (bufferSize.count(it.first)==0) bufferSize[it.first]=it.second ;
+            else bufferSize[it.first]+=it.second ;
+          }
+        }
+        else
+        {
+          for(auto& it : dataSize) 
+          {
+            if (bufferSize.count(it.first)==0) bufferSize[it.first]=it.second ;
+            else bufferSize[it.first]=std::max(bufferSize[it.first],(size_t)it.second) ;
+          }
+        }
+        evaluateBuffer[client] = bufferSize ;
+        client=nullptr ;
+      }
+    }
+    if (client==nullptr) return false ;
+    else return true;
+  }  
 
 
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp	(revision 2130)
@@ -110,5 +110,7 @@
          // Grid data buffer size for each connection of contextclient
          std::map<int, StdSize> getGridDataBufferSize(CContextClient* client, bool bufferForWriting = false);
-
+         
+         // evaluation the size of the buffer for the field
+         bool evaluateBufferSize(map<CContextClient*,map<int,size_t>>& evaluateBuffer, bool isOptPerformance) ;
        public:
           void makeGridAliasForCoupling(void) ;
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/object_factory_decl_macro.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/object_factory_decl_macro.hpp	(revision 2129)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/object_factory_decl_macro.hpp	(revision 2130)
@@ -19,2 +19,3 @@
 
 
+
Index: /XIOS/dev/dev_ym/XIOS_COUPLING/src/timeline_events.hpp
===================================================================
--- /XIOS/dev/dev_ym/XIOS_COUPLING/src/timeline_events.hpp	(revision 2130)
+++ /XIOS/dev/dev_ym/XIOS_COUPLING/src/timeline_events.hpp	(revision 2130)
@@ -0,0 +1,14 @@
+#ifndef __TIMELINE_EVENTS_HPP__
+#define __TIMELINE_EVENTS_HPP__
+
+#include <limits>
+
+namespace xios
+{
+  const size_t timeLineEventbase = std::numeric_limits<size_t>::max()-100 ; 
+  const size_t timelineEventNotifyChangeBufferSize = timeLineEventbase + 0  ; 
+  const size_t timelineEventChangeBufferSize = timeLineEventbase + 1  ; 
+}
+
+
+#endif
