Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp	(revision 1512)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp	(revision 1515)
@@ -147,5 +147,5 @@
   int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
   {
-    Debug("\nMPI_Send with EP_Intercomm\n");
+    Debug("\nMPI_Send_intercomm with EP\n");
     MPI_Request request;
     MPI_Status status;
@@ -165,5 +165,5 @@
   int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
   {
-    Debug("\nMPI_Ssend with EP_Intercomm\n");
+    Debug("\nMPI_Ssend_intercomm with EP\n");
     MPI_Request request;
     MPI_Status status;
@@ -181,8 +181,8 @@
     
     *request = new ep_request;
-    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend, *request = new ep_request");
-
-    (*request)->mpi_request = new ::MPI_Request;
-    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend, (*request)->mpi_request = new ::MPI_Request");
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_mpi, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_mpi, (*request)->mpi_request = new ::MPI_Request");
       
     (*request)->ep_src = src_rank;
@@ -197,67 +197,59 @@
   int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
-    Debug("MPI_Isend with EP_Intercomm\n");
-
-#ifdef _check_sum    
-    check_sum_send(buf, count, datatype, dest, tag, comm);
-#endif
-
-    int dest_remote_ep_rank    = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
-    int dest_remote_comm_label = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
-
-    int src_ep_rank    = comm->ep_comm_ptr->intercomm->size_rank_info[0].first;
-    int src_comm_label;
-
-    src_comm_label = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second;
-    //Message_Check(comm);
-
-    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
+    Debug("\nMPI_Isend_intercomm with EP\n");
+
+#ifdef _check_sum    
+    check_sum_send(buf, count, datatype, dest, tag, comm);
+#endif
+
+    int src_comm_label  = comm->ep_comm_ptr->comm_label;
+    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second;
+    
+    int src_rank;
+    MPI_Comm_rank(comm, &src_rank);
+
+    
+    *request = new ep_request;
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_intercomm, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_intercomm, (*request)->mpi_request = new ::MPI_Request");
+    
+
+    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first;
+    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first;
+
+#ifdef _showinfo
+    printf("ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag);
+#endif
+    
+
+    (*request)->ep_src  = src_rank;
+    (*request)->ep_tag  = tag;
+    (*request)->ep_datatype = datatype;
+
+    (*request)->type = 1;    // used in wait
+    (*request)->comm = comm;
+    (*request)->buf = const_cast<void*>(buf);
+
+
+    if(src_comm_label == dest_comm_label)
     {
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *request = new ep_request;
-      memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_intercomm, *request = new ep_request");
-
-      (*request)->mpi_request = new ::MPI_Request;
-      memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_intercomm, (*request)->mpi_request = new ::MPI_Request");
-      
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-
+      Debug("\nMPI_Isend_intercomm with EP_intracomm\n");
       return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
-
     }
 
-    else   // dest_remote_comm_label != src_comm_label
-    { 
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *request = new ep_request;
-      memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_intercomm, *request = new ep_request");
-
-      (*request)->mpi_request = new ::MPI_Request;
-      memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_intercomm, (*request)->mpi_request = new ::MPI_Request");
-
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-      
-      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request)); 
+    else
+    {
+      Debug("\nMPI_Isend_intercomm with EP_intercomm\n");
+      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request));
     }
   }
 
+
+
+
   int MPI_Issend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
@@ -268,8 +260,8 @@
     
     *request = new ep_request;
-    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend, *request = new ep_request");
-
-    (*request)->mpi_request = new ::MPI_Request;
-    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend, (*request)->mpi_request = new ::MPI_Request");
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_mpi, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_mpi, (*request)->mpi_request = new ::MPI_Request");
       
     (*request)->ep_src = src_rank;
@@ -285,64 +277,52 @@
   int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
   {
-    Debug("MPI_Issend with EP_Intercomm\n");
-
-#ifdef _check_sum    
-    check_sum_send(buf, count, datatype, dest, tag, comm);
-#endif
-
-    int dest_remote_ep_rank    = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
-    int dest_remote_comm_label = comm->ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
-
-    int src_ep_rank    = comm->ep_comm_ptr->intercomm->size_rank_info[0].first;
-    int src_comm_label;
-
-    src_comm_label = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second;
-    //Message_Check(comm);
-
-    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
+    Debug("\nMPI_Issend_intercomm with EP\n");
+
+#ifdef _check_sum    
+    check_sum_send(buf, count, datatype, dest, tag, comm);
+#endif
+
+    int src_comm_label  = comm->ep_comm_ptr->comm_label;
+    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second;
+    
+    int src_rank;
+    MPI_Comm_rank(comm, &src_rank);
+
+    
+    *request = new ep_request;
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_intercomm, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_intercomm, (*request)->mpi_request = new ::MPI_Request");
+    
+
+    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first;
+    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first;
+
+#ifdef _showinfo
+    printf("ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag);
+#endif
+    
+    (*request)->ep_src  = src_rank;
+    (*request)->ep_tag  = tag;
+    (*request)->ep_datatype = datatype;
+
+    (*request)->type = 1;    // used in wait
+    (*request)->comm = comm;
+    (*request)->buf = const_cast<void*>(buf);
+
+
+    if(src_comm_label == dest_comm_label)
     {
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *request = new ep_request;
-      memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_intercomm, *request = new ep_request");
-
-      (*request)->mpi_request = new ::MPI_Request;
-      memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_intercomm, (*request)->mpi_request = new ::MPI_Request");
-      
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-
+      Debug("\nMPI_Issend_intercomm with EP_intracomm\n");
       return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
-
     }
 
-    else   // dest_remote_comm_label != src_comm_label
-    { 
-      int inter_src = comm->ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm->ep_rank_map->at(inter_src).first;
-      int ep_dest_loc = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm->ep_comm_ptr->intercomm->inter_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      *request = new ep_request;
-      memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_intercomm, *request = new ep_request");
-
-      (*request)->mpi_request = new ::MPI_Request;
-      memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_intercomm, (*request)->mpi_request = new ::MPI_Request");
-
-      (*request)->type = 1;    // used in wait
-      (*request)->comm = comm;
-      (*request)->ep_src = src_ep_rank;
-      (*request)->ep_tag = tag;
-      (*request)->ep_datatype = datatype;
-      
-      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request)); 
+    else
+    {
+      Debug("\nMPI_Issend_intercomm with EP_intercomm\n");
+      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request));
     }
   }
