Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_lib.cpp	(revision 1520)
@@ -27,4 +27,19 @@
   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++)
     {
@@ -35,5 +50,7 @@
       }
     }
-    printf("rank not find\n");
+    printf("rank not find for EP_intracomm\n");
+    int err;
+    return MPI_Abort(comm, err);
   }
   
Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_test.cpp	(revision 1520)
@@ -33,5 +33,6 @@
         status->ep_tag = (*request)->ep_tag;
         status->ep_datatype = (*request)->ep_datatype;
-        //delete request->mpi_request;
+        delete (*request)->mpi_request;
+        delete request;
       }
 
@@ -60,5 +61,6 @@
         status->ep_tag = (*request)->ep_tag;
         status->ep_datatype = (*request)->ep_datatype;
-        //delete request->mpi_request;
+        delete (*request)->mpi_request;
+        delete request;
         //int count;
         //MPI_Get_count(status, request->ep_datatype, &count);
@@ -75,10 +77,30 @@
   {
     Debug("MPI_Testall with EP");
-    *flag = true;
-    int i=0;
-    while(*flag && i<count )
+
+    ::MPI_Request* mpi_request = new ::MPI_Request[count];
+    ::MPI_Status* mpi_status = new ::MPI_Status[count];
+
+
+    for(int i=0; i<count; i++)
     {
-      MPI_Test(&array_of_requests[i], flag, &array_of_statuses[i]);
-      i++;
+      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
+    }
+
+    ::MPI_Testall(count, mpi_request, flag, mpi_status);
+
+    if(flag)
+    {
+      for(int i=0; i<count; i++)
+      {
+        array_of_statuses[i].mpi_status = &mpi_status[i];
+        array_of_statuses[i].ep_src = array_of_requests[i]->ep_src;
+        array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag;
+        array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
+      
+        memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request");
+        delete array_of_requests[i]->mpi_request;
+        delete array_of_requests[i]; 
+      }
+      
     }
 
@@ -87,2 +109,3 @@
 
 }
+
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp	(revision 1520)
@@ -17,10 +17,33 @@
 {
 
+  int MPI_Allgather_local(const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, MPI_Comm comm)
+  {
+    assert(valid_type(datatype));
+
+    ::MPI_Aint datasize, lb;
+    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
+
+    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;
+
+    #pragma omp critical (write_buffer)
+    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
+
+    MPI_Barrier_local(comm);
+
+    #pragma omp critical (read_buffer)
+    {
+      for(int i=0; i<num_ep; i++)
+        memcpy(recvbuf + datasize * i * count, comm->my_buffer->void_buffer[i], datasize * count);
+    }
+    MPI_Barrier_local(comm);
+  }
+
   int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm)
   {
 
-    if(!comm.is_ep && comm.mpi_comm)
+    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));
+      return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
     }
 
@@ -37,10 +60,10 @@
 
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
     bool is_master = ep_rank_loc==0;
@@ -70,5 +93,5 @@
       int local_sendcount = num_ep * count;
 
-      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm.mpi_comm));
+      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm));
 
       mpi_displs[0] = 0;
@@ -79,5 +102,5 @@
 
     
-      ::MPI_Allgatherv(local_recvbuf, num_ep * count, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts, mpi_displs, to_mpi_type(datatype), to_mpi_comm(comm.mpi_comm));
+      ::MPI_Allgatherv(local_recvbuf, num_ep * count, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts, mpi_displs, to_mpi_type(datatype), to_mpi_comm(comm->mpi_comm));
 
 
@@ -86,5 +109,5 @@
       for(int i=0; i<ep_size; i++)
       {
-        offset = mpi_displs[comm.rank_map->at(i).second] + comm.rank_map->at(i).first * sendcount; 
+        offset = mpi_displs[comm->ep_rank_map->at(i).second] + comm->ep_rank_map->at(i).first * sendcount; 
         memcpy(recvbuf + i*sendcount*datasize, tmp_recvbuf+offset*datasize, sendcount*datasize);
       }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp	(revision 1520)
@@ -20,10 +20,10 @@
   {
 
-    if(!comm.is_ep && comm.mpi_comm)
+    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));
+      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->mpi_comm) return 0;
 
 
@@ -38,10 +38,10 @@
 
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
     assert(sendcount == recvcounts[ep_rank]);
@@ -79,5 +79,5 @@
 
       int local_sendcount = std::accumulate(local_recvcounts.begin(), local_recvcounts.end(), 0);
-      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm.mpi_comm));
+      ::MPI_Allgather(&local_sendcount, 1, to_mpi_type(MPI_INT), mpi_recvcounts.data(), 1, to_mpi_type(MPI_INT), to_mpi_comm(comm->mpi_comm));
 
       for(int i=1; i<mpi_size; i++)
@@ -85,5 +85,5 @@
 
 
-      ::MPI_Allgatherv(local_recvbuf, local_sendcount, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(datatype), to_mpi_comm(comm.mpi_comm));
+      ::MPI_Allgatherv(local_recvbuf, local_sendcount, to_mpi_type(datatype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(datatype), to_mpi_comm(comm->mpi_comm));
 
       // reorder 
@@ -92,6 +92,6 @@
       {
         int extra = 0;
-        for(int j=0, k=0; j<ep_size, k<comm.rank_map->at(i).first; j++)
-          if(comm.rank_map->at(i).second == comm.rank_map->at(j).second)
+        for(int j=0, k=0; j<ep_size, k<comm->ep_rank_map->at(i).first; j++)
+          if(comm->ep_rank_map->at(i).second == comm->ep_rank_map->at(j).second)
           {
             extra += recvcounts[j];
@@ -99,5 +99,5 @@
           }  
 
-        offset = mpi_displs[comm.rank_map->at(i).second] +  extra;
+        offset = mpi_displs[comm->ep_rank_map->at(i).second] +  extra;
 
         memcpy(recvbuf+displs[i]*datasize, tmp_recvbuf+offset*datasize, recvcounts[i]*datasize);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp	(revision 1520)
@@ -21,17 +21,17 @@
   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)
+    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));
+      return ::MPI_Allreduce(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
     }
 
 
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
 
@@ -55,5 +55,5 @@
     if(is_master)
     {
-      ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm));
+      ::MPI_Allreduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
     }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp	(revision 1520)
@@ -9,7 +9,7 @@
   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)
+    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));
+      return ::MPI_Alltoall(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm->mpi_comm));
     }
 
@@ -23,10 +23,10 @@
     int count = sendcount;
     
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
     void* tmp_recvbuf;
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp	(revision 1520)
@@ -9,38 +9,19 @@
   int MPI_Barrier(MPI_Comm comm)
   {
-    if(comm.is_intercomm) return MPI_Barrier_intercomm(comm);
+    if(comm->is_intercomm) return MPI_Barrier_intercomm(comm);
 
-    if(comm.is_ep)
+    if(comm->is_ep) 
     {
-      int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-
-      MPI_Barrier_local(comm);
-
-      if(ep_rank_loc == 0)
-      {
-        ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
-
-        ::MPI_Barrier(mpi_comm);
-      }
-
-      MPI_Barrier_local(comm);
-
-      return 0;
-    }
-    else if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
-    {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
-      ::MPI_Barrier(mpi_comm);
-      return 0;
+      return MPI_Barrier_intracomm(comm);
     }
 
-    else return 0;
+    
+    return MPI_Barrier_mpi(comm);
+
   }
 
-
-  int MPI_Barrier_intercomm(MPI_Comm comm)
+  int MPI_Barrier_intracomm(MPI_Comm comm)
   {
-
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
 
     MPI_Barrier_local(comm);
@@ -48,5 +29,6 @@
     if(ep_rank_loc == 0)
     {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
+
       ::MPI_Barrier(mpi_comm);
     }
@@ -55,5 +37,19 @@
 
     return 0;
+  }
 
+  int MPI_Barrier_intercomm(MPI_Comm comm)
+  {
+    MPI_Barrier_local(comm);
+
+    if(comm->ep_comm_ptr->intercomm->size_rank_info[1].first == 0)
+      ::MPI_Barrier(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm));
+
+    MPI_Barrier_local(comm);
+  }
+
+  int MPI_Barrier_mpi(MPI_Comm comm)
+  {
+    return ::MPI_Barrier(to_mpi_comm(comm->mpi_comm));
   }
 
@@ -61,6 +57,5 @@
   int MPI_Barrier_local(MPI_Comm comm)
   {
-    //Message_Check(comm);
-    comm.ep_barrier->wait();
+    comm->ep_barrier->wait();
   }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp	(revision 1520)
@@ -20,5 +20,5 @@
     assert(valid_type(datatype));
 
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
 
     ::MPI_Aint datasize, lb;
@@ -28,5 +28,5 @@
     if(ep_rank_loc == local_root)
     {
-      comm.my_buffer->void_buffer[local_root] = buffer;
+      comm->my_buffer->void_buffer[local_root] = buffer;
     }
 
@@ -36,5 +36,5 @@
     {
       #pragma omp critical (_bcast)      
-      memcpy(buffer, comm.my_buffer->void_buffer[local_root], datasize * count);
+      memcpy(buffer, comm->my_buffer->void_buffer[local_root], datasize * count);
     }
 
@@ -45,23 +45,23 @@
   {
 
-    if(!comm.is_ep)
+    if(!comm->is_ep)
     {
       #pragma omp single nowait
-      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm->mpi_comm));
       return 0;
     }
 
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
 
-    int root_mpi_rank = comm.rank_map->at(root).second;
-    int root_ep_rank_loc = comm.rank_map->at(root).first;
+    int root_mpi_rank = comm->ep_rank_map->at(root).second;
+    int root_ep_rank_loc = comm->ep_rank_map->at(root).first;
 
 
     if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root)
     {
-      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
     }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1520)
@@ -25,157 +25,4 @@
     \param [out] out_comm_hdls Handles of EP communicators.
   */
-  // #ifdef _intelmpi
-  // int MPI_Comm_create_endpoints(int base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
-  // {
-  //   int base_rank;
-  //   int base_size;
-
-  //   ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);
-
-  //   ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size
-  //   ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank
-		// 							  // parent_comm can also be endpoints communicators
-
-  //   std::vector<int> recv_num_ep(base_size);
-
-  //   out_comm_hdls = new MPI_Comm[num_ep];
-
-  //   for (int idx = 0; idx < num_ep; ++idx)
-  //   {
-  //     out_comm_hdls[idx].is_ep = true;
-  //     out_comm_hdls[idx].is_intercomm = false;
-  //     out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;
-  //     out_comm_hdls[idx].mpi_comm = base_comm_ptr;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;
-  //   }
-
-  //   ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype>(MPI_INT), &recv_num_ep[0], 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_base_comm);
-
-
-  //   int sum = 0;  // representing total ep number of process with smaller rank
-  //   for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }
-
-  //   int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
-
-  //   out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-
-  //   out_comm_hdls[0].my_buffer = new BUFFER;
-
-  //   out_comm_hdls[0].rank_map = new RANK_MAP;
-  //   out_comm_hdls[0].rank_map->resize(ep_size);
-
-
-  //   for (int i = 1; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;
-  //     out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer;
-  //     out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map;
-  //   }
-
-
-  //   for (int i = 0; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
-
-  //     out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;
-  //   }
-
-
-  //   int ind = 0;
-
-  //   for(int i=0; i<base_size; i++)
-  //   {
-  //     for(int j=0; j<recv_num_ep[i]; j++)
-  //     {
-  //       out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);
-  //       ind++;
-  //     }
-  //   }
-
-
-
-  //   return 0;
-
-  // } //MPI_Comm_create_endpoints
-
-  // #elif _openmpi
-  // int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
-  // {
-
-  //   int base_rank;
-  //   int base_size;
-
-  //   ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);
-
-  //   ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size
-  //   ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank
-  //                                                // parent_comm can also be endpoints communicators ?
-  //   std::vector<int> recv_num_ep(base_size);
-
-  //   out_comm_hdls = new MPI_Comm[num_ep];
-
-  //   for (int idx = 0; idx < num_ep; ++idx)
-  //   {
-  //     out_comm_hdls[idx].is_ep = true;
-  //     out_comm_hdls[idx].is_intercomm = false;
-  //     out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;
-  //     out_comm_hdls[idx].mpi_comm = base_comm_ptr;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;
-  //   }
-
-  //   ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype> (MPI_INT), 
-  //                  &recv_num_ep[0], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_base_comm);
-
-  //   int sum = 0;  // representing total ep number of process with smaller rank
-  //   for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }
-
-  //   int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
-
-  //   out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-  //   out_comm_hdls[0].my_buffer = new BUFFER;
-
-  //   out_comm_hdls[0].rank_map = new RANK_MAP;
-  //   out_comm_hdls[0].rank_map->resize(ep_size);
-
-
-  //   for (int i = 1; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;
-  //     out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer;
-  //     out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map;
-  //   }
-
-
-  //   for (int i = 0; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
-
-  //     out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;
-  //   }
-
-
-  //   int ind = 0;
-
-  //   for(int i=0; i<base_size; i++)
-  //   {
-  //     for(int j=0; j<recv_num_ep[i]; j++)
-  //     {
-  //       out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);
-  //       ind++;
-  //     }
-  //   }
-
-  //   return 0;
-
-  // } //MPI_Comm_create_endpoints
-
-  // #endif
-  
   
   int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
@@ -194,13 +41,35 @@
 
     out_comm_hdls = new MPI_Comm[num_ep];
+#ifdef _showinfo
+    printf("new out_comm_hdls = %p\n", out_comm_hdls);
+#endif
 
+    ::MPI_Comm *parent_comm = new ::MPI_Comm;
+    ::MPI_Comm_dup(to_mpi_comm(base_comm_ptr), parent_comm);
+
+#ifdef _showinfo
+    printf("new out_comm_hdls->mpi_comm = %p\n", parent_comm);
+#endif
+    
     for (int idx = 0; idx < num_ep; ++idx)
     {
-      out_comm_hdls[idx].is_ep = true;
-      out_comm_hdls[idx].is_intercomm = false;
-      out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;     
-      *(static_cast< ::MPI_Comm*>(out_comm_hdls[idx].mpi_comm)) = *(static_cast< ::MPI_Comm*>(base_comm_ptr));
-      out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;
-      out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;
+
+      out_comm_hdls[idx] = new ep_comm;
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d] = %p\n", idx, out_comm_hdls[idx]);
+#endif
+
+      out_comm_hdls[idx]->is_ep = true;
+      out_comm_hdls[idx]->is_intercomm = false;
+      
+      out_comm_hdls[idx]->ep_comm_ptr = new ep_communicator;     
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d]->ep_comm_ptr = %p\n", idx, out_comm_hdls[idx]->ep_comm_ptr);
+#endif
+
+
+      out_comm_hdls[idx]->mpi_comm = parent_comm;
+      out_comm_hdls[idx]->ep_comm_ptr->comm_list = out_comm_hdls;
+      out_comm_hdls[idx]->ep_comm_ptr->comm_label = 0;
     }
 
@@ -213,16 +82,24 @@
     int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
 
-    out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-    out_comm_hdls[0].my_buffer = new BUFFER;
+    out_comm_hdls[0]->ep_barrier = new ep_barrier(num_ep);
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->ep_barrier = %p\n", out_comm_hdls[0]->ep_barrier);
+#endif
 
-    out_comm_hdls[0].rank_map = new RANK_MAP;
-    out_comm_hdls[0].rank_map->resize(ep_size);
+    out_comm_hdls[0]->my_buffer = new BUFFER;
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->my_buffer = %p\n", out_comm_hdls[0]->my_buffer);
+#endif
 
+    out_comm_hdls[0]->ep_rank_map = new EP_RANK_MAP;
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->ep_rank_map = %p\n", out_comm_hdls[0]->ep_rank_map);
+#endif
 
     for (int i = 1; i < num_ep; i++)
     {
-      out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;
-      out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer;
-      out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map;
+      out_comm_hdls[i]->ep_barrier = out_comm_hdls[0]->ep_barrier;
+      out_comm_hdls[i]->my_buffer  = out_comm_hdls[0]->my_buffer;
+      out_comm_hdls[i]->ep_rank_map= out_comm_hdls[0]->ep_rank_map;
     }
 
@@ -230,9 +107,13 @@
     for (int i = 0; i < num_ep; i++)
     {
-      out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
-      out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
-      out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
+      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
+      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
+      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
 
-      out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;
+      out_comm_hdls[i]->ep_comm_ptr->message_queue = new Message_list;
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d]->ep_comm_ptr->message_queue = %p\n", i, out_comm_hdls[i]->ep_comm_ptr->message_queue);
+#endif
+
     }
 
@@ -244,5 +125,5 @@
       for(int j=0; j<recv_num_ep[i]; j++)
       {
-        out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);
+        out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i));
         ind++;
       }
@@ -253,4 +134,5 @@
   } //MPI_Comm_create_endpoints
 
+  
 
 } //namespace ep_lib
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp	(revision 1520)
@@ -42,4 +42,5 @@
 ::MPI_Op MPI_MIN_STD = MPI_MIN;
 ::MPI_Op MPI_LOR_STD = MPI_LOR;
+::MPI_Op MPI_REPLACE_STD = MPI_REPLACE;
 
 #undef MPI_SUM
@@ -47,4 +48,5 @@
 #undef MPI_MIN
 #undef MPI_LOR
+#undef MPI_REPLACE
 
 
@@ -66,4 +68,5 @@
 extern ::MPI_Op MPI_MIN_STD;
 extern ::MPI_Op MPI_LOR_STD;
+extern ::MPI_Op MPI_REPLACE_STD;
 
 extern ::MPI_Comm MPI_COMM_WORLD_STD;
@@ -89,12 +92,20 @@
 ep_lib::MPI_Op MPI_MIN = &MPI_MIN_STD;
 ep_lib::MPI_Op MPI_LOR = &MPI_LOR_STD;
+ep_lib::MPI_Op MPI_REPLACE = &MPI_REPLACE_STD;
 
-ep_lib::MPI_Comm MPI_COMM_WORLD(&MPI_COMM_WORLD_STD);
-ep_lib::MPI_Comm MPI_COMM_NULL(&MPI_COMM_NULL_STD);
+ep_lib::ep_comm EP_COMM_WORLD(&MPI_COMM_WORLD_STD);
+ep_lib::ep_comm EP_COMM_NULL(&MPI_COMM_NULL_STD);
 
-ep_lib::MPI_Request MPI_REQUEST_NULL(&MPI_REQUEST_NULL_STD);
-ep_lib::MPI_Info MPI_INFO_NULL(&MPI_INFO_NULL_STD);
+ep_lib::MPI_Comm MPI_COMM_WORLD = &EP_COMM_WORLD;
+ep_lib::MPI_Comm MPI_COMM_NULL = &EP_COMM_NULL;
+
+//ep_lib::ep_status EP_STATUS_IGNORE(&MPI_STATUS_IGNORE_STD);
+ep_lib::ep_request EP_REQUEST_NULL(&MPI_REQUEST_NULL_STD);
+ep_lib::ep_info EP_INFO_NULL(&MPI_INFO_NULL_STD);
+
+//ep_lib::MPI_Status MPI_STATUS_IGNORE = &EP_STATUS_IGNORE;
+ep_lib::MPI_Request MPI_REQUEST_NULL = &EP_REQUEST_NULL;
+ep_lib::MPI_Info MPI_INFO_NULL = &EP_INFO_NULL;
 
 
 
-
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.hpp	(revision 1520)
@@ -16,4 +16,5 @@
 #undef MPI_MIN
 #undef MPI_LOR
+#undef MPI_REPLACE
 
 #undef MPI_COMM_WORLD
@@ -38,4 +39,5 @@
 extern ep_lib::MPI_Op MPI_MIN;
 extern ep_lib::MPI_Op MPI_LOR;
+extern ep_lib::MPI_Op MPI_REPLACE;
 
 extern ep_lib::MPI_Comm MPI_COMM_WORLD;
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1520)
@@ -7,52 +7,52 @@
 {
 
-  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("Comm_dup MPI\n");
-      newcomm = new MPI_Comm;
-      newcomm->is_ep = comm.is_ep;
+    newcomm = new MPI_Comm;
+    (*newcomm)->is_ep = false;
 
-      ::MPI_Comm input = to_mpi_comm(comm.mpi_comm);
-      ::MPI_Comm *output = new ::MPI_Comm;
+    ::MPI_Comm *output = new ::MPI_Comm;
+      
+    ::MPI_Comm_dup(to_mpi_comm(comm->mpi_comm), output);
 
-      
-      ::MPI_Comm_dup(input, output);
+    (*newcomm)->mpi_comm = output;
+  }
 
-      newcomm->mpi_comm = output;
-
-      return 0;
-    }
-
-    if(comm.is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm);
-
-    // for intracomm
-    if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0;
+  int MPI_Comm_dup_intracomm(MPI_Comm comm, MPI_Comm *newcomm)
+  {
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep      = comm->ep_comm_ptr->size_rank_info[1].second;
 
 
-    int my_rank = comm.ep_comm_ptr->size_rank_info[1].first;
-    int num_ep  = comm.ep_comm_ptr->size_rank_info[1].second;
-
-
-    if(0 == my_rank)
+    if(0 == ep_rank_loc)
     {
       MPI_Info info;
       MPI_Comm *out_comm;
-      ::MPI_Comm *mpi_dup = new ::MPI_Comm;
 
-      ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm);
-
-      ::MPI_Comm_dup(in_comm, mpi_dup);
-
-      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
-      comm.ep_comm_ptr->comm_list->mem_bridge = out_comm;
+      MPI_Comm_create_endpoints(comm->mpi_comm, num_ep, info, out_comm);
+      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm;
     }
 
-    MPI_Barrier(comm);
+    MPI_Barrier_local(comm);
 
-    *newcomm = (comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]);
+    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[ep_rank_loc]);
+    
+  }
 
-    return MPI_SUCCESS;
+  int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
+  {
+    
+    if(!comm->is_ep)
+    {
+      Debug("MPI_Comm_dup with MPI\n");
+      return MPI_Comm_dup_mpi(comm, newcomm); 
+    }
+
+    if(comm->is_intercomm) return MPI_Comm_dup_intercomm(comm, newcomm);
+
+    
+    return MPI_Comm_dup_intracomm(comm, newcomm); 
+
+   
   }
 
