Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/axis.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/axis.cpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/axis.cpp	(revision 1761)
@@ -847,5 +847,8 @@
 
       numberWrittenIndexes_[writtenCommSize] = nbWritten;
-      if (isDistributed())
+
+      bool distributed_glo, distributed=isDistributed() ;
+      MPI_Allreduce(&distributed,&distributed_glo, 1, MPI_INT, MPI_LOR, writtenComm) ;
+      if (distributed_glo)
       {
              
Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.cpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.cpp	(revision 1761)
@@ -20,4 +20,8 @@
 #include "server.hpp"
 #include "distribute_file_server2.hpp"
+#include "services_manager.hpp"
+#include "contexts_manager.hpp"
+#include "cxios.hpp"
+#include "client.hpp"
 
 namespace xios {
@@ -31,6 +35,6 @@
       , calendar(), hasClient(false), hasServer(false)
       , isPostProcessed(false), finalized(false)
-      , idServer_(), client(0), server(0)
-      , allProcessed(false), countChildCtx_(0)
+      , idServer_(), client(nullptr), server(nullptr)
+      , allProcessed(false), countChildCtx_(0), isProcessingEvent_(false)
 
    { /* Ne rien faire de plus */ }
@@ -40,6 +44,6 @@
       , calendar(), hasClient(false), hasServer(false)
       , isPostProcessed(false), finalized(false)
-      , idServer_(), client(0), server(0)
-      , allProcessed(false), countChildCtx_(0)
+      , idServer_(), client(nullptr), server(nullptr)
+      , allProcessed(false), countChildCtx_(0), isProcessingEvent_(false)
    { /* Ne rien faire de plus */ }
 
@@ -264,5 +268,6 @@
    ///---------------------------------------------------------------
 
-   //! Initialize client side
+
+   //! Initialize client side : old interface to be removed
    void CContext::initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer /*= 0*/)
    TRY
@@ -270,5 +275,5 @@
 
      hasClient = true;
-     MPI_Comm intraCommServer, interCommServer;
+     MPI_Comm intraCommServer, interCommServer; 
      
 
@@ -383,4 +388,214 @@
    CATCH_DUMP_ATTR
 
+
+   void CContext::init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType)
+   TRY
+   {
+     parentServerContext_ = parentServerContext ;
+     if (serviceType==CServicesManager::CLIENT) 
+       initClient(intraComm, serviceType) ;
+     else
+       initServer(intraComm, serviceType) ;
+    }
+    CATCH_DUMP_ATTR
+
+
+
+//! Initialize client side
+   void CContext::initClient(MPI_Comm intraComm, int serviceType)
+   TRY
+   {
+      intraComm_=intraComm ;
+      serviceType_ = CServicesManager::CLIENT ;
+      if (serviceType_==CServicesManager::CLIENT)
+      {
+        hasClient=true ;
+        hasServer=false ;
+      }
+      contextId_ = getId() ;
+      
+      attached_mode=true ;
+      if (!CXios::isUsingServer()) attached_mode=false ;
+
+
+      string contextRegistryId=getId() ;
+      registryIn=new CRegistry(intraComm);
+      registryIn->setPath(contextRegistryId) ;
+      
+      int commRank ;
+      MPI_Comm_rank(intraComm_,&commRank) ;
+      if (commRank==0) registryIn->fromFile("xios_registry.bin") ;
+      registryIn->bcastRegistry() ;
+      registryOut=new CRegistry(intraComm_) ;
+      registryOut->setPath(contextRegistryId) ;
+     
+   }
+   CATCH_DUMP_ATTR
+
+   
+   void CContext::initServer(MPI_Comm intraComm, int serviceType)
+   TRY
+   {
+     hasServer=true;
+     intraComm_=intraComm ;
+     serviceType_=serviceType ;
+
+     if (serviceType_==CServicesManager::GATHERER)
+     {
+       hasClient=true ;
+       hasServer=true ;
+     }
+     else if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)
+     {
+       hasClient=false ;
+       hasServer=true ;
+     }
+
+     CXios::getContextsManager()->getContextId(getId(), contextId_, intraComm) ;
+     
+     registryIn=new CRegistry(intraComm);
+     registryIn->setPath(contextId_) ;
+     
+     int commRank ;
+     MPI_Comm_rank(intraComm_,&commRank) ;
+     if (commRank==0) registryIn->fromFile("xios_registry.bin") ;
+    
+     registryIn->bcastRegistry() ;
+     registryOut=new CRegistry(intraComm) ;
+     registryOut->setPath(contextId_) ;
+
+   }
+   CATCH_DUMP_ATTR
+
+
+  void CContext::createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer) // for servers
+  TRY
+  {
+    MPI_Comm intraCommClient ;
+    MPI_Comm_dup(intraComm_, &intraCommClient);
+    comms.push_back(intraCommClient);
+    
+    server = new CContextServer(this,intraComm_, interCommServer); // check if we need to dupl. intraComm_ ?
+    client = new CContextClient(this,intraCommClient,interCommClient);
+
+  }
+  CATCH_DUMP_ATTR
+
+  void CContext::createServerInterComm(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(), 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(), 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_) ;
+        setIdServer(CXios::getContextsManager()->getServerContextName(CClient::getPoolRessource()->getId(), CXios::defaultServerId, 0, type, getContextId())) ;
+        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_) ;
+        setIdServer(CXios::getContextsManager()->getServerContextName(CXios::defaultPoolId, CXios::defaultGathererId, 0, type, getContextId())) ;
+      }
+      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_) ;
+        setIdServer(CXios::getContextsManager()->getServerContextName(CXios::defaultPoolId, CXios::defaultServerId, 0, 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 ;
+        MPI_Comm interCommClient, interCommServer ;
+
+        intraCommClient=intraComm_ ;
+        MPI_Comm_dup(intraComm_, &intraCommServer) ;
+
+        interCommClient=interComm ;               
+        MPI_Comm_dup(interComm, &interCommServer) ; */
+      
+      MPI_Comm intraCommClient, intraCommServer ;
+      intraCommClient=intraComm_ ;
+      MPI_Comm_dup(intraComm_, &intraCommServer) ;
+      client = new CContextClient(this, intraCommClient, interCommClient);
+      server = new CContextServer(this, intraCommServer, interCommServer);
+    
+    }
+    
+    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++)
+      {
+//        CXios::getContextsManager()->createServerContextIntercomm(CXios::defaultPoolId, CXios::defaultServerId, i, getContextId(), intraComm_, interComm) ;
+        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 ;
+//        MPI_Comm interCommClient, interCommServer ;
+
+        intraCommClient=intraComm_ ;
+        MPI_Comm_dup(intraComm_, &intraCommServer) ;
+
+//        interCommClient=interComm ;               
+//        MPI_Comm_dup(interComm, &interCommServer) ;
+
+        clientPrimServer.push_back(new CContextClient(this, intraCommClient, interCommClient));
+        serverPrimServer.push_back(new CContextServer(this, intraCommServer, interCommServer));  
+      
+      }
+    }
+  }
+  CATCH_DUMP_ATTR
+
+ 
    void CContext::initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient /*= 0*/)
    TRY
