Index: /XIOS/dev/dev_olga/src/client.cpp
===================================================================
--- /XIOS/dev/dev_olga/src/client.cpp	(revision 1147)
+++ /XIOS/dev/dev_olga/src/client.cpp	(revision 1148)
@@ -18,7 +18,7 @@
     MPI_Comm CClient::interComm ;
     std::list<MPI_Comm> CClient::contextInterComms;
-    vector <int> CClient::serverLeader;
+    int CClient::serverLeader;
     bool CClient::is_MPI_Initialized ;
-    int CClient::rank = INVALID_RANK;
+    int CClient::rank_ = INVALID_RANK;
     StdOFStream CClient::m_infoStream;
     StdOFStream CClient::m_errorStream;
@@ -66,5 +66,5 @@
 
           MPI_Comm_size(CXios::globalComm,&size) ;
-          MPI_Comm_rank(CXios::globalComm,&rank);
+          MPI_Comm_rank(CXios::globalComm,&rank_);
 
           hashAll=new unsigned long[size] ;
@@ -99,16 +99,17 @@
 
           myColor=colors[hashClient] ;
-          MPI_Comm_split(CXios::globalComm,myColor,rank,&intraComm) ;
+          MPI_Comm_split(CXios::globalComm,myColor,rank_,&intraComm) ;
 
           if (CXios::usingServer)
           {
             int clientLeader=leaders[hashClient] ;
-            serverLeader.push_back(leaders[hashServer]) ;
+            serverLeader=leaders[hashServer] ;
             int intraCommSize, intraCommRank ;
             MPI_Comm_size(intraComm,&intraCommSize) ;
             MPI_Comm_rank(intraComm,&intraCommRank) ;
-            info(50)<<"intercommCreate::client "<<rank<<" intraCommSize : "<<intraCommSize
-                   <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader.back()<<endl ;
-             MPI_Intercomm_create(intraComm, 0, CXios::globalComm, serverLeader.back(), 0, &interComm) ;
+            info(50)<<"intercommCreate::client "<<rank_<<" intraCommSize : "<<intraCommSize
+                   <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< serverLeader<<endl ;
+             MPI_Intercomm_create(intraComm, 0, CXios::globalComm, serverLeader, 0, &interComm) ;
+             rank_ = intraCommRank;
           }
           else
@@ -149,8 +150,8 @@
         {
           MPI_Status status ;
-          MPI_Comm_rank(intraComm,&rank) ;
+          MPI_Comm_rank(intraComm,&rank_) ;
 
           oasis_get_intercomm(interComm,CXios::xiosCodeId) ;
-          if (rank==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ;
+          if (rank_==0) MPI_Recv(&serverLeader,1, MPI_INT, 0, 0, interComm, &status) ;
           MPI_Bcast(&serverLeader,1,MPI_INT,0,intraComm) ;
 
@@ -216,18 +217,15 @@
         buffer<<msg ;
 
-        for (int i = 0; i < serverLeader.size(); ++i)
-        {
-          MPI_Send(buff, buffer.count(), MPI_CHAR, serverLeader[i], 1, CXios::globalComm) ;
-          MPI_Intercomm_create(contextComm, 0, CXios::globalComm, serverLeader[i], 10+globalRank, &contextInterComm) ;
-          info(10)<<"Register new Context : "<<id<<endl ;
-          MPI_Comm inter ;
-          MPI_Intercomm_merge(contextInterComm,0,&inter) ;
-          MPI_Barrier(inter) ;
-
-          context->initClient(contextComm,contextInterComm) ;
-
-          contextInterComms.push_back(contextInterComm);
-          MPI_Comm_free(&inter);
-        }
+        MPI_Send(buff, buffer.count(), MPI_CHAR, serverLeader, 1, CXios::globalComm) ;
+        MPI_Intercomm_create(contextComm, 0, CXios::globalComm, serverLeader, 10+globalRank, &contextInterComm) ;
+        info(10)<<"Register new Context : "<<id<<endl ;
+        MPI_Comm inter ;
+        MPI_Intercomm_merge(contextInterComm,0,&inter) ;
+        MPI_Barrier(inter) ;
+
+        context->initClient(contextComm,contextInterComm) ;
+
+        contextInterComms.push_back(contextInterComm);
+        MPI_Comm_free(&inter);
         delete [] buff ;
 
@@ -276,8 +274,10 @@
    }
 
-
+    /*!
+    * Return rank in model intraComm
+    */
    int CClient::getRank()
    {
-     return rank;
+     return rank_;
    }
 
Index: /XIOS/dev/dev_olga/src/client.hpp
===================================================================
--- /XIOS/dev/dev_olga/src/client.hpp	(revision 1147)
+++ /XIOS/dev/dev_olga/src/client.hpp	(revision 1148)
@@ -18,5 +18,5 @@
         static MPI_Comm interComm;
         static std::list<MPI_Comm> contextInterComms;
-        static vector<int> serverLeader;
+        static int serverLeader;
         static bool is_MPI_Initialized ;
 
@@ -41,5 +41,5 @@
 
       protected:
-        static int rank;
+        static int rank_;                 //!< Rank in model intraComm
         static StdOFStream m_infoStream;
         static StdOFStream m_errorStream;
Index: /XIOS/dev/dev_olga/src/context_client.hpp
===================================================================
--- /XIOS/dev/dev_olga/src/context_client.hpp	(revision 1147)
+++ /XIOS/dev/dev_olga/src/context_client.hpp	(revision 1148)
@@ -105,10 +105,4 @@
       std::list<int> ranksServerNotLeader;
 
-    public: // Some function should be removed in the future
-      //    void registerEvent(CEventClient& event);
-//    list<CBufferOut*> newEvent(CEventClient& event,list<int>& sizes);
-//    bool locked;
-//    set<int> connectedServer;
-
   };
 }
