Index: XIOS/dev/branch_openmp/src/server.cpp
===================================================================
--- XIOS/dev/branch_openmp/src/server.cpp	(revision 1545)
+++ XIOS/dev/branch_openmp/src/server.cpp	(revision 1642)
@@ -14,13 +14,13 @@
 #include "timer.hpp"
 #include "event_scheduler.hpp"
-using namespace ep_lib;
+#include "string_tools.hpp"
 
 namespace xios
 {
-    MPI_Comm CServer::intraComm ;
-    std::list<MPI_Comm> CServer::interCommLeft ;
-    std::list<MPI_Comm> CServer::interCommRight ;
-    std::list<MPI_Comm> CServer::contextInterComms;
-    std::list<MPI_Comm> CServer::contextIntraComms;
+    ep_lib::MPI_Comm CServer::intraComm ;
+    std::list<ep_lib::MPI_Comm> CServer::interCommLeft ;
+    std::list<ep_lib::MPI_Comm> CServer::interCommRight ;
+    std::list<ep_lib::MPI_Comm> CServer::contextInterComms;
+    std::list<ep_lib::MPI_Comm> CServer::contextIntraComms;
     int CServer::serverLevel = 0 ;
     int CServer::nbContexts = 0;
@@ -47,8 +47,8 @@
     void CServer::initialize(void)
     {
-      //int initialized ;
-      //MPI_Initialized(&initialized) ;
-      //if (initialized) is_MPI_Initialized=true ;
-      //else is_MPI_Initialized=false ;
+      int initialized ;
+      ep_lib::MPI_Initialized(&initialized) ;
+      if (initialized) is_MPI_Initialized=true ;
+      else is_MPI_Initialized=false ;
       int rank ;
 
@@ -57,8 +57,8 @@
       {
 
-        //if (!is_MPI_Initialized)
-        //{
-        //  MPI_Init(NULL, NULL);
-        //}
+        if (!is_MPI_Initialized)
+        {
+          ep_lib::MPI_Init(NULL, NULL);
+        }
         CTimer::get("XIOS").resume() ;
 
@@ -72,11 +72,11 @@
         int myColor ;
         int i,c ;
-        MPI_Comm newComm;
-
-        MPI_Comm_size(CXios::globalComm, &size) ;
-        MPI_Comm_rank(CXios::globalComm, &rank_);
+        ep_lib::MPI_Comm newComm;
+
+        ep_lib::MPI_Comm_size(CXios::globalComm, &size) ;
+        ep_lib::MPI_Comm_rank(CXios::globalComm, &rank_);
 
         hashAll=new unsigned long[size] ;
-        MPI_Allgather(&hashServer, 1, MPI_LONG, hashAll, 1, MPI_LONG, CXios::globalComm) ;
+        ep_lib::MPI_Allgather(&hashServer, 1, EP_LONG, hashAll, 1, EP_LONG, CXios::globalComm) ;
 
         map<unsigned long, int> colors ;
@@ -152,5 +152,4 @@
             if (serverLevel==2)
             {
-              #pragma omp critical (_output)
               info(50)<<"The number of secondary server pools is "<< sndServerGlobalRanks.size() <<endl ;
               for (i=0; i<sndServerGlobalRanks.size(); i++)
@@ -175,5 +174,5 @@
         // (2) Create intraComm
         if (serverLevel != 2) myColor=colors[hashServer];
-        MPI_Comm_split(CXios::globalComm, myColor, rank_, &intraComm) ;
+        ep_lib::MPI_Comm_split(CXios::globalComm, myColor, rank_, &intraComm) ;
 
         // (3) Create interComm
@@ -187,15 +186,10 @@
               clientLeader=it->second ;
               int intraCommSize, intraCommRank ;
-              MPI_Comm_size(intraComm,&intraCommSize) ;
-              MPI_Comm_rank(intraComm,&intraCommRank) ;
-
-              MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
-              #pragma omp critical (_output)
-              {
-                info(50)<<"intercommCreate::server (classical mode) "<<rank_<<" intraCommSize : "<<intraCommSize
+              ep_lib::MPI_Comm_size(intraComm,&intraCommSize) ;
+              ep_lib::MPI_Comm_rank(intraComm,&intraCommRank) ;
+              info(50)<<"intercommCreate::server (classical mode) "<<rank_<<" intraCommSize : "<<intraCommSize
                        <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
-              }
-
-              
+
+              ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
               interCommLeft.push_back(newComm) ;
             }
@@ -213,14 +207,9 @@
               clientLeader=it->second ;
               int intraCommSize, intraCommRank ;
-              MPI_Comm_size(intraComm, &intraCommSize) ;
-              MPI_Comm_rank(intraComm, &intraCommRank) ;
-              
-              MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
-              #pragma omp critical (_output)
-              {
-                info(50)<<"intercommCreate::server (server level 1) "<<rank_<<" intraCommSize : "<<intraCommSize
+              ep_lib::MPI_Comm_size(intraComm, &intraCommSize) ;
+              ep_lib::MPI_Comm_rank(intraComm, &intraCommRank) ;
+              info(50)<<"intercommCreate::server (server level 1) "<<rank_<<" intraCommSize : "<<intraCommSize
                        <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
-              }
-
+              ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 0, &newComm) ;
               interCommLeft.push_back(newComm) ;
             }
@@ -230,14 +219,9 @@
           {
             int intraCommSize, intraCommRank ;
-            MPI_Comm_size(intraComm, &intraCommSize) ;
-            MPI_Comm_rank(intraComm, &intraCommRank) ;
-
-            MPI_Intercomm_create(intraComm, 0, CXios::globalComm, sndServerGlobalRanks[i], 1, &newComm) ;
-            #pragma omp critical (_output)
-            {
-              info(50)<<"intercommCreate::client (server level 1) "<<rank_<<" intraCommSize : "<<intraCommSize
+            ep_lib::MPI_Comm_size(intraComm, &intraCommSize) ;
+            ep_lib::MPI_Comm_rank(intraComm, &intraCommRank) ;
+            info(50)<<"intercommCreate::client (server level 1) "<<rank_<<" intraCommSize : "<<intraCommSize
                 <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< sndServerGlobalRanks[i]<<endl ;
-            }
-
+            ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, sndServerGlobalRanks[i], 1, &newComm) ;
             interCommRight.push_back(newComm) ;
           }
