Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp	(revision 1539)
@@ -43,8 +43,7 @@
   {
 
-    if(!comm->is_ep && comm->mpi_comm)
-    {
-      return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Allgather_intercomm(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
+
 
     assert(sendcount == recvcount);
@@ -119,7 +118,4 @@
     MPI_Bcast_local(recvbuf, count*ep_size, datatype, 0, comm);
 
-    MPI_Barrier(comm);
-
-
     if(is_master)
     {
@@ -131,4 +127,9 @@
   }
 
+  int MPI_Allgather_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
+  {
+    printf("MPI_Allgather_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
 
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp	(revision 1539)
@@ -20,10 +20,6 @@
   {
 
-    if(!comm->is_ep && comm->mpi_comm)
-    {
-      return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
-    }
-
-    if(!comm->mpi_comm) return 0;
+    if(!comm->is_ep) return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Allgatherv_intercomm(sendbuf, sendcount, sendtype, recvbuf, recvcounts, displs, recvtype, comm);
 
 
@@ -114,9 +110,13 @@
       delete[] tmp_recvbuf;
     }
-
-
   }
 
 
+  int MPI_Allgatherv_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int recvcounts[], const int displs[], MPI_Datatype recvtype, MPI_Comm comm)
+  {
+    printf("MPI_Allgatherv_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
 
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allocate.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allocate.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allocate.cpp	(revision 1539)
@@ -12,5 +12,4 @@
   {
     ::MPI_Alloc_mem(to_mpi_aint(size), to_mpi_info(info), baseptr);
-    //::MPI_Alloc_mem(size.mpi_aint, MPI_INFO_NULL_STD, baseptr);
     return 0;
    }
@@ -19,5 +18,4 @@
   {
     ::MPI_Alloc_mem(size, *(static_cast< ::MPI_Info*>(info->mpi_info)), baseptr);
-    //::MPI_Alloc_mem(size, MPI_INFO_NULL_STD, baseptr);
     return 0;
   }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp	(revision 1539)
@@ -17,13 +17,8 @@
  {
 
-
-
   int MPI_Allreduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
   {
-    if(!comm->is_ep && comm->mpi_comm)
-    {
-      return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
-    }
-
+    if(!comm->is_ep) return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Allreduce_intercomm(sendbuf, recvbuf, count, datatype, op, comm);
 
 
@@ -66,8 +61,12 @@
     }
 
-    MPI_Barrier_local(comm);
   }
 
-  
+
+  int MPI_Allreduce_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+  {
+    printf("MPI_Allreduce_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
 
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp	(revision 1539)
@@ -9,8 +9,6 @@
   int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Alltoall_intercomm(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, comm);
 
 
@@ -55,10 +53,12 @@
       delete[] tmp_sendbuf;
     }
-    
-    MPI_Barrier(comm);
-
-    return 0;
   }
 
+
+  int MPI_Alltoall_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
+  {
+    printf("MPI_Alltoall_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
 }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp	(revision 1539)
@@ -9,9 +9,8 @@
   int MPI_Barrier(MPI_Comm comm)
   {
-    if(comm->is_intercomm) return MPI_Barrier_intercomm(comm);
 
     if(comm->is_ep) 
     {
-      return MPI_Barrier_intracomm(comm);
+      return MPI_Barrier_endpoint(comm);
     }
 
@@ -21,5 +20,5 @@
   }
 
-  int MPI_Barrier_intracomm(MPI_Comm comm)
+  int MPI_Barrier_endpoint(MPI_Comm comm)
   {
     int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
@@ -35,17 +34,6 @@
 
     MPI_Barrier_local(comm);
-
-    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)
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp	(revision 1539)
@@ -45,10 +45,6 @@
   {
 
-    if(!comm->is_ep)
-    {
-      #pragma omp single nowait
-      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm));
-      return 0;
-    }
+    if(!comm->is_ep) return ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Bcast_intercomm(buffer, count, datatype, root, comm);
 
 
@@ -59,4 +55,6 @@
     int root_mpi_rank = comm->ep_rank_map->at(root).second;
     int root_ep_rank_loc = comm->ep_rank_map->at(root).first;
+
+    //printf("ep_rank = %d, root_mpi_rank = %d, root_ep_rank_loc = %d\n", ep_rank, root_mpi_rank, root_ep_rank_loc);
 
 
@@ -69,9 +67,12 @@
     else                          MPI_Bcast_local(buffer, count, datatype, 0, comm);
 
-    return 0;
   }
 
 
-
+  int MPI_Bcast_intercomm(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm)
+  {
+    printf("MPI_Bcast_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
 
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_comm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_comm.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_comm.hpp	(revision 1539)
@@ -3,5 +3,4 @@
 
 #include "ep_message.hpp"
-#include "ep_intercomm.hpp"
 #include "ep_barrier.hpp"
 #include "ep_buffer.hpp"
@@ -10,6 +9,6 @@
 typedef std::vector< std::pair<int, int> > RANK_MAP;  // at(ep_rank) = <ep_rank_local, mpi_rank>
 typedef std::map<int, std::pair<int, int> > EP_RANK_MAP;  // key(ep_rank) = <ep_rank_local, mpi_rank>
-//typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP;
 typedef std::list<ep_lib::MPI_Message > Message_list;
+typedef std::map<int, int > INTER_RANK_MAP;
 
 namespace ep_lib
@@ -26,16 +25,8 @@
                                       // 2: mpi_rank,    mpi_size
 
-                                      // for intercomm : = size_rank_info of local_comm
-
-
     ep_comm **comm_list;
 
     Message_list *message_queue;
 
-
-    int comm_label;
-
-    ep_intercomm *intercomm;
-    
   };
   
@@ -52,7 +43,7 @@
     ep_barrier *ep_barrier;
 
-    EP_RANK_MAP   *ep_rank_map;      // for intercomm : = ep_rank_map of newcomm
+    EP_RANK_MAP   *ep_rank_map;
     
-
+    INTER_RANK_MAP *inter_rank_map;
 
     void* mpi_comm;
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1539)
@@ -71,5 +71,4 @@
       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;
     }
 
@@ -130,6 +129,4 @@
     }
 
-    return 0;
-
   } //MPI_Comm_create_endpoints
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1539)
@@ -7,17 +7,21 @@
 {
 
-  int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm)
+  
+  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
   {
-    newcomm = new MPI_Comm;
-    (*newcomm)->is_ep = false;
+    
+    if(!comm->is_ep)
+    {
+      Debug("MPI_Comm_dup with MPI\n");
+      return MPI_Comm_dup_mpi(comm, newcomm); 
+    }
 
-    ::MPI_Comm *output = new ::MPI_Comm;
-      
-    ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output);
-
-    (*newcomm)->mpi_comm = output;
+    return MPI_Comm_dup_endpoint(comm, newcomm); 
+   
   }
 
-  int MPI_Comm_dup_intracomm(MPI_Comm comm, MPI_Comm *newcomm)
+
+  
+  int MPI_Comm_dup_endpoint(MPI_Comm comm, MPI_Comm *newcomm)
   {
     int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
@@ -37,102 +41,30 @@
 
     *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[ep_rank_loc]);
+
+    if(comm->is_intercomm)
+    {
+      (*newcomm)->is_intercomm = true;
+      (*newcomm)->ep_comm_ptr->size_rank_info[0] = comm->ep_comm_ptr->size_rank_info[0];
+      (*newcomm)->inter_rank_map = new INTER_RANK_MAP;
+
+      for(INTER_RANK_MAP::iterator it = comm->inter_rank_map->begin(); it !=comm->inter_rank_map->end(); it++)
+      {
+        (*newcomm)->inter_rank_map->insert(std::make_pair(it->first, it->second));
+      }
+
+    }
     
   }
 
-  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
+  int MPI_Comm_dup_mpi(MPI_Comm comm, MPI_Comm *newcomm)
   {
-    
-    if(!comm->is_ep)
-    {
-      Debug("MPI_Comm_dup with MPI\n");
-      return MPI_Comm_dup_mpi(comm, newcomm); 
-    }
+    newcomm = new MPI_Comm;
+    (*newcomm)->is_ep = false;
 
-    if(comm->is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm);
+    ::MPI_Comm *output = new ::MPI_Comm;
+      
+    ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output);
 
-    
-    return MPI_Comm_dup_intracomm(comm, newcomm); 
-
-   
-  }
-
-  int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm)
-  {
-    
-    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 == 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_create_endpoints(comm->mpi_comm, newcomm_num_ep, info, out_comm);
-
-      ::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);
-
-      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;
-      }
-
-
-      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[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];
-
-    (*newcomm)->ep_comm_ptr->intercomm->intercomm_tag = comm->ep_comm_ptr->intercomm->intercomm_tag;
-
-
-    int ep_rank_loc = (*newcomm)->ep_comm_ptr->size_rank_info[1].first;
-    
-    if(ep_rank_loc == 0)
-    {
-      int world_rank;
-      MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
-
-      (*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 )
-    {
-      int target = (*newcomm)->ep_comm_ptr->intercomm->intercomm_tag;
-      (*newcomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newcomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map; 
-      (*newcomm)->ep_comm_ptr->intercomm->local_rank_map     = (*newcomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map;
-    }
-
-    
-
-
-
-    
+    (*newcomm)->mpi_comm = output;
   }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp	(revision 1539)
@@ -228,8 +228,6 @@
   int MPI_Exscan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Exscan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Exscan_intercomm(sendbuf, recvbuf, count, datatype, op, comm);
     
     valid_type(datatype);
@@ -291,12 +289,9 @@
 
     if(ep_rank_loc == 0)
+    {
       ::MPI_Exscan(MPI_IN_PLACE, tmp_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
-
-    // printf(" ID=%d : %d  %d \n", ep_rank, static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]);
+    }
     
     MPI_Exscan_local(tmp_sendbuf, tmp_recvbuf, count, datatype, op, comm);
-
-     // printf(" ID=%d : after local tmp_sendbuf = %d %d ; tmp_recvbuf = %d  %d \n", ep_rank, static_cast<int*>(tmp_sendbuf)[0], static_cast<int*>(tmp_sendbuf)[1], static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1]);
-
 
 
@@ -314,7 +309,4 @@
 
     else memcpy(recvbuf, tmp_recvbuf, datasize*count);
-    
-
-
 
     delete[] tmp_sendbuf;
@@ -323,3 +315,10 @@
   }
 
+
+  int MPI_Exscan_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+  {
+    printf("MPI_Exscan_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp	(revision 1539)
@@ -9,30 +9,12 @@
   int MPI_Finalize()
   {
-    printf("calling EP Finalize\n");
-
-    int id = omp_get_thread_num();
-
-    if(id == 0)
+    #pragma omp master
     {
+      printf("calling EP Finalize\n");
       ::MPI_Finalize();
     }
-    return 0;
   }
 
   int MPI_Abort(MPI_Comm comm, int errorcode)
-  {
-    if(!comm->is_ep)
-      return MPI_Abort_mpi(comm, errorcode);
-
-    else
-    {
-      if(comm->ep_comm_ptr->size_rank_info[1].first == 0)
-      {
-        ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode);
-      }
-    }
-  }
-
-  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/src_ep_dev/ep_free.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1539)
@@ -9,16 +9,6 @@
   int MPI_Comm_free(MPI_Comm *comm)
   {
-    if(! (*comm)->is_ep)
-    {
-      return MPI_Comm_free_mpi(comm);
-    }
-
-    else 
-    {
-      if((*comm)->is_intercomm)
-        return MPI_Comm_free_intercomm(comm);
-      else
-        return MPI_Comm_free_intracomm(comm);
-    }
+    if(! (*comm)->is_ep) return MPI_Comm_free_mpi(comm);
+    else return MPI_Comm_free_endpoint(comm);
   }
 
@@ -28,10 +18,8 @@
   {
     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)
+  int MPI_Comm_free_endpoint(MPI_Comm *comm)
   {
     Debug("MPI_Comm_free with EP_intracomm\n");
@@ -42,8 +30,22 @@
     num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
 
-    MPI_Barrier(*comm);
+    MPI_Barrier_local(*comm);
 
     if(ep_rank_loc == 0)
     {
+
+      if((*comm)->is_intercomm)
+      {
+        for(int i=0; i<num_ep; i++)
+        {
+          (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map->clear();
+#ifdef _showinfo
+          printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->inter_rank_map = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map);
+#endif
+          delete (*comm)->ep_comm_ptr->comm_list[i]->inter_rank_map;
+        }
+      }
+
+
 
 #ifdef _showinfo
@@ -103,104 +105,4 @@
 
 
-
-
-
-
-  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;
-
-    return 0;
-    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++)
-      {
-        (*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];
-
-      }
-
-#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/src_ep_dev/ep_gather.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gather.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gather.cpp	(revision 1539)
@@ -35,6 +35,4 @@
       for(int i=0; i<num_ep; i++)
         memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count);
-
-      //printf("local_recvbuf = %d %d \n", static_cast<int*>(recvbuf)[0], static_cast<int*>(recvbuf)[1] );
     }
 
@@ -44,9 +42,7 @@
   int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Gather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype),
