Index: XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp
===================================================================
--- XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp	(revision 1500)
+++ XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp	(revision 1503)
@@ -19,22 +19,11 @@
 namespace ep_lib 
 {
-  
 
   int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
   {
 
-    if(!comm->is_ep)
-    {
-      ::MPI_Status mpi_status;
-      ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), &mpi_status);
-
-      status->ep_src = src;
-      status->ep_tag = tag;
-      status->ep_datatype = datatype;
-
-      return 0;  
-    }
-
-    //Message_Check(comm);
+    if(!comm->is_ep) return MPI_Recv_mpi(buf, count, datatype, src, tag, comm, status);
+    
+    Debug("MPI_Recv with EP");
 
     MPI_Request request;
@@ -45,31 +34,20 @@
   }
 
-
+  
 
 
   int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
   {
-
+    if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request);
+    
     Debug("MPI_Irecv with EP");
     int dest_rank;
     MPI_Comm_rank(comm, &dest_rank);
     
-
-    if(!comm->is_ep)
-    {
-      ::MPI_Request mpi_request;
-      ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), &mpi_request);
-
-      (*request)->mpi_request = new ::MPI_Request(mpi_request);
-      (*request)->ep_src = src;
-      (*request)->ep_datatype = datatype;
-      (*request)->ep_tag = tag;
-    }
-    
-    *request = new ep_request;
-    printf("new %p : in ep_lib::MPI_Irecv, *request = new ep_request\n", (*request));
+    *request = new ep_request;   
+    memcheck("new " << *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request");
 
     (*request)->mpi_request = new ::MPI_Request;
-    printf("new %p : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request\n", (*request)->mpi_request);
+    memcheck("new " << (*request)->mpi_request << " : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request");
     
     (*request)->buf = buf;
@@ -82,56 +60,91 @@
     (*request)->ep_tag = tag;
     (*request)->ep_datatype = datatype;
-    
-    
-    /* With Improbe*/
+  
+    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >;
 
-    if(EP_PendingRequests == 0 ) 
-    {
-      EP_PendingRequests = new std::list< MPI_Request* >;
-    }
-
-    EP_PendingRequests->push_back(request);                                                                
+    EP_PendingRequests->push_back(request);  
+    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
+    memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());                                                              
                                           
-    Request_Check();
-
-    return 0;
+    return Request_Check();
   }
-
-  int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request)
-  {
-    Debug("MPI_Imrecv");
-
-    (*request)->type = 3;
-	
-    ::MPI_Imrecv(buf, count, to_mpi_type(datatype), to_mpi_message_ptr(*message), to_mpi_request_ptr(*request));		
-
-    (*request)->ep_datatype = datatype;
-    (*request)->ep_tag = (*message)->ep_tag;
-    (*request)->ep_src = (*message)->ep_src;
-    
-    
-    return 0;
-  }
-
-
+  
   int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status)
   {
-    Debug("EP Mrecv called\n");
+    Debug("MPI_Mrecv with MPI/EP");
 
-    ::MPI_Status mpi_status;
-    ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >((*message)->mpi_message), &mpi_status);
+    status->mpi_status = new ::MPI_Status;
+    memcheck("new " << status->mpi_status << " : in ep_lib::MPI_Mrecv, status->mpi_status = new ::MPI_Status");
+    
+    ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >((*message)->mpi_message), to_mpi_status_ptr(*status));
 
-    status->mpi_status = new ::MPI_Status(mpi_status);
+    
     status->ep_src = (*message)->ep_src;
     status->ep_datatype = datatype;
     status->ep_tag = (*message)->ep_tag;
 
+    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Mrecv, delete (*message)->mpi_message");
     delete (*message)->mpi_message;
 
-    //check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
+#ifdef _check_sum
+    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
+#endif
 
-    return 0;
+    return Request_Check();
   }
 
+
+  int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request)
+  {
+    Debug("MPI_Imrecv with MPI/EP");
+
+    (*request)->type = 3;
+    (*request)->ep_datatype = datatype;
+    (*request)->ep_tag = (*message)->ep_tag;
+    (*request)->ep_src = (*message)->ep_src;
+	
+    ::MPI_Imrecv(buf, count, to_mpi_type(datatype), to_mpi_message_ptr(*message), to_mpi_request_ptr(*request));		
+    
+    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Imrecv, delete (*message)->mpi_message");
+    delete (*message)->mpi_message;
+
+#ifdef _check_sum
+    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
+#endif
+
+    
+    return Request_Check();
+  }
+
+
+   int MPI_Recv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
+  {
+    Debug("MPI_Recv with MPI");
+    status->ep_src = src;
+    status->ep_tag = tag;
+    status->ep_datatype = datatype;
+    
+    return ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_status_ptr(*status)); 
+  }
+  
+  int MPI_Irecv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
+  {
+    Debug("MPI_Irecv with MPI");
+    int dest_rank;
+    MPI_Comm_rank(comm, &dest_rank);
+    
+    *request = new ep_request;
+    memcheck("new "<< *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request");
+
+    (*request)->mpi_request = new ::MPI_Request;
+    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request");
+      
+    (*request)->ep_src = src;
+    (*request)->ep_datatype = datatype;
+    (*request)->type = 2;
+    (*request)->ep_tag = tag;
+    
+    return ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
+  }
 }
 
