Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/axis.cpp	(revision 1853)
@@ -319,5 +319,5 @@
       {
         // Avoid this check at writing because it fails in case of a hole
-        if (context->hasClient)
+        if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
         {
           StdSize true_size = value.numElements();
@@ -333,5 +333,5 @@
       this->checkBounds();
 
-      if (context->hasClient)
+      if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
       {
         this->checkMask();
@@ -512,5 +512,5 @@
 
      CContext* context=CContext::getCurrent();
-     if (context->hasClient && !context->hasServer) this->checkAttributes();
+     if (context->getServiceType()==CServicesManager::CLIENT) this->checkAttributes();
 
      this->areClientAttributesChecked_ = true;
@@ -529,5 +529,5 @@
 
      if (this->isClientAfterTransformationChecked) return;
-     if (context->hasClient)
+     if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
      {        
        if (orderPositionInGrid == CServerDistributionDescription::defaultDistributedDimension(globalDim.size(), distType))
@@ -556,5 +556,5 @@
 
      if (this->isChecked) return;
-     if (context->hasClient) sendAttributes(globalDim, orderPositionInGrid, distType);    
+     if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER) sendAttributes(globalDim, orderPositionInGrid, distType);    
 
      this->isChecked = true;
@@ -734,5 +734,4 @@
 
     CContext* context=CContext::getCurrent();      
-    CContextServer* server = context->server; 
 
     // We describe the distribution of client (server) on which data are written
@@ -742,5 +741,5 @@
     nBeginGlobal[0] = 0; 
     nGlob[0]        = n_glo;
-    CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); 
+    CDistributionServer srvDist(context->intraCommSize_, nBegin, nSize, nBeginGlobal, nGlob); 
     const CArray<size_t,1>& writtenGlobalIndex  = srvDist.getGlobalIndex();
 
@@ -784,6 +783,5 @@
       size_t nbWritten = 0, indGlo;
       CContext* context=CContext::getCurrent();      
-      CContextServer* server = context->server; 
-
+ 
       // We describe the distribution of client (server) on which data are written
       std::vector<int> nBegin(1), nSize(1), nBeginGlobal(1), nGlob(1);
@@ -792,5 +790,5 @@
       nBeginGlobal[0] = 0; 
       nGlob[0]        = n_glo;
-      CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); 
+      CDistributionServer srvDist(context->intraCommSize_, nBegin, nSize, nBeginGlobal, nGlob); 
       const CArray<size_t,1>& writtenGlobalIndex  = srvDist.getGlobalIndex();
       std::unordered_map<size_t,size_t>::const_iterator itb = globalLocalIndexMap_.begin(),
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/context.cpp	(revision 1853)
@@ -432,4 +432,6 @@
     server = new CContextServer(this,intraComm_, interCommServer); // check if we need to dupl. intraComm_ ?
     client = new CContextClient(this,intraCommClient,interCommClient);
+    client->setAssociatedServer(server) ;  
+    server->setAssociatedClient(client) ;  
 
   }
@@ -492,5 +494,6 @@
       client = new CContextClient(this, intraCommClient, interCommClient);
       server = new CContextServer(this, intraCommServer, interCommServer);
-    
+      client->setAssociatedServer(server) ;
+      server->setAssociatedClient(client) ;
     }
     
@@ -526,7 +529,11 @@
         MPI_Comm_dup(intraComm_, &intraCommServer) ;
 
-
-        clientPrimServer.push_back(new CContextClient(this, intraCommClient, interCommClient));
-        serverPrimServer.push_back(new CContextServer(this, intraCommServer, interCommServer));  
+        CContextClient* client = new CContextClient(this, intraCommClient, interCommClient) ;
+        CContextServer* server = new CContextServer(this, intraCommServer, interCommServer) ;
+        client->setAssociatedServer(server) ;
+        server->setAssociatedClient(client) ;
+        clientPrimServer.push_back(client);
+        serverPrimServer.push_back(server);  
+
       
       }
@@ -592,4 +599,6 @@
          CContextClient* client = new CContextClient(this, intraCommClient, interCommClient);
          CContextServer* server = new CContextServer(this, intraCommServer, interCommServer);
+         client->setAssociatedServer(server) ;
+         server->setAssociatedClient(client) ;
        }
        else
@@ -599,4 +608,6 @@
           CContextServer* server = new CContextServer(this, intraCommServer, interCommServer);
           CContextClient* client = new CContextClient(this, intraCommClient, interCommClient);