-                   root, to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Gather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype),
+                                         root, to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Gather_intercomm(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
 
     assert(sendcount == recvcount && sendtype == recvtype);
@@ -103,9 +99,4 @@
     if(is_root)
     {
-      // printf("tmp_recvbuf = %d %d %d %d %d %d %d %d\n", static_cast<int*>(tmp_recvbuf)[0], static_cast<int*>(tmp_recvbuf)[1],
-      //                                                   static_cast<int*>(tmp_recvbuf)[2], static_cast<int*>(tmp_recvbuf)[3],
-      //                                                   static_cast<int*>(tmp_recvbuf)[4], static_cast<int*>(tmp_recvbuf)[5],
-      //                                                   static_cast<int*>(tmp_recvbuf)[6], static_cast<int*>(tmp_recvbuf)[7] );
-
       int offset;
       for(int i=0; i<ep_size; i++)
@@ -128,3 +119,9 @@
   }
 
+
+  int MPI_Gather_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
+  {
+    printf("MPI_Gather_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp	(revision 1539)
@@ -46,10 +46,7 @@
   {
   
-    if(!comm->is_ep)
-    {
-      return ::MPI_Gatherv(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, const_cast<int*>(input_recvcounts), const_cast<int*>(input_displs),
-                    to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
-    }
-
+    if(!comm->is_ep) return ::MPI_Gatherv(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, const_cast<int*>(input_recvcounts), const_cast<int*>(input_displs),
+                                          to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Gatherv_intercomm(sendbuf, sendcount, sendtype, recvbuf, input_recvcounts, input_displs, recvtype, root, comm);
 
     assert(sendtype == recvtype);
@@ -169,3 +166,10 @@
   }
 
+  int MPI_Gatherv_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int input_recvcounts[], const int input_displs[],
+                            MPI_Datatype recvtype, int root, MPI_Comm comm)
+  {
+    printf("MPI_Gatherv_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp	(revision 1539)
@@ -2,5 +2,7 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
+extern MPI_Group MPI_GROUP_WORLD;
 
 namespace ep_lib
@@ -13,7 +15,8 @@
     Debug("MPI_Init_thread with EP/MPI\n");
 
-    if(omp_get_thread_num() == 0)
+    #pragma omp master
     {
       ::MPI_Init_thread(argc, argv, required, provided);
+      ::MPI_Comm_group(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &MPI_GROUP_WORLD);
     }
   }
@@ -23,13 +26,8 @@
     Debug("MPI_Init with EP/MPI\n");
 
-    if(omp_get_thread_num() == 0)
+    #pragma omp master
     {
       ::MPI_Init(argc, argv);
     }
-  }
-  
-  int EP_group_init()
-  {
-  
   }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp	(revision 1539)
@@ -6,231 +6,544 @@
 using namespace std;
 
+extern std::map<std::pair<int, int>, MPI_Group* > * tag_group_map;
+
+extern std::map<int, std::pair<ep_lib::MPI_Comm*, std::pair<int, int> > > * tag_comm_map;
+
+extern MPI_Group MPI_GROUP_WORLD;
+
 namespace ep_lib
 {
+
   int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
   {
-    assert(local_comm->is_ep);
-
+    if(!local_comm->is_ep) return MPI_Intercomm_create_mpi(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
+
+    int ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
+    
+    
+    // check if local leaders are in the same mpi proc
+    // by checking their mpi_rank in peer_comm
+    
+    int mpi_rank_of_leader[2];
+    
+    if(ep_rank == local_leader)
+    {
+      mpi_rank_of_leader[0] = peer_comm->ep_comm_ptr->size_rank_info[2].first;
+      mpi_rank_of_leader[1] = peer_comm->ep_rank_map->at(remote_leader).second;      
+    }
+    
+    MPI_Bcast(mpi_rank_of_leader, 2, MPI_INT, local_leader, local_comm);
+    
+    if(mpi_rank_of_leader[0] != mpi_rank_of_leader[1])
+    {
+      Debug("calling MPI_Intercomm_create_kernel\n");
+      return MPI_Intercomm_create_endpoint(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
+    }
+    else
+    {
+      printf("local leaders are in the same MPI proc. Routine not yet implemented\n");
+      MPI_Abort(local_comm, 0);
+    }
+  }
+  
+  
+  
+  int MPI_Intercomm_create_endpoint(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
+  {
     int ep_rank, ep_rank_loc, mpi_rank;
     int ep_size, num_ep, mpi_size;
 
-    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
+    ep_rank     = local_comm->ep_comm_ptr->size_rank_info[0].first;
     ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-
-    MPI_Barrier(local_comm);
-
-    int leader_ranks_in_peer[3];  // local_leader_rank_in_peer
-                                  // remote_leader_rank_in_peer
-                                  // size of peer
-
-    if(ep_rank == local_leader)
-    {
-      MPI_Comm_rank(peer_comm, &leader_ranks_in_peer[0]);
-      leader_ranks_in_peer[1] = remote_leader;
-      MPI_Comm_size(peer_comm, &leader_ranks_in_peer[2]);
-    }
-
-    MPI_Bcast(leader_ranks_in_peer, 3, MPI_INT, local_leader, local_comm);
-
-    if(leader_ranks_in_peer[0] != leader_ranks_in_peer[2])
-    {
-      Debug("calling MPI_Intercomm_create_kernel\n");
-      return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
-    }
-
-    else
-    {
-      if(leader_ranks_in_peer[2] == 1)
-      {
-        Debug("calling MPI_Intercomm_create_unique\n");
-        return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm); 
+    mpi_rank    = local_comm->ep_comm_ptr->size_rank_info[2].first;
+    ep_size     = local_comm->ep_comm_ptr->size_rank_info[0].second;
+    num_ep      = local_comm->ep_comm_ptr->size_rank_info[1].second;
+    mpi_size    = local_comm->ep_comm_ptr->size_rank_info[2].second;
+
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // step 1 : local leaders exchange ep_size, leader_rank_in_peer, leader_rank_in_peer_mpi, leader_rank_in_world. //
+    //          local leaders bcast results to all ep in local_comm                                                 //
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    bool is_local_leader = ep_rank==local_leader? true: false;
+    
+    
+    int local_leader_rank_in_peer;
+    int local_leader_rank_in_peer_mpi;
+    int local_leader_rank_in_world;
+
+    int remote_ep_size;
+    int remote_leader_rank_in_peer;
+    int remote_leader_rank_in_peer_mpi;
+    int remote_leader_rank_in_world;
+
+    int send_quadruple[4];
+    int recv_quadruple[4];
+
+
+    if(is_local_leader)
+    {
+      MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer);
+      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi);
+      ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world);
+
+      send_quadruple[0] = ep_size;
+      send_quadruple[1] = local_leader_rank_in_peer;
+      send_quadruple[2] = local_leader_rank_in_peer_mpi;
+      send_quadruple[3] = local_leader_rank_in_world;
+
+      MPI_Request request;
+      MPI_Status status;
+
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+
+      remote_ep_size                 = recv_quadruple[0];
+      remote_leader_rank_in_peer     = recv_quadruple[1];
+      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
+      remote_leader_rank_in_world    = recv_quadruple[3];
+#ifdef _showinfo
+      printf("peer_rank = %d, packed exchange OK\n", local_leader_rank_in_peer);
+#endif
+    }
+
+    MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm);
+    MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm);
+
+    if(!is_local_leader)
+    {
+      local_leader_rank_in_peer     = send_quadruple[1];
+      local_leader_rank_in_peer_mpi = send_quadruple[2];
+      local_leader_rank_in_world    = send_quadruple[3];
+
+      remote_ep_size                 = recv_quadruple[0];
+      remote_leader_rank_in_peer     = recv_quadruple[1];
+      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
+      remote_leader_rank_in_world    = recv_quadruple[3];
+    }
+
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, ep_size = %d, remote_ep_size = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_size, remote_ep_size);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm); 
+#endif
+
+    ///////////////////////////////////////////////////////////////////
+    // step 2 : gather ranks in world for both local and remote comm //
+    ///////////////////////////////////////////////////////////////////
+
+    int rank_in_world;
+    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
+
+    int *ranks_in_world_local  = new int[ep_size];
+    int *ranks_in_world_remote = new int[remote_ep_size];
+
+    MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm);
+
+    if(is_local_leader)
+    {
+      MPI_Request request;
+      MPI_Status status;
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+#ifdef _showinfo
+      printf("peer_rank = %d, ranks_in_world exchange OK\n", local_leader_rank_in_peer);
+#endif
+    }
+
+    MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm);
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+    if(remote_leader == 4)
+    {
+      for(int i=0; i<ep_size; i++)
+      {
+        if(ep_rank == i)
+        {
+          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_local[i]);
+          }
+    
+          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<remote_ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_remote[i]);
+          }
+          printf("\n");
+         
+        }
         
-      }
-      else
-      {
-        Debug("calling MPI_Intercomm_create_world\n");
-        return MPI_Intercomm_create_from_world(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);   
-      }
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+      }
+    }
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    
+    if(remote_leader == 13)
+    {
+      for(int i=0; i<ep_size; i++)
+      {
+        if(ep_rank == i)
+        {
+          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_local[i]);
+          }
+    
+          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<remote_ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_remote[i]);
+          }
+          printf("\n");
+         
+        }
+        
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+      }
+    }
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+    //////////////////////////////////////////////////////////////
+    // step 3 : determine the priority and ownership of each ep //
+    //////////////////////////////////////////////////////////////
+
+    bool priority = local_leader_rank_in_peer < remote_leader_rank_in_peer? true : false;
+
+
+    int ownership = priority;
+
+    if(rank_in_world == ranks_in_world_local[local_leader]) ownership = 1;
+    if(rank_in_world == remote_leader_rank_in_world)   ownership = 0;
+    
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+#endif
+
+    
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, priority = %d, ownership = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, ownership);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+#endif
+
+    //////////////////////////////////////////////////////
+    // step 4 : extract local_comm and create intercomm //
+    //////////////////////////////////////////////////////
+
+    bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world);
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, is_involved = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, is_involved);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+    if(is_involved)
+    {
+      ::MPI_Group local_group;
+      ::MPI_Group extracted_group;
+      ::MPI_Comm extracted_comm;
+
+
+      ::MPI_Comm_group(to_mpi_comm(local_comm->mpi_comm), &local_group);
+
+      int *ownership_list = new int[mpi_size];
+      int *mpi_rank_list = new int[mpi_size];
+
+      ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm));
+      ::MPI_Allgather(&mpi_rank,  1, to_mpi_type(MPI_INT), mpi_rank_list,  1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm));
+
       
-    }
-
-
-
-
-
-    int leader_ranks[6]; //! 0: rank in world, 1: mpi_size, 2: rank_in_peer.
-                         //! 3, 4, 5 : remote
-
-    bool is_decider = false;
-
-
-    if(ep_rank == local_leader)
-    {
-      MPI_Comm_rank(MPI_COMM_WORLD, &leader_ranks[0]);
-
-      leader_ranks[1] = mpi_size;
-      MPI_Comm_rank(peer_comm, &leader_ranks[2]);
-
-      MPI_Request request[2];
-      MPI_Status status[2];
-
-      MPI_Isend(&leader_ranks[0], 3, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(&leader_ranks[3], 3, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-
-      MPI_Waitall(2, request, status);
-
-    }
-
-
-    MPI_Bcast(leader_ranks, 6, MPI_INT, local_leader, local_comm);
-
-    
-    MPI_Barrier(local_comm);
-    
-
-    if(leader_ranks[0] == leader_ranks[3])
-    {
-      if( leader_ranks[1] * leader_ranks[4] == 1)
-      {
-        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_unique_leader\n");
-        local_comm->ep_comm_ptr->comm_label = -99;
-
-        return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
-      }
-      else // leader_ranks[1] * leader_ranks[4] != 1
-      {
-        // change leader
-        int new_local_leader;
-
-        if(leader_ranks[2] < leader_ranks[5])
+      int n=0;
+      for(int i=0; i<mpi_size; i++)
+      { 
+        n+=ownership_list[i];
+      }
+
+      int *new_mpi_rank_list = new int[n];
+      int j=0;
+      for(int i=0; i<mpi_size; i++)
+      { 
+        if(ownership_list[i] !=0)
         {
-          if(leader_ranks[1] > 1) //! change leader
+          new_mpi_rank_list[j++] = mpi_rank_list[i];
+        }
+      }
+
+
+      ::MPI_Group_incl(local_group, n, new_mpi_rank_list, &extracted_group);
+
+      ::MPI_Comm_create(to_mpi_comm(local_comm->mpi_comm), extracted_group, &extracted_comm);
+
+      ::MPI_Comm mpi_inter_comm;
+
+      int local_leader_rank_in_extracted_comm;
+
+      if(is_local_leader)
+      {
+        ::MPI_Comm_rank(extracted_comm, &local_leader_rank_in_extracted_comm);
+      }
+
+      ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));
+
+      ::MPI_Comm *intracomm = new ::MPI_Comm;
+      bool is_real_involved = ownership && extracted_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm);
+
+      if(is_real_involved)
+      {
+        ::MPI_Intercomm_create(extracted_comm, local_leader_rank_in_extracted_comm, to_mpi_comm(peer_comm->mpi_comm), remote_leader_rank_in_peer_mpi, tag, &mpi_inter_comm);
+        ::MPI_Intercomm_merge(mpi_inter_comm, !priority, intracomm);
+      }
+        
+        
+
+      ////////////////////////////////////
+      // step 5 :: determine new num_ep //
+      ////////////////////////////////////
+
+      int num_ep_count=0;
+
+      for(int i=0; i<ep_size; i++)
+      {
+        if(rank_in_world == ranks_in_world_local[i])
+          num_ep_count++;
+      }
+      
+      for(int i=0; i<remote_ep_size; i++)
+      {
+        if(rank_in_world == ranks_in_world_remote[i])
+          num_ep_count++;
+      }
+
+
+      ///////////////////////////////////////////////////
+      // step 6 : create endpoints from extracted_comm //
+      ///////////////////////////////////////////////////
+
+      if(is_real_involved)
+      {
+        MPI_Comm *ep_comm;
+        MPI_Info info;
+        MPI_Comm_create_endpoints(intracomm, 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
+
+        #pragma omp critical (write_to_tag_list)      
+        intercomm_list.push_back(make_pair( make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)) , make_pair(ep_comm , make_pair(num_ep_count, 0))));
+        #pragma omp flush
+#ifdef _showinfo
+        for(int i=0; i<num_ep_count; i++)
+          printf("peer_rank = %d, ep_comm = %p, ep_comm[%d] -> new_ep_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_comm, i, ep_comm[i]->ep_comm_ptr->size_rank_info[0].first);
+#endif  
+        ::MPI_Comm_free(intracomm);
+        delete intracomm;
+      }
+
+
+      delete ownership_list;
+      delete mpi_rank_list;
+      delete new_mpi_rank_list;
+
+    }
+
+    int repeated=0;
+    for(int i=0; i<remote_ep_size; i++)
+    {
+      if(rank_in_world == ranks_in_world_remote[i])
+        repeated++;
+    }
+
+    int new_ep_rank_loc = ownership==1? ep_rank_loc : ep_rank_loc+repeated;
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, ep_rank_loc = %d, ownership = %d, repeated = %d, new_ep_rank_loc = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_rank_loc, ownership, repeated, new_ep_rank_loc);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+
+    #pragma omp flush
+    #pragma omp critical (read_from_intercomm_list)
+    {
+      bool flag=true;
+      while(flag)
+      {
+        for(std::list<std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > >::iterator iter = intercomm_list.begin(); iter!=intercomm_list.end(); iter++)
+        {
+          if(iter->first == make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)))
           {
-            // change leader
-            is_decider = true;
-            int target = local_comm->ep_rank_map->at(local_leader).second;
-            {
-              for(int i=0; i<ep_size; i++)
-              {
-                if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0)
-                {
-                  new_local_leader = i;
-                  break;
-                }
-              }
-            }
-          }
-          else
-          {
-            new_local_leader = local_leader;
+            *newintercomm = iter->second.first[new_ep_rank_loc];
+            
+            iter->second.second.second++;
+            
+            if(iter->second.second.first == iter->second.second.second)
+              intercomm_list.erase(iter);
+
+            flag = false;
+            break; 
           }
         }
