Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_barrier.cpp	(revision 1515)
@@ -42,5 +42,8 @@
   {
 
-    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int ep_rank;
+    MPI_Comm_rank(comm, &ep_rank);
+
+    int ep_rank_loc = comm->ep_rank_map->at(ep_rank).first;
 
     MPI_Barrier_local(comm);
@@ -48,6 +51,6 @@
     if(ep_rank_loc == 0)
     {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm);
-      ::MPI_Barrier(mpi_comm);
+      //::MPI_Comm mpi_comm = to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm);
+      ::MPI_Barrier(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm));
     }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_comm.hpp	(revision 1515)
@@ -26,4 +26,6 @@
                                       // 2: mpi_rank,    mpi_size
 
+                                      // for intercomm : = size_rank_info of local_comm
+
 
     ep_comm **comm_list;
@@ -52,5 +54,5 @@
     BUFFER     *my_buffer;
     ep_barrier *ep_barrier;
-    EP_RANK_MAP   *ep_rank_map;
+    EP_RANK_MAP   *ep_rank_map;      // for intercomm : = ep_rank_map of newcomm
     void* mpi_comm;
     ep_communicator *ep_comm_ptr;
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_dup.cpp	(revision 1515)
@@ -91,5 +91,5 @@
 
         out_comm[i]->ep_comm_ptr->intercomm->inter_rank_map = new RANK_MAP;
-        out_comm[i]->ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP;
+        out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map = new RANK_MAP;
         out_comm[i]->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
 
@@ -101,5 +101,5 @@
 
         map_size = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->size();
-        out_comm[i]->ep_comm_ptr->intercomm->local_rank_map->resize(map_size);
+        out_comm[i]->ep_comm_ptr->intercomm->loc_rank_map->resize(map_size);
         for(int ii=0; ii<map_size; ii++)
           out_comm[i]->ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm->local_rank_map->at(ii);
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_free.cpp	(revision 1515)
@@ -92,7 +92,12 @@
   {
     int ep_rank_loc, num_ep;
+    //MPI_Barrier(*comm);
+
+    return 0;
 
     ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
     num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
+
+
 
     //MPI_Barrier(*comm);
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.cpp	(revision 1515)
@@ -24,4 +24,41 @@
 
     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);   
+      }
+      
+    }
+
+
 
 
@@ -174,7 +211,5 @@
     }
 
-    if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_kernel\n");
-
-    return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
+    
 
   }
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm.hpp	(revision 1515)
@@ -18,7 +18,12 @@
     void *mpi_inter_comm;
 
-    INTERCOMM_RANK_MAP *intercomm_rank_map;
+    INTERCOMM_RANK_MAP *intercomm_rank_map;  // quadruple : ep_rank_in_local_comm, ep_rank_loc_in_newcomm, mpi_rank_in_new_comm, comm_label
+                                             // of remote_comm
+    
+    EP_RANK_MAP *local_rank_map;             // = ep_rank_map of local_comm
+
+
     RANK_MAP *inter_rank_map;
-    RANK_MAP *local_rank_map;
+    RANK_MAP *loc_rank_map;
     RANK_MAP *remote_rank_map;
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_kernel.cpp	(revision 1515)
@@ -14,32 +14,93 @@
     int ep_size, num_ep, mpi_size;
 
-    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
+    ep_rank     = local_comm->ep_comm_ptr->size_rank_info[0].first;
     ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-
-    // step 1 : local leaders exchange ep_size then bcast to all ep in local_comm
+    mpi_rank    = local_comm->ep_comm_ptr->size_rank_info[2].first;
+    ep_size     = local_comm->ep_comm_ptr->size_rank_info[0].second;
+    num_ep      = local_comm->ep_comm_ptr->size_rank_info[1].second;
+    mpi_size    = local_comm->ep_comm_ptr->size_rank_info[2].second;
+
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // step 1 : local leaders exchange ep_size, leader_rank_in_peer, leader_rank_in_peer_mpi, leader_rank_in_world. //
+    //          local leaders bcast results to all ep in local_comm                                                 //
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    bool is_local_leader = ep_rank==local_leader? true: false;
+
+
+    
+    int local_leader_rank_in_peer;
+    int local_leader_rank_in_peer_mpi;
+    int local_leader_rank_in_world;
 
     int remote_ep_size;
-    bool is_local_leader = ep_rank==local_leader? true: false;
+    int remote_leader_rank_in_peer;
+    int remote_leader_rank_in_peer_mpi;
+    int remote_leader_rank_in_world;
+
+    int send_quadruple[4];
+    int recv_quadruple[4];
+
 
     if(is_local_leader)
     {
-      MPI_Request request[2];
-      MPI_Status status[2];
-      MPI_Isend(&ep_size, 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(&remote_ep_size, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-      MPI_Waitall(2, request, status);
-    }
-
-    MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm);
-
-#ifdef _showinfo
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    #pragma omp critical(stdoutput)
+      MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer);
+      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi);
+      ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world);
+
+      send_quadruple[0] = ep_size;
+      send_quadruple[1] = local_leader_rank_in_peer;
+      send_quadruple[2] = local_leader_rank_in_peer_mpi;
+      send_quadruple[3] = local_leader_rank_in_world;
+
+      MPI_Request request;
+      MPI_Status status;
+
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+
+      remote_ep_size                 = recv_quadruple[0];
+      remote_leader_rank_in_peer     = recv_quadruple[1];
+      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
+      remote_leader_rank_in_world    = recv_quadruple[3];
+#ifdef _showinfo
+      printf("peer_rank = %d, packed exchange OK\n", local_leader_rank_in_peer);
+#endif
+    }
+
+    MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm);
+    MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm);
+
+    if(!is_local_leader)
+    {
+      local_leader_rank_in_peer     = send_quadruple[1];
+      local_leader_rank_in_peer_mpi = send_quadruple[2];
+      local_leader_rank_in_world    = send_quadruple[3];
+
+      remote_ep_size                 = recv_quadruple[0];
+      remote_leader_rank_in_peer     = recv_quadruple[1];
+      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
+      remote_leader_rank_in_world    = recv_quadruple[3];
+    }
+
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
     printf("peer_rank = %d, ep_size = %d, remote_ep_size = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_size, remote_ep_size);
     MPI_Barrier(peer_comm);
@@ -47,5 +108,7 @@
 #endif
 
-    // step 2 : gather ranks in world for both local and remote comm
+    ///////////////////////////////////////////////////////////////////
+    // step 2 : gather ranks in world for both local and remote comm //
+    ///////////////////////////////////////////////////////////////////
 
     int rank_in_world;
@@ -59,9 +122,26 @@
     if(is_local_leader)
     {
-      MPI_Request request[2];
-      MPI_Status status[2];
-      MPI_Isend(ranks_in_world_local,  ep_size,        MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-      MPI_Waitall(2, request, status);
+      MPI_Request request;
+      MPI_Status status;
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+#ifdef _showinfo
+      printf("peer_rank = %d, ranks_in_world exchange OK\n", local_leader_rank_in_peer);
+#endif
     }
 
@@ -136,47 +216,10 @@
 #endif
 
-
-    // step 3 : determine the priority and ownership of each ep
-
-    int local_leader_rank_in_peer;
-    int remote_leader_rank_in_peer;
-
-    if(is_local_leader) MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer);
-
-    if(is_local_leader)
-    {
-      MPI_Request request[2];
-      MPI_Status status[2];
-      MPI_Isend(&local_leader_rank_in_peer,  1, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(&remote_leader_rank_in_peer, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-      MPI_Waitall(2, request, status);
-    }
-
-    MPI_Bcast(&local_leader_rank_in_peer,  1, MPI_INT, local_leader, local_comm);
-    MPI_Bcast(&remote_leader_rank_in_peer, 1, MPI_INT, local_leader, local_comm);
+    //////////////////////////////////////////////////////////////
+    // step 3 : determine the priority and ownership of each ep //
+    //////////////////////////////////////////////////////////////
 
     bool priority = local_leader_rank_in_peer > remote_leader_rank_in_peer? true : false;
 
-#ifdef _showinfo
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-    printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer);
-    MPI_Barrier(peer_comm);
-    MPI_Barrier(peer_comm);
-#endif
-
-    int local_leader_rank_in_world = ranks_in_world_local[local_leader];
-    int remote_leader_rank_in_world;
-
-    if(is_local_leader)
-    {
-      MPI_Request request[2];
-      MPI_Status status[2];
-      MPI_Isend(&local_leader_rank_in_world,  1, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(&remote_leader_rank_in_world, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-      MPI_Waitall(2, request, status);
-    }
-
-    MPI_Bcast(&remote_leader_rank_in_world, 1, MPI_INT, local_leader, local_comm);
 
     int ownership;
@@ -196,4 +239,13 @@
       }
     }
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+#endif
+
     
 #ifdef _showinfo
@@ -205,6 +257,7 @@
 #endif
 
-
-    // step 4 : extract local_comm and create intercomm
+    //////////////////////////////////////////////////////
+    // step 4 : extract local_comm and create intercomm //
+    //////////////////////////////////////////////////////
 
     bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world);
@@ -268,26 +321,11 @@
       ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));
 
