Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgather.cpp	(revision 1354)
@@ -22,10 +22,6 @@
     if(!comm.is_ep && comm.mpi_comm)
     {
-      ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, static_cast< ::MPI_Datatype>(sendtype), recvbuf, recvcount, static_cast< ::MPI_Datatype>(recvtype),
-                      static_cast< ::MPI_Comm>(comm.mpi_comm));
-      return 0;
+      return ::MPI_Allgather(const_cast<void*>(sendbuf), sendcount, to_mpi_type(sendtype), recvbuf, recvcount, to_mpi_type(recvtype), to_mpi_comm(comm.mpi_comm));
     }
-
-    if(!comm.mpi_comm) return 0;
 
     assert(sendcount == recvcount);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allgatherv.cpp	(revision 1354)
@@ -22,6 +22,5 @@
     if(!comm.is_ep && comm.mpi_comm)
     {
-      ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm.mpi_comm));
-      return 0;
+      return ::MPI_Allgatherv(sendbuf, sendcount, to_mpi_type(sendtype), recvbuf, recvcounts, displs, to_mpi_type(recvtype), to_mpi_comm(comm.mpi_comm));
     }
 
@@ -80,5 +79,5 @@
 
       int local_sendcount = std::accumulate(local_recvcounts.begin(), local_recvcounts.end(), 0);
-      MPI_Allgather(&local_sendcount, 1, MPI_INT, mpi_recvcounts.data(), 1, 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++)
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_allreduce.cpp	(revision 1354)
@@ -38,5 +38,5 @@
     ::MPI_Aint datasize, lb;
 
-    ::MPI_Type_get_extent(static_cast< ::MPI_Datatype>(datatype), &lb, &datasize);
+    ::MPI_Type_get_extent(to_mpi_type(datatype), &lb, &datasize);
 
     bool is_master = ep_rank_loc==0;
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_alltoall.cpp	(revision 1354)
@@ -19,5 +19,5 @@
 
     ::MPI_Aint datasize, llb;
-    ::MPI_Type_get_extent(static_cast< ::MPI_Datatype>(sendtype), &llb, &datasize);
+    ::MPI_Type_get_extent(to_mpi_type(sendtype), &llb, &datasize);
 
     int count = sendcount;
@@ -34,6 +34,4 @@
 
     MPI_Gather(sendbuf, count*ep_size, sendtype, tmp_recvbuf, count*ep_size, recvtype, 0, comm);
-
-    
     
     // reorder tmp_buf
@@ -46,6 +44,4 @@
       for(int j=0; j<ep_size; j++)
       {
-        //printf("tmp_recv[%d] = tmp_send[%d]\n", i*ep_size*count + j*count, j*ep_size*count + i*count);
-
         memcpy(tmp_sendbuf + j*ep_size*count*datasize + i*count*datasize, tmp_recvbuf + i*ep_size*count*datasize + j*count*datasize, count*datasize);
       }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_barrier.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 namespace ep_lib
@@ -18,5 +19,5 @@
       if(ep_rank_loc == 0)
       {
-        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
+        ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
 
         ::MPI_Barrier(mpi_comm);
@@ -27,7 +28,7 @@
       return 0;
     }
-    else if(comm.mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
+    else if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
     {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
       ::MPI_Barrier(mpi_comm);
       return 0;
@@ -47,5 +48,5 @@
     if(ep_rank_loc == 0)
     {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.ep_comm_ptr->intercomm->mpi_inter_comm);
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
       ::MPI_Barrier(mpi_comm);
     }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_bcast.cpp	(revision 1354)
@@ -31,7 +31,5 @@
     }
 
-//    #pragma omp flush
     MPI_Barrier_local(comm);
-//    #pragma omp flush
 
     if(ep_rank_loc != local_root)
@@ -50,5 +48,5 @@
     {
       #pragma omp single nowait
-      ::MPI_Bcast(buffer, count, static_cast< ::MPI_Datatype>(datatype), root, static_cast< ::MPI_Comm>(comm.mpi_comm));
+      ::MPI_Bcast(buffer, count, to_mpi_type(datatype), root, to_mpi_comm(comm.mpi_comm));
       return 0;
     }
@@ -62,5 +60,4 @@
     int root_ep_rank_loc = comm.rank_map->at(root).first;
 
-    // printf("root_mpi_rank = %d\n", root_mpi_rank);    
 
     if((ep_rank_loc==0 && mpi_rank != root_mpi_rank ) || ep_rank == root)
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1354)
@@ -9,8 +9,7 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
-
-
 
 namespace ep_lib {
@@ -26,15 +25,169 @@
     \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)
+  // #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)
   {
+
     int base_rank;
     int base_size;
-
-    ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);
+    
+    ::MPI_Comm mpi_base_comm = to_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
+                    // parent_comm can also be endpoints communicators
 
     std::vector<int> recv_num_ep(base_size);
@@ -52,5 +205,5 @@
     }
 