@@ -60,78 +60,79 @@
   {
     
-    if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0;
-
-    int my_rank = comm.ep_comm_ptr->size_rank_info[1].first;
-    int num_ep  = comm.ep_comm_ptr->size_rank_info[1].second;
+    int newcomm_ep_rank =comm->ep_comm_ptr->intercomm->size_rank_info[0].first; 
+    int newcomm_ep_rank_loc = comm->ep_comm_ptr->intercomm->size_rank_info[1].first;
+    int newcomm_num_ep = comm->ep_comm_ptr->intercomm->size_rank_info[1].second;
 
 
-    if(0 == my_rank)
+    if(0 == newcomm_ep_rank_loc)
     {
+      //printf("in dup , newcomm_ep_rank_loc = 0 :  ep %d\n", comm->ep_comm_ptr->intercomm->size_rank_info[0].first);
+
       MPI_Info info;
       MPI_Comm *out_comm;
-      ::MPI_Comm *mpi_dup = new ::MPI_Comm;
 
-      ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm);
+      MPI_Comm_create_endpoints(comm->mpi_comm, newcomm_num_ep, info, out_comm);
 
-      ::MPI_Comm_dup(in_comm, mpi_dup);
+      ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm;
+      ::MPI_Comm_dup(to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter_comm);
 
-      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
-
-      ::MPI_Comm *mpi_inter = new ::MPI_Comm;
-
-      ::MPI_Comm_dup(to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter);
-      
-      for(int i=0; i<num_ep; i++)
+      for(int i=0; i<newcomm_num_ep; i++)
       {
-        out_comm[i].ep_comm_ptr->comm_label = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->comm_label;
-        out_comm[i].ep_comm_ptr->intercomm = new ep_intercomm;
-
-        out_comm[i].ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter;
-        out_comm[i].is_intercomm = true;
-
-        out_comm[i].ep_comm_ptr->intercomm->intercomm_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->remote_rank_map = new RANK_MAP;
-
-        int map_size = 0;
-        map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->size();
-        out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->resize(map_size);
-        for(int ii=0; ii<map_size; ii++)
-          out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->at(ii);
-
-        map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->size();
-        out_comm[i].ep_comm_ptr->intercomm->local_rank_map->resize(map_size);
-        for(int ii=0; ii<map_size; ii++)
-          out_comm[i].ep_comm_ptr->intercomm->local_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->at(ii);
-
-        map_size = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->size();
-        out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->resize(map_size);
-        for(int ii=0; ii<map_size; ii++)
-          out_comm[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii) = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->at(ii);
+        out_comm[i]->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;
+      }
 
 
-        //out_comm[i].ep_comm_ptr->intercomm->intercomm_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map;
-        //out_comm[i].ep_comm_ptr->intercomm->local_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map;
-        //out_comm[i].ep_comm_ptr->intercomm->remote_rank_map = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map;
-
-        out_comm[i].ep_comm_ptr->intercomm->local_comm = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_comm;        
-        out_comm[i].ep_comm_ptr->intercomm->intercomm_tag = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_tag;
-
-        for(int j =0; j<3; j++)
-        {
-          out_comm[i].ep_comm_ptr->intercomm->size_rank_info[j] = comm.ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->size_rank_info[j];
-        }
-
-      }
-
-      comm.ep_comm_ptr->comm_list->mem_bridge = out_comm;
+      comm->ep_comm_ptr->comm_list[0]->mem_bridge = out_comm;
     }
 
-    MPI_Barrier(comm);
+    MPI_Barrier_local(comm);
 
-    *newcomm = comm.ep_comm_ptr->comm_list->mem_bridge[my_rank];
+    *newcomm = (comm->ep_comm_ptr->comm_list[0]->mem_bridge[newcomm_ep_rank_loc]);
+
+    (*newcomm)->ep_comm_ptr->size_rank_info[0] = comm->ep_comm_ptr->size_rank_info[0];
+    (*newcomm)->ep_comm_ptr->size_rank_info[1] = comm->ep_comm_ptr->size_rank_info[1];
+    (*newcomm)->ep_comm_ptr->size_rank_info[2] = comm->ep_comm_ptr->size_rank_info[2];
+
+    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[0] = comm->ep_comm_ptr->intercomm->size_rank_info[0];
+    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[1] = comm->ep_comm_ptr->intercomm->size_rank_info[1];
+    (*newcomm)->ep_comm_ptr->intercomm->size_rank_info[2] = comm->ep_comm_ptr->intercomm->size_rank_info[2];
+
+    (*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;
+    }
+
     
 
-    return MPI_SUCCESS;
+
+
+    
   }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_exscan.cpp	(revision 1520)
@@ -50,7 +50,7 @@
     valid_op(op);
 
-    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 mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
+    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 mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
     
 
@@ -60,9 +60,9 @@
     if(ep_rank_loc == 0 && mpi_rank != 0)
     {
-      comm.my_buffer->void_buffer[0] = recvbuf;
+      comm->my_buffer->void_buffer[0] = recvbuf;
     }
     if(ep_rank_loc == 0 && mpi_rank == 0)
     {
-      comm.my_buffer->void_buffer[0] = const_cast<void*>(sendbuf);  
+      comm->my_buffer->void_buffer[0] = const_cast<void*>(sendbuf);  
     } 
       
@@ -70,9 +70,9 @@
     MPI_Barrier_local(comm);
 
-    memcpy(recvbuf, comm.my_buffer->void_buffer[0], datasize*count);
+    memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize*count);
 
     MPI_Barrier_local(comm);
 
-    comm.my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);  
+    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);  
     
     MPI_Barrier_local(comm);
@@ -84,5 +84,5 @@
         assert(datasize == sizeof(int));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_sum<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
+          reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
       }
      
@@ -91,5 +91,5 @@
         assert(datasize == sizeof(float));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_sum<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
+          reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
       }
       
@@ -99,5 +99,5 @@
         assert(datasize == sizeof(double));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_sum<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+          reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
       }
 
@@ -106,5 +106,5 @@
         assert(datasize == sizeof(char));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_sum<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+          reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
       }
 
@@ -113,5 +113,5 @@
         assert(datasize == sizeof(long));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_sum<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+          reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
       }
 
@@ -120,5 +120,5 @@
         assert(datasize == sizeof(unsigned long));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_sum<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
+          reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
       }
 
@@ -134,5 +134,5 @@
         assert(datasize == sizeof(int));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_max<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
+          reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
       }
 
@@ -141,5 +141,5 @@
         assert(datasize == sizeof(float));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_max<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
+          reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
       }
 
@@ -148,5 +148,5 @@
         assert(datasize == sizeof(double));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_max<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+          reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
       }
 
@@ -155,5 +155,5 @@
         assert(datasize == sizeof(char));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_max<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+          reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
       }
 
@@ -162,5 +162,5 @@
         assert(datasize == sizeof(long));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_max<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+          reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
       }
 
@@ -169,5 +169,5 @@
         assert(datasize == sizeof(unsigned long));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_max<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
+          reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
       }
      
@@ -181,5 +181,5 @@
         assert(datasize == sizeof(int));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_min<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
+          reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
       }
 
@@ -188,5 +188,5 @@
         assert(datasize == sizeof(float));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_min<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
+          reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
       }
 
@@ -195,5 +195,5 @@
         assert(datasize == sizeof(double));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_min<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+          reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
       }
 
@@ -202,5 +202,5 @@
         assert(datasize == sizeof(char));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_min<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+          reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
       }
 
@@ -209,5 +209,5 @@
         assert(datasize == sizeof(long));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_min<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+          reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
       }
 
@@ -216,5 +216,5 @@
         assert(datasize == sizeof(unsigned long));
         for(int i=0; i<ep_rank_loc; i++)
-          reduce_min<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
+          reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
       }
 
@@ -228,17 +228,17 @@
   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_Scan(sendbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
     }
     
     valid_type(datatype);
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
     ::MPI_Aint datasize, lb;
@@ -253,5 +253,5 @@
     std::vector<int> my_map(mpi_size, 0);
 
-    for(int i=0; i<comm.rank_map->size(); i++) my_map[comm.rank_map->at(i).second]++;
+    for(int i=0; i<comm->ep_rank_map->size(); i++) my_map[comm->ep_rank_map->at(i).second]++;
 
     for(int i=0; i<mpi_rank; i++) my_src += my_map[i];
@@ -291,5 +291,5 @@
 
     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));
+      ::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]);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp	(revision 1520)
@@ -22,12 +22,19 @@
   int MPI_Abort(MPI_Comm comm, int errorcode)
   {
-    int id = omp_get_thread_num();
+    if(!comm->is_ep)
+      return MPI_Abort_mpi(comm, errorcode);
 
-    if(id == 0)
+    else
     {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
-      ::MPI_Abort(mpi_comm, errorcode);
+      if(comm->ep_comm_ptr->size_rank_info[1].first == 0)
+      {
+        ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode);
+      }
     }
-    return 0;
+  }
+
+  int MPI_Abort_mpi(MPI_Comm comm, int errorcode)
+  {
+    return ::MPI_Abort(to_mpi_comm(comm->mpi_comm), errorcode);
   }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp	(revision 1520)
@@ -16,7 +16,7 @@
     void* fint = new ::MPI_Fint;
     #ifdef _intelmpi
-    *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm.mpi_comm));
+    *static_cast< ::MPI_Fint*>(fint) = (::MPI_Fint)(to_mpi_comm(comm->mpi_comm));
     #elif _openmpi
-    *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm.mpi_comm));
+    *static_cast< ::MPI_Fint*>(fint) = MPI_Comm_c2f(to_mpi_comm(comm->mpi_comm));
     #endif
     
@@ -29,5 +29,5 @@
       {
         fc_comm_map.insert(std::make_pair( std::make_pair( *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num()) , comm));
-        printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm.ep_comm_ptr);
+        printf("EP_Comm_c2f : MAP %p insert: %d, %d, %p\n", &fc_comm_map, *static_cast< ::MPI_Fint*>(fint), omp_get_thread_num(), comm->ep_comm_ptr);
       }
     }
@@ -52,5 +52,5 @@
       MPI_Comm comm_ptr;
       comm_ptr = it->second;
-      printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr.ep_comm_ptr);
+      printf("EP_Comm_f2c : MAP %p find: %d, %d, %p\n", &fc_comm_map, it->first.first, it->first.second, comm_ptr->ep_comm_ptr);
       return  comm_ptr;
     }
@@ -65,5 +65,5 @@
     #endif
 
-    if(*base_comm != to_mpi_comm(MPI_COMM_NULL.mpi_comm))
+    if(*base_comm != to_mpi_comm(MPI_COMM_NULL->mpi_comm))
     {
       if(omp_get_thread_num() == 0)
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1520)
@@ -9,153 +9,195 @@
   int MPI_Comm_free(MPI_Comm *comm)
   {
-    if(! comm->is_ep)
-    {
-      if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
-      {
-        ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-
-        ::MPI_Comm_free(&mpi_comm);
-        Debug("comm is MPI, freed\n");
-      }
-      return 0;
-    }
-
-    else if(comm->is_intercomm)
-    {
-      return MPI_Comm_free_intercomm(comm);
-    }
-
-    else
-    {
-      int ep_rank_loc, num_ep;
-
-      ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
-      num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
-
-      MPI_Barrier(*comm);
-
-      if(ep_rank_loc == 0)
-      {
-        Debug("comm is EP, mpi_comm_ptr != NULL\n");
-
-        delete comm->my_buffer;
-
-
-        if(comm->ep_barrier != NULL)
-        {
-          comm->ep_barrier->~OMPbarrier();
-          Debug("ep_barrier freed\n");
-        }
-
-
-        if( ! comm->rank_map->empty() )
-        {
-          comm->rank_map->clear();
-          Debug("rank_map emptied\n");
-        }
-
-        for(int i=0; i<num_ep; i++)
-        {
-          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();
-          Debug("message queue freed\n");
-          
-
-          if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL)
-          {
-            delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;
-            Debug("ep_comm_ptr freed\n");
-          }
-        }
-
-        if( to_mpi_comm(comm->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm) 
-          && to_mpi_comm(comm->mpi_comm) != *static_cast< ::MPI_Comm*>(MPI_COMM_WORLD.mpi_comm))
-        {
-          ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-          ::MPI_Comm_free(&mpi_comm);
-          Debug("mpi_comm freed\n");
-        }
-
-       if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
-
-      }
-
-      return 0;
-    }
-
-
-
-  }
-
-  int MPI_Comm_free_intercomm(MPI_Comm *comm)
-  {
+    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);
+    }
+  }
+
+
+
+  int MPI_Comm_free_mpi(MPI_Comm *comm)
+  {
+    Debug("MPI_Comm_free with MPI\n");
+
+    return ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
+    
+  }
+
+  int MPI_Comm_free_intracomm(MPI_Comm *comm)
+  {
+    Debug("MPI_Comm_free with EP_intracomm\n");
+
     int ep_rank_loc, num_ep;
 
-    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);
+    ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
+    num_ep = (*comm)->ep_comm_ptr->size_rank_info[1].second;
+
+    MPI_Barrier(*comm);
 
     if(ep_rank_loc == 0)
     {
-      Debug("comm is EP, mpi_comm_ptr != NULL\n");
-
-
-      if(comm->ep_barrier != NULL)
-      {
-        comm->ep_barrier->~OMPbarrier();
-        Debug("ep_barrier freed\n");
-      }
-
-
-      if( ! comm->rank_map->empty() )
-      {
-        comm->rank_map->clear();
-        Debug("rank_map emptied\n");
-      }
+
+#ifdef _showinfo
+      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
+#endif
+      delete (*comm)->my_buffer;
+
+
+      
+#ifdef _showinfo        
+      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
+#endif
+      delete (*comm)->ep_barrier;
+      
+
+
+      (*comm)->ep_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
+#endif
+      delete (*comm)->ep_rank_map;
+      
 
       for(int i=0; i<num_ep; i++)
       {
-        comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->message_queue->clear();
-        Debug("message queue freed\n");
-
-        #pragma omp critical (memory_free)
-        if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm != NULL)
-        {
-          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->local_rank_map->clear();
-          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->remote_rank_map->clear();
-          comm->ep_comm_ptr->comm_list[i].ep_comm_ptr->intercomm->intercomm_rank_map->clear();
-          Debug("intercomm local/remote/intercomm_rank_map emptied\n");
-        }  
-
-        if(comm->ep_comm_ptr->comm_list[i].ep_comm_ptr != NULL)
-        {
-          delete comm->ep_comm_ptr->comm_list[i].ep_comm_ptr;
-          Debug("ep_comm_ptr freed\n");
-        }
+        (*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];
       }
 
-      if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
+#ifdef _showinfo
+      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
+#endif
+      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
+      
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
+#endif
+      delete[] (*comm)->ep_comm_ptr->comm_list;
+    }
+  }
+
+
+
+
+
+
+
+  int MPI_Comm_free_intercomm(MPI_Comm *comm)
+  {
+    int ep_rank;
+    MPI_Comm_rank(*comm, &ep_rank);
+    int ep_rank_loc = (*comm)->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep =      (*comm)->ep_comm_ptr->size_rank_info[1].second;
+    
+    int newcomm_ep_rank =(*comm)->ep_comm_ptr->intercomm->size_rank_info[0].first; 
+    int newcomm_ep_rank_loc = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].first;
+    int newcomm_num_ep = (*comm)->ep_comm_ptr->intercomm->size_rank_info[1].second;
+
+    MPI_Barrier(*comm);
+
+    if(ep_rank_loc == 0)
+    {
+      (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map);
+#endif
+      delete (*comm)->ep_comm_ptr->intercomm->intercomm_rank_map;
+
+      (*comm)->ep_comm_ptr->intercomm->local_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->intercomm->local_rank_map = %p\n", (*comm)->ep_comm_ptr->intercomm->local_rank_map);
+#endif
+      delete (*comm)->ep_comm_ptr->intercomm->local_rank_map;
+    }
+
+    if(newcomm_ep_rank_loc == 0)
+    {
+
+#ifdef _showinfo
+      printf("delete (*comm)->my_buffer = %p\n", (*comm)->my_buffer);
+#endif
+      delete (*comm)->my_buffer;
+
+
+      
+#ifdef _showinfo        
+      printf("delete (*comm)->ep_barrier = %p\n", (*comm)->ep_barrier);
+#endif
+      delete (*comm)->ep_barrier;
+      
+
+      (*comm)->ep_rank_map->clear();
+#ifdef _showinfo
+      printf("delete (*comm)->ep_rank_map = %p\n", (*comm)->ep_rank_map);
+#endif
+      delete (*comm)->ep_rank_map;
+      
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", (*comm)->ep_comm_ptr->intercomm->mpi_inter_comm);
+#endif
+      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->ep_comm_ptr->intercomm->mpi_inter_comm));
+
+      for(int i=0; i<newcomm_num_ep; i++)
       {
-        ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
-        ::MPI_Comm_free(&mpi_comm);
-        Debug("mpi_comm freed\n");
+        (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue->clear();
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->message_queue = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->message_queue;
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr->intercomm = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr->intercomm;        
+          
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d]->ep_comm_ptr = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i]->ep_comm_ptr;
+
+
+#ifdef _showinfo
+        printf("delete (*comm)->ep_comm_ptr->comm_list[%d] = %p\n", i, (*comm)->ep_comm_ptr->comm_list[i]);
+#endif
+        delete (*comm)->ep_comm_ptr->comm_list[i];
+
       }
 
-      if(comm->ep_comm_ptr->intercomm->mpi_inter_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
-      {
-        ::MPI_Comm mpi_comm = to_mpi_comm(comm->ep_comm_ptr->comm_list->ep_comm_ptr->intercomm->mpi_inter_comm);
-        ::MPI_Comm_free(&mpi_comm);
-        Debug("mpi_intercomm freed\n");
-      }
-
-     if(comm != NULL) {delete[] comm->ep_comm_ptr->comm_list; Debug("comm freed\n");}
-
-    }
-
-    
-    
-    return 0;
-  }
-
+#ifdef _showinfo
+      printf("delete (*comm)->mpi_comm = %p\n", (*comm)->mpi_comm);
+#endif
+      ::MPI_Comm_free(to_mpi_comm_ptr((*comm)->mpi_comm));
+      
+#ifdef _showinfo
+      printf("delete (*comm)->ep_comm_ptr->comm_list = %p\n", (*comm)->ep_comm_ptr->comm_list);
+#endif
+      delete[] (*comm)->ep_comm_ptr->comm_list;
+    }
+  }
 
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gather.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gather.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gather.cpp	(revision 1520)
@@ -23,9 +23,9 @@
     ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
 
-    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 ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
 
     #pragma omp critical (_gather)
-    comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
+    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
 
     MPI_Barrier_local(comm);
@@ -34,5 +34,5 @@
     {
       for(int i=0; i<num_ep; i++)
-        memcpy(recvbuf + datasize * i * count, comm.my_buffer->void_buffer[i], datasize * count);
+        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,21 +44,21 @@
   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)
+    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));
+                   root, to_mpi_comm(comm->mpi_comm));
     }
 
     assert(sendcount == recvcount && sendtype == recvtype);
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
-    int root_mpi_rank = comm.rank_map->at(root).second;
-    int root_ep_loc = comm.rank_map->at(root).first;
+    int root_mpi_rank = comm->ep_rank_map->at(root).second;
+    int root_ep_loc = comm->ep_rank_map->at(root).first;
 
     ::MPI_Aint datasize, lb;
@@ -90,5 +90,5 @@
       for(int i=0; i<ep_size; i++)
       {
-        recvcounts[comm.rank_map->at(i).second]+=sendcount;
+        recvcounts[comm->ep_rank_map->at(i).second]+=sendcount;
       }
 
@@ -96,5 +96,5 @@
         displs[i] = displs[i-1] + recvcounts[i-1];
 
-      ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, recvcounts.data(), displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, recvcounts.data(), displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
     }   
 
@@ -111,5 +111,5 @@
       for(int i=0; i<ep_size; i++)
       {
-        offset = displs[comm.rank_map->at(i).second] + comm.rank_map->at(i).first * sendcount; 
+        offset = displs[comm->ep_rank_map->at(i).second] + comm->ep_rank_map->at(i).first * sendcount; 
         memcpy(recvbuf + i*sendcount*datasize, tmp_recvbuf+offset*datasize, sendcount*datasize);
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp	(revision 1520)
@@ -23,10 +23,10 @@
     ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
 
-    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 ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
 
 
     #pragma omp critical (_gatherv)
-    comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
+    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
 
     MPI_Barrier_local(comm);
@@ -35,5 +35,5 @@
     {
       for(int i=0; i<num_ep; i++)
-        memcpy(recvbuf + datasize*displs[i], comm.my_buffer->void_buffer[i], datasize*recvcounts[i]);
+        memcpy(recvbuf + datasize*displs[i], comm->my_buffer->void_buffer[i], datasize*recvcounts[i]);
 
     }
@@ -46,8 +46,8 @@
   {
   
-    if(!comm.is_ep)
+    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));
+                    to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
     }
 
@@ -56,13 +56,13 @@
 
     
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
-    int root_mpi_rank = comm.rank_map->at(root).second;
-    int root_ep_loc = comm.rank_map->at(root).first;
+    int root_mpi_rank = comm->ep_rank_map->at(root).second;
+    int root_ep_loc = comm->ep_rank_map->at(root).first;
 
     ::MPI_Aint datasize, lb;
@@ -126,5 +126,5 @@
       for(int i=0; i<ep_size; i++)
       {
-        mpi_recvcounts[comm.rank_map->at(i).second]+=recvcounts[i];
+        mpi_recvcounts[comm->ep_rank_map->at(i).second]+=recvcounts[i];
       }
 
@@ -133,5 +133,5 @@
 
 
-      ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Gatherv(local_recvbuf, sendcount*num_ep, to_mpi_type(sendtype), tmp_recvbuf, mpi_recvcounts.data(), mpi_displs.data(), to_mpi_type(recvtype), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
     }   
 
