Index: XIOS/dev/dev_olga/src/buffer_client.cpp
===================================================================
--- XIOS/dev/dev_olga/src/buffer_client.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/buffer_client.cpp	(revision 992)
@@ -87,9 +87,5 @@
       {
         MPI_Comm_test_inter(interComm, &flag);
-//        if (flag)
-          MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
-//        else
-//          ERROR("bool CClientBuffer::checkBuffer(void)",
-//                << "Invalid intercommunicator");
+        MPI_Issend(buffer[current], count, MPI_CHAR, serverRank, 20, interComm, &request);
         pending = true;
         if (current == 1) current = 0;
Index: XIOS/dev/dev_olga/src/client.cpp
===================================================================
--- XIOS/dev/dev_olga/src/client.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/client.cpp	(revision 992)
@@ -24,4 +24,6 @@
     StdOFStream CClient::m_errorStream;
 
+    MPI_Comm& CClient::getInterComm(void)   { return (interComm); }
+
 ///---------------------------------------------------------------
 /*!
@@ -248,5 +250,5 @@
       MPI_Comm_rank(intraComm,&rank) ;
  
-      if ((!CXios::isServer) || (CXios::serverLevel == 1))
+      if (!CXios::isServer)
       {
         MPI_Comm_rank(intraComm,&rank) ;
@@ -282,4 +284,5 @@
    }
 
+
    int CClient::getRank()
    {
Index: XIOS/dev/dev_olga/src/client.hpp
===================================================================
--- XIOS/dev/dev_olga/src/client.hpp	(revision 987)
+++ XIOS/dev/dev_olga/src/client.hpp	(revision 992)
@@ -20,4 +20,6 @@
         static int serverLeader;
         static bool is_MPI_Initialized ;
+
+        static MPI_Comm& getInterComm();
 
         //! Get rank of the current process
Index: XIOS/dev/dev_olga/src/context_server.cpp
===================================================================
--- XIOS/dev/dev_olga/src/context_server.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/context_server.cpp	(revision 992)
@@ -23,5 +23,5 @@
 {
 
-  CContextServer::CContextServer(CContext* parent,MPI_Comm intraComm_,MPI_Comm interComm_)
+  CContextServer::CContextServer(CContext* parent, MPI_Comm intraComm_,MPI_Comm interComm_)
   {
     context=parent;
@@ -41,4 +41,27 @@
     boost::hash<string> hashString;
     hashId=hashString(context->getId());
+
+  }
+
+  CContextServer::CContextServer(CContext* parent, int srvLvl, MPI_Comm intraComm_,MPI_Comm interComm_)
+  {
+    context=parent;
+    intraComm=intraComm_;
+    MPI_Comm_size(intraComm,&intraCommSize);
+    MPI_Comm_rank(intraComm,&intraCommRank);
+    interComm=interComm_;
+    int flag;
+    MPI_Comm_test_inter(interComm,&flag);
+    if (flag) MPI_Comm_remote_size(interComm,&commSize);
+    else  MPI_Comm_size(interComm,&commSize);
+
+    currentTimeLine=0;
+    scheduled=false;
+    finished=false;
+
+    boost::hash<string> hashString;
+    StdString contextId = context->getId();
+    contextId += "_prim";                      // just to distinguish between server and serverPrimServer on server1
+    hashId=hashString(contextId);
 
   }
@@ -184,5 +207,5 @@
          // The best way to properly solve this problem will be to use the event scheduler also in attached mode
          // for now just set up a MPI barrier
-         if (!CServer::eventScheduler) MPI_Barrier(intraComm) ;
+//         if (!CServer::eventScheduler) MPI_Barrier(intraComm) ;
 
          CTimer::get("Process events").resume();
Index: XIOS/dev/dev_olga/src/context_server.hpp
===================================================================
--- XIOS/dev/dev_olga/src/context_server.hpp	(revision 987)
+++ XIOS/dev/dev_olga/src/context_server.hpp	(revision 992)
@@ -14,5 +14,6 @@
     public:
 
-    CContextServer(CContext* parent,MPI_Comm intraComm,MPI_Comm interComm) ;
+    CContextServer(CContext* parent, MPI_Comm intraComm, MPI_Comm interComm) ;
+    CContextServer(CContext* parent, int srvLvl, MPI_Comm intraComm, MPI_Comm interComm) ;
     bool eventLoop(void) ;
     void listen(void) ;
Index: XIOS/dev/dev_olga/src/cxios.hpp
===================================================================
--- XIOS/dev/dev_olga/src/cxios.hpp	(revision 987)
+++ XIOS/dev/dev_olga/src/cxios.hpp	(revision 992)
@@ -37,5 +37,5 @@
 
      static bool isClient ; //!< Check if xios is client
-     static bool isServer ; //!< Check if xios is primary server
+     static bool isServer ; //!< Check if xios is server
 
      static int serverLevel ; //
Index: XIOS/dev/dev_olga/src/distribution_client.cpp
===================================================================
--- XIOS/dev/dev_olga/src/distribution_client.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/distribution_client.cpp	(revision 992)
@@ -24,8 +24,6 @@
    , elementZoomMask_(), elementNLocal_(), elementNGlobal_()
 {
-//  numElement_ = globalLocalIndex.size();    !!! numElement_ should be calculated !!!!
-  isComputed_ = true;  // my changes
-
-
+//  numElement_ = globalLocalIndex.size();    !!! numElement_ should be calculated (?)
+  isComputed_ = true;
   localDataIndex_.resize(globalLocalIndex.size());
   localMaskIndex_.resize(globalLocalIndex.size());
Index: XIOS/dev/dev_olga/src/event_scheduler.cpp
===================================================================
--- XIOS/dev/dev_olga/src/event_scheduler.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/event_scheduler.cpp	(revision 992)
@@ -107,6 +107,4 @@
   }
   
-  
-  
   void CEventScheduler::checkParentRequest(void)
   {
@@ -152,9 +150,10 @@
         size_t hashId=recvRequest->buffer[1] ;
         size_t lev=recvRequest->buffer[2] ;
-        delete recvRequest ;
+//        delete recvRequest ;
         pendingRecvParentRequest.pop() ;       
  
         if (lev==level) eventStack.push(pair<size_t,size_t>(timeLine,hashId)) ;
         else  bcastEvent(timeLine, hashId, lev) ;
+        delete recvRequest ;
       }
     }   
Index: XIOS/dev/dev_olga/src/node/context.cpp
===================================================================
--- XIOS/dev/dev_olga/src/node/context.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/node/context.cpp	(revision 992)
@@ -15,4 +15,5 @@
 #include "xios_spl.hpp"
 
+#include "server.hpp"
 
 namespace xios {
@@ -252,5 +253,5 @@
      {
        clientPrimServer = new CContextClient(this, intraComm, interComm);
-       serverPrimServer = new CContextServer(this, intraComm, interComm);
+       serverPrimServer = new CContextServer(this, 1, intraComm, interComm);  // just some int parameter to distinguish server from serverPrimServer on server1
      }
 
@@ -414,5 +415,5 @@
       {
         finalized = true;
-        if (hasClient) sendRegistry() ;
+//        if (hasClient) sendRegistry() ;
 
 /*        if (CXios::serverLevel == 0)
@@ -446,10 +447,4 @@
         }*/
 
-        client->finalize();
-        while (!server->hasFinished())
-        {
-          server->eventLoop();
-        }
-
         if ((hasClient) && (hasServer))
         {
@@ -458,6 +453,14 @@
           {
             serverPrimServer->eventLoop();
+            CServer::eventScheduler->checkEvent() ;
           }
         }
+
+        client->finalize();
+        while (!server->hasFinished())
+        {
+          server->eventLoop();
+        }
+
 
         if (hasServer)
@@ -1056,5 +1059,5 @@
       this->solveAllInheritance();
 
-      ShowTree(info(10));
+//      ShowTree(info(10));
 
       // Check if some axis, domains or grids are eligible to for compressed indexed output.
Index: XIOS/dev/dev_olga/src/node/file.hpp
===================================================================
--- XIOS/dev/dev_olga/src/node/file.hpp	(revision 987)
+++ XIOS/dev/dev_olga/src/node/file.hpp	(revision 992)
@@ -115,5 +115,5 @@
          CVariableGroup* addVariableGroup(const string& id = "");
 
-         // Send info to serever
+         // Send info to server
          void sendEnabledFields();
          void sendAddField(const string& id = "");
Index: XIOS/dev/dev_olga/src/server.cpp
===================================================================
--- XIOS/dev/dev_olga/src/server.cpp	(revision 987)
+++ XIOS/dev/dev_olga/src/server.cpp	(revision 992)
@@ -18,4 +18,6 @@
 {
     MPI_Comm CServer::intraComm ;
+    list<MPI_Comm> CServer::interCommLeft ;
+    list<MPI_Comm> CServer::interCommRight ;
     list<MPI_Comm> CServer::interComm ;
     std::list<MPI_Comm> CServer::contextInterComms;
@@ -103,4 +105,5 @@
 
                MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
+               interCommLeft.push_back(newComm) ;
                interComm.push_back(newComm) ;
             }
@@ -125,4 +128,5 @@
                          <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
                 MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
+                interCommLeft.push_back(newComm) ;
                 interComm.push_back(newComm) ;
               }
