Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp	(revision 1517)
@@ -11,39 +11,17 @@
     if(comm->is_intercomm) return MPI_Barrier_intercomm(comm);
 
-    if(comm->is_ep)
+    if(comm->is_ep) 
     {
-      int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
-
-      MPI_Barrier_local(comm);
-
-      if(ep_rank_loc == 0)
-      {
-        ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-
-        ::MPI_Barrier(mpi_comm);
-      }
-
-      MPI_Barrier_local(comm);
-
-      return 0;
-    }
-    else if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
-    {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-      ::MPI_Barrier(mpi_comm);
-      return 0;
+      return MPI_Barrier_intracomm(comm);
     }
 
-    else return 0;
+    
+    return MPI_Barrier_mpi(comm);
+
   }
 
-
-  int MPI_Barrier_intercomm(MPI_Comm comm)
+  int MPI_Barrier_intracomm(MPI_Comm comm)
   {
-
-    int ep_rank;
-    MPI_Comm_rank(comm, &ep_rank);
-
-    int ep_rank_loc = comm->ep_rank_map->at(ep_rank).first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
 
     MPI_Barrier_local(comm);
@@ -51,6 +29,7 @@
     if(ep_rank_loc == 0)
     {
-      //::MPI_Comm mpi_comm = to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm);
-      ::MPI_Barrier(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm));
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
+
+      ::MPI_Barrier(mpi_comm);
     }
 
@@ -58,5 +37,19 @@
 
     return 0;
+  }
 
+  int MPI_Barrier_intercomm(MPI_Comm comm)
+  {
+    MPI_Barrier_local(comm);
+
+    if(comm->ep_comm_ptr->intercomm->size_rank_info[1].first == 0)
+      ::MPI_Barrier(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm));
+
+    MPI_Barrier_local(comm);
+  }
+
+  int MPI_Barrier_mpi(MPI_Comm comm)
+  {
+    return ::MPI_Barrier(to_mpi_comm(comm->mpi_comm));
   }
 
@@ -64,5 +57,4 @@
   int MPI_Barrier_local(MPI_Comm comm)
   {
-    //Message_Check(comm);
     comm->ep_barrier->wait();
   }
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp	(revision 1517)
@@ -37,8 +37,4 @@
 
     ep_intercomm *intercomm;
-
-    ep_communicator();
-    bool operator == (ep_communicator right);
-    bool operator != (ep_communicator right);
     
   };
@@ -53,6 +49,11 @@
 
     BUFFER     *my_buffer;
+    
     ep_barrier *ep_barrier;
+
     EP_RANK_MAP   *ep_rank_map;      // for intercomm : = ep_rank_map of newcomm
+    
+
+
     void* mpi_comm;
     ep_communicator *ep_comm_ptr;
@@ -60,11 +61,6 @@
     void* mpi_bridge;
 
-    ep_comm();  
+    ep_comm(){};  
     ep_comm(void* comm);
-
-
-    bool operator == (ep_comm right);
-    bool operator != (ep_comm right);
-    bool is_null();
 
   };
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp	(revision 1517)
@@ -41,12 +41,33 @@
 
     out_comm_hdls = new MPI_Comm[num_ep];
+#ifdef _showinfo
+    printf("new out_comm_hdls = %p\n", out_comm_hdls);
+#endif
 
+    ::MPI_Comm *parent_comm = new ::MPI_Comm;
+    ::MPI_Comm_dup(to_mpi_comm(base_comm_ptr), parent_comm);
+
+#ifdef _showinfo
+    printf("new out_comm_hdls->mpi_comm = %p\n", parent_comm);
+#endif
+    
     for (int idx = 0; idx < num_ep; ++idx)
     {
+
       out_comm_hdls[idx] = new ep_comm;
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d] = %p\n", idx, out_comm_hdls[idx]);
+#endif
+
       out_comm_hdls[idx]->is_ep = true;
       out_comm_hdls[idx]->is_intercomm = false;
+      
       out_comm_hdls[idx]->ep_comm_ptr = new ep_communicator;     
-      *(static_cast< ::MPI_Comm*>(out_comm_hdls[idx]->mpi_comm)) = *(static_cast< ::MPI_Comm*>(base_comm_ptr));
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d]->ep_comm_ptr = %p\n", idx, out_comm_hdls[idx]->ep_comm_ptr);
+#endif
+
+
+      out_comm_hdls[idx]->mpi_comm = parent_comm;
       out_comm_hdls[idx]->ep_comm_ptr->comm_list = out_comm_hdls;
       out_comm_hdls[idx]->ep_comm_ptr->comm_label = 0;
@@ -62,8 +83,17 @@
 
     out_comm_hdls[0]->ep_barrier = new ep_barrier(num_ep);
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->ep_barrier = %p\n", out_comm_hdls[0]->ep_barrier);
+#endif
+
     out_comm_hdls[0]->my_buffer = new BUFFER;
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->my_buffer = %p\n", out_comm_hdls[0]->my_buffer);
+#endif
 
     out_comm_hdls[0]->ep_rank_map = new EP_RANK_MAP;
