Index: XIOS3/trunk/src/event_scheduler.hpp
===================================================================
--- XIOS3/trunk/src/event_scheduler.hpp	(revision 2518)
+++ XIOS3/trunk/src/event_scheduler.hpp	(revision 2522)
@@ -27,5 +27,5 @@
         */
        CEventScheduler(const MPI_Comm& comm) ;
-
+       CEventScheduler(const MPI_Comm& comm, size_t schedulerLevel) ;
 
        //! Destructor
@@ -40,7 +40,9 @@
         */
        void registerEvent(const size_t timeLine, const size_t contextHashId) ;
+       
+       private:
+       CEventScheduler* getBaseScheduler(void) { if (childScheduler_== nullptr) return this; else return childScheduler_->getBaseScheduler();}
 
-
-
+       public:
        //! public interface for query if the event defined by timeLine and hashId is sheduled next
        /*!
@@ -51,7 +53,12 @@
         *  If the event is scheduled next, it is remove from the `eventStack` queue list  
         */    
-       bool queryEvent(const size_t timeLine, const size_t contextHashId) ;
-       void popEvent() { eventStack_.pop() ; }
-
+       bool queryEvent(const size_t timeLine, const size_t contextHashId) { return getBaseScheduler()->queryEvent_(timeLine, contextHashId); }
+       bool queryEvent_(const size_t timeLine, const size_t contextHashId) ;
+       void popEvent() { getBaseScheduler()->popEvent_() ; }
+       void popEvent_() { eventStack_.pop() ; }
+       bool isRoot(void) { return parent_[0]==mpiRank_ ;}
+       void setParentScheduler(shared_ptr<CEventScheduler> parentScheduler) { parentScheduler_ = parentScheduler ;}
+       void setChildScheduler(shared_ptr<CEventScheduler> childScheduler) { childScheduler_ = childScheduler ;}
+       void splitScheduler(const MPI_Comm& splittedComm, shared_ptr<CEventScheduler>& parent, shared_ptr<CEventScheduler>& child) ;
 
        //! Public interface to give the hand to the instance to check pending or incoming message.
@@ -59,9 +66,10 @@
         * Must be called periodicaly. Call `checkParentRequest` and `checkChildRequest` private method.
         */
-       void checkEvent(void) ;
+       void checkEvent(void) { getBaseScheduler()->checkEvent_(); } 
+       void checkEvent_(void) ;
 
        private:
-
-
+         void initialize(const MPI_Comm& comm) ;
+       
        //! Send an event to the parent of level `lev+1`
        /*!
@@ -71,5 +79,7 @@
         *  The event is sent by an asynchrounous MPI_ISend
         */
-       void registerEvent(const size_t timeLine, const size_t contextHashId, const size_t lev) ;
+      
+       void registerEvent(const size_t timeLine, const size_t contextHashId, const size_t schedulerLevel) ;
+       void registerEvent(const size_t timeLine, const size_t contextHashId, const size_t schedulerLevel, const size_t lev) ;
 
 
@@ -108,5 +118,5 @@
         * Asynchronus MPI_ISend is used.
         */
-       void bcastEvent(const size_t timeLine, const size_t contextHashId, const size_t lev) ;
+       void bcastEvent(const size_t timeLine, const size_t contextHashId, const size_t schedulerLevel ,const size_t lev) ;
        
 
@@ -118,4 +128,5 @@
          size_t timeLine ; /*!< Time line id of the event in the context */
          size_t hashId ; /*!< hassh id of the context */
+         size_t schedulerLevel ; /*!< hierarchical level of scherduler */
          size_t level ;  /*!<hierarchical level of the communication*/
 
@@ -127,5 +138,5 @@
          bool operator==(const SEvent& e) const
          { 
-           if (timeLine == e.timeLine && hashId == e.hashId && level==e.level) return true ;
+           if (timeLine == e.timeLine && hashId == e.hashId && level==e.level && schedulerLevel==e.schedulerLevel) return true ;
            else return false ;
          } ;
@@ -142,14 +153,14 @@
            if (timeLine < e.timeLine) return true ;
            else if (timeLine == e.timeLine && hashId < e.hashId) return true ;
-           else if (timeLine == e.timeLine && hashId == e.hashId && level<e.level) return true ;
+           else if (timeLine == e.timeLine && hashId == e.hashId && schedulerLevel<e.schedulerLevel) return true ;
+           else if (timeLine == e.timeLine && hashId == e.hashId && schedulerLevel==e.schedulerLevel && level<e.level) return true ;
            else return false ;
          } ;
        } ;       
-        
-
+       
        //! Pending request struture. It keep send or receive buffer from asynchronous communication while the request is not complete.
        struct SPendingRequest
        {
-         size_t buffer[3] ;      /*!< communication buffer : timeLine, hashId, level */
+         size_t buffer[4] ;      /*!< communication buffer : timeLine, hashId, level */
          MPI_Request request ;   /*!< pending MPI request */ 
        } ;
@@ -171,4 +182,9 @@
        vector<vector<int> >  child_ ; /*!< List of child rank for each level */
        vector<int> nbChild_ ;         /*!< Number of child for each level */    
+       
+       shared_ptr<CEventScheduler> parentScheduler_ ;
+       shared_ptr<CEventScheduler> childScheduler_ ;
+       bool hasParentScheduler_=false ;
+       size_t schedulerLevel_ ;
 
     } ;