@@ -144,6 +144,6 @@
       {
         int extra = 0;
-        for(int j=0, k=0; j<ep_size, k<comm.rank_map->at(i).first; j++)
-          if(comm.rank_map->at(i).second == comm.rank_map->at(j).second)
+        for(int j=0, k=0; j<ep_size, k<comm->ep_rank_map->at(i).first; j++)
+          if(comm->ep_rank_map->at(i).second == comm->ep_rank_map->at(j).second)
           {
             extra += recvcounts[j];
@@ -151,5 +151,5 @@
           }  
 
-        offset = mpi_displs[comm.rank_map->at(i).second] +  extra;
+        offset = mpi_displs[comm->ep_rank_map->at(i).second] +  extra;
 
         memcpy(recvbuf+displs[i]*datasize, tmp_recvbuf+offset*datasize, recvcounts[i]*datasize);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_init.cpp	(revision 1520)
@@ -11,34 +11,27 @@
   int MPI_Init_thread(int *argc, char*** argv, int required, int*provided)
   {
-    //printf("MPI_Init_thread\n");
+    Debug("MPI_Init_thread with EP/MPI\n");
 
-    int id = omp_get_thread_num();
-
-    if(id == 0)
+    if(omp_get_thread_num() == 0)
     {
       ::MPI_Init_thread(argc, argv, required, provided);
     }
-    return 0;
   }
 
   int MPI_Init(int *argc, char ***argv)
   {
-    //printf("MPI_init called\n");
-    int id = omp_get_thread_num();
+    Debug("MPI_Init with EP/MPI\n");
 
-    if(id == 0)
+    if(omp_get_thread_num() == 0)
     {
       ::MPI_Init(argc, argv);
     }
-  	return 0;
   }
 
   int MPI_Initialized(int *flag)
   {
-    //printf("MPI_initialized called\n");
+    Debug("MPI_Initialized with EP/MPI\n");
 
-    ::MPI_Initialized(flag);
-    
-    return 0;
+    return ::MPI_Initialized(flag);
   }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp	(revision 1520)
@@ -10,18 +10,55 @@
   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);
+    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;
+    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);   
+      }
+      
+    }
+
+
 
 
@@ -61,6 +98,6 @@
       if( leader_ranks[1] * leader_ranks[4] == 1)
       {
-        if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_unique_leader\n");
-        local_comm.ep_comm_ptr->comm_label = -99;
+        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_unique_leader\n");
+        local_comm->ep_comm_ptr->comm_label = -99;
 
         return MPI_Intercomm_create_unique_leader(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
@@ -77,9 +114,9 @@
             // change leader
             is_decider = true;
-            int target = local_comm.rank_map->at(local_leader).second;
+            int target = local_comm->ep_rank_map->at(local_leader).second;
             {
               for(int i=0; i<ep_size; i++)
               {
-                if(local_comm.rank_map->at(i).second != target && local_comm.rank_map->at(i).first == 0)
+                if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0)
                 {
                   new_local_leader = i;
@@ -100,9 +137,9 @@
             // change leader
             is_decider = true;
-            int target = local_comm.rank_map->at(local_leader).second;
+            int target = local_comm->ep_rank_map->at(local_leader).second;
             {
               for(int i=0; i<ep_size; i++)
               {
-                if(local_comm.rank_map->at(i).second != target && local_comm.rank_map->at(i).first == 0)
+                if(local_comm->ep_rank_map->at(i).second != target && local_comm->ep_rank_map->at(i).first == 0)
                 {
                   new_local_leader = i;
@@ -146,5 +183,5 @@
         if(ep_rank == new_local_leader)
         {
-          ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &leader_in_world[0]);
+          ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &leader_in_world[0]);
         }
 
@@ -165,16 +202,14 @@
         MPI_Bcast(&leader_in_world[1], 1, MPI_INT, local_leader, local_comm);
 
-        local_comm.ep_comm_ptr->comm_label = tag;
-
-        if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_from_world\n");
-
-        return MPI_Intercomm_create_from_world(local_comm, new_local_leader, MPI_COMM_WORLD.mpi_comm, leader_in_world[1], new_tag_in_world, newintercomm);
+        local_comm->ep_comm_ptr->comm_label = tag;
+
+        if(ep_rank == local_leader) printf("calling MPI_Intercomm_create_from_world\n");
+
+        return MPI_Intercomm_create_from_world(local_comm, new_local_leader, MPI_COMM_WORLD->mpi_comm, leader_in_world[1], new_tag_in_world, newintercomm);
         
       }
     }
 
-    if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_kernel\n");
-
-    return MPI_Intercomm_create_kernel(local_comm, local_leader, peer_comm, remote_leader, tag, newintercomm);
+    
 
   }
@@ -183,12 +218,12 @@
   {
     *flag = false;
-    if(comm.is_ep)
-    {
-      *flag = comm.is_intercomm;
+    if(comm->is_ep)
+    {
+      *flag = comm->is_intercomm;
       return 0;
     } 
-    else if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
-    {
-      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
+    else if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL->mpi_comm))
+    {
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
       
       ::MPI_Comm_test_inter(mpi_comm, flag);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp	(revision 1520)
@@ -14,569 +14,622 @@
     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
+    ep_rank     = local_comm->ep_comm_ptr->size_rank_info[0].first;
+    ep_rank_loc = local_comm->ep_comm_ptr->size_rank_info[1].first;
+    mpi_rank    = local_comm->ep_comm_ptr->size_rank_info[2].first;
+    ep_size     = local_comm->ep_comm_ptr->size_rank_info[0].second;
+    num_ep      = local_comm->ep_comm_ptr->size_rank_info[1].second;
+    mpi_size    = local_comm->ep_comm_ptr->size_rank_info[2].second;
+
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+    // step 1 : local leaders exchange ep_size, leader_rank_in_peer, leader_rank_in_peer_mpi, leader_rank_in_world. //
+    //          local leaders bcast results to all ep in local_comm                                                 //
+    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    bool is_local_leader = ep_rank==local_leader? true: false;
+
+
+    
+    int local_leader_rank_in_peer;
+    int local_leader_rank_in_peer_mpi;
+    int local_leader_rank_in_world;
+
+    int remote_ep_size;
+    int remote_leader_rank_in_peer;
+    int remote_leader_rank_in_peer_mpi;
+    int remote_leader_rank_in_world;
+
+    int send_quadruple[4];
+    int recv_quadruple[4];
+
+
+    if(is_local_leader)
+    {
+      MPI_Comm_rank(peer_comm, &local_leader_rank_in_peer);
+      ::MPI_Comm_rank(to_mpi_comm(peer_comm->mpi_comm), &local_leader_rank_in_peer_mpi);
+      ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &local_leader_rank_in_world);
+
+      send_quadruple[0] = ep_size;
+      send_quadruple[1] = local_leader_rank_in_peer;
+      send_quadruple[2] = local_leader_rank_in_peer_mpi;
+      send_quadruple[3] = local_leader_rank_in_world;
+
+      MPI_Request request;
+      MPI_Status status;
+
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(recv_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(send_quadruple, 4, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+
+      remote_ep_size                 = recv_quadruple[0];
+      remote_leader_rank_in_peer     = recv_quadruple[1];
+      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
+      remote_leader_rank_in_world    = recv_quadruple[3];
+#ifdef _showinfo
+      printf("peer_rank = %d, packed exchange OK\n", local_leader_rank_in_peer);
+#endif
+    }
+
+    MPI_Bcast(send_quadruple, 4, MPI_INT, local_leader, local_comm);
+    MPI_Bcast(recv_quadruple, 4, MPI_INT, local_leader, local_comm);
+
+    if(!is_local_leader)
+    {
+      local_leader_rank_in_peer     = send_quadruple[1];
+      local_leader_rank_in_peer_mpi = send_quadruple[2];
+      local_leader_rank_in_world    = send_quadruple[3];
+
+      remote_ep_size                 = recv_quadruple[0];
+      remote_leader_rank_in_peer     = recv_quadruple[1];
+      remote_leader_rank_in_peer_mpi = recv_quadruple[2];
+      remote_leader_rank_in_world    = recv_quadruple[3];
+    }
+
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, ep_size = %d, remote_ep_size = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_size, remote_ep_size);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm); 
+#endif
+
+    ///////////////////////////////////////////////////////////////////
+    // step 2 : gather ranks in world for both local and remote comm //
+    ///////////////////////////////////////////////////////////////////
 
     int rank_in_world;
-    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.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];
-      }
+    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD->mpi_comm), &rank_in_world);
+
+    int *ranks_in_world_local  = new int[ep_size];
+    int *ranks_in_world_remote = new int[remote_ep_size];
+
+    MPI_Allgather(&rank_in_world, 1, MPI_INT, ranks_in_world_local, 1, MPI_INT, local_comm);
+
+    if(is_local_leader)
+    {
+      MPI_Request request;
+      MPI_Status status;
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+       
+        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(ranks_in_world_remote, remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(ranks_in_world_local,  ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+#ifdef _showinfo
+      printf("peer_rank = %d, ranks_in_world exchange OK\n", local_leader_rank_in_peer);
+#endif
+    }
+
+    MPI_Bcast(ranks_in_world_remote, remote_ep_size, MPI_INT, local_leader, local_comm);
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+    if(remote_leader == 4)
+    {
+      for(int i=0; i<ep_size; i++)
+      {
+        if(ep_rank == i)
+        {
+          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_local[i]);
+          }
+    
+          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<remote_ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_remote[i]);
+          }
+          printf("\n");
+         
+        }
+        
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+      }
+    }
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    
+    if(remote_leader == 13)
+    {
+      for(int i=0; i<ep_size; i++)
+      {
+        if(ep_rank == i)
+        {
+          printf("peer_rank = %d, ranks_in_world_local = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_local[i]);
+          }
+    
+          printf("\npeer_rank = %d, ranks_in_world_remote = \n", peer_comm->ep_comm_ptr->size_rank_info[0].first);
+          for(int i=0; i<remote_ep_size; i++)
+          {
+            printf("%d\t", ranks_in_world_remote[i]);
+          }
+          printf("\n");
+         
+        }
+        
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+        MPI_Barrier(local_comm);
+      }
+    }
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+    //////////////////////////////////////////////////////////////
+    // step 3 : determine the priority and ownership of each ep //
+    //////////////////////////////////////////////////////////////
+
+    bool priority = local_leader_rank_in_peer > remote_leader_rank_in_peer? true : false;
+
+
+    int ownership;
+
+    if(rank_in_world == ranks_in_world_local[local_leader]) ownership = 1;
+    else if(rank_in_world == remote_leader_rank_in_world)   ownership = 0;
+    else
+    {
+      ownership = 1;
+      for(int i=0; i<remote_ep_size; i++)
+      {
+        if(rank_in_world == ranks_in_world_remote[i])
+        {
+          ownership = priority? 1 : 0;
+          break;
+        }  
+      }
+    }
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, priority = %d, local_leader_rank_in_peer = %d, remote_leader_rank_in_peer = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, local_leader_rank_in_peer, remote_leader_rank_in_peer);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+#endif
+
+    
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, priority = %d, ownership = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, priority, ownership);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+#endif
+
+    //////////////////////////////////////////////////////
+    // step 4 : extract local_comm and create intercomm //
+    //////////////////////////////////////////////////////
+
+    bool is_involved = is_local_leader || (!is_local_leader && ep_rank_loc == 0 && rank_in_world != local_leader_rank_in_world);
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, is_involved = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, is_involved);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+    if(is_involved)
+    {
+      ::MPI_Group local_group;
+      ::MPI_Group extracted_group;
+      ::MPI_Comm *extracted_comm = new ::MPI_Comm;
+
+
+      ::MPI_Comm_group(to_mpi_comm(local_comm->mpi_comm), &local_group);
+
+      int *ownership_list = new int[mpi_size];
+      int *mpi_rank_list = new int[mpi_size];
+
+      ::MPI_Allgather(&ownership, 1, to_mpi_type(MPI_INT), ownership_list, 1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm));
+      ::MPI_Allgather(&mpi_rank,  1, to_mpi_type(MPI_INT), mpi_rank_list,  1, to_mpi_type(MPI_INT), to_mpi_comm(local_comm->mpi_comm));
+
+      
+      int n=0;
+      for(int i=0; i<mpi_size; i++)
+      { 
+        n+=ownership_list[i];
+      }
+
+      int *new_mpi_rank_list = new int[n];
+      int j=0;
+      for(int i=0; i<mpi_size; i++)
+      { 
+        if(ownership_list[i] !=0)
+        {
+          new_mpi_rank_list[j++] = mpi_rank_list[i];
+        }
+      }
+
+
+      ::MPI_Group_incl(local_group, n, new_mpi_rank_list, &extracted_group);
+
+      ::MPI_Comm_create(to_mpi_comm(local_comm->mpi_comm), extracted_group, extracted_comm);
+
+      ::MPI_Comm *mpi_inter_comm = new ::MPI_Comm;
+
+      int local_leader_rank_in_extracted_comm;
 
       if(is_local_leader)
       {
-        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.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.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++)
+        ::MPI_Comm_rank(*extracted_comm, &local_leader_rank_in_extracted_comm);
+      }
+
+      ::MPI_Bcast(&local_leader_rank_in_extracted_comm, 1, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));
+
+
+      if(ownership)
+        ::MPI_Intercomm_create(*extracted_comm, local_leader_rank_in_extracted_comm, to_mpi_comm(peer_comm->mpi_comm), remote_leader_rank_in_peer_mpi, tag, mpi_inter_comm);
+
+      ////////////////////////////////////
+      // step 5 :: determine new num_ep //
+      ////////////////////////////////////
+
+      int num_ep_count=0;
+
+      for(int i=0; i<ep_size; i++)
+      {
+        if(rank_in_world == ranks_in_world_local[i])
+          num_ep_count++;
+      }
+      
+      for(int i=0; i<remote_ep_size; i++)
+      {
+        if(rank_in_world == ranks_in_world_remote[i])
+          num_ep_count++;
+      }
+
+
+      ///////////////////////////////////////////////////
+      // step 6 : create endpoints from extracted_comm //
+      ///////////////////////////////////////////////////
+
+      if(ownership)
+      {
+        MPI_Comm *ep_comm;
+        MPI_Info info;
+        MPI_Comm_create_endpoints(extracted_comm, num_ep_count, info, ep_comm);
+      
+#ifdef _showinfo
+        printf("new ep_comm->ep_comm_ptr->intercomm->mpi_inter_comm = %p\n", mpi_inter_comm);
+#endif
+
+        for(int i=0; i<num_ep_count; i++)
         {
-          int target = rank_info[0][i];
-          found = false;
-          for(int j=0; j<size_info[1]; j++)
+          ep_comm[i]->is_intercomm = true;
+          ep_comm[i]->ep_comm_ptr->comm_label = ranks_in_world_local[local_leader];
+          ep_comm[i]->ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
+#ifdef _showinfo
+          printf("new ep_comm[%d]->ep_comm_ptr->intercomm = %p\n", i, ep_comm[i]->ep_comm_ptr->intercomm);
+#endif
+          ep_comm[i]->ep_comm_ptr->intercomm->mpi_inter_comm = mpi_inter_comm;
+          
+        }
+
+
+        #pragma omp critical (write_to_tag_list)      
+        intercomm_list.push_back(make_pair( make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)) , make_pair(ep_comm , make_pair(num_ep_count, 0))));
+        #pragma omp flush
+#ifdef _showinfo
+        for(int i=0; i<num_ep_count; i++)
+          printf("peer_rank = %d, ep_comm = %p, ep_comm[%d] -> new_ep_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_comm, i, ep_comm[i]->ep_comm_ptr->size_rank_info[0].first);
+#endif
+      }
+
+
+      delete ownership_list;
+      delete mpi_rank_list;
+      delete new_mpi_rank_list;
+
+    }
+
+    int repeated=0;
+    for(int i=0; i<remote_ep_size; i++)
+    {
+      if(rank_in_world == ranks_in_world_remote[i])
+        repeated++;
+    }
+
+    int my_turn = ownership? ep_rank_loc : ep_rank_loc+repeated;
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, ep_rank_loc = %d, ownership = %d, repeated = %d, my_turn = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, ep_rank_loc, ownership, repeated, my_turn);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+
+    #pragma omp flush
+    #pragma omp critical (read_from_intercomm_list)
+    {
+      bool flag=true;
+      while(flag)
+      {
+        for(std::list<std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > >::iterator iter = intercomm_list.begin(); iter!=intercomm_list.end(); iter++)
+        {
+          if(iter->first == make_pair(tag, min(local_leader_rank_in_world, remote_leader_rank_in_world)))
           {
-            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;
+            *newintercomm = iter->second.first[my_turn];
+            
+            iter->second.second.second++;
+            
+            if(iter->second.second.first == iter->second.second.second)
+              intercomm_list.erase(iter);
+
+            flag = false;
+            break; 
           }
         }
       }
-
-      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.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.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.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++)
+    }
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, test_rank = %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].first);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
+
+    //////////////////////////////////////////////////////////
+    // step 7 : create intercomm_rank_map for local leaders //
+    //////////////////////////////////////////////////////////
+    
+    int my_quadruple[4];
+
+    my_quadruple[0] = ep_rank;
+    my_quadruple[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
+    my_quadruple[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2].first;
+    my_quadruple[3] = (*newintercomm)->ep_comm_ptr->comm_label;
+
+
+#ifdef _showinfo
+
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+    printf("peer_rank = %d, my_quadruple = %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, my_quadruple[0], my_quadruple[1], my_quadruple[2], my_quadruple[3]);
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+#endif
+
+    int *local_quadruple_list;
+    int *remote_quadruple_list;
+    if(is_involved)
+    {
+      local_quadruple_list = new int[4*ep_size];
+      remote_quadruple_list = new int[4*remote_ep_size];
+
+    }
+
+    MPI_Gather(my_quadruple, 4, MPI_INT, local_quadruple_list, 4, MPI_INT, local_leader, local_comm);
+
+
+    if(is_local_leader)
+    {
+      MPI_Request request;
+      MPI_Status status;
+
+      if(remote_leader > local_leader_rank_in_peer)
+      {
+        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);        
+
+        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+      }
+      else
+      {
+        MPI_Irecv(remote_quadruple_list, 4*remote_ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);
+          
+        MPI_Isend(local_quadruple_list,  4*ep_size, MPI_INT, remote_leader, tag, peer_comm, &request);
+        MPI_Wait(&request, &status);       
+      }
+#ifdef _showinfo
+      printf("peer_rank = %d, quadruple_list exchange OK\n", local_leader_rank_in_peer);
+#endif
+    }
+
+    if(is_involved)
+    {
+      ::MPI_Bcast(remote_quadruple_list, 4*remote_ep_size, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, to_mpi_comm(local_comm->mpi_comm));
+      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new INTERCOMM_RANK_MAP;
+#ifdef _showinfo
+      printf("new intercomm_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map);
+#endif
+      for(int i=0; i<remote_ep_size; i++)
+      {
+        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->insert(std::pair<int, std::pair< int, std::pair<int, int> > >(remote_quadruple_list[4*i], remote_quadruple_list[4*i+1], remote_quadruple_list[4*i+2], remote_quadruple_list[4*i+3]));
+      }
+    }
+
+    ////////////////////////////////////////////////////////
+    // step 8 : associate intercomm_rank_map to endpoints //
+    ////////////////////////////////////////////////////////
+
+    int *leader_rank_in_world_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second];
+
+    MPI_Allgather_local(&local_leader_rank_in_world, 1, MPI_INT, leader_rank_in_world_local_gathered, *newintercomm);
+
+
+    int new_rank_loc = (*newintercomm)->ep_comm_ptr->size_rank_info[1].first;
+    int *new_rank_loc_local_gathered = new int[(*newintercomm)->ep_comm_ptr->size_rank_info[1].second];
+
+    MPI_Allgather_local(&new_rank_loc, 1, MPI_INT, new_rank_loc_local_gathered, *newintercomm);
+
+    //printf("peer_rank = %d, leader_rank_in_world_local_gathered = %d %d %d %d, new_rank_loc_local_gathered = %d %d %d %d\n", 
+    //  peer_comm->ep_comm_ptr->size_rank_info[0].first, leader_rank_in_world_local_gathered[0], leader_rank_in_world_local_gathered[1], leader_rank_in_world_local_gathered[2], leader_rank_in_world_local_gathered[3],
+    //  new_rank_loc_local_gathered[0], new_rank_loc_local_gathered[1], new_rank_loc_local_gathered[2], new_rank_loc_local_gathered[3]);
+
+    if(is_involved)
+    {
+
+      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map = new EP_RANK_MAP;
+#ifdef _showinfo
+      printf("new local_rank_map = %p\n", (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map);
+#endif
+
+      for(std::map<int, std::pair<int, int> >::iterator it = local_comm->ep_rank_map->begin(); it != local_comm->ep_rank_map->end(); it++)
+      {
+        (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->insert(std::pair<int, std::pair< int, int > >(it->first, it->second.first, it->second.second));
+      }
+    }
+
+    MPI_Barrier_local(*newintercomm);
+
+    
+    if(!is_involved)
+    {
+      int target;
+      for(int i=0; i<(*newintercomm)->ep_comm_ptr->size_rank_info[1].second; i++)
+      {
+        if(local_leader_rank_in_world == leader_rank_in_world_local_gathered[i])
         {
-          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);
+          target = i;
+          (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = target;
           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];
-      
-      MPI_Isend((*newintercomm).rank_map->data(), 2*local_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[0]);
-      MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, remote_leader, tag+6, peer_comm, &requests[1]);
-      
-      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;
+      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->intercomm_rank_map;
+      (*newintercomm)->ep_comm_ptr->intercomm->local_rank_map     = (*newintercomm)->ep_comm_ptr->comm_list[target]->ep_comm_ptr->intercomm->local_rank_map;
+    }
+    else
+    {
+      (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = -1;
+    }
+
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = (*newintercomm)->ep_comm_ptr->size_rank_info[0];
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = (*newintercomm)->ep_comm_ptr->size_rank_info[1];
+    (*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = (*newintercomm)->ep_comm_ptr->size_rank_info[2];
+
+
+    (*newintercomm)->ep_comm_ptr->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
+    (*newintercomm)->ep_comm_ptr->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
+    (*newintercomm)->ep_comm_ptr->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
+
+
+#ifdef _showinfo
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+    printf("peer_rank = %d, size_rank_info = %d %d %d %d %d %d\n", peer_comm->ep_comm_ptr->size_rank_info[0].first, 
+      (*newintercomm)->ep_comm_ptr->size_rank_info[0].first, (*newintercomm)->ep_comm_ptr->size_rank_info[0].second,
+      (*newintercomm)->ep_comm_ptr->size_rank_info[1].first, (*newintercomm)->ep_comm_ptr->size_rank_info[1].second,
+      (*newintercomm)->ep_comm_ptr->size_rank_info[2].first, (*newintercomm)->ep_comm_ptr->size_rank_info[2].second);
+    
+    MPI_Barrier(peer_comm);
+    MPI_Barrier(peer_comm);
+
+#endif
 
 /*
-    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);
+    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5)
+    {
+      int receiver = rand()%10;
+      printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 
+        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second);
+    }
+
+    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 9)
+    {
+      int receiver = rand()%6;
+      printf("receiver = %d, intercomm_local_rank = %d, intercomm_mpi_rank = %d, comm_label = %d\n", receiver, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).first, 
+        (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.first, (*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(receiver).second.second);
+    }
+
+
+    if(peer_comm->ep_comm_ptr->size_rank_info[0].first == 5)
+    {
+      for(int i=0; i<ep_size; i++)
+      {
+        printf("rank_map->at(%d) = %d, %d\n", i, (*newintercomm)->ep_rank_map->at(i).first, (*newintercomm)->ep_rank_map->at(i).second);
+      }
+    }
 */
-
-//    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;
+    //////////////
+    // clean up //
+    //////////////
+
+    delete ranks_in_world_local;
+    delete ranks_in_world_remote;
+
+    if(is_involved)
+    {
+      delete local_quadruple_list;
+      delete remote_quadruple_list;
+    }
+
+    delete leader_rank_in_world_local_gathered;
+    delete new_rank_loc_local_gathered;
+
 
   }
@@ -584,220 +637,4 @@
 
 
-
-  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/src_ep_dev/ep_intercomm_world.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp	(revision 1520)
@@ -9,533 +9,5 @@
 {
 
-  // #ifdef _openmpi
-
-  // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm)
-  // {
-
-  //   int ep_rank, ep_rank_loc, mpi_rank;
-  //   int ep_size, num_ep, mpi_size;
-
-  //   ep_rank = local_comm.ep_comm_ptr->size_rank_info[0].first;
-  //   ep_rank_loc = local_comm.ep_comm_ptr->size_rank_info[1].first;
-  //   mpi_rank = local_comm.ep_comm_ptr->size_rank_info[2].first;
-  //   ep_size = local_comm.ep_comm_ptr->size_rank_info[0].second;
-  //   num_ep = local_comm.ep_comm_ptr->size_rank_info[1].second;
-  //   mpi_size = local_comm.ep_comm_ptr->size_rank_info[2].second;
-
-
-  //   std::vector<int> rank_info[4];  //! 0->rank_in_world of local_comm,  1->rank_in_local_parent of local_comm
-  //                                   //! 2->rank_in_world of remote_comm, 3->rank_in_local_parent of remote_comm
-
-  //   int rank_in_world;
-  //   int rank_in_local_parent;
-
-  //   int local_ep_size = ep_size;
-  //   int remote_ep_size;
-
-  //   ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr);
-  //   ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm);
-
-  //   ::MPI_Comm_rank(peer_comm, &rank_in_world);
-
-  //   ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent);
-
-  //   bool is_proc_master = false;
-  //   bool is_local_leader = false;
-  //   bool is_final_master = false;
-
-
-  //   if(ep_rank == local_leader) { is_proc_master = true; is_local_leader = true; is_final_master = true;}
-  //   if(ep_rank_loc == 0 && mpi_rank != local_comm.rank_map->at(local_leader).second) is_proc_master = true;
-
-
-  //   int size_info[4]; //! used for choose size of rank_info 0-> mpi_size of local_comm, 1-> mpi_size of remote_comm
-
-  //   int leader_info[4]; //! 0->world rank of local_leader, 1->world rank of remote leader
-
-
-  //   std::vector<int> ep_info[2]; //! 0-> num_ep in local_comm, 1->num_ep in remote_comm
-
-  //   std::vector<int> new_rank_info[4];
-  //   std::vector<int> new_ep_info[2];
-
-  //   std::vector<int> offset;
-
-  //   if(is_proc_master)
-  //   {
-
-  //     size_info[0] = mpi_size;
-
-  //     rank_info[0].resize(size_info[0]);
-  //     rank_info[1].resize(size_info[0]);
-
-
-
-  //     ep_info[0].resize(size_info[0]);
-
-  //     vector<int> send_buf(6);
-  //     vector<int> recv_buf(3*size_info[0]);
-
-  //     send_buf[0] = rank_in_world;
-  //     send_buf[1] = rank_in_local_parent;
-  //     send_buf[2] = num_ep;
-
-  //     ::MPI_Allgather(send_buf.data(), 3, to_mpi_type(MPI_INT), recv_buf.data(), 3, to_mpi_type(MPI_INT), local_mpi_comm);
-
-  //     for(int i=0; i<size_info[0]; i++)
-  //     {
-  //       rank_info[0][i] = recv_buf[3*i];
-  //       rank_info[1][i] = recv_buf[3*i+1];
-  //       ep_info[0][i]   = recv_buf[3*i+2];
-  //     }
-
-  //     if(is_local_leader)
-  //     {
-  //       leader_info[0] = rank_in_world;
-  //       leader_info[1] = mpi_remote_leader;
-
-  //       ::MPI_Status mpi_status;
-
-  //       send_buf[0] = size_info[0];
-  //       send_buf[1] = local_ep_size;
-
-  //       ::MPI_Send(send_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //       ::MPI_Recv(recv_buf.data(), 2, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-  //       recv_buf[2] = rank_in_world;
-  //       recv_buf[3] = mpi_remote_leader;
-
-  //     }
-
-  //     ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
-
-  //     size_info[1] = recv_buf[0];
-  //     remote_ep_size = recv_buf[1];
-  //     leader_info[0] = recv_buf[2];
-  //     leader_info[1] = recv_buf[3];
-
-  //     rank_info[2].resize(size_info[1]);
-  //     rank_info[3].resize(size_info[1]);
-
-  //     ep_info[1].resize(size_info[1]);
-
-  //     send_buf.resize(3*size_info[0]);
-  //     recv_buf.resize(3*size_info[1]);
-
-  //     if(is_local_leader)
-  //     {
-  //       ::MPI_Status mpi_status;
-
-
-  //       std::copy ( rank_info[0].data(), rank_info[0].data() + size_info[0], send_buf.begin() );
-  //       std::copy ( rank_info[1].data(), rank_info[1].data() + size_info[0], send_buf.begin() + size_info[0] );
-  //       std::copy ( ep_info[0].data(),   ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[0] );
-
-  //       ::MPI_Send(send_buf.data(), 3*size_info[0], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //       ::MPI_Recv(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-  //     }
-
-  //     ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
-
-  //     std::copy ( recv_buf.data(), recv_buf.data() + size_info[1], rank_info[2].begin() );
-  //     std::copy ( recv_buf.data() + size_info[1], recv_buf.data() + 2*size_info[1], rank_info[3].begin()  );
-  //     std::copy ( recv_buf.data() + 2*size_info[1], recv_buf.data() + 3*size_info[1], ep_info[1].begin() );
-
-  //     offset.resize(size_info[0]);
-
-  //     if(leader_info[0]<leader_info[1]) // erase all ranks doubled with remote_comm, except the local leader
-  //     {
-
-  //       bool found = false;
-  //       int ep_tmp;
-  //       int ep_local;
-  //       int ep_remote;
-  //       for(int i=0; i<size_info[0]; i++)
-  //       {
-  //         int target = rank_info[0][i];
-  //         found = false;
-  //         for(int j=0; j<size_info[1]; j++)
-  //         {
-  //           if(target == rank_info[2][j])
-  //           {
-  //             found = true;
-  //             ep_tmp = ep_info[1][j];
-  //             ep_local = ep_info[0][j];
-  //             ep_remote = ep_info[1][j];
-  //             break;
-  //           }
-  //         }
-  //         if(found)
-  //         {
-
-  //           if(target == leader_info[0]) // the leader is doubled in remote
-  //           {
-  //             new_rank_info[0].push_back(target);
-  //             new_rank_info[1].push_back(rank_info[1][i]);
-
-  //             new_ep_info[0].push_back(ep_local + ep_remote);
-  //             offset[i] = 0;
-  //           }
-  //           else
-  //           {
-  //             offset[i] = ep_local;
-  //           }
-  //         }
-  //         else
-  //         {
-  //           new_rank_info[0].push_back(target);
-  //           new_rank_info[1].push_back(rank_info[1][i]);
-
-  //           new_ep_info[0].push_back(ep_info[0][i]);
-
-  //           offset[i] = 0;
-  //         }
-
-  //       }
-  //     }
-
-  //     else // erase rank doubled with remote leader
-  //     {
-
-  //       bool found = false;
-  //       int ep_tmp;
-  //       int ep_local;
-  //       int ep_remote;
-  //       for(int i=0; i<size_info[0]; i++)
-  //       {
-  //         int target = rank_info[0][i];
-  //         found = false;
-  //         for(int j=0; j<size_info[1]; j++)
-  //         {
-
-  //           if(target == rank_info[2][j])
-  //           {
-  //             found = true;
-  //             ep_tmp = ep_info[1][j];
-  //             ep_local = ep_info[0][j];
-  //             ep_remote = ep_info[1][j];
-  //             break;
-  //           }
-  //         }
-  //         if(found)
-  //         {
-  //           if(target != leader_info[1])
-  //           {
-  //             new_rank_info[0].push_back(target);
-  //             new_rank_info[1].push_back(rank_info[1][i]);
-
-  //             new_ep_info[0].push_back(ep_local + ep_remote);
-  //             offset[i] = 0;
-  //           }
-  //           else // found remote leader
-  //           {
-  //             offset[i] = ep_remote;
-  //           }
-  //         }
-  //         else
-  //         {
-  //           new_rank_info[0].push_back(target);
-  //           new_rank_info[1].push_back(rank_info[1][i]);
-
-  //           new_ep_info[0].push_back(ep_info[0][i]);
-  //           offset[i] = 0;
-  //         }
-  //       }
-  //     }
-
-  //     if(offset[mpi_rank] == 0)
-  //     {
-  //       is_final_master = true;
-  //     }
-
-
-  //     // size_info[4]: 2->size of new_ep_info for local, 3->size of new_ep_info for remote
-
-  //     if(is_local_leader)
-  //     {
-  //       size_info[2] = new_ep_info[0].size();
-  //       ::MPI_Status mpi_status;
-
-  //       ::MPI_Send(&size_info[2], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //       ::MPI_Recv(&size_info[3], 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-  //     }
-
-  //     ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
-
-  //     new_rank_info[2].resize(size_info[3]);
-  //     new_rank_info[3].resize(size_info[3]);
-  //     new_ep_info[1].resize(size_info[3]);
-
-  //     send_buf.resize(size_info[2]);
-  //     recv_buf.resize(size_info[3]);
-
-  //     if(is_local_leader)
-  //     {
-  //       ::MPI_Status mpi_status;
-
-  //       std::copy ( new_rank_info[0].data(), new_rank_info[0].data() + size_info[2], send_buf.begin() );
-  //       std::copy ( new_rank_info[1].data(), new_rank_info[1].data() + size_info[2], send_buf.begin() + size_info[2] );
-  //       std::copy ( new_ep_info[0].data(),   new_ep_info[0].data()   + size_info[0], send_buf.begin() + 2*size_info[2] );
-
-  //       ::MPI_Send(send_buf.data(), 3*size_info[2], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-  //       ::MPI_Recv(recv_buf.data(), 3*size_info[3], to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-  //     }
-
-  //     ::MPI_Bcast(recv_buf.data(),   3*size_info[3], to_mpi_type(MPI_INT), local_comm.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.rank_map->at(local_leader).second, local_mpi_comm);
-
-  //     if(new_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
-  //     {
-  //       ::MPI_Barrier(*new_comm);
-
-  //       ::MPI_Intercomm_create(*new_comm, leader_info[2], peer_comm, leader_info[1], tag, intercomm);
-
-  //       int id;
-  //       ::MPI_Comm_rank(*new_comm, &id);
-  //       int my_num_ep = new_ep_info[0][id];
-
-  //       MPI_Comm *ep_intercomm;
-  //       MPI_Info info;
-  //       MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm);
-
-
-
-  //       for(int i= 0; i<my_num_ep; i++)
-  //       {
-  //         ep_intercomm[i].is_intercomm = true;
-
-  //         ep_intercomm[i].ep_comm_ptr->intercomm = new ep_lib::ep_intercomm;
-  //         ep_intercomm[i].ep_comm_ptr->intercomm->mpi_inter_comm = intercomm;
-  //         ep_intercomm[i].ep_comm_ptr->comm_label = leader_info[0];
-  //       }
-
-  //       #pragma omp critical (write_to_tag_list)
-  //       tag_list.push_back(make_pair( make_pair(tag, min(leader_info[0], leader_info[1])) , ep_intercomm));
-  //     }
-
-
-  //   }
-
-
-  //   MPI_Barrier_local(local_comm);
-
-  //   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;
-  //           //tag_list.erase(iter);
-  //           break;
-  //         }
-  //       }
-  //     }
-  //   }
-
-  //   MPI_Barrier(local_comm);
-
-  //   if(is_local_leader)
-  //   {
-  //     int local_flag = true;
-  //     int remote_flag = false;
-  //     ::MPI_Status mpi_status;
-      
-  //     ::MPI_Send(&local_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //     ::MPI_Recv(&remote_flag, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-  //   }
-
-  //   MPI_Barrier(local_comm);
-
-  //   if(is_proc_master)
-  //   {
-  //     for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-  //     {
-  //       if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1])))
-  //       {
-  //         tag_list.erase(iter);
-  //         break;
-  //       }
-  //     }
-  //   }
-
-    
-
-  //   int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
-  //   int intercomm_ep_size, intercomm_num_ep, intercomm_mpi_size;
-
-  //   intercomm_ep_rank = newintercomm->ep_comm_ptr->size_rank_info[0].first;
-  //   intercomm_ep_rank_loc = newintercomm->ep_comm_ptr->size_rank_info[1].first;
-  //   intercomm_mpi_rank = newintercomm->ep_comm_ptr->size_rank_info[2].first;
-  //   intercomm_ep_size = newintercomm->ep_comm_ptr->size_rank_info[0].second;
-  //   intercomm_num_ep = newintercomm->ep_comm_ptr->size_rank_info[1].second;
-  //   intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second;
-
-  //   MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm);
-
-  //   int my_rank_map_elem[2];
-
-
-  //   my_rank_map_elem[0] = intercomm_ep_rank;
-
-  //   my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label;
-
-  //   vector<pair<int, int> > local_rank_map_array;
-  //   vector<pair<int, int> > remote_rank_map_array;
-
-
-  //   (*newintercomm).ep_comm_ptr->intercomm->local_rank_map = new RANK_MAP;
-  //   (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size);
-
-  //   MPI_Allgather2(my_rank_map_elem, 2, MPI_INT, (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, MPI_INT, local_comm);
-
-  //   (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map = new RANK_MAP;
-  //   (*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size);
-
-  //   int local_intercomm_size = intercomm_ep_size;
-  //   int remote_intercomm_size;
-
-
-
-
-  //   if(is_local_leader)
-  //   {
-  //     ::MPI_Status status;
-
-  //     ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //     ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-
-  //     ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //     ::MPI_Recv(&remote_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-  //   }
-
-  //   MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm);
-  //   MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm);
-
-
-  //   (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;
-  //   (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);
-
-  //   (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0];
-  //   (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1];
-  //   (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2];
-
-
-  //   if(is_local_leader)
-  //   {
-  //     ::MPI_Status status;
-
-  //     ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-  //     ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-  //   }
-
-  //   MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), 0, *newintercomm);
-
-  //   (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]);
-  //   (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label;
-
-
-  //   return MPI_SUCCESS;
-
-  // }
-
-
-
-  // #elif _intelmpi
+
   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)
   {
@@ -543,10 +15,10 @@
     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;
+    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
@@ -560,5 +32,5 @@
 
     ::MPI_Comm peer_comm = to_mpi_comm(peer_comm_ptr);
-    ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm);
+    ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm->mpi_comm);
 
     ::MPI_Comm_rank(peer_comm, &rank_in_world);
@@ -572,5 +44,5 @@
 
     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.rank_map->at(local_leader).second) is_proc_master = true;
+    if(ep_rank_loc == 0 && mpi_rank != local_comm->ep_rank_map->at(local_leader).second) is_proc_master = true;
 
 
@@ -633,5 +105,5 @@
       }
 
-      ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::MPI_Bcast(recv_buf.data(), 4, to_mpi_type(MPI_INT), local_comm->ep_rank_map->at(local_leader).second, local_mpi_comm);
 
       size_info[1] = recv_buf[0];
@@ -663,5 +135,5 @@
       }
 