@@ -418,4 +633,23 @@
    }
    CATCH_DUMP_ATTR
+
+ 
+
+  bool CContext::eventLoop(bool enableEventsProcessing)
+  {
+    bool finished=true; 
+
+    if (client!=nullptr && !finalized) client->checkBuffers();
+    
+    for (int i = 0; i < clientPrimServer.size(); ++i)
+    {
+      if (!finalized) clientPrimServer[i]->checkBuffers();
+      if (!finalized) finished &= serverPrimServer[i]->eventLoop(enableEventsProcessing);
+    }
+
+    if (server!=nullptr) if (!finalized) finished &= server->eventLoop(enableEventsProcessing);
+  
+    return finalized && finished ;
+  }
 
    //! Try to send the buffers and receive possible answers
@@ -451,7 +685,9 @@
     }
   }
-   CATCH_DUMP_ATTR
-
-   //! Terminate a context
+  CATCH_DUMP_ATTR
+
+
+
+
    void CContext::finalize(void)
    TRY
@@ -462,6 +698,5 @@
       }
      // Send registry upon calling the function the first time
-     if (countChildCtx_ == 0)
-       if (hasClient) sendRegistry() ;
+     if (countChildCtx_ == 0) if (hasClient) sendRegistry() ;
 
      // Client:
@@ -562,4 +797,6 @@
          
          closeAllFile(); // Just move to here to make sure that server-level 1 can close files
+        
+        /*  ym
          if (hasServer && !hasClient)
          {           
@@ -567,4 +804,5 @@
            if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
          }
+        */
 
          //! Deallocate client buffers
@@ -589,4 +827,144 @@
    CATCH_DUMP_ATTR
 
+
+
+   //! Terminate a context
+   void CContext::finalize_old(void)
+   TRY
+   {
+      if (hasClient && !hasServer) // For now we only use server level 1 to read data
+      {
+        doPreTimestepOperationsForEnabledReadModeFiles();
+      }
+     // Send registry upon calling the function the first time
+     if (countChildCtx_ == 0) if (hasClient) sendRegistry() ;
+
+     // Client:
+     // (1) blocking send context finalize to its server
+     // (2) blocking receive context finalize from its server
+     // (3) some memory deallocations
+     if (CXios::isClient)
+     {
+       // Make sure that client (model) enters the loop only once
+       if (countChildCtx_ < 1)
+       {
+         ++countChildCtx_;
+
+         info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
+         client->finalize();
+         info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent"<<endl ;
+         while (client->havePendingRequests()) client->checkBuffers();
+         
+         info(100)<<"DEBUG: context "<<getId()<<" no pending request ok"<<endl ;
+         while (!server->hasFinished())
+           server->eventLoop();
+        info(100)<<"DEBUG: context "<<getId()<<" server has finished"<<endl ;
+        
+        bool notifiedFinalized=false ;
+        do
+        {
+          notifiedFinalized=client->isNotifiedFinalized() ;
+        } while (!notifiedFinalized) ;
+        client->releaseBuffers();
+
+         if (hasServer) // Mode attache
+         {
+           closeAllFile();
+           registryOut->hierarchicalGatherRegistry() ;
+           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
+         }
+
+         //! Deallocate client buffers
+//         client->releaseBuffers();
+        info(100)<<"DEBUG: context "<<getId()<<" release client ok"<<endl ;
+         //! Free internally allocated communicators
+         for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
+           MPI_Comm_free(&(*it));
+         comms.clear();
+
+         info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl;
+       }
+     }
+     else if (CXios::isServer)
+     {
+       // First context finalize message received from a model
+       // Send context finalize to its child contexts (if any)
+       if (countChildCtx_ == 0)
+         for (int i = 0; i < clientPrimServer.size(); ++i)
+         {
+           clientPrimServer[i]->finalize();
+           bool bufferReleased;
+           do
+           {
+             clientPrimServer[i]->checkBuffers();
+             bufferReleased = !clientPrimServer[i]->havePendingRequests();
+           } while (!bufferReleased);
+           
+           bool notifiedFinalized=false ;
+           do
+           {
+//             clientPrimServer[i]->checkBuffers();
+             notifiedFinalized=clientPrimServer[i]->isNotifiedFinalized() ;
+           } while (!notifiedFinalized) ;
+           clientPrimServer[i]->releaseBuffers();
+         }
+           
+
+       // (Last) context finalized message received
+       if (countChildCtx_ == clientPrimServer.size())
+       {
+         // Blocking send of context finalize message to its client (e.g. primary server or model)
+         info(100)<<"DEBUG: context "<<getId()<<" Send client finalize"<<endl ;
+         client->finalize();
+         info(100)<<"DEBUG: context "<<getId()<<" Client finalize sent"<<endl ;
+         bool bufferReleased;
+         do
+         {
+           client->checkBuffers();
+           bufferReleased = !client->havePendingRequests();
+         } while (!bufferReleased);
+         
+         bool notifiedFinalized=false ;
+         do
+         {
+  //         client->checkBuffers();
+           notifiedFinalized=client->isNotifiedFinalized() ;
+         } while (!notifiedFinalized) ;
+         client->releaseBuffers();
+         
+         finalized = true;
+         info(100)<<"DEBUG: context "<<getId()<<" bufferRelease OK"<<endl ;
+         
+         closeAllFile(); // Just move to here to make sure that server-level 1 can close files
+        
+        /*  ym
+         if (hasServer && !hasClient)
+         {           
+           registryOut->hierarchicalGatherRegistry() ;
+           if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
+         }
+        */
+
+         //! Deallocate client buffers
+//         client->releaseBuffers();
+         info(100)<<"DEBUG: context "<<getId()<<" client release"<<endl ;
+
+/*         
+         for (int i = 0; i < clientPrimServer.size(); ++i)
+           clientPrimServer[i]->releaseBuffers();
+*/
+         //! Free internally allocated communicators
+         for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
+           MPI_Comm_free(&(*it));
+         comms.clear();
+
+         info(20)<<"CContext: Context <"<<getId()<<"> is finalized."<<endl;
+       }
+
+       ++countChildCtx_;
+     }
+   }
+   CATCH_DUMP_ATTR
+
    //! Free internally allocated communicators
    void CContext::freeComms(void)