@@ -134,5 +138,8 @@
           }
 
-        CClient::initializeClientOnServer(rank, intraComm, srvSndLeader);
+          CClient::initializeClientOnServer(rank, intraComm, srvSndLeader);
+          interCommRight.push_back(CClient::getInterComm());
+          interComm.push_back(CClient::getInterComm());
+
         }
 
@@ -144,5 +151,4 @@
             if (it->first == hashServer1)
             {
-              // no changes needed here to create one context per process of the secondary server pool
               clientLeader=it->second ;
               int intraCommSize, intraCommRank ;
@@ -153,4 +159,5 @@
 
               MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
+              interCommLeft.push_back(newComm) ;
               interComm.push_back(newComm) ;
 
@@ -207,8 +214,4 @@
     void CServer::finalize(void)
     {
-      if (CXios::serverLevel == 1)
-      {
-        CClient::finalize();
-      }
 
       CTimer::get("XIOS").suspend() ;
@@ -219,5 +222,11 @@
         MPI_Comm_free(&(*it));
 
-      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++)
+//      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++)
+//        MPI_Comm_free(&(*it));
+
+      for (std::list<MPI_Comm>::iterator it = interCommLeft.begin(); it != interCommLeft.end(); it++)
+        MPI_Comm_free(&(*it));
+
+      for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++)
         MPI_Comm_free(&(*it));
 