-    ::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);
+    ::MPI_Allgather(&num_ep, 1, to_mpi_type(MPI_INT), &recv_num_ep[0], 1, to_mpi_type(MPI_INT), mpi_base_comm);
 
 
@@ -61,5 +214,4 @@
 
     out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-
     out_comm_hdls[0].my_buffer = new BUFFER;
 
@@ -97,164 +249,8 @@
     }
 
-
-
     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(MPI_Comm base_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
-  {
-
-    int base_rank;
-    int base_size;
-    
-    assert(!base_comm.is_ep);
-
-    ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm.mpi_comm);
-
-    ::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.mpi_comm;
-      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
-
 
 } //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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_declaration.cpp	(revision 1354)
@@ -99,6 +99,6 @@
 ep_lib::MPI_Op MPI_MIN = MPI_MIN_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::MPI_Comm MPI_COMM_WORLD(&MPI_COMM_WORLD_STD);
+ep_lib::MPI_Comm MPI_COMM_NULL(&MPI_COMM_NULL_STD);
 
 ep_lib::MPI_Request MPI_REQUEST_NULL(MPI_REQUEST_NULL_STD);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_dup.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 namespace ep_lib
@@ -14,9 +15,9 @@
       newcomm->is_ep = comm.is_ep;
 
-      ::MPI_Comm input = static_cast< ::MPI_Comm>(comm.mpi_comm);
-      ::MPI_Comm output;
+      ::MPI_Comm input = to_mpi_comm(comm.mpi_comm);
+      ::MPI_Comm *output = new ::MPI_Comm;
 
       
-      ::MPI_Comm_dup(input, &output);
+      ::MPI_Comm_dup(input, output);
 
       newcomm->mpi_comm = output;
@@ -28,5 +29,5 @@
 
     // for intracomm
-    if(comm.mpi_comm == static_cast< ::MPI_Comm >(MPI_COMM_NULL.mpi_comm)) return 0;
+    if(comm.mpi_comm == static_cast< ::MPI_Comm* >(MPI_COMM_NULL.mpi_comm)) return 0;
 
 
@@ -39,9 +40,9 @@
       MPI_Info info;
       MPI_Comm *out_comm;
-      ::MPI_Comm mpi_dup;
+      ::MPI_Comm *mpi_dup = new ::MPI_Comm;
 
-      ::MPI_Comm in_comm = static_cast< ::MPI_Comm>(comm.mpi_comm);
+      ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm);
 
-      ::MPI_Comm_dup(in_comm, &mpi_dup);
+      ::MPI_Comm_dup(in_comm, mpi_dup);
 
       MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
