Index: XIOS/dev/dev_olga/inputs/Second_server/context_atmosphere.xml
===================================================================
--- XIOS/dev/dev_olga/inputs/Second_server/context_atmosphere.xml	(revision 1071)
+++ XIOS/dev/dev_olga/inputs/Second_server/context_atmosphere.xml	(revision 1071)
@@ -0,0 +1,32 @@
+<!-- Context atm -->
+
+<context id="atmosphere">
+
+  <field_definition freq_op="1ts" enabled=".TRUE." operation="instant" domain_ref="atm_face" >
+   <field id="atm_temp1" name="atm_temp1" long_name="Surface Temperature" unit="K" />
+   <field id="atm_temp2" name="atm_temp2" long_name="Surface Temperature" unit="K" /> 
+  </field_definition>
+
+  <file_definition type="one_file" output_freq="3600s" par_access="collective" enabled=".TRUE.">
+   <file id="atm_output9" name="atm_output9" compression_level="9" >
+    <!--  <field field_ref="atm_temp1" />-->
+      <field field_ref="atm_temp2"/>
+    </file> 
+<!--    <file id="atm_output2" name="atm_output2" timeseries="both" ts_prefix="TS" >
+      <field field_ref="atm_temp2" ts_enabled=".TRUE." ts_split_freq="2h"/>
+    </file> -->
+<!--    <file id="atm_output0" name="atm_output0" >
+      <field field_ref="atm_temp1" />
+      <field field_ref="atm_temp2"/>
+    </file> 
+   <file id="atm_output2" name="atm_output2" compression_level="2" >
+      <field field_ref="atm_temp1" />
+      <field field_ref="atm_temp2"/>
+    </file> 
+-->
+ </file_definition>
+
+  <domain_definition>
+   <domain id="atm_face" name="mesh" nvertex="4"/>  
+</domain_definition>
+ </context>
Index: XIOS/dev/dev_olga/inputs/Second_server/context_surface.xml
===================================================================
--- XIOS/dev/dev_olga/inputs/Second_server/context_surface.xml	(revision 1071)
+++ XIOS/dev/dev_olga/inputs/Second_server/context_surface.xml	(revision 1071)
@@ -0,0 +1,18 @@
+<!-- Context surface -->
+
+<context id="atmosphere">
+
+  <field_definition freq_op="1ts" enabled=".TRUE." operation="instant" >
+   <field id="srf_temp" name="srf_temp" long_name="Surface Temperature" unit="K" domain_ref="domain_srf" />
+  </field_definition>
+
+  <file_definition type="one_file" output_freq="1h" par_access="collective" enabled=".TRUE.">
+    <file id="srf_output" name="srf_output" >
+      <field field_ref="srf_temp" />
+    </file> 
+  </file_definition>
+
+  <domain_definition>
+   <domain id="domain_srf" name="mesh" nvertex="4"/>  
+  </domain_definition>
+ </context>
Index: XIOS/dev/dev_olga/inputs/Second_server/iodef.xml
===================================================================
--- XIOS/dev/dev_olga/inputs/Second_server/iodef.xml	(revision 1071)
+++ XIOS/dev/dev_olga/inputs/Second_server/iodef.xml	(revision 1071)
@@ -0,0 +1,27 @@
+<?xml version="1.0"?>
+<simulation>
+
+  <context id="atmosphere" src="./context_atmosphere.xml"/> 
+  <context id="surface" src="./context_surface.xml"/>  
+
+  <context id="xios">
+      <variable_definition>
+
+         <variable_group id="server">
+            <variable id="using_server2" type="bool">true</variable>
+            <variable id="ratio_server2" type="int">50</variable>
+         </variable_group>
+
+        <variable_group id="buffer">
+            <variable id="optimal_buffer_size" type="string">performance</variable>
+            <variable id="buffer_size_factor" type="double">1.0</variable>
+         </variable_group>
+
+        <variable_group id="parameters" >
+          <variable id="info_level" type="int">100</variable>
+          <variable id="print_file" type="bool">true</variable>
+        </variable_group>
+      </variable_definition>
+  </context>
+
+</simulation>
Index: XIOS/dev/dev_olga/src/buffer_client.cpp
===================================================================
--- XIOS/dev/dev_olga/src/buffer_client.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/buffer_client.cpp	(revision 1071)
@@ -74,4 +74,7 @@
     int flag;
 