-      ::MPI_Bcast(recv_buf.data(), 3*size_info[1], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::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() );
@@ -789,5 +261,5 @@
       }
 
-      ::MPI_Bcast(&size_info[2], 2, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::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]);
@@ -811,5 +283,5 @@
       }
 
-      ::MPI_Bcast(recv_buf.data(),   3*size_info[3], to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::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() );
@@ -843,7 +315,7 @@
       }
 
-      ::MPI_Bcast(&leader_info[2], 1, to_mpi_type(MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
-
-      if(new_comm != static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm))
+      ::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);
@@ -861,9 +333,9 @@
         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];
+          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];
         }
 
@@ -979,10 +451,10 @@
     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;
+    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;
 
 
@@ -994,5 +466,5 @@
     my_rank_map_elem[0] = intercomm_ep_rank;
 
-    my_rank_map_elem[1] = (*newintercomm).ep_comm_ptr->comm_label;
+    my_rank_map_elem[1] = (*newintercomm)->ep_comm_ptr->comm_label;
 
     vector<pair<int, int> > local_rank_map_array;
@@ -1000,11 +472,11 @@
 
 
-    (*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->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->remote_rank_map = new RANK_MAP;
+    //(*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->resize(remote_ep_size);
 
     int local_intercomm_size = intercomm_ep_size;
@@ -1016,7 +488,7 @@
       ::MPI_Status status;
 
-      ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
+      //::MPI_Send((*newintercomm)->ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
+
+      //::MPI_Recv((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
 
       ::MPI_Send(&local_intercomm_size, 1, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
@@ -1025,14 +497,14 @@
     }
 
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm);
+    //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, MPI_INT, local_leader, local_comm);
     MPI_Bcast(&remote_intercomm_size, 1, MPI_INT, 0, *newintercomm);
 
 
-    (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;
-    (*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);
-
-    (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[0] = local_comm.ep_comm_ptr->size_rank_info[0];
-    (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[1] = local_comm.ep_comm_ptr->size_rank_info[1];
-    (*newintercomm).ep_comm_ptr->intercomm->size_rank_info[2] = local_comm.ep_comm_ptr->size_rank_info[2];
+    //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map = new RANK_MAP;
+    //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->resize(remote_intercomm_size);
+
+    //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[0] = local_comm->ep_comm_ptr->size_rank_info[0];
+    //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[1] = local_comm->ep_comm_ptr->size_rank_info[1];
+    //(*newintercomm)->ep_comm_ptr->intercomm->size_rank_info[2] = local_comm->ep_comm_ptr->size_rank_info[2];
 
 
@@ -1040,14 +512,29 @@
     {
       ::MPI_Status status;
-
-      ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-    }
-
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm);
-
-    (*newintercomm).ep_comm_ptr->intercomm->local_comm = &(local_comm.ep_comm_ptr->comm_list[ep_rank_loc]);
-    (*newintercomm).ep_comm_ptr->intercomm->intercomm_tag = local_comm.ep_comm_ptr->comm_label;
+      
+      std::vector<std::pair<int, std::pair<int, int> > > map2vec((*newintercomm)->ep_rank_map->size());
+      std::vector<std::pair<int, std::pair<int, int> > > vec2map((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->size());
+      
+      int ii=0;
+      for(std::map<int, std::pair<int, int> >::iterator it = (*newintercomm)->ep_rank_map->begin(); it != (*newintercomm)->ep_rank_map->end(); it++)
+      {
+        map2vec[ii++] = make_pair(it->first, make_pair(it->second.first, it->second.second));
+      }
+      
+      
+      ::MPI_Send(map2vec.data(), 3*local_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm);
+      ::MPI_Recv(vec2map.data(), 3*remote_intercomm_size, to_mpi_type(MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
+      
+     
+      for(ii=0; ii<vec2map.size(); ii++)
+      {
+        //(*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->at(vec2map[ii].first) = make_pair(vec2map[ii].second.first, vec2map[ii].second.second);
+      }
+    }
+
+    //MPI_Bcast((*newintercomm)->ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, MPI_INT, 0, *newintercomm);
+
+    //(*newintercomm)->ep_comm_ptr->intercomm->local_comm = (local_comm->ep_comm_ptr->comm_list[ep_rank_loc]);
+    (*newintercomm)->ep_comm_ptr->intercomm->intercomm_tag = local_comm->ep_comm_ptr->comm_label;
 
     return MPI_SUCCESS;
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp	(revision 1520)
@@ -4,4 +4,5 @@
 #include <iostream>
 #include <fstream>
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -14,11 +15,4 @@
 namespace ep_lib
 { 
-  bool MPI_Comm::is_null()
-  {
-    if(!this->is_intercomm)
-      return this->mpi_comm == MPI_COMM_NULL.mpi_comm;
-    else
-      return this->ep_comm_ptr->intercomm->mpi_inter_comm == MPI_COMM_NULL.mpi_comm;
-  }
 
   int tag_combine(int real_tag, int src, int dest)
@@ -33,50 +27,36 @@
   int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank)
   {
-    for(int i=0; i<comm.rank_map->size(); i++)
-    {
-      if(   ( comm.rank_map->at(i).first  == ep_rank_loc )
-         && ( comm.rank_map->at(i).second == mpi_rank ) )
-      {
-        return i;
-      }
-    }
-    printf("rank not find\n");
+    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++)
+    {
+      if(   ( it->second.first  == ep_rank_loc )
+         && ( it->second.second == mpi_rank ) )
+      {
+        return it->first;
+      }
+    }
+    printf("rank not find for EP_intracomm\n");
+    int err;
+    return MPI_Abort(comm, err);
   }
   
-  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->intercomm_rank_map->at(i).first  == ep_rank_loc )
-         && ( comm.ep_comm_ptr->intercomm->intercomm_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)
   {
-
-    ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status);
-    ::MPI_Datatype *mpi_datatype = static_cast< ::MPI_Datatype*>(datatype);
-
-    ::MPI_Get_count(mpi_status, *mpi_datatype, count);
+    return ::MPI_Get_count(to_mpi_status_ptr(*status), to_mpi_type(datatype), count);
   }
 
@@ -89,4 +69,5 @@
   void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type)
   {
+
     int src_rank;
     int int_count;
@@ -121,4 +102,5 @@
   void check_sum_recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, int type)
   {
+
     int dest_rank;
     int int_count;
@@ -147,4 +129,5 @@
     }
     else printf("Unable to open file\n");