@@ -59,5 +60,5 @@
   {
     
-    if(comm.mpi_comm == static_cast< ::MPI_Comm >(MPI_COMM_NULL.mpi_comm)) return 0;
+    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;
@@ -69,15 +70,15 @@
       MPI_Info info;
       MPI_Comm *out_comm;
-      ::MPI_Comm mpi_dup;
+      ::MPI_Comm *mpi_dup = new ::MPI_Comm;
 
-      ::MPI_Comm in_comm = static_cast< ::MPI_Comm>(comm.mpi_comm);
+      ::MPI_Comm in_comm = to_mpi_comm(comm.mpi_comm);
 
-      ::MPI_Comm_dup(in_comm, &mpi_dup);
+      ::MPI_Comm_dup(in_comm, mpi_dup);
 
       MPI_Comm_create_endpoints(mpi_dup, num_ep, info, out_comm);
 
-      ::MPI_Comm mpi_inter;
+      ::MPI_Comm *mpi_inter = new ::MPI_Comm;
 
-      ::MPI_Comm_dup(static_cast< ::MPI_Comm>(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_inter);
+      ::MPI_Comm_dup(to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), mpi_inter);
       
       for(int i=0; i<num_ep; i++)
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_finalize.cpp	(revision 1354)
@@ -2,5 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
-
+#include "ep_mpi.hpp"
 
 namespace ep_lib
@@ -26,5 +26,5 @@
     if(id == 0)
     {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.mpi_comm);
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
       ::MPI_Abort(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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_fortran.cpp	(revision 1354)
@@ -5,8 +5,9 @@
 #include <utility>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
-#ifdef _openmpi
-//#undef MPI_Fint
-#endif
+// #ifdef _openmpi
+// //#undef MPI_Fint
+// #endif
 
 namespace ep_lib
@@ -18,7 +19,7 @@
     int fint;
     #ifdef _intelmpi
-    fint = (::MPI_Fint)(comm.mpi_comm);
+    fint = (::MPI_Fint)(to_mpi_comm(comm.mpi_comm));
     #elif _openmpi
-    fint = ::MPI_Comm_c2f(static_cast< ::MPI_Comm>(comm.mpi_comm));
+    fint = ::MPI_Comm_c2f(to_mpi_comm(comm.mpi_comm));
     #endif
     
@@ -62,8 +63,9 @@
     ::MPI_Comm base_comm = ::MPI_Comm_f2c(comm);
     #elif _intelmpi
-    ::MPI_Comm base_comm = (::MPI_Comm)(comm);
+    ::MPI_Comm *base_comm = new ::MPI_Comm;
+    *base_comm = (::MPI_Comm)(comm);
     #endif
 
-    if(base_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
+    if(base_comm != static_cast< ::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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_free.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 namespace ep_lib
@@ -11,7 +12,7 @@
     if(! comm->is_ep)
     {
-      if(comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
+      if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
       {
-        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
+        ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
 
         ::MPI_Comm_free(&mpi_comm);
@@ -68,8 +69,8 @@
         }
 
-        if(  comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm) 
-          && comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_WORLD.mpi_comm))
+        if(  comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm) 
+          && comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_WORLD.mpi_comm))
         {
-          ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
+          ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
           ::MPI_Comm_free(&mpi_comm);
           Debug("mpi_comm freed\n");
@@ -134,7 +135,7 @@
       }
 
-      if(comm->mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
+      if(comm->mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
       {
-        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm->mpi_comm);
+        ::MPI_Comm mpi_comm = to_mpi_comm(comm->mpi_comm);
         ::MPI_Comm_free(&mpi_comm);
         Debug("mpi_comm freed\n");
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_gatherv.cpp	(revision 1354)
@@ -26,6 +26,4 @@
     int num_ep = comm.ep_comm_ptr->size_rank_info[1].second;
 
-    //if(ep_rank_loc == local_root) printf("local_gatherv : recvcounts = %d %d\n\n", recvcounts[0], recvcounts[1]);
-    //if(ep_rank_loc == local_root) printf("local_gatherv : displs = %d %d\n\n", displs[0], displs[1]);
 
     #pragma omp critical (_gatherv)
@@ -50,7 +48,6 @@
     if(!comm.is_ep)
     {
-      ::MPI_Gatherv(const_cast<void*>(sendbuf), sendcount, static_cast< ::MPI_Datatype>(sendtype), recvbuf, const_cast<int*>(input_recvcounts), const_cast<int*>(input_displs),
-                    static_cast< ::MPI_Datatype>(recvtype), root, static_cast< ::MPI_Comm>(comm.mpi_comm));
-      return 0;
+      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));
     }
 
@@ -114,5 +111,4 @@
     else                          MPI_Gatherv_local(sendbuf, sendcount, sendtype, local_recvbuf, local_recvcounts.data(), local_displs.data(), 0, comm);
 
-    //if(is_master) 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]);
 
     void* tmp_recvbuf;
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -39,19 +40,16 @@
       MPI_Comm_rank(peer_comm, &leader_ranks[2]);
 
-      //printf("leader_ranks = %d, %d, %d\n", leader_ranks[0], leader_ranks[1], leader_ranks[2]);
       MPI_Request request[2];
       MPI_Status status[2];
 
-      MPI_Isend(&leader_ranks[0], 3, static_cast< ::MPI_Datatype>(MPI_INT), remote_leader, tag, peer_comm, &request[0]);
-      MPI_Irecv(&leader_ranks[3], 3, static_cast< ::MPI_Datatype>(MPI_INT), remote_leader, tag, peer_comm, &request[1]);
+      MPI_Isend(&leader_ranks[0], 3, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
+      MPI_Irecv(&leader_ranks[3], 3, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
 
       MPI_Waitall(2, request, status);
 
-      //MPI_Send(&leader_ranks[0], 3, static_cast< ::MPI_Datatype>(MPI_INT), remote_leader, tag, peer_comm);
-      //MPI_Recv(&leader_ranks[3], 3, static_cast< ::MPI_Datatype>(MPI_INT), remote_leader, tag, peer_comm, &status[1]);
     }
 
 
-    MPI_Bcast(leader_ranks, 6, static_cast< ::MPI_Datatype>(MPI_INT), local_leader, local_comm);
+    MPI_Bcast(leader_ranks, 6, MPI_INT, local_leader, local_comm);
 
     
@@ -132,6 +130,6 @@
             new_tag_in_world = TAG++;
           }
-          MPI_Bcast(&new_tag_in_world, 1, static_cast< ::MPI_Datatype> (MPI_INT), new_local_leader, local_comm);
-          if(ep_rank == local_leader) MPI_Send(&new_tag_in_world, 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm);
+          MPI_Bcast(&new_tag_in_world, 1, MPI_INT, new_local_leader, local_comm);
+          if(ep_rank == local_leader) MPI_Send(&new_tag_in_world, 1, MPI_INT, remote_leader, tag, peer_comm);
         }
         else
@@ -140,7 +138,7 @@
           {
             MPI_Status status;
-            MPI_Recv(&new_tag_in_world, 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &status);
-          }
-          MPI_Bcast(&new_tag_in_world, 1, static_cast< ::MPI_Datatype> (MPI_INT), new_local_leader, local_comm);
+            MPI_Recv(&new_tag_in_world, 1, MPI_INT, remote_leader, tag, peer_comm, &status);
+          }
+          MPI_Bcast(&new_tag_in_world, 1, MPI_INT, new_local_leader, local_comm);
         }
 
