Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_allgather.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_allgather.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_allgather.cpp	(revision 1527)
@@ -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/ep_dev/ep_allgatherv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_allgatherv.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_allgatherv.cpp	(revision 1527)
@@ -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/ep_dev/ep_allocate.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_allocate.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_allocate.cpp	(revision 1527)
@@ -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/ep_dev/ep_allreduce.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_allreduce.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_allreduce.cpp	(revision 1527)
@@ -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/ep_dev/ep_alltoall.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_alltoall.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_alltoall.cpp	(revision 1527)
@@ -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/ep_dev/ep_barrier.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp	(revision 1527)
@@ -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,35 +34,6 @@
 
     MPI_Barrier_local(comm);
-
-    return 0;
   }
 
-  int MPI_Barrier2(MPI_Comm comm)
-  {
-    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
-
-    MPI_Barrier_local(comm);
-
-    if(ep_rank_loc == 0)
-    {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-
-      ::MPI_Barrier(mpi_comm);
-    }
-
-    MPI_Barrier_local(comm);
-
-    return 0;
-  }
-
-  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/ep_dev/ep_bcast.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_bcast.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_bcast.cpp	(revision 1527)
@@ -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/ep_dev/ep_comm.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp	(revision 1527)
@@ -3,5 +3,4 @@
 
 #include "ep_message.hpp"
-#include "ep_intercomm.hpp"
 #include "ep_barrier.hpp"
 #include "ep_buffer.hpp"
@@ -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,5 +43,5 @@
     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;
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_create.cpp	(revision 1527)
@@ -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/ep_dev/ep_dup.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp	(revision 1527)
@@ -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/ep_dev/ep_exscan.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_exscan.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_exscan.cpp	(revision 1527)
@@ -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/ep_dev/ep_finalize.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_finalize.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_finalize.cpp	(revision 1527)
@@ -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/ep_dev/ep_free.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp	(revision 1527)
@@ -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);
   }
 
@@ -33,5 +23,5 @@
   }
 
-  int MPI_Comm_free_intracomm(MPI_Comm *comm)
+  int MPI_Comm_free_endpoint(MPI_Comm *comm)
   {
     Debug("MPI_Comm_free with EP_intracomm\n");
@@ -40,4 +30,5 @@
 
     ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
+    int ep_rank = (*comm)->ep_comm_ptr->size_rank_info[0].first;
     num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
 
@@ -46,4 +37,18 @@
     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,178 +108,4 @@
 
 
-  int MPI_Comm_free2(MPI_Comm *comm)
-  {
-    Debug("MPI_Comm_free with EP_intracomm\n");
-
-    int ep_rank_loc, num_ep;
-
-    ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
-    num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
-
-    MPI_Barrier2(*comm);
-
-    if(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;
-      
-
-      for(int i=0; i<num_ep; i++)
-      {
-        if((*comm)->is_intercomm)
-        {
-          (*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;
-        }
-
-        (*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 = %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;
-    }
-  }
-
-
-
-  int MPI_Comm_free_intercomm(MPI_Comm *comm)
-  {
-    int ep_rank;
-    MPI_Comm_rank(*comm, &ep_rank);
-    int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
-    int num_ep =      (*comm)->ep_comm_ptr->size_rank_info[1].second;
-    
-    int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; 
-    int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first;
-    int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second;
-
-    MPI_Barrier(*comm);
-
-    if(ep_rank_loc == 0)
-    {
-      (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear();
-#ifdef _showinfo
-      printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map);
-#endif
-      delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map;
-
-      (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear();
-#ifdef _showinfo
-      printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map);
-#endif
-      delete (*comm)->ep_comm_ptr->intercomm->local_rank_map;
-    }
-
-    if(newcomm_ep_rank_loc == 0)
-    {
-
-#ifdef _showinfo
-      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
-#endif
-      delete (*comm)->my_buffer;
-
-
-      
-#ifdef _showinfo        
-      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
-#endif
-      delete (*comm)->ep_barrier;
-      
-
-      (*comm)->ep_rank_map->clear();
-#ifdef _showinfo
-      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
-#endif
-      delete (*comm)->ep_rank_map;
-      
-#ifdef _showinfo
-      printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm);
-#endif
-      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm));
-
-      for(int i=0; i<newcomm_num_ep; i++)
-      {
-        (*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/ep_dev/ep_gather.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_gather.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_gather.cpp	(revision 1527)
@@ -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/ep_dev/ep_gatherv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_gatherv.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_gatherv.cpp	(revision 1527)
@@ -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/ep_dev/ep_init.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_init.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_init.cpp	(revision 1527)
@@ -15,5 +15,5 @@
     Debug("MPI_Init_thread with EP/MPI\n");
 
-    if(omp_get_thread_num() == 0)
+    #pragma omp master
     {
       ::MPI_Init_thread(argc, argv, required, provided);
@@ -26,5 +26,5 @@
     Debug("MPI_Init with EP/MPI\n");
 
-    if(omp_get_thread_num() == 0)
+    #pragma omp master
     {
       ::MPI_Init(argc, argv);
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp	(revision 1527)
@@ -14,5 +14,5 @@
 namespace ep_lib
 {
-  int MPI_Intercomm_create2(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
+  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);
@@ -371,4 +371,5 @@
 
     (*newintercomm)->inter_rank_map = new INTER_RANK_MAP;
+  
 
     int rank_info[2];
@@ -449,71 +450,3 @@
   }
 
-
-  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);
-
-    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;
-
-
-    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); 
-        
-      }
-      else
-      {
-        Debug("calling MPI_Intercomm_create_world\n");
-        return MPI_Intercomm_create_from_world(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);   
-      }
-      
-    }
-
-  }
-
-  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);
-    }
-  }
-
-
 }
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp	(revision 1527)
@@ -9,5 +9,5 @@
 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 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;