+
 
   }
@@ -251,4 +234,9 @@
 {
   return *(static_cast< MPI_Comm* >(comm));
+} 
+
+MPI_Comm* to_mpi_comm_ptr(void* comm)
+{
+  return static_cast< MPI_Comm* >(comm);
 }  
 
@@ -258,11 +246,34 @@
 }
 
-MPI_Info to_mpi_info(void* info)
-{
-  return *(static_cast< MPI_Info* >(info));
-}
-
-
-
-
-
+MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message)
+{
+  return static_cast< MPI_Message* >(message->mpi_message);
+}
+
+MPI_Info to_mpi_info(ep_lib::MPI_Info info)
+{
+  return *(static_cast< MPI_Info* >(info->mpi_info));
+}
+
+MPI_Win to_mpi_win(void* win)
+{
+  return *(static_cast< MPI_Win* >(win));
+}
+
+MPI_Aint to_mpi_aint(ep_lib::MPI_Aint aint)
+{
+  return *(static_cast< MPI_Aint* >(aint.mpi_aint));
+}
+
+MPI_Status* to_mpi_status_ptr(ep_lib::MPI_Status status)
+{
+  return static_cast< MPI_Status* >(status.mpi_status);
+}
+
+MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request)
+{
+  return static_cast< MPI_Request* >(request->mpi_request);
+}
+
+
+
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp	(revision 1520)
@@ -4,8 +4,13 @@
 #include "ep_type.hpp"
 #include "ep_lib_intercomm.hpp"
+#include "ep_lib_intracomm.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"
+
 
 namespace ep_lib
@@ -33,12 +38,6 @@
 
   int MPI_Get_count(const MPI_Status *status, MPI_Datatype datatype, int *count);
-
-  // #ifdef _openmpi
-  // int MPI_Comm_create_endpoints(void* mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints
-  // #elif _intelmpi
-  // int MPI_Comm_create_endpoints(int mpi_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from MPI to create endpoints
-  // #endif
   
-  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints
+  int MPI_Comm_remote_size(MPI_Comm comm, int *size);
 
   int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
@@ -47,10 +46,4 @@
   int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
 
-  int tag_combine(int real_tag, int src, int dest);
-  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
-  int get_ep_rank_intercomm(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
-
-  int Message_Check(MPI_Comm comm);
-  int Request_Check();
 
   int MPI_Recv  (void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status);
@@ -74,4 +67,6 @@
   int MPI_Alloc_mem(unsigned long size, MPI_Info info, void *baseptr);
 
+  int MPI_Comm_test_inter(MPI_Comm comm, int *flag);
+
 
   void check_sum_send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, int type);
@@ -81,4 +76,14 @@
   bool valid_op(MPI_Op op);
 
+  int tag_combine(int real_tag, int src, int dest);
+  int get_ep_rank(MPI_Comm comm, int ep_rank_loc, int mpi_rank);
+
+  int Message_Check(MPI_Comm comm);
+
+  int Request_Check();
+
+  int test_sendrecv(MPI_Comm comm);
+
+
 }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_collective.hpp	(revision 1520)
@@ -10,4 +10,5 @@
 
   int MPI_Barrier(MPI_Comm comm);
+  
 
   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm);
@@ -26,4 +27,5 @@
 
   int MPI_Gather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm);
+  
   int MPI_Allgather(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
 
@@ -41,4 +43,23 @@
   int MPI_Alltoall(const void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm);
 
+  int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);
+
+  int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+
+  int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+  
+  
+  int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
+  
+  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
+
+  int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints
+
+
+
+  int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
+
+  int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
+
 }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp	(revision 1520)
@@ -8,5 +8,11 @@
   typedef void* MPI_Op;
 
-  
+  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
+  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
+  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
+
+  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request);
+
+
   int MPI_Comm_dup_intercomm(MPI_Comm comm, MPI_Comm *newcomm);
 
@@ -22,33 +28,8 @@
 
   int MPI_Iprobe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Status *status);
-  int MPI_Iprobe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Status *status);
   int MPI_Improbe_intercomm(int source, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);
-  int MPI_Improbe_any_source(int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status);
 
-  int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm *newcomm);
 
-  int MPI_Intercomm_create(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
 
-  int MPI_Intercomm_create_kernel(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
-  
-  // #ifdef _intelmpi
-  // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, int peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
-  // #elif _openmpi
-  // int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
-  // #endif
-
-  int MPI_Intercomm_create_from_world(MPI_Comm local_comm, int local_leader, void* peer_comm_ptr, int mpi_remote_leader, int tag, MPI_Comm *newintercomm);
-  
-  int MPI_Intercomm_create_unique_leader(MPI_Comm local_comm, int local_leader, MPI_Comm peer_comm, int remote_leader, int tag, MPI_Comm *newintercomm);
-
-  int MPI_Intercomm_merge(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
-
-  int MPI_Intercomm_merge_unique_leader(MPI_Comm intercomm, bool high, MPI_Comm *newintracomm);
-
-  int MPI_Comm_remote_size(MPI_Comm comm, int *size);
-
-  int MPI_Comm_test_inter(MPI_Comm comm, int *flag);
-
-  int test_sendrecv(MPI_Comm comm);
 
 }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_local.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_local.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_local.hpp	(revision 1520)
@@ -18,4 +18,6 @@
   
   int MPI_Gather_local      (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, int local_root, MPI_Comm comm);
+  
+  int MPI_Allgather_local      (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf, MPI_Comm comm);
 
   int MPI_Gatherv_local       (const void *sendbuf, int count, MPI_Datatype datatype, void *recvbuf,
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp	(revision 1520)
@@ -7,5 +7,6 @@
 
 
-namespace ep_lib {
+namespace ep_lib 
+{
 
   int MPI_Intercomm_merge_unique_leader(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
@@ -18,25 +19,25 @@
     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;
+    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 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;
+    //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;
 
 
@@ -45,6 +46,6 @@
       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_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);
@@ -52,5 +53,5 @@
 
 
-    MPI_Bcast(&remote_high, 1, MPI_INT, 0, *(inter_comm.ep_comm_ptr->intercomm->local_comm));
+    //MPI_Bcast(&remote_high, 1, MPI_INT, 0, inter_comm->ep_comm_ptr->intercomm->local_comm);
 
 
@@ -64,10 +65,10 @@
     int intra_ep_size, intra_num_ep, intra_mpi_size;
 
-    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;
+    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;
 
 
@@ -85,5 +86,5 @@
     if(intra_ep_rank_loc == 0)
     {
-      ::MPI_Bcast(reorder, intra_ep_size, to_mpi_type(MPI_INT), 0, to_mpi_comm(newintracomm->mpi_comm));
+      ::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);
@@ -92,8 +93,14 @@
       for(int i=0; i<intra_ep_size; i++)
       {
-        tmp_rank_map[reorder[i]] = newintracomm->rank_map->at(i) ;
-      }
-
-      newintracomm->rank_map->swap(tmp_rank_map);
+        tmp_rank_map[reorder[i]] = (*newintracomm)->ep_rank_map->at(i) ;
+      }
+
+      //(*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();
@@ -102,5 +109,5 @@
     MPI_Barrier_local(*newintracomm);
 
-    (*newintracomm).ep_comm_ptr->size_rank_info[0].first = my_ep_rank;
+    (*newintracomm)->ep_comm_ptr->size_rank_info[0].first = my_ep_rank;
 
     if(intra_ep_rank_loc == 0)
@@ -118,108 +125,79 @@
   int MPI_Intercomm_merge(MPI_Comm inter_comm, bool high, MPI_Comm *newintracomm)
   {
-
-    assert(inter_comm.is_intercomm);
-
-    if(inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->comm_label == -99)
-    {
-        return MPI_Intercomm_merge_unique_leader(inter_comm, high, newintracomm);
-    }
-
-
-    Debug("intercomm_merge kernel\n");
-
-    int ep_rank_loc;
-    int num_ep;
-
-    ep_rank_loc = inter_comm.ep_comm_ptr->size_rank_info[1].first;
-    num_ep = inter_comm.ep_comm_ptr->size_rank_info[1].second;
-
-
-
-    int remote_ep_size = inter_comm.ep_comm_ptr->intercomm->remote_rank_map->size();
-
-
-    MPI_Barrier(inter_comm);
-
-
-    ::MPI_Comm *mpi_intracomm = new ::MPI_Comm;
-    MPI_Comm *ep_intracomm;
-
-    if(ep_rank_loc == 0)
-    {
-
-      ::MPI_Comm mpi_comm = to_mpi_comm(inter_comm.ep_comm_ptr->intercomm->mpi_inter_comm);
-
-      ::MPI_Intercomm_merge(mpi_comm, high, mpi_intracomm);
+    
+
+    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_create_endpoints(mpi_intracomm, num_ep, info, ep_intracomm);
-
-      inter_comm.ep_comm_ptr->comm_list->mem_bridge = ep_intracomm;
-
+      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 inter_rank;
-    MPI_Comm_rank(inter_comm, &inter_rank);
+    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++)
+      {
+        (*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]));
+      }
+    }
+
+#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);
+      }
+    }
+#endif
     
-    int my_ep_rank = high? inter_rank+remote_ep_size : inter_rank;
-    int my_ep_rank_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].first;
-    int my_num_ep_loc = inter_comm.ep_comm_ptr->intercomm->local_comm->ep_comm_ptr->size_rank_info[1].second;
-    int my_num_ep_total = inter_comm.ep_comm_ptr->comm_list->mem_bridge[0].ep_comm_ptr->size_rank_info[1].second;
-    int my_ep_size = inter_comm.ep_comm_ptr->comm_list->mem_bridge[0].ep_comm_ptr->size_rank_info[0].second;
-
-    int tmp_intra_ep_rank_loc = high?my_ep_rank_loc+my_num_ep_total-my_num_ep_loc: my_ep_rank_loc;
-
-
-    *newintracomm = inter_comm.ep_comm_ptr->comm_list->mem_bridge[tmp_intra_ep_rank_loc];
-
-    int newintracomm_ep_rank = (*newintracomm).ep_comm_ptr->size_rank_info[0].first;
-    int newintracomm_ep_rank_loc = (*newintracomm).ep_comm_ptr->size_rank_info[1].first;
-    int newintracomm_mpi_rank = (*newintracomm).ep_comm_ptr->size_rank_info[2].first;
-    int newintracomm_ep_size = (*newintracomm).ep_comm_ptr->size_rank_info[0].second;
-    int newintracomm_num_ep = (*newintracomm).ep_comm_ptr->size_rank_info[1].second;
-    int newintracomm_mpi_size = (*newintracomm).ep_comm_ptr->size_rank_info[2].second;
-
-
-    int buf[3];
-    buf[0] = my_ep_rank;
-    buf[1] = tmp_intra_ep_rank_loc;
-    buf[2] = newintracomm->ep_comm_ptr->size_rank_info[2].first;
-
-    // printf("my_ep_rank = %d, tmp_intra_ep_rank_loc = %d, mpi_rank = %d\n", my_ep_rank, tmp_intra_ep_rank_loc, newintracomm->ep_comm_ptr->size_rank_info[2].first);
-
-    int *rankmap_buf;
-    rankmap_buf = new int [3*my_ep_size];
-
-    MPI_Allgather(buf, 3, MPI_INT, rankmap_buf, 3, MPI_INT, *newintracomm);
-
-    
-    // printf(" ID = %d : rankmap_buf = (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d), (%d %d %d)\n", newintracomm_ep_rank,
-    //                     rankmap_buf[0], rankmap_buf[1], rankmap_buf[2], rankmap_buf[3], rankmap_buf[4], rankmap_buf[5], rankmap_buf[6], rankmap_buf[7], rankmap_buf[8], rankmap_buf[9],
-    //                     rankmap_buf[10], rankmap_buf[11], rankmap_buf[12], rankmap_buf[13], rankmap_buf[14], rankmap_buf[15], rankmap_buf[16], rankmap_buf[17], rankmap_buf[18], rankmap_buf[19], 
-    //                     rankmap_buf[20], rankmap_buf[21], rankmap_buf[22], rankmap_buf[23], rankmap_buf[24], rankmap_buf[25], rankmap_buf[26], rankmap_buf[27], rankmap_buf[28], rankmap_buf[29],
-    //                     rankmap_buf[30], rankmap_buf[31], rankmap_buf[32], rankmap_buf[33], rankmap_buf[34], rankmap_buf[35], rankmap_buf[36], rankmap_buf[37], rankmap_buf[38], rankmap_buf[39],
-    //                     rankmap_buf[40], rankmap_buf[41], rankmap_buf[42], rankmap_buf[43], rankmap_buf[44], rankmap_buf[45], rankmap_buf[46], rankmap_buf[47]);
-
-
-    for(int i=0; i<newintracomm_ep_size; i++)
-    {
-      (*newintracomm).rank_map->at(rankmap_buf[3*i]).first  = rankmap_buf[3*i+1];
-      (*newintracomm).rank_map->at(rankmap_buf[3*i]).second = rankmap_buf[3*i+2];
-    }
-
-
-    (*newintracomm).ep_comm_ptr->size_rank_info[0].first = my_ep_rank;
-    (*newintracomm).ep_comm_ptr->size_rank_info[1].first = tmp_intra_ep_rank_loc;
-    
-
-    delete[] rankmap_buf;
-
-    
-    return MPI_SUCCESS;
-
+    delete my_triple_list;
   }
-
-
+  
 }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_message.cpp	(revision 1520)
@@ -18,86 +18,184 @@
 namespace ep_lib
 {
-
+  int Request_Check()
+  {
+    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >;
+    
+    if(EP_PendingRequests->size() == 0) return 0;
+    
+    MPI_Status status;
+    MPI_Message *message;
+    int probed = false;
+    int recv_count = 0;
+    std::list<MPI_Request* >::iterator it;
+    
+    
+    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++)
+    { 
+      Message_Check(((*(*it))->comm));
+    }
+
+
+    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); )
+    {
+      if((*(*it))->state == 0)
+      {
+        #pragma omp critical (_query0)
+        {
+          MPI_Iprobe((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status);
+          if(probed)
+          {
+            message = new MPI_Message;
+            *message = new ep_message;
+        
+            memcheck("new "<< message <<" : in ep_lib::Request_Check, message = new MPI_Message");
+            memcheck("new "<< *message <<" : in ep_lib::Request_Check, *message = new ep_message");
+          
+          
+            MPI_Improbe((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status);
+        
+          }
+        }
+      
+        
+        if(probed)
+        {
+          MPI_Get_count(&status, (*(*it))->ep_datatype, &recv_count);
+          
+          MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it);
+          (*(*it))->type = 3;
+          (*(*it))->state = 1;
+
+          memcheck("delete "<< status.mpi_status <<" : in ep_lib::Request_Check, delete status.mpi_status");
+          delete status.mpi_status;          
+
+          memcheck("delete "<< *message <<" : in ep_lib::Request_Check, delete *message");
+          memcheck("delete "<< message <<" : in ep_lib::Request_Check, delete message");
+
+          delete *message;
+          delete message;
+        
+          it++;
+          continue;      
+        }              
+      }
+      
+      if((*(*it))->state == 2)
+      {
+        int ep_rank = ((*(*it))->comm)->ep_comm_ptr->size_rank_info[0].first;
+        memcheck("delete "<< (*(*it)) <<" : in ep_lib::Request_Check, delete (*(*it))");
+        
+        
+        int world_rank;
+        MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
+        if(world_rank==2) 
+        {
+          printf("ep %d erased one pending request %p\n", world_rank,*(*it));
+        }
+        
+        EP_PendingRequests->erase(it);
+        
+        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
+        it = EP_PendingRequests->begin();
+        continue;
+      }
+      else it++;
+    }
+  }
+  
+  
+  
   int Message_Check(MPI_Comm comm)
   {
-    if(!comm.is_ep) return 0;
-
-    if(comm.is_intercomm)
-    {
-      return  Message_Check_intercomm(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)
+  {
+    
+    int flag = true;
+    ::MPI_Status status;
+    ::MPI_Message message;
+
+    while(flag) // loop until the end of global queue
+    {
+      Debug("Message probing for intracomm\n");
+     
+      #pragma omp critical (_mpi_call)
+      {
+        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->mpi_comm), &flag, &status);
+        if(flag)
+        {
+          Debug("find message in mpi comm \n");
+          ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->mpi_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);  
+          int dest_mpi = comm->ep_comm_ptr->size_rank_info[2].first;
+          memcheck("message_queue["<<dest_mpi<<","<<dest_loc<<"]->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size());
+          #pragma omp flush
+        }
+      }
+    }
+
+    return MPI_SUCCESS;
+  }
+
+
+  
+  
+  
+
+
+  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 mpi_source;
-
-    while(flag) // loop until the end of global queue
-    {
-      Debug("Message probing for intracomm\n");
-      
-      #pragma omp critical (_mpi_call)
-      {
-        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.mpi_comm), &flag, &status);
-        if(flag)
-        {
-          Debug("find message in mpi comm \n");
-          mpi_source = status.MPI_SOURCE;
-          int tag = status.MPI_TAG;
-          ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.mpi_comm), &message, &status);
-
-        }
-      }
-
-      
-      if(flag)
-      {
-
-        MPI_Message *msg_block = new MPI_Message; 
-        msg_block->mpi_message = new ::MPI_Message;
-        *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message;  
-        msg_block->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_block->ep_src  = get_ep_rank(comm, src_loc,  src_mpi);       
-        msg_block->mpi_status = new ::MPI_Status(status);
-
-        MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list;
-        MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc];
-
-
-        #pragma omp critical (_query)
-        {
-          #pragma omp flush
-          comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block);      
-          #pragma omp flush
-        }
-        
-        delete msg_block;
-      }
-
-    }
-
-    return MPI_SUCCESS;
-  }
-
-
-
-  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 mpi_source;
     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"
+    while(flag) // loop until the end of global queue "comm->ep_comm_ptr->intercomm->mpi_inter_comm"
     {
       Debug("Message probing for intracomm\n");
@@ -105,12 +203,9 @@
       #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);
+        ::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_source = status.MPI_SOURCE;
-          int tag = status.MPI_TAG;
-          ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status);
-
+          ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), &message, &status);
         }
       }
@@ -120,117 +215,40 @@
       {
 
-        MPI_Message *msg_block = new MPI_Message;
-        msg_block->mpi_message = new ::MPI_Message;
-        *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message;
-        msg_block->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;
-        int current_inter = comm.ep_comm_ptr->intercomm->local_rank_map->at(current_ep_rank).first;
+        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_block->ep_src  = get_ep_rank_intercomm(comm, src_loc,  src_mpi);
-        msg_block->mpi_status = new ::MPI_Status(status);
-
-
-        MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list;
-        MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc];
-
+        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_block);
-          #pragma omp flush
-        }
-        
-        delete msg_block;
-        
-      }
-
-    }
-
-    flag = true;
-    while(flag) // loop until the end of global queue "comm.mpi_comm"
-    {
-      Debug("Message probing for intracomm\n");
-     
-      #pragma omp critical (_mpi_call)
-      {
-        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm.mpi_comm), &flag, &status);
-        if(flag)
-        {
-          Debug("find message in mpi comm \n");
-          mpi_source = status.MPI_SOURCE;
-          int tag = status.MPI_TAG;
-          ::MPI_Mprobe(mpi_source, tag, to_mpi_comm(comm.mpi_comm), &message, &status);
-
-        }
-      }
-      
-
-      if(flag)
-      {
-
-        MPI_Message *msg_block = new MPI_Message;
-        msg_block->mpi_message = new ::MPI_Message;
-        *(static_cast< ::MPI_Message*>(msg_block->mpi_message)) = message;
-        msg_block->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_block->ep_src  = get_ep_rank_intercomm(comm, src_loc, src_mpi);
-        msg_block->mpi_status = new ::MPI_Status(status);
-        
-
-        MPI_Comm* ptr_comm_list = comm.ep_comm_ptr->comm_list;
-        MPI_Comm* ptr_comm_target = &ptr_comm_list[dest_loc];
-
-
-        #pragma omp critical (_query)
-        {
-          #pragma omp flush
-          comm.ep_comm_ptr->comm_list[dest_loc].ep_comm_ptr->message_queue->push_back(*msg_block);
-          #pragma omp flush
-        }
-        
-        delete msg_block;
-        
-      }
-
-    }
+          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;
   }
 
-  int Request_Check()
-  {
-    MPI_Status status;
-    MPI_Message message;
-    int probed = false;
-    int recv_count = 0;
-    std::list<MPI_Request* >::iterator it;
-    
-    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++)
-    { 
-      Message_Check((*it)->comm);
-    }
-
-
-    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); )
-    {
-      MPI_Improbe((*it)->ep_src, (*it)->ep_tag, (*it)->comm, &probed, &message, &status);
-      if(probed)
-      {
-        MPI_Get_count(&status, (*it)->ep_datatype, &recv_count);
-        MPI_Imrecv((*it)->buf, recv_count, (*it)->ep_datatype, &message, *it);
-        (*it)->type = 3;
-        EP_PendingRequests->erase(it);
-        it = EP_PendingRequests->begin();
-        continue;
-      }
-      it++;
-    }
-  }
+  
 
 }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp	(revision 1520)
@@ -7,6 +7,12 @@
 MPI_Op       to_mpi_op(ep_lib::MPI_Op op);
 MPI_Comm     to_mpi_comm(void* comm);
+MPI_Comm*    to_mpi_comm_ptr(void* comm);
 MPI_Message  to_mpi_message(void* message);