-        else
-        {
-          if(leader_ranks[4] == 1)
-          {
-            // change leader
-            is_decider = true;
-            int target = local_comm->ep_rank_map->at(local_leader).second;
-            {
-              for(int i=0; i<ep_size; i++)
-              {
-                if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0)
-                {
-                  new_local_leader = i;
-                  break;
-                }
-              }
-            }
-          }
-          else
-          {
-            new_local_leader = local_leader;
-          }
-        }
-
-
-        int new_tag_in_world;
-
-        int leader_in_world[2];
-
-
-        if(is_decider)
-        {
-          if(ep_rank == new_local_leader)
-          {
-            new_tag_in_world = TAG++;
-          }
-          MPI_Bcast(&new_tag_in_world, 1, MPI_INT, new_local_leader, local_comm);
-          if(ep_rank == local_leader) MPI_Send(&new_tag_in_world, 1, MPI_INT, remote_leader, tag, peer_comm);
-        }
-        else
-        {
-          if(ep_rank == local_leader)
-          {
-            MPI_Status status;
-            MPI_Recv(&new_tag_in_world, 1, MPI_INT, remote_leader, tag, peer_comm, &status);
-          }
-          MPI_Bcast(&new_tag_in_world, 1, MPI_INT, new_local_leader, local_comm);
-        }
-
-
-        if(ep_rank == new_local_leader)
-        {
-          ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &leader_in_world[0]);
-        }
-
-        MPI_Bcast(&leader_in_world[0], 1, MPI_INT, new_local_leader, local_comm);
-
-
-        if(ep_rank == local_leader)
-        {
-          MPI_Request request[2];
-          MPI_Status status[2];
-
-          MPI_Isend(&leader_in_world[0], 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-          MPI_Irecv(&leader_in_world[1], 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-
-          MPI_Waitall(2, request, status);
-        }
-
-        MPI_Bcast(&leader_in_world[1], 1, MPI_INT, local_leader, local_comm);
-
-        local_comm->ep_comm_ptr->comm_label = tag;
-
-        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_from_world\n");
-
-        return MPI_Intercomm_create_from_world(local_comm, new_local_leader, MPI_COMM_WORLD->mpi_comm, leader_in_world[1], new_tag_in_world, newintercomm);
-        
-      }
-    }
-
-    
-
+      }
+    }
+    
+
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, test_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].first);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+    //////////////////////////////////////////////////////////
+    // step 7 : create intercomm_rank_map for local leaders //
+    //////////////////////////////////////////////////////////
+
+    (*newintercomm)->is_intercomm = true;
+    
+    (*newintercomm)->inter_rank_map = new INTER_RANK_MAP;
+    
+    
+    int rank_info[2];
+    rank_info[0] = ep_rank;
+    rank_info[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first;
+
+#ifdef _showinfo
+    printf("priority = %d, ep_rank = %d, new_ep_rank = %d\n", priority, rank_info[0], rank_info[1]);
+#endif
+
+    int *local_rank_info = new int[2*ep_size];
+    int *remote_rank_info = new int[2*remote_ep_size];
+
+    MPI_Allgather(rank_info, 2, MPI_INT, local_rank_info, 2, MPI_INT, local_comm);
+
+    if(is_local_leader)
+    {
+      MPI_Request request;
+      MPI_Status status;
+
+      if(priority)
+      {
+        MPI_Isend(local_rank_info, 2*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(remote_rank_info, 2*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(remote_rank_info, 2*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(local_rank_info, 2*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+    }
+
+    MPI_Bcast(remote_rank_info, 2*remote_ep_size, MPI_INT, local_leader, local_comm);
+
+    for(int i=0; i<remote_ep_size; i++)
+    {
+      (*newintercomm)->inter_rank_map->insert(make_pair(remote_rank_info[2*i], remote_rank_info[2*i+1]));
+    }
+    
+    (*newintercomm)->ep_comm_ptr->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
+
+    
+    delete[] local_rank_info;
+    delete[] remote_rank_info;
+    delete[] ranks_in_world_local;
+    delete[] ranks_in_world_remote;
+    /*
+    if((*newintercomm)->ep_comm_ptr->size_rank_info[0].second == 1)
+    {
+      for(INTER_RANK_MAP::iterator it = (*newintercomm)->inter_rank_map->begin(); it != (*newintercomm)->inter_rank_map->end(); it++)
+      {
+        printf("inter_rank_map[%d] = %d\n", it->first, it->second);
+      }
+    }
+    */
+    
+ 
   }
-
-  int MPI_Comm_test_inter(MPI_Comm comm, int *flag)
+    
+  
+  
+  int MPI_Intercomm_create_mpi(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
   {
-    *flag = false;
-    if(comm->is_ep)
-    {
-      *flag = comm->is_intercomm;
-      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_Comm_test_inter(mpi_comm, flag);
-      return 0;  
-    }
-    return 0;
+    printf("MPI_Intercomm_create_mpi not yet implemented\n");
+    MPI_Abort(local_comm, 0);
   }
 
-
 }
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.hpp	(revision 1538)
+++ 	(revision )
@@ -1,45 +1,0 @@
-#ifndef EP_INTERCOMM_HPP_INCLUDED
-#define EP_INTERCOMM_HPP_INCLUDED
-
-typedef std::pair< int, int > SIZE_RANK_INFO; // < rank, size>
-typedef std::vector< std::pair<int, int> > RANK_MAP;  // at(ep_rank) = <ep_rank_local, mpi_rank>
-typedef std::map<int, std::pair<int, int> > EP_RANK_MAP;  // key(ep_rank) = <ep_rank_local, mpi_rank>
-typedef std::map<int, std::pair< int, std::pair<int, int> > > INTERCOMM_RANK_MAP;
-
-namespace ep_lib
-{
-
-  class ep_comm;
-
-  class ep_intercomm
-  {
-    public:
-
-    void *mpi_inter_comm;
-
-    INTERCOMM_RANK_MAP *intercomm_rank_map;  // quadruple : ep_rank_in_local_comm, ep_rank_loc_in_newcomm, mpi_rank_in_new_comm, comm_label
-                                             // of remote_comm
-    
-    EP_RANK_MAP *local_rank_map;             // = ep_rank_map of local_comm
-
-
-    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 of newcomm
-
-
-    int intercomm_tag;                       // newcomm_ep_rank_loc of ep with ep_rank_loc==0 
-                                             // used in comm_dup_intercomm
-    
-  };
-
-
-}
-
-
-
-#endif // EP_INTERCOMM_HPP_INCLUDED
-
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp	(revision 1538)
+++ 	(revision )
@@ -1,640 +1,0 @@
-#include "ep_lib.hpp"
-#include <mpi.h>
-#include "ep_declaration.hpp"
-#include "ep_mpi.hpp"
-
-using namespace std;
-
-
-namespace ep_lib
-{
-  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 ep_rank, ep_rank_loc, mpi_rank;
-    int ep_size, num_ep, mpi_size;
-
-    ep_rank     = local_comm->ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank    = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size     = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep      = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size    = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-    // step 1 : local leaders exchange ep_size, leader_rank_in_peer, leader_rank_in_peer_mpi, leader_rank_in_world. //
-    //          local leaders bcast results to all ep in local_comm                                                 //
-    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-    bool is_local_leader = ep_rank==local_leader? true: false;
-
-
-    
-    int local_leader_rank_in_peer;
-    int local_leader_rank_in_peer_mpi;
-    int local_leader_rank_in_world;
-
-    int remote_ep_size;
-    int remote_leader_rank_in_peer;
-    int remote_leader_rank_in_peer_mpi;
-    int remote_leader_rank_in_world;
-
-    int send_quadruple[4];
-    int recv_quadruple[4];
-
-
-    if(is_local_leader)
-    {
-      MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer);
-      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi);
-      ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world);
-
-      send_quadruple[0] = ep_size;
-      send_quadruple[1] = local_leader_rank_in_peer;
-      send_quadruple[2] = local_leader_rank_in_peer_mpi;
-      send_quadruple[3] = local_leader_rank_in_world;
-
-      MPI_Request request;
-      MPI_Status status;
-
-
-      if(remote_leader > local_leader_rank_in_peer)
-      {
-        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-       
-        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-      }
-      else
-      {
-        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-          
-        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-      }
-
-      remote_ep_size                 = recv_quadruple[0];
-      remote_leader_rank_in_peer     = recv_quadruple[1];
-      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
-      remote_leader_rank_in_world    = recv_quadruple[3];
-#ifdef _showinfo
-      printf("peer_rank = %d, packed exchange OK\n", local_leader_rank_in_peer);
-#endif
-    }
-
-    MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm);
-    MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm);
-
-    if(!is_local_leader)
-    {
-      local_leader_rank_in_peer     = send_quadruple[1];
-      local_leader_rank_in_peer_mpi = send_quadruple[2];
-      local_leader_rank_in_world    = send_quadruple[3];
-
-      remote_ep_size                 = recv_quadruple[0];
-      remote_leader_rank_in_peer     = recv_quadruple[1];
-      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
-      remote_leader_rank_in_world    = recv_quadruple[3];
-    }
-
-
-#ifdef _showinfo
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, ep_size = %d, remote_ep_size = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_size, remote_ep_size);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm); 
-#endif
-
-    ///////////////////////////////////////////////////////////////////
-    // step 2 : gather ranks in world for both local and remote comm //
-    ///////////////////////////////////////////////////////////////////
-
-    int rank_in_world;
-    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
-
-    int *ranks_in_world_local  = new int[ep_size];
-    int *ranks_in_world_remote = new int[remote_ep_size];
-
-    MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm);
-
-    if(is_local_leader)
-    {
-      MPI_Request request;
-      MPI_Status status;
-
-      if(remote_leader > local_leader_rank_in_peer)
-      {
-        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-       
-        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-      }
-      else
-      {
-        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-          
-        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-      }
-#ifdef _showinfo
-      printf("peer_rank = %d, ranks_in_world exchange OK\n", local_leader_rank_in_peer);
-#endif
-    }
-
-    MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm);
-
-#ifdef _showinfo
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-
-    if(remote_leader == 4)
-    {
-      for(int i=0; i<ep_size; i++)
-      {
-        if(ep_rank == i)
-        {
-          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
-          for(int i=0; i<ep_size; i++)
-          {
-            printf("%d\t", ranks_in_world_local[i]);
-          }
-    
-          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
-          for(int i=0; i<remote_ep_size; i++)
-          {
-            printf("%d\t", ranks_in_world_remote[i]);
-          }
-          printf("\n");
-         
-        }
-        
-        MPI_Barrier(local_comm);
-        MPI_Barrier(local_comm);
-        MPI_Barrier(local_comm);
-      }
-    }
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    
-    if(remote_leader == 13)
-    {
-      for(int i=0; i<ep_size; i++)
-      {
-        if(ep_rank == i)
-        {
-          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
-          for(int i=0; i<ep_size; i++)
-          {
-            printf("%d\t", ranks_in_world_local[i]);
-          }
-    
-          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
-          for(int i=0; i<remote_ep_size; i++)
-          {
-            printf("%d\t", ranks_in_world_remote[i]);
-          }
-          printf("\n");
-         
-        }
-        
-        MPI_Barrier(local_comm);
-        MPI_Barrier(local_comm);
-        MPI_Barrier(local_comm);
-      }
-    }
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-
-#endif
-
-    //////////////////////////////////////////////////////////////
-    // step 3 : determine the priority and ownership of each ep //
-    //////////////////////////////////////////////////////////////
-
-    bool priority = local_leader_rank_in_peer > remote_leader_rank_in_peer? true : false;
-
-
-    int ownership;
-
-    if(rank_in_world == ranks_in_world_local[local_leader]) ownership = 1;
-    else if(rank_in_world == remote_leader_rank_in_world)   ownership = 0;
-    else
-    {
-      ownership = 1;
-      for(int i=0; i<remote_ep_size; i++)
-      {
-        if(rank_in_world == ranks_in_world_remote[i])
-        {
-          ownership = priority? 1 : 0;
-          break;
-        }  
-      }
-    }
-
-#ifdef _showinfo
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-#endif
-
-    
-#ifdef _showinfo
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, priority = %d, ownership = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, ownership);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-#endif
-
-    //////////////////////////////////////////////////////
-    // step 4 : extract local_comm and create intercomm //
-    //////////////////////////////////////////////////////
-
-    bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world);
-
-#ifdef _showinfo
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, is_involved = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, is_involved);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-
-#endif
-
-    if(is_involved)
-    {
-      ::MPI_Group local_group;
-      ::MPI_Group extracted_group;
-      ::MPI_Comm *extracted_comm = new ::MPI_Comm;
-
-
-      ::MPI_Comm_group(to_mpi_comm(local_comm->mpi_comm), &local_group);
-
-      int *ownership_list = new int[mpi_size];
-      int *mpi_rank_list = new int[mpi_size];
-
-      ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm));
-      ::MPI_Allgather(&mpi_rank,  1, to_mpi_type(MPI_INT), mpi_rank_list,  1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm));
-
-      
-      int n=0;
-      for(int i=0; i<mpi_size; i++)
-      { 
-        n+=ownership_list[i];
-      }
-
-      int *new_mpi_rank_list = new int[n];
-      int j=0;
-      for(int i=0; i<mpi_size; i++)
-      { 
-        if(ownership_list[i] !=0)
-        {
-          new_mpi_rank_list[j++] = mpi_rank_list[i];
-        }
-      }
-
-
-      ::MPI_Group_incl(local_group, n, new_mpi_rank_list, &extracted_group);
-
-      ::MPI_Comm_create(to_mpi_comm(local_comm->mpi_comm), extracted_group, extracted_comm);
-
-      ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm;
-
-      int local_leader_rank_in_extracted_comm;
-
-      if(is_local_leader)
-      {
-        ::MPI_Comm_rank(*extracted_comm, &local_leader_rank_in_extracted_comm);
-      }
-
-      ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));
-
-
-      if(ownership)
-        ::MPI_Intercomm_create(*extracted_comm, local_leader_rank_in_extracted_comm, to_mpi_comm(peer_comm->mpi_comm), remote_leader_rank_in_peer_mpi, tag, mpi_inter_comm);
-
-      ////////////////////////////////////
-      // step 5 :: determine new num_ep //
-      ////////////////////////////////////
-
-      int num_ep_count=0;
-
-      for(int i=0; i<ep_size; i++)
-      {
-        if(rank_in_world == ranks_in_world_local[i])
-          num_ep_count++;
-      }
-      
-      for(int i=0; i<remote_ep_size; i++)
-      {
-        if(rank_in_world == ranks_in_world_remote[i])
-          num_ep_count++;
-      }
-
-
-      ///////////////////////////////////////////////////
-      // step 6 : create endpoints from extracted_comm //
-      ///////////////////////////////////////////////////
-
-      if(ownership)
-      {
-        MPI_Comm *ep_comm;
-        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++)
-        {
-          ep_comm[i]->is_intercomm = true;
-          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;
-          
-        }
-
-
-        #pragma omp critical (write_to_tag_list)      
-        intercomm_list.push_back(make_pair( make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)) , make_pair(ep_comm , make_pair(num_ep_count, 0))));
-        #pragma omp flush
-#ifdef _showinfo
-        for(int i=0; i<num_ep_count; i++)
-          printf("peer_rank = %d, ep_comm = %p, ep_comm[%d] -> new_ep_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_comm, i, ep_comm[i]->ep_comm_ptr->size_rank_info[0].first);
-#endif
-      }
-
-
-      delete ownership_list;
-      delete mpi_rank_list;
-      delete new_mpi_rank_list;
-
-    }
-
-    int repeated=0;
-    for(int i=0; i<remote_ep_size; i++)
-    {
-      if(rank_in_world == ranks_in_world_remote[i])
-        repeated++;
-    }
-
-    int my_turn = ownership? ep_rank_loc : ep_rank_loc+repeated;
-
-#ifdef _showinfo
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, ep_rank_loc = %d, ownership = %d, repeated = %d, my_turn = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_rank_loc, ownership, repeated, my_turn);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-
-#endif
-
-
-    #pragma omp flush
-    #pragma omp critical (read_from_intercomm_list)
-    {
-      bool flag=true;
-      while(flag)
-      {
-        for(std::list<std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > >::iterator iter = intercomm_list.begin(); iter!=intercomm_list.end(); iter++)
-        {
-          if(iter->first == make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)))
-          {
-            *newintercomm = iter->second.first[my_turn];
-            
-            iter->second.second.second++;
-            
-            if(iter->second.second.first == iter->second.second.second)
-              intercomm_list.erase(iter);
-
-            flag = false;
-            break; 
-          }
-        }
-      }
-    }
-
-#ifdef _showinfo
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, test_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].first);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-
-#endif
-
-    //////////////////////////////////////////////////////////
-    // step 7 : create intercomm_rank_map for local leaders //
-    //////////////////////////////////////////////////////////
-    
-    int my_quadruple[4];
-
-    my_quadruple[0] = ep_rank;
-    my_quadruple[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
-    my_quadruple[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
-    my_quadruple[3] = (*newintercomm)->ep_comm_ptr->comm_label;
-
-
-#ifdef _showinfo
-
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, my_quadruple = %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, my_quadruple[0], my_quadruple[1], my_quadruple[2], my_quadruple[3]);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-#endif
-
-    int *local_quadruple_list;
-    int *remote_quadruple_list;
-    if(is_involved)
-    {
-      local_quadruple_list = new int[4*ep_size];
-      remote_quadruple_list = new int[4*remote_ep_size];
-
-    }
-
-    MPI_Gather(my_quadruple, 4, MPI_INT, local_quadruple_list, 4, MPI_INT, local_leader, local_comm);
-
-
-    if(is_local_leader)
-    {
-      MPI_Request request;
-      MPI_Status status;
-
-      if(remote_leader > local_leader_rank_in_peer)
-      {
-        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);        
-
-        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-      }
-      else
-      {
-        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);
-          
-        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
-        MPI_Wait(&request, &status);       
-      }
-#ifdef _showinfo
-      printf("peer_rank = %d, quadruple_list exchange OK\n", local_leader_rank_in_peer);
-#endif
-    }
-
-    if(is_involved)
-    {
-      ::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++)
-      {
-        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->insert(std::pair<int, std::pair< int, std::pair<int, int> > >(remote_quadruple_list[4*i], remote_quadruple_list[4*i+1], remote_quadruple_list[4*i+2], remote_quadruple_list[4*i+3]));
-      }
-    }
-
-    ////////////////////////////////////////////////////////
-    // step 8 : associate intercomm_rank_map to endpoints //
-    ////////////////////////////////////////////////////////
-
-    int *leader_rank_in_world_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second];
-
-    MPI_Allgather_local(&local_leader_rank_in_world, 1, MPI_INT, leader_rank_in_world_local_gathered, *newintercomm);
-
-
-    int new_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
-    int *new_rank_loc_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second];
-
-    MPI_Allgather_local(&new_rank_loc, 1, MPI_INT, new_rank_loc_local_gathered, *newintercomm);
-
-    //printf("peer_rank = %d, leader_rank_in_world_local_gathered = %d %d %d %d, new_rank_loc_local_gathered = %d %d %d %d\n", 
-    //  peer_comm->ep_comm_ptr->size_rank_info[0].first, leader_rank_in_world_local_gathered[0], leader_rank_in_world_local_gathered[1], leader_rank_in_world_local_gathered[2], leader_rank_in_world_local_gathered[3],
-    //  new_rank_loc_local_gathered[0], new_rank_loc_local_gathered[1], new_rank_loc_local_gathered[2], new_rank_loc_local_gathered[3]);
-
-    if(is_involved)
-    {
-
-      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP;
-#ifdef _showinfo
-      printf("new local_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map);
-#endif
-
-      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));
-      }
-    }
-
-    MPI_Barrier_local(*newintercomm);
-
-    
-    if(!is_involved)
-    {
-      int target;
-      for(int i=0; i<(*newintercomm)->ep_comm_ptr->size_rank_info[1].second; i++)
-      {
-        if(local_leader_rank_in_world == leader_rank_in_world_local_gathered[i])
-        {
-          target = i;
-          (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = target;
-          break;
-        }
-      }
-      (*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;
-    }
-    else
-    {
-      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = -1;
-    }
-
-    (*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)
-    {
-      int receiver = rand()%10;
-      printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 
-        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second);
-    }
-
-    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 9)
-    {
-      int receiver = rand()%6;
-      printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 
-        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second);
-    }
-
-
-    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5)
-    {
-      for(int i=0; i<ep_size; i++)
-      {
-        printf("rank_map->at(%d) = %d, %d\n", i, (*newintercomm)->ep_rank_map->at(i).first, (*newintercomm)->ep_rank_map->at(i).second);
-      }
-    }
-*/
-    //////////////
-    // clean up //
-    //////////////
-
-    delete ranks_in_world_local;
-    delete ranks_in_world_remote;
-
-    if(is_involved)
-    {
-      delete local_quadruple_list;
-      delete remote_quadruple_list;
-    }
-
-    delete leader_rank_in_world_local_gathered;
-    delete new_rank_loc_local_gathered;
-
-
-  }
-
-
-
-  
-}
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_unique.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_unique.cpp	(revision 1538)
+++ 	(revision )
@@ -1,228 +1,0 @@
-#include "ep_lib.hpp"
-#include <mpi.h>
-#include "ep_declaration.hpp"
-#include "ep_mpi.hpp"
-
-using namespace std;
-
-
-namespace ep_lib
-{
-
-
-  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)
-  {
-    //! mpi_size of local comm = 1
-    //! same world rank of leaders
-
-    int ep_rank, ep_rank_loc, mpi_rank;
-    int ep_size, num_ep, mpi_size;
-
-    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-
-
-    std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm
-                                    //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm
-
-    int rank_in_world;
-
-    int rank_in_peer_mpi[2];
-
-    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
-
-
-    int local_num_ep = num_ep;
-    int remote_num_ep;
-    int total_num_ep;
-
-    int leader_rank_in_peer[2];
-
-    int my_position;
-    int tag_label[2];
-
-    vector<int> send_buf(4);
-    vector<int> recv_buf(4);
-
-
-    if(ep_rank == local_leader)
-    {
-      MPI_Status status;
-
-
-
-      MPI_Comm_rank(peer_comm, &leader_rank_in_peer[0]);
-
-      send_buf[0] = local_num_ep;
-      send_buf[1] = leader_rank_in_peer[0];
-
-      MPI_Request req_s, req_r;
-
-      MPI_Isend(send_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
-      MPI_Irecv(recv_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_r);
-
-
-      MPI_Wait(&req_s, &status);
-      MPI_Wait(&req_r, &status);
-
-      recv_buf[2] = leader_rank_in_peer[0];
-
-    }
-
-    MPI_Bcast(recv_buf.data(), 3, MPI_INT, local_leader, local_comm);
-
-    remote_num_ep = recv_buf[0];
-    leader_rank_in_peer[1] = recv_buf[1];
-    leader_rank_in_peer[0] = recv_buf[2];
-
-    total_num_ep = local_num_ep + remote_num_ep;
-
-
-    if(leader_rank_in_peer[0] < leader_rank_in_peer[1])
-    {
-      my_position = ep_rank_loc;
-      //! LEADER create EP
-      if(ep_rank == local_leader)
-      {
-        ::MPI_Comm *mpi_dup = new ::MPI_Comm;
-        
-        ::MPI_Comm_dup(to_mpi_comm(local_comm->mpi_comm), mpi_dup);
-
-        MPI_Comm *ep_intercomm;
-        MPI_Info info;
-        MPI_Comm_create_endpoints(mpi_dup, total_num_ep, info, ep_intercomm);
-
-
-        for(int i=0; i<total_num_ep; i++)
-        {
-          ep_intercomm[i]->is_intercomm = true;
-          ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
-          ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = 0;
-
-          ep_intercomm[i]->ep_comm_ptr->comm_label = leader_rank_in_peer[0];
-        }
-
-        tag_label[0] = TAG++;
-        tag_label[1] = rank_in_world;
-
-        #pragma omp critical (write_to_tag_list)
-        tag_list.push_back(make_pair( make_pair(tag_label[0], tag_label[1]) , ep_intercomm));
-
-        MPI_Request req_s;
-        MPI_Status sta_s;
-        MPI_Isend(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
-
-        MPI_Wait(&req_s, &sta_s);
-
-      }
-    }
-    else
-    {
-      //! Wait for EP creation
-      my_position = remote_num_ep + ep_rank_loc;
-      if(ep_rank == local_leader)
-      {
-        MPI_Status status;
-        MPI_Request req_r;
-        MPI_Irecv(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_r);
-        MPI_Wait(&req_r, &status);
-      }
-    }
-
-    MPI_Bcast(tag_label, 2, MPI_INT, local_leader, local_comm);
-
-
-
-
-    #pragma omp critical (read_from_tag_list)
-    {
-      bool found = false;
-      while(!found)
-      {
-        for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag_label[0], tag_label[1]))
-          {
-            *newintercomm =  iter->second[my_position];
-            found = true;
-            // tag_list.erase(iter);
-            break;
-          }
-        }
-      }
-    }
-
-    MPI_Barrier_local(local_comm);
-
-    if(leader_rank_in_peer[0] < leader_rank_in_peer[1])
-    {
-      for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag_label[0], tag_label[1]))
-          {
-            tag_list.erase(iter);
-            break;
-          }
-        }
-    }
-
-
-
-    int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
-    int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size;
-
-    intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first;
-    intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
-    intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
-    intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second;
-    intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second;
-    intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second;
-
-
-
-    (*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map  = new RANK_MAP;
-    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
-    (*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map->resize(local_num_ep);
-    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_num_ep);
-
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
-
-
-
-    int local_rank_map_ele[2];
-    local_rank_map_ele[0] = intercomm_ep_rank;
-    local_rank_map_ele[1] = (*newintercomm)->ep_comm_ptr->comm_label;
-
-    MPI_Allgather(local_rank_map_ele, 2, MPI_INT, 
-      (*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map->data(), 2, MPI_INT, local_comm);
-
-    if(ep_rank == local_leader)
-    {
-      MPI_Status status;
-      MPI_Request req_s, req_r;
-
-      MPI_Isend((*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map->data(), 2*local_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_s);
-      MPI_Irecv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_r);
-
-
-      MPI_Wait(&req_s, &status);
-      MPI_Wait(&req_r, &status);
-
-    }
-
-    MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, local_leader, local_comm);
-    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]);
-    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = tag;
-
-
-    return MPI_SUCCESS;
-  }
-
-}
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp	(revision 1538)
+++ 	(revision )
@@ -1,547 +1,0 @@
-#include "ep_lib.hpp"
-#include <mpi.h>
-#include "ep_declaration.hpp"
-#include "ep_mpi.hpp"
-
-using namespace std;
-
-namespace ep_lib
-{
-
-
-  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 ep_rank, ep_rank_loc, mpi_rank;
-    int ep_size, num_ep, mpi_size;
-
-    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-    std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm
-                                    //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm
-
-    int rank_in_world;
-    int rank_in_local_parent;
-
-    int local_ep_size = ep_size;
-    int remote_ep_size;
-
-    ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr);
-    ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm->mpi_comm);
-
-    ::MPI_Comm_rank(peer_comm, &rank_in_world);
-
-    ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent);
-
-    bool is_proc_master = false;
-    bool is_local_leader = false;
-    bool is_final_master = false;
-
-
-    if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;}
-    if(ep_rank_loc == 0 && mpi_rank != local_comm->ep_rank_map->at(local_leader).second) is_proc_master = true;
-
-
-    int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm
-
-    int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader
-
-
-    std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm
-
-    std::vector<int> new_rank_info[4];
-    std::vector<int> new_ep_info[2];
-
-    std::vector<int> offset;
-
-    if(is_proc_master)
-    {
-
-      size_info[0] = mpi_size;
-
-      rank_info[0].resize(size_info[0]);
-      rank_info[1].resize(size_info[0]);
-
-      ep_info[0].resize(size_info[0]);
-
-      vector<int> send_buf(6);
-      vector<int> recv_buf(3*size_info[0]);
-
-      send_buf[0] = rank_in_world;
-      send_buf[1] = rank_in_local_parent;
-      send_buf[2] = num_ep;
-
-      ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm);
-
-      for(int i=0; i<size_info[0]; i++)
-      {
-        rank_info[0][i] = recv_buf[3*i];
-        rank_info[1][i] = recv_buf[3*i+1];
-        ep_info[0][i]   = recv_buf[3*i+2];
-      }
-
-
-      if(is_local_leader)
-      {
-        leader_info[0] = rank_in_world;
-        leader_info[1] = mpi_remote_leader;
-
-        ::MPI_Status mpi_status;
-
-        send_buf[0] = size_info[0];
-        send_buf[1] = local_ep_size;
-
-        ::MPI_Send(send_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-        recv_buf[2] = rank_in_world;
-        recv_buf[3] = mpi_remote_leader;
-
-      }
-
-      ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      size_info[1] = recv_buf[0];
-      remote_ep_size = recv_buf[1];
-      leader_info[0] = recv_buf[2];
-      leader_info[1] = recv_buf[3];
-
-      rank_info[2].resize(size_info[1]);
-      rank_info[3].resize(size_info[1]);
-
-      ep_info[1].resize(size_info[1]);
-
-      send_buf.resize(3*size_info[0]);
-      recv_buf.resize(3*size_info[1]);
-
-      if(is_local_leader)
-      {
-        ::MPI_Status mpi_status;
-
-
-        std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() );
-        std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] );
-        std::copy ( ep_info[0].data(),   ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[0] );
-
-        ::MPI_Send(send_buf.data(), 3*size_info[0], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-      }
-
-      ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() );
-      std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin()  );
-      std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() );
-
-      offset.resize(size_info[0]);
-
-      if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader
-      {
-
-        bool found = false;
-        int ep_tmp;
-        int ep_local;
-        int ep_remote;
-        for(int i=0; i<size_info[0]; i++)
-        {
-          int target = rank_info[0][i];
-          found = false;
-          for(int j=0; j<size_info[1]; j++)
-          {
-            if(target == rank_info[2][j])
-            {
-              found = true;
-              ep_tmp = ep_info[1][j];
-              ep_local = ep_info[0][j];
-              ep_remote = ep_info[1][j];
-              break;
-            }
-          }
-          if(found)
-          {
-
-            if(target == leader_info[0]) // the leader is doubled in remote
-            {
-              new_rank_info[0].push_back(target);
-              new_rank_info[1].push_back(rank_info[1][i]);
-
-              new_ep_info[0].push_back(ep_local + ep_remote);
-              offset[i] = 0;
-            }
-            else
-            {
-              offset[i] = ep_local;
-            }
-          }
-          else
-          {
-            new_rank_info[0].push_back(target);
-            new_rank_info[1].push_back(rank_info[1][i]);
-
-            new_ep_info[0].push_back(ep_info[0][i]);
-
-            offset[i] = 0;
-          }
-
-        }
-      }
-
-      else // erase rank doubled with remote leader
-      {
-
-        bool found = false;
-        int ep_tmp;
-        int ep_local;
-        int ep_remote;
-        for(int i=0; i<size_info[0]; i++)
-        {
-          int target = rank_info[0][i];
-          found = false;
-          for(int j=0; j<size_info[1]; j++)
-          {
-
-            if(target == rank_info[2][j])
-            {
-              found = true;
-              ep_tmp = ep_info[1][j];
-              ep_local = ep_info[0][j];
-              ep_remote = ep_info[1][j];
-              break;
-            }
-          }
-          if(found)
-          {
-            if(target != leader_info[1])
-            {
-              new_rank_info[0].push_back(target);
-              new_rank_info[1].push_back(rank_info[1][i]);
-
-              new_ep_info[0].push_back(ep_local + ep_remote);
-              offset[i] = 0;
-            }
-            else // found remote leader
-            {
-              offset[i] = ep_remote;
-            }
-          }
-          else
-          {
-            new_rank_info[0].push_back(target);
-            new_rank_info[1].push_back(rank_info[1][i]);
-
-            new_ep_info[0].push_back(ep_info[0][i]);
-            offset[i] = 0;
-          }
-        }
-      }
-
-      if(offset[mpi_rank] == 0)
-      {
-        is_final_master = true;
-      }
-
-
-      // size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote
-
-      if(is_local_leader)
-      {
-        size_info[2] = new_ep_info[0].size();
-        ::MPI_Status mpi_status;
-
-        ::MPI_Send(&size_info[2], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(&size_info[3], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-      }
-
-      ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      new_rank_info[2].resize(size_info[3]);
-      new_rank_info[3].resize(size_info[3]);
-      new_ep_info[1].resize(size_info[3]);
-
-      send_buf.resize(size_info[2]);
-      recv_buf.resize(size_info[3]);
-
-      if(is_local_leader)
-      {
-        ::MPI_Status mpi_status;
-
-        std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() );
-        std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] );
-        std::copy ( new_ep_info[0].data(),   new_ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[2] );
-
-        ::MPI_Send(send_buf.data(), 3*size_info[2], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-      }
-
-      ::MPI_Bcast(recv_buf.data(),   3*size_info[3], to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() );
-      std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin()  );
-      std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() );
-
-    }
-
-
-
-    if(is_proc_master)
-    {
-      // leader_info[4]: 2-> rank of local leader in new_group generated comm;
-                      // 3-> rank of remote leader in new_group generated comm;
-      ::MPI_Group local_group;
-      ::MPI_Group new_group;
-      ::MPI_Comm *new_comm = new ::MPI_Comm;
-      ::MPI_Comm *intercomm = new ::MPI_Comm;
-
-      ::MPI_Comm_group(local_mpi_comm, &local_group);
-
-      ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group);
-
-      ::MPI_Comm_create(local_mpi_comm, new_group, new_comm);
-
-
-
-      if(is_local_leader)
-      {
-        ::MPI_Comm_rank(*new_comm, &leader_info[2]);
-      }
-
-      ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      if(new_comm != static_cast< ::MPI_Comm* >(MPI_COMM_NULL->mpi_comm))
-      {
-        ::MPI_Barrier(*new_comm);
-
-        ::MPI_Intercomm_create(*new_comm, leader_info[2], peer_comm, leader_info[1], tag, intercomm);
-
-        int id;
-        ::MPI_Comm_rank(*new_comm, &id);
-        int my_num_ep = new_ep_info[0][id];
-
-        MPI_Comm *ep_intercomm;
-        MPI_Info info;
-        MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm);
-
-        for(int i= 0; i<my_num_ep; i++)
-        {
-          ep_intercomm[i]->is_intercomm = true;
-
-          ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
-          ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = intercomm;
-          ep_intercomm[i]->ep_comm_ptr->comm_label = leader_info[0];
-        }
-
-
-        #pragma omp critical (write_to_tag_list)
-        tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm));
-        
-
-      }
-
-
-    }
-
-
-    vector<int> bcast_buf(8);
-    if(is_local_leader)
-    {
-      std::copy(size_info, size_info+4, bcast_buf.begin());
-      std::copy(leader_info, leader_info+4, bcast_buf.begin()+4);
-    }
-
-
-
-    MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm);
-
-
-    if(!is_local_leader)
-    {
-      std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info);
-      std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info);
-    }
-
-
-
-    if(!is_local_leader)
-    {
-      new_rank_info[1].resize(size_info[2]);
-      ep_info[1].resize(size_info[1]);
-      offset.resize(size_info[0]);
-    }
-
-    bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1);
-
-    if(is_local_leader)
-    {
-      bcast_buf[0] = remote_ep_size;
-      std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1);
-      std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1);
-      std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1);
-    }
-
-    MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm);
-
-
-    if(!is_local_leader)
-    {
-      remote_ep_size = bcast_buf[0];
-      std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin());
-      std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin());
-      std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin());
-    }
-
-
-    int my_position = offset[rank_in_local_parent]+ep_rank_loc;
-
-
-    #pragma omp critical (read_from_tag_list)
-    {
-      bool found = false;
-      while(!found)
-      {
-        for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1])))
-          {
-            *newintercomm =  iter->second[my_position];
-
-            found = true;
-            break;
-          }
-        }
-      }
-    }
-
-    MPI_Barrier(local_comm);
-
-    if(is_local_leader)
-    {
-      int local_flag = true;
-      int remote_flag = false;
-      ::MPI_Status mpi_status;
-      
-      ::MPI_Send(&local_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv(&remote_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-    }
-
-    MPI_Barrier(local_comm);
-
-    if(is_proc_master)
-    {
-      for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-      {
-        if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1])))
-        {
-          tag_list.erase(iter);
-          break;
-        }
-      }
-    }
-
-    int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
-    int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size;
-
-    intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first;
-    intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
-    intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
-    intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second;
-    intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second;
-    intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second;
-
-
-    MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm);
-
-    int my_rank_map_elem[2];
-
-
-    my_rank_map_elem[0] = intercomm_ep_rank;
-
-    my_rank_map_elem[1] = (*newintercomm)->ep_comm_ptr->comm_label;
-
-    vector<pair<int, int> > local_rank_map_array;
-    vector<pair<int, int> > remote_rank_map_array;
-
-
-    //(*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP;
-    //(*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size);
-
-    //MPI_Allgather(my_rank_map_elem, 2, MPI_INT, (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm);
-   
-    //(*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
-    //(*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size);
-
-    int local_intercomm_size = intercomm_ep_size;
-    int remote_intercomm_size;
-
-
-    if(is_local_leader)
-    {
-      ::MPI_Status status;
-
-      //::MPI_Send((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      //::MPI_Recv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-
-      ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv(&remote_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-    }
-
-    //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm);
-    MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm);
-
-
-    //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;
-    //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);
-
-    //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
-    //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
-    //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
-
-
-    if(is_local_leader)
-    {
-      ::MPI_Status status;
-      
-      std::vector<std::pair<int, std::pair<int, int> > > map2vec((*newintercomm)->ep_rank_map->size());
-      std::vector<std::pair<int, std::pair<int, int> > > vec2map((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->size());
-      
-      int ii=0;
-      for(std::map<int, std::pair<int, int> >::iterator it = (*newintercomm)->ep_rank_map->begin(); it != (*newintercomm)->ep_rank_map->end(); it++)
-      {
-        map2vec[ii++] = make_pair(it->first, make_pair(it->second.first, it->second.second));
-      }
-      
-      
-      ::MPI_Send(map2vec.data(), 3*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-      ::MPI_Recv(vec2map.data(), 3*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-      
-     
-      for(ii=0; ii<vec2map.size(); ii++)
-      {
-        //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second);
-      }
-    }
-
-    //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm);
-
-    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]);
-    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = local_comm->ep_comm_ptr->comm_label;
-
-    return MPI_SUCCESS;
-
-  }
-
-  // #endif
-
-}
-
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp	(revision 1539)
@@ -12,4 +12,10 @@
 
 
+std::map<std::pair<int, int>, MPI_Group* > * tag_group_map = 0;
+
+std::map<int, std::pair<ep_lib::MPI_Comm*, std::pair<int, int> > > * tag_comm_map = 0;
+
+
+MPI_Group MPI_GROUP_WORLD;
 
 namespace ep_lib
