Index: /XIOS3/trunk/src/interface/c/iccalendar.cpp
===================================================================
--- /XIOS3/trunk/src/interface/c/iccalendar.cpp	(revision 2405)
+++ /XIOS3/trunk/src/interface/c/iccalendar.cpp	(revision 2406)
@@ -15,5 +15,5 @@
     CTimer::get("XIOS update calendar").resume();
     xios::CContext* context = CContext::getCurrent();
-    if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//    if (!context->hasServer && !context->client->isAttachedModeEnabled())
       context->eventLoop();
 //ym      context->checkBuffersAndListen();
Index: /XIOS3/trunk/src/interface/c/icdata.cpp
===================================================================
--- /XIOS3/trunk/src/interface/c/icdata.cpp	(revision 2405)
+++ /XIOS3/trunk/src/interface/c/icdata.cpp	(revision 2406)
@@ -422,5 +422,5 @@
       CTimer::get("XIOS send field").resume();
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
       CArray<double, 1> data(data_k8, shape(data_Xsize), neverDeleteData);
@@ -450,5 +450,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -480,5 +480,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -512,5 +512,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -546,5 +546,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -582,5 +582,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -617,5 +617,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -653,5 +653,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -686,5 +686,5 @@
       CTimer::get("XIOS send field").resume();
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -716,5 +716,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -746,5 +746,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -778,5 +778,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -811,5 +811,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -847,5 +847,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -882,5 +882,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -917,5 +917,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -952,5 +952,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -980,5 +980,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1007,5 +1007,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1035,5 +1035,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1065,5 +1065,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1096,5 +1096,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1127,5 +1127,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1159,5 +1159,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1194,5 +1194,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1225,5 +1225,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1257,5 +1257,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1288,5 +1288,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1320,5 +1320,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1355,5 +1355,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1389,5 +1389,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
@@ -1425,5 +1425,5 @@
 
       CContext* context = CContext::getCurrent();
-      if (!context->hasServer && !context->client->isAttachedModeEnabled())
+//      if (!context->hasServer && !context->client->isAttachedModeEnabled())
         context->eventLoop();
 
Index: /XIOS3/trunk/src/node/context.cpp
===================================================================
--- /XIOS3/trunk/src/node/context.cpp	(revision 2405)
+++ /XIOS3/trunk/src/node/context.cpp	(revision 2406)
@@ -46,5 +46,4 @@
       , calendar(), hasClient(false), hasServer(false)
       , isPostProcessed(false), finalized(false)
-      , client(nullptr), server(nullptr)
       , allProcessed(false), countChildContextFinalized_(0), isProcessingEvent_(false)
 
@@ -55,5 +54,4 @@
       , calendar(), hasClient(false), hasServer(false)
       , isPostProcessed(false), finalized(false)
-      , client(nullptr), server(nullptr)
       , allProcessed(false), countChildContextFinalized_(0), isProcessingEvent_(false)
    { /* Ne rien faire de plus */ }
@@ -61,8 +59,17 @@
    CContext::~CContext(void)
    {
-     delete client;
-     delete server;
-     for (std::vector<CContextClient*>::iterator it = clientPrimServer.begin(); it != clientPrimServer.end(); it++)  delete *it;
-     for (std::vector<CContextServer*>::iterator it = serverPrimServer.begin(); it != serverPrimServer.end(); it++)  delete *it;
+     for(auto& client : writerClientOut_) delete client ;
+     for(auto& server : writerServerOut_) delete server ;
+
+     for(auto& client : writerClientIn_) delete client ;
+     for(auto& server : writerServerIn_) delete server ;
+
+     for(auto& client : readerClientOut_) delete client ;
+     for(auto& server : readerServerOut_) delete server ;
+
+     for(auto& client : readerClientIn_) delete client ;
+     for(auto& server : readerServerIn_) delete server ;
+
+
      if (registryIn!=nullptr) delete registryIn ;
      if (registryOut!=nullptr) delete registryOut ;
@@ -534,9 +541,15 @@
     comms.push_back(intraCommClient);
     // attached_mode=parentServerContext_->isAttachedMode() ; //ym probably inherited from source context
+
+    CContextServer* server ;
+    CContextClient* client ;
+    
     server = CContextServer::getNew(this,intraComm_, interCommServer); // check if we need to dupl. intraComm_ ?
     client = CContextClient::getNew(this,intraCommClient,interCommClient);
     client->setAssociatedServer(server) ;  
-    server->setAssociatedClient(client) ;  
-
+    server->setAssociatedClient(client) ;
+
+    writerServerIn_.push_back(server) ; 
+    writerClientIn_.push_back(client) ; 
   }
   CATCH_DUMP_ATTR