-MPI_Info     to_mpi_info(void* info);
+MPI_Info     to_mpi_info(ep_lib::MPI_Info info);
+MPI_Win      to_mpi_win(void* win);
+MPI_Aint     to_mpi_aint(ep_lib::MPI_Aint aint);
+MPI_Status*  to_mpi_status_ptr (ep_lib::MPI_Status status);
+MPI_Request* to_mpi_request_ptr(ep_lib::MPI_Request request);
+MPI_Message* to_mpi_message_ptr(ep_lib::MPI_Message message);
 
 #endif // EP_MPI_HPP_INCLUDED
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp	(revision 1520)
@@ -6,52 +6,49 @@
 namespace ep_lib
 {
+  int MPI_Iprobe_mpi(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *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_Iprobe(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
   {
-    *flag = false;
+    if(!comm->is_ep)
+    {
+      Debug("MPI_Iprobe with MPI\n");
+      return MPI_Iprobe_mpi(src, tag, comm, flag, status);
+    }
+    
+    else
+    {
+      Debug("MPI_Iprobe with EP\n");
+      
+      *flag = false;
+    
+      Message_Check(comm);
 
-    if(!comm.is_ep)
-    {
-      ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(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);
+      #pragma omp flush
 
-      status->mpi_status = mpi_status;
-      status->ep_src = src;
-      status->ep_tag = tag;
-      return 0;
-    }
-
-    Debug("calling MPI_Iprobe EP\n");
-
-    Message_Check(comm);
-
-    #pragma omp flush
-
-    #pragma omp critical (_query)
-    if(!comm.ep_comm_ptr->message_queue->empty())
-    {
-      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)
+      #pragma omp critical (_query)
+      for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it)
       {
-        bool src_matched = src<0? true: it->ep_src == src;
-        bool tag_matched = tag<0? true: it->ep_tag == tag;
+        bool src_matched = src<0? true: (*it)->ep_src == src;
+        bool tag_matched = tag<0? true: (*it)->ep_tag == tag;
         
         if(src_matched && tag_matched)        
         {
           Debug("find message\n");
+          
+
+          status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status));
+          status->ep_src = (*it)->ep_src;
+          status->ep_tag = (*it)->ep_tag;
+
           *flag = true;
-
-          ::MPI_Status mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status));
-
-          status->mpi_status = new ::MPI_Status(mpi_status);
-          status->ep_src = it->ep_src;
-          status->ep_tag = it->ep_tag;
-
           break;
         }
-
       }
     }
-
-    return 0;
   }
 
@@ -60,6 +57,8 @@
   int MPI_Improbe(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status)
   {
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank    = comm->ep_comm_ptr->size_rank_info[2].first;
     *flag = false;
-    if(!comm.is_ep)
+    if(!comm->is_ep)
     {
       Debug("calling MPI_Improbe MPI\n");
@@ -71,37 +70,38 @@
       #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);
+        ::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);
+          ::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);
+    	::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->mpi_status = &mpi_status;
       status->ep_src = src;
       status->ep_tag = tag;
 
-      message->mpi_message = new ::MPI_Message;
-      *(static_cast< ::MPI_Message*>(message->mpi_message)) = mpi_message;
-      message->ep_src = src;
-      message->ep_tag = tag;
+      (*message)->mpi_message = &message;
+      (*message)->ep_src = src;
+      (*message)->ep_tag = tag;
+      
+      
       return 0;
     }
 
-    
-    //Message_Check(comm);
+   
 
     #pragma omp flush
 
     #pragma omp critical (_query)
-    if(! comm.ep_comm_ptr->message_queue->empty())
+    if(! comm->ep_comm_ptr->message_queue->empty())
     {
-      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)
+      for(Message_list::iterator it = comm->ep_comm_ptr->message_queue->begin(); it!= comm->ep_comm_ptr->message_queue->end(); ++it)
       {
-        bool src_matched = src<0? true: it->ep_src == src;
-        bool tag_matched = tag<0? true: it->ep_tag == tag;
+                                          
+        bool src_matched = src<0? true: (*it)->ep_src == src;
+        bool tag_matched = tag<0? true: (*it)->ep_tag == tag;
         
         if(src_matched && tag_matched)
@@ -109,22 +109,32 @@
           *flag = true;
 
-          ::MPI_Status mpi_status;
-          mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status));
+          status->mpi_status = new ::MPI_Status(*static_cast< ::MPI_Status*>((*it)->mpi_status));
+          memcheck("new "<< status->mpi_status << " : in ep_lib::MPI_Improbe, status->mpi_status = new ::MPI_Status");
+          status->ep_src = (*it)->ep_src;
+          status->ep_tag = (*it)->ep_tag;
 
-          status->mpi_status = new ::MPI_Status(mpi_status);
-          status->ep_src = it->ep_src;
-          status->ep_tag = it->ep_tag;
-
-          message->mpi_message = it->mpi_message;
-          message->ep_tag = it->ep_tag;
-          message->ep_src = it->ep_src;
+          (*message)->mpi_message = new ::MPI_Message(*static_cast< ::MPI_Message*>((*it)->mpi_message));
+          memcheck("new "<< (*message)->mpi_message <<" : in ep_lib::MPI_Improbe, (*message)->mpi_message = new ::MPI_Message");
+          (*message)->ep_src = (*it)->ep_src;
+          (*message)->ep_tag = (*it)->ep_tag;
+                                      
 
           #pragma omp critical (_query2)
           {              
-            delete it->mpi_status;
-            comm.ep_comm_ptr->message_queue->erase(it);
+            memcheck("delete "<< (*it)->mpi_message <<" : in ep_lib::Message_Check, delete (*it)->mpi_message");
+            memcheck("delete "<< (*it)->mpi_status <<" : in ep_lib::Message_Check, delete (*it)->mpi_status");
+            memcheck("delete "<< (*it) <<" : in ep_lib::Message_Check, delete (*it)");
+            
+            
+            delete (*it)->mpi_message;     
+            delete (*it)->mpi_status; 
+            delete *it;
+            
+                       
+            comm->ep_comm_ptr->message_queue->erase(it);
+            memcheck("message_queue["<<mpi_rank<<","<<ep_rank_loc<<"]->size = "<<comm->ep_comm_ptr->message_queue->size());
             #pragma omp flush
           }
-
+          
           break;
         }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp	(revision 1520)
@@ -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/src_ep_dev/ep_recv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_recv.cpp	(revision 1520)
@@ -19,22 +19,11 @@
 namespace ep_lib 
 {
-  
 
   int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
   {
 
-    if(!comm.is_ep)
-    {
-      ::MPI_Status mpi_status;
-      ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_status);
-
-      status->ep_src = src;
-      status->ep_tag = tag;
-      status->ep_datatype = datatype;
-
-      return 0;  
-    }
-
-    Message_Check(comm);
+    if(!comm->is_ep) return MPI_Recv_mpi(buf, count, datatype, src, tag, comm, status);
+    
+    Debug("MPI_Recv with EP");
 
     MPI_Request request;
@@ -45,92 +34,138 @@
   }
 
-
+  
 
 
   int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
   {
-
+    if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request);
+    
     Debug("MPI_Irecv with EP");
     int dest_rank;
     MPI_Comm_rank(comm, &dest_rank);
     
+    *request = new ep_request;   
+    memcheck("new " << *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request");
 
-    if(!comm.is_ep)
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new " << (*request)->mpi_request << " : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request");
+    
+    (*request)->buf = buf;
+    (*request)->comm = comm;
+    (*request)->type = 2;
+    (*request)->state = 0;
+    
+
+    (*request)->ep_src = src;
+    (*request)->ep_tag = tag;
+    (*request)->ep_datatype = datatype;
+  
+    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >;
+
+    EP_PendingRequests->push_back(request);  
+    
+    int world_rank;
+    MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
+    if(world_rank==2) 
     {
-      ::MPI_Request mpi_request;
-      ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
+      printf("ep %d inserted one pending request %p\n", world_rank, *request);
+    }
+    
+    memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());    
 
-      request->mpi_request = new ::MPI_Request(mpi_request);
-      request->ep_src = src;
-      request->ep_datatype = datatype;
-      request->ep_tag = tag;
-    }
+#ifdef _showinfo
+    if(comm->is_intercomm)
+    {
+      int ep_dest_loc  = comm->ep_rank_map->at(dest_rank).first;
+      int ep_src_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).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(src).second.first;
 
-    request->buf = buf;
-    request->comm = comm;
-    request->type = 2;
+      printf("Irecv : 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;
-    request->ep_tag = tag;
-    request->ep_datatype = datatype;
+    return Request_Check();
+  }
+  
+  int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status)
+  {
+    Debug("MPI_Mrecv with MPI/EP");
 
+    status->mpi_status = new ::MPI_Status;
+    memcheck("new " << status->mpi_status << " : in ep_lib::MPI_Mrecv, status->mpi_status = new ::MPI_Status");
+    
+    ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >((*message)->mpi_message), to_mpi_status_ptr(*status));
 
+    
+    status->ep_src = (*message)->ep_src;
+    status->ep_datatype = datatype;
+    status->ep_tag = (*message)->ep_tag;
 
-    /* With Improbe*/
-    Message_Check(comm);
+    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Mrecv, delete (*message)->mpi_message");
+    delete (*message)->mpi_message;
 
-    if(EP_PendingRequests == 0 ) 
-    {
-      EP_PendingRequests = new std::list< MPI_Request* >;
-    }
+#ifdef _check_sum
+    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
+#endif
 
+    return Request_Check();
+  }
 
-    EP_PendingRequests->push_back(request);
-
-
-    Request_Check();
-
-    return 0;
-  }
 
   int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request)
   {
-    Debug("MPI_Imrecv");
+    Debug("MPI_Imrecv with MPI/EP");
 
-    request->type = 3;
+    (*request)->type = 3;
+    (*request)->ep_datatype = datatype;
+    (*request)->ep_tag = (*message)->ep_tag;
+    (*request)->ep_src = (*message)->ep_src;
+    
+    (*request)->state = 1;
+	
+    ::MPI_Imrecv(buf, count, to_mpi_type(datatype), to_mpi_message_ptr(*message), to_mpi_request_ptr(*request));		
+    
+    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Imrecv, delete (*message)->mpi_message");
+    delete (*message)->mpi_message;
 
-    ::MPI_Request mpi_request;
-    ::MPI_Imrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >(message->mpi_message), &mpi_request);		
+#ifdef _check_sum
+    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
+#endif
 
-    request->mpi_request = new ::MPI_Request(mpi_request);
-    request->ep_datatype = datatype;
-    request->ep_tag = message->ep_tag;
-    request->ep_src = message->ep_src;
     
-    delete message->mpi_message;
-
-    return 0;
+    return Request_Check();
   }
 
 
-  int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status)
+   int MPI_Recv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
   {
-    Debug("EP Mrecv called\n");
+    Debug("MPI_Recv with MPI");
+    status->ep_src = src;
+    status->ep_tag = tag;
+    status->ep_datatype = datatype;
+    
+    return ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_status_ptr(*status)); 
+  }
+  
+  int MPI_Irecv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
+  {
+    Debug("MPI_Irecv with MPI");
+    int dest_rank;
+    MPI_Comm_rank(comm, &dest_rank);
+    
+    *request = new ep_request;
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request");
 
-    ::MPI_Status mpi_status;
-    ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >(message->mpi_message), &mpi_status);
-
-    status->mpi_status = new ::MPI_Status(mpi_status);
-    status->ep_src = message->ep_src;
-    status->ep_datatype = datatype;
-    status->ep_tag = message->ep_tag;
-
-    delete message->mpi_message;
-
-    //check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
-
-    return 0;
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request");
+      
+    (*request)->ep_src = src;
+    (*request)->ep_datatype = datatype;
+    (*request)->type = 2;
+    (*request)->ep_tag = tag;
+    
+    return ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
   }
-
 }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce.cpp	(revision 1520)
@@ -66,10 +66,10 @@
     ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    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 ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    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;
 
     #pragma omp critical (_reduce)
-    comm.my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
+    comm->my_buffer->void_buffer[ep_rank_loc] = const_cast< void* >(sendbuf);
 
     MPI_Barrier_local(comm);
@@ -78,5 +78,5 @@
     {
 
-      memcpy(recvbuf, comm.my_buffer->void_buffer[0], datasize * count);
+      memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize * count);
 
       if(op == MPI_MAX)
@@ -86,5 +86,5 @@
           assert(datasize == sizeof(int));
           for(int i=1; i<num_ep; i++)
-            reduce_max<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
+            reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
         }
 
@@ -93,5 +93,5 @@
           assert(datasize == sizeof(float));
           for(int i=1; i<num_ep; i++)
-            reduce_max<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);
+            reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);
         }
 
@@ -100,5 +100,5 @@
           assert(datasize == sizeof(double));
           for(int i=1; i<num_ep; i++)
-            reduce_max<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+            reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
         }
 
@@ -107,5 +107,5 @@
           assert(datasize == sizeof(char));
           for(int i=1; i<num_ep; i++)
-            reduce_max<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+            reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
         }
 
@@ -114,5 +114,5 @@
           assert(datasize == sizeof(long));
           for(int i=1; i<num_ep; i++)
-            reduce_max<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+            reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
         }
 
@@ -121,5 +121,5 @@
           assert(datasize == sizeof(unsigned long));
           for(int i=1; i<num_ep; i++)
-            reduce_max<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);
+            reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);
         }
 
@@ -128,5 +128,5 @@
           assert(datasize == sizeof(uint64_t));
           for(int i=1; i<num_ep; i++)
-            reduce_max<uint64_t>(static_cast<uint64_t*>(comm.my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count);
+            reduce_max<uint64_t>(static_cast<uint64_t*>(comm->my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count);
         }
         
@@ -135,5 +135,5 @@
           assert(datasize == sizeof(long long));
           for(int i=1; i<num_ep; i++)
-            reduce_max<long long>(static_cast<long long*>(comm.my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count);
+            reduce_max<long long>(static_cast<long long*>(comm->my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count);
         }
 
@@ -148,5 +148,5 @@
           assert(datasize == sizeof(int));
           for(int i=1; i<num_ep; i++)
-            reduce_min<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
+            reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
         }
 
@@ -155,5 +155,5 @@
           assert(datasize == sizeof(float));
           for(int i=1; i<num_ep; i++)
-            reduce_min<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);
+            reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);
         }
 
@@ -162,5 +162,5 @@
           assert(datasize == sizeof(double));
           for(int i=1; i<num_ep; i++)
-            reduce_min<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+            reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
         }
 
@@ -169,5 +169,5 @@
           assert(datasize == sizeof(char));
           for(int i=1; i<num_ep; i++)
-            reduce_min<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+            reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
         }
 
@@ -176,5 +176,5 @@
           assert(datasize == sizeof(long));
           for(int i=1; i<num_ep; i++)
-            reduce_min<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+            reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
         }
 
@@ -183,5 +183,5 @@
           assert(datasize == sizeof(unsigned long));
           for(int i=1; i<num_ep; i++)
-            reduce_min<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);
+            reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);
         }
 
@@ -190,5 +190,5 @@
           assert(datasize == sizeof(uint64_t));
           for(int i=1; i<num_ep; i++)
-            reduce_min<uint64_t>(static_cast<uint64_t*>(comm.my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count);
+            reduce_min<uint64_t>(static_cast<uint64_t*>(comm->my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count);
         }
         
@@ -197,5 +197,5 @@
           assert(datasize == sizeof(long long));
           for(int i=1; i<num_ep; i++)
-            reduce_min<long long>(static_cast<long long*>(comm.my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count);
+            reduce_min<long long>(static_cast<long long*>(comm->my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count);
         }
 
@@ -211,5 +211,5 @@
           assert(datasize == sizeof(int));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
+            reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
         }
 
@@ -218,5 +218,5 @@
           assert(datasize == sizeof(float));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);
+            reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);
         }
 
@@ -225,5 +225,5 @@
           assert(datasize == sizeof(double));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+            reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
         }
 
@@ -232,5 +232,5 @@
           assert(datasize == sizeof(char));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+            reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
         }
 
@@ -239,5 +239,5 @@
           assert(datasize == sizeof(long));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+            reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
         }
 
@@ -246,5 +246,5 @@
           assert(datasize == sizeof(unsigned long));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);
+            reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);
         }
 
@@ -253,5 +253,5 @@
           assert(datasize == sizeof(uint64_t));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<uint64_t>(static_cast<uint64_t*>(comm.my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count);
+            reduce_sum<uint64_t>(static_cast<uint64_t*>(comm->my_buffer->void_buffer[i]), static_cast<uint64_t*>(recvbuf), count);
         }
         
@@ -260,5 +260,5 @@
           assert(datasize == sizeof(long long));
           for(int i=1; i<num_ep; i++)
-            reduce_sum<long long>(static_cast<long long*>(comm.my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count);
+            reduce_sum<long long>(static_cast<long long*>(comm->my_buffer->void_buffer[i]), static_cast<long long*>(recvbuf), count);
         }
 
@@ -275,5 +275,5 @@
           assert(datasize == sizeof(int));
           for(int i=1; i<num_ep; i++)
-            reduce_lor<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
+            reduce_lor<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);
         }
       }
@@ -288,20 +288,20 @@
   {
 
-    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));
-    }
-
-
-
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
-
-    int root_mpi_rank = comm.rank_map->at(root).second;
-    int root_ep_loc = comm.rank_map->at(root).first;
+    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));
+    }
+
+
+
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
+
+    int root_mpi_rank = comm->ep_rank_map->at(root).second;
+    int root_ep_loc = comm->ep_rank_map->at(root).first;
 
     ::MPI_Aint datasize, lb;
@@ -326,5 +326,5 @@
     if(is_master)
     {
-      ::MPI_Reduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Reduce(local_recvbuf, recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
       
     }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_reduce_scatter.cpp	(revision 1520)
@@ -19,16 +19,16 @@
   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)
+    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));
+      return ::MPI_Reduce_scatter(sendbuf, recvbuf, recvcounts, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
     }
 
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
 
@@ -52,5 +52,5 @@
     if(is_master)
     {  
-      ::MPI_Allreduce(MPI_IN_PLACE, local_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm.mpi_comm));
+      ::MPI_Allreduce(MPI_IN_PLACE, local_recvbuf, count, to_mpi_type(datatype), to_mpi_op(op), to_mpi_comm(comm->mpi_comm));
     }
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scan.cpp	(revision 1520)
@@ -50,7 +50,7 @@
     valid_op(op);
 
-    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 mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
+    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 mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
     
 
@@ -184,9 +184,9 @@
       }
 
-      comm.my_buffer->void_buffer[0] = recvbuf;
+      comm->my_buffer->void_buffer[0] = recvbuf;
     }
     else
     {
-      comm.my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);  
+      comm->my_buffer->void_buffer[ep_rank_loc] = const_cast<void*>(sendbuf);  
       memcpy(recvbuf, sendbuf, datasize*count);
     } 
@@ -196,5 +196,5 @@
     MPI_Barrier_local(comm);
 
-    memcpy(recvbuf, comm.my_buffer->void_buffer[0], datasize*count);
+    memcpy(recvbuf, comm->my_buffer->void_buffer[0], datasize*count);
 
 
@@ -205,5 +205,5 @@
         assert (datasize == sizeof(int));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_sum<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
+          reduce_sum<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
       }
      
@@ -212,5 +212,5 @@
         assert(datasize == sizeof(float));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_sum<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
+          reduce_sum<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
       }
       
@@ -220,5 +220,5 @@
         assert(datasize == sizeof(double));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_sum<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+          reduce_sum<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
       }
 
@@ -227,5 +227,5 @@
         assert(datasize == sizeof(char));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_sum<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+          reduce_sum<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
       }
 
@@ -234,5 +234,5 @@
         assert(datasize == sizeof(long));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_sum<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+          reduce_sum<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
       }
 
@@ -241,5 +241,5 @@
         assert(datasize == sizeof(unsigned long));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_sum<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
+          reduce_sum<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
       }
 
@@ -255,5 +255,5 @@
         assert(datasize == sizeof(int));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_max<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
+          reduce_max<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
       }
 
@@ -262,5 +262,5 @@
         assert(datasize == sizeof(float));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_max<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
+          reduce_max<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
       }
 
@@ -269,5 +269,5 @@
         assert(datasize == sizeof(double));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_max<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+          reduce_max<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
       }
 
@@ -276,5 +276,5 @@
         assert(datasize == sizeof(char));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_max<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+          reduce_max<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
       }
 
@@ -283,5 +283,5 @@
         assert(datasize == sizeof(long));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_max<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+          reduce_max<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
       }
 
@@ -290,5 +290,5 @@
         assert(datasize == sizeof(unsigned long));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_max<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
+          reduce_max<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
       }
      
@@ -302,5 +302,5 @@
         assert(datasize == sizeof(int));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_min<int>(static_cast<int*>(comm.my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
+          reduce_min<int>(static_cast<int*>(comm->my_buffer->void_buffer[i]), static_cast<int*>(recvbuf), count);    
       }
 
@@ -309,5 +309,5 @@
         assert(datasize == sizeof(float));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_min<float>(static_cast<float*>(comm.my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
+          reduce_min<float>(static_cast<float*>(comm->my_buffer->void_buffer[i]), static_cast<float*>(recvbuf), count);    
       }
 
@@ -316,5 +316,5 @@
         assert(datasize == sizeof(double));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_min<double>(static_cast<double*>(comm.my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
+          reduce_min<double>(static_cast<double*>(comm->my_buffer->void_buffer[i]), static_cast<double*>(recvbuf), count);
       }
 
@@ -323,5 +323,5 @@
         assert(datasize == sizeof(char));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_min<char>(static_cast<char*>(comm.my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
+          reduce_min<char>(static_cast<char*>(comm->my_buffer->void_buffer[i]), static_cast<char*>(recvbuf), count);
       }
 
@@ -330,5 +330,5 @@
         assert(datasize == sizeof(long));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_min<long>(static_cast<long*>(comm.my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
+          reduce_min<long>(static_cast<long*>(comm->my_buffer->void_buffer[i]), static_cast<long*>(recvbuf), count);
       }
 
@@ -337,5 +337,5 @@
         assert(datasize == sizeof(unsigned long));
         for(int i=1; i<ep_rank_loc+1; i++)
-          reduce_min<unsigned long>(static_cast<unsigned long*>(comm.my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
+          reduce_min<unsigned long>(static_cast<unsigned long*>(comm->my_buffer->void_buffer[i]), static_cast<unsigned long*>(recvbuf), count);    
       }
 
@@ -350,17 +350,17 @@
   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));
     }
     
     valid_type(datatype);
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
     ::MPI_Aint datasize, lb;
@@ -375,5 +375,5 @@
     std::vector<int> my_map(mpi_size, 0);
 
-    for(int i=0; i<comm.rank_map->size(); i++) my_map[comm.rank_map->at(i).second]++;
+    for(int i=0; i<comm->ep_rank_map->size(); i++) my_map[comm->ep_rank_map->at(i).second]++;
 
     for(int i=0; i<mpi_rank; i++) my_src += my_map[i];
@@ -416,5 +416,5 @@
 
     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));
+      ::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]);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatter.cpp	(revision 1520)
@@ -24,15 +24,15 @@
     ::MPI_Type_get_extent(to_mpi_type(sendtype), &lb, &datasize);
 