@@ -26,20 +32,5 @@
 
   int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank)
-  {
-    if(comm->is_intercomm)
-    {
-      for(std::map<int, std::pair< int, std::pair<int, int> > >::iterator it = comm->ep_comm_ptr->intercomm->intercomm_rank_map->begin(); it != comm->ep_comm_ptr->intercomm->intercomm_rank_map->end(); it++)
-      {
-        if(   ( it->second.first  == ep_rank_loc )
-           && ( it->second.second.first == mpi_rank ) )
-        {
-          return it->first;
-        }
-      }
-      printf("rank not find for EP_intercomm\n");
-      int err;
-      return MPI_Abort(comm, err);
-    }
-    
+  {    
     for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++)
     {
@@ -51,6 +42,5 @@
     }
     printf("rank not find for EP_intracomm\n");
-    int err;
-    return MPI_Abort(comm, err);
+    return MPI_Abort(comm, 0);
   }
   
@@ -64,5 +54,10 @@
   {
     return ::MPI_Wtime();
-
+  }
+
+  int MPI_Comm_test_inter(MPI_Comm comm, int *flag)
+  {
+    if(comm->is_ep) return *flag = comm->is_intercomm;
+    else return ::MPI_Comm_test_inter(to_mpi_comm(comm->mpi_comm), flag);
   }
 