-
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->ep_rank_map = %p\n", out_comm_hdls[0]->ep_rank_map);
+#endif
 
     for (int i = 1; i < num_ep; i++)
@@ -82,4 +112,8 @@
 
       out_comm_hdls[i]->ep_comm_ptr->message_queue = new Message_list;
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d]->ep_comm_ptr->message_queue = %p\n", i, out_comm_hdls[i]->ep_comm_ptr->message_queue);
+#endif
+
     }
 
@@ -91,5 +125,4 @@
       for(int j=0; j<recv_num_ep[i]; j++)
       {
-        //out_comm_hdls[0]->rank_map->at(ind) = make_pair(j, i);
         out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i));
         ind++;
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp	(revision 1517)
@@ -7,52 +7,52 @@
 {
 
+  int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm)
+  {
+    newcomm = new MPI_Comm;
+    (*newcomm)->is_ep = false;
+
+    ::MPI_Comm *output = new ::MPI_Comm;
+      
+    ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output);
+
+    (*newcomm)->mpi_comm = output;
+  }
+
+  int MPI_Comm_dup_intracomm(MPI_Comm comm, MPI_Comm *newcomm)
+  {
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep      = comm->ep_comm_ptr->size_rank_info[1].second;
+
+
+    if(0 == ep_rank_loc)
+    {
+      MPI_Info info;
+      MPI_Comm *out_comm;
+
+      MPI_Comm_create_endpoints(comm->mpi_comm, num_ep, info, out_comm);
+      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm;
+    }
+
+    MPI_Barrier_local(comm);
+
+    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[ep_rank_loc]);
+    
+  }
+
   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
   {
+    
     if(!comm->is_ep)
     {
-      Debug("Comm_dup MPI\n");
-      newcomm = new MPI_Comm;
-      (*newcomm)->is_ep = comm->is_ep;
-
-      ::MPI_Comm input = to_mpi_comm(comm->mpi_comm);
-      ::MPI_Comm *output = new ::MPI_Comm;
-
-      
-      ::MPI_Comm_dup(input, output);
-
-      (*newcomm)->mpi_comm = output;
-
-      return 0;
+      Debug("MPI_Comm_dup with MPI\n");
+      return MPI_Comm_dup_mpi(comm, newcomm); 
     }
 
     if(comm->is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm);
 
-    // for intracomm
-    if(comm->mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) return 0;
+    
+    return MPI_Comm_dup_intracomm(comm, newcomm); 
 
-
-    int my_rank = comm->ep_comm_ptr->size_rank_info[1].first;
-    int num_ep  = comm->ep_comm_ptr->size_rank_info[1].second;
-
-
-    if(0 == my_rank)
-    {
-      MPI_Info info;
-      MPI_Comm *out_comm;
-      ::MPI_Comm *mpi_dup = new ::MPI_Comm;
-
-      ::MPI_Comm in_comm = to_mpi_comm(comm->mpi_comm);
-
-      ::MPI_Comm_dup(in_comm, mpi_dup);
-
-      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
-      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm;
-    }
-
-    MPI_Barrier(comm);
-
-    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[my_rank]);
-
-    return MPI_SUCCESS;
+   
   }
 
@@ -60,78 +60,74 @@
   {
     
-    if(comm->mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm)) return 0;
-
-    int my_rank = comm->ep_comm_ptr->size_rank_info[1].first;
-    int num_ep  = comm->ep_comm_ptr->size_rank_info[1].second;
+    int newcomm_ep_rank =comm->ep_comm_ptr->intercomm->size_rank_info[0].first; 
+    int newcomm_ep_rank_loc = comm->ep_comm_ptr->intercomm->size_rank_info[1].first;
+    int newcomm_num_ep = comm->ep_comm_ptr->intercomm->size_rank_info[1].second;
 
 
-    if(0 == my_rank)
+    if(0 == newcomm_ep_rank_loc)
     {
+      //printf("in dup , newcomm_ep_rank_loc = 0 :  ep %d\n", comm->ep_comm_ptr->intercomm->size_rank_info[0].first);
+
       MPI_Info info;
       MPI_Comm *out_comm;
-      ::MPI_Comm *mpi_dup = new ::MPI_Comm;
 
-      ::MPI_Comm in_comm = to_mpi_comm(comm->mpi_comm);
+      MPI_Comm_create_endpoints(comm->mpi_comm, newcomm_num_ep, info, out_comm);
 
-      ::MPI_Comm_dup(in_comm, mpi_dup);
+      ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm;
+      ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter_comm);
 