-      int local_leader_rank_in_peer_mpi;
-      int remote_leader_rank_in_peer_mpi;
-
-      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi);
-
-      if(is_local_leader)
-      {
-        MPI_Request request[2];
-        MPI_Status status[2];
-        MPI_Isend(&local_leader_rank_in_peer_mpi,  1, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-        MPI_Irecv(&remote_leader_rank_in_peer_mpi, 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-        MPI_Waitall(2, request, status);
-      }
-
-      ::MPI_Bcast(&remote_leader_rank_in_peer_mpi, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));      
-
 
       if(ownership)
         ::MPI_Intercomm_create(*extracted_comm, local_leader_rank_in_extracted_comm, to_mpi_comm(peer_comm->mpi_comm), remote_leader_rank_in_peer_mpi, tag, mpi_inter_comm);
 
-
-      // step 5 :: determine new num_ep
+      ////////////////////////////////////
+      // step 5 :: determine new num_ep //
+      ////////////////////////////////////
 
       int num_ep_count=0;
@@ -305,8 +343,8 @@
       }
 
-      //printf("peer_rank = %d, num_ep_count = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, num_ep_count);
-
-
-      // step 6 : create endpoints from extracted_comm 
+
+      ///////////////////////////////////////////////////
+      // step 6 : create endpoints from extracted_comm //
+      ///////////////////////////////////////////////////
 
       if(ownership)
@@ -323,6 +361,4 @@
           ep_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm;
         }
-
-        //delete ep_comm[0]->ep_rank_map;
 
 
@@ -397,6 +433,7 @@
 #endif
 
-
-    // step 7 : create intercomm_rank_map for local leaders
+    //////////////////////////////////////////////////////////
+    // step 7 : create intercomm_rank_map for local leaders //
+    //////////////////////////////////////////////////////////
     
     int my_quadruple[4];
@@ -431,9 +468,26 @@
     if(is_local_leader)
     {
-      MPI_Request request[2];
-      MPI_Status status[2];
-      MPI_Isend(local_quadruple_list,  4*ep_size,        MPI_INT, remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
-      MPI_Waitall(2, request, status);
+      MPI_Request request;
+      MPI_Status status;
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);        
+
+        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);       
+      }
+#ifdef _showinfo
+      printf("peer_rank = %d, quadruple_list exchange OK\n", local_leader_rank_in_peer);
+#endif
     }
 
@@ -448,6 +502,7 @@
     }
 
-
-    // step 8 : associate intercomm_rank_map to endpoints
+    ////////////////////////////////////////////////////////
+    // step 8 : associate intercomm_rank_map to endpoints //
+    ////////////////////////////////////////////////////////
 
     int *leader_rank_in_world_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second];
@@ -467,11 +522,6 @@
     if(is_involved)
     {
-      if((*newintercomm)->ep_comm_ptr->size_rank_info[1].first == 0)
-      {
-        (*newintercomm)->ep_rank_map->clear();
-        delete (*newintercomm)->ep_rank_map;
-      }
-      (*newintercomm)->ep_rank_map = new EP_RANK_MAP[ep_size];
-      *((*newintercomm)->ep_rank_map) = *(local_comm->ep_rank_map);
+      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP[ep_size];
+      *((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map) = *(local_comm->ep_rank_map);
     }
 
@@ -491,11 +541,12 @@
       }
       (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map;
-      (*newintercomm)->ep_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_rank_map;
-    }
-
-
-    //printf("peer_rank = %d, intercomm_rank_map add = %p\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map);
-    
-
+      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map;
+    }
+
+    (*newintercomm)->ep_comm_ptr->size_rank_info[0]=local_comm->ep_comm_ptr->size_rank_info[0];
+    (*newintercomm)->ep_comm_ptr->size_rank_info[1]=local_comm->ep_comm_ptr->size_rank_info[1];
+    (*newintercomm)->ep_comm_ptr->size_rank_info[2]=local_comm->ep_comm_ptr->size_rank_info[2];
+    
+/*
     if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5)
     {
@@ -512,6 +563,4 @@
     }
 
-    //printf("peer_rank = %d, rank_map add = %p\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_rank_map);
-
 
     if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5)
@@ -522,7 +571,8 @@
       }
     }
-
-
-    // clean up
+*/
+    //////////////
+    // clean up //
+    //////////////
 
     delete ranks_in_world_local;
@@ -541,812 +591,6 @@
   }
 
