Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] PMPI_Waitany/all: Move redundant code to helper function
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Mon, 15 Jan 2018 13:43:42 +0000 (14:43 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Mon, 15 Jan 2018 16:15:36 +0000 (17:15 +0100)
src/smpi/bindings/smpi_pmpi_request.cpp

index 970e3f1..df9097b 100644 (file)
@@ -586,6 +586,22 @@ int PMPI_Wait(MPI_Request * request, MPI_Status * status)
   return retval;
 }
 
+// TODO: cheinrich: Move declaration to other file? Rename function - they're used for PMPI_Wait*?
+static void trace_smpi_recv_helper(MPI_Request req, MPI_Status* status);
+static void trace_smpi_recv_helper(MPI_Request req, MPI_Status* status)
+{
+  if (req != MPI_REQUEST_NULL) { // Received requests become null
+    int src_traced = req->src();
+    // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
+    int dst_traced = req->dst();
+    if (req->flags() & RECV) { // Is this request a wait for RECV?
+      if (src_traced == MPI_ANY_SOURCE)
+        src_traced = (status != MPI_STATUSES_IGNORE) ? req->comm()->group()->rank(status->MPI_SOURCE) : req->src();
+      TRACE_smpi_recv(src_traced, dst_traced, req->tag());
+    }
+  }
+}
+
 int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * status)
 {
   if (index == nullptr)
@@ -602,18 +618,7 @@ int PMPI_Waitany(int count, MPI_Request requests[], int *index, MPI_Status * sta
   *index = simgrid::smpi::Request::waitany(count, requests, status);
 
   if(*index!=MPI_UNDEFINED){
-    MPI_Request req = requests[*index];
-    if (req != MPI_REQUEST_NULL) { // Received requests become null
-      int src_traced = req->src();
-      // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
-      int dst_traced          = req->dst();
-      if (req->flags() & RECV) {
-        if (src_traced == MPI_ANY_SOURCE)
-          src_traced = (status != MPI_STATUSES_IGNORE) ? req->comm()->group()->rank(status->MPI_SOURCE) : req->src();
-        TRACE_smpi_recv(src_traced, dst_traced, req->tag());
-      }
-    }
-    TRACE_smpi_comm_out(rank_traced);
+    trace_smpi_recv_helper(requests[*index], status);
   }
 
   smpi_bench_begin();
@@ -630,17 +635,7 @@ int PMPI_Waitall(int count, MPI_Request requests[], MPI_Status status[])
   int retval = simgrid::smpi::Request::waitall(count, requests, status);
 
   for (int i = 0; i < count; i++) {
-    MPI_Request req = requests[i];
-    if (req != MPI_REQUEST_NULL) {
-      // the src may not have been known at the beginning of the recv (MPI_ANY_SOURCE)
-      int src_traced = req->src();
-      int dst_traced = req->dst();
-      if ((req->flags() & RECV)) {
-        if(src_traced==MPI_ANY_SOURCE)
-          src_traced = (status != MPI_STATUSES_IGNORE) ? req->comm()->group()->rank(status[i].MPI_SOURCE) : req->src();
-        TRACE_smpi_recv(src_traced, dst_traced, req->tag());
-      }
-    }
+    trace_smpi_recv_helper(requests[i], &status[i]);
   }
   TRACE_smpi_comm_out(rank_traced);