-      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
+      for(int i=0; i<newcomm_num_ep; i++)
+      {
+        out_comm[i]->is_intercomm = true;
+        out_comm[i]->ep_comm_ptr->comm_label = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->comm_label;
+        out_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
+#ifdef _showinfo
+        printf("new out_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, out_comm[i]->ep_comm_ptr->intercomm);
+#endif
+        out_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm;      
+      }
 
-      ::MPI_Comm *mpi_inter = new ::MPI_Comm;
-
-      ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter);
-      
-      for(int i=0; i<num_ep; i++)
-      {
-        out_comm[i]->ep_comm_ptr->comm_label = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->comm_label;
-        out_comm[i]->ep_comm_ptr->intercomm = new ep_intercomm;
-
-        out_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter;
-        out_comm[i]->is_intercomm = true;
-
-        out_comm[i]->ep_comm_ptr->intercomm->inter_rank_map = new RANK_MAP;
-        out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map = new RANK_MAP;
-        out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
-
-        int map_size = 0;
-        map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->size();
-        out_comm[i]->ep_comm_ptr->intercomm->inter_rank_map->resize(map_size);
-        for(int ii=0; ii<map_size; ii++)
-          out_comm[i]->ep_comm_ptr->intercomm->intercomm_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->at(ii);
-
-        map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->size();
-        out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map->resize(map_size);
-        for(int ii=0; ii<map_size; ii++)
-          out_comm[i]->ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->at(ii);
-
-        map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map->size();
-        out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map->resize(map_size);
-        for(int ii=0; ii<map_size; ii++)
-          out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map->at(ii);
-
-
-        //out_comm[i]->ep_comm_ptr->intercomm->intercomm_rank_map = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map;
-        //out_comm[i]->ep_comm_ptr->intercomm->local_rank_map = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map;
-        //out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map;
-
-        //out_comm[i]->ep_comm_ptr->intercomm->local_comm = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_comm;        
-        out_comm[i]->ep_comm_ptr->intercomm->intercomm_tag = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_tag;
-
-        for(int j =0; j<3; j++)
-        {
-          out_comm[i]->ep_comm_ptr->intercomm->size_rank_info[j] = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->size_rank_info[j];
-        }
-
-      }
 
       comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm;
     }
 
-    MPI_Barrier(comm);
+    MPI_Barrier_local(comm);
 
-    *newcomm = comm->ep_comm_ptr->comm_list[0]->mem_bridge[my_rank];
+    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[newcomm_ep_rank_loc]);
+
+    (*newcomm)->ep_comm_ptr->size_rank_info[0] = comm->ep_comm_ptr->size_rank_info[0];
+    (*newcomm)->ep_comm_ptr->size_rank_info[1] = comm->ep_comm_ptr->size_rank_info[1];
+    (*newcomm)->ep_comm_ptr->size_rank_info[2] = comm->ep_comm_ptr->size_rank_info[2];
+
+    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[0] = comm->ep_comm_ptr->intercomm->size_rank_info[0];
+    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[1] = comm->ep_comm_ptr->intercomm->size_rank_info[1];
+    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[2] = comm->ep_comm_ptr->intercomm->size_rank_info[2];
+
+
+    int ep_rank_loc = (*newcomm)->ep_comm_ptr->size_rank_info[1].first;
+    
+    if(ep_rank_loc == 0)
+    {
+      //printf("in dup , ep_rank_loc = 0 :  ep %d\n", (*newcomm)->ep_comm_ptr->size_rank_info[0].first);
+      (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP;
+      (*newcomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP;
+
+      *(*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = *comm->ep_comm_ptr->intercomm->intercomm_rank_map;
+      *(*newcomm)->ep_comm_ptr->intercomm->local_rank_map = *comm->ep_comm_ptr->intercomm->local_rank_map;
+    }
+
+    MPI_Barrier_local(comm);
+
+    if(ep_rank_loc !=0 )
+    {
+      (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newcomm)->ep_comm_ptr->comm_list[0]->ep_comm_ptr->intercomm->intercomm_rank_map;
+      (*newcomm)->ep_comm_ptr->intercomm->local_rank_map = (*newcomm)->ep_comm_ptr->comm_list[0]->ep_comm_ptr->intercomm->local_rank_map;
+    }
+
     
 
-    return MPI_SUCCESS;
+
+
+    
   }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_finalize.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_finalize.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_finalize.cpp	(revision 1517)
@@ -22,12 +22,19 @@
   int MPI_Abort(MPI_Comm comm, int errorcode)
   {
-    int id = omp_get_thread_num();
+    if(!comm->is_ep)
+      return MPI_Abort_mpi(comm, errorcode);
 
-    if(id == 0)
+    else
     {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-      ::MPI_Abort(mpi_comm, errorcode);
+      if(comm->ep_comm_ptr->size_rank_info[1].first == 0)
+      {
+        ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode);
+      }
     }
-    return 0;
+  }
+
+  int MPI_Abort_mpi(MPI_Comm comm, int errorcode)
+  {
+    return ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode);
   }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp	(revision 1517)