@@ -619,5 +619,5 @@
     // clean up //
     //////////////
-
+/*
     delete ranks_in_world_local;
     delete ranks_in_world_remote;
@@ -635,5 +635,5 @@
   }
 
-
+*/
 
   
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_unique.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_unique.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_unique.cpp	(revision 1527)
@@ -10,5 +10,5 @@
 {
 
-
+/*
   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)
   {
@@ -225,4 +225,4 @@
     return MPI_SUCCESS;
   }
-
+*/
 }
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_world.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_world.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_world.cpp	(revision 1527)
@@ -9,5 +9,5 @@
 {
 
-
+/*
   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)
   {
@@ -541,5 +541,5 @@
 
   }
-
+*/
   // #endif
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1527)
@@ -32,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++)
     {
@@ -57,6 +42,5 @@
     }
     printf("rank not find for EP_intracomm\n");
-    int err;
-    return MPI_Abort(comm, err);
+    return MPI_Abort(comm, 0);
   }
   
@@ -70,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);
   }
 
@@ -139,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/ep_dev/ep_lib.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1527)
@@ -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"
 
 
@@ -30,5 +28,4 @@
 
   int MPI_Comm_free(MPI_Comm* comm);
-  int MPI_Comm_free2(MPI_Comm* comm);
 
   int MPI_Finalize();
@@ -41,5 +38,4 @@
   
   int MPI_Comm_remote_size(MPI_Comm comm, int *size);
-  int MPI_Comm_remote_size2(MPI_Comm comm, int *size);
 
 
@@ -67,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);
 
@@ -93,6 +88,3 @@
 }
 
-//MPI_Datatype to_mpi(ep_lib::MPI_Datatype type);
-
-
 #endif // EP_LIB_HPP_INCLUDED
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_collective.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_collective.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_collective.hpp	(revision 1527)
@@ -10,6 +10,5 @@
 
   int MPI_Barrier(MPI_Comm comm);
-  int MPI_Barrier2(MPI_Comm comm);
-  
+ 
 
   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm);
@@ -47,12 +46,11 @@
 
   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_create2(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_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_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_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
@@ -62,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/ep_dev/ep_lib_endpoint.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_endpoint.hpp	(revision 1527)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_endpoint.hpp	(revision 1527)
@@ -0,0 +1,21 @@
+#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);
+
+}
+
+#endif // EP_LIB_ENDPOINT_HPP_INCLUDED
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intercomm.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intercomm.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intercomm.hpp	(revision 1527)
@@ -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: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intracomm.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_intracomm.hpp	(revision 1526)
+++ 	(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/ep_dev/ep_lib_mpi.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp	(revision 1527)
@@ -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);
@@ -28,6 +29,5 @@
 
   int MPI_Barrier_mpi(MPI_Comm comm);
