Index: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp	(revision 1289)
+++ XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp	(revision 1295)
@@ -9,4 +9,5 @@
 #include <mpi.h>
 #include "ep_declaration.hpp"
+#include "ep_mpi.hpp"
 
 
@@ -17,9 +18,5 @@
   {
     if(!comm.is_ep)
-    {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Send(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm);
-      return 0;
-    }
+      return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm));
 
     MPI_Request request;
@@ -38,7 +35,5 @@
     if(!comm.is_ep)
     {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Ssend(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm);
-      return 0;
+      return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm));
     }
 
@@ -51,23 +46,5 @@
   }
   
-  int MPI_Bsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
-  {
-    if(!comm.is_ep)
-    {
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Bsend(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm);
-      return 0;
-    }
-
-    MPI_Request request;
-    MPI_Status status;
-    //MPI_Ibsend(buf, count, datatype, dest, tag, comm, &request);
-    MPI_Wait(&request, &status);
-
-    //check_sum_send(buf, count, datatype, dest, tag, comm);
-
-    return 0;
-  }
- 
+
 
 
@@ -84,6 +61,5 @@
     {
       ::MPI_Request mpi_request;
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
+      ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
 
       request->mpi_request = mpi_request;
@@ -104,8 +80,8 @@
     //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
 
-    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
+    int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
     int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
-    int mpi_tag 		= tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest 	= comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
 
     request->ep_src  = src_rank;
@@ -113,11 +89,10 @@
     request->ep_datatype = datatype;
 
-    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
     ::MPI_Request mpi_request;
 
-    ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
+    ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
 
     request->mpi_request = mpi_request;
-    request->type = 1; 		// used in wait
+    request->type = 1;    // used in wait
     request->comm = comm;
     request->buf = const_cast<void*>(buf);
@@ -143,6 +118,5 @@
     {
       ::MPI_Request mpi_request;
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
+      ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
 
       request->mpi_request = mpi_request;
@@ -162,8 +136,8 @@
     //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
 
-    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
+    int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
     int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
-    int mpi_tag 		= tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest 	= comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
+    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
+    int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
     
     request->ep_src = src_rank;
@@ -171,11 +145,10 @@
     request->ep_datatype = datatype;
 
-    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
     ::MPI_Request mpi_request;
 
-    ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
+    ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
 
     request->mpi_request = mpi_request;
-    request->type = 1; 		// used in wait
+    request->type = 1;    // used in wait
     request->comm = comm;
     request->buf = NULL;
@@ -187,58 +160,4 @@
   }
   
-  int MPI_Ibsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
-  {
-    Debug("\nMPI_Isend with EP\n");
-    int src_rank;
-    MPI_Comm_rank(comm, &src_rank);
-
-  
-
-    if(!comm.is_ep)
-    {
-      ::MPI_Request mpi_request;
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Ibsend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-
-      request->ep_src = src_rank;
-      request->ep_tag = tag;
-      request->ep_datatype = datatype;
-      request->type = 1;
-      request->comm = comm;
-
-      return 0;
-    }
-
-    if(comm.is_intercomm) return 0;//MPI_Ibsend_intercomm(buf, count, datatype, dest, tag, comm, request);
-
-   // EP intracomm
-
-    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
-
-    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
-    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
-    int mpi_tag 		= tag_combine(tag, ep_src_loc, ep_dest_loc);
-    int mpi_dest 	= comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
-
-    request->ep_src  = src_rank;
-    request->ep_tag  = tag;
-    request->ep_datatype = datatype;
-
-    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
-    ::MPI_Request mpi_request;
-
-    ::MPI_Ibsend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-    request->mpi_request = mpi_request;
-    request->type = 1; 		// used in wait
-    request->comm = comm;
-    request->buf = const_cast<void*>(buf);
-
-    //Message_Check(comm);
-
-    return 0;  
-  }
 
 
@@ -256,12 +175,8 @@
     int src_comm_label;
 
-    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
-    {
-      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
-      {
-        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
-        break;
-      }
-    }
+    src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second;
+
+
+    
 
     //Message_Check(comm);
@@ -276,11 +191,10 @@
       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
 
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Request mpi_request;
-  
-      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-      request->type = 1; 		// used in wait
+      ::MPI_Request mpi_request;
+  
+      ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
+
+      request->mpi_request = mpi_request;
+      request->type = 1;    // used in wait
       request->comm = comm;
 
@@ -298,11 +212,10 @@
       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
 
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
-      ::MPI_Request mpi_request;
-
-      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-      request->type = 1; 		// used in wait
+      ::MPI_Request mpi_request;
+
+      ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request);
+
+      request->mpi_request = mpi_request;
+      request->type = 1;    // used in wait
       request->comm = comm;
    
@@ -349,11 +262,10 @@
       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
 
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Request mpi_request;
-  
-      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-      request->type = 1; 		// used in wait
+      ::MPI_Request mpi_request;
+  
+      ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
+
+      request->mpi_request = mpi_request;
+      request->type = 1;    // used in wait
       request->comm = comm;
 
@@ -371,11 +283,10 @@
       int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
 
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
-      ::MPI_Request mpi_request;
-
-      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-      request->type = 1; 		// used in wait
+      ::MPI_Request mpi_request;
+
+      ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request);
+
+      request->mpi_request = mpi_request;
+      request->type = 1;    // used in wait
       request->comm = comm;
    
@@ -389,75 +300,4 @@
   }
   
-  int MPI_Ibsend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
-  {
-    printf("MPI_Ibsend with intercomm not yet implemented\n");
-    MPI_Abort(comm, 0);
-    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
-
-    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
-    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
-
-    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
-    int src_comm_label;
-
-    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
-    {
-      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
-      {
-        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
-        break;
-      }
-    }
-
-    //Message_Check(comm);
-
-
-    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
-    {
-      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm.rank_map->at(inter_src).first;
-      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
-      ::MPI_Request mpi_request;
-  
-      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-      request->type = 1; 		// used in wait
-      request->comm = comm;
-
-      request->ep_src = src_ep_rank;
-      request->ep_tag = tag;
-      request->ep_datatype = datatype;
-    }
-
-    else   // dest_remote_comm_label != src_comm_label
-    { 
-      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
-      int ep_src_loc = comm.rank_map->at(inter_src).first;
-      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
-      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
-      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
-
-      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
-      ::MPI_Request mpi_request;
-
-      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
-
-      request->mpi_request = mpi_request;
-      request->type = 1; 		// used in wait
-      request->comm = comm;
-   
-      request->ep_src = src_ep_rank;
-      request->ep_tag = tag;
-      request->ep_datatype = datatype;
-    }
-
-    return 0;
-
-  }
 }
 