@@ -133,57 +128,4 @@
   }
 
-  int test_sendrecv(MPI_Comm comm)
-  {
-    int myRank;
-    MPI_Comm_rank(comm, &myRank);
-    bool amClient = false;
-    bool amServer = false;
-    if(myRank<=3) amClient = true;
-    else amServer = true;
-
-    if(amServer)
-    {
-      int send_buf[4];
-      MPI_Request send_request[8];
-      MPI_Status send_status[8];
-
-      
-      
-      for(int j=0; j<4; j++)  // 4 buffers
-      {
-        for(int i=0; i<2; i++)
-        {
-          send_buf[j] = (myRank+1)*100 + j;
-          MPI_Isend(&send_buf[j], 1, MPI_INT, i*2, 9999, comm, &send_request[i*4+j]);
-        }
-      }
-      
-
-      MPI_Waitall(8, send_request, send_status);
-    }
-
-
-    if(amClient&&myRank%2==0) // Clients leaders
-    {
-      int recv_buf[8];
-      MPI_Request recv_request[8];
-      MPI_Status recv_status[8];
-
-      for(int i=0; i<2; i++)  // 2 servers
-      {
-        for(int j=0; j<4; j++)
-        {
-          MPI_Irecv(&recv_buf[i*4+j], 1, MPI_INT, i+4, 9999, comm, &recv_request[i*4+j]);
-        }
-      }
-
-      MPI_Waitall(8, recv_request, recv_status);
-      printf("============ client %d, recv_buf = %d, %d, %d, %d, %d, %d, %d, %d ================\n", 
-              myRank, recv_buf[0], recv_buf[1], recv_buf[2], recv_buf[3], recv_buf[4], recv_buf[5], recv_buf[6], recv_buf[7]);
-    }
-
-    MPI_Barrier(comm);
-
-  }
 
   bool valid_type(MPI_Datatype datatype)
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp	(revision 1539)
@@ -4,12 +4,10 @@
 #include "ep_type.hpp"
 #include "ep_lib_intercomm.hpp"