-  
-  int MPI_Abort_mpi(MPI_Comm comm, int errorcode);
+
 }
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_merge.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_merge.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_merge.cpp	(revision 1527)
@@ -10,193 +10,77 @@
 {
 
-  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;
+    (*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/ep_dev/ep_message.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp	(revision 1527)
@@ -32,5 +32,5 @@
     std::list<MPI_Request* >::iterator it;
     
-//    show_EP_PendingRequests(EP_PendingRequests);
+    show_EP_PendingRequests(EP_PendingRequests);
     
     
@@ -46,13 +46,4 @@
       }
       
-      if((*(*it))->state == 2)
-      {
-        EP_PendingRequests->erase(it);
-        
-        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
-        it = EP_PendingRequests->begin();
-        continue;
-      }
-      
       Message_Check(((*(*it))->comm));
     }
@@ -72,14 +63,5 @@
       }
       
-      if((*(*it))->state == 2)
-      {
-        EP_PendingRequests->erase(it);
-        
-        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
-        it = EP_PendingRequests->begin();
-        continue;
-      }
-      
-      if((*(*it))->state == 0)
+      if((*(*it))->probed == false)
       {
         #pragma omp critical (_query0)
@@ -107,5 +89,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 +115,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 +178,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)
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_probe.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_probe.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_probe.cpp	(revision 1527)
@@ -8,8 +8,43 @@
   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)
@@ -24,5 +59,5 @@
     {
       Debug("MPI_Iprobe with EP\n");
-      
+
       *flag = false;
     
@@ -53,4 +88,6 @@
   }
 
+  
+
 
 
@@ -63,34 +100,6 @@
     {
       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;
-    }
-
-   
+      return MPI_Improbe_mpi(src, tag, comm, flag, message, status);
+    } 
 
     #pragma omp flush
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp	(revision 1527)
@@ -40,4 +40,10 @@
   {
     if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request);
+
+    if(comm->is_intercomm)
+    {
+      src = comm->inter_rank_map->at(src);
+      printf("new src = %d\n", src);
+    }
     
     Debug("MPI_Irecv with EP");
@@ -54,5 +60,5 @@
     (*request)->comm = comm;
     (*request)->type = 2;
-    (*request)->state = 0;
+    (*request)->probed = false;
     
 
@@ -118,5 +124,5 @@
     (*request)->ep_src = (*message)->ep_src;
     
-    (*request)->state = 1;
+    (*request)->probed = true;
 	
     ::MPI_Imrecv(buf, count, to_mpi_type(datatype), to_mpi_message_ptr(*message), to_mpi_request_ptr(*request));		
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_reduce.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_reduce.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_reduce.cpp	(revision 1527)
@@ -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/ep_dev/ep_reduce_scatter.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_reduce_scatter.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_reduce_scatter.cpp	(revision 1527)
@@ -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/ep_dev/ep_request.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_request.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_request.hpp	(revision 1527)
@@ -18,7 +18,8 @@
                 // 3: Imrecv 
                 
-      int state; // 0: new 
+      //int state; // 0: new 
                  // 1: imrecvd
                  // 2: tested or waited
+      bool probed;
                    
       void* buf;
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_scan.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_scan.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_scan.cpp	(revision 1527)
@@ -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/ep_dev/ep_scatter.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_scatter.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_scatter.cpp	(revision 1527)
@@ -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/ep_dev/ep_scatterv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_scatterv.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_scatterv.cpp	(revision 1527)
@@ -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/ep_dev/ep_send.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp	(revision 1527)
@@ -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/ep_dev/ep_size.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_size.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_size.cpp	(revision 1527)
@@ -22,28 +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 MPI_Comm_remote_size_mpi(comm, size);
-  }
-
-  int MPI_Comm_remote_size2(MPI_Comm comm, int *size)
-  {
-    if(comm->is_ep)
-    {
-      if(comm->is_intercomm)
-      {
-        Debug("MPI_Comm_remote_size with EP_intercomm");
-        return *size = comm->inter_rank_map->size();
-      }
-      return *size=0;
+      return *size = comm->is_intercomm? comm->inter_rank_map->size() : 0;
     }
     return MPI_Comm_remote_size_mpi(comm, size);
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_split.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_split.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_split.cpp	(revision 1527)
@@ -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: XIOS/dev/branch_openmp/extern/ep_dev/ep_tag.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_tag.hpp	(revision 1526)
+++ 	(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/ep_dev/ep_test.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp	(revision 1527)
@@ -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);
       
@@ -51,5 +48,5 @@
         status->ep_datatype = (*request)->ep_datatype;
         
-        (*request)->state = 2;
+        //(*request)->state = 2;
                 
         memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request");
@@ -61,5 +58,4 @@
     
     return Request_Check();
-
   }
 
@@ -101,5 +97,5 @@
         array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
         
-        array_of_requests[i]->state = 2;
+        //array_of_requests[i]->state = 2;
       
         memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request");