@@ -248,14 +232,10 @@
           clientLeader = leaders[hashString(CXios::xiosCodeId)];
           int intraCommSize, intraCommRank ;
-          MPI_Comm_size(intraComm, &intraCommSize) ;
-          MPI_Comm_rank(intraComm, &intraCommRank) ;
-
-          MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 1, &newComm) ;
-          #pragma omp critical (_output)
-          {
-            info(50)<<"intercommCreate::server (server level 2) "<<rank_<<" intraCommSize : "<<intraCommSize
+          ep_lib::MPI_Comm_size(intraComm, &intraCommSize) ;
+          ep_lib::MPI_Comm_rank(intraComm, &intraCommRank) ;
+          info(50)<<"intercommCreate::server (server level 2) "<<rank_<<" intraCommSize : "<<intraCommSize
                    <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< clientLeader<<endl ;
-          }
-
+
+          ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, clientLeader, 1, &newComm) ;
           interCommLeft.push_back(newComm) ;
         }
@@ -273,20 +253,20 @@
 
         CTimer::get("XIOS").resume() ;
-        MPI_Comm localComm;
+        ep_lib::MPI_Comm localComm;
         oasis_get_localcomm(localComm);
-        MPI_Comm_rank(localComm,&rank_) ;
+        ep_lib::MPI_Comm_rank(localComm,&rank_) ;
 
 //      (1) Create server intraComm
         if (!CXios::usingServer2)
         {
-          MPI_Comm_dup(localComm, &intraComm);
+          ep_lib::MPI_Comm_dup(localComm, &intraComm);
         }
         else
         {
           int globalRank;
-          MPI_Comm_size(localComm,&size) ;
-          MPI_Comm_rank(CXios::globalComm,&globalRank) ;
+          ep_lib::MPI_Comm_size(localComm,&size) ;
+          ep_lib::MPI_Comm_rank(CXios::globalComm,&globalRank) ;
           srvGlobalRanks = new int[size] ;
-          MPI_Allgather(&globalRank, 1, MPI_INT, srvGlobalRanks, 1, MPI_INT, localComm) ;
+          ep_lib::MPI_Allgather(&globalRank, 1, EP_INT, srvGlobalRanks, 1, EP_INT, localComm) ;
 
           int reqNbProc = size*CXios::ratioServer2/100.;
@@ -296,5 +276,5 @@
                 << "It is impossible to dedicate the requested number of processes = "<<reqNbProc
                 <<" to secondary server. XIOS will run in the classical server mode."<<endl;
-            MPI_Comm_dup(localComm, &intraComm);
+            ep_lib::MPI_Comm_dup(localComm, &intraComm);
           }
           else
