From 5b547799240cfe5d60c1c4161e3fc8849095e2ca Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Wed, 23 Jun 2021 10:56:43 +0200 Subject: [PATCH] Use ssize_t as return type for Comm::wait_any. --- examples/c/app-chainsend/peer.c | 2 +- examples/c/comm-waitany/comm-waitany.c | 4 ++-- examples/cpp/app-chainsend/s4u-app-chainsend.cpp | 2 +- .../cpp/comm-serialize/s4u-comm-serialize.cpp | 2 +- examples/cpp/comm-waitany/s4u-comm-waitany.cpp | 4 ++-- include/simgrid/Exception.hpp | 6 +++--- include/simgrid/comm.h | 5 +++-- include/simgrid/s4u/Comm.hpp | 8 ++++---- include/simgrid/simix.h | 3 +-- src/kernel/activity/CommImpl.cpp | 4 ++-- src/msg/msg_comm.cpp | 4 ++-- src/s4u/s4u_Comm.cpp | 16 ++++++++-------- src/simix/libsmx.cpp | 4 ++-- src/simix/popping_accessors.hpp | 12 ++++++------ src/simix/popping_bodies.cpp | 4 ++-- src/simix/simcalls.in | 2 +- teshsuite/s4u/wait-any-for/wait-any-for.cpp | 4 ++-- 17 files changed, 43 insertions(+), 43 deletions(-) diff --git a/examples/c/app-chainsend/peer.c b/examples/c/app-chainsend/peer.c index 3161dd433b..022e851b30 100644 --- a/examples/c/app-chainsend/peer.c +++ b/examples/c/app-chainsend/peer.c @@ -30,7 +30,7 @@ static void peer_forward_file(peer_t p) p->pending_recvs[nb_pending_recvs] = sg_mailbox_get_async(p->me, &received); nb_pending_recvs++; - int idx = sg_comm_wait_any(p->pending_recvs, nb_pending_recvs); + ssize_t idx = sg_comm_wait_any(p->pending_recvs, nb_pending_recvs); if (idx != -1) { XBT_DEBUG("Peer %s got a 'SEND_DATA' message", sg_mailbox_get_name(p->me)); /* move the last pending comm where the finished one was, and decrement */ diff --git a/examples/c/comm-waitany/comm-waitany.c b/examples/c/comm-waitany/comm-waitany.c index ea987fb57f..e5c030f386 100644 --- a/examples/c/comm-waitany/comm-waitany.c +++ b/examples/c/comm-waitany/comm-waitany.c @@ -64,13 +64,13 @@ static void sender(int argc, char* argv[]) * Even in this simple example, the pending comms do not terminate in the exact same order of creation. */ while (pending_comms_count != 0) { - int changed_pos = sg_comm_wait_any(pending_comms, pending_comms_count); + ssize_t changed_pos = sg_comm_wait_any(pending_comms, pending_comms_count); memmove(pending_comms + changed_pos, pending_comms + changed_pos + 1, sizeof(sg_comm_t) * (pending_comms_count - changed_pos - 1)); pending_comms_count--; if (changed_pos != 0) - XBT_INFO("Remove the %dth pending comm: it terminated earlier than another comm that was initiated first.", + XBT_INFO("Remove the %zdth pending comm: it terminated earlier than another comm that was initiated first.", changed_pos); } diff --git a/examples/cpp/app-chainsend/s4u-app-chainsend.cpp b/examples/cpp/app-chainsend/s4u-app-chainsend.cpp index 66c9bb48dc..c8f387b25f 100644 --- a/examples/cpp/app-chainsend/s4u-app-chainsend.cpp +++ b/examples/cpp/app-chainsend/s4u-app-chainsend.cpp @@ -61,7 +61,7 @@ public: simgrid::s4u::CommPtr comm = me->get_async(&received); pending_recvs.push_back(comm); - int idx = simgrid::s4u::Comm::wait_any(pending_recvs); + ssize_t idx = simgrid::s4u::Comm::wait_any(pending_recvs); if (idx != -1) { comm = pending_recvs.at(idx); XBT_DEBUG("Peer %s got a 'SEND_DATA' message", me->get_cname()); diff --git a/examples/cpp/comm-serialize/s4u-comm-serialize.cpp b/examples/cpp/comm-serialize/s4u-comm-serialize.cpp index 41e44335a7..6afc5544b0 100644 --- a/examples/cpp/comm-serialize/s4u-comm-serialize.cpp +++ b/examples/cpp/comm-serialize/s4u-comm-serialize.cpp @@ -80,7 +80,7 @@ public: pending_comms.emplace_back(mbox->get_async(pending_msgs[i].get())); } while (not pending_comms.empty()) { - int index = sg4::Comm::wait_any(pending_comms); + ssize_t index = sg4::Comm::wait_any(pending_comms); std::string* msg = *pending_msgs[index]; XBT_INFO("I got '%s'.", msg->c_str()); /* cleanup memory and remove from vectors */ diff --git a/examples/cpp/comm-waitany/s4u-comm-waitany.cpp b/examples/cpp/comm-waitany/s4u-comm-waitany.cpp index fa8b117cdb..a7e57cd83e 100644 --- a/examples/cpp/comm-waitany/s4u-comm-waitany.cpp +++ b/examples/cpp/comm-waitany/s4u-comm-waitany.cpp @@ -77,10 +77,10 @@ public: * Even in this simple example, the pending comms do not terminate in the exact same order of creation. */ while (not pending_comms.empty()) { - int changed_pos = sg4::Comm::wait_any(pending_comms); + ssize_t changed_pos = sg4::Comm::wait_any(pending_comms); pending_comms.erase(pending_comms.begin() + changed_pos); if (changed_pos != 0) - XBT_INFO("Remove the %dth pending comm: it terminated earlier than another comm that was initiated first.", + XBT_INFO("Remove the %zdth pending comm: it terminated earlier than another comm that was initiated first.", changed_pos); } diff --git a/include/simgrid/Exception.hpp b/include/simgrid/Exception.hpp index fa3d7aa1fb..a5b0cd9968 100644 --- a/include/simgrid/Exception.hpp +++ b/include/simgrid/Exception.hpp @@ -93,8 +93,8 @@ public: xbt::ThrowPoint const& throw_point() const { return throwpoint_; } /** Allow to carry a value (used by testany/waitany) */ - int get_value() const { return value_; } - void set_value(int value) { value_ = value; } + ssize_t get_value() const { return value_; } + void set_value(ssize_t value) { value_ = value; } std::string resolve_backtrace() const { return throwpoint_.backtrace_.resolve(); } @@ -105,7 +105,7 @@ public: private: xbt::ThrowPoint throwpoint_; - int value_ = 0; + ssize_t value_ = 0; }; #define DECLARE_SIMGRID_EXCEPTION(AnyException, ...) \ diff --git a/include/simgrid/comm.h b/include/simgrid/comm.h index 093cf1306d..bc73bdaa46 100644 --- a/include/simgrid/comm.h +++ b/include/simgrid/comm.h @@ -7,6 +7,7 @@ #define INCLUDE_SIMGRID_COMM_H_ #include +#include /* ssize_t */ #include /* C interface */ @@ -18,8 +19,8 @@ XBT_PUBLIC sg_error_t sg_comm_wait(sg_comm_t comm); XBT_PUBLIC sg_error_t sg_comm_wait_for(sg_comm_t comm, double timeout); XBT_PUBLIC void sg_comm_wait_all(sg_comm_t* comms, size_t count); XBT_PUBLIC size_t sg_comm_wait_all_for(sg_comm_t* comms, size_t count, double timeout); -XBT_PUBLIC int sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout); -XBT_PUBLIC int sg_comm_wait_any(sg_comm_t* comms, size_t count); +XBT_PUBLIC ssize_t sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout); +XBT_PUBLIC ssize_t sg_comm_wait_any(sg_comm_t* comms, size_t count); XBT_PUBLIC void sg_comm_unref(sg_comm_t comm); SG_END_DECL diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 7fb446f409..0fee089808 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -69,9 +69,9 @@ public: /*! take a vector s4u::CommPtr and return when one of them is finished. * The return value is the rank of the first finished CommPtr. */ - static int wait_any(const std::vector& comms) { return wait_any_for(comms, -1); } + static ssize_t wait_any(const std::vector& comms) { return wait_any_for(comms, -1); } /*! Same as wait_any, but with a timeout. Return -1 if the timeout occurs.*/ - static int wait_any_for(const std::vector& comms, double timeout); + static ssize_t wait_any_for(const std::vector& comms, double timeout); /*! take a vector s4u::CommPtr and return when all of them is finished. */ static void wait_all(const std::vector& comms); @@ -82,9 +82,9 @@ public: static ssize_t test_any(const std::vector& comms); XBT_ATTRIB_DEPRECATED_v332("Please use a plain vector for parameter") - static int wait_any(const std::vector* comms) { return wait_any_for(*comms, -1); } + static int wait_any(const std::vector* comms) { return static_cast(wait_any_for(*comms, -1)); } XBT_ATTRIB_DEPRECATED_v332("Please use a plain vector for first parameter") - static int wait_any_for(const std::vector* comms, double timeout) { return wait_any_for(*comms, timeout); } + static int wait_any_for(const std::vector* comms, double timeout) { return static_cast(wait_any_for(*comms, timeout)); } XBT_ATTRIB_DEPRECATED_v332("Please use a plain vector for parameter") static void wait_all(const std::vector* comms) { wait_all(*comms); } XBT_ATTRIB_DEPRECATED_v332("Please use a plain vector for parameter") diff --git a/include/simgrid/simix.h b/include/simgrid/simix.h index bf2486fe4a..eeb501f90a 100644 --- a/include/simgrid/simix.h +++ b/include/simgrid/simix.h @@ -170,8 +170,7 @@ XBT_ATTRIB_DEPRECATED_v330("Please use Mailbox::iprobe()") XBT_PUBLIC simgrid::k XBT_ATTRIB_DEPRECATED_v330("Please use a CommImpl*[] for first parameter") XBT_PUBLIC unsigned int simcall_comm_waitany(simgrid::kernel::activity::ActivityImplPtr comms[], size_t count, double timeout); -XBT_PUBLIC unsigned int simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count, - double timeout); +XBT_PUBLIC ssize_t simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count, double timeout); XBT_PUBLIC void simcall_comm_wait(simgrid::kernel::activity::ActivityImpl* comm, double timeout); XBT_PUBLIC bool simcall_comm_test(simgrid::kernel::activity::ActivityImpl* comm); XBT_ATTRIB_DEPRECATED_v330("Please use a CommImpl*[] for first parameter") XBT_PUBLIC diff --git a/src/kernel/activity/CommImpl.cpp b/src/kernel/activity/CommImpl.cpp index e3ea115191..1724a85b50 100644 --- a/src/kernel/activity/CommImpl.cpp +++ b/src/kernel/activity/CommImpl.cpp @@ -580,7 +580,7 @@ void CommImpl::finish() } if (not MC_is_active() && not MC_record_replay_is_active()) { CommImpl** element = std::find(comms, comms + count, this); - int rank = (element != comms + count) ? element - comms : -1; + ssize_t rank = (element != comms + count) ? element - comms : -1; simcall_comm_waitany__set__result(simcall, rank); } } @@ -664,7 +664,7 @@ void CommImpl::finish() count = simcall_comm_testany__get__count(simcall); } CommImpl** element = std::find(comms, comms + count, this); - int rank = (element != comms + count) ? element - comms : -1; + ssize_t rank = (element != comms + count) ? element - comms : -1; // In order to modify the exception we have to rethrow it: try { std::rethrow_exception(simcall->issuer_->exception_); diff --git a/src/msg/msg_comm.cpp b/src/msg/msg_comm.cpp index 274358f7d7..91f56b0591 100644 --- a/src/msg/msg_comm.cpp +++ b/src/msg/msg_comm.cpp @@ -161,7 +161,7 @@ void MSG_comm_waitall(msg_comm_t* comm, int nb_elem, double timeout) */ int MSG_comm_waitany(const_xbt_dynar_t comms) { - int finished_index = -1; + ssize_t finished_index = -1; /* Create the equivalent array with SIMIX objects: */ std::vector s_comms; @@ -197,7 +197,7 @@ int MSG_comm_waitany(const_xbt_dynar_t comms) (*comm->task_received)->set_not_used(); } - return finished_index; + return static_cast(finished_index); } /** diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index 45681595d6..00c6bcf9c9 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -39,12 +39,12 @@ Comm::~Comm() } } -int Comm::wait_any_for(const std::vector& comms, double timeout) +ssize_t Comm::wait_any_for(const std::vector& comms, double timeout) { std::vector rcomms(comms.size()); std::transform(begin(comms), end(comms), begin(rcomms), [](const CommPtr& comm) { return static_cast(comm->pimpl_.get()); }); - int changed_pos = simcall_comm_waitany(rcomms.data(), rcomms.size(), timeout); + ssize_t changed_pos = simcall_comm_waitany(rcomms.data(), rcomms.size(), timeout); if (changed_pos != -1) comms.at(changed_pos)->complete(State::FINISHED); return changed_pos; @@ -356,20 +356,20 @@ size_t sg_comm_wait_all_for(sg_comm_t* comms, size_t count, double timeout) return pos; } -int sg_comm_wait_any(sg_comm_t* comms, size_t count) +ssize_t sg_comm_wait_any(sg_comm_t* comms, size_t count) { return sg_comm_wait_any_for(comms, count, -1); } -int sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout) +ssize_t sg_comm_wait_any_for(sg_comm_t* comms, size_t count, double timeout) { std::vector s4u_comms; - for (unsigned int i = 0; i < count; i++) + for (size_t i = 0; i < count; i++) s4u_comms.emplace_back(comms[i], false); - int pos = simgrid::s4u::Comm::wait_any_for(s4u_comms, timeout); - for (unsigned i = 0; i < count; i++) { - if (pos != -1 && static_cast(pos) != i) + ssize_t pos = simgrid::s4u::Comm::wait_any_for(s4u_comms, timeout); + for (size_t i = 0; i < count; i++) { + if (pos != -1 && static_cast(pos) != i) s4u_comms[i]->add_ref(); } return pos; diff --git a/src/simix/libsmx.cpp b/src/simix/libsmx.cpp index b327f59938..d32231a1ae 100644 --- a/src/simix/libsmx.cpp +++ b/src/simix/libsmx.cpp @@ -191,10 +191,10 @@ unsigned int simcall_comm_waitany(simgrid::kernel::activity::ActivityImplPtr com std::transform(comms, comms + count, begin(rcomms), [](const simgrid::kernel::activity::ActivityImplPtr& comm) { return static_cast(comm.get()); }); - return simcall_BODY_comm_waitany(rcomms.data(), rcomms.size(), timeout); + return static_cast(simcall_BODY_comm_waitany(rcomms.data(), rcomms.size(), timeout)); } -unsigned int simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count, double timeout) +ssize_t simcall_comm_waitany(simgrid::kernel::activity::CommImpl* comms[], size_t count, double timeout) { return simcall_BODY_comm_waitany(comms, count, timeout); } diff --git a/src/simix/popping_accessors.hpp b/src/simix/popping_accessors.hpp index 44c49db9ae..d963f3be72 100644 --- a/src/simix/popping_accessors.hpp +++ b/src/simix/popping_accessors.hpp @@ -597,17 +597,17 @@ static inline void simcall_comm_waitany__set__timeout(smx_simcall_t simcall, dou { simgrid::simix::marshal(simcall->args_[2], arg); } -static inline int simcall_comm_waitany__get__result(smx_simcall_t simcall) +static inline ssize_t simcall_comm_waitany__get__result(smx_simcall_t simcall) { - return simgrid::simix::unmarshal(simcall->result_); + return simgrid::simix::unmarshal(simcall->result_); } -static inline int simcall_comm_waitany__getraw__result(smx_simcall_t simcall) +static inline ssize_t simcall_comm_waitany__getraw__result(smx_simcall_t simcall) { - return simgrid::simix::unmarshal_raw(simcall->result_); + return simgrid::simix::unmarshal_raw(simcall->result_); } -static inline void simcall_comm_waitany__set__result(smx_simcall_t simcall, int result) +static inline void simcall_comm_waitany__set__result(smx_simcall_t simcall, ssize_t result) { - simgrid::simix::marshal(simcall->result_, result); + simgrid::simix::marshal(simcall->result_, result); } static inline simgrid::kernel::activity::CommImpl* simcall_comm_wait__get__comm(smx_simcall_t simcall) diff --git a/src/simix/popping_bodies.cpp b/src/simix/popping_bodies.cpp index bb48811434..c3b3d94bad 100644 --- a/src/simix/popping_bodies.cpp +++ b/src/simix/popping_bodies.cpp @@ -82,11 +82,11 @@ inline static ssize_t simcall_BODY_comm_testany(simgrid::kernel::activity::CommI return simcall(Simcall::COMM_TESTANY, comms, count); } -inline static int simcall_BODY_comm_waitany(simgrid::kernel::activity::CommImpl** comms, size_t count, double timeout) +inline static ssize_t simcall_BODY_comm_waitany(simgrid::kernel::activity::CommImpl** comms, size_t count, double timeout) { if (false) /* Go to that function to follow the code flow through the simcall barrier */ simcall_HANDLER_comm_waitany(&SIMIX_process_self()->simcall_, comms, count, timeout); - return simcall(Simcall::COMM_WAITANY, comms, count, timeout); + return simcall(Simcall::COMM_WAITANY, comms, count, timeout); } inline static void simcall_BODY_comm_wait(simgrid::kernel::activity::CommImpl* comm, double timeout) diff --git a/src/simix/simcalls.in b/src/simix/simcalls.in index db4bfbf3c0..9875570536 100644 --- a/src/simix/simcalls.in +++ b/src/simix/simcalls.in @@ -41,7 +41,7 @@ void comm_send(smx_actor_t sender, smx_mailbox_t mbox, double task_siz boost::intrusive_ptr comm_isend(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_clean_func_t clean_fun, simix_copy_data_func_t copy_data_fun, void* data, bool detached); bool comm_test(simgrid::kernel::activity::CommImpl* comm); ssize_t comm_testany(simgrid::kernel::activity::CommImpl** comms, size_t count); -int comm_waitany(simgrid::kernel::activity::CommImpl** comms, size_t count, double timeout) [[block]]; +ssize_t comm_waitany(simgrid::kernel::activity::CommImpl** comms, size_t count, double timeout) [[block]]; void comm_wait(simgrid::kernel::activity::CommImpl* comm, double timeout) [[block]]; void run_kernel(std::function const* code) [[nohandler]]; diff --git a/teshsuite/s4u/wait-any-for/wait-any-for.cpp b/teshsuite/s4u/wait-any-for/wait-any-for.cpp index c25455d66a..9438f45e04 100644 --- a/teshsuite/s4u/wait-any-for/wait-any-for.cpp +++ b/teshsuite/s4u/wait-any-for/wait-any-for.cpp @@ -31,11 +31,11 @@ static void worker() std::vector comms = {put1, put2, get1, get2}; while (not comms.empty()) { - int index = simgrid::s4u::Comm::wait_any_for(comms, 0.5); + ssize_t index = simgrid::s4u::Comm::wait_any_for(comms, 0.5); if (index < 0) XBT_INFO("wait_any_for: Timeout reached"); else { - XBT_INFO("wait_any_for: A comm finished (index=%d, #comms=%zu)", index, comms.size()); + XBT_INFO("wait_any_for: A comm finished (index=%zd, #comms=%zu)", index, comms.size()); comms.erase(comms.begin() + index); } } -- 2.20.1