+    int error, errclass, len;
+    char errstring[MPI_MAX_ERROR_STRING];
+
     if (pending)
     {
@@ -86,6 +89,12 @@
       if (count > 0)
       {
-        MPI_Comm_test_inter(interComm, &flag);
-        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
+        MPI_Errhandler_set(interComm,MPI_ERRORS_RETURN);
+        error = MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
+        if (error != MPI_SUCCESS)
+        {
+          MPI_Error_class(error, &errclass);
+          MPI_Error_string(error, errstring, &len);
+          ERROR("MPI error class: ", <<errclass<<" MPI error "<<errstring );
+        }
         pending = true;
         if (current == 1) current = 0;
Index: XIOS/dev/dev_olga/src/context_client.cpp
===================================================================
--- XIOS/dev/dev_olga/src/context_client.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/context_client.cpp	(revision 1071)
@@ -91,6 +91,6 @@
         // We force the getBuffers call to be non-blocking on the servers
         list<CBufferOut*> buffList;
-        bool couldBuffer = getBuffers(ranks, sizes, buffList, !CXios::isClient);
 //        bool couldBuffer = getBuffers(ranks, sizes, buffList, CXios::isServer);
+        bool couldBuffer = getBuffers(ranks, sizes, buffList, false);
 
         if (couldBuffer)
@@ -182,5 +182,6 @@
      * \return whether the already allocated buffers could be used
     */
-    bool CContextClient::getBuffers(const list<int>& serverList, const list<int>& sizeList, list<CBufferOut*>& retBuffers, bool nonBlocking /*= false*/)
+    bool CContextClient::getBuffers(const list<int>& serverList, const list<int>& sizeList, list<CBufferOut*>& retBuffers,
+                                    bool nonBlocking /*= false*/)
     {
       list<int>::const_iterator itServer, itSize;
@@ -211,11 +212,9 @@
         {
           checkBuffers();
-//          if (?)
-//          {
+
+         // WHY DO WE PUT HERE SERVER INTO LISTENING LOOP AT ALL????
+//            context->server->listen();
 //            for (int i = 0; i < context->serverPrimServer.size(); ++i)
 //              context->serverPrimServer[i]->listen();
-//          }
-//          else
-            context->server->listen();
         }
       } while (!areBuffersFree && !nonBlocking);
@@ -237,14 +236,14 @@
    void CContextClient::newBuffer(int rank)
    {
-      if (!mapBufferSize_.count(rank))
-      {
-        error(0) << "WARNING: Unexpected request for buffer to communicate with server " << rank << std::endl;
-        mapBufferSize_[rank] = CXios::minBufferSize;
-      }
-      CClientBuffer* buffer = buffers[rank] = new CClientBuffer(interComm, rank, mapBufferSize_[rank], maxBufferedEvents);
-      // Notify the server
-      CBufferOut* bufOut = buffer->getBuffer(sizeof(StdSize));
-      bufOut->put(mapBufferSize_[rank]); // Stupid C++
-      buffer->checkBuffer();
+     if (!mapBufferSize_.count(rank))
+     {
+       error(0) << "WARNING: Unexpected request for buffer to communicate with server " << rank << std::endl;
+       mapBufferSize_[rank] = CXios::minBufferSize;
+     }
+     CClientBuffer* buffer = buffers[rank] = new CClientBuffer(interComm, rank, mapBufferSize_[rank], maxBufferedEvents);
+     // Notify the server
+     CBufferOut* bufOut = buffer->getBuffer(sizeof(StdSize));
+     bufOut->put(mapBufferSize_[rank]); // Stupid C++
+     buffer->checkBuffer();
    }
 
@@ -262,8 +261,9 @@
 
    //! Release all buffers
-   void CContextClient::releaseBuffers(void)
+   void CContextClient::releaseBuffers()
    {
       map<int,CClientBuffer*>::iterator itBuff;
       for (itBuff = buffers.begin(); itBuff != buffers.end(); itBuff++) delete itBuff->second;
+//        buffersReleased_ = true;
    }
 
@@ -273,4 +273,5 @@
    \return state of buffers, pending(true), ready(false)
    */
+//   bool CContextClient::checkBuffers(list<int>& ranks)
    bool CContextClient::checkBuffers(list<int>& ranks)
    {
@@ -358,5 +359,6 @@
    Finalize context client and do some reports
    */
-  void CContextClient::finalize(void)
+//  void CContextClient::finalize(void)
+  void CContextClient::finalize()
   {
     map<int,CClientBuffer*>::iterator itBuff;
@@ -396,4 +398,5 @@
     std::map<int,StdSize>::const_iterator itbMap = mapBufferSize_.begin(),
                                           iteMap = mapBufferSize_.end(), itMap;
+
     StdSize totalBuf = 0;
     for (itMap = itbMap; itMap != iteMap; ++itMap)
Index: XIOS/dev/dev_olga/src/context_client.hpp
===================================================================
--- XIOS/dev/dev_olga/src/context_client.hpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/context_client.hpp	(revision 1071)
@@ -70,5 +70,6 @@
       MPI_Comm intraComm; //!< Communicator of client group
 
-      map<int,CClientBuffer*> buffers;     //!< Buffers for connection to servers
+      map<int,CClientBuffer*> buffers;         //!< Buffers for connection to servers
+//      map<int,CClientBuffer*> buffersPrim;     //!< Buffers for connection to secondary servers
 
     private:
@@ -77,4 +78,6 @@
       //! Maximum number of events that can be buffered
       StdSize maxBufferedEvents;
+
+//      bool buffersReleased_;
 
       struct {
Index: XIOS/dev/dev_olga/src/context_server.cpp
===================================================================
--- XIOS/dev/dev_olga/src/context_server.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/context_server.cpp	(revision 1071)
@@ -225,5 +225,5 @@
     {
       finished=true;
-      info(20)<<"Server Side context <"<<context->getId()<<"> finalized"<<endl;
+//      info(20)<<"Server Side context <"<<context->getId()<<"> finalized"<<endl;            // moved to CContext::finalize()
       std::map<int, StdSize>::const_iterator itbMap = mapBufferSize_.begin(),
                            iteMap = mapBufferSize_.end(), itMap;
@@ -231,11 +231,11 @@
       {
         rank = itMap->first;
-        report(10)<< " Memory report : Context <"<<ctxId<<"> : server side : memory used for buffer of each connection to client" << endl
-            << "  +) With client of rank " << rank << " : " << itMap->second << " bytes " << endl;
+//        report(10)<< " Memory report : Context <"<<ctxId<<"> : server side : memory used for buffer of each connection to client" << endl
+//            << "  +) With client of rank " << rank << " : " << itMap->second << " bytes " << endl;
         totalBuf_ += itMap->second;
       }
       context->finalize();
 
-//      report(0)<< " Memory report : Context <"<<ctxId<<"> : server side : total memory used for buffer "<<totalBuf<<" bytes"<<endl;
+//      report(0)<< " Memory report : Context <"<<ctxId<<"> : server side : total memory used for buffer "<<totalBuf<<" bytes"<<endl; // moved to CContext::finalize()
     }
     else if (event.classId==CContext::GetType()) CContext::dispatchEvent(event);
Index: XIOS/dev/dev_olga/src/node/context.cpp
===================================================================
--- XIOS/dev/dev_olga/src/node/context.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/context.cpp	(revision 1071)
@@ -28,5 +28,4 @@
       , isPostProcessed(false), finalized(false)
       , idServer_(), client(0), server(0)
-//	  , clientPrimServer(0), serverPrimServer(0)
       , allProcessed(false)
    { /* Ne rien faire de plus */ }
@@ -37,5 +36,4 @@
       , isPostProcessed(false), finalized(false)
       , idServer_(), client(0), server(0)
-//	  , clientPrimServer(0), serverPrimServer(0)
       , allProcessed(false)
    { /* Ne rien faire de plus */ }
@@ -45,6 +43,6 @@
      delete client;
      delete server;
-//     delete clientPrimServer;
-//     delete serverPrimServer;
+     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;
    }
 
@@ -249,11 +247,10 @@
 
      hasClient = true;
+     MPI_Comm intraCommServer, interCommServer;
 
      if (CServer::serverLevel != 1)
-     // initClient is called by client
+      // initClient is called by client
      {
        client = new CContextClient(this, intraComm, interComm, cxtServer);
-       server = new CContextServer(this, intraComm, interComm);
-       MPI_Comm intraCommServer, interCommServer;
        if (cxtServer) // Attached mode
        {
@@ -263,29 +260,28 @@
        else
        {
-//         MPI_Comm_dup(intraComm, &intraCommServer);
-//         comms.push_back(intraCommServer);
-//         MPI_Comm_dup(interComm, &interCommServer);
-//         comms.push_back(interCommServer);
-       }
-     }
-
+         MPI_Comm_dup(intraComm, &intraCommServer);
+         comms.push_back(intraCommServer);
+         MPI_Comm_dup(interComm, &interCommServer);
+         comms.push_back(interCommServer);
+       }
+       registryIn=new CRegistry(intraComm);
+       registryIn->setPath(getId()) ;
+       if (client->clientRank==0) registryIn->fromFile("xios_registry.bin") ;
+       registryIn->bcastRegistry() ;
+       registryOut=new CRegistry(intraComm) ;
+       registryOut->setPath(getId()) ;
+
+       server = new CContextServer(this, intraCommServer, interCommServer);
+     }
      else
      // initClient is called by primary server
      {
        clientPrimServer.push_back(new CContextClient(this, intraComm, interComm));
-       serverPrimServer.push_back(new CContextServer(this, intraComm, interComm));
-     }
-
-
-
-//     registryIn=new CRegistry(intraComm);
-//     registryIn->setPath(getId()) ;
-//     if (client->clientRank==0) registryIn->fromFile("xios_registry.bin") ;
-//     registryIn->bcastRegistry() ;
-//
-//     registryOut=new CRegistry(intraComm) ;
-//     registryOut->setPath(getId()) ;
-
-
+       MPI_Comm_dup(intraComm, &intraCommServer);
+       comms.push_back(intraCommServer);
+       MPI_Comm_dup(interComm, &interCommServer);
+       comms.push_back(interCommServer);
+       serverPrimServer.push_back(new CContextServer(this, intraCommServer, interCommServer));
+     }
    }
 
@@ -354,13 +350,12 @@
      hasServer=true;
      server = new CContextServer(this,intraComm,interComm);
-     client = new CContextClient(this,intraComm,interComm);
 //     client = new CContextClient(this,intraComm,interComm, cxtClient);
 
-//     registryIn=new CRegistry(intraComm);
-//     registryIn->setPath(getId()) ;
-//     if (server->intraCommRank==0) registryIn->fromFile("xios_registry.bin") ;
-//     registryIn->bcastRegistry() ;
-//     registryOut=new CRegistry(intraComm) ;
-//     registryOut->setPath(getId()) ;
+     registryIn=new CRegistry(intraComm);
+     registryIn->setPath(getId()) ;
+     if (server->intraCommRank==0) registryIn->fromFile("xios_registry.bin") ;
+     registryIn->bcastRegistry() ;
+     registryOut=new CRegistry(intraComm) ;
+     registryOut->setPath(getId()) ;
 
      MPI_Comm intraCommClient, interCommClient;
@@ -372,34 +367,12 @@
      else
      {
-//       MPI_Comm_dup(intraComm, &intraCommClient);
-//       comms.push_back(intraCommClient);
-//       MPI_Comm_dup(interComm, &interCommClient);
-//       comms.push_back(interCommClient);
-     }
-
-   }
-
-   //! Server side: Put server into a loop in order to listen message from client
-//   bool CContext::eventLoop(void)
-//   {
-//     if (CServer::serverLevel == 0)
-//     {
-//       return server->eventLoop();
-//     }
-//     else if (CServer::serverLevel == 1)
-//     {
-//       bool serverFinished = server->eventLoop();
-//       bool serverPrimFinished = true;
-//       for (int i = 0; i < serverPrimServer.size(); ++i)
-//       {
-//         serverPrimFinished *= serverPrimServer[i]->eventLoop();
-//       }
-//       return ( serverFinished && serverPrimFinished);
-//     }
-//     else
-//     {
-//       return server->eventLoop();
-//     }
-//   }
+       MPI_Comm_dup(intraComm, &intraCommClient);
+       comms.push_back(intraCommClient);
+       MPI_Comm_dup(interComm, &interCommClient);
+       comms.push_back(interCommClient);
+     }
+     client = new CContextClient(this,intraCommClient,interCommClient);
+
+   }
 
    //! Try to send the buffers and receive possible answers