-  int MPI_Intercomm_create_kernel_bkp(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
-  {
-    int ep_rank, ep_rank_loc, mpi_rank;
-    int ep_size, num_ep, mpi_size;
-
-    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-
-    std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm
-                                    //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm
-
-    int rank_in_world;
-    int rank_in_local_parent;
-
-    int rank_in_peer_mpi[2];
-
-    int local_ep_size = ep_size;
-    int remote_ep_size;
-
-
-    ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm->mpi_comm);
-
-    
-    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
-    ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent);
-    
-
-    bool is_proc_master = false;
-    bool is_local_leader = false;
-    bool is_final_master = false;
-
-
-    if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;}
-    if(ep_rank_loc == 0 && mpi_rank != local_comm->ep_rank_map->at(local_leader).second) is_proc_master = true;
-
-
-    int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm
-
-    int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader
-
-
-    std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm
-
-    std::vector<int> new_rank_info[4];
-    std::vector<int> new_ep_info[2];
-
-    std::vector<int> offset;
-
-    if(is_proc_master)
-    {
-
-      size_info[0] = mpi_size;
-
-      rank_info[0].resize(size_info[0]);
-      rank_info[1].resize(size_info[0]);
-
-
-
-      ep_info[0].resize(size_info[0]);
-
-      vector<int> send_buf(6);
-      vector<int> recv_buf(3*size_info[0]);
-
-      send_buf[0] = rank_in_world;
-      send_buf[1] = rank_in_local_parent;
-      send_buf[2] = num_ep;
-
-      ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm);
-
-      for(int i=0; i<size_info[0]; i++)
-      {
-        rank_info[0][i] = recv_buf[3*i];
-        rank_info[1][i] = recv_buf[3*i+1];
-        ep_info[0][i]   = recv_buf[3*i+2];
-      }
-
-      if(is_local_leader)
-      {
-        leader_info[0] = rank_in_world;
-        leader_info[1] = remote_leader;
-
-        ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &rank_in_peer_mpi[0]);
-
-        send_buf[0] = size_info[0];
-        send_buf[1] = local_ep_size;
-        send_buf[2] = rank_in_peer_mpi[0];
-
-        
-        
-        MPI_Request requests[2];
-        MPI_Status statuses[2];
-        
-        MPI_Isend(send_buf.data(), 3, MPI_INT, remote_leader, tag, peer_comm, &requests[0]);
-        MPI_Irecv(recv_buf.data(), 3, MPI_INT, remote_leader, tag, peer_comm, &requests[1]);
-
-
-        MPI_Waitall(2, requests, statuses);
-        
-        size_info[1] = recv_buf[0];
-        remote_ep_size = recv_buf[1];
-        rank_in_peer_mpi[1] = recv_buf[2];
-
-      }
-
-
-
-      send_buf[0] = size_info[1];
-      send_buf[1] = leader_info[0];
-      send_buf[2] = leader_info[1];
-      send_buf[3] = rank_in_peer_mpi[0];
-      send_buf[4] = rank_in_peer_mpi[1];
-
-      ::MPI_Bcast(send_buf.data(), 5, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      size_info[1] = send_buf[0];
-      leader_info[0] = send_buf[1];
-      leader_info[1] = send_buf[2];
-      rank_in_peer_mpi[0] = send_buf[3];
-      rank_in_peer_mpi[1] = send_buf[4];
-
-
-      rank_info[2].resize(size_info[1]);
-      rank_info[3].resize(size_info[1]);
-
-      ep_info[1].resize(size_info[1]);
-
-      send_buf.resize(3*size_info[0]);
-      recv_buf.resize(3*size_info[1]);
-
-      if(is_local_leader)
-      {
-        MPI_Request requests[2];
-        MPI_Status statuses[2];
-
-        std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() );
-        std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] );
-        std::copy ( ep_info[0].data(),   ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[0] );
-
-        MPI_Isend(send_buf.data(), 3*size_info[0], MPI_INT, remote_leader, tag+1, peer_comm, &requests[0]);
-        MPI_Irecv(recv_buf.data(), 3*size_info[1], MPI_INT, remote_leader, tag+1, peer_comm, &requests[1]);
-        
-        MPI_Waitall(2, requests, statuses);
-      }
-
-      ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() );
-      std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin()  );
-      std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() );
-
-
-      offset.resize(size_info[0]);
-
-      if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader
-      {
-
-        bool found = false;
-        int ep_local;
-        int ep_remote;
-        for(int i=0; i<size_info[0]; i++)
-        {
-          int target = rank_info[0][i];
-          found = false;
-          for(int j=0; j<size_info[1]; j++)
-          {
-            if(target == rank_info[2][j])
-            {
-              found = true;
-              ep_local = ep_info[0][j];
-              ep_remote = ep_info[1][j];
-              break;
-            }
-          }
-          if(found)
-          {
-
-            if(target == leader_info[0]) // the leader is doubled in remote
-            {
-              new_rank_info[0].push_back(target);
-              new_rank_info[1].push_back(rank_info[1][i]);
-
-              new_ep_info[0].push_back(ep_local + ep_remote);
-              offset[i] = 0;
-            }
-            else
-            {
-              offset[i] = ep_local;
-            }
-          }
-          else
-          {
-            new_rank_info[0].push_back(target);
-            new_rank_info[1].push_back(rank_info[1][i]);
-
-            new_ep_info[0].push_back(ep_info[0][i]);
-
-            offset[i] = 0;
-          }
-
-        }
-      }
-
-      else // erase rank doubled with remote leader
-      {
-
-        bool found = false;
-        int ep_local;
-        int ep_remote;
-        for(int i=0; i<size_info[0]; i++)
-        {
-          int target = rank_info[0][i];
-          found = false;
-          for(int j=0; j<size_info[1]; j++)
-          {
-
-            if(target == rank_info[2][j])
-            {
-              found = true;
-              ep_local = ep_info[0][j];
-              ep_remote = ep_info[1][j];
-              break;
-            }
-          }
-          if(found)
-          {
-            if(target != leader_info[1])
-            {
-              new_rank_info[0].push_back(target);
-              new_rank_info[1].push_back(rank_info[1][i]);
-
-              new_ep_info[0].push_back(ep_local + ep_remote);
-              offset[i] = 0;
-            }
-            else // found remote leader
-            {
-              offset[i] = ep_remote;
-            }
-          }
-          else
-          {
-            new_rank_info[0].push_back(target);
-            new_rank_info[1].push_back(rank_info[1][i]);
-
-            new_ep_info[0].push_back(ep_info[0][i]);
-            offset[i] = 0;
-          }
-        }
-      }
-
-      if(offset[mpi_rank] == 0)
-      {
-        is_final_master = true;
-      }
-
-
-      //! size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote
-
-      if(is_local_leader)
-      {
-        size_info[2] = new_ep_info[0].size();
-        MPI_Request requests[2];
-        MPI_Status statuses[2];
-        MPI_Isend(&size_info[2], 1, MPI_INT, remote_leader, tag+2, peer_comm, &requests[0]);
-        MPI_Irecv(&size_info[3], 1, MPI_INT, remote_leader, tag+2, peer_comm, &requests[1]);
-         
-        MPI_Waitall(2, requests, statuses);
-      }
-
-      ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      new_rank_info[2].resize(size_info[3]);
-      new_rank_info[3].resize(size_info[3]);
-      new_ep_info[1].resize(size_info[3]);
-
-      send_buf.resize(size_info[2]);
-      recv_buf.resize(size_info[3]);
-
-      if(is_local_leader)
-      {
-        MPI_Request requests[2];
-        MPI_Status statuses[2];
-
-        std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() );
-        std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] );
-        std::copy ( new_ep_info[0].data(),   new_ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[2] );
-
-        MPI_Isend(send_buf.data(), 3*size_info[2], MPI_INT, remote_leader, tag+3, peer_comm, &requests[0]);
-        MPI_Irecv(recv_buf.data(), 3*size_info[3], MPI_INT, remote_leader, tag+3, peer_comm, &requests[1]);
-        
-        MPI_Waitall(2, requests, statuses);
-      }
-
-      ::MPI_Bcast(recv_buf.data(),   3*size_info[3], to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      std::copy ( recv_buf.data(), recv_buf.data() + size_info[3], new_rank_info[2].begin() );
-      std::copy ( recv_buf.data() + size_info[3], recv_buf.data() + 2*size_info[3], new_rank_info[3].begin()  );
-      std::copy ( recv_buf.data() + 2*size_info[3], recv_buf.data() + 3*size_info[3], new_ep_info[1].begin() );
-
-    }
-
-    
-
-    if(is_proc_master)
-    {
-      //! leader_info[4]: 2-> rank of local leader in new_group generated comm;
-                      // 3-> rank of remote leader in new_group generated comm;
-      ::MPI_Group local_group;
-      ::MPI_Group new_group;
-      ::MPI_Comm *new_comm = new ::MPI_Comm;
-      ::MPI_Comm *intercomm = new ::MPI_Comm;
-
-      ::MPI_Comm_group(local_mpi_comm, &local_group);
-
-      ::MPI_Group_incl(local_group, size_info[2], new_rank_info[1].data(), &new_group);
-
-      ::MPI_Comm_create(local_mpi_comm, new_group, new_comm);
-
-
-
-      if(is_local_leader)
-      {
-        ::MPI_Comm_rank(*new_comm, &leader_info[2]);
-      }
-
-      ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
-
-      if(new_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
-      {
-
-        ::MPI_Barrier(*new_comm);
-
-        ::MPI_Intercomm_create(*new_comm, leader_info[2], to_mpi_comm(peer_comm->mpi_comm), rank_in_peer_mpi[1], tag, intercomm);
-
-        int id;
-
-        ::MPI_Comm_rank(*new_comm, &id);
-        int my_num_ep = new_ep_info[0][id];
-
-        MPI_Comm *ep_intercomm;
-        MPI_Info info;
-        MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm);
-
-
-        for(int i= 0; i<my_num_ep; i++)
-        {
-          ep_intercomm[i]->is_intercomm = true;
-
-          ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
-          ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = intercomm;
-          ep_intercomm[i]->ep_comm_ptr->comm_label = leader_info[0];
-        }
-
-
-        #pragma omp critical (write_to_tag_list)
-        tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm));
-        //printf("tag_list size = %lu\n", tag_list.size());
-      }
-    }
-
-    vector<int> bcast_buf(8);
-    if(is_local_leader)
-    {
-      std::copy(size_info, size_info+4, bcast_buf.begin());
-      std::copy(leader_info, leader_info+4, bcast_buf.begin()+4);
-    }
-
-    MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm);
-
-    if(!is_local_leader)
-    {
-      std::copy(bcast_buf.begin(), bcast_buf.begin()+4, size_info);
-      std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info);
-    }
-
-    if(!is_local_leader)
-    {
-      new_rank_info[1].resize(size_info[2]);
-      ep_info[1].resize(size_info[1]);
-      offset.resize(size_info[0]);
-    }
-
-    bcast_buf.resize(size_info[2]+size_info[1]+size_info[0]+1);
-
-    if(is_local_leader)
-    {
-      bcast_buf[0] = remote_ep_size;
-      std::copy(new_rank_info[1].data(), new_rank_info[1].data()+size_info[2], bcast_buf.begin()+1);
-      std::copy(ep_info[1].data(), ep_info[1].data()+size_info[1], bcast_buf.begin()+size_info[2]+1);
-      std::copy(offset.data(), offset.data()+size_info[0], bcast_buf.begin()+size_info[2]+size_info[1]+1);
-    }
-
-    MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, MPI_INT, local_leader, local_comm);
-
-    if(!is_local_leader)
-    {
-      remote_ep_size = bcast_buf[0];
-      std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin());
-      std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin());
-      std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin());
-    }
-
-    int my_position = offset[rank_in_local_parent]+ep_rank_loc;
-    
-    MPI_Barrier_local(local_comm);
-    #pragma omp flush
-
-
-    #pragma omp critical (read_from_tag_list)
-    {
-      bool found = false;
-      while(!found)
-      {
-        for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1])))
-          {
-            *newintercomm = iter->second[my_position];
-            found = true;
-            break;
-          }
-        }
-      }
-    }
-
-    MPI_Barrier(local_comm);
-
-    if(is_local_leader)
-    {
-      int local_flag = true;
-      int remote_flag = false;
-      MPI_Request mpi_requests[2];
-      MPI_Status mpi_statuses[2];
-      
-      MPI_Isend(&local_flag, 1, MPI_INT, remote_leader, tag, peer_comm, &mpi_requests[0]);
-      MPI_Irecv(&remote_flag, 1, MPI_INT, remote_leader, tag, peer_comm, &mpi_requests[1]);
-      
-      MPI_Waitall(2, mpi_requests, mpi_statuses);
-    }
-
-
-    MPI_Barrier(local_comm);
-
-    if(is_proc_master)
-    {
-      for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-      {
-        if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1])))
-        {
-          tag_list.erase(iter);
-          break;
-        }
-      }
-    }
-
-    int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
-    int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size;
-
-    intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first;
-    intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
-    intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
-    intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second;
-    intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second;
-    intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second;
-
-    MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm);
-
-    int my_rank_map_elem[2];
-
-    my_rank_map_elem[0] = intercomm_ep_rank;
-    my_rank_map_elem[1] = (*newintercomm)->ep_comm_ptr->comm_label;
-
-    vector<pair<int, int> > local_rank_map_array;
-    vector<pair<int, int> > remote_rank_map_array;
-
-
-    (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP;
-    (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size);
-
-    MPI_Allgather(my_rank_map_elem, 2, MPI_INT, 
-      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm);
-
-    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
-    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size);
-
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
-
-    int local_intercomm_size = intercomm_ep_size;
-    int remote_intercomm_size;
-
-    int new_bcast_root_0 = 0;
-    int new_bcast_root = 0;
-
-
-    if(is_local_leader)
-    {
-      MPI_Request requests[4];
-      MPI_Status statuses[4];
-      
-      MPI_Isend((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, MPI_INT, remote_leader, tag+4, peer_comm, &requests[0]);
-      MPI_Irecv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, remote_leader, tag+4, peer_comm, &requests[1]);
-
-      MPI_Isend(&local_intercomm_size, 1, MPI_INT, remote_leader, tag+5, peer_comm, &requests[2]);
-      MPI_Irecv(&remote_intercomm_size, 1, MPI_INT, remote_leader, tag+5, peer_comm, &requests[3]);
-      
-      MPI_Waitall(4, requests, statuses);
-
-      new_bcast_root_0 = intercomm_ep_rank;
-    }
-
-    MPI_Allreduce(&new_bcast_root_0, &new_bcast_root, 1, MPI_INT, MPI_SUM, *newintercomm);
-
-
-    MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm);
-    MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, new_bcast_root, *newintercomm);
-
-
-    //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;
-    //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);
-
-
-
-
-    if(is_local_leader)
-    {
-      MPI_Request requests[2];
-      MPI_Status statuses[2];
-      
-      std::vector<std::pair<int, std::pair<int, int> > > map2vec((*newintercomm)->ep_rank_map->size());
-      std::vector<std::pair<int, std::pair<int, int> > > vec2map((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->size());
-      
-      int ii=0;
-      for(std::map<int, std::pair<int, int> >::iterator it = (*newintercomm)->ep_rank_map->begin(); it != (*newintercomm)->ep_rank_map->end(); it++)
-      {
-        map2vec[ii++] = make_pair(it->first, make_pair(it->second.first, it->second.second));
-      }
-      
-      
-      MPI_Isend(map2vec.data(), 3*local_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[0]);
-      MPI_Irecv(vec2map.data(), 3*remote_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[1]);
-      
-     
-      for(ii=0; ii<vec2map.size(); ii++)
-      {
-        //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second);
-      }
-      
-      MPI_Waitall(2, requests, statuses);
-    }
-
-    //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, new_bcast_root, *newintercomm);
-
-    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]);
-    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = tag;
-
-/*
-    for(int i=0; i<local_ep_size; i++)
-    if(local_comm->ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, local_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i,
-          (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->at(i).first, (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->at(i).second);
-
-    for(int i=0; i<remote_ep_size; i++)
-    if(local_comm->ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, remote_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i,
-          (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->at(i).first, (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->at(i).second);
-
-    for(int i=0; i<remote_intercomm_size; i++)
-    if(local_comm->ep_comm_ptr->comm_label == 0) printf("ep_rank (from EP) = %d, intercomm_rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i,
-          (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(i).first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(i).second);
-*/
-
-//    for(int i=0; i<(*newintercomm)->rank_map->size(); i++)
-//    if(local_comm->ep_comm_ptr->comm_label != 99) printf("ep_rank = %d, rank_map[%d] = (%d,%d)\n", intercomm_ep_rank, i,
-//          (*newintercomm)->rank_map->at(i).first, (*newintercomm)->rank_map->at(i).second);
-
-//    MPI_Comm *test_comm = newintercomm->ep_comm_ptr->intercomm->local_comm;
-//    int test_rank;
-//    MPI_Comm_rank(*test_comm, &test_rank);
-//    printf("=================test_rank = %d\n", test_rank);
-    
-    
-
-    return MPI_SUCCESS;
-
-  }
-
-
-
-
-  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
-  {
-    //! mpi_size of local comm = 1
-    //! same world rank of leaders
-
-    int ep_rank, ep_rank_loc, mpi_rank;
-    int ep_size, num_ep, mpi_size;
-
-    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
-    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
-    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
-
-
-
-    std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm
-                                    //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm
-
-    int rank_in_world;
-
-    int rank_in_peer_mpi[2];
-
-    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
-
-
-    int local_num_ep = num_ep;
-    int remote_num_ep;
-    int total_num_ep;
-
-    int leader_rank_in_peer[2];
-
-    int my_position;
-    int tag_label[2];
-
-    vector<int> send_buf(4);
-    vector<int> recv_buf(4);
-
-
-    if(ep_rank == local_leader)
-    {
-      MPI_Status status;
-
-
-
-      MPI_Comm_rank(peer_comm, &leader_rank_in_peer[0]);
-
-      send_buf[0] = local_num_ep;
-      send_buf[1] = leader_rank_in_peer[0];
-
-      MPI_Request req_s, req_r;
-
-      MPI_Isend(send_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
-      MPI_Irecv(recv_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_r);
-
-
-      MPI_Wait(&req_s, &status);
-      MPI_Wait(&req_r, &status);
-
-      recv_buf[2] = leader_rank_in_peer[0];
-
-    }
-
-    MPI_Bcast(recv_buf.data(), 3, MPI_INT, local_leader, local_comm);
-
-    remote_num_ep = recv_buf[0];
-    leader_rank_in_peer[1] = recv_buf[1];
-    leader_rank_in_peer[0] = recv_buf[2];
-
-    total_num_ep = local_num_ep + remote_num_ep;
-
-
-    if(leader_rank_in_peer[0] < leader_rank_in_peer[1])
-    {
-      my_position = ep_rank_loc;
-      //! LEADER create EP
-      if(ep_rank == local_leader)
-      {
-        ::MPI_Comm *mpi_dup = new ::MPI_Comm;
-        
-        ::MPI_Comm_dup(to_mpi_comm(local_comm->mpi_comm), mpi_dup);
-
-        MPI_Comm *ep_intercomm;
-        MPI_Info info;
-        MPI_Comm_create_endpoints(mpi_dup, total_num_ep, info, ep_intercomm);
-
-
-        for(int i=0; i<total_num_ep; i++)
-        {
-          ep_intercomm[i]->is_intercomm = true;
-          ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
-          ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = 0;
-
-          ep_intercomm[i]->ep_comm_ptr->comm_label = leader_rank_in_peer[0];
-        }
-
-        tag_label[0] = TAG++;
-        tag_label[1] = rank_in_world;
-
-        #pragma omp critical (write_to_tag_list)
-        tag_list.push_back(make_pair( make_pair(tag_label[0], tag_label[1]) , ep_intercomm));
-
-        MPI_Request req_s;
-        MPI_Status sta_s;
-        MPI_Isend(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
-
-        MPI_Wait(&req_s, &sta_s);
-
-      }
-    }
-    else
-    {
-      //! Wait for EP creation
-      my_position = remote_num_ep + ep_rank_loc;
-      if(ep_rank == local_leader)
-      {
-        MPI_Status status;
-        MPI_Request req_r;
-        MPI_Irecv(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_r);
-        MPI_Wait(&req_r, &status);
-      }
-    }
-
-    MPI_Bcast(tag_label, 2, MPI_INT, local_leader, local_comm);
-
-
-
-
-    #pragma omp critical (read_from_tag_list)
-    {
-      bool found = false;
-      while(!found)
-      {
-        for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag_label[0], tag_label[1]))
-          {
-            *newintercomm =  iter->second[my_position];
-            found = true;
-            // tag_list.erase(iter);
-            break;
-          }
-        }
-      }
-    }
-
-    MPI_Barrier_local(local_comm);
-
-    if(leader_rank_in_peer[0] < leader_rank_in_peer[1])
-    {
-      for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag_label[0], tag_label[1]))
-          {
-            tag_list.erase(iter);
-            break;
-          }
-        }
-    }
-
-
-
-    int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
-    int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size;
-
-    intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first;
-    intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
-    intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
-    intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second;
-    intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second;
-    intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second;
-
-
-
-    (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map  = new RANK_MAP;
-    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
-    (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->resize(local_num_ep);
-    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_num_ep);
-
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
-    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
-
-
-
-    int local_rank_map_ele[2];
-    local_rank_map_ele[0] = intercomm_ep_rank;
-    local_rank_map_ele[1] = (*newintercomm)->ep_comm_ptr->comm_label;
-
-    MPI_Allgather(local_rank_map_ele, 2, MPI_INT, 
-      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm);
-
-    if(ep_rank == local_leader)
-    {
-      MPI_Status status;
-      MPI_Request req_s, req_r;
-
-      MPI_Isend((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_s);
-      MPI_Irecv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_r);
-
-
-      MPI_Wait(&req_s, &status);
-      MPI_Wait(&req_r, &status);
-
-    }
-
-    MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, local_leader, local_comm);
-    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]);
-    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = tag;
-
-
-    return MPI_SUCCESS;
-  }
-
-
+
+
+  
 }
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_unique.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_unique.cpp	(revision 1515)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_intercomm_unique.cpp	(revision 1515)
@@ -0,0 +1,228 @@
+#include "ep_lib.hpp"
+#include <mpi.h>
+#include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
+
+using namespace std;
+
+
+namespace ep_lib
+{
+
+
+  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm)
+  {
+    //! mpi_size of local comm = 1
+    //! same world rank of leaders
+
+    int ep_rank, ep_rank_loc, mpi_rank;
+    int ep_size, num_ep, mpi_size;
+
+    ep_rank = local_comm->ep_comm_ptr->size_rank_info[0].first;
+    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
+    mpi_rank = local_comm->ep_comm_ptr->size_rank_info[2].first;
+    ep_size = local_comm->ep_comm_ptr->size_rank_info[0].second;
+    num_ep = local_comm->ep_comm_ptr->size_rank_info[1].second;
+    mpi_size = local_comm->ep_comm_ptr->size_rank_info[2].second;
+
+
+
+    std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm
+                                    //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm
+
+    int rank_in_world;
+
+    int rank_in_peer_mpi[2];
+
+    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
+
+
+    int local_num_ep = num_ep;
+    int remote_num_ep;
+    int total_num_ep;
+
+    int leader_rank_in_peer[2];
+
+    int my_position;
+    int tag_label[2];
+
+    vector<int> send_buf(4);
+    vector<int> recv_buf(4);
+
+
+    if(ep_rank == local_leader)
+    {
+      MPI_Status status;
+
+
+
+      MPI_Comm_rank(peer_comm, &leader_rank_in_peer[0]);
+
+      send_buf[0] = local_num_ep;
+      send_buf[1] = leader_rank_in_peer[0];
+
+      MPI_Request req_s, req_r;
+
+      MPI_Isend(send_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
+      MPI_Irecv(recv_buf.data(), 2, MPI_INT, remote_leader, tag, peer_comm, &req_r);
+
+
+      MPI_Wait(&req_s, &status);
+      MPI_Wait(&req_r, &status);
+
+      recv_buf[2] = leader_rank_in_peer[0];
+
+    }
+
+    MPI_Bcast(recv_buf.data(), 3, MPI_INT, local_leader, local_comm);
+
+    remote_num_ep = recv_buf[0];
+    leader_rank_in_peer[1] = recv_buf[1];
+    leader_rank_in_peer[0] = recv_buf[2];
+
+    total_num_ep = local_num_ep + remote_num_ep;
+
+
+    if(leader_rank_in_peer[0] < leader_rank_in_peer[1])
+    {
+      my_position = ep_rank_loc;
+      //! LEADER create EP
+      if(ep_rank == local_leader)
+      {
+        ::MPI_Comm *mpi_dup = new ::MPI_Comm;
+        
+        ::MPI_Comm_dup(to_mpi_comm(local_comm->mpi_comm), mpi_dup);
+
+        MPI_Comm *ep_intercomm;
+        MPI_Info info;
+        MPI_Comm_create_endpoints(mpi_dup, total_num_ep, info, ep_intercomm);
+
+
+        for(int i=0; i<total_num_ep; i++)
+        {
+          ep_intercomm[i]->is_intercomm = true;
+          ep_intercomm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
+          ep_intercomm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = 0;
+
+          ep_intercomm[i]->ep_comm_ptr->comm_label = leader_rank_in_peer[0];
+        }
+
+        tag_label[0] = TAG++;
+        tag_label[1] = rank_in_world;
+
+        #pragma omp critical (write_to_tag_list)
+        tag_list.push_back(make_pair( make_pair(tag_label[0], tag_label[1]) , ep_intercomm));
+
+        MPI_Request req_s;
+        MPI_Status sta_s;
+        MPI_Isend(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
+
+        MPI_Wait(&req_s, &sta_s);
+
+      }
+    }
+    else
+    {
+      //! Wait for EP creation
+      my_position = remote_num_ep + ep_rank_loc;
+      if(ep_rank == local_leader)
+      {
+        MPI_Status status;
+        MPI_Request req_r;
+        MPI_Irecv(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_r);
+        MPI_Wait(&req_r, &status);
+      }
+    }
+
+    MPI_Bcast(tag_label, 2, MPI_INT, local_leader, local_comm);
+
+
+
+
+    #pragma omp critical (read_from_tag_list)
+    {
+      bool found = false;
+      while(!found)
+      {
+        for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
+        {
+          if((*iter).first == make_pair(tag_label[0], tag_label[1]))
+          {
+            *newintercomm =  iter->second[my_position];
+            found = true;
+            // tag_list.erase(iter);
+            break;
+          }
+        }
+      }
+    }
+
+    MPI_Barrier_local(local_comm);
+
+    if(leader_rank_in_peer[0] < leader_rank_in_peer[1])
+    {
+      for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
+        {
+          if((*iter).first == make_pair(tag_label[0], tag_label[1]))
+          {
+            tag_list.erase(iter);
+            break;
+          }
+        }
+    }
+
+
+
+    int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
+    int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size;
+
+    intercomm_ep_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[0].first;
+    intercomm_ep_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
+    intercomm_mpi_rank = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
+    intercomm_ep_size = (*newintercomm)->ep_comm_ptr->size_rank_info[0].second;
+    intercomm_num_ep = (*newintercomm)->ep_comm_ptr->size_rank_info[1].second;
+    intercomm_mpi_size = (*newintercomm)->ep_comm_ptr->size_rank_info[2].second;
+
+
+
+    (*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map  = new RANK_MAP;
+    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
+    (*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map->resize(local_num_ep);
+    (*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_num_ep);
+
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
+
+
+
+    int local_rank_map_ele[2];
+    local_rank_map_ele[0] = intercomm_ep_rank;
+    local_rank_map_ele[1] = (*newintercomm)->ep_comm_ptr->comm_label;
+
+    MPI_Allgather(local_rank_map_ele, 2, MPI_INT, 
+      (*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map->data(), 2, MPI_INT, local_comm);
+
+    if(ep_rank == local_leader)
+    {
+      MPI_Status status;
+      MPI_Request req_s, req_r;
+
+      MPI_Isend((*newintercomm)->ep_comm_ptr->intercomm->loc_rank_map->data(), 2*local_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_s);
+      MPI_Irecv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, remote_leader, tag, peer_comm, &req_r);
+
+
+      MPI_Wait(&req_s, &status);
+      MPI_Wait(&req_r, &status);
+
+    }
+
+    MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, MPI_INT, local_leader, local_comm);
+    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]);
+    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = tag;
+
+
+    return MPI_SUCCESS;
+  }
+
+}
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1515)
@@ -33,10 +33,10 @@
   int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank)
   {
-    for(int i=0; i<comm->ep_rank_map->size(); i++)
-    {
-      if(   ( comm->ep_rank_map->at(i).first  == ep_rank_loc )
-         && ( comm->ep_rank_map->at(i).second == mpi_rank ) )
+    for(std::map<int, std::pair<int, int> >::iterator it = comm->ep_rank_map->begin(); it != comm->ep_rank_map->end(); it++)
+    {
+      if(   ( it->second.first  == ep_rank_loc )
+         && ( it->second.second == mpi_rank ) )
       {
-        return i;
+        return it->first;
       }
     }
@@ -44,31 +44,4 @@
   }
   
-  int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank)
-  {
-    // intercomm
-    int inter_rank;
-    for(int i=0; i<comm->ep_comm_ptr->intercomm->intercomm_rank_map->size(); i++)
-    {
-      if(   ( comm->ep_comm_ptr->intercomm->inter_rank_map->at(i).first  == ep_rank_loc )
-         && ( comm->ep_comm_ptr->intercomm->inter_rank_map->at(i).second == mpi_rank ) )
-      {
-        inter_rank =  i;
-        break;
-      }
-    }
-
-    for(int i=0; i<comm->ep_comm_ptr->intercomm->remote_rank_map->size(); i++)
-    {
-      if(  comm->ep_comm_ptr->intercomm->remote_rank_map->at(i).first  == inter_rank  )
-      {
-        //printf("get_ep_rank for intercomm, ep_rank_loc = %d, mpi_rank = %d => ep_src = %d\n", ep_rank_loc, mpi_rank, i);
-        return i;
-      }
-    }
-
-    printf("rank not find\n");
-    
-  }
-
 
   int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count)
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.hpp	(revision 1515)
@@ -28,4 +28,5 @@
 
   int MPI_Comm_free(MPI_Comm* comm);