-    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 ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
 
 
     if(ep_rank_loc == local_root)
-      comm.my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf);
+      comm->my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf);
 
     MPI_Barrier_local(comm);
 
     #pragma omp critical (_scatter)      
-    memcpy(recvbuf, comm.my_buffer->void_buffer[local_root]+datasize*ep_rank_loc*sendcount, datasize * recvcount);
+    memcpy(recvbuf, comm->my_buffer->void_buffer[local_root]+datasize*ep_rank_loc*sendcount, datasize * recvcount);
     
 
@@ -42,20 +42,20 @@
   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)
+    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));
+      return ::MPI_Scatter(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
     }
    
     assert(sendcount == recvcount);
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
-    int root_mpi_rank = comm.rank_map->at(root).second;
-    int root_ep_loc = comm.rank_map->at(root).first;
+    int root_mpi_rank = comm->ep_rank_map->at(root).second;
+    int root_ep_loc = comm->ep_rank_map->at(root).first;
 
     bool is_master = (ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root;
@@ -87,5 +87,5 @@
       for(int i=0; i<ep_size; i++)
       {
-        recvcounts[comm.rank_map->at(i).second]++;
+        recvcounts[comm->ep_rank_map->at(i).second]++;
       }
 
@@ -93,5 +93,5 @@
         displs[i] = displs[i-1] + recvcounts[i-1];
 
-      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
     }
 
@@ -121,9 +121,9 @@
     {
       int local_sendcount = num_ep * count;
-      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
       
       if(is_root) for(int i=1; i<mpi_size; i++) displs[i] = displs[i-1] + recvcounts[i-1];
 
-      ::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));
+      ::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]);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_scatterv.cpp	(revision 1520)
@@ -25,16 +25,16 @@
     ::MPI_Type_get_extent(to_mpi_type(sendtype), &lb, &datasize);
 
-    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 ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
 
     assert(recvcount == sendcounts[ep_rank_loc]);
 
     if(ep_rank_loc == local_root)
-      comm.my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf);
+      comm->my_buffer->void_buffer[local_root] = const_cast<void*>(sendbuf);
 
     MPI_Barrier_local(comm);
 
     #pragma omp critical (_scatterv)      
-    memcpy(recvbuf, comm.my_buffer->void_buffer[local_root]+datasize*displs[ep_rank_loc], datasize * recvcount);
+    memcpy(recvbuf, comm->my_buffer->void_buffer[local_root]+datasize*displs[ep_rank_loc], datasize * recvcount);
     
 
@@ -45,20 +45,20 @@
                    MPI_Datatype recvtype, int root, MPI_Comm comm)
   {
-    if(!comm.is_ep)
+    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));
+      return ::MPI_Scatterv(sendbuf, sendcounts, displs, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), root, to_mpi_comm(comm->mpi_comm));
     }
    
     assert(sendtype == recvtype);
 
-    int ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    int ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    int ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    int mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    int ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    int mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    int ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    int num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    int mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
-    int root_mpi_rank = comm.rank_map->at(root).second;
-    int root_ep_loc = comm.rank_map->at(root).first;
+    int root_mpi_rank = comm->ep_rank_map->at(root).second;
+    int root_ep_loc = comm->ep_rank_map->at(root).first;
 
     bool is_master = (ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root;
@@ -90,5 +90,5 @@
       for(int i=0; i<ep_size; i++)
       {
-        recvcounts[comm.rank_map->at(i).second]++;
+        recvcounts[comm->ep_rank_map->at(i).second]++;
       }
 
@@ -96,5 +96,5 @@
         my_displs[i] = my_displs[i-1] + recvcounts[i-1];
 
-      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), my_displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Gatherv(local_ranks.data(), num_ep, to_mpi_type(MPI_INT), ranks.data(), recvcounts.data(), my_displs.data(), to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
     }
 
@@ -124,9 +124,9 @@
       local_sendbuf = new void*[datasize * local_sendcount];
  
-      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm.mpi_comm));
+      ::MPI_Gather(&local_sendcount, 1, to_mpi_type(MPI_INT), recvcounts.data(), 1, to_mpi_type(MPI_INT), root_mpi_rank, to_mpi_comm(comm->mpi_comm));
 
       if(is_root) for(int i=1; i<mpi_size; i++) my_displs[i] = my_displs[i-1] + recvcounts[i-1];
 
-      ::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));
+      ::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] );
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp	(revision 1520)
@@ -12,31 +12,24 @@
 
 
-namespace ep_lib {
-
-
+namespace ep_lib 
+{
+  
   int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
   {
-    if(!comm.is_ep)
-      return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm));
-    if(comm.is_intercomm)
-    {
-      MPI_Request request;
-      MPI_Status status;
-      MPI_Isend(buf, count, datatype, dest, tag, comm, &request);
-      MPI_Wait(&request, &status);
-    }
-    else
-    {
-      int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
-      int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
-      int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
-      int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
-
-      ::MPI_Send(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm));
-      //printf("call mpi_send for intracomm, dest = %d, tag = %d\n", dest, tag);
-    }
-    //check_sum_send(buf, count, datatype, dest, tag, comm);
-
-    return 0;
+    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);
+    
+    Debug("\nMPI_Send with EP\n");
+    
+    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
+    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
+
+#ifdef _check_sum    
+    check_sum_send(buf, count, datatype, dest, tag, comm);
+#endif
+
+    return ::MPI_Send(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm));
   }
 
@@ -44,269 +37,293 @@
   int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
   {
-    if(!comm.is_ep)
-    {
-      return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm));
-    }
-
+    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);
+    
+    Debug("\nMPI_Ssend with EP\n");
+
+    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
+    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
+    
+#ifdef _check_sum    
+    check_sum_send(buf, count, datatype, dest, tag, comm);
+#endif
+    
+    return ::MPI_Ssend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm));
+  }
+  
+
+
+
+
+  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
+  {
+    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);
+
+    Debug("\nMPI_Isend with EP\n");
+   
+    int src_rank;
+    MPI_Comm_rank(comm, &src_rank);
+
+
+#ifdef _check_sum    
+    check_sum_send(buf, count, datatype, dest, tag, comm);
+#endif
+    
+    *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");
+    
+
+    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
+    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
+
+    (*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);
+
+
+    return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
+  }
+
+
+
+
+  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
+  {
+ 
+    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);
+
+    Debug("\nMPI_Issend with EP\n");
+   
+    int src_rank;
+    MPI_Comm_rank(comm, &src_rank);
+
+
+#ifdef _check_sum    
+    check_sum_send(buf, count, datatype, dest, tag, comm);
+#endif
+    
+    *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");
+    
+
+    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
+    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
+
+    (*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);
+    
+    return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));    
+  }
+  
+  int MPI_Send_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
+  {
+    Debug("\nMPI_Send with MPI\n");
+    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)
+  {
+    Debug("\nMPI_Ssend with MPI\n");
+    return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm));
+  }
+  
+
+  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);
-    //check_sum_send(buf, count, datatype, dest, tag, comm);
-    return 0;
-  }
-  
-
-
-
-
-  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
-  {
-    Debug("\nMPI_Isend with EP\n");
-    int src_rank;
-    MPI_Comm_rank(comm, &src_rank);
-
-    
-
-    if(!comm.is_ep)
+    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)
+  {
+    Debug("\nMPI_Isend with MPI\n");
+    
+    int src_rank;
+    MPI_Comm_rank(comm, &src_rank);
+    
+    *request = new ep_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;
+    (*request)->ep_tag = tag;
+    (*request)->ep_datatype = datatype;
+    (*request)->type = 1;
+    (*request)->comm = comm;
+    
+    return ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
+  }
+  
+  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)
     {
-      ::MPI_Request mpi_request;
-      ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
-
-      request->mpi_request = new ::MPI_Request(mpi_request);
-
-      request->ep_src = src_rank;
-      request->ep_tag = tag;
-      request->ep_datatype = datatype;
-      request->type = 1;
-      request->comm = comm;
-
-      return 0;
+      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));
     }
 
-    if(comm.is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request);
-
-    // EP intracomm
-
-    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
-
-    int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
-    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
-    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
-
-    request->ep_src  = src_rank;
-    request->ep_tag  = tag;
-    request->ep_datatype = datatype;
-
-    ::MPI_Request mpi_request;
-
-    ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
-
-    request->mpi_request = new ::MPI_Request(mpi_request);
-    request->type = 1;    // used in wait
-    request->comm = comm;
-    request->buf = const_cast<void*>(buf);
-
-    //Message_Check(comm);
-
-    return 0;
-  }
-
-
-
-
-  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
-  {
-    Debug("\nMPI_Issend with EP\n");
-
-    int src_rank;
-    MPI_Comm_rank(comm, &src_rank);
-
-    
-
-    if(!comm.is_ep)
+    else
     {
-      ::MPI_Request mpi_request;
-      ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
-
-      request->mpi_request = new ::MPI_Request(mpi_request);
-      request->ep_src = src_rank;
-      request->ep_tag = tag;
-      request->ep_datatype = datatype;
-      request->type = 1;
-      request->comm = comm;
-
-      return 0;
+      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));
     }
-
-    if(comm.is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request);
-
-    // EP intracomm
-
-    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
-
-    int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
-    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
-    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
-    
-    request->ep_src = src_rank;
-    request->ep_tag = tag;
-    request->ep_datatype = datatype;
-
-    ::MPI_Request mpi_request;
-
-    ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
-
-    request->mpi_request = new ::MPI_Request(mpi_request);
-    request->type = 1;    // used in wait
-    request->comm = comm;
-    request->buf = NULL;
-    
-
-    //Message_Check(comm);
-
-    return 0;
-  }
-  
-
-
-
-  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 intercomm\n");
-
-    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
-
-    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
+  }
+
+
+
+
+  int MPI_Issend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
+  {
+    Debug("\nMPI_Issend with MPI\n");
+    
+    int src_rank;
+    MPI_Comm_rank(comm, &src_rank);
+    
+    *request = new ep_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;
+    (*request)->ep_tag = tag;
+    (*request)->ep_datatype = datatype;
+    (*request)->type = 1;
+    (*request)->comm = comm;
+    
+    return ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
+  }
+
+
+  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)
     {
-      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm.rank_map->at(inter_src).first;
-      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      ::MPI_Request mpi_request;
-  
-      ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
-
-      request->mpi_request = new ::MPI_Request(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.rank_map->at(inter_src).first;
-      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      ::MPI_Request mpi_request;
-
-      ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request);
-
-      request->mpi_request = new ::MPI_Request(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;
+    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));
     }
-
-    return 0;
-
-  }
-
-
-  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 intercomm\n");
-
-    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
-
-    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;
-
-    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
-    {
-      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
-      {
-        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
-        break;
-      }
-    }
-
-    //Message_Check(comm);
-
-
-    if(dest_remote_comm_label == src_comm_label)       // dest rank (loc, mpi) differs
-    {
-      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm.rank_map->at(inter_src).first;
-      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      ::MPI_Request mpi_request;
-  
-      ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
-
-      request->mpi_request = new ::MPI_Request(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;
-    }
-
-    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.rank_map->at(inter_src).first;
-      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      ::MPI_Request mpi_request;
-
-      ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request);
-
-      request->mpi_request = new ::MPI_Request(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 0;
-
   }
   
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp	(revision 1520)
@@ -7,74 +7,47 @@
 {
 
-
-
-
   int MPI_Comm_size(MPI_Comm comm, int* size)
   {
-    
-    if(comm.is_ep)
+    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);
-      printf("============ ep comm size called for non ep comm, %d\n", mpi_size);
-      *size = mpi_size;
-      return 0;
-    }
-
-    else
-    {
-      *size = MPI_UNDEFINED;
-      printf("============ ep comm size called for non ep comm not defined\n");
-      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/src_ep_dev/ep_split.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp	(revision 1520)
@@ -31,4 +31,25 @@
     inout_vector->swap(out_vec);
   }
+  
+  void vec_simplify(std::vector<int> *in_vector, std::vector<int> *out_vector)
+  {
+    int found=false;
+    for(std::vector<int>::iterator it_in = in_vector->begin() ; it_in != in_vector->end(); ++it_in)
+    {
+      for(std::vector<int>::iterator it = out_vector->begin() ; it != out_vector->end(); ++it)
+      {
+        if(*it_in == *it)
+        {
+          found=true;
+          break;
+        }
+        else found=false;
+      }
+      if(found == false)
+      {
+        out_vector->push_back(*it_in);
+      }
+    }
+  }
 
 
@@ -39,10 +60,10 @@
     int ep_size, num_ep, mpi_size;
 
-    ep_rank = comm.ep_comm_ptr->size_rank_info[0].first;
-    ep_rank_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    mpi_rank = comm.ep_comm_ptr->size_rank_info[2].first;
-    ep_size = comm.ep_comm_ptr->size_rank_info[0].second;
-    num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
-    mpi_size = comm.ep_comm_ptr->size_rank_info[2].second;
+    ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    ep_rank_loc = comm->ep_comm_ptr->size_rank_info[1].first;
+    mpi_rank = comm->ep_comm_ptr->size_rank_info[2].first;
+    ep_size = comm->ep_comm_ptr->size_rank_info[0].second;
+    num_ep = comm->ep_comm_ptr->size_rank_info[1].second;
+    mpi_size = comm->ep_comm_ptr->size_rank_info[2].second;
 
     int num_color = 0;
@@ -52,22 +73,28 @@
     vector<int> matched_number;
     vector<int> matched_number_loc;
-
-
+    
     vector<int> all_color(ep_size);
     vector<int> all_color_loc(num_ep);
 
-    MPI_Gather_local(&color, 1, MPI_INT, all_color_loc.data(), 0, comm);
-    MPI_Bcast_local(all_color_loc.data(), num_ep, MPI_INT, 0, comm);
-
-
     MPI_Allgather(&color, 1, MPI_INT, all_color.data(), 1, MPI_INT, comm);
+    MPI_Allgather_local(&color, 1, MPI_INT, all_color_loc.data(), comm);
 
     list<int> color_list(all_color.begin(), all_color.end());
     list<int> color_list_loc(all_color_loc.begin(), all_color_loc.end());
 
-    vec_simplify(&all_color);
-
-    matched_number.resize(all_color.size(), 0);
-    matched_number_loc.resize(all_color.size(), 0);
+    vector<int> all_color_simplified;
+    vec_simplify(&all_color, &all_color_simplified);
+    int number_of_color;
+    for(int i=0; i<all_color_simplified.size(); i++)
+    {
+      if(color == all_color_simplified[i])
+      {
+        number_of_color = i;
+        break;
+      }
+    }
+
+    matched_number.resize(all_color_simplified.size(), 0);
+    matched_number_loc.resize(all_color_simplified.size(), 0);
 
 
@@ -93,13 +120,24 @@
       num_color++;
     }
-
-
+        
+
+    vector<int> all_key(ep_size);
+    vector<int> all_key_loc(num_ep);
+    
+    vector<int> colored_key[num_color];
     vector<int> colored_key_loc[num_color];
-    vector<int> key_loc(num_ep);
-
-    MPI_Gather_local(&key, 1, MPI_INT, key_loc.data(), 0, comm);
-    MPI_Bcast_local(key_loc.data(), num_ep, MPI_INT, 0, comm);
-    
-    std::sort(key_loc.begin(), key_loc.end());
+    
+
+    MPI_Allgather(&key, 1, MPI_INT, all_key.data(),1, MPI_INT, comm);
+    MPI_Allgather_local(&key, 1, MPI_INT, all_key_loc.data(), comm);
+    
+    vector<int> all_ep_rank(ep_size);
+    vector<int> all_ep_rank_loc(num_ep);
+    
+    vector<int> colored_ep_rank[num_color];
+    vector<int> colored_ep_rank_loc[num_color];
+    
+    MPI_Allgather(&ep_rank, 1, MPI_INT, all_ep_rank.data(),1, MPI_INT, comm);
+    MPI_Allgather_local(&ep_rank, 1, MPI_INT, all_ep_rank_loc.data(), comm);
 
     for(int i=0; i<num_ep; i++)
@@ -107,31 +145,90 @@
       for(int j = 0; j<num_color; j++)
       {
-        if(all_color_loc[i] == all_color[j])
-        {
-          colored_key_loc[j].push_back(key_loc[i]);
-        }
-      }
-    }
-
+        if(all_color_loc[i] == all_color_simplified[j])
+        {
+          colored_key_loc[j].push_back(all_key_loc[i]);
+          colored_ep_rank_loc[j].push_back(all_ep_rank_loc[i]);
+        }
+      }
+    }
+    
+    for(int i=0; i<ep_size; i++)
+    {
+      for(int j = 0; j<num_color; j++)
+      {
+        if(all_color[i] == all_color_simplified[j])
+        {
+          colored_key[j].push_back(all_key[i]);
+          colored_ep_rank[j].push_back(all_ep_rank[i]);
+        }
+      }
+    }
+    
+    int my_offset=0;
+    for(int i=0; i<colored_key[number_of_color].size(); i++)
+    {
+      if(key == colored_key[number_of_color][i])
+      {
+        if(ep_rank != colored_ep_rank[number_of_color][i])
+        {
+          my_offset++;
+        }
+        else
+          break;
+      }
+    }
+    
+    int my_offset_loc=0;
+    for(int i=0; i<colored_key_loc[number_of_color].size(); i++)
+    {
+      if(key == colored_key_loc[number_of_color][i])
+      {
+        if(ep_rank != colored_ep_rank_loc[number_of_color][i])
+        {
+          my_offset_loc++;
+        }
+        else
+          break;
+      }
+    }
+    
+    
+    
+    for(int i=0; i<num_color; i++)
+    {
+      std::sort(colored_key[i].begin(), colored_key[i].end());
+      std::sort(colored_key_loc[i].begin(), colored_key_loc[i].end());
+    }
+
+    int new_ep_rank;
+    
+    for(int i=0; i<colored_key[number_of_color].size(); i++)
+    {
+      if(key == colored_key[number_of_color][i])
+      {
+        new_ep_rank = i+my_offset;
+        break;
+      }
+    }
+    
     int new_ep_rank_loc;
-
-    for(int i=0; i<num_color; i++)
-    {
-      if(colored_key_loc[i].size()>1)
-      {
-        std::sort(colored_key_loc[i].begin(), colored_key_loc[i].end());
-      }
-      if(color == all_color[i])
-      {
-        for(int j=0; j<colored_key_loc[i].size(); j++)
-        {
-          if(key == colored_key_loc[i][j])
-          {
-            new_ep_rank_loc = j;
-            break;
-          }
-        }
-      }
-    }
+    
+    for(int i=0; i<colored_key_loc[number_of_color].size(); i++)
+    {
+      if(key == colored_key_loc[number_of_color][i])
+      {
+        new_ep_rank_loc = i+my_offset_loc;
+        break;
+      }
+    }
+
+#ifdef _showinfo
+    printf("ep_rank = %d, color = %d, key = %d, new_ep_rank = %d, new_ep_rank_loc = %d\n", ep_rank, color, key, new_ep_rank, new_ep_rank_loc);
+#endif
+
+    MPI_Barrier(comm);
+    MPI_Barrier(comm);
+    MPI_Barrier(comm);
+    
 
     ::MPI_Comm **split_mpi_comm;
@@ -147,12 +244,14 @@
         if(matched_number_loc[j] == 0) master_color = MPI_UNDEFINED;
 
-        ::MPI_Comm_split(to_mpi_comm(comm.mpi_comm), master_color, mpi_rank, split_mpi_comm[j]);
-        
-        comm.ep_comm_ptr->comm_list->mpi_bridge = split_mpi_comm[j];
-      }
+        ::MPI_Comm_split(to_mpi_comm(comm->mpi_comm), master_color, mpi_rank, split_mpi_comm[j]);
+        
+        comm->ep_comm_ptr->comm_list[0]->mpi_bridge = split_mpi_comm[j];
+      }
+      
       MPI_Barrier_local(comm);
+      
       int num_new_ep = 0;
 
-      if(new_ep_rank_loc == 0 && color == all_color[j])
+      if(new_ep_rank_loc == 0 && color == all_color_simplified[j])
       {
         num_new_ep = matched_number_loc[j];
@@ -160,21 +259,86 @@
         MPI_Comm *ep_comm;
 
-        MPI_Comm_create_endpoints(comm.ep_comm_ptr->comm_list->mpi_bridge, num_new_ep, info, ep_comm);
-
-
-        comm.ep_comm_ptr->comm_list->mem_bridge = ep_comm;
-      }
+        MPI_Comm_create_endpoints(comm->ep_comm_ptr->comm_list[0]->mpi_bridge, num_new_ep, info, ep_comm);
+
+        comm->ep_comm_ptr->comm_list[0]->mem_bridge = ep_comm;
+        
+        (*ep_comm)->ep_rank_map->clear();
+        
+        memcheck("in MPI_Split ep_rank="<< ep_rank <<" : *ep_comm = "<< *ep_comm);
+      }
+      
       MPI_Barrier_local(comm);
