Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_dup.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_dup.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_dup.cpp	(revision 1067)
@@ -5,54 +5,4 @@
 namespace ep_lib
 {
-
-
-
-  int MPI_Comm_dup_dev(MPI_Comm comm, MPI_Comm *newcomm)
-  {
-    if(!comm.is_ep)
-    {
-      Debug("Comm_dup MPI\n");
-      newcomm = new MPI_Comm;
-      newcomm->is_ep = comm.is_ep;
-
-      ::MPI_Comm input = static_cast< ::MPI_Comm>(comm.mpi_comm);
-      ::MPI_Comm output;
-
-      
-      ::MPI_Comm_dup(input, &output);
-
-      newcomm->mpi_comm = output;
-
-      return 0;
-    }
-
-    if(!comm.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;
-
-
-    if(0 == my_rank)
-    {
-      MPI_Info info;
-      ::MPI_Comm mpi_dup;
-
-      ::MPI_Comm in_comm = static_cast< ::MPI_Comm>(comm.mpi_comm);
-
-      ::MPI_Comm_dup(in_comm, &mpi_dup);
-
-      MPI_Comm_create_endpoints(mpi_dup, num_ep, info, newcomm);
-      comm.ep_comm_ptr->comm_list->mem_bridge = newcomm;
-    }
-
-    MPI_Barrier_local(comm);
-
-    newcomm = &(comm.ep_comm_ptr->comm_list->mem_bridge[my_rank]);
-
-    return MPI_SUCCESS;
-  }
-
-
 
   int MPI_Comm_dup(MPI_Comm comm, MPI_Comm *newcomm)
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_fortran.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_fortran.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_fortran.cpp	(revision 1067)
@@ -1,7 +1,8 @@
-//#include "ep_lib.hpp"
+#include "ep_lib.hpp"
 #include "ep_lib_fortran.hpp"
 #include <mpi.h>
 #include <map>
 #include <utility>
+#include "ep_declaration.hpp"
 
 #ifdef _intelmpi
@@ -26,5 +27,5 @@
     fint = ::MPI_Comm_c2f(static_cast< ::MPI_Comm>(comm.mpi_comm));
     #endif
-    std::map<std::pair<int, int>, MPI_Comm  > ::iterator it;
+    std::map<std::pair<int, int>, MPI_Comm > ::iterator it;
     
     it = fc_comm_map.find(std::make_pair(fint, omp_get_thread_num()));
@@ -32,5 +33,5 @@
     {
       fc_comm_map.insert(std::make_pair( std::make_pair( fint, omp_get_thread_num()) , comm));
-      //printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), &comm);
+      printf("EP_Comm_c2f : MAP insert: %d, %d, %p\n", fint, omp_get_thread_num(), &comm);
     }
     
@@ -45,5 +46,5 @@
     
     
-    std::map<std::pair<int, int>, MPI_Comm  > ::iterator it;
+    std::map<std::pair<int, int>, MPI_Comm > ::iterator it;
     
     it = fc_comm_map.find(std::make_pair(comm, omp_get_thread_num()));
@@ -51,6 +52,6 @@
     {
       MPI_Comm comm_ptr;
-      comm_ptr =  it->second;
-      //printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, &comm_ptr);
+      comm_ptr = it->second;
+      printf("EP_Comm_f2c : MAP find: %d, %d, %p\n", it->first.first, it->first.second, it->second);
       return  comm_ptr;
     }
@@ -58,5 +59,19 @@
     {      
       MPI_Comm return_comm;
-      return_comm.mpi_comm = ::MPI_Comm_f2c(comm);
+      if(omp_get_thread_num() == 0)
+      {
+        ::MPI_Comm base_comm = ::MPI_Comm_f2c(comm);
+        if(base_comm != MPI_COMM_NULL_STD)
+        {
+          int num_ep = omp_get_num_threads();
+          MPI_Comm *new_comm;
+          MPI_Info info;
+          MPI_Comm_create_endpoints(base_comm, num_ep, info, new_comm);
+          return_comm = new_comm[omp_get_thread_num()];
+        }
+        return MPI_COMM_NULL;
+      }
+      
+      
       return return_comm;
     }
@@ -122,5 +137,5 @@
     fint = ::MPI_Comm_c2f(static_cast< ::MPI_Comm>(comm.mpi_comm));
     
-    std::map<std::pair<int, int>, MPI_Comm  > ::iterator it;
+    std::map<std::pair<int, int>, MPI_Comm > ::iterator it;
     
     it = fc_comm_map.find(std::make_pair(fint, omp_get_thread_num()));
@@ -140,5 +155,5 @@
     
     
-    std::map<std::pair<int, int>, MPI_Comm  > ::iterator it;
+    std::map<std::pair<int, int>, MPI_Comm > ::iterator it;
     
     it = fc_comm_map.find(std::make_pair(comm, omp_get_thread_num()));
@@ -147,5 +162,5 @@
       MPI_Comm comm_ptr;
       comm_ptr =  it->second;
-      printf("MAP find: %d, %d, %p\n", it->first.first, it->first.second, &comm_ptr);
+      printf("MAP find: %d, %d, %p\n", it->first.first, it->first.second, comm_ptr);
       return  comm_ptr;
     }
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm_kernel.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm_kernel.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm_kernel.cpp	(revision 1067)
@@ -351,4 +351,5 @@
         #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());
       }
 