@@ -412,5 +385,4 @@
        if (hasTmpBufferedEvent)
          hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent();
-
        // Don't process events if there is a temporarily buffered event
        return server->eventLoop(!hasTmpBufferedEvent);
@@ -432,5 +404,6 @@
          if (hasTmpBufferedEventPrim)
            hasTmpBufferedEventPrim = !clientPrimServer[i]->sendTemporarilyBufferedEvent();
-         serverPrimFinished *= serverPrimServer[i]->eventLoop(hasTmpBufferedEventPrim);
+//         serverPrimFinished *= serverPrimServer[i]->eventLoop(!hasTmpBufferedEventPrim);
+         serverPrimFinished *= serverPrimServer[i]->eventLoop();
        }
        return ( serverFinished && serverPrimFinished);
@@ -441,8 +414,9 @@
        client->checkBuffers();
        bool hasTmpBufferedEvent = client->hasTemporarilyBufferedEvent();
-       if (hasTmpBufferedEvent)
-         hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent();
-       return server->eventLoop(!hasTmpBufferedEvent);
-     }
+//       if (hasTmpBufferedEvent)
+//         hasTmpBufferedEvent = !client->sendTemporarilyBufferedEvent();
+//       return server->eventLoop(!hasTmpBufferedEvent);
+       return server->eventLoop();
+      }
    }
 