@@ -148,8 +146,8 @@
         if(ep_rank == new_local_leader)
         {
-          ::MPI_Comm_rank(static_cast< ::MPI_Comm >(MPI_COMM_WORLD.mpi_comm), &leader_in_world[0]);
-        }
-
-        MPI_Bcast(&leader_in_world[0], 1, static_cast< ::MPI_Datatype> (MPI_INT), new_local_leader, local_comm);
+          ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &leader_in_world[0]);
+        }
+
+        MPI_Bcast(&leader_in_world[0], 1, MPI_INT, new_local_leader, local_comm);
 
 
@@ -159,6 +157,6 @@
           MPI_Status status[2];
 
-          MPI_Isend(&leader_in_world[0], 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &request[0]);
-          MPI_Irecv(&leader_in_world[1], 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &request[1]);
+          MPI_Isend(&leader_in_world[0], 1, MPI_INT, remote_leader, tag, peer_comm, &request[0]);
+          MPI_Irecv(&leader_in_world[1], 1, MPI_INT, remote_leader, tag, peer_comm, &request[1]);
 
           MPI_Waitall(2, request, status);
@@ -171,5 +169,5 @@
         if(ep_rank == local_leader) Debug("calling MPI_Intercomm_create_from_world\n");
 
-        return MPI_Intercomm_create_from_world(local_comm, new_local_leader, static_cast< ::MPI_Comm >(MPI_COMM_WORLD.mpi_comm), leader_in_world[1], new_tag_in_world, newintercomm);
+        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);
         
       }
@@ -190,7 +188,7 @@
       return 0;
     } 
-    else if(comm.mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
-    {
-      ::MPI_Comm mpi_comm = static_cast< ::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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_kernel.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -32,9 +33,9 @@
 
 
-    ::MPI_Comm local_mpi_comm = static_cast< ::MPI_Comm>(local_comm.mpi_comm);
+    ::MPI_Comm local_mpi_comm = to_mpi_comm(local_comm.mpi_comm);
 
     
-    ::MPI_Comm_rank(static_cast< ::MPI_Comm>(MPI_COMM_WORLD.mpi_comm), &rank_in_world);
-    ::MPI_Comm_rank(static_cast< ::MPI_Comm>(local_comm.mpi_comm), &rank_in_local_parent);
+    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &rank_in_world);
+    ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent);
     
 
@@ -79,5 +80,5 @@
       send_buf[2] = num_ep;
 
-      ::MPI_Allgather(send_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), recv_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), local_mpi_comm);
+      ::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++)
@@ -93,7 +94,5 @@
         leader_info[1] = remote_leader;
 
-        ::MPI_Comm_rank(static_cast< ::MPI_Comm>(peer_comm.mpi_comm), &rank_in_peer_mpi[0]);
-
-        
+        ::MPI_Comm_rank(to_mpi_comm(peer_comm.mpi_comm), &rank_in_peer_mpi[0]);
 
         send_buf[0] = size_info[0];
@@ -106,6 +105,6 @@
         MPI_Status statuses[2];
         
-        MPI_Isend(send_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &requests[0]);
-        MPI_Irecv(recv_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &requests[1]);
+        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]);
 
 
@@ -126,5 +125,5 @@
       send_buf[4] = rank_in_peer_mpi[1];
 
-      ::MPI_Bcast(send_buf.data(), 5, static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::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];
@@ -152,11 +151,11 @@
         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], static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+1, peer_comm, &requests[0]);
-        MPI_Irecv(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+1, peer_comm, &requests[1]);
+        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], static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::MPI_Bcast(recv_buf.data(), 3*size_info[1], 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() );
@@ -276,11 +275,11 @@
         MPI_Request requests[2];
         MPI_Status statuses[2];
-        MPI_Isend(&size_info[2], 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+2, peer_comm, &requests[0]);
-        MPI_Irecv(&size_info[3], 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+2, peer_comm, &requests[1]);
+        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, static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+      ::MPI_Bcast(&size_info[2], 2, MPI_INT, local_comm.rank_map->at(local_leader).second, local_mpi_comm);
 
       new_rank_info[2].resize(size_info[3]);
@@ -300,11 +299,11 @@
         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], static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+3, peer_comm, &requests[0]);
-        MPI_Irecv(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+3, peer_comm, &requests[1]);
+        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], static_cast< ::MPI_Datatype> (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.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() );
@@ -322,6 +321,6 @@
       ::MPI_Group local_group;
       ::MPI_Group new_group;
-      ::MPI_Comm new_comm;
-      ::MPI_Comm intercomm;
+      ::MPI_Comm *new_comm = new ::MPI_Comm;
+      ::MPI_Comm *intercomm = new ::MPI_Comm;
 
       ::MPI_Comm_group(local_mpi_comm, &local_group);
@@ -329,5 +328,5 @@
       ::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);
