Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/context_client.cpp	(revision 1853)
+++ 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;
 
   }