@@ -453,11 +427,6 @@
      {
        finalized = true;
-//       if (hasClient) sendRegistry() ;
-
-       client->finalize();
-       while (!server->hasFinished())
-       {
-         server->eventLoop();
-       }
+
+       if (hasClient) sendRegistry() ;
 
        if ((hasClient) && (hasServer))
@@ -475,5 +444,11 @@
          }
        }
-
+       client->finalize();
+       while (!server->hasFinished())
+       {
+         server->eventLoop();
+       }
+
+       info(20)<<"Server Side context <"<<getId()<<"> finalized"<<endl;
        report(0)<< " Memory report : Context <"<<getId()<<"> : server side : total memory used for buffers "<<CContextServer::getTotalBuf()<<" bytes"<<endl;
 
@@ -482,21 +457,21 @@
        {
          closeAllFile();
-//         registryOut->hierarchicalGatherRegistry() ;
-//         if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
-       }
-
-       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 (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
-         MPI_Comm_free(&(*it));
-       comms.clear();
+         registryOut->hierarchicalGatherRegistry() ;
+         if (server->intraCommRank==0) CXios::globalRegistry->mergeRegistry(*registryOut) ;
+       }
+
+//       for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
+//         MPI_Comm_free(&(*it));
+//       comms.clear();
 
       }
    }
-
+   //! Free internally allocated communicators
+   void CContext::freeComms(void)
+   {
+     for (std::list<MPI_Comm>::iterator it = comms.begin(); it != comms.end(); ++it)
+       MPI_Comm_free(&(*it));
+     comms.clear();
+   }
 
    void CContext::postProcessingGlobalAttributes()
@@ -1597,5 +1572,4 @@
 
     // 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)
@@ -1618,33 +1592,4 @@
          else contextClientTmp->sendEvent(event);
     }
-
-    // if (!hasServer)
-    // {
-    //   if (client->isServerLeader())
-    //   {
-    //      CMessage msg ;
-    //      msg<<this->getIdServer();
-    //      if (client->clientRank==0) msg<<*registryOut ;
-    //      const std::list<int>& ranks = client->getRanksServerLeader();
-    //      for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-    //        event.push(*itRank,1,msg);
-    //      client->sendEvent(event);
-    //    }
-    //    else client->sendEvent(event);
-    // }
-    // else
-    // {
-    //   if (clientPrimServer->isServerLeader())
-    //   {
-    //      CMessage msg ;
-    //      msg<<this->getIdServer();
-    //      if (clientPrimServer->clientRank==0) msg<<*registryOut ;
-    //      const std::list<int>& ranks = clientPrimServer->getRanksServerLeader();
-    //      for (std::list<int>::const_iterator itRank = ranks.begin(), itRankEnd = ranks.end(); itRank != itRankEnd; ++itRank)
-    //        event.push(*itRank,1,msg);
-    //      clientPrimServer->sendEvent(event);
-    //    }
-    //    else clientPrimServer->sendEvent(event);
-    // }
   }
 