@@ -594,6 +607,6 @@
       else createServerInterComm(CXios::defaultPoolId, CXios::defaultServerId, clientServers) ;
       
-      client = clientServers[0].second.first ;
-      server = clientServers[0].second.second ;
+      writerClientOut_.push_back(clientServers[0].second.first) ; 
+      writerServerOut_.push_back(clientServers[0].second.second) ;
     }
     else if (serviceType_ == CServicesManager::GATHERER)
@@ -604,113 +617,10 @@
         primServerId_.push_back(clientServer.first) ;
         clientPrimServer.push_back(clientServer.second.first);
-        serverPrimServer.push_back(clientServer.second.second); 
-      }
-    }
-
-  }
-  CATCH_DUMP_ATTR
-
-  void CContext::createServerInterComm_old(void) 
-  TRY
-  {
-   
-    MPI_Comm interCommClient, interCommServer ;
-
-    if (serviceType_ == CServicesManager::CLIENT)
-    {
-
-      int commRank ;
-      MPI_Comm_rank(intraComm_,&commRank) ;
-      if (commRank==0)
-      {
-        if (attached_mode) CXios::getContextsManager()->createServerContext(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultServerId, 0, getContextId()) ;
-        else if (CXios::usingServer2) CXios::getContextsManager()->createServerContext(CXios::defaultPoolId, CXios::defaultGathererId, 0, getContextId()) ;
-        else  CXios::getContextsManager()->createServerContext(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId()) ;
-      }
-
-      MPI_Comm interComm ;
-      
-      if (attached_mode)
-      {
-        parentServerContext_->createIntercomm(CClient::getPoolRessource()->getId(), getContextId()+"_"+CXios::defaultServerId, 0, getContextId(), intraComm_, 
-                                              interCommClient, interCommServer) ;
-        int type ; 
-        if (commRank==0) CXios::getServicesManager()->getServiceType(CClient::getPoolRessource()->getId(), CXios::defaultServerId, 0, type) ;
-        MPI_Bcast(&type,1,MPI_INT,0,intraComm_) ;
-        setCurrent(getId()) ; // getCurrent/setCurrent may be supress, it can cause a lot of trouble
-      }
-      else if (CXios::usingServer2)
-      { 
-//      CXios::getContextsManager()->createServerContextIntercomm(CXios::defaultPoolId, CXios::defaultGathererId, 0, getContextId(), intraComm_, interComm) ;
-        parentServerContext_->createIntercomm(CXios::defaultPoolId, CXios::defaultGathererId, 0, getContextId(), intraComm_,
-                                              interCommClient, interCommServer) ;
-        int type ; 
-        if (commRank==0) CXios::getServicesManager()->getServiceType(CXios::defaultPoolId, CXios::defaultGathererId, 0, type) ;
-        MPI_Bcast(&type,1,MPI_INT,0,intraComm_) ;
-      }
-      else
-      {
-        
-        //CXios::getContextsManager()->createServerContextIntercomm(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId(), intraComm_, interComm) ;
-        parentServerContext_->createIntercomm(CXios::defaultPoolId, CXios::defaultServerId, 0, getContextId(), intraComm_,
-                                              interCommClient, interCommServer) ;
-        int type ; 
-        if (commRank==0) CXios::getServicesManager()->getServiceType(CXios::defaultPoolId, CXios::defaultServerId, 0, type) ;
-        MPI_Bcast(&type,1,MPI_INT,0,intraComm_) ;
-      }
-
-        // intraComm client is not duplicated. In all the code we use client->intraComm for MPI
-        // in future better to replace it by intracommuncator associated to the context
-    
-      MPI_Comm intraCommClient, intraCommServer ;
-      intraCommClient=intraComm_ ;
-      MPI_Comm_dup(intraComm_, &intraCommServer) ;
-      client = CContextClient::getNew(this, intraCommClient, interCommClient);
-      server = CContextServer::getNew(this, intraCommServer, interCommServer);
-      client->setAssociatedServer(server) ;
-      server->setAssociatedClient(client) ;
-    }
-    
-    if (serviceType_ == CServicesManager::GATHERER)
-    {
-      int commRank ;
-      MPI_Comm_rank(intraComm_,&commRank) ;
-      
-      int nbPartitions ;
-      if (commRank==0) 
-      { 
-        CXios::getServicesManager()->getServiceNbPartitions(CXios::defaultPoolId, CXios::defaultServerId, 0, nbPartitions) ;
-        for(int i=0 ; i<nbPartitions; i++)
-          CXios::getContextsManager()->createServerContext(CXios::defaultPoolId, CXios::defaultServerId, i, getContextId()) ;
-      }      
-      MPI_Bcast(&nbPartitions, 1, MPI_INT, 0, intraComm_) ;
-      
-      MPI_Comm interComm ;
-      for(int i=0 ; i<nbPartitions; i++)
-      {
-        parentServerContext_->createIntercomm(CXios::defaultPoolId, CXios::defaultServerId, i, getContextId(), intraComm_, interCommClient, interCommServer) ;
-        int type ; 
-        if (commRank==0) CXios::getServicesManager()->getServiceType(CXios::defaultPoolId, CXios::defaultServerId, 0, type) ;
-        MPI_Bcast(&type,1,MPI_INT,0,intraComm_) ;
-        primServerId_.push_back(CXios::getContextsManager()->getServerContextName(CXios::defaultPoolId, CXios::defaultServerId, i, type, getContextId())) ;
-
-        // intraComm client is not duplicated. In all the code we use client->intraComm for MPI
-        // in future better to replace it by intracommuncator associated to the context
-      
-        MPI_Comm intraCommClient, intraCommServer ;
-
-        intraCommClient=intraComm_ ;
-        MPI_Comm_dup(intraComm_, &intraCommServer) ;
-
-        CContextClient* client = CContextClient::getNew(this, intraCommClient, interCommClient) ;
-        CContextServer* server = CContextServer::getNew(this, intraCommServer, interCommServer) ;
-        client->setAssociatedServer(server) ;
-        server->setAssociatedClient(client) ;
-        clientPrimServer.push_back(client);
-        serverPrimServer.push_back(server);  
-
-      
-      }
-    }
+        serverPrimServer.push_back(clientServer.second.second);
+        writerClientOut_.push_back(clientServer.second.first) ; 
+        writerServerOut_.push_back(clientServer.second.second) ;
+      }
+    }
+
   }
   CATCH_DUMP_ATTR
