From: Arnaud Giersch Date: Wed, 17 Mar 2021 21:47:10 +0000 (+0100) Subject: Make simcall execution_waitany_for use a std::vector internally. X-Git-Tag: v3.27~100 X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/96c028707959cb28e44efb23dd23318ec8d29a6c Make simcall execution_waitany_for use a std::vector internally. --- diff --git a/src/kernel/activity/ExecImpl.cpp b/src/kernel/activity/ExecImpl.cpp index 0f925c9600..75cf11ecf5 100644 --- a/src/kernel/activity/ExecImpl.cpp +++ b/src/kernel/activity/ExecImpl.cpp @@ -19,18 +19,18 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(simix_process); -void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl* execs[], - size_t count, double timeout) +void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, + const std::vector* execs, + double timeout) { if (timeout < 0.0) { simcall->timeout_cb_ = nullptr; } else { - simcall->timeout_cb_ = simgrid::simix::Timer::set(SIMIX_get_clock() + timeout, [simcall, execs, count]() { + simcall->timeout_cb_ = simgrid::simix::Timer::set(SIMIX_get_clock() + timeout, [simcall, execs]() { simcall->timeout_cb_ = nullptr; - for (size_t i = 0; i < count; i++) { + for (auto* exec : *execs) { // Remove the first occurrence of simcall: - auto* exec = execs[i]; - auto j = boost::range::find(exec->simcalls_, simcall); + auto j = boost::range::find(exec->simcalls_, simcall); if (j != exec->simcalls_.end()) exec->simcalls_.erase(j); } @@ -39,9 +39,8 @@ void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, simgrid::kerne }); } - for (size_t i = 0; i < count; i++) { + for (auto* exec : *execs) { /* associate this simcall to the the synchro */ - auto* exec = execs[i]; exec->simcalls_.push_back(simcall); /* see if the synchro is already finished */ @@ -201,13 +200,12 @@ void ExecImpl::finish() if (simcall->call_ == simix::Simcall::NONE) // FIXME: maybe a better way to handle this case continue; // if process handling comm is killed if (simcall->call_ == simix::Simcall::EXECUTION_WAITANY_FOR) { - simgrid::kernel::activity::ExecImpl** execs = simcall_execution_waitany_for__get__execs(simcall); - size_t count = simcall_execution_waitany_for__get__count(simcall); + const std::vector* execs = + simcall_execution_waitany_for__get__execs(simcall); - for (size_t i = 0; i < count; i++) { + for (auto* exec : *execs) { // Remove the first occurrence of simcall: - auto* exec = execs[i]; - auto j = boost::range::find(exec->simcalls_, simcall); + auto j = boost::range::find(exec->simcalls_, simcall); if (j != exec->simcalls_.end()) exec->simcalls_.erase(j); @@ -218,8 +216,8 @@ void ExecImpl::finish() } if (not MC_is_active() && not MC_record_replay_is_active()) { - ExecImpl** element = std::find(execs, execs + count, this); - int rank = (element != execs + count) ? element - execs : -1; + auto element = std::find(execs->begin(), execs->end(), this); + int rank = (element != execs->end()) ? std::distance(execs->begin(), element) : -1; simcall_execution_waitany_for__set__result(simcall, rank); } } diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index 16e7f8f3d0..4dcfc051bc 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -62,7 +62,8 @@ bool simcall_execution_test(const simgrid::kernel::activity::ActivityImplPtr& ex unsigned int simcall_execution_waitany_for(simgrid::kernel::activity::ExecImpl* execs[], size_t count, double timeout) { - return simcall_BODY_execution_waitany_for(execs, count, timeout); + std::vector execsv(execs, execs + count); + return simcall_BODY_execution_waitany_for(&execsv, timeout); } void simcall_process_join(smx_actor_t process, double timeout) // XBT_ATTRIB_DEPRECATED_v328 diff --git a/src/simix/popping_accessors.hpp b/src/simix/popping_accessors.hpp index db744d4e1b..90b307e863 100644 --- a/src/simix/popping_accessors.hpp +++ b/src/simix/popping_accessors.hpp @@ -15,41 +15,29 @@ */ #include "src/simix/popping_private.hpp" -static inline simgrid::kernel::activity::ExecImpl** simcall_execution_waitany_for__get__execs(smx_simcall_t simcall) +static inline const std::vector* simcall_execution_waitany_for__get__execs(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args_[0]); + return simgrid::simix::unmarshal*>(simcall->args_[0]); } -static inline simgrid::kernel::activity::ExecImpl** simcall_execution_waitany_for__getraw__execs(smx_simcall_t simcall) +static inline const std::vector* simcall_execution_waitany_for__getraw__execs(smx_simcall_t simcall) { - return simgrid::simix::unmarshal_raw(simcall->args_[0]); + return simgrid::simix::unmarshal_raw*>(simcall->args_[0]); } -static inline void simcall_execution_waitany_for__set__execs(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl** arg) +static inline void simcall_execution_waitany_for__set__execs(smx_simcall_t simcall, const std::vector* arg) { - simgrid::simix::marshal(simcall->args_[0], arg); -} -static inline size_t simcall_execution_waitany_for__get__count(smx_simcall_t simcall) -{ - return simgrid::simix::unmarshal(simcall->args_[1]); -} -static inline size_t simcall_execution_waitany_for__getraw__count(smx_simcall_t simcall) -{ - return simgrid::simix::unmarshal_raw(simcall->args_[1]); -} -static inline void simcall_execution_waitany_for__set__count(smx_simcall_t simcall, size_t arg) -{ - simgrid::simix::marshal(simcall->args_[1], arg); + simgrid::simix::marshal*>(simcall->args_[0], arg); } static inline double simcall_execution_waitany_for__get__timeout(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->args_[2]); + return simgrid::simix::unmarshal(simcall->args_[1]); } static inline double simcall_execution_waitany_for__getraw__timeout(smx_simcall_t simcall) { - return simgrid::simix::unmarshal_raw(simcall->args_[2]); + return simgrid::simix::unmarshal_raw(simcall->args_[1]); } static inline void simcall_execution_waitany_for__set__timeout(smx_simcall_t simcall, double arg) { - simgrid::simix::marshal(simcall->args_[2], arg); + simgrid::simix::marshal(simcall->args_[1], arg); } static inline int simcall_execution_waitany_for__get__result(smx_simcall_t simcall) { @@ -712,7 +700,7 @@ static inline void simcall_run_blocking__set__code(smx_simcall_t simcall, std::f /* The prototype of all simcall handlers, automatically generated for you */ -XBT_PRIVATE void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, simgrid::kernel::activity::ExecImpl** execs, size_t count, double timeout); +XBT_PRIVATE void simcall_HANDLER_execution_waitany_for(smx_simcall_t simcall, const std::vector* execs, double timeout); XBT_PRIVATE void simcall_HANDLER_comm_recv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout, double rate); XBT_PRIVATE boost::intrusive_ptr simcall_HANDLER_comm_irecv(smx_simcall_t simcall, smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double rate); XBT_PRIVATE void simcall_HANDLER_comm_send(smx_simcall_t simcall, smx_actor_t sender, smx_mailbox_t mbox, double task_size, double rate, unsigned char* src_buff, size_t src_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout); diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index dae4e7508e..83a3ec4487 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -41,11 +41,11 @@ inline static R simcall(Simcall call, T const&... t) return simgrid::simix::unmarshal(self->simcall_.result_); } -inline static int simcall_BODY_execution_waitany_for(simgrid::kernel::activity::ExecImpl** execs, size_t count, double timeout) +inline static int simcall_BODY_execution_waitany_for(const std::vector* execs, double timeout) { if (false) /* Go to that function to follow the code flow through the simcall barrier */ - simcall_HANDLER_execution_waitany_for(&SIMIX_process_self()->simcall_, execs, count, timeout); - return simcall(Simcall::EXECUTION_WAITANY_FOR, execs, count, timeout); + simcall_HANDLER_execution_waitany_for(&SIMIX_process_self()->simcall_, execs, timeout); + return simcall*, double>(Simcall::EXECUTION_WAITANY_FOR, execs, timeout); } inline static void simcall_BODY_comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout, double rate) diff --git a/src/simix/popping_generated.cpp b/src/simix/popping_generated.cpp index 5e3d98b25c..122b248d46 100644 --- a/src/simix/popping_generated.cpp +++ b/src/simix/popping_generated.cpp @@ -57,7 +57,7 @@ void simgrid::kernel::actor::ActorImpl::simcall_handle(int times_considered_) return; switch (simcall_.call_) { case Simcall::EXECUTION_WAITANY_FOR: - simcall_HANDLER_execution_waitany_for(&simcall_, simgrid::simix::unmarshal(simcall_.args_[0]), simgrid::simix::unmarshal(simcall_.args_[1]), simgrid::simix::unmarshal(simcall_.args_[2])); + simcall_HANDLER_execution_waitany_for(&simcall_, simgrid::simix::unmarshal*>(simcall_.args_[0]), simgrid::simix::unmarshal(simcall_.args_[1])); break; case Simcall::COMM_RECV: diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index a6274c60ba..ecbb39ff61 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -35,7 +35,7 @@ # Last but not the least, you should declare the new simix call in # ./include/simgrid/simix.h (otherwise you will get a warning at compile time) -int execution_waitany_for(simgrid::kernel::activity::ExecImpl** execs, size_t count, double timeout) [[block]]; +int execution_waitany_for(const std::vector* execs, double timeout) [[block]]; void comm_recv(smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double timeout, double rate) [[block]]; boost::intrusive_ptr comm_irecv(smx_actor_t receiver, smx_mailbox_t mbox, unsigned char* dst_buff, size_t* dst_buff_size, simix_match_func_t match_fun, simix_copy_data_func_t copy_data_fun, void* data, double rate);