+          client->setAssociatedServer(server) ;
+          server->setAssociatedClient(client) ;
        }
        MPI_Comm_free(&interComm) ;
@@ -633,5 +644,5 @@
       if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
 
-      if (hasClient && !hasServer)
+      if (serviceType_==CServicesManager::CLIENT)
       {
         doPreTimestepOperationsForEnabledReadModeFiles(); // For now we only use server level 1 to read data
@@ -650,5 +661,5 @@
         info(100)<<"DEBUG: context "<<getId()<<" release client ok"<<endl ;
       }
-      else if (hasClient && hasServer)
+      else if (serviceType_==CServicesManager::GATHERER)
       {
          for (int i = 0; i < clientPrimServer.size(); ++i)
@@ -672,5 +683,5 @@
 
       }
-      else if (!hasClient && hasServer)
+      else if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER)
       {
         closeAllFile();
@@ -724,12 +735,12 @@
      checkGridEnabledFields();
 
-     setClientServerBuffer(client, (hasClient && !hasServer));
+     setClientServerBuffer(client, (serviceType_==CServicesManager::CLIENT) ) ;
      for (int i = 0; i < clientPrimServer.size(); ++i)
          setClientServerBuffer(clientPrimServer[i], true);
 
     
-     if (hasClient)
+     if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER)
      { 
-       if (hasServer)
+       if (serviceType_==CServicesManager::GATHERER)
        { 
          for (auto it=clientPrimServer.begin(); it!=clientPrimServer.end();++it) 
@@ -739,5 +750,5 @@
          }
        }
-       else
+       else 
        {
          this->sendAllAttributesToServer(client);   // Send all attributes of current context to server
@@ -750,17 +761,16 @@
       sendEnabledFiles(this->enabledWriteModeFiles);
       // We only use server-level 1 (for now) to read data
-      if (!hasServer)
-        sendEnabledFiles(this->enabledReadModeFiles);
+      if (serviceType_==CServicesManager::CLIENT)  sendEnabledFiles(this->enabledReadModeFiles);
 
       // Then, send all enabled fields      
       sendEnabledFieldsInFiles(this->enabledWriteModeFiles);
-      if (!hasServer)
-        sendEnabledFieldsInFiles(this->enabledReadModeFiles);
+      
+      if (serviceType_==CServicesManager::CLIENT) sendEnabledFieldsInFiles(this->enabledReadModeFiles);
 
       // Then, check whether we have domain_ref, axis_ref or scalar_ref attached to the enabled fields
       // If any, so send them to server
-       sendRefDomainsAxisScalars(this->enabledWriteModeFiles);
-      if (!hasServer)
-        sendRefDomainsAxisScalars(this->enabledReadModeFiles);        
+       sendRefDomainsAxisScalars(this->enabledWriteModeFiles); 
+     
+      if (serviceType_==CServicesManager::CLIENT) sendRefDomainsAxisScalars(this->enabledReadModeFiles);        
 
        // Check whether enabled fields have grid_ref, if any, send this info to server
@@ -780,6 +790,7 @@
       // Finally, we send information of grid itself to server 
       sendGridEnabledFieldsInFiles(this->enabledWriteModeFiles);       
-      if (!hasServer)
-        sendGridEnabledFieldsInFiles(this->enabledReadModeFiles);       
+     
+      if (serviceType_==CServicesManager::CLIENT) sendGridEnabledFieldsInFiles(this->enabledReadModeFiles);       
+     
      }
      allProcessed = true;
@@ -790,10 +801,16 @@
    TRY
    {
-      // Use correct context client to send message
-     // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1;
-    int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
-     for (int i = 0; i < nbSrvPools; ++i)
-     {
-       CContextClient* contextClientTmp = (0 != clientPrimServer.size()) ? clientPrimServer[i] : client;
+
+    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_POST_PROCESS_GLOBAL_ATTRIBUTES);
 
@@ -844,10 +861,10 @@
     postProcessingGlobalAttributes();
 
-    if (hasClient) sendPostProcessingGlobalAttributes();
+    if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER) sendPostProcessingGlobalAttributes();
 
     // There are some processings that should be done after all of above. For example: check mask or index
     this->buildFilterGraphOfEnabledFields();
     