+      ::MPI_Comm_create(local_mpi_comm, new_group, new_comm);
 
 
@@ -335,19 +334,19 @@
       if(is_local_leader)
       {
-        ::MPI_Comm_rank(new_comm, &leader_info[2]);
-      }
-
-      ::MPI_Bcast(&leader_info[2], 1, static_cast< ::MPI_Datatype> (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], static_cast< ::MPI_Comm>(peer_comm.mpi_comm), rank_in_peer_mpi[1], tag, &intercomm);
+        ::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);
+        ::MPI_Comm_rank(*new_comm, &id);
         int my_num_ep = new_ep_info[0][id];
 
@@ -380,5 +379,5 @@
     }
 
-    MPI_Bcast(bcast_buf.data(), 8, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm);
 
     if(!is_local_leader)
@@ -405,5 +404,5 @@
     }
 
-    MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    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)
@@ -478,5 +477,5 @@
     intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second;
 
-    MPI_Bcast(&remote_ep_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm);
 
     int my_rank_map_elem[2];
@@ -492,6 +491,6 @@
     (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->resize(local_ep_size);
 
-    MPI_Allgather(my_rank_map_elem, 2, static_cast< ::MPI_Datatype> (MPI_INT), 
-      (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), local_comm);
+    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;
@@ -514,9 +513,9 @@
       MPI_Status statuses[4];
       
-      MPI_Isend((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+4, peer_comm, &requests[1]);
-
-      MPI_Isend(&local_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+5, peer_comm, &requests[2]);
-      MPI_Irecv(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+5, peer_comm, &requests[3]);
+      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);
@@ -525,9 +524,9 @@
     }
 
-    MPI_Allreduce(&new_bcast_root_0, &new_bcast_root, 1, static_cast< ::MPI_Datatype> (MPI_INT), static_cast< ::MPI_Op>(MPI_SUM), *newintercomm);
-
-
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
-    MPI_Bcast(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), new_bcast_root, *newintercomm);
+    MPI_Allreduce(&new_bcast_root_0, &new_bcast_root, 1, MPI_INT, static_cast< ::MPI_Op>(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);
 
 
@@ -543,11 +542,11 @@
       MPI_Status statuses[2];
       
-      MPI_Isend((*newintercomm).rank_map->data(), 2*local_intercomm_size, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag+6, peer_comm, &requests[1]);
+      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, static_cast< ::MPI_Datatype> (MPI_INT), new_bcast_root, *newintercomm);
+    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]);
@@ -610,5 +609,5 @@
     int rank_in_peer_mpi[2];
 
-    ::MPI_Comm_rank(static_cast< ::MPI_Comm >(MPI_COMM_WORLD.mpi_comm), &rank_in_world);
+    ::MPI_Comm_rank(to_mpi_comm(MPI_COMM_WORLD.mpi_comm), &rank_in_world);
 
 
@@ -639,6 +638,6 @@
       MPI_Request req_s, req_r;
 
-      MPI_Isend(send_buf.data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &req_s);
-      MPI_Irecv(recv_buf.data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &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);
 
 
@@ -650,5 +649,5 @@
     }
 
-    MPI_Bcast(recv_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    MPI_Bcast(recv_buf.data(), 3, MPI_INT, local_leader, local_comm);
 
     remote_num_ep = recv_buf[0];
@@ -665,7 +664,7 @@
       if(ep_rank == local_leader)
       {
-        ::MPI_Comm mpi_dup;
+        ::MPI_Comm *mpi_dup = new ::MPI_Comm;
         
-        ::MPI_Comm_dup(static_cast< ::MPI_Comm>(local_comm.mpi_comm), &mpi_dup);
+        ::MPI_Comm_dup(to_mpi_comm(local_comm.mpi_comm), mpi_dup);
 
         MPI_Comm *ep_intercomm;
@@ -691,5 +690,5 @@
         MPI_Request req_s;
         MPI_Status sta_s;
-        MPI_Isend(tag_label, 2, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &req_s);
+        MPI_Isend(tag_label, 2, MPI_INT, remote_leader, tag, peer_comm, &req_s);
 
         MPI_Wait(&req_s, &sta_s);
@@ -705,10 +704,10 @@
         MPI_Status status;
         MPI_Request req_r;
-        MPI_Irecv(tag_label, 2, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &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, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    MPI_Bcast(tag_label, 2, MPI_INT, local_leader, local_comm);
 
 
@@ -776,6 +775,6 @@
     local_rank_map_ele[1] = (*newintercomm).ep_comm_ptr->comm_label;
 
-    MPI_Allgather(local_rank_map_ele, 2, static_cast< ::MPI_Datatype> (MPI_INT), 
-      (*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), local_comm);
+    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)
@@ -784,6 +783,6 @@
       MPI_Request req_s, req_r;
 
-      MPI_Isend((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_num_ep, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &req_s);
-      MPI_Irecv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, static_cast< ::MPI_Datatype> (MPI_INT), remote_leader, tag, peer_comm, &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);
 
 
@@ -793,5 +792,5 @@
     }
 
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_num_ep, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    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;
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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_intercomm_world.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -8,9 +9,535 @@
 {
 
-  #ifdef _openmpi
-
+  // #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)
   {
-
     int ep_rank, ep_rank_loc, mpi_rank;
     int ep_size, num_ep, mpi_size;
@@ -23,5 +550,4 @@
     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
@@ -33,10 +559,10 @@
     int remote_ep_size;
 
-    ::MPI_Comm peer_comm = static_cast< ::MPI_Comm>(peer_comm_ptr);
-    ::MPI_Comm local_mpi_comm = static_cast< ::MPI_Comm>(local_comm.mpi_comm);
+    ::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(static_cast< ::MPI_Comm>(local_comm.mpi_comm), &rank_in_local_parent);
+    ::MPI_Comm_rank(local_mpi_comm, &rank_in_local_parent);
 
     bool is_proc_master = false;
@@ -69,6 +595,4 @@
       rank_info[1].resize(size_info[0]);
 
-
-
       ep_info[0].resize(size_info[0]);
 
@@ -80,5 +604,5 @@
       send_buf[2] = num_ep;
 
-      ::MPI_Allgather(send_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), recv_buf.data(), 3, static_cast< ::MPI_Datatype> (MPI_INT), local_mpi_comm);
+      ::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++)
@@ -89,4 +613,5 @@
       }
 