-#include "ep_lib_intracomm.hpp"
+#include "ep_lib_endpoint.hpp"
 #include "ep_lib_local.hpp"
 #include "ep_lib_collective.hpp"
-#include "ep_tag.hpp"
 #include "ep_lib_fortran.hpp"
 #include "ep_lib_win.hpp"
 #include "ep_lib_mpi.hpp"
-//#include "ep_mpi.hpp"
 
 
@@ -41,4 +39,5 @@
   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);
   int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
@@ -64,5 +63,4 @@
   
   int MPI_Alloc_mem(MPI_Aint size, MPI_Info info, void *baseptr);
-  
   int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr);
 
@@ -86,12 +84,7 @@
 
   int test_sendrecv(MPI_Comm comm);
-  
-  int EP_group_init();
 
 
 }
 
-//MPI_Datatype to_mpi(ep_lib::MPI_Datatype type);
-
-
 #endif // EP_LIB_HPP_INCLUDED
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp	(revision 1539)
@@ -10,5 +10,5 @@
 
   int MPI_Barrier(MPI_Comm comm);
-  
+ 
 
   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm);
@@ -47,10 +47,10 @@
   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_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
@@ -60,5 +60,5 @@
   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_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
 
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_endpoint.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_endpoint.hpp	(revision 1539)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_endpoint.hpp	(revision 1539)
@@ -0,0 +1,26 @@
+#ifndef EP_LIB_ENDPOINT_HPP_INCLUDED
+#define EP_LIB_ENDPOINT_HPP_INCLUDED
+
+namespace ep_lib
+{
+
+  typedef void* MPI_Datatype;
+  typedef void* MPI_Op;
+
+
+  int MPI_Barrier_endpoint(MPI_Comm comm);
+
+  int MPI_Comm_free_endpoint(MPI_Comm* comm);
+
+  int Message_Check_endpoint(MPI_Comm comm);
+  
+  int MPI_Comm_dup_endpoint(MPI_Comm comm, MPI_Comm *newcomm);
+  
+  int MPI_Iprobe_endpoint(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status);
+  int MPI_Improbe_endpoint(int source, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);
+  
+  int MPI_Intercomm_create_endpoint(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+
+}
+
+#endif // EP_LIB_ENDPOINT_HPP_INCLUDED
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp	(revision 1539)
@@ -8,29 +8,28 @@
   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_Allgather_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
+  int MPI_Allgatherv_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int recvcounts[], const int displs[], MPI_Datatype recvtype, MPI_Comm comm);
 
-  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
+  int MPI_Allreduce_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
 
+  int MPI_Alltoall_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
 
-  int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm);
+  int MPI_Bcast_intercomm(void *buffer, int count, MPI_Datatype datatype, int root, MPI_Comm comm);
 
-  int MPI_Comm_free_intercomm(MPI_Comm* comm);
+  int MPI_Exscan_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
+  int MPI_Scan_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
 
-  int MPI_Barrier_intercomm(MPI_Comm comm);
+  int MPI_Gather_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
 
-  int Message_Check_intercomm(MPI_Comm comm);
+  int MPI_Gatherv_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, const int input_recvcounts[], const int input_displs[],
+                            MPI_Datatype recvtype, int root, 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_Reduce_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm);
 
+  int MPI_Reduce_scatter_intercomm(const void *sendbuf, void *recvbuf, const int recvcounts[], MPI_Datatype datatype, MPI_Op op, MPI_Comm comm);
 
-  int MPI_Iprobe_intercomm(int 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_Scatter_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
+  int MPI_Scatterv_intercomm(const void *sendbuf, const int sendcounts[], const int displs[], MPI_Datatype sendtype, void *recvbuf, int recvcount,
+                   MPI_Datatype recvtype, int root, MPI_Comm comm);
 }
 
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intracomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intracomm.hpp	(revision 1538)
+++ 	(revision )
@@ -1,21 +1,0 @@
-#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/src_ep_dev/ep_lib_mpi.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_mpi.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_mpi.hpp	(revision 1539)
@@ -19,4 +19,5 @@
 
   int MPI_Iprobe_mpi(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status);
+  int MPI_Improbe_mpi(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);
   
   int MPI_Comm_rank_mpi(MPI_Comm comm, int* rank);
@@ -29,5 +30,6 @@
   int MPI_Barrier_mpi(MPI_Comm comm);
   
-  int MPI_Abort_mpi(MPI_Comm comm, int errorcode);
+  int MPI_Intercomm_create_mpi(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+
 }
 
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_lib_tests.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_tests.hpp	(revision 1538)
+++ 	(revision )
@@ -1,28 +1,0 @@
-#ifndef EP_LIB_TESTS_HPP_INCLUDED
-#define EP_LIB_TESTS_HPP_INCLUDED
-
-#include "ep_type.hpp"
-
-namespace ep_lib
-{
-  int check_test_1(MPI_Comm comm);  
-
-  int check_test_2(MPI_Comm comm);
-
-  int check_test_3(MPI_Comm comm);
-
-  int check_test_4(MPI_Comm comm);
-
-  int check_test_bcast(MPI_Comm comm);
-
-  int check_test_gather(MPI_Comm comm);
-
-  int check_test_gatherv(MPI_Comm comm);
-
-  int check_test_allgather(MPI_Comm comm);
-
-  int check_test_allgatherv(MPI_Comm comm);
-}
-
-
-#endif // EP_LIB_TESTS_HPP_INCLUDED
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp	(revision 1539)
@@ -10,193 +10,95 @@
 {
 
-  int MPI_Intercomm_merge_unique_leader(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
+  int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
   {
-    Debug("intercomm_merge with unique leader\n");
+    
+    int ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second;
+    int ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_rank = inter_comm->ep_comm_ptr->size_rank_info[2].first;
 
+    int remote_ep_size = inter_comm->inter_rank_map->size();
 
-
-    int ep_rank, ep_rank_loc, mpi_rank;
-    int ep_size, num_ep, mpi_size;
-
-    ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = inter_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = inter_comm->ep_comm_ptr->size_rank_info[2].second;
-
-    int local_high = high;
-    int remote_high;
-
-    int remote_ep_size = inter_comm->ep_comm_ptr->intercomm->remote_rank_map->size();
-
-    int local_ep_rank, local_ep_rank_loc, local_mpi_rank;
-    int local_ep_size, local_num_ep, local_mpi_size;
-
-    //local_ep_rank = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].first;
-    //local_ep_rank_loc = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first;
-    //local_mpi_rank = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].first;
-    //local_ep_size = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[0].second;
-    //local_num_ep = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second;
-    //local_mpi_size = inter_comm->ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-
-    if(local_ep_rank == 0)
-    {
-      MPI_Status status[2];
-      MPI_Request request[2];
-      MPI_Isend(&local_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[0]);
-      MPI_Irecv(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->intercomm_tag, inter_comm, &request[1]);
-
-      MPI_Waitall(2, request, status);
-    }
-
-
-    //MPI_Bcast(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->local_comm);
-
+    int new_ep_rank = high? remote_ep_size + ep_rank : ep_rank;
 
 
     MPI_Comm_dup(inter_comm, newintracomm);
 
-    int my_ep_rank = local_high<remote_high? local_ep_rank: local_ep_rank+remote_ep_size;
+    (*newintracomm)->is_intercomm = false;
+    (*newintracomm)->inter_rank_map->clear();
+    delete (*newintracomm)->inter_rank_map;
+
+    (*newintracomm)->ep_comm_ptr->size_rank_info[0].second = ep_size + remote_ep_size;
+    
+    ///////////////////////////////////
+    int int_high = high? 1 : 0;
+    int sum_high;
+    
+    MPI_Allreduce(&int_high, &sum_high, 1, MPI_INT, MPI_SUM, *newintracomm);
+
+    if(sum_high==0 || sum_high==ep_size+remote_ep_size)
+    {
+      printf("MPI_Intercomm_merge error: please define high with different value...\n");
+      MPI_Abort(inter_comm, 0);
+    }
+    
+    
+    
+    ///////////////////////////////////
+    
+    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank;
+
+    // modif ep_rank_map
+    int my_triple[3] = {new_ep_rank, ep_rank_loc, mpi_rank};
+    int *my_triple_list = new int[3*(ep_size+remote_ep_size)];
+
+    
+    MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm); 
 
 
-    int intra_ep_rank, intra_ep_rank_loc, intra_mpi_rank;
-    int intra_ep_size, intra_num_ep, intra_mpi_size;
+#ifdef _showinfo
+    for(int i=0; i<ep_size+remote_ep_size; i++)
+    {
+      if(new_ep_rank == i)
+      {
+        for(int j=0; j<ep_size+remote_ep_size; j++)
+        {
+          printf("rank %d : my_triple_list[%d] = %d %d %d\n", i, j, my_triple_list[3*j], my_triple_list[3*j+1], my_triple_list[3*j+2]);
+        }
+        printf("\n");
+      }
+      MPI_Barrier(*newintracomm);
+    }
+#endif
 
-    intra_ep_rank = (*newintracomm)->ep_comm_ptr->size_rank_info[0].first;
-    intra_ep_rank_loc = (*newintracomm)->ep_comm_ptr->size_rank_info[1].first;
-    intra_mpi_rank = (*newintracomm)->ep_comm_ptr->size_rank_info[2].first;
-    intra_ep_size = (*newintracomm)->ep_comm_ptr->size_rank_info[0].second;
-    intra_num_ep = (*newintracomm)->ep_comm_ptr->size_rank_info[1].second;
-    intra_mpi_size = (*newintracomm)->ep_comm_ptr->size_rank_info[2].second;
-
-
-    MPI_Barrier_local(*newintracomm);
-
-
-    int *reorder;
-    if(intra_ep_rank_loc == 0)
+    if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first==0)
     {
-      reorder = new int[intra_ep_size];
-    }
-
-
-    MPI_Gather(&my_ep_rank, 1, MPI_INT, reorder, 1, MPI_INT, 0, *newintracomm);
-    if(intra_ep_rank_loc == 0)
-    {
-      ::MPI_Bcast(reorder, intra_ep_size, to_mpi_type(MPI_INT), 0, to_mpi_comm((*newintracomm)->mpi_comm));
-
-      vector< pair<int, int> > tmp_rank_map(intra_ep_size);
-
-
-      for(int i=0; i<intra_ep_size; i++)
+      for(int i=0; i<ep_size+remote_ep_size; i++)
       {
-        tmp_rank_map[reorder[i]] = (*newintracomm)->ep_rank_map->at(i) ;
+        (*newintracomm)->ep_comm_ptr->comm_list[0]->ep_rank_map->at(my_triple_list[3*i]) = std::make_pair(my_triple_list[3*i+1], my_triple_list[3*i+2]);
       }
-
-      //(*newintracomm)->rank_map->swap(tmp_rank_map);
-      (*newintracomm)->ep_rank_map->clear();
-      for(int i=0; i<tmp_rank_map.size(); i++)
-      {
-        (*newintracomm)->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(i, tmp_rank_map[i].first, tmp_rank_map[i].second));
-      }
-      
-
-      tmp_rank_map.clear();
     }
 
     MPI_Barrier_local(*newintracomm);
 
-    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = my_ep_rank;
+#ifdef _showinfo
 
-    if(intra_ep_rank_loc == 0)
+    for(int i=0; i<ep_size+remote_ep_size; i++)
     {
-      delete[] reorder;
-    }
-
-    return MPI_SUCCESS;
-  }
-
-
-
-
-
-  int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
-  {
-    
-
-    assert(inter_comm->is_intercomm);
-
-    // determine if only one MPI proc
-
-        // to be completed ......
-
-    // multiple MPI proc and high differs
-
-    int newcomm_ep_rank = inter_comm->ep_comm_ptr->intercomm->size_rank_info[0].first;
-    int newcomm_ep_rank_loc = inter_comm->ep_comm_ptr->intercomm->size_rank_info[1].first;
-    int newcomm_num_ep = inter_comm->ep_comm_ptr->intercomm->size_rank_info[1].second;
-
-    int ep_rank = inter_comm->ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = inter_comm->ep_comm_ptr->size_rank_info[1].first;
-    int num_ep = inter_comm->ep_comm_ptr->size_rank_info[1].second;
-
-    if(newcomm_ep_rank_loc == 0)
-    {
-      ::MPI_Comm *mpi_intracomm = new ::MPI_Comm;
-      ::MPI_Intercomm_merge(to_mpi_comm(inter_comm->ep_comm_ptr->intercomm->mpi_inter_comm), high, mpi_intracomm);
-      
-      MPI_Info info;
-      MPI_Comm *ep_comm;
-      MPI_Comm_create_endpoints(mpi_intracomm, newcomm_num_ep, info, ep_comm);
-
-      inter_comm->ep_comm_ptr->comm_list[0]->mem_bridge = ep_comm;
-    }
-
-    MPI_Barrier_local(inter_comm);
-
-    int remote_num_ep = newcomm_num_ep - num_ep;
-
-    *newintracomm = inter_comm->ep_comm_ptr->comm_list[0]->mem_bridge[high? remote_num_ep+ep_rank_loc : ep_rank_loc];
-
-    int ep_size = inter_comm->ep_comm_ptr->size_rank_info[0].second;
-    int remote_ep_size = inter_comm->ep_comm_ptr->intercomm->intercomm_rank_map->size();
-
-    //printf("ep_size = %d, remote_ep_size = %d\n", ep_size, remote_ep_size);
-
-    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = high? remote_ep_size+ep_rank : ep_rank;
-
-    int my_triple[3];
-    my_triple[0] = (*newintracomm)->ep_comm_ptr->size_rank_info[0].first;
-    my_triple[1] = (*newintracomm)->ep_comm_ptr->size_rank_info[1].first;
-    my_triple[2] = (*newintracomm)->ep_comm_ptr->size_rank_info[2].first;
-
-    int *my_triple_list = new int[3 * (*newintracomm)->ep_comm_ptr->size_rank_info[0].second];
-
-
-    MPI_Allgather(my_triple, 3, MPI_INT, my_triple_list, 3, MPI_INT, *newintracomm);
-
-    if((*newintracomm)->ep_comm_ptr->size_rank_info[1].first == 0)
-    {
-      (*newintracomm)->ep_rank_map->clear();
-      for(int i=0; i<(*newintracomm)->ep_comm_ptr->size_rank_info[0].second; i++)
+      if(new_ep_rank == i)
       {
-        (*newintracomm)->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_list[3*i], my_triple_list[3*i+1], my_triple_list[3*i+2]));
+        for(EP_RANK_MAP::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++)
+        {
+          printf("rank %d : ep_rank_map[%d] = %d %d\n", i, it->first, it->second.first, it->second.second);
+        }
+        printf("\n");
       }