@@ -11,159 +11,193 @@
     if(! (*comm)->is_ep)
     {
-      if((*comm)->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
-      {
-        ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->mpi_comm);
-
-        ::MPI_Comm_free(&mpi_comm);
-        Debug("comm is MPI, freed\n");
-      }
-      return 0;
-    }
-
-    else if((*comm)->is_intercomm)
-    {
-      return MPI_Comm_free_intercomm(comm);
-    }
-
-    else
-    {
-      int ep_rank_loc, num_ep;
-
-      ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
-      num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
-
-      MPI_Barrier(*comm);
-
-      if(ep_rank_loc == 0)
-      {
-        Debug("comm is EP, mpi_comm_ptr != NULL\n");
-
-        delete (*comm)->my_buffer;
-
-
-        if((*comm)->ep_barrier != NULL)
-        {
-          (*comm)->ep_barrier->~ep_barrier();
-          Debug("ep_barrier freed\n");
-        }
-
-
-        if( ! (*comm)->ep_rank_map->empty() )
-        {
-          (*comm)->ep_rank_map->clear();
-          delete (*comm)->ep_rank_map;
-          Debug("ep_rank_map emptied and freed\n");
-        }
-
-        for(int i=0; i<num_ep; i++)
-        {
-          (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
-          delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
-          Debug("message queue freed\n");
-          
-
-          if((*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr != NULL)
-          {
-            delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
-            Debug("ep_comm_ptr freed\n");
-          }
-        }
-
-        if( to_mpi_comm((*comm)->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm) 
-          && to_mpi_comm((*comm)->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_WORLD->mpi_comm))
-        {
-          ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->mpi_comm);
-          ::MPI_Comm_free(&mpi_comm);
-          Debug("mpi_comm freed\n");
-        }
-
-       //if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
-
-      }
-
-      return 0;
-    }
-
-
-
-  }
-
-  int MPI_Comm_free_intercomm(MPI_Comm *comm)
-  {
+      return MPI_Comm_free_mpi(comm);
+    }
+
+    else 
+    {
+      if((*comm)->is_intercomm)
+        return MPI_Comm_free_intercomm(comm);
+      else
+        return MPI_Comm_free_intracomm(comm);
+    }
+  }
+
+
+
+  int MPI_Comm_free_mpi(MPI_Comm *comm)
+  {
+    Debug("MPI_Comm_free with MPI\n");
+
+    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
+    
+  }
+
+  int MPI_Comm_free_intracomm(MPI_Comm *comm)
+  {
+    Debug("MPI_Comm_free with EP_intracomm\n");
+
     int ep_rank_loc, num_ep;
-    //MPI_Barrier(*comm);
-
-    return 0;
 
     ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
     num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
 
-
-
-    //MPI_Barrier(*comm);
+    MPI_Barrier(*comm);
 
     if(ep_rank_loc == 0)
     {
-      Debug("comm is EP, mpi_comm_ptr != NULL\n");
-
-
-      if((*comm)->ep_barrier != NULL)
-      {
-        (*comm)->ep_barrier->~ep_barrier();
-        Debug("ep_barrier freed\n");
-      }
-
-
-      if( ! (*comm)->ep_rank_map->empty() )
-      {
-        (*comm)->ep_rank_map->clear();
-        delete (*comm)->ep_rank_map;
-        Debug("ep_rank_map emptied and freed\n");
-      }
+
+#ifdef _showinfo
+      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
+#endif
+      delete (*comm)->my_buffer;
+
+
+      
+#ifdef _showinfo        
+      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
+#endif
+      delete (*comm)->ep_barrier;
+      
+
+
+      (*comm)->ep_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
+#endif
+      delete (*comm)->ep_rank_map;
+      
 
       for(int i=0; i<num_ep; i++)
       {
         (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
-        Debug("message queue freed\n");
-
-        #pragma omp critical (memory_free)
-        if((*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm != NULL)
-        {
-          (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->clear();
-          (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->remote_rank_map->clear();
-          (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->intercomm_rank_map->clear();
-          Debug("intercomm local/remote/intercomm_rank_map emptied\n");
-        }  
-
-        if((*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr != NULL)
-        {
-          delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
-          Debug("ep_comm_ptr freed\n");
-        }
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
+          
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
+
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i];
       }
 
-      if((*comm)->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
+#ifdef _showinfo
+      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
+#endif
+      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
+      
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
+#endif
+      delete[] (*comm)->ep_comm_ptr->comm_list;
+    }
+  }
+
+
+
+
+
+
+
+  int MPI_Comm_free_intercomm(MPI_Comm *comm)
+  {
+    int ep_rank;
+    MPI_Comm_rank(*comm, &ep_rank);
+    int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep =      (*comm)->ep_comm_ptr->size_rank_info[1].second;
+    
+    int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; 
+    int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first;
+    int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second;
+
+    MPI_Barrier(*comm);
+
+    if(ep_rank_loc == 0)
+    {
+      (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map);
+#endif
+      delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map;
+
+      (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map);
+#endif
+      delete (*comm)->ep_comm_ptr->intercomm->local_rank_map;
+    }
+
+    if(newcomm_ep_rank_loc == 0)
+    {
+
+#ifdef _showinfo
+      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
+#endif
+      delete (*comm)->my_buffer;
+
+
+      
+#ifdef _showinfo        
+      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
+#endif
+      delete (*comm)->ep_barrier;
+      
+
+      (*comm)->ep_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
+#endif
+      delete (*comm)->ep_rank_map;
+      
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm);
+#endif
+      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm));
+
+      for(int i=0; i<newcomm_num_ep; i++)
       {
-        ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->mpi_comm);
-        ::MPI_Comm_free(&mpi_comm);
-        Debug("mpi_comm freed\n");
+        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->intercomm = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm;        
+          
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
+
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i];
+
       }
 
-      if((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
-      {
-        ::MPI_Comm mpi_comm = to_mpi_comm((*comm)->ep_comm_ptr->comm_list[0]->ep_comm_ptr->intercomm->mpi_inter_comm);
-        ::MPI_Comm_free(&mpi_comm);
-        Debug("mpi_intercomm freed\n");
-      }
-
-     if(comm != NULL) {delete[] (*comm)->ep_comm_ptr->comm_list; Debug("comm freed\n");}
-
-    }
-
-    
-    
-    return 0;
-  }
-
+#ifdef _showinfo
+      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
+#endif
+      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
+      
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
+#endif
+      delete[] (*comm)->ep_comm_ptr->comm_list;
+    }
+  }
 
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_info.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_info.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_info.hpp	(revision 1517)
@@ -12,5 +12,5 @@
       void* mpi_info;
 
-      ep_info();
+      ep_info(){};
       ep_info(void* info);
   };
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_init.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_init.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_init.cpp	(revision 1517)
@@ -11,34 +11,27 @@
   int MPI_Init_thread(int *argc, char*** argv, int required, int*provided)
   {
-    //printf("MPI_Init_thread\n");
+    Debug("MPI_Init_thread with EP/MPI\n");
 
-    int id = omp_get_thread_num();
-
-    if(id == 0)
+    if(omp_get_thread_num() == 0)
     {
       ::MPI_Init_thread(argc, argv, required, provided);
     }
-    return 0;
   }
 
   int MPI_Init(int *argc, char ***argv)
   {
-    //printf("MPI_init called\n");
-    int id = omp_get_thread_num();
+    Debug("MPI_Init with EP/MPI\n");
 
-    if(id == 0)
+    if(omp_get_thread_num() == 0)
     {
       ::MPI_Init(argc, argv);
     }
-  	return 0;
   }
 
   int MPI_Initialized(int *flag)
   {
-    //printf("MPI_initialized called\n");
+    Debug("MPI_Initialized with EP/MPI\n");
 
-    ::MPI_Initialized(flag);
-    
-    return 0;
+    return ::MPI_Initialized(flag);
   }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp	(revision 1517)
