From 491bcca47bc2deaf174ff8941f35065e0b2f5e50 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Mon, 15 Jan 2018 14:43:42 +0100 Subject: [PATCH] [SMPI] PMPI_Waitany/all: Move redundant code to helper function --- src/smpi/bindings/smpi_pmpi_request.cpp | 41 +++++++++++-------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/smpi/bindings/smpi_pmpi_request.cpp b/src/smpi/bindings/smpi_pmpi_request.cpp index 970e3f1767..df9097b510 100644 --- a/src/smpi/bindings/smpi_pmpi_request.cpp +++ b/src/smpi/bindings/smpi_pmpi_request.cpp @@ -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); -- 2.20.1