+  int MPI_Comm_free_intracomm(MPI_Comm* comm);
 
   int MPI_Finalize();
@@ -52,5 +53,4 @@
   int tag_combine(int real_tag, int src, int dest);
   int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
-  int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
 
   int Message_Check(MPI_Comm comm);
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_lib_mpi.hpp	(revision 1515)
@@ -26,4 +26,8 @@
   int MPI_Irecv_mpi      (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request);
 
+  int MPI_Comm_rank_mpi(MPI_Comm comm, int* rank);
+  int MPI_Comm_size_mpi(MPI_Comm comm, int* size);
+  int MPI_Comm_remote_size_mpi(MPI_Comm comm, int* size);
+
 }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp	(revision 1515)
@@ -104,5 +104,5 @@
     if(comm->is_intercomm)
     {
-      return  Message_Check_intercomm(comm);
+      Message_Check_intercomm(comm);
     }
     
@@ -148,5 +148,10 @@
         int src_mpi  = status.MPI_SOURCE;
              
-        msg->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);       
+        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");
@@ -213,7 +218,10 @@
         int dest_loc = bitset<8> (status.MPI_TAG)	    .to_ulong();
         int src_mpi  = status.MPI_SOURCE;
-        int current_inter = comm->ep_comm_ptr->intercomm->local_rank_map->at(current_ep_rank).first;
              