@@ -419,4 +420,5 @@
             *newintercomm =  iter->second[my_position];
             found = true;
+            tag_list.erase(iter);
             break;
           }
@@ -426,4 +428,15 @@
 
     MPI_Barrier_local(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;
@@ -674,4 +687,5 @@
             *newintercomm =  iter->second[my_position];
             found = true;
+            tag_list.erase(iter);
             break;
           }
@@ -679,4 +693,15 @@
       }
     }
+
+    // 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);
+    //       }
+    //     }
+    // }
 
 
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm_world.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm_world.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_intercomm_world.cpp	(revision 1067)
@@ -417,4 +417,5 @@
 
             found = true;
+            tag_list.erase(iter);
             break;
           }
@@ -424,4 +425,17 @@
 
     MPI_Barrier_local(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);
+    //     }
+    //   }
+    // }
+
+    
 
     int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
@@ -920,4 +934,5 @@
 
             found = true;
+            tag_list.erase(iter);
             break;
           }
@@ -927,4 +942,15 @@
 
     MPI_Barrier_local(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);
+    //     }
+    //   }
+    // }
 
     int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_message.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_message.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_message.cpp	(revision 1067)
@@ -24,5 +24,5 @@
 
     if(comm.is_intercomm)
-	  {
+    {
       return  Message_Check_intercomm(comm);
     }
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_test.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_test.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_test.cpp	(revision 1067)
@@ -65,6 +65,6 @@
         status->ep_tag = request->ep_tag;
         status->ep_datatype = request->ep_datatype;
-        int count;
-        MPI_Get_count(status, request->ep_datatype, &count);
+        //int count;
+        //MPI_Get_count(status, request->ep_datatype, &count);
         //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
       }
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_type.hpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_type.hpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_type.hpp	(revision 1067)
@@ -282,5 +282,5 @@
     MPI_Comm()
     {
-      is_ep = false;
+      is_ep = true;
       is_intercomm = false;
       my_buffer = NULL;
@@ -338,4 +338,5 @@
       bool c = mpi_comm != right.mpi_comm;
       bool d = is_ep ? ep_comm_ptr != right.ep_comm_ptr : true;
+
       return a||b||c||d;
     }
@@ -424,5 +425,5 @@
   static std::list<std::pair<std::pair<int, int>, MPI_Comm * > > tag_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;
             //    <MPI_Fint,thread_num>   EP_Comm
 
Index: XIOS/dev/branch_yushan/extern/src_ep_dev/ep_wait.cpp
===================================================================
--- XIOS/dev/branch_yushan/extern/src_ep_dev/ep_wait.cpp	(revision 1063)
+++ XIOS/dev/branch_yushan/extern/src_ep_dev/ep_wait.cpp	(revision 1067)
@@ -68,6 +68,6 @@
       status->ep_datatype = request->ep_datatype;
 
-      int count;
-      MPI_Get_count(status, request->ep_datatype, &count);
+      //int count;
+      //MPI_Get_count(status, request->ep_datatype, &count);
       //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
     }
@@ -104,6 +104,6 @@
             if(array_of_requests[i].type == 3)
             {
-              int check_count;
-              MPI_Get_count(&array_of_statuses[i], array_of_requests[i].ep_datatype, &check_count);
+              //int check_count;
+              //MPI_Get_count(&array_of_statuses[i], array_of_requests[i].ep_datatype, &check_count);
               //check_sum_recv(array_of_requests[i].buf, count, array_of_requests[i].ep_datatype, array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].comm, 2);
             }