Index: XIOS/dev/dev_olga/src/node/context.hpp
===================================================================
--- XIOS/dev/dev_olga/src/node/context.hpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/context.hpp	(revision 1071)
@@ -100,4 +100,5 @@
          void finalize(void);
          void closeDefinition(void);
+         bool isFinalized(void);
 
          // Some functions to process context
@@ -165,5 +166,5 @@
          void recvRegistry(CBufferIn& buffer) ; //!< registry is received by the servers
 
-         bool isFinalized(void);
+         void freeComms(void); //!< Free internally allcoated communicators
 
          // dispatch event
@@ -231,16 +232,11 @@
          bool hasServer;
 
-         // Concrete contex client
-         CContextClient* client;
+         CContextServer* server;  //!< Concrete context server
+         CContextClient* client;  //!< Concrete contex client
+         std::vector<CContextServer*> serverPrimServer;
+         std::vector<CContextClient*> clientPrimServer;
+
          CRegistry* registryIn ;  //!< input registry which is read from file
          CRegistry* registryOut ; //!< output registry which will be wrote on file at the finalize
-
-         // Concrete context server
-         CContextServer* server;
-
-//         CContextClient* clientPrimServer;
-//         CContextServer* serverPrimServer;
-         std::vector<CContextClient*> clientPrimServer;
-         std::vector<CContextServer*> serverPrimServer;
 
       private:
@@ -250,5 +246,5 @@
          StdString idServer_;
          CGarbageCollector garbageCollector;
-         std::list<MPI_Comm> comms; //!< Communicators allocated internally  --- significance??
+         std::list<MPI_Comm> comms; //!< Communicators allocated internally
 
       public: // Some function maybe removed in the near future
Index: XIOS/dev/dev_olga/src/node/field.cpp
===================================================================
--- XIOS/dev/dev_olga/src/node/field.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/field.cpp	(revision 1071)
@@ -398,5 +398,7 @@
   {
     CContext* context = CContext::getCurrent();
-    CContextClient* client = context->client;
+//    CContextClient* client = context->client;
+    CContextClient* client = (!context->hasServer) ? context->client : this->file->getContextClient();
+
 
     lastDataRequestedFromServer = tsDataRequested;
Index: XIOS/dev/dev_olga/src/node/file.cpp
===================================================================
--- XIOS/dev/dev_olga/src/node/file.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/file.cpp	(revision 1071)
@@ -857,4 +857,5 @@
    }
 
