From 05235cab14333e478e8719a57ba7b89fc0d30139 Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Mon, 26 Mar 2018 15:37:09 +0200 Subject: [PATCH] [SMPI] Replay: Classify the actions, start with Wait --- examples/smpi/replay/replay.tesh | 1 + src/smpi/internals/smpi_replay.cpp | 99 +++++++++++++++++++++--------- 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/examples/smpi/replay/replay.tesh b/examples/smpi/replay/replay.tesh index 8569f164d5..22103b0ed8 100644 --- a/examples/smpi/replay/replay.tesh +++ b/examples/smpi/replay/replay.tesh @@ -263,6 +263,7 @@ $ ../../smpi_script/bin/smpirun -ext smpi_replay --log=replay.thresh:critical -- > [Fafard:2:(3) 29.490406] [smpi_replay/VERBOSE] 2 compute 2.5e8 3.276712 > [Fafard:2:(3) 29.490606] [smpi_replay/VERBOSE] 2 test 0.000200 > [Fafard:2:(3) 32.767318] [smpi_replay/VERBOSE] 2 compute 2.5e8 3.276712 +> [Fafard:2:(3) 32.767318] [smpi_replay/VERBOSE] 2 wait 0.000000 > [Fafard:2:(3) 32.767318] [smpi_replay/VERBOSE] 2 Isend 0 1e6 0.000000 > [Tremblay:0:(1) 32.923014] [smpi_replay/VERBOSE] 0 recv 2 1e6 12.367458 > [Fafard:2:(3) 39.320741] [smpi_replay/VERBOSE] 2 compute 5e8 6.553424 diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 95b3e80b87..8067fd4cd3 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -65,6 +65,76 @@ static double parse_double(std::string string) namespace simgrid { namespace smpi { +namespace Replay { +class ActionArgParser { +public: + virtual void parse(simgrid::xbt::ReplayAction& action){}; +}; + +template class ReplayAction { + protected: + const std::string name; + T args; + + /* + * Used to compute the duration of this action. + */ + double start_time; + + int my_proc_id; + +public: + explicit ReplayAction(std::string name) + : name(name), start_time(smpi_process()->simulated_elapsed()), my_proc_id(simgrid::s4u::Actor::self()->getPid()) + { + } + + virtual void execute(simgrid::xbt::ReplayAction& action) + { + args.parse(action); + kernel(action); + log_timed_action(action, start_time); + } + + virtual void kernel(simgrid::xbt::ReplayAction& action) = 0; +}; + +class WaitAction : public ReplayAction { +public: + WaitAction() : ReplayAction("Wait") {} + void kernel(simgrid::xbt::ReplayAction& action) override + { + CHECK_ACTION_PARAMS(action, 0, 0) + MPI_Status status; + + std::string s = boost::algorithm::join(action, " "); + xbt_assert(get_reqq_self()->size(), "action wait not preceded by any irecv or isend: %s", s.c_str()); + MPI_Request request = get_reqq_self()->back(); + get_reqq_self()->pop_back(); + + if (request == nullptr) { + /* Assume that the trace is well formed, meaning the comm might have been caught by a MPI_test. Then just + * return.*/ + return; + } + + int rank = request->comm() != MPI_COMM_NULL ? request->comm()->rank() : -1; + + MPI_Group group = request->comm()->group(); + int src_traced = group->rank(request->src()); + int dst_traced = group->rank(request->dst()); + bool is_wait_for_receive = (request->flags() & RECV); + // TODO: Here we take the rank while we normally take the process id (look for my_proc_id) + TRACE_smpi_comm_in(rank, __FUNCTION__, new simgrid::instr::NoOpTIData("wait")); + + Request::wait(&request, &status); + + TRACE_smpi_comm_out(rank); + if (is_wait_for_receive) + TRACE_smpi_recv(src_traced, dst_traced, 0); + } +}; + static void action_init(simgrid::xbt::ReplayAction& action) { XBT_DEBUG("Initialize the counters"); @@ -253,34 +323,7 @@ static void action_test(simgrid::xbt::ReplayAction& action) static void action_wait(simgrid::xbt::ReplayAction& action) { - CHECK_ACTION_PARAMS(action, 0, 0) - double clock = smpi_process()->simulated_elapsed(); - MPI_Status status; - - std::string s = boost::algorithm::join(action, " "); - xbt_assert(get_reqq_self()->size(), "action wait not preceded by any irecv or isend: %s", s.c_str()); - MPI_Request request = get_reqq_self()->back(); - get_reqq_self()->pop_back(); - - if (request==nullptr){ - /* Assume that the trace is well formed, meaning the comm might have been caught by a MPI_test. Then just return.*/ - return; - } - - int rank = request->comm() != MPI_COMM_NULL ? request->comm()->rank() : -1; - - MPI_Group group = request->comm()->group(); - int src_traced = group->rank(request->src()); - int dst_traced = group->rank(request->dst()); - int is_wait_for_receive = (request->flags() & RECV); - TRACE_smpi_comm_in(rank, __FUNCTION__, new simgrid::instr::NoOpTIData("wait")); - - Request::wait(&request, &status); - - TRACE_smpi_comm_out(rank); - if (is_wait_for_receive) - TRACE_smpi_recv(src_traced, dst_traced, 0); - log_timed_action (action, clock); + Replay::WaitAction().execute(action); } static void action_waitall(simgrid::xbt::ReplayAction& action) -- 2.20.1