@@ -756,25 +666,15 @@
     setCurrent(getId()) ;
 
-    if (client!=nullptr && !finalized) client->eventLoop();
-    
-    for (int i = 0; i < clientPrimServer.size(); ++i)
-    {
-      if (!finalized) clientPrimServer[i]->eventLoop();
-      if (!finalized) finished &= serverPrimServer[i]->eventLoop(enableEventsProcessing);
-    }
-
-    for (auto couplerOut : couplerOutClient_)
-      if (!finalized) couplerOut.second->eventLoop();
-    
-    for (auto couplerIn : couplerInClient_)
-      if (!finalized) couplerIn.second->eventLoop();
-    
-    for (auto couplerOut : couplerOutServer_)
-      if (!finalized) couplerOut.second->eventLoop(enableEventsProcessing);
-
-    for (auto couplerIn : couplerInServer_)
-      if (!finalized) couplerIn.second->eventLoop(enableEventsProcessing);
-    
-    if (server!=nullptr) if (!finalized) finished &= server->eventLoop(enableEventsProcessing);
+    if (!finalized)
+    {
+      for(auto client : writerClientOut_) client->eventLoop();
+      for(auto server : writerServerOut_) finished &= server->eventLoop(enableEventsProcessing);
+      for(auto client : writerClientIn_) client->eventLoop();
+      for(auto server : writerServerIn_) finished &= server->eventLoop(enableEventsProcessing);
+      for(auto couplerOut : couplerOutClient_) couplerOut.second->eventLoop();
+      for(auto couplerIn : couplerInClient_) couplerIn.second->eventLoop();
+      for(auto couplerOut : couplerOutServer_) couplerOut.second->eventLoop(enableEventsProcessing);
+      for(auto couplerIn : couplerInServer_) couplerIn.second->eventLoop(enableEventsProcessing);
+    }
     setCurrent(getId()) ;
     return finalized && finished ;