+
    /*!
    \brief Send a message to create a field on server side
@@ -1081,5 +1082,5 @@
    void CFile::sendAddVariable(const string& id, CContextClient* client)
    {
-      sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE, client);
+      sendAddItem(id, (int)EVENT_ID_ADD_VARIABLE);
     // CContext* context = CContext::getCurrent();
 
Index: XIOS/dev/dev_olga/src/node/file.hpp
===================================================================
--- XIOS/dev/dev_olga/src/node/file.hpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/file.hpp	(revision 1071)
@@ -122,5 +122,5 @@
 
          // Send info to server
-//         void sendEnabledFields();
+         void sendEnabledFields();
          void sendEnabledFields(CContextClient* client);
          void sendAddField(const string& id = "");
Index: XIOS/dev/dev_olga/src/node/variable.cpp
===================================================================
--- XIOS/dev/dev_olga/src/node/variable.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/variable.cpp	(revision 1071)
@@ -128,5 +128,5 @@
    }
 
-   void CVariable::sendValue(CContextClient* client)
+   void CVariable::sendValue(CContextClient* client, bool clientPrim /*= false*/)
    {
      CEventClient event(this->getType(),EVENT_ID_VARIABLE_VALUE) ;
Index: XIOS/dev/dev_olga/src/node/variable.hpp
===================================================================
--- XIOS/dev/dev_olga/src/node/variable.hpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/node/variable.hpp	(revision 1071)
@@ -79,5 +79,5 @@
             //! Sending a request to set up variable data
             void sendValue();
-            void sendValue(CContextClient* client);
+            void sendValue(CContextClient* client, bool clientPrim = false);
 
             static void recvValue(CEventServer& event) ;
Index: XIOS/dev/dev_olga/src/server.cpp
===================================================================
--- XIOS/dev/dev_olga/src/server.cpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/server.cpp	(revision 1071)
@@ -22,9 +22,11 @@
 //    list<MPI_Comm> CServer::interComm ;
     std::list<MPI_Comm> CServer::contextInterComms;
+    std::list<MPI_Comm> CServer::contextIntraComms;
     int CServer::serverLevel = 0 ;
-    int CServer::serverLeader = 0;
-    int CServer::serverSize = 0;
+    int CServer::serverLeader_ = 0;
+    int CServer::serverSize_ = 0;
     int CServer::nbPools = 0;
     int CServer::poolId = 0;
+    int CServer::nbContexts_ = 0;
     bool CServer::isRoot = false ;
     int CServer::rank = INVALID_RANK;
@@ -103,7 +105,7 @@
         {
           int serverRank = rank - leaders[hashServer]; // server proc rank starting 0
-          serverSize = size - leaders[hashServer];
-          nbPools = serverSize * CXios::ratioServer2 / 100;
-          if ( serverRank < (serverSize - nbPools) )
+          serverSize_ = size - leaders[hashServer];
+          nbPools = serverSize_ * CXios::ratioServer2 / 100;
+          if ( serverRank < (serverSize_ - nbPools) )
           {
             serverLevel = 1;
@@ -112,5 +114,5 @@
           {
             serverLevel = 2;
-            poolId = serverRank - serverSize + nbPools;
+            poolId = serverRank - serverSize_ + nbPools;
             myColor = rank;
           }
@@ -156,10 +158,10 @@
             }
             else
-              serverLeader = it->second;
+              serverLeader_ = it->second;
           }
 
           for (int i = 0; i < nbPools; ++i)
           {
-            srvSndLeader = serverLeader + serverSize - nbPools + i;
+            srvSndLeader = serverLeader_ + serverSize_ - nbPools + i;
             int intraCommSize, intraCommRank ;
             MPI_Comm_size(intraComm, &intraCommSize) ;
@@ -239,4 +241,7 @@
 
       for (std::list<MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++)
+        MPI_Comm_free(&(*it));
+
+      for (std::list<MPI_Comm>::iterator it = contextIntraComms.begin(); it != contextIntraComms.end(); it++)
         MPI_Comm_free(&(*it));
 
@@ -310,5 +315,4 @@
               {
                 MPI_Send(&msg,1,MPI_INT,0,0,*itr) ;
-//                itr = interCommRight.erase(itr) ;
               }
               MPI_Comm_free(&(*it));
@@ -488,10 +492,10 @@
        contextList[contextId]=context;
 
-       // All type of servers initialize its own server (CContextServer)
+       // Primary or classical server: initialize its own server (CContextServer)
+       MPI_Comm inter;
        if (serverLevel < 2)
        {
          MPI_Comm contextInterComm;
          MPI_Intercomm_create(intraComm, 0, CXios::globalComm, leaderRank, 10+leaderRank, &contextInterComm);
-         MPI_Comm inter;
          MPI_Intercomm_merge(contextInterComm,1,&inter);
          MPI_Barrier(inter);
@@ -499,8 +503,13 @@
          context->initServer(intraComm,contextInterComm);
          contextInterComms.push_back(contextInterComm);
-       }
+
+       }
+       // Secondary server: initialize its own server (CContextServer)
        else if (serverLevel == 2)
        {
-         context->initServer(intraComm, interCommLeft.front());
+         MPI_Comm_dup(interCommLeft.front(), &inter);
+         contextInterComms.push_back(inter);
+         context->initServer(intraComm, contextInterComms.back());
+//         context->initServer(intraComm, interCommLeft.front());
        }
 
@@ -520,9 +529,16 @@
            CBufferOut buffer(buff,messageSize) ;
            buffer<<msg ;
-           int sndServerGloRanks = serverSize-nbPools+serverLeader +i;  // the assumption is that there is only one proc per secondary server pool
+           int sndServerGloRanks = serverSize_-nbPools+serverLeader_ +i;  // the assumption is that there is only one proc per secondary server pool
            MPI_Send(buff, buffer.count(), MPI_CHAR, sndServerGloRanks, 1, CXios::globalComm) ;
-           context->initClient(intraComm, *it) ;
+           MPI_Comm_dup(*it, &inter);
+           contextInterComms.push_back(inter);
+           MPI_Comm_dup(intraComm, &inter);
+           contextIntraComms.push_back(inter);
+           context->initClient(contextIntraComms.back(), contextInterComms.back()) ;
+//           context->initClient(intraComm, contextPrimInterComms.back()) ;
+//           context->initClient(intraComm, *it) ;
            delete [] buff ;
          }
+         ++nbContexts_;
        }
      }
@@ -539,9 +555,12 @@
          if (finished)
          {
+//           it->second->freeComms();  // deallocate internally allcoated context communicators
            contextList.erase(it) ;
            break ;
          }
          else
+         {
            finished=it->second->checkBuffersAndListen();
+         }
        }
      }