-        msg->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);       
+        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");
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_rank.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_rank.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_rank.cpp	(revision 1515)
@@ -7,42 +7,21 @@
 {
 
+  int MPI_Comm_rank(MPI_Comm comm, int* rank)
+  {
+    if(comm->is_ep)
+    {
+      Debug("MPI_Comm_rank with EP");
+      return *rank = comm->ep_comm_ptr->size_rank_info[0].first;      
+    }
+
+    return MPI_Comm_rank_mpi(comm, rank);
+  }
 
 
-  int MPI_Comm_rank(MPI_Comm comm, int* rank)
+  int MPI_Comm_rank_mpi(MPI_Comm comm, int* rank)
   {
-
-    if(comm->is_ep)
-    {
-      Debug("Calling EP_Comm_rank\n");
-
-      if(comm->is_intercomm)
-      {
-        *rank = comm->ep_comm_ptr->intercomm->size_rank_info[0].first;
-        return 0;
-      }
-      else
-      {
-        *rank = comm->ep_comm_ptr->size_rank_info[0].first;
-        return 0;
-      }
-    }
-
-
-    if(comm != MPI_COMM_NULL)
-    {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-      ::MPI_Comm_rank(mpi_comm, rank);
-      return 0;
-    }
-    else
-    {
-      printf("rank is undefined\n");
-
-      *rank = MPI_UNDEFINED;
-      return 0;
-    }
-
+    Debug("MPI_Comm_rank with MPI");
+    return ::MPI_Comm_rank(to_mpi_comm(comm->mpi_comm), rank);
   }
-
 
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp	(revision 1515)
@@ -147,5 +147,5 @@
   int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
   {
-    Debug("\nMPI_Send with EP_Intercomm\n");
+    Debug("\nMPI_Send_intercomm with EP\n");
     MPI_Request request;
     MPI_Status status;
@@ -165,5 +165,5 @@
   int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
   {
-    Debug("\nMPI_Ssend with EP_Intercomm\n");
+    Debug("\nMPI_Ssend_intercomm with EP\n");
     MPI_Request request;
     MPI_Status status;
@@ -181,8 +181,8 @@
     
     *request = new ep_request;
-    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend, *request = new ep_request");
-
-    (*request)->mpi_request = new ::MPI_Request;
-    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend, (*request)->mpi_request = new ::MPI_Request");
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_mpi, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_mpi, (*request)->mpi_request = new ::MPI_Request");
       
     (*request)->ep_src = src_rank;
@@ -197,67 +197,59 @@
   int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
-    Debug("MPI_Isend with EP_Intercomm\n");
-
-#ifdef _check_sum    
-    check_sum_send(buf, count, datatype, dest, tag, comm);
-#endif
-
-    int dest_remote_ep_rank    = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
-    int dest_remote_comm_label = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
-
-    int src_ep_rank    = comm->ep_comm_ptr->intercomm->size_rank_info[0].first;
-    int src_comm_label;
-
-    src_comm_label = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second;
-    //Message_Check(comm);
-
-    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
+    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("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)
     {
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *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");
-      
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-
+      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   // dest_remote_comm_label != src_comm_label
-    { 
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *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");
-
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-      
-      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)); 
+    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));
     }
   }
 