@@ -614,4 +992,9 @@
      if (allProcessed) return;  
      
+    // create intercommunicator with servers. 
+    // not sure it is the good place to be called here 
+    createServerInterComm() ;
+
+
      // After xml is parsed, there are some more works with post processing
      postProcessing();
@@ -734,5 +1117,7 @@
    TRY
    {
-    CTimer::get("Context : close definition").resume() ;
+     CTimer::get("Context : close definition").resume() ;
+    
+    //
     postProcessingGlobalAttributes();
 
@@ -1548,4 +1933,28 @@
    CATCH_DUMP_ATTR
 
+   void CContext::setIdServer(const StdString& idServer)
+   TRY
+   {
+      idServer_=idServer ;
+   }
+   CATCH_DUMP_ATTR
+
+   
+   const StdString& CContext::getIdServer()
+   TRY
+   {
+      return idServer_;
+   }
+   CATCH_DUMP_ATTR
+
+   const StdString& CContext::getIdServer(const int i)
+   TRY
+   {
+//     return idServer_ + std::to_string(static_cast<unsigned long long>(i));
+      return primServerId_[i] ;
+   }
+   CATCH_DUMP_ATTR
+
+/*
    const StdString& CContext::getIdServer()
    TRY
@@ -1570,4 +1979,6 @@
    }
    CATCH_DUMP_ATTR
+*/
+
 
    /*!
Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/context.hpp	(revision 1761)
@@ -12,4 +12,6 @@
 #include "registry.hpp"
 #include "mpi.hpp"
+#include "services_manager.hpp"
+#include "server_context.hpp"
 
 
@@ -89,5 +91,12 @@
          // Initialize server or client
          void initClient(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtServer = 0);
+         void init(CServerContext* parentServerContext, MPI_Comm intraComm, int serviceType);
+         void initClient(MPI_Comm intraComm, int serviceType);
+         
          void initServer(MPI_Comm intraComm, MPI_Comm interComm, CContext* cxtClient = 0);
+         void initServer(MPI_Comm intraComm, int serviceType );
+         void createClientInterComm(MPI_Comm interCommClient, MPI_Comm interCommServer)  ;
+         void createServerInterComm(void)  ;
+
          bool isInitialized(void);
 
@@ -96,7 +105,9 @@
          // Put sever or client into loop state
          bool checkBuffersAndListen(bool enableEventsProcessing=true);
+         bool eventLoop(bool enableEventsProcessing=true);
 
          // Finalize a context
          void finalize(void);
+         void finalize_old(void);
          bool isFinalized(void);
 
@@ -161,5 +172,7 @@
 
          const StdString& getIdServer();
+         void setIdServer(const StdString& idServer);
          const StdString& getIdServer(const int srvPoolNb);
+         std::string getContextId() {return contextId_;}
 
          // Client side: Receive and process messages
@@ -208,4 +221,5 @@
         static void ShowTree(StdOStream & out = std::clog);
         static void CleanTree(void);
+        int getServiceType(void) {return serviceType_;}
 
       public :
@@ -223,4 +237,7 @@
          virtual bool hasChild(void) const;
 
+         bool isProcessingEvent(void) {return isProcessingEvent_;}
+         bool setProcessingEvent(void) {isProcessingEvent_=true ;}
+         bool unsetProcessingEvent(void) {isProcessingEvent_=false ;}
 
       public :
@@ -252,7 +269,11 @@
          std::vector<CContextServer*> serverPrimServer;
          std::vector<CContextClient*> clientPrimServer;
+         std::vector<std::string> primServerId_;
 
          CRegistry* registryIn ;    //!< input registry which is read from file
          CRegistry* registryOut ;   //!< output registry which will be written into file at the finalize
+
+
+        MPI_Comm intraComm_ ; //! context intra communicator
 
       private:
@@ -265,4 +286,9 @@
          std::list<MPI_Comm> comms; //!< Communicators allocated internally
 
+         int serviceType_;  //!< service associated to the context
+         string contextId_ ; //!< context client id for the servers. For clients this is same as getId() 
+         bool isProcessingEvent_ ;
+         CServerContext* parentServerContext_ ;
+
       public: // Some function maybe removed in the near future
         // virtual void toBinary  (StdOStream & os) const;
Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/domain.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/domain.cpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/domain.cpp	(revision 1761)
@@ -226,4 +226,5 @@
       bool distributed =  !((!ni.isEmpty() && (ni == ni_glo) && !nj.isEmpty() && (nj == nj_glo)) ||
               (!i_index.isEmpty() && i_index.numElements() == ni_glo*nj_glo));
+      bool distributed_glo ;
       distributed |= (1 == CContext::getCurrent()->client->clientSize);
 
@@ -2061,5 +2062,8 @@
 
       numberWrittenIndexes_[writtenCommSize] = nbWritten;
-      if (isDistributed())
+      bool distributed_glo, distributed=isDistributed() ;
+      MPI_Allreduce(&distributed,&distributed_glo, 1, MPI_INT, MPI_LOR, writtenComm) ;
+      
+      if (distributed_glo)
       {
              
Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/field.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/field.cpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/field.cpp	(revision 1761)
@@ -634,5 +634,6 @@
           timer.resume();
 
-          context->checkBuffersAndListen();
+//ym          context->checkBuffersAndListen();
+            context->eventLoop();
 
           timer.suspend();
Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/file.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/file.cpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/file.cpp	(revision 1761)
@@ -323,6 +323,7 @@
       // Done by classical server or secondary server
       // This condition should be changed soon
-      if (CServer::serverLevel == 0 || CServer::serverLevel == 2)
-      {
+//ym      if (CServer::serverLevel == 0 || CServer::serverLevel == 2)
+       if (context->getServiceType()==CServicesManager::IO_SERVER || context->getServiceType()==CServicesManager::OUT_SERVER)
+       {
         if (mode.isEmpty() || mode.getValue() == mode_attr::write)
         {
@@ -349,5 +350,7 @@
       // Done by classical server or secondary server
       // TODO: This condition should be changed soon. It only works with maximum number of level as 2
-      if (CServer::serverLevel == 0 || CServer::serverLevel == 1)
+
+//ym      if (CServer::serverLevel == 0 || CServer::serverLevel == 1)
+      if (context->getServiceType()==CServicesManager::IO_SERVER || context->getServiceType()==CServicesManager::GATHERER)
       {
         if (!mode.isEmpty() && mode.getValue() == mode_attr::read)
Index: XIOS/dev/dev_ym/XIOS_SERVICES/src/node/grid.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_SERVICES/src/node/grid.cpp	(revision 1758)
+++ XIOS/dev/dev_ym/XIOS_SERVICES/src/node/grid.cpp	(revision 1761)
@@ -907,5 +907,6 @@
        }
      }
-     if (CServer::serverLevel==2)
+//ym     if (CServer::serverLevel==2)
+     if (context->getServiceType()==CServicesManager::OUT_SERVER)
      {
        computeWrittenIndex() ;
@@ -1679,10 +1680,12 @@
     connectedServerRankRead_ = ranks;
 
-    int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1;
-    nbSrvPools = 1;    
+// ym something is bad here, I comment some line, to be checked in future
+   // int nbSrvPools = (context->hasServer) ? (context->hasClient ? context->clientPrimServer.size() : 1) : 1;
+    int nbSrvPools = 1;    
     nbReadSenders.clear();
     for (int p = 0; p < nbSrvPools; ++p)
     {
-      CContextServer* server = (!context->hasClient) ? context->server : context->serverPrimServer[p];
+     // CContextServer* server = (!context->hasClient) ? context->server : context->serverPrimServer[p];
+      CContextServer* server = context->server  ;
       CContextClient* client = context->client;   //(!context->hasClient) ? context->client : context->clientPrimServer[p];
       