@@ -359,19 +339,19 @@
             }
             if (serverLevel != 2) myColor=0;
-            MPI_Comm_split(localComm, myColor, rank_, &intraComm) ;
+            ep_lib::MPI_Comm_split(localComm, myColor, rank_, &intraComm) ;
           }
         }
 
         string codesId=CXios::getin<string>("oasis_codes_id") ;
-        vector<string> splitted ;
-        boost::split( splitted, codesId, boost::is_any_of(","), boost::token_compress_on ) ;
+        vector<string> oasisCodeId=splitRegex(codesId,"\\s*,\\s*") ;
+ 
         vector<string>::iterator it ;
 
-        MPI_Comm newComm ;
+        ep_lib::MPI_Comm newComm ;
         int globalRank ;
-        MPI_Comm_rank(CXios::globalComm,&globalRank);
+        ep_lib::MPI_Comm_rank(CXios::globalComm,&globalRank);
 
 //      (2) Create interComms with models
-        for(it=splitted.begin();it!=splitted.end();it++)
+        for(it=oasisCodeId.begin();it!=oasisCodeId.end();it++)
         {
           oasis_get_intercomm(newComm,*it) ;
@@ -379,5 +359,5 @@
           {
             interCommLeft.push_back(newComm) ;
-            if (rank_==0) MPI_Send(&globalRank,1,MPI_INT,0,0,newComm) ;
+            if (rank_==0) ep_lib::MPI_Send(&globalRank,1,EP_INT,0,0,newComm) ;
           }
         }
@@ -385,6 +365,6 @@
 //      (3) Create interComms between primary and secondary servers
         int intraCommSize, intraCommRank ;
-        MPI_Comm_size(intraComm,&intraCommSize) ;
-        MPI_Comm_rank(intraComm, &intraCommRank) ;
+        ep_lib::MPI_Comm_size(intraComm,&intraCommSize) ;
+        ep_lib::MPI_Comm_rank(intraComm, &intraCommRank) ;
 
         if (serverLevel == 1)
@@ -395,5 +375,5 @@
             info(50)<<"intercommCreate::client (server level 1) "<<globalRank<<" intraCommSize : "<<intraCommSize
                 <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< srvSndLeader<<endl ;
-            MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvSndLeader, 0, &newComm) ;
+            ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvSndLeader, 0, &newComm) ;
             interCommRight.push_back(newComm) ;
           }
@@ -403,13 +383,15 @@
           info(50)<<"intercommCreate::server (server level 2)"<<globalRank<<" intraCommSize : "<<intraCommSize
                    <<" intraCommRank :"<<intraCommRank<<"  clientLeader "<< srvGlobalRanks[0] <<endl ;
-          MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvGlobalRanks[0], 0, &newComm) ;
+          ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, srvGlobalRanks[0], 0, &newComm) ;
           interCommLeft.push_back(newComm) ;
         }
         if (CXios::usingServer2) delete [] srvGlobalRanks ;
-        oasis_enddef() ;
+
+        bool oasisEnddef=CXios::getin<bool>("call_oasis_enddef",true) ;
+        if (!oasisEnddef) oasis_enddef() ;
       }
 
 
-      MPI_Comm_rank(intraComm, &rank) ;
+      ep_lib::MPI_Comm_rank(intraComm, &rank) ;
       if (rank==0) isRoot=true;
       else isRoot=false;