+
+
+
   int MPI_Issend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
@@ -268,8 +260,8 @@
     
     *request = new ep_request;
-    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend, *request = new ep_request");
-
-    (*request)->mpi_request = new ::MPI_Request;
-    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend, (*request)->mpi_request = new ::MPI_Request");
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_mpi, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_mpi, (*request)->mpi_request = new ::MPI_Request");
       
     (*request)->ep_src = src_rank;
@@ -285,64 +277,52 @@
   int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
-    Debug("MPI_Issend with EP_Intercomm\n");
-
-#ifdef _check_sum    
-    check_sum_send(buf, count, datatype, dest, tag, comm);
-#endif
-
-    int dest_remote_ep_rank    = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
-    int dest_remote_comm_label = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
-
-    int src_ep_rank    = comm->ep_comm_ptr->intercomm->size_rank_info[0].first;
-    int src_comm_label;
-
-    src_comm_label = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second;
-    //Message_Check(comm);
-
-    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
+    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)
     {
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *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");
-      
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-
+      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   // dest_remote_comm_label != src_comm_label
-    { 
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *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");
-
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-      
-      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)); 
+    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 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/ep_size.cpp	(revision 1515)
@@ -7,72 +7,47 @@
 {
 
-
-
-
   int MPI_Comm_size(MPI_Comm comm, int* size)
   {
-    
     if(comm->is_ep)
     {
-      if(!comm->is_intercomm)
-      {
-        *size = comm->ep_comm_ptr->size_rank_info[0].second;
-
-        return 0;
-      }
-      else
-      {
-        *size = comm->ep_comm_ptr->intercomm->size_rank_info[0].second;
-
-        return 0;
-      }
-
+      Debug("MPI_Comm_size with EP");
+      return *size = comm->ep_comm_ptr->size_rank_info[0].second;
     }
 
-    Debug("Calling EP_Comm_size\n");
-
-    if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
-    {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 
-      int mpi_size;
-
-      ::MPI_Comm_size(mpi_comm, &mpi_size);
-      *size = mpi_size;
-      return 0;
-    }
-
-    else
-    {
-      *size = MPI_UNDEFINED;
-      return 0;
-    }
+    return MPI_Comm_size_mpi(comm, size);
   }
 
   int MPI_Comm_remote_size(MPI_Comm comm, int *size)
   {
-    if(!comm->is_ep)
+    if(comm->is_ep)
     {
-      if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
+      if(comm->is_intercomm)
       {
-        ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm); 
-        ::MPI_Comm_remote_size(mpi_comm, size);
-        return 0;
+        Debug("MPI_Comm_remote_size with EP_intercomm");
+        return *size = comm->ep_comm_ptr->intercomm->intercomm_rank_map->size();
       }
-
       else
       {
-        *size = MPI_UNDEFINED;
-        return 0;
+        Debug("MPI_Comm_remote_size with EP_intracomm");
+        return *size=0;
       }
     }
-    
-    if(comm->is_intercomm)
-    {
-      *size = comm->ep_comm_ptr->intercomm->remote_rank_map->size();
-      return 0;
-    }
-    *size = MPI_UNDEFINED;
-    return 0; 
+    return MPI_Comm_remote_size_mpi(comm, size);
   }