Index: /XIOS/dev/dev_olga/src/server.cpp
===================================================================
--- /XIOS/dev/dev_olga/src/server.cpp	(revision 1147)
+++ /XIOS/dev/dev_olga/src/server.cpp	(revision 1148)
@@ -28,5 +28,5 @@
     int CServer::nbPools = 0;
     int CServer::poolId = 0;
-    int CServer::nbContexts_ = 0;
+    int CServer::nbContexts = 0;
     bool CServer::isRoot = false ;
     int CServer::rank_ = INVALID_RANK;
@@ -44,8 +44,8 @@
  * In case of secondary servers intraComm is created for each secondary server pool.
  * (For now the assumption is that there is one proc per pool.)
- * Creates the following lists of interComms:
+ * Creates interComm and stores them into the following lists:
  *   classical server -- interCommLeft
  *   primary server -- interCommLeft and interCommRight
- *   secondary server -- interComm for each pool.
+ *   secondary server -- interCommLeft for each pool.
  */
     void CServer::initialize(void)
@@ -85,5 +85,4 @@
         map<unsigned long, int> colors ;
         map<unsigned long, int> leaders ;
-        map<unsigned long, int> lastProcesses ;  // needed in case of two server levels
         map<unsigned long, int>::iterator it ;
 
@@ -97,7 +96,5 @@
             c++ ;
           }
-          if (hashAll[i] == hashServer) ++nbSrv;
-          //if (hashAll[i+1] != hashAll[i])  // Potential bug here!
-          //  lastProcesses[hashAll[i]]=i ; // It seems that lastprocesses is only used for calculating the server size. Can we count server size directly?
+          if (hashAll[i] == hashServer) ++serverSize_;
         }
 