@@ -424,9 +406,9 @@
       delete eventScheduler ;
 
-      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));
+      for (std::list<ep_lib::MPI_Comm>::iterator it = contextInterComms.begin(); it != contextInterComms.end(); it++)
+        ep_lib::MPI_Comm_free(&(*it));
+
+      for (std::list<ep_lib::MPI_Comm>::iterator it = contextIntraComms.begin(); it != contextIntraComms.end(); it++)
+        ep_lib::MPI_Comm_free(&(*it));
 
 //      for (std::list<MPI_Comm>::iterator it = interComm.begin(); it != interComm.end(); it++)
@@ -436,15 +418,14 @@
 //          MPI_Comm_free(&(*it));
 
-        for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++)
-          MPI_Comm_free(&(*it));
-
-      MPI_Comm_free(&intraComm);
+        for (std::list<ep_lib::MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++)
+          ep_lib::MPI_Comm_free(&(*it));
+
+      ep_lib::MPI_Comm_free(&intraComm);
 
       if (!is_MPI_Initialized)
       {
         if (CXios::usingOasis) oasis_finalize();
-        //else MPI_Finalize() ;
+        else ep_lib::MPI_Finalize() ;
       }
-
       report(0)<<"Performance report : Time spent for XIOS : "<<CTimer::get("XIOS server").getCumulatedTime()<<endl  ;
       report(0)<<"Performance report : Time spent in processing events : "<<CTimer::get("Process events").getCumulatedTime()<<endl  ;
@@ -464,4 +445,6 @@
            listenContext();
            listenRootContext();
+           listenOasisEnddef() ;
+           listenRootOasisEnddef() ;
            if (!finished) listenFinalize() ;
          }
@@ -469,4 +452,5 @@
          {
            listenRootContext();
+           listenRootOasisEnddef() ;
            if (!finished) listenRootFinalize() ;
          }