+
+
+  int MPI_Comm_size_mpi(MPI_Comm comm, int* size)
+  {
+    Debug("MPI_Comm_size with MPI");
+    return ::MPI_Comm_size(to_mpi_comm(comm->mpi_comm), size);
+  }
+
+  int MPI_Comm_remote_size_mpi(MPI_Comm comm, int *size)
+  {
+    Debug("MPI_Comm_remote_size with MPI");
+    return ::MPI_Comm_remote_size(to_mpi_comm(comm->mpi_comm), size);
+  }
+
+
 }
 
Index: /XIOS/dev/branch_openmp/extern/ep_dev/main.cpp
===================================================================
--- /XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1514)
+++ /XIOS/dev/branch_openmp/extern/ep_dev/main.cpp	(revision 1515)
@@ -67,5 +67,5 @@
     
     if(rank == 0) printf("           \t test MPI_Comm_dup \t OK \n");
-/*
+
     // TIMING SYCHRONIZATION
     {
@@ -112,5 +112,5 @@
       std::cout << "proc "<< mpi_rank <<" for_loop "<< time_span.count() << " seconds."<<std::endl;
     }// END TIMING SYCHRONIZATION
-*/    
+    
     // TEST of p2p blocking communication
     {
@@ -762,7 +762,13 @@
       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};