@@ -24,19 +24,13 @@
 
 
-    RANK_MAP *inter_rank_map;
+    RANK_MAP *inter_rank_map;  
     RANK_MAP *loc_rank_map;
     RANK_MAP *remote_rank_map;
 
 
-    SIZE_RANK_INFO size_rank_info[3];
+    SIZE_RANK_INFO size_rank_info[3];        // size_rank_info of newcomm
 
 
-    //ep_comm *local_comm;
     int intercomm_tag;
-
-    ep_intercomm();
-    //~ep_intercomm(){delete mpi_inter_comm;}
-    bool operator == (ep_intercomm right);
-    bool operator != (ep_intercomm right);
     
   };
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp	(revision 1517)
@@ -353,4 +353,8 @@
         MPI_Info info;
         MPI_Comm_create_endpoints(extracted_comm, num_ep_count, info, ep_comm);
+      
+#ifdef _showinfo
+        printf("new ep_comm->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", mpi_inter_comm);
+#endif
 
         for(int i=0; i<num_ep_count; i++)
@@ -359,5 +363,9 @@
           ep_comm[i]->ep_comm_ptr->comm_label = ranks_in_world_local[local_leader];
           ep_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
+#ifdef _showinfo
+          printf("new ep_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, ep_comm[i]->ep_comm_ptr->intercomm);
+#endif
           ep_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm;
+          
         }
 
