From 8222fb56e43b2a3925731f7974505846adc07970 Mon Sep 17 00:00:00 2001 From: Augustin Degomme Date: Sun, 7 Mar 2021 18:36:40 +0100 Subject: [PATCH 1/1] Use flags to handle cancellation instead of a tri-state int --- src/smpi/include/private.hpp | 2 ++ src/smpi/include/smpi_request.hpp | 1 - src/smpi/mpi/smpi_request.cpp | 14 ++++++-------- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/smpi/include/private.hpp b/src/smpi/include/private.hpp index cb38feb9ba..fd6c957d1a 100644 --- a/src/smpi/include/private.hpp +++ b/src/smpi/include/private.hpp @@ -27,6 +27,8 @@ constexpr unsigned MPI_REQ_ACCUMULATE = 0x400; constexpr unsigned MPI_REQ_GENERALIZED = 0x800; constexpr unsigned MPI_REQ_COMPLETE = 0x1000; constexpr unsigned MPI_REQ_BSEND = 0x2000; +constexpr unsigned MPI_REQ_MATCHED = 0x4000; +constexpr unsigned MPI_REQ_CANCELLED = 0x8000; enum class SmpiProcessState { UNINITIALIZED, INITIALIZING, INITIALIZED /*(=MPI_Init called)*/, FINALIZED }; diff --git a/src/smpi/include/smpi_request.hpp b/src/smpi/include/smpi_request.hpp index 0c04de5847..16b89986c6 100644 --- a/src/smpi/include/smpi_request.hpp +++ b/src/smpi/include/smpi_request.hpp @@ -48,7 +48,6 @@ class Request : public F2C { MPI_Request detached_sender_; int refcount_; MPI_Op op_; - int cancelled_; // tri-state std::unique_ptr generalized_funcs; MPI_Request* nbc_requests_; int nbc_requests_size_; diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 850b77e01a..aa81e462b6 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -61,7 +61,6 @@ Request::Request(const void* buf, int count, MPI_Datatype datatype, int src, int refcount_ = 1; else refcount_ = 0; - cancelled_ = 0; nbc_requests_=nullptr; nbc_requests_size_=0; init_buffer(count); @@ -127,8 +126,7 @@ bool Request::match_common(MPI_Request req, MPI_Request sender, MPI_Request rece if (sender->detached_) receiver->detached_sender_ = sender; // tie the sender to the receiver, as it is detached and has to be freed in // the receiver - if (req->cancelled_ == 0) - req->cancelled_ = -1; // mark as uncancelable + req->flags_ |= MPI_REQ_MATCHED; // mark as impossible to cancel anymore XBT_DEBUG("match succeeded"); return true; } @@ -581,8 +579,7 @@ void Request::startall(int count, MPI_Request * requests) void Request::cancel() { - if(cancelled_!=-1) - cancelled_=1; + this->flags_ |= MPI_REQ_CANCELLED; if (this->action_ != nullptr) (boost::static_pointer_cast(this->action_))->cancel(); } @@ -616,7 +613,7 @@ int Request::test(MPI_Request * request, MPI_Status * status, int* flag) { Status::empty(status); *flag = 1; if (((*request)->flags_ & (MPI_REQ_PREPARED | MPI_REQ_FINISHED)) == 0) { - if ((*request)->action_ != nullptr && (*request)->cancelled_ != 1){ + if ((*request)->action_ != nullptr && ((*request)->flags_ & MPI_REQ_CANCELLED) == 0){ try{ *flag = simcall_comm_test((*request)->action_.get()); } catch (const Exception&) { @@ -859,14 +856,15 @@ void Request::finish_wait(MPI_Request* request, MPI_Status * status) { MPI_Request req = *request; Status::empty(status); - - if (req->cancelled_==1){ + if((req->flags_ & MPI_REQ_CANCELLED) != 0 && (req->flags_ & MPI_REQ_MATCHED) == 0) { if (status!=MPI_STATUS_IGNORE) status->cancelled=1; if(req->detached_sender_ != nullptr) unref(&(req->detached_sender_)); unref(request); return; + } else if ((req->flags_ & MPI_REQ_CANCELLED) != 0){ + XBT_WARN("tatatata"); } if ((req->flags_ & (MPI_REQ_PREPARED | MPI_REQ_GENERALIZED | MPI_REQ_FINISHED)) == 0) { -- 2.20.1