+
       if(is_local_leader)
       {
@@ -99,7 +624,7 @@
         send_buf[1] = local_ep_size;
 
-        ::MPI_Send(send_buf.data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 2, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
+        ::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;
@@ -108,5 +633,5 @@
       }
 
-      ::MPI_Bcast(recv_buf.data(), 4, static_cast< ::MPI_Datatype> (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.rank_map->at(local_leader).second, local_mpi_comm);
 
       size_info[1] = recv_buf[0];
@@ -132,11 +657,11 @@
         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], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-      }
-
-      ::MPI_Bcast(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+        ::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() );
@@ -259,10 +784,10 @@
         ::MPI_Status mpi_status;
 
-        ::MPI_Send(&size_info[2], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(&size_info[3], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-      }
-
-      ::MPI_Bcast(&size_info[2], 2, static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+        ::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]);
@@ -281,10 +806,10 @@
         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], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-        ::MPI_Recv(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-      }
-
-      ::MPI_Bcast(recv_buf.data(),   3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), local_comm.rank_map->at(local_leader).second, local_mpi_comm);
+        ::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() );
@@ -302,6 +827,6 @@
       ::MPI_Group local_group;
       ::MPI_Group new_group;
-      ::MPI_Comm new_comm;
-      ::MPI_Comm intercomm;
+      ::MPI_Comm *new_comm = new ::MPI_Comm;
+      ::MPI_Comm *intercomm = new ::MPI_Comm;
 
       ::MPI_Comm_group(local_mpi_comm, &local_group);
@@ -309,5 +834,5 @@
       ::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);
+      ::MPI_Comm_create(local_mpi_comm, new_group, new_comm);
 
 
@@ -315,17 +840,17 @@
       if(is_local_leader)
       {
-        ::MPI_Comm_rank(new_comm, &leader_info[2]);
-      }
-
-      ::MPI_Bcast(&leader_info[2], 1, static_cast< ::MPI_Datatype> (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);
+        ::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);
+        ::MPI_Comm_rank(*new_comm, &id);
         int my_num_ep = new_ep_info[0][id];
 
@@ -333,6 +858,4 @@
         MPI_Info info;
         MPI_Comm_create_endpoints(new_comm, my_num_ep, info, ep_intercomm);
-
-
 
         for(int i= 0; i<my_num_ep; i++)
@@ -345,13 +868,14 @@
         }
 
+
         #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);
@@ -362,5 +886,8 @@
     }
 
-    MPI_Bcast(bcast_buf.data(), 8, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+
+
+    MPI_Bcast(bcast_buf.data(), 8, MPI_INT, local_leader, local_comm);
+
 
     if(!is_local_leader)
@@ -369,4 +896,6 @@
       std::copy(bcast_buf.begin()+4, bcast_buf.begin()+8, leader_info);
     }
+
+
 
     if(!is_local_leader)
@@ -387,5 +916,6 @@
     }
 
-    MPI_Bcast(bcast_buf.data(), size_info[2]+size_info[1]+size_info[0]+1, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+    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)
@@ -399,8 +929,4 @@
 
     int my_position = offset[rank_in_local_parent]+ep_rank_loc;
-
-
-    MPI_Barrier_local(local_comm);
-    #pragma omp flush
 
 
@@ -417,5 +943,4 @@
 
             found = true;
-            //tag_list.erase(iter);
             break;
           }
@@ -432,7 +957,7 @@
       ::MPI_Status mpi_status;
       
-      ::MPI_Send(&local_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv(&remote_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm, &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);
     }
 
@@ -450,6 +975,4 @@
       }
     }
-
-    
 
     int intercomm_ep_rank, intercomm_ep_rank_loc, intercomm_mpi_rank;
@@ -463,528 +986,6 @@
     intercomm_mpi_size = newintercomm->ep_comm_ptr->size_rank_info[2].second;
 
-    MPI_Bcast(&remote_ep_size, 1, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-
-      ::MPI_Send(&local_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-    }
-
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
-    MPI_Bcast(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-    }
-
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (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, int 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 = static_cast< ::MPI_Comm>(peer_comm_ptr);
-    ::MPI_Comm local_mpi_comm = static_cast< ::MPI_Comm>(local_comm.mpi_comm);
-
-    ::MPI_Comm_rank(peer_comm, &rank_in_world);
-
-    ::MPI_Comm_rank(static_cast< ::MPI_Comm>(local_comm.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, static_cast< ::MPI_Datatype> (MPI_INT), recv_buf.data(), 3, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 2, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (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], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-
-      }
-
-      ::MPI_Bcast(recv_buf.data(), 3*size_info[1], static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(&size_info[3], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-      }
-
-      ::MPI_Bcast(&size_info[2], 2, static_cast< ::MPI_Datatype> (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], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-        ::MPI_Recv(recv_buf.data(), 3*size_info[3], static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &mpi_status);
-      }
-
-      ::MPI_Bcast(recv_buf.data(),   3*size_info[3], static_cast< ::MPI_Datatype> (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;
-      ::MPI_Comm intercomm;
-
-      ::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, static_cast< ::MPI_Datatype> (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));
-        
-
-      }
-
-
-    }
-
-
-    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, static_cast< ::MPI_Datatype> (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, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
-
-
-    if(!is_local_leader)
-    {
-      remote_ep_size = bcast_buf[0];
-      std::copy(bcast_buf.data()+1, bcast_buf.data()+1+size_info[2], new_rank_info[1].begin());
-      std::copy(bcast_buf.data()+1+size_info[2], bcast_buf.data()+1+size_info[2]+size_info[1], ep_info[1].begin());
-      std::copy(bcast_buf.data()+1+size_info[2]+size_info[1], bcast_buf.data()+1+size_info[2]+size_info[1]+size_info[0], offset.begin());
-    }
-
-
-    int my_position = offset[rank_in_local_parent]+ep_rank_loc;
-
-
-    #pragma omp critical (read_from_tag_list)
-    {
-      bool found = false;
-      while(!found)
-      {
-        for(std::list<std::pair < std::pair<int,int>, MPI_Comm* > >::iterator iter = tag_list.begin(); iter!=tag_list.end(); iter++)
-        {
-          if((*iter).first == make_pair(tag, min(leader_info[0], leader_info[1])))
-          {
-            *newintercomm =  iter->second[my_position];
-
-            found = true;
-            break;
-          }
-        }
-      }
-    }
-
-    MPI_Barrier(local_comm);
-
-    if(is_local_leader)
-    {
-      int local_flag = true;
-      int remote_flag = false;
-      ::MPI_Status mpi_status;
-      
-      ::MPI_Send(&local_flag, 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv(&remote_flag, 1, static_cast< ::MPI_Datatype>(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, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
+
+    MPI_Bcast(&remote_ep_size, 1, MPI_INT, local_leader, local_comm);
 
     int my_rank_map_elem[2];
@@ -1015,15 +1016,15 @@
       ::MPI_Status status;
 
-      ::MPI_Send((*newintercomm).ep_comm_ptr->intercomm->local_rank_map->data(), 2*local_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-
-      ::MPI_Send(&local_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-    }
-
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->remote_rank_map->data(), 2*remote_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), local_leader, local_comm);
-    MPI_Bcast(&remote_intercomm_size, 1, static_cast< ::MPI_Datatype> (MPI_INT), 0, *newintercomm);
+      ::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);
 
 
@@ -1040,10 +1041,10 @@
       ::MPI_Status status;
 
-      ::MPI_Send((*newintercomm).rank_map->data(), 2*local_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm);
-
-      ::MPI_Recv((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), mpi_remote_leader, tag, peer_comm, &status);
-    }
-
-    MPI_Bcast((*newintercomm).ep_comm_ptr->intercomm->intercomm_rank_map->data(), 2*remote_intercomm_size, static_cast< ::MPI_Datatype> (MPI_INT), 0, *newintercomm);
+      ::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]);
@@ -1054,5 +1055,5 @@
   }
 
-  #endif
+  // #endif
 
 }
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.cpp	(revision 1354)
@@ -246,7 +246,7 @@
 }
 
-MPI_Comm to_mpi_comm(int comm)
+MPI_Comm to_mpi_comm(void* comm)
 {
-  return static_cast< MPI_Comm >(comm);
+  return *(static_cast< MPI_Comm* >(comm));
 }  
 
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib.hpp	(revision 1354)
@@ -43,11 +43,11 @@
   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
+  // #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(MPI_Comm base_comm, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls); // from EP to create endpoints
+  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_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm);
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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_lib_intercomm.hpp	(revision 1354)
@@ -35,9 +35,11 @@
   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
+  // #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);
-  #endif
   
   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);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_merge.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -84,5 +85,5 @@
     if(intra_ep_rank_loc == 0)
     {
-      ::MPI_Bcast(reorder, intra_ep_size, static_cast< ::MPI_Datatype> (MPI_INT), 0, static_cast< ::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);
@@ -142,5 +143,5 @@
 
 
-    ::MPI_Comm mpi_intracomm;
+    ::MPI_Comm *mpi_intracomm = new ::MPI_Comm;
     MPI_Comm *ep_intracomm;
 
@@ -148,7 +149,7 @@
     {
 
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(inter_comm.ep_comm_ptr->intercomm->mpi_inter_comm);
-
-      ::MPI_Intercomm_merge(mpi_comm, high, &mpi_intracomm);
+      ::MPI_Comm mpi_comm = to_mpi_comm(inter_comm.ep_comm_ptr->intercomm->mpi_inter_comm);
+
+      ::MPI_Intercomm_merge(mpi_comm, high, mpi_intracomm);
       MPI_Info info;
       MPI_Comm_create_endpoints(mpi_intracomm, num_ep, info, ep_intracomm);
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_mpi.hpp	(revision 1354)
@@ -6,5 +6,5 @@
 MPI_Datatype to_mpi_type(ep_lib::MPI_Datatype type);
 MPI_Op       to_mpi_op(ep_lib::MPI_Op op);
-MPI_Comm     to_mpi_comm(int comm);
+MPI_Comm     to_mpi_comm(void* comm);
 
 #endif // EP_MPI_HPP_INCLUDED
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_rank.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 namespace ep_lib
@@ -30,5 +31,5 @@
     if(comm != MPI_COMM_NULL)
     {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm);
       ::MPI_Comm_rank(mpi_comm, rank);
       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 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_size.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 namespace ep_lib
@@ -31,7 +32,7 @@
     Debug("Calling EP_Comm_size\n");
 
-    if(comm.mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
+    if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
     {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm); 
+      ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
       int mpi_size;
 
@@ -54,7 +55,7 @@
     if(!comm.is_ep)
     {
-      if(comm.mpi_comm != static_cast< ::MPI_Comm>(MPI_COMM_NULL.mpi_comm))
+      if(comm.mpi_comm != static_cast< ::MPI_Comm*>(MPI_COMM_NULL.mpi_comm))
       {
-        ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm); 
+        ::MPI_Comm mpi_comm = to_mpi_comm(comm.mpi_comm); 
         ::MPI_Comm_remote_size(mpi_comm, size);
         return 0;
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_split.cpp	(revision 1354)
@@ -2,4 +2,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 using namespace std;
@@ -134,5 +135,8 @@
     }
 
-    ::MPI_Comm split_mpi_comm[num_color];
+    ::MPI_Comm **split_mpi_comm;
+    split_mpi_comm = new ::MPI_Comm* [num_color];
+    for(int ii=0; ii<num_color; ii++)
+      split_mpi_comm[ii] = new ::MPI_Comm;
 
     for(int j=0; j<num_color; j++)
@@ -143,5 +147,5 @@
         if(matched_number_loc[j] == 0) master_color = MPI_UNDEFINED;
 
-        ::MPI_Comm_split(static_cast< ::MPI_Comm>(comm.mpi_comm), master_color, mpi_rank, &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->mpi_bridge = split_mpi_comm[j];
Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp	(revision 1347)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_type.hpp	(revision 1354)
@@ -153,9 +153,11 @@
 
 
-    #ifdef _intelmpi
-    int mpi_inter_comm;
-    #elif _openmpi
+    // #ifdef _intelmpi
+    // int mpi_inter_comm;
+    // #elif _openmpi
+    // void * mpi_inter_comm;
+    // #endif
+
     void * mpi_inter_comm;
-    #endif
 
     RANK_MAP *intercomm_rank_map;
@@ -258,9 +260,11 @@
     public:
 
-    #ifdef _intelmpi
-    int mpi_comm;
-    #elif _openmpi
+    // #ifdef _intelmpi
+    // int mpi_comm;
+    // #elif _openmpi
+    // void * mpi_comm;
+    // #endif
+
     void * mpi_comm;
-    #endif
 
     bool is_ep;
@@ -276,9 +280,11 @@
 
 
-    #ifdef _intelmpi
-    int mpi_bridge;
-    #elif _openmpi
+    // #ifdef _intelmpi
+    // int mpi_bridge;
+    // #elif _openmpi
+    // void * mpi_bridge;
+    // #endif
+
     void * mpi_bridge;
-    #endif
 
     MPI_Comm()
@@ -294,6 +300,35 @@
     }
 
-    #ifdef _intelmpi
-    MPI_Comm(int comm)
+    // #ifdef _intelmpi
+    // MPI_Comm(int 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 = comm;
+    // }
+
+    // #elif _openmpi
+
+    // 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 = comm;
+    // }
+    // #endif
+    
+    MPI_Comm(void* comm)
     {
       is_ep = false;
@@ -308,21 +343,4 @@
     }
 
-    #elif _openmpi
-
-    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 = comm;
-    }
-    #endif
-
-
     bool operator == (MPI_Comm right)
     {