@@ -496,4 +504,7 @@
       ::MPI_Bcast(remote_quadruple_list, 4*remote_ep_size, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));
       (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP;
+#ifdef _showinfo
+      printf("new intercomm_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map);
+#endif
       for(int i=0; i<remote_ep_size; i++)
       {
@@ -522,6 +533,12 @@
     if(is_involved)
     {
-      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP[ep_size];
-      *((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map) = *(local_comm->ep_rank_map);
+
+      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP;
+      printf("new local_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map);
+
+      for(std::map<int, std::pair<int, int> >::iterator it = local_comm->ep_rank_map->begin(); it != local_comm->ep_rank_map->end(); it++)
+      {
+        (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->insert(std::pair<int, std::pair< int, int > >(it->first, it->second.first, it->second.second));
+      }
     }
 
@@ -541,11 +558,31 @@
       }
       (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map;
-      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map;
-    }
-
-    (*newintercomm)->ep_comm_ptr->size_rank_info[0]=local_comm->ep_comm_ptr->size_rank_info[0];
-    (*newintercomm)->ep_comm_ptr->size_rank_info[1]=local_comm->ep_comm_ptr->size_rank_info[1];
-    (*newintercomm)->ep_comm_ptr->size_rank_info[2]=local_comm->ep_comm_ptr->size_rank_info[2];
-    
+      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map     = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map;
+    }
+
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = (*newintercomm)->ep_comm_ptr->size_rank_info[0];
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1];
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2];
+
+
+    (*newintercomm)->ep_comm_ptr->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
+    (*newintercomm)->ep_comm_ptr->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
+    (*newintercomm)->ep_comm_ptr->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
+
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+    printf("peer_rank = %d, size_rank_info = %d %d %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, 
+      (*newintercomm)->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].second,
+      (*newintercomm)->ep_comm_ptr->size_rank_info[1].first, (*newintercomm)->ep_comm_ptr->size_rank_info[1].second,
+      (*newintercomm)->ep_comm_ptr->size_rank_info[2].first, (*newintercomm)->ep_comm_ptr->size_rank_info[2].second);
+    
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
 /*
     if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5)
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1517)
@@ -4,4 +4,5 @@
 #include <iostream>
 #include <fstream>
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -14,11 +15,4 @@
 namespace ep_lib
 { 
-  bool ep_comm::is_null()
-  {
-    if(!this->is_intercomm)
-      return this->mpi_comm == MPI_COMM_NULL->mpi_comm;
-    else
-      return this->ep_comm_ptr->intercomm->mpi_inter_comm == MPI_COMM_NULL->mpi_comm;
-  }
 
   int tag_combine(int real_tag, int src, int dest)
@@ -47,9 +41,5 @@
   int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count)
   {
-
-    ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status);
-    ::MPI_Datatype *mpi_datatype = static_cast< ::MPI_Datatype*>(datatype);
-
-    ::MPI_Get_count(mpi_status, *mpi_datatype, count);
+    return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count);
   }
 
@@ -227,4 +217,9 @@
 {
   return *(static_cast< MPI_Comm* >(comm));
+} 
+
+MPI_Comm* to_mpi_comm_ptr(void* comm)
+{
+  return static_cast< MPI_Comm* >(comm);
 }  
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1517)
@@ -4,4 +4,5 @@
 #include "ep_type.hpp"
 #include "ep_lib_intercomm.hpp"
+#include "ep_lib_intracomm.hpp"
 #include "ep_lib_local.hpp"
 #include "ep_lib_collective.hpp"
@@ -10,4 +11,5 @@
 #include "ep_lib_win.hpp"
 #include "ep_lib_mpi.hpp"
+//#include "ep_mpi.hpp"
 
 
@@ -28,5 +30,4 @@
 
   int MPI_Comm_free(MPI_Comm* comm);
-  int MPI_Comm_free_intracomm(MPI_Comm* comm);
 
   int MPI_Finalize();
@@ -37,12 +38,6 @@
 
   int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count);
-
-  // #ifdef _openmpi
-  // int MPI_Comm_create_endpoints(void* mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints
-  // #elif _intelmpi
-  // int MPI_Comm_create_endpoints(int mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints
-  // #endif
   
-  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints
+  int MPI_Comm_remote_size(MPI_Comm comm, int *size);
 
   int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
@@ -51,10 +46,4 @@
   int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
 
-  int tag_combine(int real_tag, int src, int dest);
-  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
-
-  int Message_Check(MPI_Comm comm);
-  int Message_Check_intracomm(MPI_Comm comm);
-  int Request_Check();
 
   int MPI_Recv  (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status);
@@ -78,4 +67,6 @@
   int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr);
 
+  int MPI_Comm_test_inter(MPI_Comm comm, int *flag);
+
 
   void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type);
@@ -85,4 +76,14 @@
   bool valid_op(MPI_Op op);
 
+  int tag_combine(int real_tag, int src, int dest);
+  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
+
+  int Message_Check(MPI_Comm comm);
+
+  int Request_Check();
+
+  int test_sendrecv(MPI_Comm comm);
+
+
 }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_collective.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_collective.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_collective.hpp	(revision 1517)
@@ -10,4 +10,5 @@
 
   int MPI_Barrier(MPI_Comm comm);
+  
 
   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm);
@@ -26,4 +27,5 @@
 
   int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
+  
   int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
 
@@ -41,4 +43,23 @@
   int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
 
+  int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);
+
+  int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+
+  int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+  
+  
+  int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
+  
+  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+
+  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints
+
+
+
+  int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
+
+  int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
+
 }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intercomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intercomm.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intercomm.hpp	(revision 1517)
@@ -8,5 +8,11 @@
   typedef void* MPI_Op;
 
-  
+  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
+  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
+  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
+
+  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
+
+
   int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm);
 
@@ -22,33 +28,8 @@
 
   int MPI_Iprobe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status);
-  int MPI_Iprobe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Status *status);
   int MPI_Improbe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);
-  int MPI_Improbe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);
 
-  int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);
 
-  int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
 
-  int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
-  
-  // #ifdef _intelmpi
-  // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, int peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
-  // #elif _openmpi
-  // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
-  // #endif
-
-  int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
-  
-  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
-
-  int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
-
-  int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
-
-  int MPI_Comm_remote_size(MPI_Comm comm, int *size);
-
-  int MPI_Comm_test_inter(MPI_Comm comm, int *flag);
-
-  int test_sendrecv(MPI_Comm comm);
 
 }
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intracomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intracomm.hpp	(revision 1517)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intracomm.hpp	(revision 1517)
@@ -0,0 +1,21 @@
+#ifndef EP_LIB_INTRACOMM_HPP_INCLUDED
+#define EP_LIB_INTRACOMM_HPP_INCLUDED
+
+namespace ep_lib
+{
+
+  typedef void* MPI_Datatype;
+  typedef void* MPI_Op;
+
+
+  int MPI_Barrier_intracomm(MPI_Comm comm);
+
+  int MPI_Comm_free_intracomm(MPI_Comm* comm);
+
+  int Message_Check_intracomm(MPI_Comm comm);
+  
+  int MPI_Comm_dup_intracomm(MPI_Comm comm, MPI_Comm *newcomm);
+
+}
+
+#endif // EP_LIB_INTRACOMM_HPP_INCLUDED
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp	(revision 1517)
@@ -10,19 +10,12 @@
 
   int MPI_Send_mpi      (void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
-  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
-  
   int MPI_Ssend_mpi      (void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
-  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
-  
   int MPI_Isend_mpi      (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
-  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
-  
   int MPI_Issend_mpi      (const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
-  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
   
   
   int MPI_Recv_mpi      (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status);
-  
   int MPI_Irecv_mpi      (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request);
+
 
   int MPI_Comm_rank_mpi(MPI_Comm comm, int* rank);
@@ -30,4 +23,10 @@
   int MPI_Comm_remote_size_mpi(MPI_Comm comm, int* size);
 
+  int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm);
+  int MPI_Comm_free_mpi(MPI_Comm *comm);
+
+  int MPI_Barrier_mpi(MPI_Comm comm);
+  
+  int MPI_Abort_mpi(MPI_Comm comm, int errorcode);
 }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp	(revision 1517)
@@ -61,5 +61,5 @@
         if(probed)
         {
-          ::MPI_Get_count(to_mpi_status_ptr(status), to_mpi_type((*(*it))->ep_datatype), &recv_count);
+          MPI_Get_count(&status, (*(*it))->ep_datatype, &recv_count);
           
           MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it);
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.hpp	(revision 1517)
@@ -15,6 +15,4 @@
       void* mpi_status;
 
-      ep_message() {}
-      ep_message(void* message);
   };
   
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_mpi.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_mpi.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_mpi.hpp	(revision 1517)
@@ -7,4 +7,5 @@
 MPI_Op       to_mpi_op(ep_lib::MPI_Op op);
 MPI_Comm     to_mpi_comm(void* comm);
+MPI_Comm*    to_mpi_comm_ptr(void* comm);
 MPI_Message  to_mpi_message(void* message);
 MPI_Info     to_mpi_info(ep_lib::MPI_Info info);
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_request.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_request.hpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_request.hpp	(revision 1517)
@@ -34,5 +34,4 @@
       ep_request() {}
       ep_request(void* request);
-      bool operator == (ep_request right);
   };
   
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_type.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_type.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_type.cpp	(revision 1517)
@@ -11,71 +11,27 @@
 namespace ep_lib
 { 
-  
-  ep_intercomm::ep_intercomm()
+  ep_comm::ep_comm(void* comm)
   {
-    intercomm_rank_map = NULL;
-    local_rank_map = NULL;
-    remote_rank_map = NULL;
-    mpi_inter_comm = new ::MPI_Comm;
-  }
-
-  bool ep_intercomm::operator == (ep_intercomm right)
-  {
-    bool a = intercomm_rank_map == right.intercomm_rank_map;
-    bool b = local_rank_map == right.local_rank_map;
-    bool c = remote_rank_map == right.remote_rank_map;
-    bool d = *(static_cast< ::MPI_Comm*>(mpi_inter_comm)) == *(static_cast< ::MPI_Comm*>(right.mpi_inter_comm));
-    bool e = size_rank_info == right.size_rank_info;
-    bool f = intercomm_tag == right.intercomm_tag;
-    return a&&b&&c&&d&&e&&f;
-  }
-
-  bool ep_intercomm::operator != (ep_intercomm right)
-  {
-    bool a = intercomm_rank_map != right.intercomm_rank_map;
-    bool b = local_rank_map != right.local_rank_map;
-    bool c = remote_rank_map != right.remote_rank_map;
-    bool d = *(static_cast< ::MPI_Comm*>(mpi_inter_comm)) != *(static_cast< ::MPI_Comm*>(right.mpi_inter_comm));
-    bool e = size_rank_info != right.size_rank_info;
-    bool f = intercomm_tag != right.intercomm_tag;
-    return a||b||c||d||e||f;
-  }
-
-  ep_communicator::ep_communicator()
-  {
-    comm_list = NULL;
-    message_queue = NULL;
-    intercomm = NULL;
-  }
-
-  ep_message::ep_message(void* message)
-  {
-    mpi_message = new ::MPI_Message;
-    *(static_cast< ::MPI_Message*>(mpi_message)) = *(static_cast< ::MPI_Message*>(message));
+    is_ep = false;
+    is_intercomm = false;
+    mpi_comm = static_cast< ::MPI_Comm*>(comm);
   }
 
   ep_info::ep_info(void* info)
   {
-    mpi_info = new ::MPI_Info;
-    *(static_cast< ::MPI_Info*>(mpi_info)) = *(static_cast< ::MPI_Info*>(info));
+    mpi_info = static_cast< ::MPI_Info*>(info);
   }
-  
-  ep_info::ep_info()
-  {
-    mpi_info = new ::MPI_Info;
-    *(static_cast< ::MPI_Info*>(mpi_info)) = *(static_cast< ::MPI_Info*>(MPI_INFO_NULL->mpi_info));
-  }
-  
+
   ep_request::ep_request(void* request)
   {
-    mpi_request = new ::MPI_Request;
-    *(static_cast< ::MPI_Request*>(mpi_request)) = *static_cast< ::MPI_Request*>(request);
+    mpi_request = static_cast< ::MPI_Request*>(request);
   }
   
   ep_status::ep_status(void* status)
   {
-    mpi_status = new ::MPI_Status;
-    *(static_cast< ::MPI_Status*>(mpi_status)) = *static_cast< ::MPI_Status*>(status);
+    mpi_status = static_cast< ::MPI_Status*>(status);
   }
+
+  /*
   
   MPI_Aint::MPI_Aint(void* aint)
@@ -103,78 +59,7 @@
   }
 
-  bool ep_communicator::operator == (ep_communicator right)
-  {
-    bool a = size_rank_info == right.size_rank_info;
-    bool b = comm_label == right.comm_label;
-    bool c = intercomm == right.intercomm;
-    return a&&b&&c;
-  }
-
-  bool ep_communicator::operator != (ep_communicator right)
-  {
-    bool a = size_rank_info != right.size_rank_info;
-    bool b = comm_label != right.comm_label;
-    bool c = intercomm != right.intercomm;
-    return a||b||c;
-  }
-
-  ep_comm::ep_comm()
-  {
-    is_ep = true;
-    is_intercomm = false;
-    my_buffer = NULL;
-    ep_barrier = NULL;
-    ep_rank_map = NULL;
-    ep_comm_ptr = NULL;
-    mem_bridge = NULL;
-    mpi_bridge = NULL;
-    mpi_comm = new ::MPI_Comm;
-  }
-
   
-
-  ep_comm::ep_comm(void* comm)
-  {
-    is_ep = false;
-    is_intercomm = false;
-    my_buffer = NULL;
-    ep_barrier = NULL;
-    ep_rank_map = NULL;
-    ep_comm_ptr = NULL;
-    mem_bridge = NULL;
-    mpi_bridge = NULL;
-    mpi_comm = new ::MPI_Comm;
-    *(static_cast< ::MPI_Comm*>(mpi_comm)) = *(static_cast< ::MPI_Comm*>(comm));
-  }
-
+*/
   
-
-  bool ep_comm::operator == (ep_comm right)
-  {
-    bool a = is_ep == right.is_ep;
-    bool b = is_intercomm == right.is_intercomm;
-    bool c = *(static_cast< ::MPI_Comm*>(mpi_comm)) == *(static_cast< ::MPI_Comm*>(right.mpi_comm));
-    bool d = is_ep ? ep_comm_ptr == right.ep_comm_ptr : true;
-    return a&&b&&c&&d;
-  }
-
-  bool ep_comm::operator != (ep_comm right)
-  {
-    bool a = is_ep != right.is_ep;
-    bool b = is_intercomm != right.is_intercomm;
-    bool c = *(static_cast< ::MPI_Comm*>(mpi_comm)) != *(static_cast< ::MPI_Comm*>(right.mpi_comm));
-    bool d = is_ep ? ep_comm_ptr != right.ep_comm_ptr : true;
-    return a||b||c||d;
-  }
-
-  bool ep_request::operator == (ep_request right)
-  {
-    bool b = type == right.type;
-    bool c = buf == right.buf;
-    bool d = ep_src == right.ep_src;
-    bool e = ep_tag == right.ep_tag;
-    bool f = ep_datatype == right.ep_datatype;
-    return b&&c&&d&&e&&f;
-  }
 
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/main.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1516)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1517)
@@ -19,5 +19,5 @@
   srand (time(NULL));
 
-  printf("Testing ep_lib\n");
+  //printf("Testing ep_lib\n");
   int required=3, provided;
 
@@ -32,4 +32,6 @@
   MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
  
+  
+
   #pragma omp parallel default(shared)
   {
@@ -858,7 +860,22 @@
       MPI_Comm_free(&split_comm);
 
-      MPI_Barrier(comm);
-      MPI_Barrier(comm);
-
+
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+
+      MPI_Comm inter_comm_dup;
+      MPI_Comm_dup(inter_comm, &inter_comm_dup);
+
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+
+
+      MPI_Comm_free(&inter_comm_dup);
+
+
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+
+      MPI_Barrier(inter_comm);
       MPI_Comm_free(&inter_comm);
       