@@ -837,10 +737,9 @@
    {
       registryOut->hierarchicalGatherRegistry() ;
-      if (server->getIntraCommRank()==0) CXios::getRegistryManager()->merge(*registryOut) ;
+      if (intraCommRank_==0) CXios::getRegistryManager()->merge(*registryOut) ;
 
       if (serviceType_==CServicesManager::CLIENT)
       {
 //ym        doPreTimestepOperationsForEnabledReadModeFiles(); // For now we only use server level 1 to read data
-
         triggerLateFields() ;
 
@@ -857,4 +756,8 @@
         } while (!couplersInFinalized) ;
 
+
+        auto& client=writerClientOut_[0] ;
+        auto& server=writerServerOut_[0] ;
+
         info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
         client->finalize();
@@ -865,5 +768,5 @@
         do
         {
-          notifiedFinalized=client->isNotifiedFinalized() ;
+          notifiedFinalized = client->isNotifiedFinalized() ;
         } while (!notifiedFinalized) ;
 
@@ -874,12 +777,12 @@
       else if (serviceType_==CServicesManager::GATHERER)
       {
-         for (int i = 0; i < clientPrimServer.size(); ++i)
+         for(auto& client : writerClientOut_)
          {
-           clientPrimServer[i]->finalize();
+           client->finalize();
            bool bufferReleased;
            do
            {
-             clientPrimServer[i]->eventLoop();
-             bufferReleased = !clientPrimServer[i]->havePendingRequests();
+             client->eventLoop();
+             bufferReleased = !client->havePendingRequests();
            } while (!bufferReleased);
            
@@ -887,16 +790,16 @@
            do
            {
-             notifiedFinalized=clientPrimServer[i]->isNotifiedFinalized() ;
+             notifiedFinalized=client->isNotifiedFinalized() ;
            } while (!notifiedFinalized) ;
-           clientPrimServer[i]->releaseBuffers();
+           client->releaseBuffers();
          }
          closeAllFile();
-
+         //ym writerClientIn & writerServerIn not released here ==> to check !!
       }
       else if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)
       {
         closeAllFile();
-        client->releaseBuffers();
-        server->releaseBuffers();
+        writerClientIn_[0]->releaseBuffers();
+        writerServerIn_[0]->releaseBuffers();
       }
 
@@ -916,14 +819,4 @@
        MPI_Comm_free(&(*it));
      comms.clear();
-   }
-   CATCH_DUMP_ATTR
-
-   //! Deallocate buffers allocated by clientContexts
-   void CContext::releaseClientBuffers(void)
-   TRY
-   {
-     client->releaseBuffers();
-     for (int i = 0; i < clientPrimServer.size(); ++i)
-       clientPrimServer[i]->releaseBuffers();
    }
    CATCH_DUMP_ATTR