@@ -107,6 +104,4 @@
         {
           int serverRank = rank_ - leaders[hashServer]; // server proc rank starting 0
-          serverSize_ = nbSrv; //lastProcesses[hashServer] - leaders[hashServer] + 1;
-//          serverSize_ = lastProcesses - leaders[hashServer];
           nbPools = serverSize_ * CXios::ratioServer2 / 100;
           if ( serverRank < (serverSize_ - nbPools) )
@@ -324,4 +319,5 @@
          {
            listenContext();
+           listenRootContext();
            if (!finished) listenFinalize() ;
          }
@@ -467,13 +463,28 @@
          int size ;
          MPI_Comm_size(intraComm,&size) ;
-         MPI_Request* requests= new MPI_Request[size-1] ;
-         MPI_Status* status= new MPI_Status[size-1] ;
-
-         for(int i=1;i<size;i++)
-         {
-            MPI_Isend(buff,count,MPI_CHAR,i,2,intraComm,&requests[i-1]) ;
-         }
-         MPI_Waitall(size-1,requests,status) ;
-         registerContext(buff,count,it->second.leaderRank) ;
+//         MPI_Request* requests= new MPI_Request[size-1] ;
+//         MPI_Status* status= new MPI_Status[size-1] ;
+         MPI_Request* requests= new MPI_Request[size] ;
+         MPI_Status* status= new MPI_Status[size] ;
+
+         CMessage msg ;
+         msg<<id<<it->second.leaderRank;
+         int messageSize=msg.size() ;
+         void * sendBuff = new char[messageSize] ;
+         CBufferOut sendBuffer(sendBuff,messageSize) ;
+         sendBuffer<<msg ;
+
+         // Include root itself in order not to have a divergence
+         for(int i=0; i<size; i++)
+         {
+           MPI_Isend(sendBuff,count,MPI_CHAR,i,2,intraComm,&requests[i]) ;
+         }
+
+//         for(int i=1;i<size;i++)
+//         {
+//            MPI_Isend(buff,count,MPI_CHAR,i,2,intraComm,&requests[i-1]) ;
+//         }
+//         MPI_Waitall(size-1,requests,status) ;
+//         registerContext(buff,count,it->second.leaderRank) ;
 
          recvContextId.erase(it) ;
@@ -492,7 +503,11 @@
        static bool recept=false ;
        int rank ;
-       int count ;
+//       int count ;
+       static int count ;
        const int root=0 ;
-
+       boost::hash<string> hashString;
+       size_t hashId = hashString("RegisterContext");
+
+       // (1) Receive context id from the root
        if (recept==false)
        {
@@ -508,4 +523,5 @@
          }
        }
+       // (2) If context id is received, save it into a buffer and register an event
        else
        {
@@ -514,8 +530,16 @@
          {
            MPI_Get_count(&status,MPI_CHAR,&count) ;
-           registerContext(buffer,count) ;
-           delete [] buffer ;
+           eventScheduler->registerEvent(nbContexts,hashId);
+//           registerContext(buffer,count) ;
+//           delete [] buffer ;
            recept=false ;
          }
+       }
+       // (3) If event has been scheduled, call register context
+       if (eventScheduler->queryEvent(nbContexts,hashId))
+       {
+         registerContext(buffer,count) ;
+         ++nbContexts;
+         delete [] buffer ;
        }
      }
@@ -525,5 +549,6 @@
        string contextId;
        CBufferIn buffer(buff, count);
-       buffer >> contextId;
+//       buffer >> contextId;
+       buffer >> contextId>>leaderRank;
        CContext* context;
 
@@ -537,5 +562,7 @@
        contextList[contextId]=context;
 
-       // Primary or classical server: initialize its own server (CContextServer)
+       // Primary or classical server: create communication channel with a client
+       // (1) create interComm (with a client)
+       // (2) initialize client and server (contextClient and contextServer)
        MPI_Comm inter;
        if (serverLevel < 2)
@@ -550,5 +577,10 @@
 
        }
-       // Secondary server: initialize its own server (CContextServer)
+       // Secondary server: create communication channel with a primary server
+       // (1) duplicate interComm with a primary server
+       // (2) initialize client and server (contextClient and contextServer)
+       // Remark: in the case of the secondary server there is no need to create an interComm calling MPI_Intercomm_create,
+       //         because interComm of CContext is defined on the same processes as the interComm of CServer.
+       //         So just duplicate it.
        else if (serverLevel == 2)
        {
@@ -558,5 +590,7 @@
        }
 
-       // Primary server: send create context message to secondary servers and initialize its own client (CContextClient)
+       // Primary server:
+       // (1) send create context message to secondary servers
+       // (2) initialize communication channels with secondary servers (create contextClient and contextServer)
        if (serverLevel == 1)
        {
@@ -582,5 +616,4 @@
            delete [] buff ;
          }
-         ++nbContexts_;
        }
      }
@@ -596,5 +629,4 @@
          if (isFinalized)
          {
-//           it->second->postFinalize();
            contextList.erase(it) ;
            break ;
@@ -605,5 +637,5 @@
      }
 
-     //! Get rank of the current process
+     //! Get rank of the current process in the intraComm
      int CServer::getRank()
      {
Index: /XIOS/dev/dev_olga/src/server.hpp
===================================================================
--- /XIOS/dev/dev_olga/src/server.hpp	(revision 1147)
+++ /XIOS/dev/dev_olga/src/server.hpp	(revision 1148)
@@ -65,9 +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 nbPools;       //!< Number of secondary server pools
-        static int poolId;        //!< id of a secondary server pool starting from 1
-        static int nbContexts_;
+        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;        //!< Number of contexts registered by server
         static StdOFStream m_infoStream;
         static StdOFStream m_errorStream;