-     if (hasClient && !hasServer)
+     if (serviceType_==CServicesManager::CLIENT)
     {
       buildFilterGraphOfFieldsWithReadAccess();
@@ -857,15 +874,13 @@
     checkGridEnabledFields();   
 
-    if (hasClient) this->sendProcessingGridOfEnabledFields();
-    if (hasClient) this->sendCloseDefinition();
+    if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER) this->sendProcessingGridOfEnabledFields();
+    if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER) this->sendCloseDefinition();
 
     // Nettoyage de l'arborescence
-    if (hasClient) CleanTree(); // Only on client side??
-
-    if (hasClient)
-    {
-      sendCreateFileHeader();
-      if (!hasServer) startPrefetchingOfEnabledReadModeFiles();
-    }
+    if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER) CleanTree(); // Only on client side??
+
+    if (serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER) sendCreateFileHeader();
+    if (serviceType_==CServicesManager::CLIENT) startPrefetchingOfEnabledReadModeFiles();
+    
     CTimer::get("Context : close definition").suspend() ;
    }
@@ -1109,6 +1124,5 @@
       const vector<CGrid*> allGrids= CGrid::getAll();
 
-      if (hasClient && !hasServer)
-      //if (hasClient)
+      if (serviceType_==CServicesManager::CLIENT)
       {
         for (unsigned int i = 0; i < allFiles.size(); i++)
@@ -1229,6 +1243,5 @@
      double eps=std::numeric_limits<double>::epsilon()*10 ;
      
-     // If primary server
-     if (hasServer && hasClient)
+     if (serviceType_==CServicesManager::GATHERER)
      {
        std::ofstream ofs(("distribute_file_"+getId()+".dat").c_str(), std::ofstream::out);
@@ -1310,6 +1323,5 @@
    TRY
    {
-     // If primary server
-     if (hasServer && hasClient)
+     if (serviceType_==CServicesManager::GATHERER)
      {
        int nbPools = clientPrimServer.size();
@@ -1502,9 +1514,14 @@
    TRY
    {
-     // Use correct context client to send message
-     int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
-     for (int i = 0; i < nbSrvPools; ++i)
-     {
-       CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client;
+    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())
@@ -1534,9 +1551,14 @@
    TRY
    {
-     // Use correct context client to send message
-    int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
-     for (int i = 0; i < nbSrvPools; ++i)
-     {
-       CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client;
+    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_UPDATE_CALENDAR);
 
@@ -1544,8 +1566,5 @@
          {
            CMessage msg;
-           if (hasServer)
-             msg<<step;
-           else
-             msg<<step;
+           msg<<step;
            const std::list<int>& ranks = contextClientTmp->getRanksServerLeader();
            for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
@@ -1574,5 +1593,5 @@
       buffer>>step;
       updateCalendar(step);
-      if (hasClient && hasServer)
+      if (serviceType_==CServicesManager::GATHERER)
       {        
         sendUpdateCalendar(step);
@@ -1585,10 +1604,14 @@
    TRY
    {
-     // Use correct context client to send message
-     // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1;
-     int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
+     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)
      {
-       CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client;
+       if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ;
+       else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ;
        CEventClient event(getType(),EVENT_ID_CREATE_FILE_HEADER);
 
@@ -1619,5 +1642,5 @@
    TRY
    {
-      if (!hasClient && hasServer) 
+      if (serviceType_==CServicesManager::IO_SERVER || serviceType_==CServicesManager::OUT_SERVER) 
         createFileHeader();
    }
@@ -1628,9 +1651,15 @@
    TRY
    {
-      // Use correct context client to send message
-     int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
+     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)
      {
-       CContextClient* contextClientTmp = (0 != clientPrimServer.size()) ? clientPrimServer[i] : client;
+       if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ;
+       else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ;
+
        CEventClient event(getType(),EVENT_ID_PROCESS_GRID_ENABLED_FIELDS);
 
@@ -1661,10 +1690,14 @@
    TRY
    {
-      // Use correct context client to send message
-     // int nbSrvPools = (hasServer) ? clientPrimServer.size() : 1;
-     int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
+     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)
      {
-       CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client;
+       if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ;
+       else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ;
        CEventClient event(getType(),EVENT_ID_POST_PROCESS);
        if (contextClientTmp->isServerLeader())
@@ -1732,5 +1765,6 @@
 
       // The timeseries should only be prepared in client
-      if (hasClient && !hasServer) prepareTimeseries();
+
+      if (serviceType_==CServicesManager::CLIENT) prepareTimeseries();
 
       //Initialisation du vecteur 'enabledFiles' contenant la liste des fichiers Ã  sortir.
@@ -1754,5 +1788,5 @@
       //   findAllEnabledFieldsInFiles(this->enabledReadModeFiles);      
 
-      if (hasClient && !hasServer)
+      if (serviceType_==CServicesManager::CLIENT)
       {
         initReadFiles();
@@ -1768,7 +1802,7 @@
 
       // Find all fields with read access from the public API
-      if (hasClient && !hasServer) findFieldsWithReadAccess();
+      if (serviceType_==CServicesManager::CLIENT) findFieldsWithReadAccess();
       // and solve the all reference for them
-      if (hasClient && !hasServer) solveAllRefOfFieldsWithReadAccess();
+      if (serviceType_==CServicesManager::CLIENT) solveAllRefOfFieldsWithReadAccess();
 
       isPostProcessed = true;
@@ -1920,5 +1954,5 @@
    TRY
    {
-     if (!hasClient) return;
+     if (!(serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER)) return;
 
      const vector<CAxis*> allAxis = CAxis::getAll();
@@ -1940,5 +1974,5 @@
    TRY
    {
-     if (!hasClient) return;
+     if (!(serviceType_==CServicesManager::CLIENT || serviceType_==CServicesManager::GATHERER)) return;
 
      const std::vector<CFile*> allFiles = CFile::getAll();
@@ -2146,5 +2180,5 @@
       if (prevStep < step)
       {
-        if (hasClient && !hasServer) // For now we only use server level 1 to read data
+        if (serviceType_==CServicesManager::CLIENT) // For now we only use server level 1 to read data
         {
           doPreTimestepOperationsForEnabledReadModeFiles();
@@ -2158,5 +2192,5 @@
   #endif
 
-        if (hasClient && !hasServer) // For now we only use server level 1 to read data
+        if (serviceType_==CServicesManager::CLIENT) // For now we only use server level 1 to read data
         {
           doPostTimestepOperationsForEnabledReadModeFiles();
@@ -2268,20 +2302,26 @@
     registryOut->hierarchicalGatherRegistry() ;
 
-    // Use correct context client to send message
-    int nbSrvPools = (this->hasServer) ? (this->hasClient ? this->clientPrimServer.size() : 0) : 1;
+    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)
     {
-      CContextClient* contextClientTmp = (hasServer) ? clientPrimServer[i] : client;
+      if (serviceType_==CServicesManager::CLIENT) contextClientTmp = client ;
+      else if (serviceType_==CServicesManager::GATHERER ) contextClientTmp = clientPrimServer[i] ;
+
       CEventClient event(CContext::GetType(), CContext::EVENT_ID_SEND_REGISTRY);
-        if (contextClientTmp->isServerLeader())
-        {
-           CMessage msg ;
-           if (contextClientTmp->clientRank==0) msg<<*registryOut ;
-           const std::list<int>& ranks = contextClientTmp->getRanksServerLeader();
-           for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
+      if (contextClientTmp->isServerLeader())
+      {
+        CMessage msg ;
+        if (contextClientTmp->clientRank==0) msg<<*registryOut ;
+        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);
+        contextClientTmp->sendEvent(event);
+      }
+      else contextClientTmp->sendEvent(event);
     }
   }
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/domain.cpp	(revision 1853)
@@ -1727,9 +1727,9 @@
 
      if (this->isClientAfterTransformationChecked) return;
-     if (context->hasClient)
+     if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
      {
       this->computeConnectedClients();
        if (hasLonLat)
-         if (!context->hasServer)
+         if (context->getServiceType()==CServicesManager::CLIENT)
            this->completeLonLatClient();
      }
@@ -1748,5 +1748,5 @@
      CContext* context=CContext::getCurrent();
 
-      if (context->hasClient && !context->hasServer)
+      if (context->getServiceType()==CServicesManager::CLIENT)
       {
         this->checkDomain();
@@ -1756,5 +1756,5 @@
       }
 
-      if (context->hasClient && !context->hasServer)
+      if (context->getServiceType()==CServicesManager::CLIENT)
       { // Ct client uniquement
          this->checkMask();
@@ -1780,5 +1780,5 @@
 
      if (this->isChecked) return;
-     if (context->hasClient)
+     if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
      {
        sendAttributes();
@@ -1799,5 +1799,5 @@
       this->checkArea();
 
-      if (context->hasClient)
+      if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
       { // Ct client uniquement
          this->checkMask();
@@ -1811,5 +1811,5 @@
       }
 
-      if (context->hasClient)
+      if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
       {
         this->computeConnectedClients();
@@ -1972,5 +1972,4 @@
 
       CContext* context=CContext::getCurrent();      
-      CContextServer* server = context->server;  
 
       std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2);
@@ -1979,5 +1978,5 @@
       nBeginGlobal[0] = 0; nBeginGlobal[1] = 0;
       nGlob[0]        = ni_glo;   nGlob[1] = nj_glo;
-      CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); 
+      CDistributionServer srvDist(context->intraCommSize_, nBegin, nSize, nBeginGlobal, nGlob); 
       const CArray<size_t,1>& writtenGlobalIndex  = srvDist.getGlobalIndex();
 
@@ -2018,5 +2017,4 @@
       size_t nbWritten = 0, indGlo;
       CContext* context=CContext::getCurrent();      
-      CContextServer* server = context->server;  
 
       std::vector<int> nBegin(2), nSize(2), nBeginGlobal(2), nGlob(2);
@@ -2025,5 +2023,5 @@
       nBeginGlobal[0] = 0; nBeginGlobal[1] = 0;
       nGlob[0]        = ni_glo;   nGlob[1] = nj_glo;
-      CDistributionServer srvDist(server->intraCommSize, nBegin, nSize, nBeginGlobal, nGlob); 
+      CDistributionServer srvDist(context->intraCommSize_, nBegin, nSize, nBeginGlobal, nGlob); 
       const CArray<size_t,1>& writtenGlobalIndex  = srvDist.getGlobalIndex();
 
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.cpp	(revision 1853)
@@ -143,11 +143,8 @@
   CATCH
 
-  void CField::sendUpdateData(const CArray<double,1>& data)
+  void CField::sendUpdateData(const CArray<double,1>& data, CContextClient* client)
   TRY
   {
     CTimer::get("Field : send data").resume();
-
-    CContext* context = CContext::getCurrent();
-    CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient();
     int receiverSize = client->serverSize;
 
@@ -319,12 +316,8 @@
     \param [in] tsDataRequested timestamp when the call is made
   */
-  bool CField::sendReadDataRequest(const CDate& tsDataRequested)
+  bool CField::sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client)
   TRY
   {
     CContext* context = CContext::getCurrent();
-    // CContextClient* client = context->client;
-
-    // This code is for future: If we want to read file with level-2 servers
-    CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient();
 
     lastDataRequestedFromServer = tsDataRequested;
@@ -372,5 +365,5 @@
       info(20) << "lastDataRequestedFromServer + file->output_freq.getValue() : " << lastDataRequestedFromServer + file->output_freq << endl ;
 
-      dataRequested |= sendReadDataRequest(lastDataRequestedFromServer + file->output_freq);
+      dataRequested |= sendReadDataRequest(lastDataRequestedFromServer + file->output_freq, file->getContextClient());
     }
 
@@ -385,5 +378,5 @@
     StdString fieldId;
     *buffer >> fieldId;
-    get(fieldId)->recvReadDataRequest();
+    get(fieldId)->recvReadDataRequest(event.getContextServer());
   }
   CATCH
@@ -395,10 +388,8 @@
     In the future, this should (only) be done by the last level servers.
   */
-  void CField::recvReadDataRequest(void)
+  void CField::recvReadDataRequest(CContextServer* server)
   TRY
   {
-    CContext* context = CContext::getCurrent();
-    CContextClient* client = context->client;
-
+    CContextClient* client = server->getAssociatedClient() ;
     CEventClient event(getType(), EVENT_ID_READ_DATA_READY);
     std::list<CMessage> msgs;
@@ -532,5 +523,5 @@
     if (!nstepMaxRead)
     {
-       MPI_Allreduce(MPI_IN_PLACE, &nstepMax, 1, MPI_INT, MPI_MAX, context->server->intraComm);
+       MPI_Allreduce(MPI_IN_PLACE, &nstepMax, 1, MPI_INT, MPI_MAX, context->intraComm_);
        nstepMaxRead = true;
     }
@@ -809,5 +800,5 @@
    {
      CContext* context = CContext::getCurrent();
-     if (context->hasClient && !context->hasServer)
+     if (context->getServiceType()==CServicesManager::CLIENT)
      {
        if (grid && !grid->isTransformed() && hasDirectFieldReference() && grid != getDirectFieldReference()->grid)
@@ -826,5 +817,5 @@
    {
      CContext* context = CContext::getCurrent();
-     if (context->hasClient && !context->hasServer)
+     if (context->getServiceType()==CServicesManager::CLIENT)
      {
        std::map<CGrid*,std::pair<bool,StdString> >& gridSrcMap = grid->getTransGridSource();
@@ -913,6 +904,4 @@
    {
      CContext* context = CContext::getCurrent();
-     bool hasClient = context->hasClient;
-     bool hasServer = context->hasServer;
 
      if (!isReferenceSolvedAndTransformed)
@@ -920,5 +909,5 @@
         isReferenceSolvedAndTransformed = true;
 
-        if (hasClient && !hasServer)
+        if (context->getServiceType()==CServicesManager::CLIENT)
         {
           solveRefInheritance(true);
@@ -926,10 +915,10 @@
         }
 
-        if (hasServer)
+        if (context->getServiceType()==CServicesManager::GATHERER || context->getServiceType()==CServicesManager::OUT_SERVER)
           solveServerOperation();
 
         solveGridReference();
 
-        if (hasClient && !hasServer)
+       if (context->getServiceType()==CServicesManager::CLIENT)
        {
          solveGenerateGrid();
@@ -939,5 +928,5 @@
        solveGridDomainAxisRef(false);
 
-       if (hasClient && !hasServer)
+       if (context->getServiceType()==CServicesManager::CLIENT)
        {
          solveTransformedGrid();
@@ -984,5 +973,5 @@
         isReferenceSolved = true;
 
-        if (context->hasClient && !context->hasServer)
+        if (context->getServiceType()==CServicesManager::CLIENT)
         {
           solveRefInheritance(true);
@@ -990,5 +979,5 @@
         }
 
-        if (context->hasServer)
+        if (context->getServiceType()==CServicesManager::GATHERER || context->getServiceType()==CServicesManager::OUT_SERVER)
           solveServerOperation();
 
@@ -996,5 +985,5 @@
         grid->solveDomainAxisRefInheritance(true); // make it again to solve grid reading from file
 
-        if (context->hasClient && !context->hasServer)
+       if (context->getServiceType()==CServicesManager::CLIENT)
        {
          solveGenerateGrid();
@@ -1015,10 +1004,10 @@
         areAllReferenceSolved = true;
        
-        if (context->hasClient && !context->hasServer)
+        if (context->getServiceType()==CServicesManager::CLIENT)
         {
           solveRefInheritance(true);
           if (hasDirectFieldReference()) getDirectFieldReference()->solveAllReferenceEnabledField(false);
         }
-        else if (context->hasServer)
+        else if (context->getServiceType()==CServicesManager::GATHERER || context->getServiceType()==CServicesManager::OUT_SERVER)
           solveServerOperation();
 
@@ -1028,5 +1017,5 @@
      solveGridDomainAxisRef(doSending2Server);
 
-     if (context->hasClient && !context->hasServer)
+     if (context->getServiceType()==CServicesManager::CLIENT)
      {
        solveTransformedGrid();
@@ -1065,5 +1054,5 @@
       CContext* context = CContext::getCurrent();
 
-      if (!context->hasServer || !hasOutputFile) return;
+      if (context->getServiceType()==CServicesManager::CLIENT || !hasOutputFile) return;
 
       if (freq_op.isEmpty())
@@ -1126,6 +1115,6 @@
 
      CContext* context = CContext::getCurrent();
-     bool hasWriterServer = context->hasServer && !context->hasClient;
-     bool hasIntermediateServer = context->hasServer && context->hasClient;
+     bool hasWriterServer = context->getServiceType()==CServicesManager::OUT_SERVER ;
+     bool hasIntermediateServer = context->getServiceType()==CServicesManager::GATHERER ;
 
      if (hasWriterServer)
@@ -1155,5 +1144,5 @@
          if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write))
          {
-           fileWriterFilter = std::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this));
+           fileWriterFilter = std::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this, file->getContextClient()));
            instantDataFilter->connectOutput(fileWriterFilter, 0);
          }
@@ -1217,5 +1206,5 @@
          if (file && (file->mode.isEmpty() || file->mode == CFile::mode_attr::write))
          {
-           fileWriterFilter = std::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this));
+           fileWriterFilter = std::shared_ptr<CFileWriterFilter>(new CFileWriterFilter(gc, this, file->getContextClient()));
            getTemporalDataFilter(gc, file->output_freq)->connectOutput(fileWriterFilter, 0);
          }
@@ -1736,15 +1725,13 @@
      CContext* context = CContext::getCurrent();
      client = contextClient;
-     if (context->hasClient)
-     {
-       // A grid is sent by a client (both for read or write) or by primary server (write only)
-       if (context->hasServer)
-       {
-         if (file->mode.isEmpty() || (!file->mode.isEmpty() && file->mode == CFile::mode_attr::write))
-           grid->setContextClient(contextClient);
-       }
-       else
-           grid->setContextClient(contextClient);
-     }
+  
+     // A grid is sent by a client (both for read or write) or by primary server (write only)
+     if (context->getServiceType()==CServicesManager::GATHERER)
+     {
+       if (file->mode.isEmpty() || (!file->mode.isEmpty() && file->mode == CFile::mode_attr::write))
+         grid->setContextClient(contextClient);
+     }
+     else if (context->getServiceType()==CServicesManager::CLIENT)
+       grid->setContextClient(contextClient);
    }
    CATCH_DUMP_ATTR
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/field.hpp	(revision 1853)
@@ -46,4 +46,5 @@
    END_DECLARE_ATTRIBUTE_MAP(CField)
 
+   class CContextClient ;
    ///--------------------------------------------------------------
    class CField
@@ -167,8 +168,8 @@
         void recvUpdateData(std::map<int,CBufferIn*>& rankBuffers);
         void writeField(void);
-        bool sendReadDataRequest(const CDate& tsDataRequested);
+        bool sendReadDataRequest(const CDate& tsDataRequested, CContextClient* client);
         bool sendReadDataRequestIfNeeded(void);
         static void recvReadDataRequest(CEventServer& event);
-        void recvReadDataRequest(void);
+        void recvReadDataRequest(CContextServer* server);
         EReadField readField(void);
         static void recvReadDataReady(CEventServer& event);
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/file.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/file.cpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/file.cpp	(revision 1853)
@@ -226,5 +226,4 @@
       CContext* context = CContext::getCurrent();
       const CDate& currentDate = context->calendar->getCurrentDate();
-      CContextServer* server = context->server;
 
       lastSync  = currentDate;
@@ -294,5 +293,4 @@
     {
       CContext* context = CContext::getCurrent();
-      CContextServer* server = context->server;
 
       // create sub communicator for file
@@ -307,5 +305,5 @@
 
       int color = allZoneEmpty ? 0 : 1;
-      MPI_Comm_split(server->intraComm, color, server->intraCommRank, &fileComm);
+      MPI_Comm_split(context->intraComm_, color, context->intraCommRank_, &fileComm);
       if (allZoneEmpty) MPI_Comm_free(&fileComm);
     }
@@ -443,6 +441,5 @@
    {
       CContext* context = CContext::getCurrent();
-      CContextServer* server = context->server;
-
+      
       if (!allZoneEmpty)
       {
@@ -560,5 +557,5 @@
             MPI_Comm_rank(fileComm, &commRank);
 
-            if (server->intraCommSize > 1)
+            if (context->intraCommSize_ > 1)
             {
               oss << "_" ;
@@ -636,5 +633,4 @@
   {
     CContext* context = CContext::getCurrent();
-    CContextServer* server = context->server;
     MPI_Comm readComm = this->fileComm;
 
@@ -683,5 +679,5 @@
         MPI_Comm_rank(readComm, &commRank);
 
-        if (server->intraCommSize > 1)
+        if (context->intraCommSize_ > 1)
         {
           oss << "_";
@@ -699,5 +695,5 @@
       bool isCollective = par_access.isEmpty() || par_access == par_access_attr::collective;
       bool readMetaDataPar = true;
-      if (!context->hasServer) readMetaDataPar = (read_metadata_par.isEmpty()) ? false : read_metadata_par;
+      if (context->getServiceType()==CServicesManager::CLIENT) readMetaDataPar = (read_metadata_par.isEmpty()) ? false : read_metadata_par;
 
       if (isOpen) data_out->closeFile();
@@ -1005,5 +1001,5 @@
      int size = this->enabledFields.size();
      for (int i = 0; i < size; ++i)
-       this->enabledFields[i]->sendReadDataRequest(CContext::getCurrent()->getCalendar()->getCurrentDate());
+       this->enabledFields[i]->sendReadDataRequest(CContext::getCurrent()->getCalendar()->getCurrentDate(), getContextClient());
    }
    CATCH_DUMP_ATTR
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.cpp	(revision 1853)
@@ -331,9 +331,12 @@
    {
      CContext* context = CContext::getCurrent();
-     if (context->hasClient && this->isChecked && doSendingIndex && !isIndexSent) 
-     { 
-       if (isScalarGrid())  sendIndexScalarGrid();
-       else  sendIndex();
-       this->isIndexSent = true; 
+     if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)     
+     {
+       if (this->isChecked && doSendingIndex && !isIndexSent) 
+       { 
+         if (isScalarGrid())  sendIndexScalarGrid();
+         else  sendIndex();
+         this->isIndexSent = true; 
+       }
      }
 
@@ -726,5 +729,5 @@
           }
 
-          if (doGridHaveDataDistributed(client) && (nbIndex != localIndex.numElements()))
+          if (nbIndex != localIndex.numElements())
                ERROR("void CGrid::computeClientIndex()",
                   << "Number of local index on client is different from number of received global index"
@@ -892,5 +895,5 @@
      {
        computeClientIndexScalarGrid();
-       if (context->hasClient)
+       if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
        {
          computeConnectedClientsScalarGrid();
@@ -900,5 +903,5 @@
      {
        computeClientIndex();
-       if (context->hasClient)
+       if (context->getServiceType()==CServicesManager::CLIENT || context->getServiceType()==CServicesManager::GATHERER)
        {
          computeConnectedClients();
@@ -1474,5 +1477,5 @@
           }
 
-          if (context->hasClient && !context->hasServer)
+          if (context->getServiceType()==CServicesManager::CLIENT)  
             storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer)));
 
@@ -1497,5 +1500,5 @@
           }
 
-          if (context->hasClient && !context->hasServer)
+          if (context->getServiceType()==CServicesManager::CLIENT)
             storeIndex_fromSrv_.insert(std::make_pair(rank, CArray<int,1>(outLocalIndexToServer)));
         }
@@ -1544,5 +1547,5 @@
           {
             storeIndex_toSrv_[client].insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer)));
-            if (context->hasClient && !context->hasServer)
+            if (context->getServiceType()==CServicesManager::CLIENT)
               storeIndex_fromSrv_.insert(std::make_pair(*itRank, CArray<int,1>(outLocalIndexToServer)));
             
@@ -1644,9 +1647,9 @@
       buffers.push_back(buffer);
     }
-    get(gridId)->recvIndex(ranks, buffers);
+    get(gridId)->recvIndex(ranks, buffers, event.getContextServer());
   }
   CATCH
 
-  void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers)
+  void CGrid::recvIndex(vector<int> ranks, vector<CBufferIn*> buffers, CContextServer* server)
   TRY
   {
@@ -1655,6 +1658,5 @@
 
     nbReadSenders_.clear();
-    CContextServer* server = context->server  ;
-    CContextClient* client = context->client;   
+    CContextClient* client = server->getAssociatedClient();   
       
     int idx = 0, numElement = axis_domain_order.numElements();
@@ -1811,5 +1813,6 @@
     if (isScalarGrid()) return;
 
-    nbReadSenders_[client] = CClientServerMappingDistributed::computeConnectedClients(context->client->serverSize, context->client->clientSize, context->client->intraComm, ranks);
+    nbReadSenders_[client] = CClientServerMappingDistributed::computeConnectedClients(client->serverSize, client->clientSize,
+                                                                                      client->intraComm, ranks);
 
   }
@@ -2222,5 +2225,5 @@
     {
       CDomain* pDom = CDomain::get(*it);
-      if (context->hasClient && !context->hasServer)      
+      if (context->getServiceType()==CServicesManager::CLIENT)
       {
         pDom->solveRefInheritance(apply);
@@ -2234,5 +2237,5 @@
     {
       CAxis* pAxis = CAxis::get(*it);
-      if (context->hasClient && !context->hasServer)
+      if (context->getServiceType()==CServicesManager::CLIENT)
       {
         pAxis->solveRefInheritance(apply);
@@ -2246,5 +2249,5 @@
     {
       CScalar* pScalar = CScalar::get(*it);
-      if (context->hasClient && !context->hasServer)
+      if (context->getServiceType()==CServicesManager::CLIENT)
       {
         pScalar->solveRefInheritance(apply);
Index: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp
===================================================================
--- XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp	(revision 1848)
+++ XIOS/dev/dev_ym/XIOS_COUPLING/src/node/grid.hpp	(revision 1853)
@@ -160,5 +160,5 @@
          static bool dispatchEvent(CEventServer& event);
          static void recvIndex(CEventServer& event);
-         void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers);
+         void recvIndex(vector<int> ranks, vector<CBufferIn*> buffers, CContextServer* server);
          void sendIndex(void);
          void sendIndexScalarGrid();