@@ -109,9 +105,7 @@
         
       }
-      
     }
-    
+
     return Request_Check();
-
   }
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_type.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_type.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_type.cpp	(revision 1527)
@@ -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/ep_dev/ep_type.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_type.hpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_type.hpp	(revision 1527)
@@ -38,5 +38,4 @@
 #include "ep_barrier.hpp"
 #include "ep_comm.hpp"
-#include "ep_intercomm.hpp"
 #include "ep_window.hpp"
 
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_wait.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_wait.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_wait.cpp	(revision 1527)
@@ -26,5 +26,4 @@
     {
       printf("MPI_Wait : Error in request type\n");
- 
       exit(1);
     }
@@ -41,5 +40,5 @@
     status->ep_datatype = (*request)->ep_datatype;
     
-    (*request)->state = 2;
+    //(*request)->state = 2;
 
     memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Wait, delete (*request)->mpi_request");
@@ -95,5 +94,5 @@
       array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
       
-      array_of_requests[i]->state = 2;
+      //array_of_requests[i]->state = 2;
       
       memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request");
Index: XIOS/dev/branch_openmp/extern/ep_dev/main.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1526)
+++ XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1527)
@@ -31,4 +31,174 @@
   MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
   MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+
+  #pragma omp parallel default(shared)
+  {
+    MPI_Comm_rank(MPI_COMM_WORLD , &mpi_rank);
+
+    int num_ep = omp_get_num_threads();
+    MPI_Info info;
+
+    //printf("mpi_rank = %d, thread_num = %d\n", mpi_rank, omp_get_thread_num());
+
+    MPI_Comm *ep_comm;
+    #pragma omp master
+    {
+      MPI_Comm *ep_comm;
+      MPI_Comm_create_endpoints(MPI_COMM_WORLD->mpi_comm, num_ep, info, ep_comm);
+      passage = ep_comm;  
+    }
+
+    #pragma omp barrier
+
+    MPI_Comm comm; // this should act as EP_COMM_WORLD
+        
+    comm = passage[omp_get_thread_num()];
+
+    // TEST OF COMM_SPLIT
+    {
+
+      MPI_Barrier(comm);
+      int rank, size;
+      MPI_Comm_rank(comm, &rank);
+      MPI_Comm_size(comm, &size);
+    
+      int tab_color[16] = {2, 2, 2, 1, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1}; // used for config 1
+      int tab_key[16]   = {2, 1, 4, 1, 0, 4, 3, 3, 4, 3, 4, 4, 4, 0, 0, 2}; // used for config 1
+
+      int color = tab_color[rank];
+      int key = tab_key[rank];
+      
+  
+      MPI_Comm split_comm;
+      MPI_Comm_split(comm, color, key, &split_comm);
+
+
+    
+      int split_rank, split_size;
+      MPI_Comm_rank(split_comm, &split_rank);
+      MPI_Comm_size(split_comm, &split_size);
+    
+#ifdef _Memory_check    
+      printf("rank = %d, color = %d, key = %d, split_rank = %d, local_rank=%d\n", rank, color, key, split_rank, split_comm->ep_comm_ptr->size_rank_info[1].first);
+#endif
+
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+      
+      if(rank == 0) printf("            \t MPI_Comm_split \t OK\n");
+
+
+      int local_leader = 0;
+      int remote_leader = color==2? 13: 4; // used for config 1
+
+      MPI_Comm peer_comm = comm;
+
+      MPI_Comm inter_comm;
+      MPI_Intercomm_create(split_comm, local_leader, peer_comm, remote_leader, 99, &inter_comm);
+
+      int inter_rank, inter_size, remote_size;
+      MPI_Comm_rank(inter_comm, &inter_rank);
+      MPI_Comm_size(inter_comm, &inter_size);
+      MPI_Comm_remote_size(inter_comm, &remote_size);
+      
+      
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+
+      if(rank == 0) printf("            \t MPI_Intercomm_create \t OK\n");
+
+      //printf("rank = %d, split_rank = %d, split_size = %d, inter_rank=%d, inter_size=%d, remote_size=%d\n", rank, split_rank, split_size, inter_rank, inter_size, remote_size);
+
+
+      MPI_Comm_free(&split_comm);
+
+      
+      MPI_Barrier(comm);
+
+
+      if(color==2 && split_rank==0)
+      {
+        double sendbuf[9]={1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};
+        MPI_Request send_request;
+        MPI_Status send_status;
+        MPI_Isend(sendbuf, 9, MPI_DOUBLE, 0, 10, inter_comm, &send_request);
+        MPI_Wait(&send_request, &send_status);
+      }
+
+      if(color==1 && split_rank==0)
+      {
+        double recvbuf[9];
+        MPI_Request recv_request;
+        MPI_Status recv_status;
+        MPI_Irecv(recvbuf, 9, MPI_DOUBLE, 0, 10, inter_comm, &recv_request);
+        MPI_Wait(&recv_request, &recv_status);
+        for(int i=0; i<9; i++)
+        {
+          printf("recvbuf[%d] = %lf\n", i, recvbuf[i]);
+        }
+      }
+
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+
+      if(rank == 0) printf("            \t Test iP2P for intercomm \t OK\n");
+
+
+      MPI_Comm inter_comm_dup;
+      MPI_Comm_dup(inter_comm, &inter_comm_dup);
+      int inter_dup_rank, inter_dup_size;
+      MPI_Comm_rank(inter_comm_dup, &inter_dup_rank);
+      MPI_Comm_size(inter_comm_dup, &inter_dup_size);
+
+      //printf("rank = %d, split_rank = %d, split_size = %d, inter_dup_rank=%d, inter_dup_size=%d\n", rank, split_rank, split_size, inter_dup_rank, inter_dup_size);
+
+
+
+      MPI_Comm inter_comm_dup_merged;
+      bool high;
+      if(color==2) high=true;
+      else high = false;
+
+      MPI_Intercomm_merge(inter_comm_dup, high, &inter_comm_dup_merged);
+      int merged_rank, merged_size;
+      MPI_Comm_rank(inter_comm_dup_merged, &merged_rank);
+      MPI_Comm_size(inter_comm_dup_merged, &merged_size);
+
+      //printf("merged_rank=%d, merged_rank_loc=%d, root_ep_loc = %d\n", merged_rank, inter_comm_dup_merged->ep_comm_ptr->size_rank_info[1].first, inter_comm_dup_merged->ep_rank_map->at(0).first);
+
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+            
+      int sendbuf=0;
+      if(merged_rank == 0) sendbuf = 99;
+      MPI_Bcast(&sendbuf, 1, MPI_INT, 0, inter_comm_dup_merged);
+      printf("merged_rank = %d, sendbuf = %d\n", merged_rank, sendbuf);
+
+
+
+      MPI_Barrier(comm);
+
+      MPI_Comm_free(&inter_comm_dup_merged);
+      MPI_Comm_free(&inter_comm_dup);
+
+
+
+
+      MPI_Comm_free(&inter_comm);
+           
+    }
+    
+    
+
+    MPI_Barrier(comm);
+    MPI_Comm_free(&comm);
+  }
+
+  //MPI_Finalize();
+  //return 0;
+
+
+
  
   
@@ -899,4 +1069,10 @@
       // TEST OF GATHER
       {
+        int inter_comm_dup_merged_rank;
+        MPI_Comm_rank(inter_comm_dup_merged, &inter_comm_dup_merged_rank);
+
+        int inter_comm_dup_merged_size;
+        MPI_Comm_size(inter_comm_dup_merged, &inter_comm_dup_merged_size);
+        
         
 
@@ -907,6 +1083,11 @@
           gather_root = rand() % inter_comm_dup_merged_size;
         }
+
+
   
         MPI_Bcast(&gather_root, 1, MPI_INT, 0, inter_comm_dup_merged);
+
+        printf("rank = %d, inter_comm_dup_merged_rank = %d, inter_comm_dup_merged_size = %d, gather_root = %d\n", rank, inter_comm_dup_merged_rank, inter_comm_dup_merged_size, gather_root);
+
 
         double sendbuf[2];
@@ -1133,4 +1314,5 @@
       }
 
+
       MPI_Barrier(comm);
       MPI_Barrier(comm);
@@ -1202,5 +1384,5 @@
 
       MPI_Comm inter_comm;
-      MPI_Intercomm_create2(split_comm, local_leader, peer_comm, remote_leader, 99, &inter_comm);
+      MPI_Intercomm_create(split_comm, local_leader, peer_comm, remote_leader, 99, &inter_comm);
 
       int inter_rank;
@@ -1214,6 +1396,6 @@
       MPI_Comm_free(&split_comm);
 
-      MPI_Barrier2(inter_comm);
-      MPI_Comm_free2(&inter_comm);
+      MPI_Barrier(inter_comm);
+      MPI_Comm_free(&inter_comm);
       
     }