-    }
-
-#ifdef _showinfo
-    MPI_Barrier_local(inter_comm);
-    if((*newintracomm)->ep_comm_ptr->size_rank_info[0].first == 15)
-    {
-      for(std::map<int, std::pair<int, int> >::iterator it = (*newintracomm)->ep_rank_map->begin(); it != (*newintracomm)->ep_rank_map->end(); it++)
-      {
-        printf("(%d  %d  %d)\n", it->first, it->second.first, it->second.second);
-      }
+      MPI_Barrier(*newintracomm);
     }
 #endif
-    
-    delete my_triple_list;
+
+    delete[] my_triple_list;
+
   }
   
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp	(revision 1539)
@@ -32,5 +32,5 @@
     std::list<MPI_Request* >::iterator it;
     
-//    show_EP_PendingRequests(EP_PendingRequests);
+    show_EP_PendingRequests(EP_PendingRequests);
     
     
@@ -81,9 +81,9 @@
       }
       
-      if((*(*it))->state == 0)
+      if((*(*it))->probed == false)
       {
         #pragma omp critical (_query0)
         {
-          MPI_Iprobe((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status);
+          MPI_Iprobe_endpoint((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status);
           if(probed)
           {
@@ -95,5 +95,5 @@
           
           
-            MPI_Improbe((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status);
+            MPI_Improbe_endpoint((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status);
         
           }
@@ -107,5 +107,5 @@
           MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it);
           (*(*it))->type = 3;
-          (*(*it))->state = 1;
+          (*(*it))->probed = true;
 
           memcheck("delete "<< status.mpi_status <<" : in ep_lib::Request_Check, delete status.mpi_status");
@@ -133,17 +133,9 @@
   int Message_Check(MPI_Comm comm)
   {
-    if(!comm->is_ep) return MPI_SUCCESS;
-
-    if(comm->is_intercomm)
-    {
-      Message_Check_intercomm(comm);
-    }
-    
-    return Message_Check_intracomm(comm);
-
-  }
-  
-  
-  int Message_Check_intracomm(MPI_Comm comm)
+    if(comm->is_ep) return Message_Check_endpoint(comm);
+  }
+  
+  
+  int Message_Check_endpoint(MPI_Comm comm)
   {
     
@@ -204,71 +196,4 @@
   }
 
-
-  int Message_Check_intercomm(MPI_Comm comm)
-  {
-    if(!comm->ep_comm_ptr->intercomm->mpi_inter_comm) return 0;
-
-    Debug("Message probing for intercomm\n");
-
-    int flag = true;
-    ::MPI_Message message;
-    ::MPI_Status status;
-    int current_ep_rank;
-    MPI_Comm_rank(comm, &current_ep_rank);
-
-    while(flag) // loop until the end of global queue "comm->ep_comm_ptr->intercomm->mpi_inter_comm"
-    {
-      Debug("Message probing for intracomm\n");
-
-      #pragma omp critical (_mpi_call)
-      {
-        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &flag, &status);
-        if(flag)
-        {
-          Debug("find message in mpi comm \n");
-          ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status);
-        }
-      }
-      
-
-      if(flag)
-      {
-
-        MPI_Message msg = new ep_message; 
-        msg->mpi_message = new ::MPI_Message(message);
-
-        memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message");
-        memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message");
-              
-
-        msg->ep_tag  = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 
-        int src_loc  = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 
-        int dest_loc = bitset<8> (status.MPI_TAG)	    .to_ulong();
-        int src_mpi  = status.MPI_SOURCE;
-             
-        msg->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);   
-#ifdef _showinfo
-        printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag);
-#endif
-
-        msg->mpi_status = new ::MPI_Status(status); 
-        memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status");
-
-        #pragma omp critical (_query)
-        {
-          #pragma omp flush
-          comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg);
-          memcheck("comm->ep_comm_ptr->comm_list["<<dest_loc<<"]->ep_comm_ptr->message_queue->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size());
-          #pragma omp flush
-        }
-      }
-    }
-
-    Message_Check_intracomm(comm);
-
-    return MPI_SUCCESS;
-  }
-  
-  
   
   void show_EP_PendingRequests(std::list< ep_lib::MPI_Request* > * EP_PendingRequest)
@@ -310,2 +235,3 @@
 
 }
+
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp	(revision 1539)
@@ -8,8 +8,41 @@
   int MPI_Iprobe_mpi(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
   {
+    ::MPI_Status mpi_status;
+
+    ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_status);
+
+    status->mpi_status = new ::MPI_Status(mpi_status);
     status->ep_src = src;
     status->ep_tag = tag;
-    return ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, to_mpi_status_ptr(*status));
   }
+
+
+  int MPI_Improbe_mpi(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status)
+  {
+    ::MPI_Status mpi_status;
+    ::MPI_Message mpi_message;
+
+    #ifdef _openmpi
+    #pragma omp critical (_mpi_call)
+    {
+      ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_status);
+      if(*flag)
+      {
+        ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), &mpi_message, &mpi_status);
+      }
+    }
+    #elif _intelmpi
+    ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_message, &mpi_status);
+    #endif
+      
+    status->mpi_status = new ::MPI_Status(mpi_status);
+    status->ep_src = src;
+    status->ep_tag = tag;
+
+    (*message)->mpi_message = &message;
+    (*message)->ep_src = src;
+    (*message)->ep_tag = tag;
+  }
+
 
   int MPI_Iprobe(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
@@ -20,78 +53,82 @@
       return MPI_Iprobe_mpi(src, tag, comm, flag, status);
     }
+
+    if(comm->is_intercomm)
+    {
+      if(src>=0) src = comm->inter_rank_map->at(src);
+    } 
     
-    else
+    return MPI_Iprobe_endpoint(src, tag, comm, flag, status);
+  }
+
+  int MPI_Iprobe_endpoint(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
+  {
+    Debug("MPI_Iprobe with EP\n");
+
+    *flag = false;
+    
+    Message_Check(comm);
+
+    #pragma omp flush
+
+    #pragma omp critical (_query)
+    for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it)
     {
-      Debug("MPI_Iprobe with EP\n");
+      bool src_matched = src<0? true: (*it)->ep_src == src;
+      bool tag_matched = tag<0? true: (*it)->ep_tag == tag;
       
-      *flag = false;
-    
-      Message_Check(comm);
+      if(src_matched && tag_matched)        
+      {
+        Debug("find message\n");
+         
+        status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status));
+        status->ep_src = (*it)->ep_src;
+        status->ep_tag = (*it)->ep_tag;
+        
+        if(comm->is_intercomm)
+        {
+          for(INTER_RANK_MAP::iterator iter = comm->inter_rank_map->begin(); iter != comm->inter_rank_map->end(); iter++)
+          {
+            if(iter->second == (*it)->ep_src) status->ep_src=iter->first;
+          }
+        }
 
-      #pragma omp flush
-
-      #pragma omp critical (_query)
-      for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it)
-      {
-        bool src_matched = src<0? true: (*it)->ep_src == src;
-        bool tag_matched = tag<0? true: (*it)->ep_tag == tag;
-        
-        if(src_matched && tag_matched)        
-        {
-          Debug("find message\n");
-          
-
-          status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status));
-          status->ep_src = (*it)->ep_src;
-          status->ep_tag = (*it)->ep_tag;
-
-          *flag = true;
-          break;
-        }
+        *flag = true;
+        break;
       }
     }
   }
 
-
+  
 
   int MPI_Improbe(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status)
   {
+    if(!comm->is_ep)
+    {
+      Debug("MPI_Iprobe with MPI\n");
+      return MPI_Improbe_mpi(src, tag, comm, flag, message, status);
+    }
+
+    if(comm->is_intercomm)
+    {
+      src = comm->inter_rank_map->at(src);
+      *message = new ep_message;
+      printf("============= new *message = %p\n", *message);
+    } 
+    
+    return MPI_Improbe_endpoint(src, tag, comm, flag, message, status);
+  }
+
+
+
+  int MPI_Improbe_endpoint(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status)
+  {
     int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
     int mpi_rank    = comm->ep_comm_ptr->size_rank_info[2].first;
+
     *flag = false;
-    if(!comm->is_ep)
-    {
-      Debug("calling MPI_Improbe MPI\n");
-
-      ::MPI_Status mpi_status;
-      ::MPI_Message mpi_message;
-
-      #ifdef _openmpi
-      #pragma omp critical (_mpi_call)
-      {
-        ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_status);
-        if(*flag)
-        {
-          ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), &mpi_message, &mpi_status);
-        }
-      }
-      #elif _intelmpi
-    	::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), flag, &mpi_message, &mpi_status);
-      #endif
-    	
-      status->mpi_status = &mpi_status;
-      status->ep_src = src;
-      status->ep_tag = tag;
-
-      (*message)->mpi_message = &message;
-      (*message)->ep_src = src;
-      (*message)->ep_tag = tag;
-      
-      
-      return 0;
-    }
-
-   
-
+    
+    Message_Check(comm);
+    
     #pragma omp flush
 
@@ -146,2 +183,3 @@
 }
 
+
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp	(revision 1539)
@@ -40,4 +40,9 @@
   {
     if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request);
+
+    if(comm->is_intercomm)
+    {
+      if(src>=0) src = comm->inter_rank_map->at(src);
+    }
     
     Debug("MPI_Irecv with EP");
@@ -54,6 +59,6 @@
     (*request)->comm = comm;
     (*request)->type = 2;
+    (*request)->probed = false;
     (*request)->state = 0;
-    
 
     (*request)->ep_src = src;
@@ -63,5 +68,5 @@
     if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >;
 
-    EP_PendingRequests->push_back(request);  
+    EP_PendingRequests->push_back(request); 
     
     memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());    
@@ -100,4 +105,6 @@
     memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Mrecv, delete (*message)->mpi_message");
     delete (*message)->mpi_message;
+    memcheck("delete " << *message << " : in ep_lib::MPI_Imrecv, delete *message");
+    delete *message;
 
 #ifdef _check_sum
@@ -118,4 +125,5 @@
     (*request)->ep_src = (*message)->ep_src;
     
+    (*request)->probed = true;
     (*request)->state = 1;
 	
@@ -125,4 +133,5 @@
     delete (*message)->mpi_message;
 
+
 #ifdef _check_sum
     check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
@@ -130,5 +139,5 @@
 
     
-    return Request_Check();
+    //return Request_Check();
   }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp	(revision 1539)