@@ -579,5 +598,5 @@
       {
         if (serverLevel == 1)
-          id = rank-serverLeader;
+          id = rank-serverLeader_;
         else
           id = poolId;
Index: XIOS/dev/dev_olga/src/server.hpp
===================================================================
--- XIOS/dev/dev_olga/src/server.hpp	(revision 1070)
+++ XIOS/dev/dev_olga/src/server.hpp	(revision 1071)
@@ -27,5 +27,6 @@
         static list<MPI_Comm> interCommLeft;           // interComm between server (primary, classical or secondary) and its client (client or primary server)
         static list<MPI_Comm> interCommRight;          // interComm between primary server and secondary server (non-empty only for primary server pool)
-        static std::list<MPI_Comm> contextInterComms;  // significance ??
+        static std::list<MPI_Comm> contextInterComms;  // list of context intercomms
+        static std::list<MPI_Comm> contextIntraComms;  // list of context intercomms (needed only in case of secondary servers)
         static CEventScheduler* eventScheduler;
 
@@ -64,8 +65,9 @@
       private:
         static int rank;
-        static int serverLeader;  //!< Leader of the classical or primary server (needed in case of secondary servers)
-        static int serverSize;    //!< Number of procs dedicated to servers (primary and seconday (if any) combined)
+        static int serverLeader_;  //!< Leader of the classical or primary server (needed in case of secondary servers)
+        static int serverSize_;    //!< Number of procs dedicated to servers (primary and seconday (if any) combined)
         static int nbPools;       //!< Number of secondary server pools
         static int poolId;        //!< id of a secondary server pool starting from 1
+        static int nbContexts_;
         static StdOFStream m_infoStream;
         static StdOFStream m_errorStream;
Index: XIOS/dev/dev_olga/src/test/test_second_server.f90
===================================================================
--- XIOS/dev/dev_olga/src/test/test_second_server.f90	(revision 1071)
+++ XIOS/dev/dev_olga/src/test/test_second_server.f90	(revision 1071)
@@ -0,0 +1,248 @@
+PROGRAM test_regular
+
+  USE xios
+  USE mod_wait
+  IMPLICIT NONE
+  INCLUDE "mpif.h"
+
+  INTEGER, PARAMETER :: ntime=1
+
+  CHARACTER(len=*),PARAMETER :: id="client"
+  TYPE(xios_duration)  :: dtime
+  TYPE(xios_context) :: ctx_hdl
+  TYPE(xios_field) :: field_hdl
+  TYPE(xios_fieldgroup) :: fieldgroup_hdl
+  TYPE(xios_file) :: file_hdl
+  LOGICAL :: ok
+  CHARACTER(len=256) :: crname
+  INTEGER :: ts, i
+  INTEGER :: comm  
+  INTEGER :: ierr
+  INTEGER :: size, rank
+
+  INTEGER :: nlon = 6 !20 
+  INTEGER :: nlat = 6 !16 
+  INTEGER :: ncell 
+  
+  INTEGER :: ilat, ilon, ind
+  DOUBLE PRECISION :: lon1, lon2, lat1, lat2
+  INTEGER :: ni, ibegin
+
+  DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:)
+  DOUBLE PRECISION,ALLOCATABLE :: lat_glo(:)
+  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: bounds_lat_glo(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_temp_glo(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: lon(:)
+  DOUBLE PRECISION,ALLOCATABLE :: lat(:)
+  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: bounds_lat(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_temp(:,:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_temp1(:)
+  DOUBLE PRECISION,ALLOCATABLE :: field_temp2(:)
+  INTEGER,ALLOCATABLE  :: field_int(:)
+
+!!! MPI Initialization
+  CALL MPI_INIT(ierr)
+
+!!! XIOS Initialization (get the local communicator)
+  CALL xios_initialize(id,return_comm=comm)
+
+!!! Initialisation des coordonnÃ©es globales et locales pour la grille rÃ©guliÃšre
+
+! Regions around the poles are not included into the grid
+! The whole grid is rectangular (nvertex=4)
+
+  ncell = nlon * (nlat-1)
+  ALLOCATE(lon_glo(ncell))
+  ALLOCATE(lat_glo(ncell))
+  ALLOCATE(bounds_lon_glo(4,ncell))
+  ALLOCATE(bounds_lat_glo(4,ncell))
+  ALLOCATE(field_temp_glo(ncell,ntime))
+
+
+  ind = 0
+  DO ilat = 1, nlat-1
+   DO ilon = 1, nlon
+
+      ind=ind+1
+
+      lon1 = 360./DBLE(nlon) * DBLE(ilon-1)
+      lon2 = lon1 + 360./DBLE(nlon)
+
+      lat1 = (90. + 90./DBLE(nlat)) - 180./DBLE(nlat)*DBLE(ilat)
+      lat2 = lat1 - 180./DBLE(nlat)
+
+      lon_glo(ind) = (lon1+lon2)*0.5
+      lat_glo(ind) = (lat1+lat2)*0.5 
+
+      bounds_lon_glo(1,ind) = lon1
+      bounds_lon_glo(2,ind) = lon2
+      bounds_lon_glo(3,ind) = lon2
+      bounds_lon_glo(4,ind) = lon1
+
+      bounds_lat_glo(1,ind) = lat1
+      bounds_lat_glo(2,ind) = lat1
+      bounds_lat_glo(3,ind) = lat2      
+      bounds_lat_glo(4,ind) = lat2     
+
+      field_temp_glo(ind,1) = DBLE(ind)
+
+    ENDDO
+  ENDDO
+
+! Initialization of local variables
+
+  CALL MPI_COMM_RANK(comm,rank,ierr)
+  CALL MPI_COMM_SIZE(comm,size,ierr)
+
+  IF (MOD(ncell, size) == 0) THEN
+    ni = ncell/size
+    ibegin = rank*ni
+  ELSE
+    IF (rank < MOD(ncell, size)) THEN
+      ni = ncell/size + 1
+      ibegin = rank*(ncell/size + 1)
+    ELSE
+      ni = ncell/size
+      IF (rank == MOD(ncell, size)) THEN
+        ibegin = rank*(ncell/size + 1)
+      ELSE
+        ibegin = MOD(ncell,size)*(ncell/size + 1) + (rank-MOD(ncell,size))*ncell/size
+      END IF
+    END IF
+  END IF
+
+  ALLOCATE(lon(ni))
+  ALLOCATE(lat(ni))
+  ALLOCATE(bounds_lon(4,ni))
+  ALLOCATE(bounds_lat(4,ni))
+  ALLOCATE(field_temp(ni,ntime)) 
+  ALLOCATE(field_temp1(ni))
+  ALLOCATE(field_temp2(ni))
+  ALLOCATE(field_int(ni))
+  lon = lon_glo(1+ibegin:ibegin+ni)
+  lat = lat_glo(1+ibegin:ibegin+ni)
+  bounds_lon(:,:) = bounds_lon_glo(:,1+ibegin:ibegin+ni)
+  bounds_lat(:,:) = bounds_lat_glo(:,1+ibegin:ibegin+ni)
+
+  !field_temp(:) = rank
+  field_temp1(:) = rank + 10
+  field_temp2(:) = rank + 20
+ 
+ DO i = 1, ni
+  field_temp1 (i) = 100*rank + i
+  field_temp2 (i) = 0 !200*rank + i
+  !field_temp1 (i) = 10
+END DO
+
+!###########################################################################
+! Contexte ATM
+!###########################################################################
+
+  CALL xios_context_initialize("atmosphere",comm)
+  CALL xios_get_handle("atmosphere",ctx_hdl)
+  CALL xios_set_current_context(ctx_hdl)
+
+  CALL xios_define_calendar(type="Gregorian", &
+                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
+                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
+
+  CALL xios_set_domain_attr("atm_face", ni_glo=ncell, ibegin=ibegin, ni=ni, type='unstructured')
+  CALL xios_set_domain_attr("atm_face", lonvalue_1d=lon, latvalue_1d=lat)
+  CALL xios_set_domain_attr("atm_face", bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat)
+
+!!! Definition du timestep
+
+  dtime%second=3600
+  CALL xios_set_timestep(timestep=dtime)
+
+!!! Fin de la definition du contexte
+
+  CALL xios_close_context_definition()
+
+!###########################################################################
+! Contexte SRF
+!###########################################################################
+
+  CALL xios_context_initialize("surface",comm)
+  CALL xios_get_handle("surface",ctx_hdl)
+  CALL xios_set_current_context(ctx_hdl)
+
+  CALL xios_define_calendar(type="Gregorian", &
+                            start_date=xios_date(2000, 01, 01, 00, 00, 00), &
+                            time_origin=xios_date(1999, 01, 01, 15, 00, 00))
+
+  CALL xios_set_domain_attr("domain_srf", ni_glo=ncell, ibegin=ibegin, ni=ni, type='unstructured')
+  CALL xios_set_domain_attr("domain_srf", lonvalue_1d=lon, latvalue_1d=lat)
+  CALL xios_set_domain_attr("domain_srf", bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat)
+
+   
+!!! Definition du timestep
+
+  dtime%second=3600
+  CALL xios_set_timestep(timestep=dtime)
+
+!!! Fin de la definition du contexte
+
+  CALL xios_close_context_definition()
+
+
+!####################################################################################
+!!! Boucle temporelle
+!####################################################################################
+    
+    DO ts=1,ntime
+
+      CALL xios_get_handle("atmosphere",ctx_hdl)
+      CALL xios_set_current_context(ctx_hdl)
+
+!!! Mise a jour du pas de temps
+      CALL xios_update_calendar(ts)
+
+!!! On donne la valeur du champ atm
+     CALL xios_send_field("atm_temp1",field_temp1(:))
+     CALL xios_send_field("atm_temp2",field_temp2(:))
+
+     CALL xios_get_handle("surface",ctx_hdl)
+     CALL xios_set_current_context(ctx_hdl)
+
+!!! Mise a jour du pas de temps
+     CALL xios_update_calendar(ts)
+
+!!! On donne la valeur du champ srf
+     CALL xios_send_field("srf_temp",field_temp1(:))
+     CALL wait_us(5000) ;
+
+    ENDDO
+
+    CALL xios_context_finalize()
+
+    CALL xios_get_handle("atmosphere",ctx_hdl)
+    CALL xios_set_current_context(ctx_hdl)
+    CALL xios_context_finalize()
+
+    DEALLOCATE(lon_glo, lat_glo)
+    DEALLOCATE(bounds_lon_glo, bounds_lat_glo)
+    DEALLOCATE(field_temp_glo)
+    DEALLOCATE(lon, lat)
+    DEALLOCATE(bounds_lon, bounds_lat)
+    DEALLOCATE(field_temp)
+    DEALLOCATE(field_temp1, field_temp2)
+    DEALLOCATE(field_int)
+
+!!! Fin de XIOS
+
+    CALL MPI_COMM_FREE(comm, ierr)
+
+    CALL xios_finalize()
+
+    CALL MPI_FINALIZE(ierr)
+
+  END PROGRAM test_regular
+
+
+
+
+
+