@@ -1072,13 +965,13 @@
 
     // Distribute files between secondary servers according to the data size => assign a context to a file and then to fields
-    if (serviceType_==CServicesManager::GATHERER) distributeFiles(this->enabledWriteModeFiles);
-    else if (serviceType_==CServicesManager::CLIENT) for(auto file : this->enabledWriteModeFiles) file->setContextClient(client) ;
+    if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER ) distributeFiles(this->enabledWriteModeFiles);
+    //else if (serviceType_==CServicesManager::CLIENT) for(auto file : this->enabledWriteModeFiles) file->setContextClient(client) ;
 
     // client side, assign context for file reading
-    if (serviceType_==CServicesManager::CLIENT) for(auto file : this->enabledReadModeFiles) file->setContextClient(client) ;
+    if (serviceType_==CServicesManager::CLIENT) for(auto file : this->enabledReadModeFiles) file->setContextClient(writerClientOut_[0]) ;
     
     // server side, assign context where to send file data read
     if (serviceType_==CServicesManager::CServicesManager::GATHERER || serviceType_==CServicesManager::IO_SERVER) 
-      for(auto file : this->enabledReadModeFiles) file->setContextClient(client) ;
+      for(auto file : this->enabledReadModeFiles) file->setContextClient(writerClientIn_[0]) ;
    
 
@@ -1486,6 +1379,15 @@
      distFileMemory=CXios::getin<bool>("server2_dist_file_memory", distFileMemory);
 
-     if (distFileMemory) distributeFileOverMemoryBandwith(files) ;
+     int nbPools = writerClientOut_.size();
+     if (nbPools==1) distributeFileOverOne(files) ;
+     else if (distFileMemory) distributeFileOverMemoryBandwith(files) ;
      else distributeFileOverBandwith(files) ;
+   }
+   CATCH_DUMP_ATTR
+
+   void CContext::distributeFileOverOne(const vector<CFile*>& files)
+   TRY
+   {
+    for(auto& file : files) file->setContextClient(writerClientOut_[0]) ;
    }
    CATCH_DUMP_ATTR
@@ -1497,5 +1399,5 @@
      
      std::ofstream ofs(("distribute_file_"+getId()+".dat").c_str(), std::ofstream::out);
-     int nbPools = clientPrimServer.size();
+     int nbPools = writerClientOut_.size();
 
      // (1) Find all enabled files in write mode
@@ -1550,5 +1452,5 @@
        dataSize=(*poolDataSize.begin()).first ;
        j=(*poolDataSize.begin()).second ;
-       dataSizeMap[i].second->setContextClient(clientPrimServer[j]);
+       dataSizeMap[i].second->setContextClient(writerClientOut_[j]);
        dataSize+=dataSizeMap[i].first;
        poolDataSize.erase(poolDataSize.begin()) ;
@@ -1563,5 +1465,5 @@
    TRY
    {
-     int nbPools = clientPrimServer.size();
+     int nbPools = writerClientOut_.size();
      double ratio=0.5 ;
      ratio=CXios::getin<double>("server2_dist_file_memory_ratio", ratio);
@@ -1629,5 +1531,5 @@
          }
        }
-       filesList[i]->setContextClient(clientPrimServer[files[i].assignedServer_]) ;
+       filesList[i]->setContextClient(writerClientOut_[files[i].assignedServer_]) ;
        delete [] files[i].assignedGrid_ ;
      }
@@ -1729,33 +1631,4 @@
    CATCH
 
