From 29036bc0419a7bd0b531370ec066948b49af5602 Mon Sep 17 00:00:00 2001 From: Gabriel Corona Date: Fri, 22 Jul 2016 10:45:30 +0200 Subject: [PATCH] [simix] Dexbtization: remove xbt_dynar_t argument in simcall_comm_waitany --- include/simgrid/simix.h | 2 +- src/mc/mc_request.cpp | 16 ++++++---------- src/mc/mc_state.cpp | 12 ++++-------- src/msg/msg_gos.cpp | 10 +++++----- src/simix/libsmx.cpp | 6 +++--- src/simix/popping_accessors.h | 16 +++++++++++----- src/simix/popping_bodies.cpp | 6 +++--- src/simix/popping_generated.cpp | 2 +- src/simix/simcalls.in | 2 +- src/simix/smx_network.cpp | 23 ++++++++++++++++------- src/smpi/smpi_base.cpp | 11 ++++++----- 11 files changed, 57 insertions(+), 49 deletions(-) diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index d9b6007c41..f996f13c96 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -362,7 +362,7 @@ XBT_PUBLIC(void) simcall_comm_cancel(smx_synchro_t comm); XBT_PUBLIC(unsigned int) simcall_comm_waitany(xbt_dynar_t comms); XBT_PUBLIC(void) simcall_comm_wait(smx_synchro_t comm, double timeout); XBT_PUBLIC(int) simcall_comm_test(smx_synchro_t comm); -XBT_PUBLIC(int) simcall_comm_testany(xbt_dynar_t comms); +XBT_PUBLIC(int) simcall_comm_testany(smx_synchro_t* comms, size_t count); /************************** Tracing handling **********************************/ XBT_PUBLIC(void) simcall_set_category(smx_synchro_t synchro, const char *category); diff --git a/src/mc/mc_request.cpp b/src/mc/mc_request.cpp index cf8a8bfae4..1feb6e8e2b 100644 --- a/src/mc/mc_request.cpp +++ b/src/mc/mc_request.cpp @@ -375,8 +375,7 @@ std::string simgrid::mc::request_to_string(smx_simcall_t req, int value, simgrid type = "TestAny"; args = bprintf("(%d of %zu)", value + 1, - read_length(mc_model_checker->process(), - simcall_comm_testany__get__comms(req))); + simcall_comm_testany__get__count(req)); } break; @@ -451,12 +450,9 @@ bool request_is_enabled_by_idx(smx_simcall_t req, unsigned int idx) } break; - case SIMCALL_COMM_TESTANY: { - read_element( - mc_model_checker->process(), &remote_act, - remote(simcall_comm_testany__get__comms(req)), - idx, sizeof(remote_act)); - } + case SIMCALL_COMM_TESTANY: + remote_act = mc_model_checker->process().read(remote( + simcall_comm_testany__get__comms(req) + idx)); break; default: @@ -601,12 +597,12 @@ std::string request_get_dot_output(smx_simcall_t req, int value) label = simgrid::xbt::string_printf("[(%lu)%s] TestAny TRUE [%d of %lu]", issuer->pid, MC_smx_process_get_host_name(issuer), value + 1, - xbt_dynar_length(simcall_comm_testany__get__comms(req))); + simcall_comm_testany__get__count(req)); else label = simgrid::xbt::string_printf("[(%lu)] TestAny TRUE [%d of %lu]", issuer->pid, value + 1, - xbt_dynar_length(simcall_comm_testany__get__comms(req))); + simcall_comm_testany__get__count(req)); } break; diff --git a/src/mc/mc_state.cpp b/src/mc/mc_state.cpp index a919c30238..59a9de060f 100644 --- a/src/mc/mc_state.cpp +++ b/src/mc/mc_state.cpp @@ -106,8 +106,7 @@ static inline smx_simcall_t MC_state_get_request_for_process( unsigned start_count = procstate->interleave_count; state->transition.argument = -1; while (procstate->interleave_count < - read_length(mc_model_checker->process(), - remote(simcall_comm_testany__get__comms(&process->simcall)))) + simcall_comm_testany__get__count(&process->simcall)) if (simgrid::mc::request_is_enabled_by_idx(&process->simcall, procstate->interleave_count++)) { state->transition.argument = procstate->interleave_count - 1; @@ -115,8 +114,7 @@ static inline smx_simcall_t MC_state_get_request_for_process( } if (procstate->interleave_count >= - read_length(mc_model_checker->process(), - remote(simcall_comm_testany__get__comms(&process->simcall)))) + simcall_comm_testany__get__count(&process->simcall)) procstate->setDone(); if (state->transition.argument != -1 || start_count == 0) @@ -191,10 +189,8 @@ static inline smx_simcall_t MC_state_get_request_for_process( state->internal_req.issuer = req->issuer; if (state->transition.argument > 0) { - smx_synchro_t remote_comm; - read_element(mc_model_checker->process(), - &remote_comm, remote(simcall_comm_testany__get__comms(req)), - state->transition.argument, sizeof(remote_comm)); + smx_synchro_t remote_comm = mc_model_checker->process().read( + remote(simcall_comm_testany__get__comms(req) + state->transition.argument)); mc_model_checker->process().read(state->internal_comm, remote( static_cast(remote_comm))); } diff --git a/src/msg/msg_gos.cpp b/src/msg/msg_gos.cpp index 9e0378e805..5a1f0b5a64 100644 --- a/src/msg/msg_gos.cpp +++ b/src/msg/msg_gos.cpp @@ -504,17 +504,18 @@ int MSG_comm_testany(xbt_dynar_t comms) { int finished_index = -1; - /* create the equivalent dynar with SIMIX objects */ - xbt_dynar_t s_comms = xbt_dynar_new(sizeof(smx_synchro_t), nullptr); + /* Create the equivalent array with SIMIX objects: */ + std::vector s_comms; + s_comms.reserve(xbt_dynar_length(comms)); msg_comm_t comm; unsigned int cursor; xbt_dynar_foreach(comms, cursor, comm) { - xbt_dynar_push(s_comms, &comm->s_comm); + s_comms.push_back(comm->s_comm); } msg_error_t status = MSG_OK; try { - finished_index = simcall_comm_testany(s_comms); + finished_index = simcall_comm_testany(s_comms.data(), s_comms.size()); } catch (xbt_ex& e) { switch (e.category) { @@ -530,7 +531,6 @@ int MSG_comm_testany(xbt_dynar_t comms) throw; } } - xbt_dynar_free(&s_comms); if (finished_index != -1) { comm = xbt_dynar_get_as(comms, finished_index, msg_comm_t); diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 8f41f627b8..10177cc30d 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -773,11 +773,11 @@ unsigned int simcall_comm_waitany(xbt_dynar_t comms) /** * \ingroup simix_comm_management */ -int simcall_comm_testany(xbt_dynar_t comms) +int simcall_comm_testany(smx_synchro_t* comms, size_t count) { - if (xbt_dynar_is_empty(comms)) + if (count == 0) return -1; - return simcall_BODY_comm_testany(comms); + return simcall_BODY_comm_testany(comms, count); } /** diff --git a/src/simix/popping_accessors.h b/src/simix/popping_accessors.h index 32e906ec8f..64db9d15c8 100644 --- a/src/simix/popping_accessors.h +++ b/src/simix/popping_accessors.h @@ -690,11 +690,17 @@ static inline void simcall_comm_test__set__result(smx_simcall_t simcall, int res simgrid::simix::marshal(simcall->result, result); } -static inline xbt_dynar_t simcall_comm_testany__get__comms(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args[0]); +static inline smx_synchro_t* simcall_comm_testany__get__comms(smx_simcall_t simcall) { + return simgrid::simix::unmarshal(simcall->args[0]); } -static inline void simcall_comm_testany__set__comms(smx_simcall_t simcall, xbt_dynar_t arg) { - simgrid::simix::marshal(simcall->args[0], arg); +static inline void simcall_comm_testany__set__comms(smx_simcall_t simcall, smx_synchro_t* arg) { + simgrid::simix::marshal(simcall->args[0], arg); +} +static inline size_t simcall_comm_testany__get__count(smx_simcall_t simcall) { + return simgrid::simix::unmarshal(simcall->args[1]); +} +static inline void simcall_comm_testany__set__count(smx_simcall_t simcall, size_t arg) { + simgrid::simix::marshal(simcall->args[1], arg); } static inline int simcall_comm_testany__get__result(smx_simcall_t simcall){ return simgrid::simix::unmarshal(simcall->result); @@ -1182,7 +1188,7 @@ XBT_PRIVATE smx_synchro_t simcall_HANDLER_comm_irecv(smx_simcall_t simcall, smx_ XBT_PRIVATE void simcall_HANDLER_comm_waitany(smx_simcall_t simcall, xbt_dynar_t comms); XBT_PRIVATE void simcall_HANDLER_comm_wait(smx_simcall_t simcall, smx_synchro_t comm, double timeout); XBT_PRIVATE void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_synchro_t comm); -XBT_PRIVATE void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t comms); +XBT_PRIVATE void simcall_HANDLER_comm_testany(smx_simcall_t simcall, smx_synchro_t* comms, size_t count); XBT_PRIVATE smx_mutex_t simcall_HANDLER_mutex_init(smx_simcall_t simcall); XBT_PRIVATE void simcall_HANDLER_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex); XBT_PRIVATE int simcall_HANDLER_mutex_trylock(smx_simcall_t simcall, smx_mutex_t mutex); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index ba83d704e2..f830047458 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -239,10 +239,10 @@ inline static int simcall_BODY_comm_test(smx_synchro_t comm) { return simcall(SIMCALL_COMM_TEST, comm); } -inline static int simcall_BODY_comm_testany(xbt_dynar_t comms) { +inline static int simcall_BODY_comm_testany(smx_synchro_t* comms, size_t count) { /* Go to that function to follow the code flow through the simcall barrier */ - if (0) simcall_HANDLER_comm_testany(&SIMIX_process_self()->simcall, comms); - return simcall(SIMCALL_COMM_TESTANY, comms); + if (0) simcall_HANDLER_comm_testany(&SIMIX_process_self()->simcall, comms, count); + return simcall(SIMCALL_COMM_TESTANY, comms, count); } inline static smx_mutex_t simcall_BODY_mutex_init() { diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 1ba87540ed..e5bd57b15d 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -266,7 +266,7 @@ case SIMCALL_COMM_TEST: break; case SIMCALL_COMM_TESTANY: - simcall_HANDLER_comm_testany(simcall, simgrid::simix::unmarshal(simcall->args[0])); + simcall_HANDLER_comm_testany(simcall, simgrid::simix::unmarshal(simcall->args[0]), simgrid::simix::unmarshal(simcall->args[1])); break; case SIMCALL_MUTEX_INIT: diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index 55858b21f1..dbef0797a4 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -75,7 +75,7 @@ smx_synchro_t comm_irecv(smx_process_t receiver, smx_mailbox_t mbox, void* dst_b int comm_waitany(xbt_dynar_t comms) [[block]]; void comm_wait(smx_synchro_t comm, double timeout) [[block]]; int comm_test(smx_synchro_t comm) [[block]]; -int comm_testany(xbt_dynar_t comms) [[block]]; +int comm_testany(smx_synchro_t* comms, size_t count) [[block]]; smx_mutex_t mutex_init(); void mutex_lock(smx_mutex_t mutex) [[block]]; diff --git a/src/simix/smx_network.cpp b/src/simix/smx_network.cpp index db3b4fde80..0b47f73f02 100644 --- a/src/simix/smx_network.cpp +++ b/src/simix/smx_network.cpp @@ -3,6 +3,8 @@ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#include + #include #include @@ -443,10 +445,9 @@ void simcall_HANDLER_comm_test(smx_simcall_t simcall, smx_synchro_t synchro) } } -void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t synchros) +void simcall_HANDLER_comm_testany( + smx_simcall_t simcall, simgrid::simix::Synchro* comms[], size_t count) { - unsigned int cursor; - smx_synchro_t synchro; // The default result is -1 -- this means, "nothing is ready". // It can be changed below, but only if something matches. simcall_comm_testany__set__result(simcall, -1); @@ -456,7 +457,7 @@ void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t synchros) if(idx == -1){ SIMIX_simcall_answer(simcall); }else{ - synchro = xbt_dynar_get_as(synchros, idx, smx_synchro_t); + simgrid::simix::Synchro* synchro = comms[idx]; simcall_comm_testany__set__result(simcall, idx); synchro->simcalls.push_back(simcall); synchro->state = SIMIX_DONE; @@ -465,9 +466,10 @@ void simcall_HANDLER_comm_testany(smx_simcall_t simcall, xbt_dynar_t synchros) return; } - xbt_dynar_foreach(simcall_comm_testany__get__comms(simcall), cursor,synchro) { + for (std::size_t i = 0; i != count; ++i) { + simgrid::simix::Synchro* synchro = comms[i]; if (synchro->state != SIMIX_WAITING && synchro->state != SIMIX_RUNNING) { - simcall_comm_testany__set__result(simcall, cursor); + simcall_comm_testany__set__result(simcall, i); synchro->simcalls.push_back(simcall); SIMIX_comm_finish(synchro); return; @@ -669,7 +671,14 @@ void SIMIX_comm_finish(smx_synchro_t synchro) e.value = xbt_dynar_search(simcall_comm_waitany__get__comms(simcall), &synchro); } else if (simcall->call == SIMCALL_COMM_TESTANY) { - e.value = xbt_dynar_search(simcall_comm_testany__get__comms(simcall), &synchro); + e.value = -1; + auto comms = simcall_comm_testany__get__comms(simcall); + auto count = simcall_comm_testany__get__count(simcall); + auto element = std::find(comms, comms + count, synchro); + if (element == comms + count) + e.value = -1; + else + e.value = element - comms; } simcall->issuer->exception = std::make_exception_ptr(e); } diff --git a/src/smpi/smpi_base.cpp b/src/smpi/smpi_base.cpp index 0170851808..b1389d334e 100644 --- a/src/smpi/smpi_base.cpp +++ b/src/smpi/smpi_base.cpp @@ -773,16 +773,18 @@ int smpi_mpi_test(MPI_Request * request, MPI_Status * status) { int smpi_mpi_testany(int count, MPI_Request requests[], int *index, MPI_Status * status) { - xbt_dynar_t comms; + std::vector comms; + comms.reserve(count); + int i; int flag = 0; *index = MPI_UNDEFINED; - comms = xbt_dynar_new(sizeof(smx_synchro_t), nullptr); + std::vector map; /** Maps all matching comms back to their location in requests **/ for(i = 0; i < count; i++) { if ((requests[i] != MPI_REQUEST_NULL) && requests[i]->action && !(requests[i]->flags & PREPARED)) { - xbt_dynar_push(comms, &requests[i]->action); + comms.push_back(requests[i]->action); map.push_back(i); } } @@ -792,7 +794,7 @@ int smpi_mpi_testany(int count, MPI_Request requests[], int *index, MPI_Status * if(smpi_test_sleep > 0) simcall_process_sleep(nsleeps*smpi_test_sleep); - i = simcall_comm_testany(comms); // The i-th element in comms matches! + i = simcall_comm_testany(comms.data(), comms.size()); // The i-th element in comms matches! if (i != -1) { // -1 is not MPI_UNDEFINED but a SIMIX return code. (nothing matches) *index = map[i]; finish_wait(&requests[*index], status); @@ -809,7 +811,6 @@ int smpi_mpi_testany(int count, MPI_Request requests[], int *index, MPI_Status * flag = 1; smpi_empty_status(status); } - xbt_dynar_free(&comms); return flag; } -- 2.20.1