@@ -481,5 +465,5 @@
      void CServer::listenFinalize(void)
      {
-        list<MPI_Comm>::iterator it, itr;
+        list<ep_lib::MPI_Comm>::iterator it, itr;
         int msg ;
         int flag ;
@@ -487,18 +471,18 @@
         for(it=interCommLeft.begin();it!=interCommLeft.end();it++)
         {
-           MPI_Status status ;
+           ep_lib::MPI_Status status ;
            traceOff() ;
-           MPI_Iprobe(0,0,*it,&flag,&status) ;
+           ep_lib::MPI_Iprobe(0,0,*it,&flag,&status) ;
            traceOn() ;
            if (flag==true)
            {
-              MPI_Recv(&msg,1,MPI_INT,0,0,*it,&status) ;
+              ep_lib::MPI_Recv(&msg,1,EP_INT,0,0,*it,&status) ;
               info(20)<<" CServer : Receive client finalize"<<endl ;
               // Sending server finalize message to secondary servers (if any)
               for(itr=interCommRight.begin();itr!=interCommRight.end();itr++)
               {
-                MPI_Send(&msg,1,MPI_INT,0,0,*itr) ;
+                ep_lib::MPI_Send(&msg,1,EP_INT,0,0,*itr) ;
               }
-              MPI_Comm_free(&(*it));
+              ep_lib::MPI_Comm_free(&(*it));
               interCommLeft.erase(it) ;
               break ;
@@ -509,10 +493,10 @@
          {
            int i,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(&msg,1,MPI_INT,i,4,intraComm,&requests[i-1]) ;
-           MPI_Waitall(size-1,requests,status) ;
+           ep_lib::MPI_Comm_size(intraComm,&size) ;
+           ep_lib::MPI_Request* requests= new ep_lib::MPI_Request[size-1] ;
+           ep_lib::MPI_Status* status= new ep_lib::MPI_Status[size-1] ;
+
+           for(int i=1;i<size;i++) ep_lib::MPI_Isend(&msg,1,EP_INT,i,4,intraComm,&requests[i-1]) ;
+           ep_lib::MPI_Waitall(size-1,requests,status) ;
 
            finished=true ;
@@ -526,24 +510,124 @@
      {
         int flag ;
-        MPI_Status status ;
+        ep_lib::MPI_Status status ;
         int msg ;
 
         traceOff() ;
-        MPI_Iprobe(0,4,intraComm, &flag, &status) ;
+        ep_lib::MPI_Iprobe(0,4,intraComm, &flag, &status) ;
         traceOn() ;
         if (flag==true)
         {
-           MPI_Recv(&msg,1,MPI_INT,0,4,intraComm,&status) ;
+           ep_lib::MPI_Recv(&msg,1,EP_INT,0,4,intraComm,&status) ;
            finished=true ;
         }
       }
 
+
+   /*!
+    * Root process is listening for an order sent by client to call "oasis_enddef".
+    * The root client of a compound send the order (tag 5). It is probed and received.
+    * When the order has been received from each coumpound, the server root process ping the order to the root processes of the secondary levels of servers (if any).
+    * After, it also inform (asynchronous call) other processes of the communicator that the oasis_enddef call must be done
+    */
+    
+     void CServer::listenOasisEnddef(void)
+     {
+        int flag ;
+        ep_lib::MPI_Status status ;
+        list<ep_lib::MPI_Comm>::iterator it;
+        int msg ;
+        static int nbCompound=0 ;
+        int size ;
+        static bool sent=false ;
+        static ep_lib::MPI_Request* allRequests ;
+        static ep_lib::MPI_Status* allStatus ;
+
+
+        if (sent)
+        {
+          ep_lib::MPI_Comm_size(intraComm,&size) ;
+          ep_lib::MPI_Testall(size,allRequests, &flag, allStatus) ;
+          if (flag==true)
+          {
+            delete [] allRequests ;
+            delete [] allStatus ;
+            sent=false ;
+          }
+        }
+        
+
+        for(it=interCommLeft.begin();it!=interCommLeft.end();it++)
+        {
+           ep_lib::MPI_Status status ;
+           traceOff() ;
+           ep_lib::MPI_Iprobe(0,5,*it,&flag,&status) ;  // tags oasis_endded = 5
+           traceOn() ;
+           if (flag==true)
+           {
+              ep_lib::MPI_Recv(&msg,1,EP_INT,0,5,*it,&status) ; // tags oasis_endded = 5
+              nbCompound++ ;
+              if (nbCompound==interCommLeft.size())
+              {
+                for (std::list<ep_lib::MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++)
+                {
+                   ep_lib::MPI_Send(&msg,1,EP_INT,0,5,*it) ; // tags oasis_endded = 5
+                }
+                ep_lib::MPI_Comm_size(intraComm,&size) ;
+                allRequests= new ep_lib::MPI_Request[size] ;
+                allStatus= new ep_lib::MPI_Status[size] ;
+                for(int i=0;i<size;i++) ep_lib::MPI_Isend(&msg,1,EP_INT,i,5,intraComm,&allRequests[i]) ; // tags oasis_endded = 5
+                sent=true ;
+              }
+           }
+        }
+     }
+     
+   /*!
+    * Processes probes message from root process if oasis_enddef call must be done.
+    * When the order is received it is scheduled to be treated in a synchronized way by all server processes of the communicator
+    */
+     void CServer::listenRootOasisEnddef(void)
+     {
+       int flag ;
+       ep_lib::MPI_Status status ;
+       const int root=0 ;
+       int msg ;
+       static bool eventSent=false ;
+
+       if (eventSent)
+       {
+         boost::hash<string> hashString;
+         size_t hashId = hashString("oasis_enddef");
+         if (eventScheduler->queryEvent(0,hashId))
+         {
+           oasis_enddef() ;
+           eventSent=false ;
+         }
+       }
+         
+       traceOff() ;
+       ep_lib::MPI_Iprobe(root,5,intraComm, &flag, &status) ;
+       traceOn() ;
+       if (flag==true)
+       {
+         ep_lib::MPI_Recv(&msg,1,EP_INT,root,5,intraComm,&status) ; // tags oasis_endded = 5
+         boost::hash<string> hashString;
+         size_t hashId = hashString("oasis_enddef");
+         eventScheduler->registerEvent(0,hashId);
+         eventSent=true ;
+       }
+     }
+
+
+
+     
+
      void CServer::listenContext(void)
      {
 
-       MPI_Status status ;
+       ep_lib::MPI_Status status ;
        int flag ;
        static char* buffer ;
-       static MPI_Request request ;
+       static ep_lib::MPI_Request request ;
        static bool recept=false ;
        int rank ;
@@ -553,5 +637,9 @@
        {
          traceOff() ;
-         MPI_Iprobe(-2,1,CXios::globalComm, &flag, &status) ;
+         #ifdef _usingMPI
+         ep_lib::MPI_Iprobe(MPI_ANY_SOURCE,1,CXios::globalComm, &flag, &status) ;
+         #elif _usingEP
+         ep_lib::MPI_Iprobe(-2,1,CXios::globalComm, &flag, &status) ;
+         #endif
          traceOn() ;
          if (flag==true)
@@ -560,9 +648,9 @@
            rank=status.MPI_SOURCE ;
            #elif _usingEP
-           rank=status.ep_src;
+           rank=status.ep_src ;
            #endif
-           MPI_Get_count(&status,MPI_CHAR,&count) ;
+           ep_lib::MPI_Get_count(&status,EP_CHAR,&count) ;
            buffer=new char[count] ;
-           MPI_Irecv((void*)buffer,count,MPI_CHAR,rank,1,CXios::globalComm,&request) ;
+           ep_lib::MPI_Irecv((void*)buffer,count,EP_CHAR,rank,1,CXios::globalComm,&request) ;
            recept=true ;
          }
@@ -571,5 +659,5 @@
        {
          traceOff() ;
-         MPI_Test(&request,&flag,&status) ;
+         ep_lib::MPI_Test(&request,&flag,&status) ;
          traceOn() ;
          if (flag==true)
@@ -578,7 +666,7 @@
            rank=status.MPI_SOURCE ;
            #elif _usingEP
-           rank=status.ep_src;
+           rank=status.ep_src ;
            #endif
-           MPI_Get_count(&status,MPI_CHAR,&count) ;
+           ep_lib::MPI_Get_count(&status,EP_CHAR,&count) ;
            recvContextMessage((void*)buffer,count) ;
            delete [] buffer ;
@@ -613,9 +701,9 @@
        {
          int size ;
-         MPI_Comm_size(intraComm,&size) ;
+         ep_lib::MPI_Comm_size(intraComm,&size) ;
 //         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] ;
+         ep_lib::MPI_Request* requests= new ep_lib::MPI_Request[size] ;
+         ep_lib::MPI_Status* status= new ep_lib::MPI_Status[size] ;
 
          CMessage msg ;
@@ -629,5 +717,5 @@
          for(int i=0; i<size; i++)
          {
-           MPI_Isend(sendBuff,sendBuffer.count(),MPI_CHAR,i,2,intraComm,&requests[i]) ;
+           ep_lib::MPI_Isend(sendBuff,sendBuffer.count(),EP_CHAR,i,2,intraComm,&requests[i]) ;
          }
 
@@ -641,12 +729,12 @@
      void CServer::listenRootContext(void)
      {
-       MPI_Status status ;
+       ep_lib::MPI_Status status ;
        int flag ;
        static std::vector<void*> buffers;
-       static std::vector<MPI_Request> requests ;
+       static std::vector<ep_lib::MPI_Request> requests ;
        static std::vector<int> counts ;
        static std::vector<bool> isEventRegistered ;
        static std::vector<bool> isEventQueued ;
-       MPI_Request request;
+       ep_lib::MPI_Request request;
 
        int rank ;
@@ -657,13 +745,13 @@
        // (1) Receive context id from the root, save it into a buffer
        traceOff() ;
-       MPI_Iprobe(root,2,intraComm, &flag, &status) ;
+       ep_lib::MPI_Iprobe(root,2,intraComm, &flag, &status) ;
        traceOn() ;
        if (flag==true)
        {
          counts.push_back(0);
-         MPI_Get_count(&status,MPI_CHAR,&(counts.back())) ;
+         ep_lib::MPI_Get_count(&status,EP_CHAR,&(counts.back())) ;
          buffers.push_back(new char[counts.back()]) ;
-         MPI_Irecv((void*)(buffers.back()),counts.back(),MPI_CHAR,root,2,intraComm,&request) ;
          requests.push_back(request);
+         ep_lib::MPI_Irecv((void*)(buffers.back()),counts.back(),EP_CHAR,root,2,intraComm,&(requests.back())) ;
          isEventRegistered.push_back(false);
          isEventQueued.push_back(false);
@@ -674,5 +762,5 @@
        {
          // (2) If context id is received, register an event
-         if(!isEventRegistered[ctxNb]) MPI_Test(&requests[ctxNb],&flag,&status) ;
+         ep_lib::MPI_Test(&requests[ctxNb],&flag,&status) ;
          if (flag==true && !isEventRegistered[ctxNb])
          {
@@ -711,15 +799,15 @@
        // (1) create interComm (with a client)
        // (2) initialize client and server (contextClient and contextServer)
-       MPI_Comm inter;
+       ep_lib::MPI_Comm inter;
        if (serverLevel < 2)
        {
-         MPI_Comm contextInterComm;
-         MPI_Intercomm_create(intraComm, 0, CXios::globalComm, leaderRank, 10+leaderRank, &contextInterComm);
-         MPI_Intercomm_merge(contextInterComm,1,&inter);
-         MPI_Barrier(inter);
+         ep_lib::MPI_Comm contextInterComm;
+         ep_lib::MPI_Intercomm_create(intraComm, 0, CXios::globalComm, leaderRank, 10+leaderRank, &contextInterComm);
+         ep_lib::MPI_Intercomm_merge(contextInterComm,1,&inter);
+         ep_lib::MPI_Barrier(inter);
+         ep_lib::MPI_Comm_free(&inter);
          context->initServer(intraComm,contextInterComm);
          contextInterComms.push_back(contextInterComm);
 
-         MPI_Comm_free(&inter);
        }
        // Secondary server: create communication channel with a primary server
@@ -731,5 +819,5 @@
        else if (serverLevel == 2)
        {
-         MPI_Comm_dup(interCommLeft.front(), &inter);
+         ep_lib::MPI_Comm_dup(interCommLeft.front(), &inter);
          contextInterComms.push_back(inter);
          context->initServer(intraComm, contextInterComms.back());
@@ -742,6 +830,6 @@
        {
          int i = 0, size;
-         MPI_Comm_size(intraComm, &size) ;
-         for (std::list<MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++, ++i)
+         ep_lib::MPI_Comm_size(intraComm, &size) ;
+         for (std::list<ep_lib::MPI_Comm>::iterator it = interCommRight.begin(); it != interCommRight.end(); it++, ++i)
          {
            StdString str = contextId +"_server_" + boost::lexical_cast<string>(i);
@@ -753,8 +841,8 @@
            CBufferOut buffer(buff,messageSize) ;
            buffer<<msg ;
-           MPI_Send(buff, buffer.count(), MPI_CHAR, sndServerGlobalRanks[i], 1, CXios::globalComm) ;
-           MPI_Comm_dup(*it, &inter);
+           ep_lib::MPI_Send(buff, buffer.count(), EP_CHAR, sndServerGlobalRanks[i], 1, CXios::globalComm) ;
+           ep_lib::MPI_Comm_dup(*it, &inter);
            contextInterComms.push_back(inter);
-           MPI_Comm_dup(intraComm, &inter);
+           ep_lib::MPI_Comm_dup(intraComm, &inter);
            contextIntraComms.push_back(inter);
            context->initClient(contextIntraComms.back(), contextInterComms.back()) ;
@@ -786,5 +874,5 @@
      {
        int rank;
-       MPI_Comm_rank(intraComm,&rank);
+       ep_lib::MPI_Comm_rank(intraComm,&rank);
        return rank;
      }
@@ -809,5 +897,5 @@
       int size = 0;
       int id;
-      MPI_Comm_size(CXios::globalComm, &size);
+      ep_lib::MPI_Comm_size(CXios::globalComm, &size);
       while (size)
       {