@@ -263,9 +272,9 @@
      void CServer::listenFinalize(void)
      {
-        list<MPI_Comm>::iterator it;
+        list<MPI_Comm>::iterator it, itr;
         int msg ;
         int flag ;
 
-        for(it=interComm.begin();it!=interComm.end();it++)
+        for(it=interCommLeft.begin();it!=interCommLeft.end();it++)
         {
            MPI_Status status ;
@@ -275,13 +284,25 @@
            if (flag==true)
            {
-              MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ;
-              info(20)<<" CServer : Receive client finalize"<<endl ;
+             MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ;
+             info(20)<<" CServer : Receive client finalize"<<endl ;
+
+             // If primary server, send finalize to secondary server pool(s)
+             for(itr=interCommRight.begin(); itr!=interCommRight.end(); itr++)
+             {
+               MPI_Send(&msg,1,MPI_INT,0,0,*itr) ;
+
+//               MPI_Comm_free(&(*itr));
+//               interCommRight.erase(itr) ;
+             }
+
               MPI_Comm_free(&(*it));
-              interComm.erase(it) ;
+//              interComm.erase(it) ;
+              interCommLeft.erase(it) ;
               break ;
             }
          }
 
-         if (interComm.empty())
+        if (interCommLeft.empty())
+//        if (interComm.empty())
          {
            int i,size ;
Index: XIOS/dev/dev_olga/src/server.hpp
===================================================================
--- XIOS/dev/dev_olga/src/server.hpp	(revision 987)
+++ XIOS/dev/dev_olga/src/server.hpp	(revision 992)
@@ -27,5 +27,7 @@
         // Communicators for the primary group of servers
         static MPI_Comm intraComm;
-        static list<MPI_Comm> interComm;
+        static list<MPI_Comm> interCommLeft;   // interComm between server 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 list<MPI_Comm> interComm;       // interCommLeft + interCommRight
         static std::list<MPI_Comm> contextInterComms;
         static CEventScheduler* eventScheduler;