-   //! Client side: Send a message to server to make it close
-   // ym obsolete
-   void CContext::sendCloseDefinition(void)
-   TRY
-   {
-    int nbSrvPools ;
-    if (serviceType_==CServicesManager::CLIENT) nbSrvPools = 1 ;
-    else if (serviceType_==CServicesManager::GATHERER) nbSrvPools = this->clientPrimServer.size() ;
-    else nbSrvPools = 0 ;
-    CContextClient* contextClientTmp ;
-
-    for (int i = 0; i < nbSrvPools; ++i)
-     {
-       if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ;
-       else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ;
-       CEventClient event(getType(),EVENT_ID_CLOSE_DEFINITION);
-       if (contextClientTmp->isServerLeader())
-       {
-         CMessage msg;
-         const std::list<int>& ranks = contextClientTmp->getRanksServerLeader();
-         for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-           event.push(*itRank,1,msg);
-         contextClientTmp->sendEvent(event);
-       }
-       else contextClientTmp->sendEvent(event);
-     }
-   }
-   CATCH_DUMP_ATTR
-   
    //  ! Client side: Send a message to server to make it close
    void CContext::sendCloseDefinition(CContextClient* client)
Index: /XIOS3/trunk/src/node/context.hpp
===================================================================
--- /XIOS3/trunk/src/node/context.hpp	(revision 2405)
+++ /XIOS3/trunk/src/node/context.hpp	(revision 2406)
@@ -160,10 +160,10 @@
          // Distribute files (in write mode) among secondary-server pools according to the estimated data flux
          void distributeFiles(const std::vector<CFile*>& files);
-         void distributeFileOverBandwith(const std::vector<CFile*>& files) ;
-         void distributeFileOverMemoryBandwith(const std::vector<CFile*>& files) ;
+         void distributeFileOverOne(const vector<CFile*>& files) ; //!< Distribute files over one single server (no distribution)
+         void distributeFileOverBandwith(const std::vector<CFile*>& files) ; //!< Distribute files overs servers to balance the I/O bandwith
+         void distributeFileOverMemoryBandwith(const std::vector<CFile*>& files) ; //!< Distribute files overs servers to minimize the memory consumption
          
+       public:
          // Send context close definition
-         void sendCloseDefinition(void);
-       public:
          void sendCloseDefinition(CContextClient* client) ;
        private:
@@ -223,5 +223,4 @@
        public:  
         void freeComms(void);                  //!< Free internally allcoated communicators
-        void releaseClientBuffers(void);       //! Deallocate buffers allocated by clientContexts
 
          // dispatch event
@@ -309,6 +308,5 @@
          bool hasServer;
 
-         CContextServer* server;    //!< Concrete context server
-         CContextClient* client;    //!< Concrete contex client
+      private:
          std::vector<CContextServer*> serverPrimServer;
          std::vector<CContextClient*> clientPrimServer;
@@ -321,4 +319,15 @@
         std::string defaultWriterId ;
         std::string defaultGathererId ;
+
+        std::vector<CContextClient*> writerClientOut_ ;
+        std::vector<CContextServer*> writerServerOut_ ;
+        std::vector<CContextClient*> writerClientIn_ ;
+        std::vector<CContextServer*> writerServerIn_ ;
+
+        std::vector<CContextClient*> readerClientOut_ ;
+        std::vector<CContextServer*> readerServerOut_ ;
+        std::vector<CContextClient*> readerClientIn_ ;
+        std::vector<CContextServer*> readerServerIn_ ;
+
 
         std::map<std::string, CContextClient*> clients_ ;
Index: /XIOS3/trunk/src/node/field.cpp
===================================================================
--- /XIOS3/trunk/src/node/field.cpp	(revision 2405)
+++ /XIOS3/trunk/src/node/field.cpp	(revision 2406)
@@ -1456,8 +1456,4 @@
   CATCH_DUMP_ATTR
 
-  void CField::sendCloseDefinition(void)
-  {
-    CContext::getCurrent()->sendCloseDefinition(client) ;
-  }
 
   void CField::sendFieldToFileServer(void)
Index: /XIOS3/trunk/src/node/field.hpp
===================================================================
--- /XIOS3/trunk/src/node/field.hpp	(revision 2405)
+++ /XIOS3/trunk/src/node/field.hpp	(revision 2406)
@@ -146,5 +146,4 @@
 
          void sendFieldToFileServer(void) ;
-         void sendCloseDefinition(void) ;
       
       public:
