Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1356)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_create.cpp	(revision 1520)
@@ -25,157 +25,4 @@
     \param [out] out_comm_hdls Handles of EP communicators.
   */
-  // #ifdef _intelmpi
-  // int MPI_Comm_create_endpoints(int base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
-  // {
-  //   int base_rank;
-  //   int base_size;
-
-  //   ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);
-
-  //   ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size
-  //   ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank
-		// 							  // parent_comm can also be endpoints communicators
-
-  //   std::vector<int> recv_num_ep(base_size);
-
-  //   out_comm_hdls = new MPI_Comm[num_ep];
-
-  //   for (int idx = 0; idx < num_ep; ++idx)
-  //   {
-  //     out_comm_hdls[idx].is_ep = true;
-  //     out_comm_hdls[idx].is_intercomm = false;
-  //     out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;
-  //     out_comm_hdls[idx].mpi_comm = base_comm_ptr;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;
-  //   }
-
-  //   ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype>(MPI_INT), &recv_num_ep[0], 1, static_cast< ::MPI_Datatype>(MPI_INT), mpi_base_comm);
-
-
-  //   int sum = 0;  // representing total ep number of process with smaller rank
-  //   for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }
-
-  //   int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
-
-  //   out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-
-  //   out_comm_hdls[0].my_buffer = new BUFFER;
-
-  //   out_comm_hdls[0].rank_map = new RANK_MAP;
-  //   out_comm_hdls[0].rank_map->resize(ep_size);
-
-
-  //   for (int i = 1; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;
-  //     out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer;
-  //     out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map;
-  //   }
-
-
-  //   for (int i = 0; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
-
-  //     out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;
-  //   }
-
-
-  //   int ind = 0;
-
-  //   for(int i=0; i<base_size; i++)
-  //   {
-  //     for(int j=0; j<recv_num_ep[i]; j++)
-  //     {
-  //       out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);
-  //       ind++;
-  //     }
-  //   }
-
-
-
-  //   return 0;
-
-  // } //MPI_Comm_create_endpoints
-
-  // #elif _openmpi
-  // int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
-  // {
-
-  //   int base_rank;
-  //   int base_size;
-
-  //   ::MPI_Comm mpi_base_comm = static_cast< ::MPI_Comm> (base_comm_ptr);
-
-  //   ::MPI_Comm_size(mpi_base_comm, &base_size);  // ep_lib::mpi_comm_size
-  //   ::MPI_Comm_rank(mpi_base_comm, &base_rank);  // ep_lib::mpi_comm_rank
-  //                                                // parent_comm can also be endpoints communicators ?
-  //   std::vector<int> recv_num_ep(base_size);
-
-  //   out_comm_hdls = new MPI_Comm[num_ep];
-
-  //   for (int idx = 0; idx < num_ep; ++idx)
-  //   {
-  //     out_comm_hdls[idx].is_ep = true;
-  //     out_comm_hdls[idx].is_intercomm = false;
-  //     out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;
-  //     out_comm_hdls[idx].mpi_comm = base_comm_ptr;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;
-  //     out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;
-  //   }
-
-  //   ::MPI_Allgather(&num_ep, 1, static_cast< ::MPI_Datatype> (MPI_INT), 
-  //                  &recv_num_ep[0], 1, static_cast< ::MPI_Datatype> (MPI_INT), mpi_base_comm);
-
-  //   int sum = 0;  // representing total ep number of process with smaller rank
-  //   for (int i = 0; i < base_rank; ++i) {sum += recv_num_ep[i]; }
-
-  //   int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
-
-  //   out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-  //   out_comm_hdls[0].my_buffer = new BUFFER;
-
-  //   out_comm_hdls[0].rank_map = new RANK_MAP;
-  //   out_comm_hdls[0].rank_map->resize(ep_size);
-
-
-  //   for (int i = 1; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;
-  //     out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer;
-  //     out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map;
-  //   }
-
-
-  //   for (int i = 0; i < num_ep; i++)
-  //   {
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
-  //     out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
-
-  //     out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;
-  //   }
-
-
-  //   int ind = 0;
-
-  //   for(int i=0; i<base_size; i++)
-  //   {
-  //     for(int j=0; j<recv_num_ep[i]; j++)
-  //     {
-  //       out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);
-  //       ind++;
-  //     }
-  //   }
-
-  //   return 0;
-
-  // } //MPI_Comm_create_endpoints
-
-  // #endif
-  
   
   int MPI_Comm_create_endpoints(void* base_comm_ptr, int num_ep, MPI_Info info, MPI_Comm *& out_comm_hdls)
@@ -194,13 +41,35 @@
 
     out_comm_hdls = new MPI_Comm[num_ep];
+#ifdef _showinfo
+    printf("new out_comm_hdls = %p\n", out_comm_hdls);
+#endif
 
+    ::MPI_Comm *parent_comm = new ::MPI_Comm;
+    ::MPI_Comm_dup(to_mpi_comm(base_comm_ptr), parent_comm);
+
+#ifdef _showinfo
+    printf("new out_comm_hdls->mpi_comm = %p\n", parent_comm);
+#endif
+    
     for (int idx = 0; idx < num_ep; ++idx)
     {
-      out_comm_hdls[idx].is_ep = true;
-      out_comm_hdls[idx].is_intercomm = false;
-      out_comm_hdls[idx].ep_comm_ptr = new ep_communicator;     
-      *(static_cast< ::MPI_Comm*>(out_comm_hdls[idx].mpi_comm)) = *(static_cast< ::MPI_Comm*>(base_comm_ptr));
-      out_comm_hdls[idx].ep_comm_ptr->comm_list = out_comm_hdls;
-      out_comm_hdls[idx].ep_comm_ptr->comm_label = 0;
+
+      out_comm_hdls[idx] = new ep_comm;
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d] = %p\n", idx, out_comm_hdls[idx]);
+#endif
+
+      out_comm_hdls[idx]->is_ep = true;
+      out_comm_hdls[idx]->is_intercomm = false;
+      
+      out_comm_hdls[idx]->ep_comm_ptr = new ep_communicator;     
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d]->ep_comm_ptr = %p\n", idx, out_comm_hdls[idx]->ep_comm_ptr);
+#endif
+
+
+      out_comm_hdls[idx]->mpi_comm = parent_comm;
+      out_comm_hdls[idx]->ep_comm_ptr->comm_list = out_comm_hdls;
+      out_comm_hdls[idx]->ep_comm_ptr->comm_label = 0;
     }
 
@@ -213,16 +82,24 @@
     int ep_size = std::accumulate(recv_num_ep.begin(), recv_num_ep.end(), 0);
 
-    out_comm_hdls[0].ep_barrier = new OMPbarrier(num_ep);
-    out_comm_hdls[0].my_buffer = new BUFFER;
+    out_comm_hdls[0]->ep_barrier = new ep_barrier(num_ep);
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->ep_barrier = %p\n", out_comm_hdls[0]->ep_barrier);
+#endif
 
-    out_comm_hdls[0].rank_map = new RANK_MAP;
-    out_comm_hdls[0].rank_map->resize(ep_size);
+    out_comm_hdls[0]->my_buffer = new BUFFER;
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->my_buffer = %p\n", out_comm_hdls[0]->my_buffer);
+#endif
 
+    out_comm_hdls[0]->ep_rank_map = new EP_RANK_MAP;
+#ifdef _showinfo
+    printf("new out_comm_hdls[0]->ep_rank_map = %p\n", out_comm_hdls[0]->ep_rank_map);
+#endif
 
     for (int i = 1; i < num_ep; i++)
     {
-      out_comm_hdls[i].ep_barrier = out_comm_hdls[0].ep_barrier;
-      out_comm_hdls[i].my_buffer  = out_comm_hdls[0].my_buffer;
-      out_comm_hdls[i].rank_map   = out_comm_hdls[0].rank_map;
+      out_comm_hdls[i]->ep_barrier = out_comm_hdls[0]->ep_barrier;
+      out_comm_hdls[i]->my_buffer  = out_comm_hdls[0]->my_buffer;
+      out_comm_hdls[i]->ep_rank_map= out_comm_hdls[0]->ep_rank_map;
     }
 
@@ -230,9 +107,13 @@
     for (int i = 0; i < num_ep; i++)
     {
-      out_comm_hdls[i].ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
-      out_comm_hdls[i].ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
-      out_comm_hdls[i].ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
+      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[0] = std::make_pair(sum+i, ep_size);
+      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[1] = std::make_pair(i, num_ep);
+      out_comm_hdls[i]->ep_comm_ptr->size_rank_info[2] = std::make_pair(base_rank, base_size);
 
-      out_comm_hdls[i].ep_comm_ptr->message_queue = new Message_list;
+      out_comm_hdls[i]->ep_comm_ptr->message_queue = new Message_list;
+#ifdef _showinfo
+      printf("new out_comm_hdls[%d]->ep_comm_ptr->message_queue = %p\n", i, out_comm_hdls[i]->ep_comm_ptr->message_queue);
+#endif
+
     }
 
@@ -244,5 +125,5 @@
       for(int j=0; j<recv_num_ep[i]; j++)
       {
-        out_comm_hdls[0].rank_map->at(ind) = make_pair(j, i);
+        out_comm_hdls[0]->ep_rank_map->insert(std::pair< int, std::pair<int,int> >(ind, j, i));
         ind++;
       }
@@ -253,4 +134,5 @@
   } //MPI_Comm_create_endpoints
 
+  
 
 } //namespace ep_lib