@@ -288,8 +288,6 @@
   {
 
-    if(!comm->is_ep && comm->mpi_comm)
-    {
-      return ::MPI_Reduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root, to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Reduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root, to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Reduce_intercomm(sendbuf, recvbuf, count, datatype, op, root, comm);
 
 
@@ -339,4 +337,9 @@
 
 
+  int MPI_Reduce_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
+  {
+    printf("MPI_Reduce_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
 }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp	(revision 1539)
@@ -19,8 +19,6 @@
   int MPI_Reduce_scatter(const void *sendbuf, void *recvbuf, const int recvcounts[], MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Reduce_scatter_intercomm(sendbuf, recvbuf, recvcounts, datatype, op, comm);
 
 
@@ -81,4 +79,10 @@
   }
 
+  int MPI_Reduce_scatter_intercomm(const void *sendbuf, void *recvbuf, const int recvcounts[], MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+  {
+    printf("MPI_Reduce_scatter_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
   
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_request.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_request.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_request.hpp	(revision 1539)
@@ -21,4 +21,5 @@
                  // 1: imrecvd
                  // 2: tested or waited
+      bool probed;
                    
       void* buf;
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp	(revision 1539)
@@ -350,8 +350,6 @@
   int MPI_Scan(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Scan_intercomm(sendbuf, recvbuf, count, datatype, op, comm);
     
     valid_type(datatype);
@@ -446,3 +444,9 @@
   }
 
+  int MPI_Scan_intercomm(const void *sendbuf, void *recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+  {
+    printf("MPI_Scan_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp	(revision 1539)
@@ -42,8 +42,6 @@
   int MPI_Scatter(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Scatter(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Scatter(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Scatter_intercomm(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype, root, comm);
    
     assert(sendcount == recvcount);
@@ -97,8 +95,4 @@
 
 
-
-    // if(is_root) printf("\nranks = %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", ranks[0], ranks[1], ranks[2], ranks[3], ranks[4], ranks[5], ranks[6], ranks[7], 
-    //                                                                                   ranks[8], ranks[9], ranks[10], ranks[11], ranks[12], ranks[13], ranks[14], ranks[15]);
-
     if(is_root)
     for(int i=0; i<ep_size; i++)
@@ -106,10 +100,4 @@
       memcpy(tmp_sendbuf + i*datasize*count, sendbuf + ranks[i]*datasize*count, count*datasize);
     }
-
-    // if(is_root) printf("\ntmp_sendbuf = %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", static_cast<int*>(tmp_sendbuf)[0], static_cast<int*>(tmp_sendbuf)[2], static_cast<int*>(tmp_sendbuf)[4], static_cast<int*>(tmp_sendbuf)[6], 
-    //                                                                           static_cast<int*>(tmp_sendbuf)[8], static_cast<int*>(tmp_sendbuf)[10], static_cast<int*>(tmp_sendbuf)[12], static_cast<int*>(tmp_sendbuf)[14], 
-    //                                                                           static_cast<int*>(tmp_sendbuf)[16], static_cast<int*>(tmp_sendbuf)[18], static_cast<int*>(tmp_sendbuf)[20], static_cast<int*>(tmp_sendbuf)[22], 
-    //                                                                           static_cast<int*>(tmp_sendbuf)[24], static_cast<int*>(tmp_sendbuf)[26], static_cast<int*>(tmp_sendbuf)[28], static_cast<int*>(tmp_sendbuf)[30] );
-
 
     // MPI_Scatterv from root to masters
@@ -127,6 +115,4 @@
       ::MPI_Scatterv(tmp_sendbuf, recvcounts.data(), displs.data(), to_mpi_type(sendtype), local_recvbuf, num_ep*count, to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
 
-      // printf("local_recvbuf = %d %d %d %d\n", static_cast<int*>(local_recvbuf)[0], static_cast<int*>(local_recvbuf)[1], static_cast<int*>(local_recvbuf)[2], static_cast<int*>(local_recvbuf)[3]);
-                                                          // static_cast<int*>(local_recvbuf)[4], static_cast<int*>(local_recvbuf)[5], static_cast<int*>(local_recvbuf)[6], static_cast<int*>(local_recvbuf)[7]);
     }
 
@@ -138,3 +124,10 @@
   }
 
+
+  int MPI_Scatter_intercomm(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
+  {
+    printf("MPI_Scatter_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp	(revision 1539)
@@ -45,8 +45,6 @@
                    MPI_Datatype recvtype, int root, MPI_Comm comm)
   {
-    if(!comm->is_ep)
-    {
-      return ::MPI_Scatterv(sendbuf, sendcounts, displs, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
-    }
+    if(!comm->is_ep) return ::MPI_Scatterv(sendbuf, sendcounts, displs, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
+    if(comm->is_intercomm) return MPI_Scatterv_intercomm(sendbuf, sendcounts, displs, sendtype, recvbuf, recvcount, recvtype, root, comm);
    
     assert(sendtype == recvtype);
@@ -105,10 +103,7 @@
       for(int i=0; i<ep_size; i++)
       {
-        //printf("i=%d : start from %d, src displs = %d, count = %d\n ", i, local_displs/datasize, displs[ranks[i]], sendcounts[ranks[i]]);
         memcpy(tmp_sendbuf+local_displs, sendbuf + displs[ranks[i]]*datasize, sendcounts[ranks[i]]*datasize);
         local_displs += sendcounts[ranks[i]]*datasize;
       }
-      
-      //for(int i=0; i<ep_size*2; i++) printf("%d\t", static_cast<int*>(const_cast<void*>(tmp_sendbuf))[i]);
     }
 
@@ -129,9 +124,4 @@
 
       ::MPI_Scatterv(tmp_sendbuf, recvcounts.data(), my_displs.data(), to_mpi_type(sendtype), local_sendbuf, num_ep*count, to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
-
-      // printf("my_displs = %d %d %d %d\n", my_displs[0], my_displs[1], my_displs[2], my_displs[3] );
-
-      // printf("%d %d %d %d %d %d %d %d\n", static_cast<int*>(local_sendbuf)[0], static_cast<int*>(local_sendbuf)[1], static_cast<int*>(local_sendbuf)[2], static_cast<int*>(local_sendbuf)[3],
-      //                                     static_cast<int*>(local_sendbuf)[4], static_cast<int*>(local_sendbuf)[5], static_cast<int*>(local_sendbuf)[6], static_cast<int*>(local_sendbuf)[7]);
     }
 
@@ -154,3 +144,11 @@
 
 
+  int MPI_Scatterv_intercomm(const void *sendbuf, const int sendcounts[], const int displs[], MPI_Datatype sendtype, void *recvbuf, int recvcount,
+                   MPI_Datatype recvtype, int root, MPI_Comm comm)
+  {
+    printf("MPI_Scatterv_intercomm not yet implemented\n");
+    MPI_Abort(comm, 0);
+  }
+
+
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp	(revision 1539)
@@ -18,5 +18,5 @@
   {
     if(!comm->is_ep)       return MPI_Send_mpi(buf, count, datatype, dest, tag, comm);
-    if(comm->is_intercomm) return MPI_Send_intercomm(buf, count, datatype, dest, tag, comm);
+    if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest);
     
     Debug("\nMPI_Send with EP\n");
@@ -38,5 +38,5 @@
   {
     if(!comm->is_ep)       return MPI_Ssend_mpi(buf, count, datatype, dest, tag, comm);
-    if(comm->is_intercomm) return MPI_Ssend_intercomm(buf, count, datatype, dest, tag, comm);
+    if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest);
     
     Debug("\nMPI_Ssend with EP\n");
@@ -61,5 +61,5 @@
   {
     if(!comm->is_ep)       return MPI_Isend_mpi(buf, count, datatype, dest, tag, comm, request);
-    if(comm->is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request);
+    if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest);
 
     Debug("\nMPI_Isend with EP\n");
@@ -104,5 +104,5 @@
  
     if(!comm->is_ep) return MPI_Issend_mpi(buf, count, datatype, dest, tag, comm, request);
-    if(comm->is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request);
+    if(comm->is_intercomm) dest = comm->inter_rank_map->at(dest);
 
     Debug("\nMPI_Issend with EP\n");
@@ -144,15 +144,5 @@
     return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm));
   }
-  
-  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
-  {
-    Debug("\nMPI_Send_intercomm with EP\n");
-    MPI_Request request;
-    MPI_Status status;
-    MPI_Isend(buf, count, datatype, dest, tag, comm, &request);
-    MPI_Wait(&request, &status);
-    return MPI_SUCCESS;
-  }
-  
+ 
   
   int MPI_Ssend_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
@@ -163,14 +153,4 @@
   
 
-  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
-  {
-    Debug("\nMPI_Ssend_intercomm with EP\n");
-    MPI_Request request;
-    MPI_Status status;
-    MPI_Issend(buf, count, datatype, dest, tag, comm, &request);
-    MPI_Wait(&request, &status);
-    return MPI_SUCCESS;
-  }
-  
   int MPI_Isend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
@@ -195,59 +175,5 @@
   }
   
-  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
-  {
-    Debug("\nMPI_Isend_intercomm with EP\n");
-
-#ifdef _check_sum    
-    check_sum_send(buf, count, datatype, dest, tag, comm);
-#endif
-
-    int src_comm_label  = comm->ep_comm_ptr->comm_label;
-    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second;
-    
-    int src_rank;
-    MPI_Comm_rank(comm, &src_rank);
-
-    
-    *request = new ep_request;
-    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_intercomm, *request = new ep_request");
-
-    (*request)->mpi_request = new ::MPI_Request;
-    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_intercomm, (*request)->mpi_request = new ::MPI_Request");
-    
-
-    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first;
-    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first;
-    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first;
-
-#ifdef _showinfo
-    printf("Send : ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag);
-#endif
-    
-
-    (*request)->ep_src  = src_rank;
-    (*request)->ep_tag  = tag;
-    (*request)->ep_datatype = datatype;
-
-    (*request)->type = 1;    // used in wait
-    (*request)->comm = comm;
-    (*request)->buf = const_cast<void*>(buf);
-
-
-    if(src_comm_label == dest_comm_label)
-    {
-      Debug("\nMPI_Isend_intercomm with EP_intracomm\n");
-      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
-    }
-
-    else
-    {
-      Debug("\nMPI_Isend_intercomm with EP_intercomm\n");
-      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request));
-    }
-  }
-
-
+  
 
 
@@ -275,57 +201,4 @@
 
 
-  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
-  {
-    Debug("\nMPI_Issend_intercomm with EP\n");
-
-#ifdef _check_sum    
-    check_sum_send(buf, count, datatype, dest, tag, comm);
-#endif
-
-    int src_comm_label  = comm->ep_comm_ptr->comm_label;
-    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second;
-    
-    int src_rank;
-    MPI_Comm_rank(comm, &src_rank);
-
-    
-    *request = new ep_request;
-    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_intercomm, *request = new ep_request");
-
-    (*request)->mpi_request = new ::MPI_Request;
-    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_intercomm, (*request)->mpi_request = new ::MPI_Request");
-    
-
-    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first;
-    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first;
-    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first;
-
-#ifdef _showinfo
-    printf("ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag);
-#endif
-    
-    (*request)->ep_src  = src_rank;
-    (*request)->ep_tag  = tag;
-    (*request)->ep_datatype = datatype;
-
-    (*request)->type = 1;    // used in wait
-    (*request)->comm = comm;
-    (*request)->buf = const_cast<void*>(buf);
-
-
-    if(src_comm_label == dest_comm_label)
-    {
-      Debug("\nMPI_Issend_intercomm with EP_intracomm\n");
-      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
-    }
-
-    else
-    {
-      Debug("\nMPI_Issend_intercomm with EP_intercomm\n");
-      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request));
-    }
-  }
-  
 }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp	(revision 1539)
@@ -22,14 +22,5 @@
     if(comm->is_ep)
     {
-      if(comm->is_intercomm)
-      {
-        Debug("MPI_Comm_remote_size with EP_intercomm");
-        return *size = comm->ep_comm_ptr->intercomm->intercomm_rank_map->size();
-      }
-      else
-      {
-        Debug("MPI_Comm_remote_size with EP_intracomm");
-        return *size=0;
-      }
+      return *size = comm->is_intercomm? comm->inter_rank_map->size() : 0;
     }
     return MPI_Comm_remote_size_mpi(comm, size);
@@ -49,5 +40,4 @@
   }
 
-
 }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp	(revision 1539)
@@ -9,27 +9,4 @@
 {
 
-  void vec_simplify(std::vector<int> *inout_vector)
-  {
-    std::vector<int> out_vec;
-    int found=false;
-    for(std::vector<int>::iterator it_in = inout_vector->begin() ; it_in != inout_vector->end(); ++it_in)
-    {
-      for(std::vector<int>::iterator it = out_vec.begin() ; it != out_vec.end(); ++it)
-      {
-        if(*it_in == *it)
-        {
-          found=true;
-          break;
-        }
-        else found=false;
-      }
-      if(found == false)
-      {
-        out_vec.push_back(*it_in);
-      }
-    }
-    inout_vector->swap(out_vec);
-  }
-  
   void vec_simplify(std::vector<int> *in_vector, std::vector<int> *out_vector)
   {
@@ -274,6 +251,4 @@
         *newcomm = comm->ep_comm_ptr->comm_list[0]->mem_bridge[new_ep_rank_loc];
         memcheck("in MPI_Split ep_rank="<< ep_rank <<" : *newcomm = "<< *newcomm);
-
-        (*newcomm)->ep_comm_ptr->comm_label = color;
         
         (*newcomm)->ep_comm_ptr->size_rank_info[0].first = new_ep_rank;
Index: OS/dev/branch_openmp/extern/src_ep_dev/ep_tag.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_tag.hpp	(revision 1538)
+++ 	(revision )
@@ -1,25 +1,0 @@
-#ifndef EP_TAG_HPP_INCLUDED
-#define EP_TAG_HPP_INCLUDED
-
-
-
-namespace ep_lib
-{
-  int print_comm_info(MPI_Comm comm);
-
-
-
-//  int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request);
-//  int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message);
-
-
-//  int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses);
-//  int MPI_Testany(int count, MPI_Request *array_of_requests, int *index, int *flag, MPI_Status *status);
-//  int MPI_Testsome(int incount, MPI_Request *array_of_requests, int *outcount, int *array_of_indices, MPI_Status *array_of_statuses);
-
-
-//  int MPI_Waitany(int count, MPI_Request *array_of_requests,  int *index, MPI_Status *array_of_statuses);
-//  int MPI_Waitsome(int incount, MPI_Request *array_of_requests, int *outcount, int *array_of_indices, MPI_Status *array_of_statuses);
-}
-
-#endif // EP_TAG_HPP_INCLUDED
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp	(revision 1539)
@@ -25,5 +25,4 @@
     {
       printf("MPI_Test : Error in request type\n");
- 
       exit(1);
     }
@@ -39,6 +38,4 @@
       
       ::MPI_Status mpi_status;
-      
-      
       ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status);
       
@@ -61,5 +58,4 @@
     
     return Request_Check();
-
   }
 
@@ -109,9 +105,7 @@
         
       }
-      
     }
-    
+
     return Request_Check();
-
   }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp	(revision 1539)
@@ -33,35 +33,4 @@
   }
 
-  /*
-  
-  MPI_Aint::MPI_Aint(void* aint)
-  {
-    mpi_aint = new ::MPI_Aint;
-    *(static_cast< ::MPI_Aint*>(mpi_aint)) = *(static_cast< ::MPI_Aint*>(aint));
-  }
-
-  MPI_Aint::MPI_Aint(int aint)
-  {
-    mpi_aint = new ::MPI_Aint;
-    *(static_cast< ::MPI_Aint*>(mpi_aint)) = aint;
-  }
-
-  MPI_Aint MPI_Aint::operator=(int a)
-  {
-    mpi_aint = new ::MPI_Aint;
-    *(static_cast< int*>(mpi_aint)) = a; 
-  }
-  
-  MPI_Fint::MPI_Fint(void* fint)
-  {
-    mpi_fint = new ::MPI_Fint;
-    *(static_cast< ::MPI_Fint*>(mpi_fint)) = *(static_cast< ::MPI_Fint*>(fint));
-  }
-
-  
-*/
-  
-
-
 }
 
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp	(revision 1539)
@@ -38,5 +38,4 @@
 #include "ep_barrier.hpp"
 #include "ep_comm.hpp"
-#include "ep_intercomm.hpp"
 #include "ep_window.hpp"
 
@@ -86,4 +85,6 @@
   static std::map<std::pair<int, int>, MPI_Comm >  fc_comm_map;
 
+  
+
 
 }
Index: /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp	(revision 1538)
+++ /XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp	(revision 1539)
@@ -26,5 +26,4 @@
     {
       printf("MPI_Wait : Error in request type\n");
- 
       exit(1);
     }