-      int tab_key[16]   = {2, 1, 4, 1, 0, 4, 3, 3, 4, 3, 4, 4, 4, 0, 0, 2};
+
+      int config = 1;
+      if(config=1)
+      {
+        assert(size == 16 && omp_get_num_threads()==4);
+      }
+      
+      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];
@@ -779,5 +785,5 @@
 
 
-      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);
+      
 
       MPI_Barrier(comm);
@@ -794,5 +800,5 @@
       
       int local_leader = 0;
-      int remote_leader = color==2? 13: 4;
+      int remote_leader = color==2? 13: 4; // used for config 1
 
       MPI_Comm peer_comm = comm;
@@ -800,5 +806,48 @@
       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_Barrier(comm);
+      MPI_Barrier(comm);
+
+      if(color==2 && split_rank==1)
+      {
+        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, 5, 10, inter_comm, &send_request);
+        MPI_Wait(&send_request, &send_status);
+      }
+
+      if(color==1 && split_rank==5)
+      {
+        double recvbuf[9];
+        MPI_Request recv_request;
+        MPI_Status recv_status;
+        MPI_Irecv(recvbuf, 9, MPI_DOUBLE, 1, 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");
 
 
@@ -809,4 +858,9 @@
       MPI_Comm_free(&split_comm);
 
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+
+      MPI_Comm_free(&inter_comm);
+      
 
       /*