-      if(color == all_color[j])
-      {
-        *newcomm = comm.ep_comm_ptr->comm_list->mem_bridge[new_ep_rank_loc];
-
-        (*newcomm).ep_comm_ptr->comm_label = color;
-      }
-    }
-
-
-
-
+      
+      if(color == all_color_simplified[j])
+      {
+        *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;
+        (*newcomm)->ep_comm_ptr->size_rank_info[1].first = new_ep_rank_loc;
+        
+        int my_triple[3];
+        vector<int> my_triple_vector;
+        vector<int> my_triple_vector_recv;
+        my_triple[0] = new_ep_rank;
+        my_triple[1] = new_ep_rank_loc;
+        my_triple[2] = (*newcomm)->ep_comm_ptr->size_rank_info[2].first; // new_mpi_rank
+        
+        int new_ep_size = (*newcomm)->ep_comm_ptr->size_rank_info[0].second;
+        int new_num_ep  = (*newcomm)->ep_comm_ptr->size_rank_info[1].second;
+        
+        int new_mpi_size = (*newcomm)->ep_comm_ptr->size_rank_info[2].second;
+        
+        if(new_ep_rank_loc == 0) my_triple_vector.resize(3*new_ep_size);
+        if(new_ep_rank_loc == 0) my_triple_vector_recv.resize(3*new_ep_size);
+        
+        MPI_Gather_local(my_triple, 3, MPI_INT, my_triple_vector.data(), 0, *newcomm);
+        
+        if(new_ep_rank_loc == 0)
+        {
+          int *recvcounts = new int[new_mpi_size];
+          int *displs = new int[new_mpi_size];
+          int new_num_epx3 = new_num_ep * 3;
+          ::MPI_Allgather(&new_num_epx3, 1, to_mpi_type(MPI_INT), recvcounts, 1, to_mpi_type(MPI_INT), to_mpi_comm((*newcomm)->mpi_comm));
+          displs[0]=0;
+          for(int i=1; i<new_mpi_size; i++)
+            displs[i] = displs[i-1] + recvcounts[i-1];
+             
+          ::MPI_Allgatherv(my_triple_vector.data(), 3*new_num_ep, to_mpi_type(MPI_INT), my_triple_vector_recv.data(), recvcounts, displs, to_mpi_type(MPI_INT), to_mpi_comm((*newcomm)->mpi_comm));
+          
+          for(int i=0; i<new_ep_size; i++)
+          {
+            (*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(my_triple_vector_recv[3*i], my_triple_vector_recv[3*i+1], my_triple_vector_recv[3*i+2]));
+          }
+          
+          (*newcomm)->ep_rank_map = (*newcomm)->ep_comm_ptr->comm_list[0]->ep_rank_map;
+          
+          delete recvcounts;
+          delete displs;
+        } 
+      }
+    }
+
+#ifdef _Memory_check   
+    for(int i=0; i<ep_size; i++)
+    {
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+      if(ep_rank==i) 
+      {
+        printf("ep_rank_map for endpoint %d = \n", ep_rank);
+        for(std::map<int, std::pair<int, int> > :: iterator it = (*newcomm)->ep_rank_map->begin(); it != (*newcomm)->ep_rank_map->end(); it++)
+        {
+          printf("\t\t\t %d %d %d\n", it->first, it->second.first, it->second.second);
+        }
+        printf("\n");
+      }
+      MPI_Barrier(comm);
+      MPI_Barrier(comm);
+    }   
+#endif
+    
     return 0;
   }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_test.cpp	(revision 1520)
@@ -22,15 +22,18 @@
     
 
-    if(request->type == 1)      // isend
+    if((*request)->type == 1)      // isend
     {
       ::MPI_Status mpi_status;
-      ::MPI_Test(static_cast< ::MPI_Request*>(request->mpi_request), flag, &mpi_status);
+      ::MPI_Test(static_cast< ::MPI_Request*>((*request)->mpi_request), flag, &mpi_status);
       
       if(*flag) 
       {
         status->mpi_status = new ::MPI_Status(mpi_status);
-        status->ep_src = request->ep_src;
-        status->ep_tag = request->ep_tag;
-        status->ep_datatype = request->ep_datatype;
+        status->ep_src = (*request)->ep_src;
+        status->ep_tag = (*request)->ep_tag;
+        status->ep_datatype = (*request)->ep_datatype;
+        (*request)->state = 2;
+        delete (*request)->mpi_request;
+        delete *request;
       }
 
@@ -38,5 +41,5 @@
     }
 
-    if(request->type == 2)   // irecv message not probed
+    if((*request)->type == 2)   // irecv message not probed
     {
       Request_Check();
@@ -46,9 +49,13 @@
     }
 
-    if(request->type == 3)  // imrecv
+    if((*request)->type == 3)  // imrecv
     {
+      if((*request)->state == 2)
+      {
+        return *flag = true;
+      }
       ::MPI_Status mpi_status;
       
-      ::MPI_Test(static_cast< ::MPI_Request*>(request->mpi_request), flag, &mpi_status);
+      ::MPI_Test(static_cast< ::MPI_Request*>((*request)->mpi_request), flag, &mpi_status);
       
       
@@ -56,7 +63,12 @@
       {
         status->mpi_status = new ::MPI_Status(mpi_status);
-        status->ep_src = request->ep_src;
-        status->ep_tag = request->ep_tag;
-        status->ep_datatype = request->ep_datatype;
+        status->ep_src = (*request)->ep_src;
+        status->ep_tag = (*request)->ep_tag;
+        status->ep_datatype = (*request)->ep_datatype;
+        
+        (*request)->state = 2;
+        
+        delete (*request)->mpi_request;
+        delete *request;
         //int count;
         //MPI_Get_count(status, request->ep_datatype, &count);
@@ -64,5 +76,5 @@
       }  
 
-      return 0;
+      return Request_Check();
     }
 
@@ -73,13 +85,38 @@
   {
     Debug("MPI_Testall with EP");
-    *flag = true;
-    int i=0;
-    while(*flag && i<count )
+
+    ::MPI_Request* mpi_request = new ::MPI_Request[count];
+    ::MPI_Status* mpi_status = new ::MPI_Status[count];
+
+
+    for(int i=0; i<count; i++)
     {
-      MPI_Test(&array_of_requests[i], flag, &array_of_statuses[i]);
-      i++;
+      mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
     }
+
+    ::MPI_Testall(count, mpi_request, flag, mpi_status);
+
+    if(*flag)
+    {
+      for(int i=0; i<count; i++)
+      {
+        array_of_statuses[i].mpi_status = &mpi_status[i];
+        array_of_statuses[i].ep_src = array_of_requests[i]->ep_src;
+        array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag;
+        array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
+        
+        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");
+        delete array_of_requests[i]->mpi_request;
+        delete array_of_requests[i]; 
+      }
+      
+    }
+
+    return Request_Check();
   }
 
 
 }
+
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.cpp	(revision 1520)
@@ -11,65 +11,27 @@
 namespace ep_lib
 { 
-  
-  ep_intercomm::ep_intercomm()
+  ep_comm::ep_comm(void* comm)
   {
-    intercomm_rank_map = NULL;
-    local_rank_map = NULL;
-    remote_rank_map = NULL;
-    mpi_inter_comm = new ::MPI_Comm;
+    is_ep = false;
+    is_intercomm = false;
+    mpi_comm = static_cast< ::MPI_Comm*>(comm);
   }
 
-  bool ep_intercomm::operator == (ep_intercomm right)
+  ep_info::ep_info(void* info)
   {
-    bool a = intercomm_rank_map == right.intercomm_rank_map;
-    bool b = local_rank_map == right.local_rank_map;
-    bool c = remote_rank_map == right.remote_rank_map;
-    bool d = *(static_cast< ::MPI_Comm*>(mpi_inter_comm)) == *(static_cast< ::MPI_Comm*>(right.mpi_inter_comm));
-    bool e = size_rank_info == right.size_rank_info;
-    bool f = intercomm_tag == right.intercomm_tag;
-    return a&&b&&c&&d&&e&&f;
+    mpi_info = static_cast< ::MPI_Info*>(info);
   }
 
-  bool ep_intercomm::operator != (ep_intercomm right)
+  ep_request::ep_request(void* request)
   {
-    bool a = intercomm_rank_map != right.intercomm_rank_map;
-    bool b = local_rank_map != right.local_rank_map;
-    bool c = remote_rank_map != right.remote_rank_map;
-    bool d = *(static_cast< ::MPI_Comm*>(mpi_inter_comm)) != *(static_cast< ::MPI_Comm*>(right.mpi_inter_comm));
-    bool e = size_rank_info != right.size_rank_info;
-    bool f = intercomm_tag != right.intercomm_tag;
-    return a||b||c||d||e||f;
+    mpi_request = static_cast< ::MPI_Request*>(request);
+  }
+  
+  ep_status::ep_status(void* status)
+  {
+    mpi_status = static_cast< ::MPI_Status*>(status);
   }
 
-  ep_communicator::ep_communicator()
-  {
-    comm_list = NULL;
-    message_queue = NULL;
-    intercomm = NULL;
-  }
-
-  MPI_Message::MPI_Message(void* message)
-  {
-    mpi_message = new ::MPI_Message;
-    *(static_cast< ::MPI_Message*>(mpi_message)) = *(static_cast< ::MPI_Message*>(message));
-  }
-
-  MPI_Info::MPI_Info(void* info)
-  {
-    mpi_info = new ::MPI_Info;
-    *(static_cast< ::MPI_Info*>(mpi_info)) = *(static_cast< ::MPI_Info*>(info));
-  }
-  
-  MPI_Info::MPI_Info()
-  {
-    mpi_info = new ::MPI_Info;
-    *(static_cast< ::MPI_Info*>(mpi_info)) = *(static_cast< ::MPI_Info*>(MPI_INFO_NULL.mpi_info));
-  }
-  
-  MPI_Request::MPI_Request(void* request)
-  {
-    mpi_request = new ::MPI_Request;
-    *(static_cast< ::MPI_Request*>(mpi_request)) = *static_cast< ::MPI_Request*>(request);
-  }
+  /*
   
   MPI_Aint::MPI_Aint(void* aint)
@@ -77,4 +39,16 @@
     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; 
   }
   
@@ -85,78 +59,7 @@
   }
 
-  bool ep_communicator::operator == (ep_communicator right)
-  {
-    bool a = size_rank_info == right.size_rank_info;
-    bool b = comm_label == right.comm_label;
-    bool c = intercomm == right.intercomm;
-    return a&&b&&c;
-  }
-
-  bool ep_communicator::operator != (ep_communicator right)
-  {
-    bool a = size_rank_info != right.size_rank_info;
-    bool b = comm_label != right.comm_label;
-    bool c = intercomm != right.intercomm;
-    return a||b||c;
-  }
-
-  MPI_Comm::MPI_Comm()
-  {
-    is_ep = true;
-    is_intercomm = false;
-    my_buffer = NULL;
-    ep_barrier = NULL;
-    rank_map = NULL;
-    ep_comm_ptr = NULL;
-    mem_bridge = NULL;
-    mpi_bridge = NULL;
-    mpi_comm = new ::MPI_Comm;
-  }
-
   
-
-  MPI_Comm::MPI_Comm(void* comm)
-  {
-    is_ep = false;
-    is_intercomm = false;
-    my_buffer = NULL;
-    ep_barrier = NULL;
-    rank_map = NULL;
-    ep_comm_ptr = NULL;
-    mem_bridge = NULL;
-    mpi_bridge = NULL;
-    mpi_comm = new ::MPI_Comm;
-    *(static_cast< ::MPI_Comm*>(mpi_comm)) = *(static_cast< ::MPI_Comm*>(comm));
-  }
-
+*/
   
-
-  bool MPI_Comm::operator == (MPI_Comm right)
-  {
-    bool a = is_ep == right.is_ep;
-    bool b = is_intercomm == right.is_intercomm;
-    bool c = *(static_cast< ::MPI_Comm*>(mpi_comm)) == *(static_cast< ::MPI_Comm*>(right.mpi_comm));
-    bool d = is_ep ? ep_comm_ptr == right.ep_comm_ptr : true;
-    return a&&b&&c&&d;
-  }
-
-  bool MPI_Comm::operator != (MPI_Comm right)
-  {
-    bool a = is_ep != right.is_ep;
-    bool b = is_intercomm != right.is_intercomm;
-    bool c = *(static_cast< ::MPI_Comm*>(mpi_comm)) != *(static_cast< ::MPI_Comm*>(right.mpi_comm));
-    bool d = is_ep ? ep_comm_ptr != right.ep_comm_ptr : true;
-    return a||b||c||d;
-  }
-
-  bool MPI_Request::operator == (MPI_Request right)
-  {
-    bool b = type == right.type;
-    bool c = buf == right.buf;
-    bool d = ep_src == right.ep_src;
-    bool e = ep_tag == right.ep_tag;
-    bool f = ep_datatype == right.ep_datatype;
-    return b&&c&&d&&e&&f;
-  }
 
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp	(revision 1520)
@@ -12,5 +12,4 @@
 #include <numeric>
 #include <bitset>
-//#include <memory.h>
 #include <algorithm>
 #include <assert.h>
@@ -24,228 +23,31 @@
 #endif
 
+#ifdef _Memory_check
+#define memcheck(x) std::cout << x << std::endl
+#else
+#define memcheck(x)
+#endif
+
+
 #define BUFFER_SIZE 10000
 
-//#define NUM_THREADS 12
-
-typedef std::pair< int, int > SIZE_RANK_INFO; // < rank, size>
-
-typedef std::vector< std::pair<int, int> > RANK_MAP;  // at(ep_rank) = <ep_rank_local, mpi_rank>
-
-typedef std::vector<std::pair< std::pair<int, int>, std::pair<int, int> > > INTERCOMM_RANK_MAP;
+#include "ep_status.hpp"
+#include "ep_request.hpp"
+#include "ep_info.hpp"
+#include "ep_message.hpp"
+#include "ep_barrier.hpp"
+#include "ep_comm.hpp"
+#include "ep_intercomm.hpp"
+#include "ep_window.hpp"
 
 
-typedef struct
-{
-  int first;
-  int second;
-  int third;
-} Triple_int;
 
 namespace ep_lib
 {
-  //#define EP_UNDEFINED -32766
 
   class ep_communicator;
   class ep_intercomm;
-  class OMPbarrier;
-  typedef ep_communicator* EP_Comm;
-  class MPI_Comm;
 
 
-  class MPI_Status
-  {
-    public:
-
-      void* ep_datatype;
-      int ep_src;
-      int ep_tag;
-      void* mpi_status;
-  };
-
-  class MPI_Message
-  {
-    public:
-
-      void* mpi_message;
-      int ep_src;
-      int ep_tag;
-      void* mpi_status;
-
-      MPI_Message() {}
-      MPI_Message(void* message);
-  };
-
-  typedef std::list<MPI_Message > Message_list;
-
-
-  class OMPbarrier
-  {
-    private:
-      int nbThreads;          //<The number of threads for this barrier
-      int currentNbThread;    //<The current number of threads waiting
-      bool sense;             //<Direct barrier feedback protection
-      omp_lock_t mutex;       //<To have an atomic int
-
-      OMPbarrier(OMPbarrier&){}
-      OMPbarrier& operator=(OMPbarrier&){return *this;}
-
-    public:
-      /** Constructor with the number of threads */
-      explicit OMPbarrier(const int inNbThreads)
-          : nbThreads(inNbThreads), currentNbThread(0), sense(false) {
-          omp_init_lock( &mutex );
-      }
-
-      /** Destructor, release the omp lock */
-      ~OMPbarrier(){
-          omp_destroy_lock( &mutex );
-      }
-
-      /** Perform a barrier */
-      void wait(){
-          const bool mySense = sense;
-          omp_set_lock( &mutex );
-          const int nbThreadsArrived = (++currentNbThread);
-          omp_unset_lock( &mutex );
-
-          if(nbThreadsArrived == nbThreads) {
-              currentNbThread = 0;
-              sense = !sense;
-              #pragma omp flush
-          }
-          else {
-              volatile const bool* const ptSense = &sense;
-              while( (*ptSense) == mySense){
-              }
-          }
-      }
-
-
-      /** Change the number of threads */
-      void setNbThreads(const int inNbThread){
-          omp_set_lock( &mutex );
-          nbThreads = inNbThread;
-          omp_unset_lock( &mutex );
-      }
-  };
-
-  class ep_intercomm
-  {
-    public:
-
-    void *mpi_inter_comm;
-
-    RANK_MAP *intercomm_rank_map;
-    RANK_MAP *local_rank_map;
-    RANK_MAP *remote_rank_map;
-
-
-    SIZE_RANK_INFO size_rank_info[3];
-
-
-    MPI_Comm *local_comm;
-    int intercomm_tag;
-
-    ep_intercomm();
-    //~ep_intercomm(){delete mpi_inter_comm;}
-    bool operator == (ep_intercomm right);
-    bool operator != (ep_intercomm right);
-    
-
-
-  };
-
-
-  class ep_communicator
-  {
-    public:
-
-    SIZE_RANK_INFO size_rank_info[3]; // 0: ep_rank,     ep_size
-                                      // 1: ep_rank_loc, num_ep
-                                      // 2: mpi_rank,    mpi_size
-
-
-    MPI_Comm *comm_list;
-
-    Message_list *message_queue;
-
-
-    int comm_label;
-
-    ep_intercomm *intercomm;
-
-    ep_communicator();
-    bool operator == (ep_communicator right);
-    bool operator != (ep_communicator right);
-    
-  };
-
-
-  struct BUFFER
-  {
-    void * void_buffer[12];
-  };
-
-
-  class MPI_Comm
-  {
-    public:
-
-    bool is_ep;
-    bool is_intercomm;
-
-    BUFFER     *my_buffer;
-    OMPbarrier *ep_barrier;
-    RANK_MAP   *rank_map;
-    void* mpi_comm;
-    EP_Comm ep_comm_ptr;
-    MPI_Comm *mem_bridge;
-    void* mpi_bridge;
-
-    MPI_Comm();  
-    MPI_Comm(void* comm);
-    //~MPI_Comm(){delete mpi_comm;}
-
-
-    bool operator == (MPI_Comm right);
-    bool operator != (MPI_Comm right);
-    bool is_null();
-
-  };
-
-
-  class MPI_Info
-  {
-    public:
-
-      void* mpi_info;
-
-      MPI_Info();
-      MPI_Info(void* info);
-  };
-
-
-  class MPI_Request
-  {
-    public:
-
-      void* mpi_request;
-
-      int type;	//! type of the non-blocking communication. 1: Isend; 2:Irecv; 3:Imrecv; 4:Issend
-      void* buf;
-
-      int ep_src;
-      int ep_tag;
-      void* ep_datatype;
-
-      MPI_Comm comm;	//! EP communicator related to the communication
-
-      MPI_Request() {}
-      MPI_Request(void* request);
-      bool operator == (MPI_Request right);
-
-  };
-
-  
   class MPI_Aint
   {
@@ -256,5 +58,6 @@
     MPI_Aint() {}
     MPI_Aint(void* aint);
-    //MPI_Aint(int a): mpi_aint(a) {}
+    MPI_Aint(int aint);
+    MPI_Aint operator=(int a);
   };
 
@@ -262,12 +65,13 @@
   {
     public:
-
+  
     void* mpi_fint;
-
+    
     MPI_Fint() {}
     MPI_Fint(void* fint);
-    //MPI_Fint(int f): mpi_fint(f) {}
-    
+                                 
   };
+ 
+  
 
 
@@ -278,9 +82,8 @@
   static std::list<std::pair<std::pair<int, int>, MPI_Comm * > > tag_list;
 
+  static std::list< std::pair<std::pair<int, int> , std::pair<MPI_Comm * , std::pair<int, int> > > > intercomm_list;
+
   static std::map<std::pair<int, int>, MPI_Comm >  fc_comm_map;
 
-//  static std::map<std::pair<int, int>, MPI_Comm >  *fc_comm_map_ptr;
-//  #pragma omp threadprivate(fc_comm_map_ptr)
-//            //    <MPI_Fint,thread_num>   EP_Comm
 
 }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp	(revision 1518)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_wait.cpp	(revision 1520)
@@ -9,4 +9,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -22,5 +23,5 @@
   int MPI_Wait(MPI_Request *request, MPI_Status *status)
   {
-    if(request->type !=1 && request->type !=2 && request->type !=3) 
+    if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) 
     {
       printf("Error in request type\n");
@@ -29,24 +30,21 @@
     }
 
-    while(request->type == 2) Request_Check();
+    while((*request)->type == 2) Request_Check();
+    
+    ::MPI_Wait(to_mpi_request_ptr(*request), to_mpi_status_ptr(status));
 
+    
+    status->ep_src = (*request)->ep_src;
+    status->ep_tag = (*request)->ep_tag;
+    status->ep_datatype = (*request)->ep_datatype;
+    
+    (*request)->state = 2;
 
-    //::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
-    ::MPI_Status mpi_status;
-    ::MPI_Wait(static_cast< ::MPI_Request*>(request->mpi_request), &mpi_status);
-
-   
-           
- 
-    // request->mpi_request = mpi_request;
-
-    status->mpi_status = &mpi_status;
-    status->ep_src = request->ep_src;
-    status->ep_tag = request->ep_tag;
-    status->ep_datatype = request->ep_datatype;
+    memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Wait, delete (*request)->mpi_request");
+    delete (*request)->mpi_request;
+    delete *request;
     
 
-
-    return MPI_SUCCESS;
+    return Request_Check();
 
   }   /*end of mpi_wait*/
@@ -69,5 +67,5 @@
       for(int i=0; i<count; i++)
       {
-        if(array_of_requests[i].type !=1 && array_of_requests[i].type !=2 && array_of_requests[i].type !=3) 
+        if(array_of_requests[i]->type !=1 && array_of_requests[i]->type !=2 && array_of_requests[i]->type !=3) 
         {
           printf("Error in request type\n");
@@ -76,10 +74,9 @@
         }
         
-        if(array_of_requests[i].type == 2) Request_Check(); 
-        if(array_of_requests[i].type != 2 && finished.at(i) == 0) 
+        if(array_of_requests[i]->type == 2) Request_Check(); 
+        if(array_of_requests[i]->type != 2 && finished.at(i) == 0) 
         {
           finished.at(i) = 1;
-          //mpi_request[i] = static_cast< ::MPI_Request >(array_of_requests[i].mpi_request);
-          mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i].mpi_request);
+          mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request);
         }
       }    
@@ -91,7 +88,13 @@
     {
       array_of_statuses[i].mpi_status = &mpi_status[i];
-      array_of_statuses[i].ep_src = array_of_requests[i].ep_src;
-      array_of_statuses[i].ep_tag = array_of_requests[i].ep_tag;
-      array_of_statuses[i].ep_datatype = array_of_requests[i].ep_datatype;
+      array_of_statuses[i].ep_src = array_of_requests[i]->ep_src;
+      array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag;
+      array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype;
+      
+      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");
+      delete array_of_requests[i]->mpi_request;
+      delete array_of_requests[i];
     }
 
@@ -99,6 +102,5 @@
     delete[] mpi_status;
     
-    
-    return MPI_SUCCESS;
+    return Request_Check();
   }  /* end of mpi_waitall*/
 
