From: Christian Heinrich Date: Tue, 20 Mar 2018 16:31:30 +0000 (+0100) Subject: [REPLAY] Remove C-based Replay API X-Git-Tag: v3.20~600^2~38 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/684228063a7091913611aba778528e2acb528139 [REPLAY] Remove C-based Replay API This is a huge commit, unfortunately, but it was not possible to split it up easily without breaking the build. This commit changes: - Remove the 'const char* const* action' madness, replace by std::vector (aliased as ReplayAction) - Rename replay.c to replay.cpp - Change CMake files - Rewrite several macros to make them C++ compliant --- diff --git a/examples/s4u/replay-comm/s4u-replay-comm.cpp b/examples/s4u/replay-comm/s4u-replay-comm.cpp index 4c5db1efdc..42c94811c0 100644 --- a/examples/s4u/replay-comm/s4u-replay-comm.cpp +++ b/examples/s4u/replay-comm/s4u-replay-comm.cpp @@ -6,24 +6,23 @@ #include "simgrid/s4u.hpp" #include "xbt/replay.hpp" #include "xbt/str.h" +#include #include XBT_LOG_NEW_DEFAULT_CATEGORY(replay_comm, "Messages specific for this msg example"); #define ACT_DEBUG(...) \ - if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) { \ - char* NAME = xbt_str_join_array(action, " "); \ + if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) { \ + std::string NAME = boost::algorithm::join(action, " "); \ XBT_DEBUG(__VA_ARGS__); \ - xbt_free(NAME); \ } else \ ((void)0) -static void log_action(const char* const* action, double date) +static void log_action(simgrid::xbt::ReplayAction& action, double date) { if (XBT_LOG_ISENABLED(replay_comm, xbt_log_priority_verbose)) { - char* name = xbt_str_join_array(action, " "); - XBT_VERB("%s %f", name, date); - xbt_free(name); + std::string s = boost::algorithm::join(action, " "); + XBT_VERB("%s %f", s.c_str(), date); } } @@ -49,36 +48,37 @@ public: } /* My actions */ - static void compute(const char* const* action) + static void compute(simgrid::xbt::ReplayAction& action) { double amount = std::stod(action[2]); double clock = simgrid::s4u::Engine::getClock(); - ACT_DEBUG("Entering %s", NAME); + ACT_DEBUG("Entering %s", NAME.c_str()); simgrid::s4u::this_actor::execute(amount); log_action(action, simgrid::s4u::Engine::getClock() - clock); } - static void send(const char* const* action) + static void send(simgrid::xbt::ReplayAction& action) { double size = std::stod(action[3]); std::string* payload = new std::string(action[3]); double clock = simgrid::s4u::Engine::getClock(); simgrid::s4u::MailboxPtr to = simgrid::s4u::Mailbox::byName(simgrid::s4u::this_actor::getName() + "_" + action[2]); - ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME, size, - simgrid::s4u::this_actor::getCname(), to->getCname()); + ACT_DEBUG("Entering Send: %s (size: %g) -- Actor %s on mailbox %s", NAME.c_str(), size, + simgrid::s4u::this_actor::getCname(), to->getCname()); to->put(payload, size); delete payload; log_action(action, simgrid::s4u::Engine::getClock() - clock); } - static void recv(const char* const* action) + static void recv(simgrid::xbt::ReplayAction& action) { double clock = simgrid::s4u::Engine::getClock(); simgrid::s4u::MailboxPtr from = simgrid::s4u::Mailbox::byName(std::string(action[2]) + "_" + simgrid::s4u::this_actor::getName()); - ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME, simgrid::s4u::this_actor::getCname(), from->getCname()); + ACT_DEBUG("Receiving: %s -- Actor %s on mailbox %s", NAME.c_str(), simgrid::s4u::this_actor::getCname(), + from->getCname()); from->get(); log_action(action, simgrid::s4u::Engine::getClock() - clock); } diff --git a/examples/s4u/replay-storage/s4u-replay-storage.cpp b/examples/s4u/replay-storage/s4u-replay-storage.cpp index 4300098097..3d69a72462 100644 --- a/examples/s4u/replay-storage/s4u-replay-storage.cpp +++ b/examples/s4u/replay-storage/s4u-replay-storage.cpp @@ -16,18 +16,16 @@ static std::unordered_map opened_files; #define ACT_DEBUG(...) \ if (XBT_LOG_ISENABLED(replay_storage, xbt_log_priority_verbose)) { \ - char* NAME = xbt_str_join_array(action, " "); \ + std::string NAME = boost::algorithm::join(action, " "); \ XBT_DEBUG(__VA_ARGS__); \ - xbt_free(NAME); \ } else \ ((void)0) -static void log_action(const char* const* action, double date) +static void log_action(simgrid::xbt::ReplayAction& action, double date) { if (XBT_LOG_ISENABLED(replay_storage, xbt_log_priority_verbose)) { - char* name = xbt_str_join_array(action, " "); - XBT_VERB("%s %f", name, date); - xbt_free(name); + std::string s = boost::algorithm::join(action, " "); + XBT_VERB("%s %f", s.c_str(), date); } } @@ -60,13 +58,13 @@ public: } /* My actions */ - static void open(const char* const* action) + static void open(simgrid::xbt::ReplayAction& action) { std::string file_name = action[2]; double clock = simgrid::s4u::Engine::getClock(); std::string full_name = simgrid::s4u::this_actor::getName() + ":" + file_name; - ACT_DEBUG("Entering Open: %s (filename: %s)", NAME, file_name.c_str()); + ACT_DEBUG("Entering Open: %s (filename: %s)", NAME.c_str(), file_name.c_str()); simgrid::s4u::File* file = new simgrid::s4u::File(file_name, NULL); opened_files.insert({full_name, file}); @@ -74,7 +72,7 @@ public: log_action(action, simgrid::s4u::Engine::getClock() - clock); } - static void read(const char* const* action) + static void read(simgrid::xbt::ReplayAction& action) { std::string file_name = action[2]; sg_size_t size = std::stoul(action[3]); @@ -82,20 +80,20 @@ public: simgrid::s4u::File* file = get_file_descriptor(file_name); - ACT_DEBUG("Entering Read: %s (size: %llu)", NAME, size); + ACT_DEBUG("Entering Read: %s (size: %llu)", NAME.c_str(), size); file->read(size); log_action(action, simgrid::s4u::Engine::getClock() - clock); } - static void close(const char* const* action) + static void close(simgrid::xbt::ReplayAction& action) { std::string file_name = action[2]; double clock = simgrid::s4u::Engine::getClock(); simgrid::s4u::File* file = get_file_descriptor(file_name); - ACT_DEBUG("Entering Close: %s (filename: %s)", NAME, file_name.c_str()); + ACT_DEBUG("Entering Close: %s (filename: %s)", NAME.c_str(), file_name.c_str()); delete file; log_action(action, simgrid::s4u::Engine::getClock() - clock); diff --git a/examples/smpi/CMakeLists.txt b/examples/smpi/CMakeLists.txt index 2d08813347..9ac0497426 100644 --- a/examples/smpi/CMakeLists.txt +++ b/examples/smpi/CMakeLists.txt @@ -4,7 +4,14 @@ if(enable_smpi) file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/mc/") - foreach(x replay trace trace_simple trace_call_location energy) + foreach(x replay) + add_executable (smpi_${x} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) + target_link_libraries(smpi_${x} simgrid) + set_target_properties(smpi_${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) + set(examples_src ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.cpp) + endforeach() + + foreach(x trace trace_simple trace_call_location energy) add_executable (smpi_${x} ${CMAKE_CURRENT_SOURCE_DIR}/${x}/${x}.c) target_link_libraries(smpi_${x} simgrid) set_target_properties(smpi_${x} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${x}) diff --git a/examples/smpi/replay/replay.c b/examples/smpi/replay/replay.cpp similarity index 89% rename from examples/smpi/replay/replay.c rename to examples/smpi/replay/replay.cpp index fb0e9f9577..2ac6850081 100644 --- a/examples/smpi/replay/replay.c +++ b/examples/smpi/replay/replay.cpp @@ -8,19 +8,20 @@ /* This shows how to extend the trace format by adding a new kind of events. This function is registered through xbt_replay_action_register() below. */ -static void action_blah(const char* const* args) +static void action_blah(simgrid::xbt::ReplayAction& args) { /* Add your answer to the blah event here. args is a strings array containing the blank-separated parameters found in the trace for this event instance. */ } action_fun previous_send; -static void overriding_send(const char* const* args) +static void overriding_send(simgrid::xbt::ReplayAction& args) { (*previous_send)(args); // Just call the overriden symbol. That's a toy example. } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) +{ /* Setup things and register default actions */ smpi_replay_init(&argc, &argv); diff --git a/include/xbt/replay.hpp b/include/xbt/replay.hpp index de1fbc53b2..72f5069068 100644 --- a/include/xbt/replay.hpp +++ b/include/xbt/replay.hpp @@ -10,7 +10,6 @@ #include /* SG_BEGIN_DECL */ -#ifdef __cplusplus #include #include #include @@ -25,14 +24,9 @@ XBT_PUBLIC_DATA std::ifstream* action_fs; XBT_PUBLIC int replay_runner(int argc, char* argv[]); } } -#endif - -SG_BEGIN_DECL() -typedef void (*action_fun)(const char* const* args); +typedef void (*action_fun)(simgrid::xbt::ReplayAction&); XBT_PUBLIC void xbt_replay_action_register(const char* action_name, action_fun function); XBT_PUBLIC action_fun xbt_replay_action_get(const char* action_name); -SG_END_DECL() - #endif diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index 676685c42a..d1602ed2f3 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -12,6 +12,7 @@ #include "smpi_request.hpp" #include "xbt/replay.hpp" +#include #include #include #include @@ -28,25 +29,21 @@ static std::unordered_map*> reqq; static MPI_Datatype MPI_DEFAULT_TYPE; #define CHECK_ACTION_PARAMS(action, mandatory, optional) {\ - int i=0;\ - while(action[i]!=nullptr)\ - i++;\ - if(i(mandatory+2)) \ THROWF(arg_error, 0, "%s replay failed.\n" \ - "%d items were given on the line. First two should be process_id and action. " \ - "This action needs after them %d mandatory arguments, and accepts %d optional ones. \n" \ - "Please contact the Simgrid team if support is needed", __FUNCTION__, i, mandatory, optional);\ + "%lu items were given on the line. First two should be process_id and action. " \ + "This action needs after them %lu mandatory arguments, and accepts %lu optional ones. \n" \ + "Please contact the Simgrid team if support is needed", __FUNCTION__, action.size(), static_cast(mandatory), static_cast(optional));\ } class ReplayActionArg { ReplayActionArg() {} }; -static void log_timed_action (const char *const *action, double clock){ +static void log_timed_action (simgrid::xbt::ReplayAction& action, double clock){ if (XBT_LOG_ISENABLED(smpi_replay, xbt_log_priority_verbose)){ - char *name = xbt_str_join_array(action, " "); - XBT_VERB("%s %f", name, smpi_process()->simulated_elapsed()-clock); - xbt_free(name); + std::string s = boost::algorithm::join(action, " "); + XBT_VERB("%s %f", s.c_str(), smpi_process()->simulated_elapsed()-clock); } } @@ -61,20 +58,16 @@ static void set_reqq_self(std::vector *mpi_request) } /* Helper function */ -static double parse_double(const char *string) +static double parse_double(std::string string) { - char *endptr; - double value = strtod(string, &endptr); - if (*endptr != '\0') - THROWF(unknown_error, 0, "%s is not a double", string); - return value; + return xbt_str_parse_double(string.c_str(), "%s is not a double"); } //TODO: this logic should be moved inside the datatype class, to support all predefined types and get rid of is_replayable. -static MPI_Datatype decode_datatype(const char *const action) +static MPI_Datatype decode_datatype(std::string action) { - return simgrid::smpi::Datatype::decode(action); + return simgrid::smpi::Datatype::decode(const_cast(action.c_str())); } const char* encode_datatype(MPI_Datatype datatype) @@ -88,11 +81,11 @@ const char* encode_datatype(MPI_Datatype datatype) namespace simgrid { namespace smpi { -static void action_init(const char *const *action) +static void action_init(simgrid::xbt::ReplayAction& action) { XBT_DEBUG("Initialize the counters"); CHECK_ACTION_PARAMS(action, 0, 1) - if(action[2]) + if (action.size() > 2) MPI_DEFAULT_TYPE = MPI_DOUBLE; // default MPE datatype else MPI_DEFAULT_TYPE = MPI_BYTE; // default TAU datatype @@ -105,28 +98,28 @@ static void action_init(const char *const *action) set_reqq_self(new std::vector); } -static void action_finalize(const char *const *action) +static void action_finalize(simgrid::xbt::ReplayAction& action) { /* Nothing to do */ } -static void action_comm_size(const char *const *action) +static void action_comm_size(simgrid::xbt::ReplayAction& action) { communicator_size = parse_double(action[2]); log_timed_action (action, smpi_process()->simulated_elapsed()); } -static void action_comm_split(const char *const *action) +static void action_comm_split(simgrid::xbt::ReplayAction& action) { log_timed_action (action, smpi_process()->simulated_elapsed()); } -static void action_comm_dup(const char *const *action) +static void action_comm_dup(simgrid::xbt::ReplayAction& action) { log_timed_action (action, smpi_process()->simulated_elapsed()); } -static void action_compute(const char *const *action) +static void action_compute(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 1, 0) double clock = smpi_process()->simulated_elapsed(); @@ -140,14 +133,14 @@ static void action_compute(const char *const *action) log_timed_action (action, clock); } -static void action_send(const char *const *action) +static void action_send(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 2, 1) int to = std::stoi(action[2]); double size=parse_double(action[3]); double clock = smpi_process()->simulated_elapsed(); - MPI_Datatype MPI_CURRENT_TYPE = (action[4]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 4) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; int my_proc_id = Actor::self()->getPid(); int dst_traced = MPI_COMM_WORLD->group()->actor(to)->getPid(); @@ -164,14 +157,14 @@ static void action_send(const char *const *action) log_timed_action(action, clock); } -static void action_Isend(const char *const *action) +static void action_Isend(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 2, 1) int to = std::stoi(action[2]); double size=parse_double(action[3]); double clock = smpi_process()->simulated_elapsed(); - MPI_Datatype MPI_CURRENT_TYPE = (action[4]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 4) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; int my_proc_id = Actor::self()->getPid(); int dst_traced = MPI_COMM_WORLD->group()->actor(to)->getPid(); @@ -189,14 +182,15 @@ static void action_Isend(const char *const *action) log_timed_action (action, clock); } -static void action_recv(const char *const *action) { +static void action_recv(simgrid::xbt::ReplayAction& action) +{ CHECK_ACTION_PARAMS(action, 2, 1) int from = std::stoi(action[2]); double size=parse_double(action[3]); double clock = smpi_process()->simulated_elapsed(); MPI_Status status; - MPI_Datatype MPI_CURRENT_TYPE = (action[4]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 4) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; int my_proc_id = Actor::self()->getPid(); int src_traced = MPI_COMM_WORLD->group()->actor(from)->getPid(); @@ -220,14 +214,14 @@ static void action_recv(const char *const *action) { log_timed_action (action, clock); } -static void action_Irecv(const char *const *action) +static void action_Irecv(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 2, 1) int from = std::stoi(action[2]); double size=parse_double(action[3]); double clock = smpi_process()->simulated_elapsed(); - MPI_Datatype MPI_CURRENT_TYPE = (action[4]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 4) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; int my_proc_id = Actor::self()->getPid(); TRACE_smpi_comm_in(my_proc_id, __FUNCTION__, @@ -247,7 +241,7 @@ static void action_Irecv(const char *const *action) log_timed_action (action, clock); } -static void action_test(const char* const* action) +static void action_test(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 0, 0) double clock = smpi_process()->simulated_elapsed(); @@ -273,13 +267,14 @@ static void action_test(const char* const* action) log_timed_action (action, clock); } -static void action_wait(const char *const *action){ +static void action_wait(simgrid::xbt::ReplayAction& action) +{ CHECK_ACTION_PARAMS(action, 0, 0) double clock = smpi_process()->simulated_elapsed(); MPI_Status status; - xbt_assert(get_reqq_self()->size(), "action wait not preceded by any irecv or isend: %s", - xbt_str_join_array(action," ")); + 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(); @@ -304,7 +299,8 @@ static void action_wait(const char *const *action){ log_timed_action (action, clock); } -static void action_waitall(const char *const *action){ +static void action_waitall(simgrid::xbt::ReplayAction& action) +{ CHECK_ACTION_PARAMS(action, 0, 0) double clock = smpi_process()->simulated_elapsed(); const unsigned int count_requests = get_reqq_self()->size(); @@ -336,7 +332,8 @@ static void action_waitall(const char *const *action){ log_timed_action (action, clock); } -static void action_barrier(const char *const *action){ +static void action_barrier(simgrid::xbt::ReplayAction& action) +{ double clock = smpi_process()->simulated_elapsed(); int my_proc_id = Actor::self()->getPid(); TRACE_smpi_comm_in(my_proc_id, __FUNCTION__, new simgrid::instr::NoOpTIData("barrier")); @@ -347,14 +344,14 @@ static void action_barrier(const char *const *action){ log_timed_action (action, clock); } -static void action_bcast(const char *const *action) +static void action_bcast(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 1, 2) double size = parse_double(action[2]); double clock = smpi_process()->simulated_elapsed(); - int root = (action[3]) ? std::stoi(action[3]) : 0; + int root = (action.size() > 3) ? std::stoi(action[3]) : 0; /* Initialize MPI_CURRENT_TYPE in order to decrease the number of the checks */ - MPI_Datatype MPI_CURRENT_TYPE = (action[3] && action[4]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 4) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; int my_proc_id = Actor::self()->getPid(); TRACE_smpi_comm_in(my_proc_id, __FUNCTION__, @@ -369,15 +366,15 @@ static void action_bcast(const char *const *action) log_timed_action (action, clock); } -static void action_reduce(const char *const *action) +static void action_reduce(simgrid::xbt::ReplayAction& action) { CHECK_ACTION_PARAMS(action, 2, 2) double comm_size = parse_double(action[2]); double comp_size = parse_double(action[3]); double clock = smpi_process()->simulated_elapsed(); - int root = (action[4]) ? std::stoi(action[4]) : 0; + int root = (action.size() > 4) ? std::stoi(action[4]) : 0; - MPI_Datatype MPI_CURRENT_TYPE = (action[4] && action[5]) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 5) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE; int my_proc_id = Actor::self()->getPid(); TRACE_smpi_comm_in(my_proc_id, __FUNCTION__, @@ -393,12 +390,13 @@ static void action_reduce(const char *const *action) log_timed_action (action, clock); } -static void action_allReduce(const char *const *action) { +static void action_allReduce(simgrid::xbt::ReplayAction& action) +{ CHECK_ACTION_PARAMS(action, 2, 1) double comm_size = parse_double(action[2]); double comp_size = parse_double(action[3]); - MPI_Datatype MPI_CURRENT_TYPE = (action[4]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = (action.size() > 4) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; double clock = smpi_process()->simulated_elapsed(); int my_proc_id = Actor::self()->getPid(); @@ -414,14 +412,15 @@ static void action_allReduce(const char *const *action) { log_timed_action (action, clock); } -static void action_allToAll(const char *const *action) { +static void action_allToAll(simgrid::xbt::ReplayAction& action) +{ CHECK_ACTION_PARAMS(action, 2, 2) //two mandatory (send and recv volumes) and two optional (corresponding datatypes) double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); int send_size = parse_double(action[2]); int recv_size = parse_double(action[3]); - MPI_Datatype MPI_CURRENT_TYPE = (action[4] && action[5]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{(action[4] && action[5]) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE{(action.size() > 5) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 5) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE}; void *send = smpi_get_tmp_sendbuffer(send_size*comm_size* MPI_CURRENT_TYPE->size()); void *recv = smpi_get_tmp_recvbuffer(recv_size*comm_size* MPI_CURRENT_TYPE2->size()); @@ -437,7 +436,8 @@ static void action_allToAll(const char *const *action) { log_timed_action (action, clock); } -static void action_gather(const char *const *action) { +static void action_gather(simgrid::xbt::ReplayAction& action) +{ /* The structure of the gather action for the rank 0 (total 4 processes) is the following: 0 gather 68 68 0 0 0 where: @@ -449,15 +449,15 @@ static void action_gather(const char *const *action) { */ CHECK_ACTION_PARAMS(action, 2, 3) double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); int send_size = parse_double(action[2]); int recv_size = parse_double(action[3]); - MPI_Datatype MPI_CURRENT_TYPE = (action[5] && action[6]) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{(action[5] && action[6]) ? decode_datatype(action[6]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE{(action.size() > 6) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 6) ? decode_datatype(action[6]) : MPI_DEFAULT_TYPE}; void *send = smpi_get_tmp_sendbuffer(send_size* MPI_CURRENT_TYPE->size()); void *recv = nullptr; - int root = (action[4]) ? std::stoi(action[4]) : 0; + int root = (action.size() > 4) ? std::stoi(action[4]) : 0; int rank = MPI_COMM_WORLD->rank(); if(rank==root) @@ -473,7 +473,7 @@ static void action_gather(const char *const *action) { log_timed_action (action, clock); } -static void action_scatter(const char* const* action) +static void action_scatter(simgrid::xbt::ReplayAction& action) { /* The structure of the scatter action for the rank 0 (total 4 processes) is the following: 0 gather 68 68 0 0 0 @@ -486,15 +486,15 @@ static void action_scatter(const char* const* action) */ CHECK_ACTION_PARAMS(action, 2, 3) double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); int send_size = parse_double(action[2]); int recv_size = parse_double(action[3]); - MPI_Datatype MPI_CURRENT_TYPE = (action[5] && action[6]) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{(action[5] && action[6]) ? decode_datatype(action[6]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE{(action.size() > 6) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 6) ? decode_datatype(action[6]) : MPI_DEFAULT_TYPE}; void* send = smpi_get_tmp_sendbuffer(send_size * MPI_CURRENT_TYPE->size()); void* recv = nullptr; - int root = (action[4]) ? std::stoi(action[4]) : 0; + int root = (action.size() > 4) ? std::stoi(action[4]) : 0; int rank = MPI_COMM_WORLD->rank(); if (rank == root) @@ -510,7 +510,8 @@ static void action_scatter(const char* const* action) log_timed_action(action, clock); } -static void action_gatherv(const char *const *action) { +static void action_gatherv(simgrid::xbt::ReplayAction& action) +{ /* The structure of the gatherv action for the rank 0 (total 4 processes) is the following: 0 gather 68 68 10 10 10 0 0 0 where: @@ -521,25 +522,25 @@ static void action_gatherv(const char *const *action) { 5) 0 is the recv datatype id, see decode_datatype() */ double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); CHECK_ACTION_PARAMS(action, comm_size+1, 2) int send_size = parse_double(action[2]); std::vector disps(comm_size, 0); std::shared_ptr> recvcounts(new std::vector(comm_size)); MPI_Datatype MPI_CURRENT_TYPE = - (action[4 + comm_size] && action[5 + comm_size]) ? decode_datatype(action[4 + comm_size]) : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{ - (action[4 + comm_size] && action[5 + comm_size]) ? decode_datatype(action[5 + comm_size]) : MPI_DEFAULT_TYPE}; + (action.size() > 5 + comm_size) ? decode_datatype(action[4 + comm_size]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 5 + comm_size) ? decode_datatype(action[5 + comm_size]) + : MPI_DEFAULT_TYPE}; void *send = smpi_get_tmp_sendbuffer(send_size* MPI_CURRENT_TYPE->size()); void *recv = nullptr; - for(int i=0;ibegin(), recvcounts->end(), 0); - int root = (action[3 + comm_size]) ? std::stoi(action[3 + comm_size]) : 0; + int root = (action.size() > 3 + comm_size) ? std::stoi(action[3 + comm_size]) : 0; int rank = MPI_COMM_WORLD->rank(); if(rank==root) @@ -556,7 +557,7 @@ static void action_gatherv(const char *const *action) { log_timed_action (action, clock); } -static void action_scatterv(const char* const* action) +static void action_scatterv(simgrid::xbt::ReplayAction& action) { /* The structure of the scatterv action for the rank 0 (total 4 processes) is the following: 0 gather 68 10 10 10 68 0 0 0 @@ -568,25 +569,25 @@ static void action_scatterv(const char* const* action) 5) 0 is the recv datatype id, see decode_datatype() */ double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); CHECK_ACTION_PARAMS(action, comm_size + 1, 2) int recv_size = parse_double(action[2 + comm_size]); std::vector disps(comm_size, 0); std::shared_ptr> sendcounts(new std::vector(comm_size)); MPI_Datatype MPI_CURRENT_TYPE = - (action[4 + comm_size] && action[5 + comm_size]) ? decode_datatype(action[4 + comm_size]) : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{ - (action[4 + comm_size] && action[5 + comm_size]) ? decode_datatype(action[5 + comm_size]) : MPI_DEFAULT_TYPE}; + (action.size() > 5 + comm_size) ? decode_datatype(action[4 + comm_size]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 5 + comm_size) ? decode_datatype(action[5 + comm_size]) + : MPI_DEFAULT_TYPE}; void* send = nullptr; void* recv = smpi_get_tmp_recvbuffer(recv_size * MPI_CURRENT_TYPE->size()); - for (int i = 0; i < comm_size; i++) { + for (unsigned int i = 0; i < comm_size; i++) { (*sendcounts)[i] = std::stoi(action[i + 2]); } int send_sum = std::accumulate(sendcounts->begin(), sendcounts->end(), 0); - int root = (action[3 + comm_size]) ? std::stoi(action[3 + comm_size]) : 0; + int root = (action.size() > 3 + comm_size) ? std::stoi(action[3 + comm_size]) : 0; int rank = MPI_COMM_WORLD->rank(); if (rank == root) @@ -603,23 +604,25 @@ static void action_scatterv(const char* const* action) log_timed_action(action, clock); } -static void action_reducescatter(const char *const *action) { - /* The structure of the reducescatter action for the rank 0 (total 4 processes) is the following: - 0 reduceScatter 275427 275427 275427 204020 11346849 0 - where: - 1) The first four values after the name of the action declare the recvcounts array - 2) The value 11346849 is the amount of instructions - 3) The last value corresponds to the datatype, see decode_datatype(). -*/ +static void action_reducescatter(simgrid::xbt::ReplayAction& action) +{ + /* The structure of the reducescatter action for the rank 0 (total 4 processes) is the following: + 0 reduceScatter 275427 275427 275427 204020 11346849 0 + where: + 1) The first four values after the name of the action declare the recvcounts array + 2) The value 11346849 is the amount of instructions + 3) The last value corresponds to the datatype, see decode_datatype(). + */ double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); CHECK_ACTION_PARAMS(action, comm_size+1, 1) int comp_size = parse_double(action[2+comm_size]); int my_proc_id = Actor::self()->getPid(); std::shared_ptr> recvcounts(new std::vector); - MPI_Datatype MPI_CURRENT_TYPE = (action[3 + comm_size]) ? decode_datatype(action[3 + comm_size]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE = + (action.size() > 3 + comm_size) ? decode_datatype(action[3 + comm_size]) : MPI_DEFAULT_TYPE; - for(int i=0;ipush_back(std::stoi(action[i + 2])); } int size{std::accumulate(recvcounts->begin(), recvcounts->end(), 0)}; @@ -639,7 +642,8 @@ static void action_reducescatter(const char *const *action) { log_timed_action (action, clock); } -static void action_allgather(const char *const *action) { +static void action_allgather(simgrid::xbt::ReplayAction& action) +{ /* The structure of the allgather action for the rank 0 (total 4 processes) is the following: 0 allGather 275427 275427 where: @@ -653,8 +657,8 @@ static void action_allgather(const char *const *action) { int sendcount = std::stoi(action[2]); int recvcount = std::stoi(action[3]); - MPI_Datatype MPI_CURRENT_TYPE = (action[4] && action[5]) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{(action[4] && action[5]) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE{(action.size() > 5) ? decode_datatype(action[4]) : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 5) ? decode_datatype(action[5]) : MPI_DEFAULT_TYPE}; void *sendbuf = smpi_get_tmp_sendbuffer(sendcount* MPI_CURRENT_TYPE->size()); void *recvbuf = smpi_get_tmp_recvbuffer(recvcount* MPI_CURRENT_TYPE2->size()); @@ -671,7 +675,8 @@ static void action_allgather(const char *const *action) { log_timed_action (action, clock); } -static void action_allgatherv(const char *const *action) { +static void action_allgatherv(simgrid::xbt::ReplayAction& action) +{ /* The structure of the allgatherv action for the rank 0 (total 4 processes) is the following: 0 allGatherV 275427 275427 275427 275427 204020 where: @@ -681,25 +686,26 @@ static void action_allgatherv(const char *const *action) { */ double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); CHECK_ACTION_PARAMS(action, comm_size+1, 2) int sendcount = std::stoi(action[2]); std::shared_ptr> recvcounts(new std::vector(comm_size)); std::vector disps(comm_size, 0); int datatype_index = 0, disp_index = 0; - if (action[3 + 2 * comm_size]) { /* datatype + disp are specified */ + if (action.size() > 3 + 2 * comm_size) { /* datatype + disp are specified */ datatype_index = 3 + comm_size; disp_index = datatype_index + 1; - } else if (action[3 + 2 * comm_size]) { /* disps specified; datatype is not specified; use the default one */ + } else if (action.size() > 3 + 2 * comm_size) { /* disps specified; datatype is not specified; use the default one */ datatype_index = -1; disp_index = 3 + comm_size; - } else if (action[3 + comm_size]) { /* only datatype, no disp specified */ + } else if (action.size() > 3 + comm_size) { /* only datatype, no disp specified */ datatype_index = 3 + comm_size; } if (disp_index != 0) { - std::copy(action[disp_index], action[disp_index + comm_size], disps.begin()); + for (unsigned int i = 0; i < comm_size; i++) + disps[i] = std::stoi(action[disp_index + i]); } MPI_Datatype MPI_CURRENT_TYPE{(datatype_index > 0) ? decode_datatype(action[datatype_index]) : MPI_DEFAULT_TYPE}; @@ -707,7 +713,7 @@ static void action_allgatherv(const char *const *action) { void *sendbuf = smpi_get_tmp_sendbuffer(sendcount* MPI_CURRENT_TYPE->size()); - for(int i=0;ibegin(), recvcounts->end(), 0); @@ -726,7 +732,8 @@ static void action_allgatherv(const char *const *action) { log_timed_action (action, clock); } -static void action_allToAllv(const char *const *action) { +static void action_allToAllv(simgrid::xbt::ReplayAction& action) +{ /* The structure of the allToAllV action for the rank 0 (total 4 processes) is the following: 0 allToAllV 100 1 7 10 12 100 1 70 10 5 where: @@ -737,19 +744,17 @@ static void action_allToAllv(const char *const *action) { */ double clock = smpi_process()->simulated_elapsed(); - int comm_size = MPI_COMM_WORLD->size(); + unsigned long comm_size = MPI_COMM_WORLD->size(); CHECK_ACTION_PARAMS(action, 2*comm_size+2, 2) std::shared_ptr> sendcounts(new std::vector(comm_size)); std::shared_ptr> recvcounts(new std::vector(comm_size)); std::vector senddisps(comm_size, 0); std::vector recvdisps(comm_size, 0); - MPI_Datatype MPI_CURRENT_TYPE = (action[4 + 2 * comm_size] && action[5 + 2 * comm_size]) - ? decode_datatype(action[4 + 2 * comm_size]) - : MPI_DEFAULT_TYPE; - MPI_Datatype MPI_CURRENT_TYPE2{(action[4 + 2 * comm_size] && action[5 + 2 * comm_size]) - ? decode_datatype(action[5 + 2 * comm_size]) - : MPI_DEFAULT_TYPE}; + MPI_Datatype MPI_CURRENT_TYPE = + (action.size() > 5 + 2 * comm_size) ? decode_datatype(action[4 + 2 * comm_size]) : MPI_DEFAULT_TYPE; + MPI_Datatype MPI_CURRENT_TYPE2{(action.size() > 5 + 2 * comm_size) ? decode_datatype(action[5 + 2 * comm_size]) + : MPI_DEFAULT_TYPE}; int send_buf_size=parse_double(action[2]); int recv_buf_size=parse_double(action[3+comm_size]); @@ -757,7 +762,7 @@ static void action_allToAllv(const char *const *action) { void *sendbuf = smpi_get_tmp_sendbuffer(send_buf_size* MPI_CURRENT_TYPE->size()); void *recvbuf = smpi_get_tmp_recvbuffer(recv_buf_size* MPI_CURRENT_TYPE2->size()); - for(int i=0;ieof(); } -static ReplayAction* get_action(char* name) +static ReplayAction get_action(char* name) { ReplayAction* action; @@ -75,7 +75,7 @@ static ReplayAction* get_action(char* name) // if it's for me, I'm done std::string evtname = action->front(); if (evtname.compare(name) == 0) { - return action; + return *action; } else { // Else, I have to store it for the relevant colleague std::queue* otherqueue = nullptr; @@ -94,34 +94,22 @@ static ReplayAction* get_action(char* name) // Get something from my queue and return it action = myqueue->front(); myqueue->pop(); - return action; + return *action; } - return nullptr; + + return ReplayAction(); } -static void handle_action(ReplayAction* action) +static void handle_action(ReplayAction& action) { - XBT_DEBUG("%s replays a %s action", action->at(0).c_str(), action->at(1).c_str()); - char** c_action = new char*[action->size() + 1]; - action_fun function = action_funs.at(action->at(1)); - int i = 0; - for (auto const& arg : *action) { - c_action[i] = xbt_strdup(arg.c_str()); - i++; - } - c_action[i] = nullptr; + XBT_DEBUG("%s replays a %s action", action.at(0).c_str(), action.at(1).c_str()); + action_fun function = action_funs.at(action.at(1)); try { - function(c_action); + function(action); } catch (xbt_ex& e) { - for (unsigned int j = 0; j < action->size(); j++) - xbt_free(c_action[j]); - delete[] c_action; - action->clear(); + action.clear(); xbt_die("Replay error:\n %s", e.what()); } - for (unsigned int j = 0; j < action->size(); j++) - xbt_free(c_action[j]); - delete[] c_action; } /** @@ -132,11 +120,10 @@ int replay_runner(int argc, char* argv[]) { if (simgrid::xbt::action_fs) { // A unique trace file while (true) { - simgrid::xbt::ReplayAction* evt = simgrid::xbt::get_action(argv[0]); - if (evt == nullptr) + simgrid::xbt::ReplayAction evt(std::move(simgrid::xbt::get_action(argv[0]))); + if (evt.empty()) break; simgrid::xbt::handle_action(evt); - delete evt; } if (action_queues.find(std::string(argv[0])) != action_queues.end()) { std::queue* myqueue = action_queues.at(std::string(argv[0])); @@ -151,7 +138,7 @@ int replay_runner(int argc, char* argv[]) simgrid::xbt::ReplayReader reader(argv[1]); while (reader.get(&evt)) { if (evt.front().compare(argv[0]) == 0) { - simgrid::xbt::handle_action(&evt); + simgrid::xbt::handle_action(evt); } else { XBT_WARN("Ignore trace element not for me"); }